meep fails on OP_DUP after OP_UTXOVALUE
kliyer-ai opened this issue · 1 comments
kliyer-ai commented
kliyer-ai commented
This is the contract:
pragma cashscript ^0.7.0;
contract CashBox(bytes20 creator, bytes20 admin, int valuePerRedeem, int numRedeemsLeft) {
function redeem(pubkey adminPK, sig adminSig, bytes20 redeemer) {
// if this is the case, the creator needs to call the withdraw function
require(numRedeemsLeft > 0);
// only admin can call this function
require(hash160(adminPK) == admin);
require(checkSig(adminSig, adminPK));
// the script moust contain enough value so that all future redeems can be processed
int minerFee = 1000; // hardcoded fee
int amountSent = tx.inputs[this.activeInputIndex].value;
require(amountSent >= valuePerRedeem * numRedeemsLeft + minerFee * numRedeemsLeft);
// the first output needs to be money sent to the redeemer
bytes25 redeemerLock = new LockingBytecodeP2PKH(redeemer);
require(tx.outputs[0].lockingBytecode == redeemerLock);
require(tx.outputs[0].value == valuePerRedeem);
// the second output has to be a modified version of this contract (simulating state)
int newContractValue = amountSent - minerFee - valuePerRedeem;
require(tx.outputs[1].value == newContractValue);
// Cut out old initialBlock (OP_PUSHBYTES_8 <initialBlock>)
// Insert new initialBlock (OP_PUSHBYTES_8 <tx.locktime>)
// Note that constructor parameters are added in reverse order,
// so initialBlock is the first statement in the contract bytecode.
bytes newContract = 0x08 + bytes8(numRedeemsLeft - 1) + this.activeBytecode.split(9)[1];
// Create the locking bytecode for the new contract and check that
// the change output sends to that contract
bytes23 newContractLock = new LockingBytecodeP2SH(hash160(newContract));
require(tx.outputs[1].lockingBytecode == newContractLock);
}
function end(pubkey creatorPK, sig creatorSig){
// only the creator can end the contract
require(hash160(creatorPK) == creator);
require(checkSig(creatorSig, creatorPK));
int minerFee = 1000; // hardcoded fee
int amountSent = tx.inputs[this.activeInputIndex].value;
bytes25 creatorLock = new LockingBytecodeP2PKH(creator);
require(tx.outputs[0].lockingBytecode == creatorLock);
require(tx.outputs[0].value == amountSent - minerFee);
}
}