0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-20 12:12:41 -05:00
bitcoin-bitcoin-core/src/test/fuzz/psbt.cpp
fanquake 07c54de550
Merge bitcoin/bitcoin#26691: Update secp256k1 subtree to libsecp256k1 version 0.2.0
2022917223 Add secp256k1_selftest call (Pieter Wuille)
3bfca788b0 Remove explicit enabling of default modules (Pieter Wuille)
4462cb0498 Adapt to libsecp256k1 API changes (Pieter Wuille)
9d47e7b71b Squashed 'src/secp256k1/' changes from 44c2452fd3..21ffe4b22a (Pieter Wuille)

Pull request description:

  Now that libsecp256k1 has a release (https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2022-December/021271.html), update the subtree to match it.

  The changes themselves are not very impactful for Bitcoin Core, but include:
  * It's no longer needed to specify whether contexts are for signing or verification or both (all contexts support everything), so make use of that in this PR.
  * Verification operations can use the static context now, removing the need for some infrastructure in pubkey.cpp to make sure a context exists.
  * Most modules are now enabled by default, so we can drop explicit enabling for them.
  * CI improvements (in particular, MSVC and more recent MacOS)
  * Introduction of an internal int128 type, which has no effect for GCC/Clang builds, but enables 128-bit multiplication in MSVC, giving a ~20% speedup there (but still slower than GCC/Clang).
  * Release process changes (process documentation, changelog, ...).

ACKs for top commit:
  Sjors:
    ACK 2022917223, but 4462cb0498 could use more eyes on it.
  achow101:
    ACK 2022917223
  jonasnick:
    utACK 2022917223

Tree-SHA512: 8a9fe28852abe74abd6f96fef16a94d5a427b1d99bff4caab1699014d24698aab9b966a5364a46ed1001c07a7c1d825154ed4e6557c7decce952b77330a8616b
2023-01-13 09:40:57 +00:00

94 lines
2.8 KiB
C++

// Copyright (c) 2019-2022 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 <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <node/psbt.h>
#include <psbt.h>
#include <pubkey.h>
#include <script/script.h>
#include <streams.h>
#include <util/check.h>
#include <version.h>
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
using node::AnalyzePSBT;
using node::PSBTAnalysis;
using node::PSBTInputAnalysis;
FUZZ_TARGET(psbt)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
PartiallySignedTransaction psbt_mut;
std::string error;
auto str = fuzzed_data_provider.ConsumeRandomLengthString();
if (!DecodeRawPSBT(psbt_mut, MakeByteSpan(str), error)) {
return;
}
const PartiallySignedTransaction psbt = psbt_mut;
const PSBTAnalysis analysis = AnalyzePSBT(psbt);
(void)PSBTRoleName(analysis.next);
for (const PSBTInputAnalysis& input_analysis : analysis.inputs) {
(void)PSBTRoleName(input_analysis.next);
}
(void)psbt.IsNull();
std::optional<CMutableTransaction> tx = psbt.tx;
if (tx) {
const CMutableTransaction& mtx = *tx;
const PartiallySignedTransaction psbt_from_tx{mtx};
}
for (const PSBTInput& input : psbt.inputs) {
(void)PSBTInputSigned(input);
(void)input.IsNull();
}
(void)CountPSBTUnsignedInputs(psbt);
for (const PSBTOutput& output : psbt.outputs) {
(void)output.IsNull();
}
for (size_t i = 0; i < psbt.tx->vin.size(); ++i) {
CTxOut tx_out;
if (psbt.GetInputUTXO(tx_out, i)) {
(void)tx_out.IsNull();
(void)tx_out.ToString();
}
}
psbt_mut = psbt;
(void)FinalizePSBT(psbt_mut);
psbt_mut = psbt;
CMutableTransaction result;
if (FinalizeAndExtractPSBT(psbt_mut, result)) {
const PartiallySignedTransaction psbt_from_tx{result};
}
PartiallySignedTransaction psbt_merge;
str = fuzzed_data_provider.ConsumeRandomLengthString();
if (!DecodeRawPSBT(psbt_merge, MakeByteSpan(str), error)) {
psbt_merge = psbt;
}
psbt_mut = psbt;
(void)psbt_mut.Merge(psbt_merge);
psbt_mut = psbt;
(void)CombinePSBTs(psbt_mut, {psbt_mut, psbt_merge});
psbt_mut = psbt;
for (unsigned int i = 0; i < psbt_merge.tx->vin.size(); ++i) {
(void)psbt_mut.AddInput(psbt_merge.tx->vin[i], psbt_merge.inputs[i]);
}
for (unsigned int i = 0; i < psbt_merge.tx->vout.size(); ++i) {
Assert(psbt_mut.AddOutput(psbt_merge.tx->vout[i], psbt_merge.outputs[i]));
}
psbt_mut.unknown.insert(psbt_merge.unknown.begin(), psbt_merge.unknown.end());
}