| 74 | #define MAX_LEN (1024 * 1024) |
| 75 | |
| 76 | FUZZ_TARGET_INIT(simplicity, initialize_simplicity) |
| 77 | { |
| 78 | const unsigned char *buf = buffer.data(); |
| 79 | |
| 80 | uint32_t budget; |
| 81 | uint32_t tx_data_len; |
| 82 | uint32_t prog_data_len; |
| 83 | uint32_t wit_data_len; |
| 84 | |
| 85 | // 1. Sanitize and parse the buffer |
| 86 | if (buffer.size() < 8) { |
| 87 | return; |
| 88 | } |
| 89 | budget = read_u32(&buf); |
| 90 | |
| 91 | tx_data_len = read_u32(&buf); |
| 92 | if (tx_data_len > MAX_LEN || buffer.size() < tx_data_len + 12) { |
| 93 | return; |
| 94 | } |
| 95 | const unsigned char *tx_data = buf; |
| 96 | buf += tx_data_len; |
| 97 | |
| 98 | prog_data_len = read_u32(&buf); |
| 99 | if (prog_data_len > MAX_LEN || buffer.size() < tx_data_len + prog_data_len + 16) { |
| 100 | return; |
| 101 | } |
| 102 | const unsigned char *prog_data = buf; |
| 103 | buf += prog_data_len; |
| 104 | |
| 105 | wit_data_len = read_u32(&buf); |
| 106 | if (wit_data_len > MAX_LEN || buffer.size() != tx_data_len + prog_data_len + wit_data_len + 16) { |
| 107 | return; |
| 108 | } |
| 109 | const unsigned char *wit_data = buf; |
| 110 | |
| 111 | //printf("OK going\n"); |
| 112 | |
| 113 | // 2. Parse the transaction (the program and witness are just raw bytes) |
| 114 | CMutableTransaction mtx; |
| 115 | CDataStream txds{Span{tx_data, tx_data_len}, SER_NETWORK, INIT_PROTO_VERSION}; |
| 116 | try { |
| 117 | txds >> mtx; |
| 118 | mtx.witness.vtxinwit.resize(mtx.vin.size()); |
| 119 | mtx.witness.vtxoutwit.resize(mtx.vout.size()); |
| 120 | |
| 121 | // We use the first vin as a "random oracle" rather than reading more from |
| 122 | // the fuzzer, because we want our fuzz seeds to have as simple a structure |
| 123 | // as possible. This means we must reject 0-input transactions, which are |
| 124 | // invalid on-chain anyway. |
| 125 | if (mtx.vin.size() == 0) { |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | // This is an assertion in the Simplicity interpreter. It is guaranteed |
| 130 | // to hold for anything on the network since (even if validatepegin is off) |
| 131 | // pegins are validated for well-formedness long before the script interpreter |
| 132 | // is invoked. But in this code we just call the interpreter directly without |
| 133 | // these checks. |
nothing calls this directly
no test coverage detected