Changeset View
Changeset View
Standalone View
Standalone View
src/test/script_tests.cpp
Show First 20 Lines • Show All 261 Lines • ▼ Show 20 Lines | private: | ||||
} | } | ||||
std::vector<uint8_t> DoSign(const CKey &key, const uint256 &hash, | std::vector<uint8_t> DoSign(const CKey &key, const uint256 &hash, | ||||
unsigned int lenR = 32, | unsigned int lenR = 32, | ||||
unsigned int lenS = 32) const { | unsigned int lenS = 32) const { | ||||
std::vector<uint8_t> vchSig, r, s; | std::vector<uint8_t> vchSig, r, s; | ||||
uint32_t iter = 0; | uint32_t iter = 0; | ||||
do { | do { | ||||
key.Sign(hash, vchSig, iter++); | key.SignECDSA(hash, vchSig, iter++); | ||||
if ((lenS == 33) != (vchSig[5 + vchSig[3]] == 33)) { | if ((lenS == 33) != (vchSig[5 + vchSig[3]] == 33)) { | ||||
NegateSignatureS(vchSig); | NegateSignatureS(vchSig); | ||||
} | } | ||||
r = std::vector<uint8_t>(vchSig.begin() + 4, | r = std::vector<uint8_t>(vchSig.begin() + 4, | ||||
vchSig.begin() + 4 + vchSig[3]); | vchSig.begin() + 4 + vchSig[3]); | ||||
s = std::vector<uint8_t>(vchSig.begin() + 6 + vchSig[3], | s = std::vector<uint8_t>(vchSig.begin() + 6 + vchSig[3], | ||||
vchSig.begin() + 6 + vchSig[3] + | vchSig.begin() + 6 + vchSig[3] + | ||||
▲ Show 20 Lines • Show All 1,156 Lines • ▼ Show 20 Lines | CScript sign_multisig(CScript scriptPubKey, std::vector<CKey> keys, | ||||
// NOTE: CHECKMULTISIG has an unfortunate bug; it requires one extra item on | // NOTE: CHECKMULTISIG has an unfortunate bug; it requires one extra item on | ||||
// the stack, before the signatures. Putting OP_0 on the stack is the | // the stack, before the signatures. Putting OP_0 on the stack is the | ||||
// workaround; fixing the bug would mean splitting the block chain (old | // workaround; fixing the bug would mean splitting the block chain (old | ||||
// clients would not accept new CHECKMULTISIG transactions, and vice-versa) | // clients would not accept new CHECKMULTISIG transactions, and vice-versa) | ||||
// | // | ||||
result << OP_0; | result << OP_0; | ||||
for (const CKey &key : keys) { | for (const CKey &key : keys) { | ||||
std::vector<uint8_t> vchSig; | std::vector<uint8_t> vchSig; | ||||
BOOST_CHECK(key.Sign(hash, vchSig)); | BOOST_CHECK(key.SignECDSA(hash, vchSig)); | ||||
vchSig.push_back(uint8_t(SIGHASH_ALL)); | vchSig.push_back(uint8_t(SIGHASH_ALL)); | ||||
result << vchSig; | result << vchSig; | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
CScript sign_multisig(CScript scriptPubKey, const CKey &key, | CScript sign_multisig(CScript scriptPubKey, const CKey &key, | ||||
▲ Show 20 Lines • Show All 266 Lines • ▼ Show 20 Lines | combined = CombineSignatures( | ||||
scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), | scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), | ||||
empty, SignatureData(scriptSig)); | empty, SignatureData(scriptSig)); | ||||
BOOST_CHECK(combined.scriptSig == scriptSig); | BOOST_CHECK(combined.scriptSig == scriptSig); | ||||
// A couple of partially-signed versions: | // A couple of partially-signed versions: | ||||
std::vector<uint8_t> sig1; | std::vector<uint8_t> sig1; | ||||
uint256 hash1 = SignatureHash(scriptPubKey, CTransaction(txTo), 0, | uint256 hash1 = SignatureHash(scriptPubKey, CTransaction(txTo), 0, | ||||
SigHashType(), Amount::zero()); | SigHashType(), Amount::zero()); | ||||
BOOST_CHECK(keys[0].Sign(hash1, sig1)); | BOOST_CHECK(keys[0].SignECDSA(hash1, sig1)); | ||||
sig1.push_back(SIGHASH_ALL); | sig1.push_back(SIGHASH_ALL); | ||||
std::vector<uint8_t> sig2; | std::vector<uint8_t> sig2; | ||||
uint256 hash2 = SignatureHash( | uint256 hash2 = SignatureHash( | ||||
scriptPubKey, CTransaction(txTo), 0, | scriptPubKey, CTransaction(txTo), 0, | ||||
SigHashType().withBaseType(BaseSigHashType::NONE), Amount::zero()); | SigHashType().withBaseType(BaseSigHashType::NONE), Amount::zero()); | ||||
BOOST_CHECK(keys[1].Sign(hash2, sig2)); | BOOST_CHECK(keys[1].SignECDSA(hash2, sig2)); | ||||
sig2.push_back(SIGHASH_NONE); | sig2.push_back(SIGHASH_NONE); | ||||
std::vector<uint8_t> sig3; | std::vector<uint8_t> sig3; | ||||
uint256 hash3 = SignatureHash( | uint256 hash3 = SignatureHash( | ||||
scriptPubKey, CTransaction(txTo), 0, | scriptPubKey, CTransaction(txTo), 0, | ||||
SigHashType().withBaseType(BaseSigHashType::SINGLE), Amount::zero()); | SigHashType().withBaseType(BaseSigHashType::SINGLE), Amount::zero()); | ||||
BOOST_CHECK(keys[2].Sign(hash3, sig3)); | BOOST_CHECK(keys[2].SignECDSA(hash3, sig3)); | ||||
sig3.push_back(SIGHASH_SINGLE); | sig3.push_back(SIGHASH_SINGLE); | ||||
// Not fussy about order (or even existence) of placeholders or signatures: | // Not fussy about order (or even existence) of placeholders or signatures: | ||||
CScript partial1a = CScript() << OP_0 << sig1 << OP_0; | CScript partial1a = CScript() << OP_0 << sig1 << OP_0; | ||||
CScript partial1b = CScript() << OP_0 << OP_0 << sig1; | CScript partial1b = CScript() << OP_0 << OP_0 << sig1; | ||||
CScript partial2a = CScript() << OP_0 << sig2; | CScript partial2a = CScript() << OP_0 << sig2; | ||||
CScript partial2b = CScript() << sig2 << OP_0; | CScript partial2b = CScript() << sig2 << OP_0; | ||||
CScript partial3a = CScript() << sig3; | CScript partial3a = CScript() << sig3; | ||||
▲ Show 20 Lines • Show All 324 Lines • Show Last 20 Lines |