6#include <chainparams.h>
15#include <test/data/bip352_send_and_receive_vectors.json.h>
19#include <boost/test/unit_test.hpp>
41 for (
const auto&
vec :
tests.getValues()) {
45 for (
const auto& sender :
vec[
"sending"].getValues()) {
47 const UniValue& expected = sender[
"expected"];
49 std::vector<COutPoint> outpoints;
50 std::vector<CKey>
keys;
52 for (
const auto& input :
given[
"vin"].getValues()) {
54 outpoints.push_back(outpoint);
55 const auto&
spk_bytes =
ParseHex(input[
"prevout"][
"scriptPubKey"][
"hex"].get_str());
68 if (pubkey.has_value()) {
69 std::vector<std::vector<unsigned char>>
solutions;
79 BOOST_CHECK(expected[
"outputs"].getValues()[0].empty());
84 std::map<size_t, SilentPaymentsDestination>
sp_dests;
103 BOOST_CHECK(expected[
"outputs"].getValues()[0].empty());
115 return std::find(expected_spks.begin(), expected_spks.end(), entry.second) != expected_spks.end();
123 for (
const auto& recipient :
vec[
"receiving"].getValues()) {
126 const UniValue& expected = recipient[
"expected"];
128 std::vector<CTxIn> vin;
129 std::map<COutPoint, Coin> coins;
130 for (
const auto& input :
given[
"vin"].getValues()) {
132 const auto&
spk_bytes =
ParseHex(input[
"prevout"][
"scriptPubKey"][
"hex"].get_str());
154 for (
const auto& pubkey :
given[
"outputs"].getValues()) {
183 if (found_outputs->empty()) {
187 if (!expected[
"n_outputs"].isNull()) {
191 for (
const auto& output : expected[
"outputs"].
getValues()) {
198 for (
const auto& output : *found_outputs) {
201 BOOST_CHECK(output.tweak == expected_output->second);
211 CKey scan_key =
ParseHexToCKey(
"0000000000000000000000000000000000000000000000000000000000000002");
229 CKey key =
ParseHexToCKey(
"0000000000000000000000000000000000000000000000000000000000000001");
238 std::map<COutPoint, Coin> coins;
249 CKey scan_key =
ParseHexToCKey(
"0000000000000000000000000000000000000000000000000000000000000002");
251 const COutPoint outpoint{
Txid::FromHex(
"0000000000000000000000000000000000000000000000000000000000000001").value(), 0};
253 std::map<size_t, SilentPaymentsDestination>
sp_dests;
261 txin.scriptWitness.stack.emplace_back();
264 std::map<COutPoint, Coin> coins;
277 BOOST_CHECK(found_outputs->front().output == expected_output);
289 const CKey key =
ParseHexToCKey(
"0000000000000000000000000000000000000000000000000000000000000001");
295 tx.
vin.emplace_back(
COutPoint{
Txid::FromHex(
"0000000000000000000000000000000000000000000000000000000000000001").value(), 0});
296 std::vector<unsigned char> sig;
317 CKey scan_key =
ParseHexToCKey(
"0000000000000000000000000000000000000000000000000000000000000002");
337 std::string scan_pubkey;
338 std::string spend_pubkey;
344 "sp1qq22l5s6l9460ww6t4tkzsy2a7zejurcmzz35pt0ffrzk5erlaykdcqugecjjnjqf7ggq39vl6wexjlm00n66z94v675n7wcux6d2krr68gdjvfn2",
345 "0295fa435f2d74f73b4baaec28115df0b32e0f1b10a340ade948c56a647fe92cdc",
346 "0388ce2529c809f21008959fd3b2697f6f7cf5a116acd7a93f3b1c369aab0c7a3a",
349 "sp1pq22l5s6l9460ww6t4tkzsy2a7zejurcmzz35pt0ffrzk5erlaykdcqugecjjnjqf7ggq39vl6wexjlm00n66z94v675n7wcux6d2krr68t02m0h0s8cwhy",
350 "0295fa435f2d74f73b4baaec28115df0b32e0f1b10a340ade948c56a647fe92cdc",
351 "0388ce2529c809f21008959fd3b2697f6f7cf5a116acd7a93f3b1c369aab0c7a3a",
354 "tsp1qqthpye3hdcnydp9temp7yduy6uw5h2nw8u9fz677ccrna280qwj3uq60zeqs3zfpj3age62h4ljq2lyawwdecmk8a545yysk4x3tu3skjqm2thu6",
355 "02ee1266376e264684abcec3e23784d71d4baa6e3f0a916bdec6073ea8ef03a51e",
356 "034f1641088921947a8ce957afe4057c9d739b9c6ec7ed2b421216a9a2be461690",
359 "tsp1qqvrl2accqtatgtkllv5fdsfapq6vqnrr0uf2whhmjyas4teg7ljfqqlpec0ze90m97t3stv92p5ekzkcwzmpx0x8p7ljj9xqcjjpvnfurc00tjn9",
360 "0307f5771802fab42edffb2896c13d0834c04c637f12a75efb913b0aaf28f7e490",
361 "03e1ce1e2c95fb2f97182d8550699b0ad870b6133cc70fbf2914c0c4a4164d3c1e",
364 "sprt1qq04xgllnqqfdlxjkr355rmsahfn9t8l6sd0k20t4uka4c73nvvpnwqu4kvg0nm62d5jtmqp54lkc7tul0dzt25ejtn4f80505z3u0h5jag59rdg4",
365 "03ea647ff30012df9a561c6941ee1dba66559ffa835f653d75e5bb5c7a33630337",
366 "0395b310f9ef4a6d24bd8034afed8f2f9f7b44b553325cea93be8fa0a3c7de92ea",
394 std::optional<ChainType> chain = std::nullopt;
398 {
"spx1qq22l5s6l9460ww6t4tkzsy2a7zejurcmzz35pt0ffrzk5erlaykdcqugecjjnjqf7ggq39vl6wexjlm00n66z94v675n7wcux6d2krr68g37pn04",
399 "Invalid or unsupported prefix for Silent Payments address (expected sp, got spx)."},
400 {
"sp1qq22l5s6l9460ww6t4tkzsy2a7zejurcmzz35pt0ffrzk5erlaykdcqugecjjnjqf7ggq39vl6wexjlm00n66z94v675n7wcux6d2krr68gcwu9kg",
401 "Silent Payments address must use Bech32m checksum", std::nullopt,
true},
402 {
"sp1qqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq2qugecjjnjqf7ggq39vl6wexjlm00n66z94v675n7wcux6d2krr68g25havg",
404 {
"sp1qq22l5s6l9460ww6t4tkzsy2a7zejurcmzz35pt0ffrzk5erlaykdcqsqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq57qc9nf",
406 {
"sp1lq22l5s6l9460ww6t4tkzsy2a7zejurcmzz35pt0ffrzk5erlaykdcqugecjjnjqf7ggq39vl6wexjlm00n66z94v675n7wcux6d2krr68gaafydt",
407 "This implementation only supports Silent payments addresses v0 through v30 (got 31).",
ChainType::MAIN},
408 {
"sp1qq22l5s6l9460ww6t4tkzsy2a7zejurcmzz35pt0ffrzk5erlaykdcznsxsn",
409 "Silent payments data payload is too small (expected at least 66, got 33).",
ChainType::MAIN},
410 {
"tsp1qqthpye3hdcnydp9temp7yduy6uw5h2nw8u9fz677ccrna280qwj3uq60zeqs3zfpj3age62h4ljq2lyawwdecmk8a545yysk4x3tu3skjqm2thum",
411 "Silent Payments address must use Bech32m checksum", std::nullopt,
true},
412 {
"sp1qqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqsqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqf26rn7",
413 "Silent Payments address must use Bech32m checksum", std::nullopt,
true},
414 {
"sprt1qqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq2qu4kvg0nm62d5jtmqp54lkc7tul0dzt25ejtn4f80505z3u0h5jagf9zkp5",
423 if (
vec.chain_independent || chain ==
vec.chain) {
426 BOOST_CHECK_MESSAGE(
sp.error().starts_with(
"Invalid or unsupported prefix for Silent Payments address"),
sp.error());
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
void SelectParams(const ChainType chain)
Sets the params returned by Params() to those for the given chain type.
const CChainParams & Params()
Return the currently selected parameters.
An encapsulated private key.
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig, bool grind=true, uint32_t test_case=0) const
Create a DER-serialized signature.
CPubKey GetPubKey() const
Compute the public key from a private key.
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
An outpoint - a combination of a transaction hash and an index n into its vout.
An encapsulated public key.
const unsigned char * end() const
const unsigned char * begin() const
Serialized script, used inside transaction inputs and outputs.
An input of a transaction.
CScriptWitness scriptWitness
Only serialized through CTransaction.
An output of a transaction.
Double ended buffer combining vector and stream-like interfaces.
Minimal stream for reading from an existing byte array by std::span.
const std::vector< UniValue > & getValues() const
const unsigned char * begin() const
static std::optional< SilentPaymentsLabel > Unserialize(Stream &s)
void Serialize(Stream &s) const
A silent payments recipient's scanning identity.
static std::optional< transaction_identifier > FromHex(std::string_view hex)
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, int32_t nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache, SigHashCache *sighash_cache)
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, script_verify_flags flags, const BaseSignatureChecker &checker, ScriptError *serror)
@ BASE
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
@ ASSERT_FAIL
Abort execution through assertion failure (for consensus code)
util::Expected< PrevoutsSummary, PrevoutsSummaryError > GetSilentPaymentsPrevoutsSummary(const std::vector< CTxIn > &vin, const std::map< COutPoint, Coin > &coins)
Get silent payments public data from transaction inputs.
std::optional< PubKey > GetPubKeyFromInput(const CTxIn &txin, const CScript &spk)
Get the public key from an input.
std::optional< std::map< size_t, WitnessV1Taproot > > GenerateSilentPaymentsTaprootDestinations(const std::map< size_t, SilentPaymentsDestination > &sp_dests, const std::vector< CKey > &plain_keys, const std::vector< KeyPair > &taproot_keys, const COutPoint &smallest_outpoint)
Generate silent payments taproot destinations.
CKey ParseHexToCKey(std::string_view hex)
util::Expected< SilentPaymentsDestination, std::string > DecodeSilentPaymentsAddress(const std::string &str, const CChainParams ¶ms)
Decode a BIP352 "sp1..." address. Returns the destination, or an error message on failure.
BOOST_AUTO_TEST_CASE(bip352_send_and_receive_test_vectors)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
constexpr script_verify_flags MANDATORY_SCRIPT_VERIFY_FLAGS
Mandatory script verification flags that all new transactions must comply with for them to be valid.
std::vector< unsigned char > ToByteVector(const T &in)
std::string ScriptErrorString(const ScriptError serror)
enum ScriptError_t ScriptError
static unsigned char smallest_outpoint[36]
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
A mutable version of CTransaction.
std::vector< std::vector< unsigned char > > stack
CTxDestination subtype to encode any future Witness version.
static std::optional< SilentPaymentsDestination > From(const CPubKey &scan_pubkey, const CPubKey &spend_pubkey, uint8_t version=0, std::span< const unsigned char > extension_data={})
std::vector< uint16_t > keys
constexpr std::array tests
std::string ToUpper(std::string_view str)
Returns the uppercase equivalent of the given string.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.