// Copyright (c) 2020 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include extern "C" { #include #include } #include #include #include #include #include #include #include FUZZ_TARGET(simplicity) { FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); { const std::optional mtx_precomputed = ConsumeDeserializable(fuzzed_data_provider); if (mtx_precomputed) { const CTransaction tx_precomputed{*mtx_precomputed}; const PrecomputedTransactionData precomputed_transaction_data{tx_precomputed}; const transaction* tx = precomputed_transaction_data.m_simplicity_tx_data; const uint256 genesisBlockHash = precomputed_transaction_data.m_hash_genesis_block; std::vector imr = fuzzed_data_provider.ConsumeBytes(32); const uint_fast32_t ix = fuzzed_data_provider.ConsumeIntegral(); const std::vector control = ConsumeRandomLengthByteVector(fuzzed_data_provider); // control block invariant: 33 + pathLen*32 // https://github.com/ElementsProject/elements/blob/174c46baecd/src/script/interpreter.cpp#L3285 if ( control.size() >= TAPROOT_CONTROL_BASE_SIZE && control.size() <= TAPROOT_CONTROL_MAX_SIZE && ((control.size() - TAPROOT_CONTROL_BASE_SIZE) % TAPROOT_CONTROL_NODE_SIZE) == 0 ) { const std::vector script_bytes = fuzzed_data_provider.ConsumeBytes(32); // script_bytes invariant: 32 bytes // https://github.com/ElementsProject/elements/blob/174c46baecd/src/script/interpreter.cpp#L3300 if (script_bytes.size() == 32) { rawTapEnv simplicityRawTap; simplicityRawTap.controlBlock = control.data(); simplicityRawTap.pathLen = (control.size() - TAPROOT_CONTROL_BASE_SIZE) / TAPROOT_CONTROL_NODE_SIZE; simplicityRawTap.scriptCMR = script_bytes.data(); tapEnv* taproot = simplicity_elements_mallocTapEnv(&simplicityRawTap); const int64_t budget = fuzzed_data_provider.ConsumeIntegral(); const std::vector amr = fuzzed_data_provider.ConsumeBytes(32); const std::vector program = ConsumeRandomLengthByteVector(fuzzed_data_provider); simplicity_err error; simplicity_elements_execSimplicity(&error, imr.data(), tx, ix, taproot, genesisBlockHash.data(), budget, amr.data(), program.data(), program.size()); free(taproot); } } } } }