|
2 | 2 | // Distributed under the MIT software license, see the accompanying
|
3 | 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
4 | 4 |
|
5 |
| -#include <cstdio> |
6 | 5 | #include <span.h>
|
7 | 6 | #include <kernel/validation_cache_sizes.h>
|
8 | 7 | #include <primitives/transaction.h>
|
@@ -67,14 +66,6 @@ void initialize_simplicity_tx()
|
67 | 66 | INPUT_ASSET_CONF.vchCommitment[0] = 0x0a;
|
68 | 67 | }
|
69 | 68 |
|
70 |
| -void write_u32(FILE *fh, uint32_t val) { |
71 |
| - unsigned char buf[4]; |
72 |
| - |
73 |
| - val = htole32(val); |
74 |
| - memcpy(buf, &val, 4); |
75 |
| - assert(fwrite(buf, 1, 4, fh) == 4); |
76 |
| -} |
77 |
| - |
78 | 69 | FUZZ_TARGET_INIT(simplicity_tx, initialize_simplicity_tx)
|
79 | 70 | {
|
80 | 71 | simplicity_err error;
|
@@ -124,6 +115,7 @@ FUZZ_TARGET_INIT(simplicity_tx, initialize_simplicity_tx)
|
124 | 115 | // 3. Construct `nIn` and `spent_outs` arrays.
|
125 | 116 | bool expect_simplicity = false;
|
126 | 117 | std::vector<CTxOut> spent_outs{};
|
| 118 | + unsigned char last_cmr[32] = { 0 }; |
127 | 119 | for (unsigned int i = 0; i < mtx.vin.size(); i++) {
|
128 | 120 | // Null asset or value would assert in the interpreter, and are impossible
|
129 | 121 | // to hit in real transactions. Nonces are not included in the UTXO set and
|
@@ -162,6 +154,15 @@ FUZZ_TARGET_INIT(simplicity_tx, initialize_simplicity_tx)
|
162 | 154 | // Compute CMR and do some sanity checks on it (and the program)
|
163 | 155 | std::vector<unsigned char> cmr(32, 0);
|
164 | 156 | assert(simplicity_computeCmr(&error, cmr.data(), program.data(), program.size()));
|
| 157 | + if (error == SIMPLICITY_NO_ERROR) { |
| 158 | + if (memcmp(last_cmr, cmr.data(), sizeof(last_cmr)) == 0) { |
| 159 | + // If we have already seen this CMR this transaction, try mangling |
| 160 | + // it to check that this produces a CMR error and not something worse. |
| 161 | + cmr.data()[1] ^= 1; |
| 162 | + } |
| 163 | + memcpy(last_cmr, cmr.data(), sizeof(last_cmr)); |
| 164 | + } |
| 165 | + |
165 | 166 | const XOnlyPubKey internal{Span{control}.subspan(1, TAPROOT_CONTROL_BASE_SIZE - 1)};
|
166 | 167 |
|
167 | 168 | const CScript leaf_script{cmr.begin(), cmr.end()};
|
|
0 commit comments