Skip to content

Commit

Permalink
Revert "Merge pull request ElementsProject#1414 from apoelstra/2025-0…
Browse files Browse the repository at this point in the history
…2--fuzz-update"

This reverts commit e343610, reversing
changes made to 0397d22.
  • Loading branch information
psgreco committed Feb 18, 2025
1 parent 12c586a commit 9310412
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/test/fuzz/simplicity_tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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>
Expand Down Expand Up @@ -64,6 +65,14 @@ 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;
Expand Down Expand Up @@ -113,7 +122,6 @@ 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
Expand Down Expand Up @@ -152,15 +160,6 @@ 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()};
Expand Down

0 comments on commit 9310412

Please sign in to comment.