While the bitcoin/elements project testing isn't trying to gain coverage of the regular
libsecp256k1 library, in our case we do want our (fuzz) testing to cover
simplicity's own copy of libsecp256k1, which has been specifically trimmed down
to only include functionality needed by simplicity's jets.
The main difference is that there is now explicit simplicity deallocation functions to go with the allocation functions in the API.
There are some minor changes to error message text.
The deserialization code is now automatically generated.
The are some other minor internal changes.
Without this patch, the --with-sanitizers config flag has no effect on
the copy of libsimplicity in Elements Core. This means that we aren't
running asan or tsan when we intend to, and also means that when fuzzing
we aren't instrumenting the Simplicity binary.
The result is extremely bad fuzz coverage and missed bugs.
ubsan suppression for simplicity sha256.c
ubsan detects when a left shift would overflow an integer type. This is
not UB (it would be if you tried to shift more than the type's width in
one shot) but "may be unintentional" and is therefore detected.
Add a whitelist to the giant list of whitelists.
We have the code fragment `txTo.GetHash().begin()`, which takes a
transaction, computes its txid as a uint256, and then saves a pointer to
the internal data of the uint256.
However, in C++, expressions of the form a.b().c() lead to the return
value of `b` being dropped immediately after the call to `c`. This is
fine if `c` is something like `GetHex` which returns a new independently
allocated object with no pointers to its input. It is not fine for
`begin` which returns a pointer into the return value of `GetHash`.
So this fragment returns a dangling pointer, which is later used by the
Simplicity interpreter, leading to UB.
In practice this code appeared to work, possibly because the stack
layout was such that it actually did work ok. Or possibly because we
don't test with enough fidelity to tell that Simplicity's view of the
txid of a transaction was mangled.
Copy the parameters for mainnet because they seem to have worked fine
for Taproot and are therefore a good starting point for Simplicity.
Copy them for regtest so that we can also copy the functional test for
activation, without needing to change a whole bunch of numbers.
Compare the expected script error, parsed from JSON, with the actual
error that VerifyScript returns. If the JSON does not include an
expected error, then skip this check.
Take the existing function to parse script errors and extend it to parse
Elements errors. SCRIPT_ERR_ERROR_COUNT is not included because it is a
pseudo error.
Thanks to Jon Griffiths for picking up that the amount and nonce discount
should be multiplied by the witness scaling factor as they form part of
the base transaction.