mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
Merge pull request #1414 from apoelstra/2025-02--fuzz-update
fuzz: minor updates to the Simplicity fuzz tests
This commit is contained in:
commit
e343610b99
1 changed files with 10 additions and 9 deletions
|
|
@ -2,7 +2,6 @@
|
|||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <cstdio>
|
||||
#include <span.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <script/sigcache.h>
|
||||
|
|
@ -65,14 +64,6 @@ void initialize_simplicity_tx()
|
|||
INPUT_ASSET_CONF.vchCommitment[0] = 0x0a;
|
||||
}
|
||||
|
||||
void write_u32(FILE *fh, uint32_t val) {
|
||||
unsigned char buf[4];
|
||||
|
||||
val = htole32(val);
|
||||
memcpy(buf, &val, 4);
|
||||
assert(fwrite(buf, 1, 4, fh) == 4);
|
||||
}
|
||||
|
||||
FUZZ_TARGET_INIT(simplicity_tx, initialize_simplicity_tx)
|
||||
{
|
||||
simplicity_err error;
|
||||
|
|
@ -122,6 +113,7 @@ FUZZ_TARGET_INIT(simplicity_tx, initialize_simplicity_tx)
|
|||
// 3. Construct `nIn` and `spent_outs` arrays.
|
||||
bool expect_simplicity = false;
|
||||
std::vector<CTxOut> spent_outs{};
|
||||
unsigned char last_cmr[32] = { 0 };
|
||||
for (unsigned int i = 0; i < mtx.vin.size(); i++) {
|
||||
// Null asset or value would assert in the interpreter, and are impossible
|
||||
// to hit in real transactions. Nonces are not included in the UTXO set and
|
||||
|
|
@ -160,6 +152,15 @@ FUZZ_TARGET_INIT(simplicity_tx, initialize_simplicity_tx)
|
|||
// Compute CMR and do some sanity checks on it (and the program)
|
||||
std::vector<unsigned char> cmr(32, 0);
|
||||
assert(simplicity_computeCmr(&error, cmr.data(), program.data(), program.size()));
|
||||
if (error == SIMPLICITY_NO_ERROR) {
|
||||
if (memcmp(last_cmr, cmr.data(), sizeof(last_cmr)) == 0) {
|
||||
// If we have already seen this CMR this transaction, try mangling
|
||||
// it to check that this produces a CMR error and not something worse.
|
||||
cmr.data()[1] ^= 1;
|
||||
}
|
||||
memcpy(last_cmr, cmr.data(), sizeof(last_cmr));
|
||||
}
|
||||
|
||||
const XOnlyPubKey internal{Span{control}.subspan(1, TAPROOT_CONTROL_BASE_SIZE - 1)};
|
||||
|
||||
const CScript leaf_script{cmr.begin(), cmr.end()};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue