mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +01:00
script: add ToByteVector() for converting anything with begin/end
This should move to a util header once their dependencies are cleaned up.
This commit is contained in:
parent
066e2a1403
commit
e9ca4280f3
@ -398,7 +398,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
|||||||
if (!reservekey.GetReservedKey(pubkey))
|
if (!reservekey.GetReservedKey(pubkey))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
CScript scriptPubKey = CScript() << pubkey << OP_CHECKSIG;
|
CScript scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
|
||||||
return CreateNewBlock(scriptPubKey);
|
return CreateNewBlock(scriptPubKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,12 @@
|
|||||||
|
|
||||||
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // bytes
|
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // bytes
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::vector<unsigned char> ToByteVector(const T& in)
|
||||||
|
{
|
||||||
|
return std::vector<unsigned char>(in.begin(), in.end());
|
||||||
|
}
|
||||||
|
|
||||||
/** Script opcodes */
|
/** Script opcodes */
|
||||||
enum opcodetype
|
enum opcodetype
|
||||||
{
|
{
|
||||||
@ -358,7 +364,6 @@ public:
|
|||||||
CScript(int64_t b) { operator<<(b); }
|
CScript(int64_t b) { operator<<(b); }
|
||||||
|
|
||||||
explicit CScript(opcodetype b) { operator<<(b); }
|
explicit CScript(opcodetype b) { operator<<(b); }
|
||||||
explicit CScript(const uint256& b) { operator<<(b); }
|
|
||||||
explicit CScript(const CScriptNum& b) { operator<<(b); }
|
explicit CScript(const CScriptNum& b) { operator<<(b); }
|
||||||
explicit CScript(const std::vector<unsigned char>& b) { operator<<(b); }
|
explicit CScript(const std::vector<unsigned char>& b) { operator<<(b); }
|
||||||
|
|
||||||
@ -373,28 +378,6 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CScript& operator<<(const uint160& b)
|
|
||||||
{
|
|
||||||
insert(end(), sizeof(b));
|
|
||||||
insert(end(), (unsigned char*)&b, (unsigned char*)&b + sizeof(b));
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
CScript& operator<<(const uint256& b)
|
|
||||||
{
|
|
||||||
insert(end(), sizeof(b));
|
|
||||||
insert(end(), (unsigned char*)&b, (unsigned char*)&b + sizeof(b));
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
CScript& operator<<(const CPubKey& key)
|
|
||||||
{
|
|
||||||
assert(key.size() < OP_PUSHDATA1);
|
|
||||||
insert(end(), (unsigned char)key.size());
|
|
||||||
insert(end(), key.begin(), key.end());
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
CScript& operator<<(const CScriptNum& b)
|
CScript& operator<<(const CScriptNum& b)
|
||||||
{
|
{
|
||||||
*this << b.getvch();
|
*this << b.getvch();
|
||||||
|
@ -78,7 +78,7 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
|
|||||||
{
|
{
|
||||||
CPubKey vch;
|
CPubKey vch;
|
||||||
keystore.GetPubKey(keyID, vch);
|
keystore.GetPubKey(keyID, vch);
|
||||||
scriptSigRet << vch;
|
scriptSigRet << ToByteVector(vch);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case TX_SCRIPTHASH:
|
case TX_SCRIPTHASH:
|
||||||
|
@ -282,13 +282,13 @@ public:
|
|||||||
|
|
||||||
bool operator()(const CKeyID &keyID) const {
|
bool operator()(const CKeyID &keyID) const {
|
||||||
script->clear();
|
script->clear();
|
||||||
*script << OP_DUP << OP_HASH160 << keyID << OP_EQUALVERIFY << OP_CHECKSIG;
|
*script << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator()(const CScriptID &scriptID) const {
|
bool operator()(const CScriptID &scriptID) const {
|
||||||
script->clear();
|
script->clear();
|
||||||
*script << OP_HASH160 << scriptID << OP_EQUAL;
|
*script << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -308,7 +308,7 @@ CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys)
|
|||||||
|
|
||||||
script << CScript::EncodeOP_N(nRequired);
|
script << CScript::EncodeOP_N(nRequired);
|
||||||
BOOST_FOREACH(const CPubKey& key, keys)
|
BOOST_FOREACH(const CPubKey& key, keys)
|
||||||
script << key;
|
script << ToByteVector(key);
|
||||||
script << CScript::EncodeOP_N(keys.size()) << OP_CHECKMULTISIG;
|
script << CScript::EncodeOP_N(keys.size()) << OP_CHECKMULTISIG;
|
||||||
return script;
|
return script;
|
||||||
}
|
}
|
||||||
|
@ -51,13 +51,13 @@ BOOST_AUTO_TEST_CASE(multisig_verify)
|
|||||||
key[i].MakeNewKey(true);
|
key[i].MakeNewKey(true);
|
||||||
|
|
||||||
CScript a_and_b;
|
CScript a_and_b;
|
||||||
a_and_b << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
a_and_b << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
||||||
|
|
||||||
CScript a_or_b;
|
CScript a_or_b;
|
||||||
a_or_b << OP_1 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
a_or_b << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
||||||
|
|
||||||
CScript escrow;
|
CScript escrow;
|
||||||
escrow << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << key[2].GetPubKey() << OP_3 << OP_CHECKMULTISIG;
|
escrow << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
|
||||||
|
|
||||||
CMutableTransaction txFrom; // Funding transaction
|
CMutableTransaction txFrom; // Funding transaction
|
||||||
txFrom.vout.resize(3);
|
txFrom.vout.resize(3);
|
||||||
@ -138,28 +138,28 @@ BOOST_AUTO_TEST_CASE(multisig_IsStandard)
|
|||||||
txnouttype whichType;
|
txnouttype whichType;
|
||||||
|
|
||||||
CScript a_and_b;
|
CScript a_and_b;
|
||||||
a_and_b << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
a_and_b << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
||||||
BOOST_CHECK(::IsStandard(a_and_b, whichType));
|
BOOST_CHECK(::IsStandard(a_and_b, whichType));
|
||||||
|
|
||||||
CScript a_or_b;
|
CScript a_or_b;
|
||||||
a_or_b << OP_1 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
a_or_b << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
||||||
BOOST_CHECK(::IsStandard(a_or_b, whichType));
|
BOOST_CHECK(::IsStandard(a_or_b, whichType));
|
||||||
|
|
||||||
CScript escrow;
|
CScript escrow;
|
||||||
escrow << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << key[2].GetPubKey() << OP_3 << OP_CHECKMULTISIG;
|
escrow << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
|
||||||
BOOST_CHECK(::IsStandard(escrow, whichType));
|
BOOST_CHECK(::IsStandard(escrow, whichType));
|
||||||
|
|
||||||
CScript one_of_four;
|
CScript one_of_four;
|
||||||
one_of_four << OP_1 << key[0].GetPubKey() << key[1].GetPubKey() << key[2].GetPubKey() << key[3].GetPubKey() << OP_4 << OP_CHECKMULTISIG;
|
one_of_four << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << ToByteVector(key[3].GetPubKey()) << OP_4 << OP_CHECKMULTISIG;
|
||||||
BOOST_CHECK(!::IsStandard(one_of_four, whichType));
|
BOOST_CHECK(!::IsStandard(one_of_four, whichType));
|
||||||
|
|
||||||
CScript malformed[6];
|
CScript malformed[6];
|
||||||
malformed[0] << OP_3 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
malformed[0] << OP_3 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
||||||
malformed[1] << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << OP_3 << OP_CHECKMULTISIG;
|
malformed[1] << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
|
||||||
malformed[2] << OP_0 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
malformed[2] << OP_0 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
||||||
malformed[3] << OP_1 << key[0].GetPubKey() << key[1].GetPubKey() << OP_0 << OP_CHECKMULTISIG;
|
malformed[3] << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_0 << OP_CHECKMULTISIG;
|
||||||
malformed[4] << OP_1 << key[0].GetPubKey() << key[1].GetPubKey() << OP_CHECKMULTISIG;
|
malformed[4] << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_CHECKMULTISIG;
|
||||||
malformed[5] << OP_1 << key[0].GetPubKey() << key[1].GetPubKey();
|
malformed[5] << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey());
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
BOOST_CHECK(!::IsStandard(malformed[i], whichType));
|
BOOST_CHECK(!::IsStandard(malformed[i], whichType));
|
||||||
@ -192,7 +192,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1)
|
|||||||
vector<valtype> solutions;
|
vector<valtype> solutions;
|
||||||
txnouttype whichType;
|
txnouttype whichType;
|
||||||
CScript s;
|
CScript s;
|
||||||
s << key[0].GetPubKey() << OP_CHECKSIG;
|
s << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG;
|
||||||
BOOST_CHECK(Solver(s, whichType, solutions));
|
BOOST_CHECK(Solver(s, whichType, solutions));
|
||||||
BOOST_CHECK(solutions.size() == 1);
|
BOOST_CHECK(solutions.size() == 1);
|
||||||
CTxDestination addr;
|
CTxDestination addr;
|
||||||
@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1)
|
|||||||
vector<valtype> solutions;
|
vector<valtype> solutions;
|
||||||
txnouttype whichType;
|
txnouttype whichType;
|
||||||
CScript s;
|
CScript s;
|
||||||
s << OP_DUP << OP_HASH160 << key[0].GetPubKey().GetID() << OP_EQUALVERIFY << OP_CHECKSIG;
|
s << OP_DUP << OP_HASH160 << ToByteVector(key[0].GetPubKey().GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||||
BOOST_CHECK(Solver(s, whichType, solutions));
|
BOOST_CHECK(Solver(s, whichType, solutions));
|
||||||
BOOST_CHECK(solutions.size() == 1);
|
BOOST_CHECK(solutions.size() == 1);
|
||||||
CTxDestination addr;
|
CTxDestination addr;
|
||||||
@ -222,7 +222,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1)
|
|||||||
vector<valtype> solutions;
|
vector<valtype> solutions;
|
||||||
txnouttype whichType;
|
txnouttype whichType;
|
||||||
CScript s;
|
CScript s;
|
||||||
s << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
s << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
||||||
BOOST_CHECK(Solver(s, whichType, solutions));
|
BOOST_CHECK(Solver(s, whichType, solutions));
|
||||||
BOOST_CHECK_EQUAL(solutions.size(), 4U);
|
BOOST_CHECK_EQUAL(solutions.size(), 4U);
|
||||||
CTxDestination addr;
|
CTxDestination addr;
|
||||||
@ -237,7 +237,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1)
|
|||||||
vector<valtype> solutions;
|
vector<valtype> solutions;
|
||||||
txnouttype whichType;
|
txnouttype whichType;
|
||||||
CScript s;
|
CScript s;
|
||||||
s << OP_1 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
s << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
||||||
BOOST_CHECK(Solver(s, whichType, solutions));
|
BOOST_CHECK(Solver(s, whichType, solutions));
|
||||||
BOOST_CHECK_EQUAL(solutions.size(), 4U);
|
BOOST_CHECK_EQUAL(solutions.size(), 4U);
|
||||||
vector<CTxDestination> addrs;
|
vector<CTxDestination> addrs;
|
||||||
@ -256,7 +256,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1)
|
|||||||
vector<valtype> solutions;
|
vector<valtype> solutions;
|
||||||
txnouttype whichType;
|
txnouttype whichType;
|
||||||
CScript s;
|
CScript s;
|
||||||
s << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << key[2].GetPubKey() << OP_3 << OP_CHECKMULTISIG;
|
s << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
|
||||||
BOOST_CHECK(Solver(s, whichType, solutions));
|
BOOST_CHECK(Solver(s, whichType, solutions));
|
||||||
BOOST_CHECK(solutions.size() == 5);
|
BOOST_CHECK(solutions.size() == 5);
|
||||||
}
|
}
|
||||||
@ -274,13 +274,13 @@ BOOST_AUTO_TEST_CASE(multisig_Sign)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CScript a_and_b;
|
CScript a_and_b;
|
||||||
a_and_b << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
a_and_b << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
||||||
|
|
||||||
CScript a_or_b;
|
CScript a_or_b;
|
||||||
a_or_b << OP_1 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
a_or_b << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
||||||
|
|
||||||
CScript escrow;
|
CScript escrow;
|
||||||
escrow << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << key[2].GetPubKey() << OP_3 << OP_CHECKMULTISIG;
|
escrow << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
|
||||||
|
|
||||||
CMutableTransaction txFrom; // Funding transaction
|
CMutableTransaction txFrom; // Funding transaction
|
||||||
txFrom.vout.resize(3);
|
txFrom.vout.resize(3);
|
||||||
|
@ -67,9 +67,9 @@ BOOST_AUTO_TEST_CASE(sign)
|
|||||||
// 8 Scripts: checking all combinations of
|
// 8 Scripts: checking all combinations of
|
||||||
// different keys, straight/P2SH, pubkey/pubkeyhash
|
// different keys, straight/P2SH, pubkey/pubkeyhash
|
||||||
CScript standardScripts[4];
|
CScript standardScripts[4];
|
||||||
standardScripts[0] << key[0].GetPubKey() << OP_CHECKSIG;
|
standardScripts[0] << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG;
|
||||||
standardScripts[1] = GetScriptForDestination(key[1].GetPubKey().GetID());
|
standardScripts[1] = GetScriptForDestination(key[1].GetPubKey().GetID());
|
||||||
standardScripts[2] << key[1].GetPubKey() << OP_CHECKSIG;
|
standardScripts[2] << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG;
|
||||||
standardScripts[3] = GetScriptForDestination(key[2].GetPubKey().GetID());
|
standardScripts[3] = GetScriptForDestination(key[2].GetPubKey().GetID());
|
||||||
CScript evalScripts[4];
|
CScript evalScripts[4];
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
@ -206,9 +206,9 @@ BOOST_AUTO_TEST_CASE(set)
|
|||||||
BOOST_AUTO_TEST_CASE(is)
|
BOOST_AUTO_TEST_CASE(is)
|
||||||
{
|
{
|
||||||
// Test CScript::IsPayToScriptHash()
|
// Test CScript::IsPayToScriptHash()
|
||||||
uint160 dummy;
|
uint160 dummy(0);
|
||||||
CScript p2sh;
|
CScript p2sh;
|
||||||
p2sh << OP_HASH160 << dummy << OP_EQUAL;
|
p2sh << OP_HASH160 << ToByteVector(dummy) << OP_EQUAL;
|
||||||
BOOST_CHECK(p2sh.IsPayToScriptHash());
|
BOOST_CHECK(p2sh.IsPayToScriptHash());
|
||||||
|
|
||||||
// Not considered pay-to-script-hash if using one of the OP_PUSHDATA opcodes:
|
// Not considered pay-to-script-hash if using one of the OP_PUSHDATA opcodes:
|
||||||
@ -224,13 +224,13 @@ BOOST_AUTO_TEST_CASE(is)
|
|||||||
CScript not_p2sh;
|
CScript not_p2sh;
|
||||||
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());
|
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());
|
||||||
|
|
||||||
not_p2sh.clear(); not_p2sh << OP_HASH160 << dummy << dummy << OP_EQUAL;
|
not_p2sh.clear(); not_p2sh << OP_HASH160 << ToByteVector(dummy) << ToByteVector(dummy) << OP_EQUAL;
|
||||||
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());
|
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());
|
||||||
|
|
||||||
not_p2sh.clear(); not_p2sh << OP_NOP << dummy << OP_EQUAL;
|
not_p2sh.clear(); not_p2sh << OP_NOP << ToByteVector(dummy) << OP_EQUAL;
|
||||||
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());
|
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());
|
||||||
|
|
||||||
not_p2sh.clear(); not_p2sh << OP_HASH160 << dummy << OP_CHECKSIG;
|
not_p2sh.clear(); not_p2sh << OP_HASH160 << ToByteVector(dummy) << OP_CHECKSIG;
|
||||||
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());
|
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,9 +285,9 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
|
|||||||
// vout[3] is complicated 1-of-3 AND 2-of-3
|
// vout[3] is complicated 1-of-3 AND 2-of-3
|
||||||
// ... that is OK if wrapped in P2SH:
|
// ... that is OK if wrapped in P2SH:
|
||||||
CScript oneAndTwo;
|
CScript oneAndTwo;
|
||||||
oneAndTwo << OP_1 << key[0].GetPubKey() << key[1].GetPubKey() << key[2].GetPubKey();
|
oneAndTwo << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey());
|
||||||
oneAndTwo << OP_3 << OP_CHECKMULTISIGVERIFY;
|
oneAndTwo << OP_3 << OP_CHECKMULTISIGVERIFY;
|
||||||
oneAndTwo << OP_2 << key[3].GetPubKey() << key[4].GetPubKey() << key[5].GetPubKey();
|
oneAndTwo << OP_2 << ToByteVector(key[3].GetPubKey()) << ToByteVector(key[4].GetPubKey()) << ToByteVector(key[5].GetPubKey());
|
||||||
oneAndTwo << OP_3 << OP_CHECKMULTISIG;
|
oneAndTwo << OP_3 << OP_CHECKMULTISIG;
|
||||||
keystore.AddCScript(oneAndTwo);
|
keystore.AddCScript(oneAndTwo);
|
||||||
txFrom.vout[3].scriptPubKey = GetScriptForDestination(CScriptID(oneAndTwo));
|
txFrom.vout[3].scriptPubKey = GetScriptForDestination(CScriptID(oneAndTwo));
|
||||||
@ -296,7 +296,7 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
|
|||||||
// vout[4] is max sigops:
|
// vout[4] is max sigops:
|
||||||
CScript fifteenSigops; fifteenSigops << OP_1;
|
CScript fifteenSigops; fifteenSigops << OP_1;
|
||||||
for (unsigned i = 0; i < MAX_P2SH_SIGOPS; i++)
|
for (unsigned i = 0; i < MAX_P2SH_SIGOPS; i++)
|
||||||
fifteenSigops << key[i%3].GetPubKey();
|
fifteenSigops << ToByteVector(key[i%3].GetPubKey());
|
||||||
fifteenSigops << OP_15 << OP_CHECKMULTISIG;
|
fifteenSigops << OP_15 << OP_CHECKMULTISIG;
|
||||||
keystore.AddCScript(fifteenSigops);
|
keystore.AddCScript(fifteenSigops);
|
||||||
txFrom.vout[4].scriptPubKey = GetScriptForDestination(CScriptID(fifteenSigops));
|
txFrom.vout[4].scriptPubKey = GetScriptForDestination(CScriptID(fifteenSigops));
|
||||||
|
@ -162,7 +162,7 @@ public:
|
|||||||
TestBuilder(const CScript& redeemScript, const std::string& comment_, int flags_, bool P2SH = false) : scriptPubKey(redeemScript), havePush(false), comment(comment_), flags(flags_)
|
TestBuilder(const CScript& redeemScript, const std::string& comment_, int flags_, bool P2SH = false) : scriptPubKey(redeemScript), havePush(false), comment(comment_), flags(flags_)
|
||||||
{
|
{
|
||||||
if (P2SH) {
|
if (P2SH) {
|
||||||
creditTx = BuildCreditingTransaction(CScript() << OP_HASH160 << CScriptID(redeemScript) << OP_EQUAL);
|
creditTx = BuildCreditingTransaction(CScript() << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL);
|
||||||
} else {
|
} else {
|
||||||
creditTx = BuildCreditingTransaction(redeemScript);
|
creditTx = BuildCreditingTransaction(redeemScript);
|
||||||
}
|
}
|
||||||
@ -270,135 +270,135 @@ BOOST_AUTO_TEST_CASE(script_build)
|
|||||||
std::vector<TestBuilder> good;
|
std::vector<TestBuilder> good;
|
||||||
std::vector<TestBuilder> bad;
|
std::vector<TestBuilder> bad;
|
||||||
|
|
||||||
good.push_back(TestBuilder(CScript() << keys.pubkey0 << OP_CHECKSIG,
|
good.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0) << OP_CHECKSIG,
|
||||||
"P2PK", 0
|
"P2PK", 0
|
||||||
).PushSig(keys.key0));
|
).PushSig(keys.key0));
|
||||||
bad.push_back(TestBuilder(CScript() << keys.pubkey0 << OP_CHECKSIG,
|
bad.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0) << OP_CHECKSIG,
|
||||||
"P2PK, bad sig", 0
|
"P2PK, bad sig", 0
|
||||||
).PushSig(keys.key0).DamagePush(10));
|
).PushSig(keys.key0).DamagePush(10));
|
||||||
|
|
||||||
good.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << keys.pubkey1C.GetID() << OP_EQUALVERIFY << OP_CHECKSIG,
|
good.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey1C.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
|
||||||
"P2PKH", 0
|
"P2PKH", 0
|
||||||
).PushSig(keys.key1).Push(keys.pubkey1C));
|
).PushSig(keys.key1).Push(keys.pubkey1C));
|
||||||
bad.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << keys.pubkey2C.GetID() << OP_EQUALVERIFY << OP_CHECKSIG,
|
bad.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey2C.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
|
||||||
"P2PKH, bad pubkey", 0
|
"P2PKH, bad pubkey", 0
|
||||||
).PushSig(keys.key2).Push(keys.pubkey2C).DamagePush(5));
|
).PushSig(keys.key2).Push(keys.pubkey2C).DamagePush(5));
|
||||||
|
|
||||||
good.push_back(TestBuilder(CScript() << keys.pubkey1 << OP_CHECKSIG,
|
good.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1) << OP_CHECKSIG,
|
||||||
"P2PK anyonecanpay", 0
|
"P2PK anyonecanpay", 0
|
||||||
).PushSig(keys.key1, SIGHASH_ALL | SIGHASH_ANYONECANPAY));
|
).PushSig(keys.key1, SIGHASH_ALL | SIGHASH_ANYONECANPAY));
|
||||||
bad.push_back(TestBuilder(CScript() << keys.pubkey1 << OP_CHECKSIG,
|
bad.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1) << OP_CHECKSIG,
|
||||||
"P2PK anyonecanpay marked with normal hashtype", 0
|
"P2PK anyonecanpay marked with normal hashtype", 0
|
||||||
).PushSig(keys.key1, SIGHASH_ALL | SIGHASH_ANYONECANPAY).EditPush(70, "81", "01"));
|
).PushSig(keys.key1, SIGHASH_ALL | SIGHASH_ANYONECANPAY).EditPush(70, "81", "01"));
|
||||||
|
|
||||||
good.push_back(TestBuilder(CScript() << keys.pubkey0C << OP_CHECKSIG,
|
good.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0C) << OP_CHECKSIG,
|
||||||
"P2SH(P2PK)", SCRIPT_VERIFY_P2SH, true
|
"P2SH(P2PK)", SCRIPT_VERIFY_P2SH, true
|
||||||
).PushSig(keys.key0).PushRedeem());
|
).PushSig(keys.key0).PushRedeem());
|
||||||
bad.push_back(TestBuilder(CScript() << keys.pubkey0C << OP_CHECKSIG,
|
bad.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0C) << OP_CHECKSIG,
|
||||||
"P2SH(P2PK), bad redeemscript", SCRIPT_VERIFY_P2SH, true
|
"P2SH(P2PK), bad redeemscript", SCRIPT_VERIFY_P2SH, true
|
||||||
).PushSig(keys.key0).PushRedeem().DamagePush(10));
|
).PushSig(keys.key0).PushRedeem().DamagePush(10));
|
||||||
|
|
||||||
good.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << keys.pubkey1.GetID() << OP_EQUALVERIFY << OP_CHECKSIG,
|
good.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey1.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
|
||||||
"P2SH(P2PKH), bad sig but no VERIFY_P2SH", 0, true
|
"P2SH(P2PKH), bad sig but no VERIFY_P2SH", 0, true
|
||||||
).PushSig(keys.key0).DamagePush(10).PushRedeem());
|
).PushSig(keys.key0).DamagePush(10).PushRedeem());
|
||||||
bad.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << keys.pubkey1.GetID() << OP_EQUALVERIFY << OP_CHECKSIG,
|
bad.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey1.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
|
||||||
"P2SH(P2PKH), bad sig", SCRIPT_VERIFY_P2SH, true
|
"P2SH(P2PKH), bad sig", SCRIPT_VERIFY_P2SH, true
|
||||||
).PushSig(keys.key0).DamagePush(10).PushRedeem());
|
).PushSig(keys.key0).DamagePush(10).PushRedeem());
|
||||||
|
|
||||||
good.push_back(TestBuilder(CScript() << OP_3 << keys.pubkey0C << keys.pubkey1C << keys.pubkey2C << OP_3 << OP_CHECKMULTISIG,
|
good.push_back(TestBuilder(CScript() << OP_3 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG,
|
||||||
"3-of-3", 0
|
"3-of-3", 0
|
||||||
).Num(0).PushSig(keys.key0).PushSig(keys.key1).PushSig(keys.key2));
|
).Num(0).PushSig(keys.key0).PushSig(keys.key1).PushSig(keys.key2));
|
||||||
bad.push_back(TestBuilder(CScript() << OP_3 << keys.pubkey0C << keys.pubkey1C << keys.pubkey2C << OP_3 << OP_CHECKMULTISIG,
|
bad.push_back(TestBuilder(CScript() << OP_3 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG,
|
||||||
"3-of-3, 2 sigs", 0
|
"3-of-3, 2 sigs", 0
|
||||||
).Num(0).PushSig(keys.key0).PushSig(keys.key1).Num(0));
|
).Num(0).PushSig(keys.key0).PushSig(keys.key1).Num(0));
|
||||||
|
|
||||||
good.push_back(TestBuilder(CScript() << OP_2 << keys.pubkey0C << keys.pubkey1C << keys.pubkey2C << OP_3 << OP_CHECKMULTISIG,
|
good.push_back(TestBuilder(CScript() << OP_2 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG,
|
||||||
"P2SH(2-of-3)", SCRIPT_VERIFY_P2SH, true
|
"P2SH(2-of-3)", SCRIPT_VERIFY_P2SH, true
|
||||||
).Num(0).PushSig(keys.key1).PushSig(keys.key2).PushRedeem());
|
).Num(0).PushSig(keys.key1).PushSig(keys.key2).PushRedeem());
|
||||||
bad.push_back(TestBuilder(CScript() << OP_2 << keys.pubkey0C << keys.pubkey1C << keys.pubkey2C << OP_3 << OP_CHECKMULTISIG,
|
bad.push_back(TestBuilder(CScript() << OP_2 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG,
|
||||||
"P2SH(2-of-3), 1 sig", SCRIPT_VERIFY_P2SH, true
|
"P2SH(2-of-3), 1 sig", SCRIPT_VERIFY_P2SH, true
|
||||||
).Num(0).PushSig(keys.key1).Num(0).PushRedeem());
|
).Num(0).PushSig(keys.key1).Num(0).PushRedeem());
|
||||||
|
|
||||||
good.push_back(TestBuilder(CScript() << keys.pubkey1C << OP_CHECKSIG,
|
good.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1C) << OP_CHECKSIG,
|
||||||
"P2PK with too much R padding but no DERSIG", 0
|
"P2PK with too much R padding but no DERSIG", 0
|
||||||
).PushSig(keys.key1, SIGHASH_ALL, 31, 32).EditPush(1, "43021F", "44022000"));
|
).PushSig(keys.key1, SIGHASH_ALL, 31, 32).EditPush(1, "43021F", "44022000"));
|
||||||
bad.push_back(TestBuilder(CScript() << keys.pubkey1C << OP_CHECKSIG,
|
bad.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1C) << OP_CHECKSIG,
|
||||||
"P2PK with too much R padding", SCRIPT_VERIFY_DERSIG
|
"P2PK with too much R padding", SCRIPT_VERIFY_DERSIG
|
||||||
).PushSig(keys.key1, SIGHASH_ALL, 31, 32).EditPush(1, "43021F", "44022000"));
|
).PushSig(keys.key1, SIGHASH_ALL, 31, 32).EditPush(1, "43021F", "44022000"));
|
||||||
good.push_back(TestBuilder(CScript() << keys.pubkey1C << OP_CHECKSIG,
|
good.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1C) << OP_CHECKSIG,
|
||||||
"P2PK with too much S padding but no DERSIG", 0
|
"P2PK with too much S padding but no DERSIG", 0
|
||||||
).PushSig(keys.key1, SIGHASH_ALL).EditPush(1, "44", "45").EditPush(37, "20", "2100"));
|
).PushSig(keys.key1, SIGHASH_ALL).EditPush(1, "44", "45").EditPush(37, "20", "2100"));
|
||||||
bad.push_back(TestBuilder(CScript() << keys.pubkey1C << OP_CHECKSIG,
|
bad.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1C) << OP_CHECKSIG,
|
||||||
"P2PK with too much S padding", SCRIPT_VERIFY_DERSIG
|
"P2PK with too much S padding", SCRIPT_VERIFY_DERSIG
|
||||||
).PushSig(keys.key1, SIGHASH_ALL).EditPush(1, "44", "45").EditPush(37, "20", "2100"));
|
).PushSig(keys.key1, SIGHASH_ALL).EditPush(1, "44", "45").EditPush(37, "20", "2100"));
|
||||||
good.push_back(TestBuilder(CScript() << keys.pubkey1C << OP_CHECKSIG,
|
good.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1C) << OP_CHECKSIG,
|
||||||
"P2PK with too little R padding but no DERSIG", 0
|
"P2PK with too little R padding but no DERSIG", 0
|
||||||
).PushSig(keys.key1, SIGHASH_ALL, 33, 32).EditPush(1, "45022100", "440220"));
|
).PushSig(keys.key1, SIGHASH_ALL, 33, 32).EditPush(1, "45022100", "440220"));
|
||||||
bad.push_back(TestBuilder(CScript() << keys.pubkey1C << OP_CHECKSIG,
|
bad.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1C) << OP_CHECKSIG,
|
||||||
"P2PK with too little R padding", SCRIPT_VERIFY_DERSIG
|
"P2PK with too little R padding", SCRIPT_VERIFY_DERSIG
|
||||||
).PushSig(keys.key1, SIGHASH_ALL, 33, 32).EditPush(1, "45022100", "440220"));
|
).PushSig(keys.key1, SIGHASH_ALL, 33, 32).EditPush(1, "45022100", "440220"));
|
||||||
good.push_back(TestBuilder(CScript() << keys.pubkey2C << OP_CHECKSIG << OP_NOT,
|
good.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG << OP_NOT,
|
||||||
"P2PK NOT with bad sig with too much R padding but no DERSIG", 0
|
"P2PK NOT with bad sig with too much R padding but no DERSIG", 0
|
||||||
).PushSig(keys.key2, SIGHASH_ALL, 31, 32).EditPush(1, "43021F", "44022000").DamagePush(10));
|
).PushSig(keys.key2, SIGHASH_ALL, 31, 32).EditPush(1, "43021F", "44022000").DamagePush(10));
|
||||||
bad.push_back(TestBuilder(CScript() << keys.pubkey2C << OP_CHECKSIG << OP_NOT,
|
bad.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG << OP_NOT,
|
||||||
"P2PK NOT with bad sig with too much R padding", SCRIPT_VERIFY_DERSIG
|
"P2PK NOT with bad sig with too much R padding", SCRIPT_VERIFY_DERSIG
|
||||||
).PushSig(keys.key2, SIGHASH_ALL, 31, 32).EditPush(1, "43021F", "44022000").DamagePush(10));
|
).PushSig(keys.key2, SIGHASH_ALL, 31, 32).EditPush(1, "43021F", "44022000").DamagePush(10));
|
||||||
bad.push_back(TestBuilder(CScript() << keys.pubkey2C << OP_CHECKSIG << OP_NOT,
|
bad.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG << OP_NOT,
|
||||||
"P2PK NOT with too much R padding but no DERSIG", 0
|
"P2PK NOT with too much R padding but no DERSIG", 0
|
||||||
).PushSig(keys.key2, SIGHASH_ALL, 31, 32).EditPush(1, "43021F", "44022000"));
|
).PushSig(keys.key2, SIGHASH_ALL, 31, 32).EditPush(1, "43021F", "44022000"));
|
||||||
bad.push_back(TestBuilder(CScript() << keys.pubkey2C << OP_CHECKSIG << OP_NOT,
|
bad.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG << OP_NOT,
|
||||||
"P2PK NOT with too much R padding", SCRIPT_VERIFY_DERSIG
|
"P2PK NOT with too much R padding", SCRIPT_VERIFY_DERSIG
|
||||||
).PushSig(keys.key2, SIGHASH_ALL, 31, 32).EditPush(1, "43021F", "44022000"));
|
).PushSig(keys.key2, SIGHASH_ALL, 31, 32).EditPush(1, "43021F", "44022000"));
|
||||||
|
|
||||||
good.push_back(TestBuilder(CScript() << keys.pubkey2C << OP_CHECKSIG,
|
good.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG,
|
||||||
"P2PK with high S but no LOW_S", 0
|
"P2PK with high S but no LOW_S", 0
|
||||||
).PushSig(keys.key2, SIGHASH_ALL, 32, 33));
|
).PushSig(keys.key2, SIGHASH_ALL, 32, 33));
|
||||||
bad.push_back(TestBuilder(CScript() << keys.pubkey2C << OP_CHECKSIG,
|
bad.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG,
|
||||||
"P2PK with high S", SCRIPT_VERIFY_LOW_S
|
"P2PK with high S", SCRIPT_VERIFY_LOW_S
|
||||||
).PushSig(keys.key2, SIGHASH_ALL, 32, 33));
|
).PushSig(keys.key2, SIGHASH_ALL, 32, 33));
|
||||||
|
|
||||||
good.push_back(TestBuilder(CScript() << keys.pubkey0H << OP_CHECKSIG,
|
good.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0H) << OP_CHECKSIG,
|
||||||
"P2PK with hybrid pubkey but no STRICTENC", 0
|
"P2PK with hybrid pubkey but no STRICTENC", 0
|
||||||
).PushSig(keys.key0, SIGHASH_ALL));
|
).PushSig(keys.key0, SIGHASH_ALL));
|
||||||
bad.push_back(TestBuilder(CScript() << keys.pubkey0H << OP_CHECKSIG,
|
bad.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0H) << OP_CHECKSIG,
|
||||||
"P2PK with hybrid pubkey", SCRIPT_VERIFY_STRICTENC
|
"P2PK with hybrid pubkey", SCRIPT_VERIFY_STRICTENC
|
||||||
).PushSig(keys.key0, SIGHASH_ALL));
|
).PushSig(keys.key0, SIGHASH_ALL));
|
||||||
bad.push_back(TestBuilder(CScript() << keys.pubkey0H << OP_CHECKSIG << OP_NOT,
|
bad.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0H) << OP_CHECKSIG << OP_NOT,
|
||||||
"P2PK NOT with hybrid pubkey but no STRICTENC", 0
|
"P2PK NOT with hybrid pubkey but no STRICTENC", 0
|
||||||
).PushSig(keys.key0, SIGHASH_ALL));
|
).PushSig(keys.key0, SIGHASH_ALL));
|
||||||
good.push_back(TestBuilder(CScript() << keys.pubkey0H << OP_CHECKSIG << OP_NOT,
|
good.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0H) << OP_CHECKSIG << OP_NOT,
|
||||||
"P2PK NOT with hybrid pubkey", SCRIPT_VERIFY_STRICTENC
|
"P2PK NOT with hybrid pubkey", SCRIPT_VERIFY_STRICTENC
|
||||||
).PushSig(keys.key0, SIGHASH_ALL));
|
).PushSig(keys.key0, SIGHASH_ALL));
|
||||||
good.push_back(TestBuilder(CScript() << keys.pubkey0H << OP_CHECKSIG << OP_NOT,
|
good.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0H) << OP_CHECKSIG << OP_NOT,
|
||||||
"P2PK NOT with invalid hybrid pubkey but no STRICTENC", 0
|
"P2PK NOT with invalid hybrid pubkey but no STRICTENC", 0
|
||||||
).PushSig(keys.key0, SIGHASH_ALL).DamagePush(10));
|
).PushSig(keys.key0, SIGHASH_ALL).DamagePush(10));
|
||||||
good.push_back(TestBuilder(CScript() << keys.pubkey0H << OP_CHECKSIG << OP_NOT,
|
good.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0H) << OP_CHECKSIG << OP_NOT,
|
||||||
"P2PK NOT with invalid hybrid pubkey", SCRIPT_VERIFY_STRICTENC
|
"P2PK NOT with invalid hybrid pubkey", SCRIPT_VERIFY_STRICTENC
|
||||||
).PushSig(keys.key0, SIGHASH_ALL).DamagePush(10));
|
).PushSig(keys.key0, SIGHASH_ALL).DamagePush(10));
|
||||||
|
|
||||||
good.push_back(TestBuilder(CScript() << keys.pubkey1 << OP_CHECKSIG,
|
good.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1) << OP_CHECKSIG,
|
||||||
"P2PK with undefined hashtype but no STRICTENC", 0
|
"P2PK with undefined hashtype but no STRICTENC", 0
|
||||||
).PushSig(keys.key1, 5));
|
).PushSig(keys.key1, 5));
|
||||||
bad.push_back(TestBuilder(CScript() << keys.pubkey1 << OP_CHECKSIG,
|
bad.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1) << OP_CHECKSIG,
|
||||||
"P2PK with undefined hashtype", SCRIPT_VERIFY_STRICTENC
|
"P2PK with undefined hashtype", SCRIPT_VERIFY_STRICTENC
|
||||||
).PushSig(keys.key1, 5));
|
).PushSig(keys.key1, 5));
|
||||||
good.push_back(TestBuilder(CScript() << keys.pubkey1 << OP_CHECKSIG << OP_NOT,
|
good.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1) << OP_CHECKSIG << OP_NOT,
|
||||||
"P2PK NOT with invalid sig and undefined hashtype but no STRICTENC", 0
|
"P2PK NOT with invalid sig and undefined hashtype but no STRICTENC", 0
|
||||||
).PushSig(keys.key1, 5).DamagePush(10));
|
).PushSig(keys.key1, 5).DamagePush(10));
|
||||||
bad.push_back(TestBuilder(CScript() << keys.pubkey1 << OP_CHECKSIG << OP_NOT,
|
bad.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey1) << OP_CHECKSIG << OP_NOT,
|
||||||
"P2PK NOT with invalid sig and undefined hashtype", SCRIPT_VERIFY_STRICTENC
|
"P2PK NOT with invalid sig and undefined hashtype", SCRIPT_VERIFY_STRICTENC
|
||||||
).PushSig(keys.key1, 5).DamagePush(10));
|
).PushSig(keys.key1, 5).DamagePush(10));
|
||||||
|
|
||||||
good.push_back(TestBuilder(CScript() << OP_3 << keys.pubkey0C << keys.pubkey1C << keys.pubkey2C << OP_3 << OP_CHECKMULTISIG,
|
good.push_back(TestBuilder(CScript() << OP_3 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG,
|
||||||
"3-of-3 with nonzero dummy but no NULLDUMMY", 0
|
"3-of-3 with nonzero dummy but no NULLDUMMY", 0
|
||||||
).Num(1).PushSig(keys.key0).PushSig(keys.key1).PushSig(keys.key2));
|
).Num(1).PushSig(keys.key0).PushSig(keys.key1).PushSig(keys.key2));
|
||||||
bad.push_back(TestBuilder(CScript() << OP_3 << keys.pubkey0C << keys.pubkey1C << keys.pubkey2C << OP_3 << OP_CHECKMULTISIG,
|
bad.push_back(TestBuilder(CScript() << OP_3 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG,
|
||||||
"3-of-3 with nonzero dummy", SCRIPT_VERIFY_NULLDUMMY
|
"3-of-3 with nonzero dummy", SCRIPT_VERIFY_NULLDUMMY
|
||||||
).Num(1).PushSig(keys.key0).PushSig(keys.key1).PushSig(keys.key2));
|
).Num(1).PushSig(keys.key0).PushSig(keys.key1).PushSig(keys.key2));
|
||||||
good.push_back(TestBuilder(CScript() << OP_3 << keys.pubkey0C << keys.pubkey1C << keys.pubkey2C << OP_3 << OP_CHECKMULTISIG << OP_NOT,
|
good.push_back(TestBuilder(CScript() << OP_3 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG << OP_NOT,
|
||||||
"3-of-3 NOT with invalid sig and nonzero dummy but no NULLDUMMY", 0
|
"3-of-3 NOT with invalid sig and nonzero dummy but no NULLDUMMY", 0
|
||||||
).Num(1).PushSig(keys.key0).PushSig(keys.key1).PushSig(keys.key2).DamagePush(10));
|
).Num(1).PushSig(keys.key0).PushSig(keys.key1).PushSig(keys.key2).DamagePush(10));
|
||||||
bad.push_back(TestBuilder(CScript() << OP_3 << keys.pubkey0C << keys.pubkey1C << keys.pubkey2C << OP_3 << OP_CHECKMULTISIG << OP_NOT,
|
bad.push_back(TestBuilder(CScript() << OP_3 << ToByteVector(keys.pubkey0C) << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey2C) << OP_3 << OP_CHECKMULTISIG << OP_NOT,
|
||||||
"3-of-3 NOT with invalid sig with nonzero dummy", SCRIPT_VERIFY_NULLDUMMY
|
"3-of-3 NOT with invalid sig with nonzero dummy", SCRIPT_VERIFY_NULLDUMMY
|
||||||
).Num(1).PushSig(keys.key0).PushSig(keys.key1).PushSig(keys.key2).DamagePush(10));
|
).Num(1).PushSig(keys.key0).PushSig(keys.key1).PushSig(keys.key2).DamagePush(10));
|
||||||
|
|
||||||
@ -582,7 +582,7 @@ BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG12)
|
|||||||
key3.MakeNewKey(true);
|
key3.MakeNewKey(true);
|
||||||
|
|
||||||
CScript scriptPubKey12;
|
CScript scriptPubKey12;
|
||||||
scriptPubKey12 << OP_1 << key1.GetPubKey() << key2.GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
scriptPubKey12 << OP_1 << ToByteVector(key1.GetPubKey()) << ToByteVector(key2.GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
||||||
|
|
||||||
CMutableTransaction txFrom12 = BuildCreditingTransaction(scriptPubKey12);
|
CMutableTransaction txFrom12 = BuildCreditingTransaction(scriptPubKey12);
|
||||||
CMutableTransaction txTo12 = BuildSpendingTransaction(CScript(), txFrom12);
|
CMutableTransaction txTo12 = BuildSpendingTransaction(CScript(), txFrom12);
|
||||||
@ -608,7 +608,7 @@ BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG23)
|
|||||||
key4.MakeNewKey(false);
|
key4.MakeNewKey(false);
|
||||||
|
|
||||||
CScript scriptPubKey23;
|
CScript scriptPubKey23;
|
||||||
scriptPubKey23 << OP_2 << key1.GetPubKey() << key2.GetPubKey() << key3.GetPubKey() << OP_3 << OP_CHECKMULTISIG;
|
scriptPubKey23 << OP_2 << ToByteVector(key1.GetPubKey()) << ToByteVector(key2.GetPubKey()) << ToByteVector(key3.GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
|
||||||
|
|
||||||
CMutableTransaction txFrom23 = BuildCreditingTransaction(scriptPubKey23);
|
CMutableTransaction txFrom23 = BuildCreditingTransaction(scriptPubKey23);
|
||||||
CMutableTransaction txTo23 = BuildSpendingTransaction(CScript(), txFrom23);
|
CMutableTransaction txTo23 = BuildSpendingTransaction(CScript(), txFrom23);
|
||||||
@ -695,7 +695,7 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
|
|||||||
BOOST_CHECK(combined == scriptSigCopy || combined == scriptSig);
|
BOOST_CHECK(combined == scriptSigCopy || combined == scriptSig);
|
||||||
|
|
||||||
// P2SH, single-signature case:
|
// P2SH, single-signature case:
|
||||||
CScript pkSingle; pkSingle << keys[0].GetPubKey() << OP_CHECKSIG;
|
CScript pkSingle; pkSingle << ToByteVector(keys[0].GetPubKey()) << OP_CHECKSIG;
|
||||||
keystore.AddCScript(pkSingle);
|
keystore.AddCScript(pkSingle);
|
||||||
scriptPubKey = GetScriptForDestination(CScriptID(pkSingle));
|
scriptPubKey = GetScriptForDestination(CScriptID(pkSingle));
|
||||||
SignSignature(keystore, txFrom, txTo, 0);
|
SignSignature(keystore, txFrom, txTo, 0);
|
||||||
|
@ -31,8 +31,8 @@ BOOST_AUTO_TEST_CASE(GetSigOpCount)
|
|||||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 0U);
|
BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 0U);
|
||||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 0U);
|
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 0U);
|
||||||
|
|
||||||
uint160 dummy;
|
uint160 dummy(0);
|
||||||
s1 << OP_1 << dummy << dummy << OP_2 << OP_CHECKMULTISIG;
|
s1 << OP_1 << ToByteVector(dummy) << ToByteVector(dummy) << OP_2 << OP_CHECKMULTISIG;
|
||||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 2U);
|
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 2U);
|
||||||
s1 << OP_IF << OP_CHECKSIG << OP_ENDIF;
|
s1 << OP_IF << OP_CHECKSIG << OP_ENDIF;
|
||||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 3U);
|
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 3U);
|
||||||
@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(GetSigOpCount)
|
|||||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(true), 0U);
|
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(true), 0U);
|
||||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(false), 0U);
|
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(false), 0U);
|
||||||
CScript scriptSig2;
|
CScript scriptSig2;
|
||||||
scriptSig2 << OP_1 << dummy << dummy << Serialize(s2);
|
scriptSig2 << OP_1 << ToByteVector(dummy) << ToByteVector(dummy) << Serialize(s2);
|
||||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig2), 3U);
|
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig2), 3U);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,9 +259,9 @@ SetupDummyInputs(CBasicKeyStore& keystoreRet, CCoinsViewCache& coinsRet)
|
|||||||
// Create some dummy input transactions
|
// Create some dummy input transactions
|
||||||
dummyTransactions[0].vout.resize(2);
|
dummyTransactions[0].vout.resize(2);
|
||||||
dummyTransactions[0].vout[0].nValue = 11*CENT;
|
dummyTransactions[0].vout[0].nValue = 11*CENT;
|
||||||
dummyTransactions[0].vout[0].scriptPubKey << key[0].GetPubKey() << OP_CHECKSIG;
|
dummyTransactions[0].vout[0].scriptPubKey << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG;
|
||||||
dummyTransactions[0].vout[1].nValue = 50*CENT;
|
dummyTransactions[0].vout[1].nValue = 50*CENT;
|
||||||
dummyTransactions[0].vout[1].scriptPubKey << key[1].GetPubKey() << OP_CHECKSIG;
|
dummyTransactions[0].vout[1].scriptPubKey << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG;
|
||||||
coinsRet.ModifyCoins(dummyTransactions[0].GetHash())->FromTx(dummyTransactions[0], 0);
|
coinsRet.ModifyCoins(dummyTransactions[0].GetHash())->FromTx(dummyTransactions[0], 0);
|
||||||
|
|
||||||
dummyTransactions[1].vout.resize(2);
|
dummyTransactions[1].vout.resize(2);
|
||||||
|
Loading…
Reference in New Issue
Block a user