CashScript / cashscript

⚖️ Easily write and interact with Bitcoin Cash smart contracts
https://cashscript.org
MIT License
115 stars 80 forks source link

mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element) (code 16) #69

Closed nyusternie closed 4 years ago

nyusternie commented 4 years ago

I have a contract that's having some inconsistencies I can't explain .. I've tried searching for the error, but none of the hits offered a solution..

meep debug --tx=02000000017296be2da833d7b7e31a7b8e15fdf589e475026328287043cd6a84dfe70cc8dc00000000fd400308cbd0090039070000473045022100c2d72abce0fd542df2930698eddce94271f4d879e7dfa6e9264c29e1dadcb91002207ece5c08bfe499954c34a2f0e9ab1f76a016c7d716e242819cf2515cc9e94b314114731693c66e94a4b68d087b8bf6434e37a36384659e314a8f8fb3247fb41a13a1945bf1d58d7e4000e63aebe27ff3c97ee807d0d63eb31b89877c709d83a4e741210344b28c3daf7c88741c483f068fa4525572587263af3344c631bccf5df6492f124d910102000000a5fcba62f38eae614cf7723686ece695377208659da365de1c321ae1ea763de418606b350cd8bf565266bc352f0caddcf01e8fa789dd8a15386327cf8cabe1987296be2da833d7b7e31a7b8e15fdf589e475026328287043cd6a84dfe70cc8dc00000000f40333d009210344b28c3daf7c88741c483f068fa4525572587263af3344c631bccf5df6492f12144dec2661eb4de14a3b8cda28fb7ca19f0e98cad01455670d530c2feb8a7a2d0bb2d888d6db02e1a1cb14212afcde653565e8121a180aebee97f5d235817d5579009c63567901697f77820134947f587f547f7701207f755b7a5b796e7c828c7f755d7aa87bbbad5a7a5b79587abb5979547f7581597aa9577a876376b1756776b17568567aa269567a547f7781023905537a8152795880041976a9147e567a7e0288ac7e7c537a947b9458800317a9147e537aa97e01877e7eaa87777767557a519d5579a97b8871ad6d6d5168720c000000000000feffffff6594114b69be15493cda32acca1a0e5725b66fc5a843ccf446a77dc0e92b3450fbd0090041000000004cf40333d009210344b28c3daf7c88741c483f068fa4525572587263af3344c631bccf5df6492f12144dec2661eb4de14a3b8cda28fb7ca19f0e98cad01455670d530c2feb8a7a2d0bb2d888d6db02e1a1cb14212afcde653565e8121a180aebee97f5d235817d5579009c63567901697f77820134947f587f547f7701207f755b7a5b796e7c828c7f755d7aa87bbbad5a7a5b79587abb5979547f7581597aa9577a876376b1756776b17568567aa269567a547f7781023905537a8152795880041976a9147e567a7e0288ac7e7c537a947b9458800317a9147e537aa97e01877e7eaa87777767557a519d5579a97b8871ad6d6d5168feffffff0139070000000000001976a914212afcde653565e8121a180aebee97f5d235817d88acfbd00900 --idx=0 --amt=3186 --pkscript=a914133c04f70740a2f5d567679a4b37c095830200fe87

for some reason, I'm unable to install meep to run this and "maybe" shed some light on the issue .. could someone that has a "working" version of meep, run this and post the results??

~I have a few workarounds to this issue that so far HAVE been consistent, but they would degrade the effectiveness of this contract.~ fyi, I have SEVERAL versions of this contract, but I can post one or more if that would help in resolving the issue..

thanks!


edit: here's the error when I try to make meep .. also go get github.com/gcash/meep is hanging, probably for the same reason

env GO111MODULE=on go build .
../../go/src/github.com/gcash/bchd/txscript/pkscript.go:10:2: cannot find package "github.com/gcash/bchutil" in any of:
    /usr/lib/go-1.10/src/github.com/gcash/bchutil (from $GOROOT)
    /home/dev/go/src/github.com/gcash/bchutil (from $GOPATH)
main.go:5:2: cannot find package "github.com/jessevdk/go-flags" in any of:
    /usr/lib/go-1.10/src/github.com/jessevdk/go-flags (from $GOROOT)
    /home/dev/go/src/github.com/jessevdk/go-flags (from $GOPATH)
debug.go:16:2: cannot find package "github.com/nsf/termbox-go" in any of:
    /usr/lib/go-1.10/src/github.com/nsf/termbox-go (from $GOROOT)
    /home/dev/go/src/github.com/nsf/termbox-go (from $GOPATH)
../../go/src/github.com/gcash/bchd/txscript/opcode.go:15:2: cannot find package "golang.org/x/crypto/ripemd160" in any of:
    /usr/lib/go-1.10/src/golang.org/x/crypto/ripemd160 (from $GOROOT)
    /home/dev/go/src/golang.org/x/crypto/ripemd160 (from $GOPATH)
Makefile:9: recipe for target 'all' failed
make: *** [all] Error 1
rkalis commented 4 years ago

So I ran the meep command through meep and it looks like your tx.hashOutputs do not exactly match the outputs of the transaction. Note that the CashScript SDK automatically adds a change output for the leftover money in the contract, which might be a source of error here. You can disable this change output by calling withMinChange(Number.MAX_VALUE) when building the transaction.

If that is not the cause of the error, try to double check if the outputs you added using the to() function exactly match the expected output of the smart contract.

nyusternie commented 4 years ago

Note that the CashScript SDK automatically adds a change output for the leftover money in the contract, which might be a source of error here

hmmm, yeah that sounds about right, considering the inconsistency came with varying UTXO amounts for the same Script .. ugh! likely NOT gonna go back and re-test this right now .. really determined to get the Mecenas contract fully tested (w/ all edge cases) so I can launch Causes Cash asap..

withMinChange(Number.MAX_VALUE)

if I hit this issue again, I'll definitely give this a try..

appreciate you making the time to sort me out 🙏