Skip to content

Conversation

@darosior
Copy link
Contributor

Based on #93, since the bugfix is needed.

This replicates the tests of random_tests, except for TestSatisfy: instead of iterating to find the challenges, and set making them available one by one to compare the satisfactions with the previous iteration's ones, just assert the result against VerifyScript and some invariants regarding mal / nonmal.

This is does not try to be (expensively) smart by trying to always create a valid node, instead carry around the fuzz data provider and return as soon as we generate an invalid node at any depth. tThanks to Pieter for guidance.)

@darosior
Copy link
Contributor Author

I've been running it overnight (with -maxlen=60000 -lencontrol=0 to find more interesting seeds).

@darosior
Copy link
Contributor Author

It's pretty similar to #78, but i don't think it's redundant

@darosior
Copy link
Contributor Author

As noted by MarcoFalke on the Bitcoin Core repo, this may be potentially
dangerous.
Use a generalistic named function for constructing CScripts instead.

Co-Authored-By: Pieter Wuille <[email protected]>
@sipa
Copy link
Owner

sipa commented Jan 31, 2022

If you're done with changes here, I'd like to take a shot at making this non-recursive.

@darosior
Copy link
Contributor Author

darosior commented Jan 31, 2022 via email

@sipa
Copy link
Owner

sipa commented Jan 31, 2022

I won't have time for this before tomorrow, so I'll let you go first.

@darosior darosior force-pushed the random_tests_to_fuzz branch from 8fdbcac to c4f5df0 Compare February 1, 2022 10:15
@darosior
Copy link
Contributor Author

darosior commented Feb 1, 2022

Applied your comments, thanks. All yours now :)

@sipa
Copy link
Owner

sipa commented Feb 2, 2022

Here is my branch (yours, with a commit on top): https://github.com/sipa/bitcoin/commits/random_fuzz

It has some logic to propagate type requirements down, in the hope that this causes faster failure on uninteresting paths. The downside is that it adds complexity, and in case it is wrong, may mean potentially interesting cases are never explored. I'm open to discussing dropping some or all of that.

The current commit keeps track of (nodetype, type) tuples and prints out the generated miniscripts for each new case in those. That's mostly to observe whether it actually reaches interesting things.

@sipa
Copy link
Owner

sipa commented Feb 2, 2022

Hmm, it hits assertion failures! Will investigate tomorrow.

@sipa
Copy link
Owner

sipa commented Feb 2, 2022

This miniscript is considered IsSaneTopLevel, but signing for it fails with ops limit exceeded: c:andor(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(and_n(or_d(or_d(or_d(or_d(or_d(pkh(037a7e3ccbfffbc4ca8e155033db460bce1a6d66d12baf2ad572381980830d9b24),pkh(037a7e3ccbfffbc4ca8e155033db460bce1a6d66d12baf2ad572381980830d9b24)),pkh(037a7e3ccbfffbc4ca8e155033db460bce1a6d66d12baf2ad572381980830d9b24)),pkh(037a7e3ccbfffbc4ca8e155033db460bce1a6d66d12baf2ad572381980830d9b24)),pkh(037a7e3ccbfffbc4ca8e155033db460bce1a6d66d12baf2ad572381980830d9b24)),pkh(037a7e3ccbfffbc4ca8e155033db460bce1a6d66d12baf2ad572381980830d9b24)),or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(and_n(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(or_d(multi(1,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa,028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0)),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),pk_k(028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa),pk_k(028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa)).

The decoded script is OP_DUP OP_HASH160 fa616b190a402bd1ec90a9abdf0473d1d7d471dd OP_EQUALVERIFY OP_CHECKSIG OP_IFDUP OP_NOTIF OP_DUP OP_HASH160 fa616b190a402bd1ec90a9abdf0473d1d7d471dd OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF OP_IFDUP OP_NOTIF OP_DUP OP_HASH160 fa616b190a402bd1ec90a9abdf0473d1d7d471dd OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF OP_IFDUP OP_NOTIF OP_DUP OP_HASH160 fa616b190a402bd1ec90a9abdf0473d1d7d471dd OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF OP_IFDUP OP_NOTIF OP_DUP OP_HASH160 fa616b190a402bd1ec90a9abdf0473d1d7d471dd OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF OP_IFDUP OP_NOTIF OP_DUP OP_HASH160 fa616b190a402bd1ec90a9abdf0473d1d7d471dd OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF OP_NOTIF 0 OP_ELSE 1 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa 20 OP_CHECKMULTISIG OP_IFDUP OP_NOTIF 0 OP_ENDIF OP_IFDUP OP_NOTIF 0 OP_ENDIF OP_IFDUP OP_NOTIF 0 OP_ENDIF OP_IFDUP OP_NOTIF 0 OP_EN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OTIF 0 OP_ENDIF OP_IFDUP OP_NOTIF 0 OP_ENDIF OP_IFDUP OP_NOTIF 0 OP_ENDIF OP_IFDUP OP_NOTIF 0 OP_ENDIF OP_NOTIF 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa OP_ELSE 028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa OP_ENDIF OP_CHECKSIG

case NodeType::PK_H: return subsize + 3 + 21;
case NodeType::OLDER: return subsize + 1 + (CScript() << k).size();
case NodeType::AFTER: return subsize + 1 + (CScript() << k).size();
case NodeType::OLDER: return subsize + 1 + BuildScript(k).size();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR but i wonder why we add subsize here. It must always be 0 so that's unnecessarily confusing. Same for all fragments without subs in this function.

Removing them on the PR following this comment: bitcoin/bitcoin#24147 (comment)

@darosior
Copy link
Contributor Author

So i'm going to close this since it's not up to date and the work around the fuzz targets has been scattered all around the place. I'll open an issue to centralize what's left to be done.

@darosior darosior closed this Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants