15#include <validation.h>
19#include <boost/test/unit_test.hpp>
35 std::vector<unsigned char> sSerialized(
s.begin(),
s.end());
43 txFrom.
vout.resize(1);
44 txFrom.
vout[0].scriptPubKey = scriptPubKey;
49 txTo.
vin[0].prevout.n = 0;
51 txTo.
vin[0].scriptSig = scriptSig;
52 txTo.
vout[0].nValue = 1;
69 for (
int i = 0; i < 4; i++)
83 for (
int i = 0; i < 4; i++)
91 txFrom.
vout.resize(8);
92 for (
int i = 0; i < 4; i++)
94 txFrom.
vout[i].scriptPubKey = evalScripts[i];
96 txFrom.
vout[i+4].scriptPubKey = standardScripts[i];
102 for (
int i = 0; i < 8; i++)
104 txTo[i].
vin.resize(1);
105 txTo[i].
vout.resize(1);
106 txTo[i].
vin[0].prevout.n = i;
107 txTo[i].
vin[0].prevout.hash = txFrom.
GetHash();
108 txTo[i].
vout[0].nValue = 1;
110 for (
int i = 0; i < 8; i++)
118 for (
int i = 0; i < 8; i++) {
120 for (
int j = 0; j < 8; j++)
123 txTo[i].
vin[0].scriptSig = txTo[j].
vin[0].scriptSig;
126 BOOST_CHECK_MESSAGE(sigOK,
strprintf(
"VerifySignature %d %d", i, j));
128 BOOST_CHECK_MESSAGE(!sigOK,
strprintf(
"VerifySignature %d %d", i, j));
129 txTo[i].
vin[0].scriptSig = sigSave;
166 std::vector<CPubKey>
keys;
168 for (
int i = 0; i < 4; i++)
182 for (
int i = 0; i < 4; i++)
190 txFrom.
vout.resize(4);
191 for (
int i = 0; i < 4; i++)
193 txFrom.
vout[i].scriptPubKey = outer[i];
199 for (
int i = 0; i < 4; i++)
201 txTo[i].
vin.resize(1);
202 txTo[i].
vout.resize(1);
203 txTo[i].
vin[0].prevout.n = i;
204 txTo[i].
vin[0].prevout.hash = txFrom.
GetHash();
206 txTo[i].
vout[0].scriptPubKey = inner[i];
208 for (
int i = 0; i < 4; i++)
214 BOOST_CHECK_MESSAGE((i == 0 ? no_pbms_is_std : !no_pbms_is_std),
strprintf(
"txTo[%d].IsStandard(permbaremulti=false)", i));
226 std::vector<unsigned char> direct = {
OP_HASH160, 20};
227 direct.insert(direct.end(), 20, 0);
233 pushdata1.insert(pushdata1.end(), 20, 0);
237 pushdata2.insert(pushdata2.end(), 20, 0);
241 pushdata4.insert(pushdata4.end(), 20, 0);
283 for (
int i = 0; i < 6; i++)
288 std::vector<CPubKey>
keys;
290 for (
int i = 0; i < 3; i++)
294 txFrom.
vout.resize(10);
302 txFrom.
vout[0].nValue = 1000;
303 txFrom.
vout[1].scriptPubKey = pay1;
304 txFrom.
vout[1].nValue = 2000;
305 txFrom.
vout[2].scriptPubKey = pay1of3;
306 txFrom.
vout[2].nValue = 3000;
317 txFrom.
vout[3].nValue = 4000;
326 txFrom.
vout[4].nValue = 5000;
332 txFrom.
vout[5].nValue = 5000;
336 txFrom.
vout[6].nValue = 3000;
340 txFrom.
vout[7].scriptPubKey = no_sigops;
341 txFrom.
vout[7].nValue = 1000;
344 static const unsigned char op_return[] = {
OP_RETURN};
345 const auto op_return_script =
CScript(op_return, op_return +
sizeof(op_return));
347 txFrom.
vout[8].nValue = 1000;
352 txFrom.
vout[9].scriptPubKey = witnessUnknown;
353 txFrom.
vout[9].nValue = 1000;
363 for (
int i = 0; i < 5; i++)
365 txTo.
vin[i].prevout.n = i;
377 txTo.
vin[3].scriptSig << OP_11 << OP_11 << std::vector<unsigned char>(oneAndTwo.
begin(), oneAndTwo.
end());
378 txTo.
vin[4].scriptSig << std::vector<unsigned char>(fifteenSigops.
begin(), fifteenSigops.
end());
387 coinbase_tx_mut.
vin.resize(1);
396 txToNonStd1.
vout.resize(1);
398 txToNonStd1.
vout[0].nValue = 1000;
399 txToNonStd1.
vin.resize(1);
400 txToNonStd1.
vin[0].prevout.n = 5;
401 txToNonStd1.
vin[0].prevout.hash = txFrom.
GetHash();
402 txToNonStd1.
vin[0].scriptSig << std::vector<unsigned char>(sixteenSigops.
begin(), sixteenSigops.
end());
406 BOOST_CHECK_EQUAL(txToNonStd1_res.GetRejectReason(),
"bad-txns-nonstandard-inputs");
407 BOOST_CHECK_EQUAL(txToNonStd1_res.GetDebugMessage(),
"p2sh redeemscript sigops exceed limit (input 0: 16 > 15)");
414 txToNonStd2.
vout.resize(1);
416 txToNonStd2.
vout[0].nValue = 1000;
417 txToNonStd2.
vin.resize(1);
418 txToNonStd2.
vin[0].prevout.n = 6;
419 txToNonStd2.
vin[0].prevout.hash = txFrom.
GetHash();
420 txToNonStd2.
vin[0].scriptSig << std::vector<unsigned char>(twentySigops.
begin(), twentySigops.
end());
424 BOOST_CHECK_EQUAL(txToNonStd2_res.GetRejectReason(),
"bad-txns-nonstandard-inputs");
425 BOOST_CHECK_EQUAL(txToNonStd2_res.GetDebugMessage(),
"p2sh redeemscript sigops exceed limit (input 0: 20 > 15)");
431 txToNonStd2_no_scriptSig.
vout.resize(1);
433 txToNonStd2_no_scriptSig.
vout[0].nValue = 1000;
434 txToNonStd2_no_scriptSig.
vin.resize(1);
435 txToNonStd2_no_scriptSig.
vin[0].prevout.n = 6;
436 txToNonStd2_no_scriptSig.
vin[0].prevout.hash = txFrom.
GetHash();
439 BOOST_CHECK(txToNonStd2_no_scriptSig_res.IsInvalid());
440 BOOST_CHECK_EQUAL(txToNonStd2_no_scriptSig_res.GetRejectReason(),
"bad-txns-nonstandard-inputs");
441 BOOST_CHECK_EQUAL(txToNonStd2_no_scriptSig_res.GetDebugMessage(),
"input 0 P2SH redeemscript missing");
448 txToNonStd3.
vout.resize(1);
450 txToNonStd3.
vout[0].nValue = 1000;
451 txToNonStd3.
vin.resize(1);
452 txToNonStd3.
vin[0].prevout.n = 7;
453 txToNonStd3.
vin[0].prevout.hash = txFrom.
GetHash();
457 BOOST_CHECK_EQUAL(txToNonStd3_res.GetRejectReason(),
"bad-txns-nonstandard-inputs");
464 txToNonStd4.
vout.resize(1);
466 txToNonStd4.
vout[0].nValue = 1000;
467 txToNonStd4.
vin.resize(1);
468 txToNonStd4.
vin[0].prevout.n = 8;
469 txToNonStd4.
vin[0].prevout.hash = txFrom.
GetHash();
470 txToNonStd4.
vin[0].scriptSig = op_return_script;
474 BOOST_CHECK_EQUAL(txToNonStd4_res.GetRejectReason(),
"bad-txns-nonstandard-inputs");
475 BOOST_CHECK_EQUAL(txToNonStd4_res.GetDebugMessage(),
"p2sh scriptsig malformed (input 0: OP_RETURN was encountered)");
481 txWitnessUnknown.
vout.resize(1);
483 txWitnessUnknown.
vout[0].nValue = 1000;
484 txWitnessUnknown.
vin.resize(1);
485 txWitnessUnknown.
vin[0].prevout.n = 9;
486 txWitnessUnknown.
vin[0].prevout.hash = txFrom.
GetHash();
489 BOOST_CHECK_EQUAL(txWitnessUnknown_res.GetRejectReason(),
"bad-txns-nonstandard-inputs");
490 BOOST_CHECK_EQUAL(txWitnessUnknown_res.GetDebugMessage(),
"input 0 witness program is undefined");
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
static constexpr CAmount COIN
The amount of satoshis in one BTC.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
An encapsulated private key.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
CPubKey GetPubKey() const
Compute the public key from a private key.
Closure representing one script verification Note that this stores references to the spending transac...
Serialized script, used inside transaction inputs and outputs.
bool IsPayToScriptHash() const
The basic transaction that is broadcasted on the network and contained in blocks.
static CoinsViewEmpty & Get()
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddCScript(const CScript &redeemScript)
virtual bool AddKey(const CKey &key)
Valid signature cache, to avoid doing expensive ECDSA signature checking twice for every transaction ...
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check_for_overwrite)
Utility function to add all of a transaction's outputs to a cache.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(headers.FindFirst("key"), "value")
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, script_verify_flags flags, const BaseSignatureChecker &checker, ScriptError *serror)
GenericTransactionSignatureChecker< CMutableTransaction > MutableTransactionSignatureChecker
@ ASSERT_FAIL
Abort execution through assertion failure (for consensus code)
@ SCRIPT_VERIFY_STRICTENC
static constexpr script_verify_flags SCRIPT_VERIFY_NONE
Script verification flags.
static int sign(const secp256k1_context *ctx, struct signer_secrets *signer_secrets, struct signer *signer, const secp256k1_musig_keyagg_cache *cache, const unsigned char *msg32, unsigned char *sig64)
#define BOOST_CHECK(expr)
TxValidationState ValidateInputsStandardness(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check transaction inputs.
static constexpr unsigned int DUST_RELAY_TX_FEE
Min feerate for defining dust.
static constexpr unsigned int MAX_P2SH_SIGOPS
Maximum number of signature check operations in an IsStandard() P2SH script.
std::vector< unsigned char > ToByteVector(const T &in)
std::string ScriptErrorString(const ScriptError serror)
enum ScriptError_t ScriptError
static bool Verify(const CScript &scriptSig, const CScript &scriptPubKey, bool fStrict, ScriptError &err)
BOOST_AUTO_TEST_CASE(sign)
static std::vector< unsigned char > Serialize(const CScript &s)
static bool IsStandardTx(const CTransaction &tx, bool permit_bare_multisig, std::string &reason)
static constexpr CAmount CENT
static constexpr size_t DEFAULT_SIGNATURE_CACHE_BYTES
static bool GetPubKey(const SigningProvider &provider, const SignatureData &sigdata, const CKeyID &address, CPubKey &pubkey)
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
A mutable version of CTransaction.
std::vector< CTxOut > vout
Txid GetHash() const
Compute the hash of this CMutableTransaction.
std::vector< uint16_t > keys
bool SignSignature(const SigningProvider &provider, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const CAmount &amount, int nHashType, SignatureData &sig_data)
Produce a satisfying script (scriptSig or witness).
unsigned int GetP2SHSigOpCount(const CTransaction &tx, const CCoinsViewCache &inputs)
Count ECDSA signature operations in pay-to-script-hash inputs.