From 77269e077ea8e4601d789cd7cc5545cd6ff8f781 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 5 Aug 2015 23:15:10 +0200 Subject: [PATCH] Update to new libsecp256k1 --- configure.ac | 2 +- src/blind.cpp | 19 ++++++----- src/coins.cpp | 1 + src/key.cpp | 24 +++++++------- src/key.h | 2 +- src/pubkey.cpp | 55 +++++++++++++++++++++++-------- src/rpcrawtransaction.cpp | 6 ++-- src/script/interpreter.cpp | 6 +++- src/test/data/script_invalid.json | 38 ++++++++++----------- src/test/data/script_valid.json | 28 ++++++++-------- src/test/key_tests.cpp | 4 +-- 11 files changed, 112 insertions(+), 73 deletions(-) diff --git a/configure.ac b/configure.ac index d024570aa7..f3fce9de7e 100644 --- a/configure.ac +++ b/configure.ac @@ -909,7 +909,7 @@ PKGCONFIG_LIBDIR_TEMP="$PKG_CONFIG_LIBDIR" unset PKG_CONFIG_LIBDIR PKG_CONFIG_LIBDIR="$PKGCONFIG_LIBDIR_TEMP" -ac_configure_args="${ac_configure_args} --disable-shared --with-pic" +ac_configure_args="${ac_configure_args} --disable-shared --with-pic --enable-module-schnorr --enable-module-ecdh --enable-module-rangeproof" AC_CONFIG_SUBDIRS([src/secp256k1]) AC_OUTPUT diff --git a/src/blind.cpp b/src/blind.cpp index 5de469a72f..a018037c30 100644 --- a/src/blind.cpp +++ b/src/blind.cpp @@ -6,14 +6,17 @@ #include "util.h" #include +#include static secp256k1_context_t* secp256k1_context = NULL; void ECC_Blinding_Start() { assert(secp256k1_context == NULL); - secp256k1_context_t *ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_COMMIT | SECP256K1_CONTEXT_RANGEPROOF); + secp256k1_context_t *ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); assert(ctx != NULL); + secp256k1_pedersen_context_initialize(ctx); + secp256k1_rangeproof_context_initialize(ctx); secp256k1_context = ctx; } @@ -42,14 +45,13 @@ int UnblindOutput(const CKey &key, const CTxOut& txout, CAmount& amount_out, std if (!ephemeral_key.IsValid()) { return 0; } - CPubKey nonce_key = key.ECDH(ephemeral_key); - unsigned char nonce[32]; - CHash256().Write(nonce_key.begin(), nonce_key.size()).Finalize(nonce); + uint256 nonce = key.ECDH(ephemeral_key); + CSHA256().Write(nonce.begin(), 32).Finalize(nonce.begin()); unsigned char msg[4096]; int msg_size; uint64_t min_value, max_value, amount; blinding_factor_out.resize(32); - int res = secp256k1_rangeproof_rewind(secp256k1_context, &blinding_factor_out[0], &amount, msg, &msg_size, nonce, &min_value, &max_value, &txout.nValue.vchCommitment[0], &txout.nValue.vchRangeproof[0], txout.nValue.vchRangeproof.size()); + int res = secp256k1_rangeproof_rewind(secp256k1_context, &blinding_factor_out[0], &amount, msg, &msg_size, nonce.begin(), &min_value, &max_value, &txout.nValue.vchCommitment[0], &txout.nValue.vchRangeproof[0], txout.nValue.vchRangeproof.size()); if (!res || amount > (uint64_t)MAX_MONEY || !MoneyRange((CAmount)amount)) { amount_out = 0; blinding_factor_out.resize(0); @@ -121,14 +123,13 @@ void BlindOutputs(const std::vector >& input_blinding value.vchNonceCommitment.resize(33); memcpy(&value.vchNonceCommitment[0], &ephemeral_pubkey[0], 33); // Generate nonce - CPubKey nonce_key = ephemeral_key.ECDH(output_pubkeys[nOut]); - unsigned char nonce[32]; - CHash256().Write(nonce_key.begin(), nonce_key.size()).Finalize(nonce); + uint256 nonce = ephemeral_key.ECDH(output_pubkeys[nOut]); + CSHA256().Write(nonce.begin(), 32).Finalize(nonce.begin()); // Create range proof int nRangeProofLen = 5134; // TODO: smarter min_value selection value.vchRangeproof.resize(nRangeProofLen); - int res = secp256k1_rangeproof_sign(ECC_Blinding_Context(), &value.vchRangeproof[0], &nRangeProofLen, 0, &value.vchCommitment[0], blindptrs.back(), nonce, std::min(std::max((int)GetArg("-ct_exponent", 0), -1),18), std::min(std::max((int)GetArg("-ct_bits", 32), 1), 51), amount); + int res = secp256k1_rangeproof_sign(ECC_Blinding_Context(), &value.vchRangeproof[0], &nRangeProofLen, 0, &value.vchCommitment[0], blindptrs.back(), nonce.begin(), std::min(std::max((int)GetArg("-ct_exponent", 0), -1),18), std::min(std::max((int)GetArg("-ct_bits", 32), 1), 51), amount); value.vchRangeproof.resize(nRangeProofLen); // TODO: do something smarter here assert(res); diff --git a/src/coins.cpp b/src/coins.cpp index b5d873c6a6..68ecd7ac70 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -9,6 +9,7 @@ #include #include +#include /** * calculate number of bytes for the bitmask, and its number of non-zero bytes diff --git a/src/key.cpp b/src/key.cpp index 9f5f4edeec..aa85e5b8bf 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -12,6 +12,8 @@ #include "random.h" #include +#include +#include static secp256k1_context_t* secp256k1_context = NULL; @@ -51,21 +53,21 @@ CPubKey CKey::GetPubKey() const { assert(fValid); CPubKey result; int clen = 65; - int ret = secp256k1_ec_pubkey_create(secp256k1_context, (unsigned char*)result.begin(), &clen, begin(), fCompressed); + secp256k1_pubkey_t pubkey; + int ret = secp256k1_ec_pubkey_create(secp256k1_context, &pubkey, begin()); + secp256k1_ec_pubkey_serialize(secp256k1_context, (unsigned char*)result.begin(), &clen, &pubkey, fCompressed); assert((int)result.size() == clen); assert(ret); assert(result.IsValid()); return result; } -CPubKey CKey::ECDH(const CPubKey& pubkey) const { +uint256 CKey::ECDH(const CPubKey& pubkey) const { assert(fValid); - CPubKey result = pubkey; - int clen = result.size(); - int ret = secp256k1_point_multiply((unsigned char*)result.begin(), &clen, begin()); - assert((int)result.size() == clen); - assert(ret); - assert(result.IsValid()); + uint256 result; + secp256k1_pubkey_t pkey; + assert(secp256k1_ec_pubkey_parse(secp256k1_context, &pkey, pubkey.begin(), pubkey.size())); + assert(secp256k1_ecdh(secp256k1_context, result.begin(), &pkey, begin())); return result; } @@ -101,9 +103,9 @@ bool CKey::SignCompact(const uint256 &hash, std::vector& vchSig) return false; vchSig.resize(65); int rec = -1; - int ret = secp256k1_ecdsa_sign_compact(secp256k1_context, hash.begin(), &vchSig[1], begin(), secp256k1_nonce_function_rfc6979, NULL, &rec); - assert(ret); - assert(rec != -1); + secp256k1_ecdsa_signature_t sig; + assert(secp256k1_ecdsa_sign(secp256k1_context, hash.begin(), &sig, begin(), secp256k1_nonce_function_rfc6979, NULL)); + assert(secp256k1_ecdsa_signature_serialize_compact(secp256k1_context, &vchSig[1], &rec, &sig)); vchSig[0] = 27 + rec + (fCompressed ? 4 : 0); return true; } diff --git a/src/key.h b/src/key.h index 080fce9a15..b261d49858 100644 --- a/src/key.h +++ b/src/key.h @@ -125,7 +125,7 @@ class CKey /** * Compute the ECDH exchange result using this private key and another public key. */ - CPubKey ECDH(const CPubKey& pubkey) const; + uint256 ECDH(const CPubKey& pubkey) const; /** * Create a DER-serialized signature. diff --git a/src/pubkey.cpp b/src/pubkey.cpp index c3fa54f9bb..a5805bf99f 100644 --- a/src/pubkey.cpp +++ b/src/pubkey.cpp @@ -5,6 +5,8 @@ #include "pubkey.h" #include +#include +#include secp256k1_context_t* secp256k1_bitcoin_verify_context = NULL; static secp256k1_context_t*& secp256k1_context = secp256k1_bitcoin_verify_context; @@ -14,7 +16,10 @@ bool CPubKey::Verify(const uint256 &hash, const std::vector& vchS return false; if (vchSig.size() != 64) return false; - if (secp256k1_schnorr_verify(secp256k1_context, (const unsigned char*)&hash, &vchSig[0], begin(), size()) != 1) + secp256k1_pubkey_t pubkey; + if (!secp256k1_ec_pubkey_parse(secp256k1_context, &pubkey, begin(), size())) + return false; + if (secp256k1_schnorr_verify(secp256k1_context, (const unsigned char*)&hash, &vchSig[0], &pubkey) != 1) return false; return true; } @@ -24,17 +29,26 @@ bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector #include "json/json_spirit_utils.h" #include "json/json_spirit_value.h" -#include +#include using namespace boost; using namespace boost::assign; using namespace json_spirit; using namespace std; +extern secp256k1_context_t* secp256k1_bitcoin_verify_context; + void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeHex) { txnouttype type; @@ -91,7 +93,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) int mantissa; uint64_t minv; uint64_t maxv; - if (secp256k1_rangeproof_info(NULL, &exp, &mantissa, &minv, &maxv, &txout.nValue.vchRangeproof[0], txout.nValue.vchRangeproof.size())) { + if (secp256k1_rangeproof_info(secp256k1_bitcoin_verify_context, &exp, &mantissa, &minv, &maxv, &txout.nValue.vchRangeproof[0], txout.nValue.vchRangeproof.size())) { if (exp == -1) { out.push_back(Pair("value", ValueFromAmount((CAmount)minv))); } else { diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 378eda21a6..ffe0df2337 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1462,7 +1462,11 @@ bool EvalScript(vector >& stack, const CScript& script, un unsigned char *pub_start = &(*(sdpc - 33)); CHMAC_SHA256(pub_start, 33).Write(&vcontract[0], 40).Finalize(tweak); // If someone creates a tweak that makes this fail, they broke SHA256 - assert(secp256k1_ec_pubkey_tweak_add(secp256k1_context, pub_start, 33, tweak) != 0); + secp256k1_pubkey_t pubkey; + int pubkeylen = 33; + assert(secp256k1_ec_pubkey_parse(secp256k1_context, &pubkey, pub_start, 33)); + assert(secp256k1_ec_pubkey_tweak_add(secp256k1_context, &pubkey, tweak) != 0); + assert(secp256k1_ec_pubkey_serialize(secp256k1_context, pub_start, &pubkeylen, &pubkey, 1)); } } } diff --git a/src/test/data/script_invalid.json b/src/test/data/script_invalid.json index 899725a9ce..df4c27ebc2 100644 --- a/src/test/data/script_invalid.json +++ b/src/test/data/script_invalid.json @@ -519,115 +519,115 @@ ["Automatically generated test cases"], [ - "0x41 0x40935c44b798ebd79da7a83cefe2310c7cc2e60aa4eb353417d0f7646fa9886dcde7cc347575f5ebe004e4c3bdfe58bd92012177ba7615eb2dfdce59cbc20dd201", + "0x41 0x0d676d409b7e64a10317ee8ede493482f90c3cdbf81cefe3c22f1326c53087352fa61ba8a289273706c3d80b3030b679be674ec2e40c3692067d063b1c3c06b801", "0x41 0x0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 CHECKSIG", "", "P2PK, bad sig" ], [ - "0x41 0x2e98609c89cd86386b5b42d9b992028217a3d198387c8ff7e5980af68e25fe27760abb21a3f90b9f7757966d8658ad6af32f84afda6f739dd685fc460e31f3e001 0x21 0x03363d90d446b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640", + "0x41 0x82501cd8c9032f48e70e698cc4553b3e546be50657ea31322e0a2435918c7f682e790b98b7e337c51fee33e81c5d8bcb28efbf623258ec94b2d7afac09bb550901 0x21 0x03363d90d446b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640", "DUP HASH160 0x14 0xc0834c0c158f53be706d234c38fd52de7eece656 EQUALVERIFY CHECKSIG", "", "P2PKH, bad pubkey" ], [ - "0x41 0x4f0d68fe60fe86298dc48d7a2d8416c49a037d9471b849e3408bdd417e7282a8169b7610632cdc5241cc554e239147cebdf3e8b9be2e08777a415e6d5fc0500d01", + "0x41 0x040f320c2201b8aa7daa5e30d2be94564e6aac8cf6d9c74bd19e39839b4405a3bbcce62918cd7f1b8e26965c9634543c806fc032277be0b198f21ab106ee90ca01", "0x41 0x048282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f5150811f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf CHECKSIG", "", "P2PK anyonecanpay marked with normal hashtype" ], [ - "0x41 0x9e6312ff6b1e091d1874a6ae0402fd3e5554d44b77e26a1d3aa3c73a68fb41cf4ad2a561e52929769421cf0c6e0ea2bf7ffcf0511b8e16f335f314b358b1202901 0x23 0x210279be667ef9dcbbac54a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac", + "0x41 0xa6637f9b08d85bab62929779dc1d0d7627e542d27a9b83e81b1f5dea098b9f56913be9fbeca898a60e26c18969d9458e83f782a7832f3d0346dddc79447d078301 0x23 0x210279be667ef9dcbbac54a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac", "HASH160 0x14 0x23b0ad3477f2178bc0b3eed26e4e6316f4e83aa1 EQUAL", "P2SH", "P2SH(P2PK), bad redeemscript" ], [ - "0x41 0x06971e9df6c53de39238b9aea03f586aaf194b48e0dfdb99cd3fc3e446ac358b17361fc415445110a44b97cfe7692c2666ad6fb72a1a33d3cb449cc9f4d0443301 0x19 0x76a9147cf9c846cd4882efec4bf07e44ebdad495c94f4b88ac", + "0x41 0xa594654c074e82156a9d47a46fd78f105e0d200eae1fb198c95edb297fbf4bbbe7292da1c68fa7563ee1f448ffb1cc00757c4e9b52930bef0bcef3cc7f044ce701 0x19 0x76a9147cf9c846cd4882efec4bf07e44ebdad495c94f4b88ac", "HASH160 0x14 0x2df519943d5acc0ef5222091f9dfe3543f489a82 EQUAL", "P2SH", "P2SH(P2PKH), bad sig" ], [ - "0 0x41 0x434260ba2a37f605c8c5959abd764d1785ed5678f5112875e8d708db790e0f4d6d7b42b291b2a66dae09140852f60e6ee37ab2c031387a6e8e2ba15179463bae01 0x41 0xe64e579c3cdb1c5d99ed3ac4dd73095554860eec64ac40924772138eb3e3765675decfb264e69865465fe3e7d84992791ed23be1d96b1b49f3eb5e6866ab83e601 0", + "0 0x41 0xb852c8c7207c813acd1e002fb98a63327324db6474782558f1726750df6544a3b898c43bb0ddee5848c34e45b719cee1559d8d74b789eef83665d43dca5f243c01 0x41 0xd8bf0745999d38500ecc503ca0941c5d7103272428ca6733cad1ae4b19e97d0b021479b53242476dbab1b19d10c065d0373ffa01f0bfeb15e72c941ab7bc8c1b01 0", "3 0x21 0x0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 0x21 0x03363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640 3 CHECKMULTISIG", "", "3-of-3, 2 sigs" ], [ - "0 0x41 0x8b03faf3dcd30dde4ec45aa313a51de01769d1e25233eb68b732f45b3949cfb4f77c5ad4629ce73a310d449cae3bd4449b0a10fa07112cdbfb2cee2025b2691b01 0 0x4c69 0x52210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179821038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f515082103363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff464053ae", + "0 0x41 0xc98cdd05746c1232eee979e134680a47b53f14f484a35aaf4ece9487e1010f4240ed76d2acf6dc641b66ed1c1d331d663ff47ba749f8f50f7188f9e6c230944b01 0 0x4c69 0x52210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179821038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f515082103363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff464053ae", "HASH160 0x14 0xc9e4a896d149702d0d1695434feddd52e24ad78d EQUAL", "P2SH", "P2SH(2-of-3), 1 sig" ], [ - "0x41 0x98b330e1a8662c34ec3982e1db35a1409a7a472db6bcb0db7af4a02bf00b051affd2a4dfd70a96aea9b08e64e984e79c963407f62d9b7ff622dfd4438468b88801", + "0x41 0x4196ce2d3cfbb5f81aa894153cbf59a6a07281a8b2beb14f0d5ba034f9a5c41de0f5f4a2d9d932c961e1e500bdae14dac64cc0ed5ede10cb7df62a2616a618cd01", "0x41 0x0679be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 CHECKSIG", "STRICTENC", "P2PK with hybrid pubkey" ], [ - "0x41 0xe9c1ca40b01fe16d8ddb6128496616ebbff6ef1fa214b8dd46f2d9fb143f307f0e6813c4be37790d86826feb13e0818974089440ff9a47a030c2dbfd1a6af07d01", + "0x41 0x710f8d3e4abdeffc9c715aa660f76243d0b219e3a0087b8bdd928a709870e9781a43a6bd870beefc5865d2a548d11439ac51aa7e2e57f287471ed215f0f6e70801", "0x41 0x0679be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 CHECKSIG NOT", "", "P2PK NOT with hybrid pubkey but no STRICTENC" ], [ - "0x41 0xe9c1ca40b01fe16d8ddb6128496616ebbff6ef1fa214b8dd46f2d9fb143f307f0e6813c4be37790d86826feb13e0818974089440ff9a47a030c2dbfd1a6af07d01", + "0x41 0x710f8d3e4abdeffc9c715aa660f76243d0b219e3a0087b8bdd928a709870e9781a43a6bd870beefc5865d2a548d11439ac51aa7e2e57f287471ed215f0f6e70801", "0x41 0x0679be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 CHECKSIG NOT", "STRICTENC", "P2PK NOT with hybrid pubkey" ], [ - "0x41 0xe9c1ca40b01fe16d8ddb6028496616ebbff6ef1fa214b8dd46f2d9fb143f307f0e6813c4be37790d86826feb13e0818974089440ff9a47a030c2dbfd1a6af07d01", + "0x41 0x710f8d3e4abdeffc9c715ba660f76243d0b219e3a0087b8bdd928a709870e9781a43a6bd870beefc5865d2a548d11439ac51aa7e2e57f287471ed215f0f6e70801", "0x41 0x0679be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 CHECKSIG NOT", "STRICTENC", "P2PK NOT with invalid hybrid pubkey" ], [ - "0 0x41 0x5ab9dada5869f774573e9749c95f1ae31ff416c50232d5ee27bc16ab511a84dae9575afe8733869295b62f1729a495bcd217e9c50b609c9911675fec4c194a7801", + "0 0x41 0x099981456a47f7d9dbe190985794ae28449b3cda259c40db07ad3b5b6c8fa1dab4506a5d519b8fab88a097ef45bbad8b880594596132cfa34b913929bc98c1ef01", "1 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 0x41 0x0679be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 2 CHECKMULTISIG", "STRICTENC", "1-of-2 with the first 1 hybrid pubkey" ], [ - "0x41 0x3e97989da4fd193f094caaebbdb75522564604f90673bf276164522d3c0528003d039e65ced8d9a3b52299f75f25344b33a1b6d36f1946e3e62392f10a86677005", + "0x41 0x91896eb451aa34bedeedeb8e042c5de0d1774fa6151705eec402aa949523fad55c7067d80542f01892ff89ba1a703aca6adc9038f1d4e8541c66212512f4620505", "0x41 0x048282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f5150811f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf CHECKSIG", "STRICTENC", "P2PK with undefined hashtype" ], [ - "0x41 0x7494b1309e9447cdc23dbc92ff3ca33a2a8bd42e5df669fa8ae4b4d65435069b4ab31b52eea2b8ab2854d9d40a12c262bcc691eb9dd20afed3fe8f73fbb7cd7605", + "0x41 0xe2ae57ffe4b6858a9b097023835e4ee68faf7f8406b149790ba76892cbc650513a4a76f86aef2b94e85dc9dee3edb835488e70a9db0383adaca5441ac4e6a75105", "0x41 0x048282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f5150811f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf CHECKSIG NOT", "STRICTENC", "P2PK NOT with invalid sig and undefined hashtype" ], [ - "1 0x41 0x434260ba2a37f605c8c5959abd764d1785ed5678f5112875e8d708db790e0f4d6d7b42b291b2a66dae09140852f60e6ee37ab2c031387a6e8e2ba15179463bae01 0x41 0xe64e579c3cdb1c5d99ed3ac4dd73095554860eec64ac40924772138eb3e3765675decfb264e69865465fe3e7d84992791ed23be1d96b1b49f3eb5e6866ab83e601 0x41 0x095bce722466be45b3b110f8e92be4c3ae17abefccb73c84fbdd458b667646ea8b3dea40fccf036985e5dcd43ef1e6c781c99bcea36691d9f90ae958307cc48901", + "1 0x41 0xb852c8c7207c813acd1e002fb98a63327324db6474782558f1726750df6544a3b898c43bb0ddee5848c34e45b719cee1559d8d74b789eef83665d43dca5f243c01 0x41 0xd8bf0745999d38500ecc503ca0941c5d7103272428ca6733cad1ae4b19e97d0b021479b53242476dbab1b19d10c065d0373ffa01f0bfeb15e72c941ab7bc8c1b01 0x41 0xaaa573ffdcf283a4aa608b81540e0bab4a8d2aa2e8bffe030736831c3399e360c78eab9ebf8da9d98c6306409ad752fcbc762222828dc3e54a7d2594d7fb728b01", "3 0x21 0x0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 0x21 0x03363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640 3 CHECKMULTISIG", "NULLDUMMY", "3-of-3 with nonzero dummy" ], [ - "1 0x41 0x1040558786f096861c0f202bf12e8de33e2c4354a7c8d9fd625bdccd350fc2ffa6cb54fc126652e9d89b757e478c10d336c14efb7342afaf688067321a2be2d901 0x41 0x254dc8cb5633fe5a9fb6951b8987c1bfeb8c69c876e1c4dec588d1f9708853260a5c386740ed87394537a6b1e72f942480c56f43c5d281feae37f8eb1d7b611c01 0x41 0xbb03ec9b47446fb988049e7e0f97f8c60528886f50d4679ae4d6e8c55558314257031b5c18b8424d409d41707177dc0eb571dd5c7083a454a52a7dd52aaa550701", + "1 0x41 0xc5ade7edc471ebf6f93cfdcd081efc826e42c90b9608257336917fe19dd49f1f9d9025cf85851990010e76f90fa2a10091aa20d7b4714c1dbbe35d7ab4ae7af901 0x41 0x636bac4be2a9d2bb9efb027b3455a09b942904b15f421d1578f058fb35ec8116a80690cbc2f994596d3ce9469bff6aa0a6a5a850abec57f70c32a51cd6175b1401 0x41 0x0dfa9ea0fd70ff9a86a83d9e41408b90e26797549977698b4362c8f41ce7201caea6c53a79b99065d09cd338bf7f262756b81ddae4e4d1626e41f7945272576801", "3 0x21 0x0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 0x21 0x03363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640 3 CHECKMULTISIG NOT", "NULLDUMMY", "3-of-3 NOT with invalid sig with nonzero dummy" ], [ - "0 0x41 0x2d35edb5b8539821925fd0315e30882e7db9a1b4b697a0f339b77a3835216ffae2d196dd275901c78877942a44da3ad91bc9702e134545c5a7f4b5da4170fd8301 DUP", + "0 0x41 0xde2fb5c3ac521e16c92a44a31bffc213dbafbf39fc370ec3aab76e2af7e4be6d33f1dea322991d3921ca483fd3db8b9f5f3f9a42b6ca3e9b561d963887d7c8b101 DUP", "2 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 2 CHECKMULTISIG", "SIGPUSHONLY", "2-of-2 with two identical keys and sigs pushed using OP_DUP" ], [ - "0x41 0x63025a2ea40b83adae916ef3d30b8e1cdc2283847d024ea8b6c33d199a2933652de1aeef0deddd7160ba6b149cae87231da61367e88f1ef3257b33e3fbfd08b801 0x23 0x2103363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640ac", + "0x41 0x2e3cee81c63207d7f4730be4be45c9b5cec7316494d5d10da84e26196a270051542401318e8871020a60f7beedf68202327358fdb3303945d6f793f1232bc2fb01 0x23 0x2103363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640ac", "0x21 0x03363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640 CHECKSIG", "", "P2SH(P2PK) with non-push scriptSig but no SIGPUSHONLY" ], [ - "0x41 0x63025a2ea40b83adae916ef3d30b8e1cdc2283847d024ea8b6c33d199a2933652de1aeef0deddd7160ba6b149cae87231da61367e88f1ef3257b33e3fbfd08b801 0x23 0x2103363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640ac", + "0x41 0x2e3cee81c63207d7f4730be4be45c9b5cec7316494d5d10da84e26196a270051542401318e8871020a60f7beedf68202327358fdb3303945d6f793f1232bc2fb01 0x23 0x2103363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640ac", "0x21 0x03363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640 CHECKSIG", "SIGPUSHONLY", "P2SH(P2PK) with non-push scriptSig" diff --git a/src/test/data/script_valid.json b/src/test/data/script_valid.json index 6be140bea2..23c10d341b 100644 --- a/src/test/data/script_valid.json +++ b/src/test/data/script_valid.json @@ -767,85 +767,85 @@ ["Automatically generated test cases"], [ - "0x41 0x40935c44b798ebd79da7a93cefe2310c7cc2e60aa4eb353417d0f7646fa9886dcde7cc347575f5ebe004e4c3bdfe58bd92012177ba7615eb2dfdce59cbc20dd201", + "0x41 0x0d676d409b7e64a10317ef8ede493482f90c3cdbf81cefe3c22f1326c53087352fa61ba8a289273706c3d80b3030b679be674ec2e40c3692067d063b1c3c06b801", "0x41 0x0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 CHECKSIG", "", "P2PK" ], [ - "0x41 0xcfbcd6d7c65ac52b50bb79ad3ae34f3caf4ceef26640bc7321cc0684ca0b79a24c6586c66997a994de4066a615fee25770d8990d46aaa29a377c680541fa226f01 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508", + "0x41 0x5f4a78c77c1b27aa28abc0f33c9fc0dc4a959fb554d73d8356c79f6db5083537cb195f7ca14644300dbe0b206789838f6ed6e336f8bd62ccc240f77c1921fe0901 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508", "DUP HASH160 0x14 0x1018853670f9f3b0582c5b9ee8ce93764ac32b93 EQUALVERIFY CHECKSIG", "", "P2PKH" ], [ - "0x41 0x4f0d68fe60fe86298dc48d7a2d8416c49a037d9471b849e3408bdd417e7282a8169b7610632cdc5241cc554e239147cebdf3e8b9be2e08777a415e6d5fc0500d81", + "0x41 0x040f320c2201b8aa7daa5e30d2be94564e6aac8cf6d9c74bd19e39839b4405a3bbcce62918cd7f1b8e26965c9634543c806fc032277be0b198f21ab106ee90ca81", "0x41 0x048282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f5150811f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf CHECKSIG", "", "P2PK anyonecanpay" ], [ - "0x41 0x9e6312ff6b1e091d1874a6ae0402fd3e5554d44b77e26a1d3aa3c73a68fb41cf4ad2a561e52929769421cf0c6e0ea2bf7ffcf0511b8e16f335f314b358b1202901 0x23 0x210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac", + "0x41 0xa6637f9b08d85bab62929779dc1d0d7627e542d27a9b83e81b1f5dea098b9f56913be9fbeca898a60e26c18969d9458e83f782a7832f3d0346dddc79447d078301 0x23 0x210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac", "HASH160 0x14 0x23b0ad3477f2178bc0b3eed26e4e6316f4e83aa1 EQUAL", "P2SH", "P2SH(P2PK)" ], [ - "0x41 0x06971e9df6c53de39238b9aea03f586aaf194b48e0dfdb99cd3fc3e446ac358b17361fc415445110a44b97cfe7692c2666ad6fb72a1a33d3cb449cc9f4d0443301 0x19 0x76a9147cf9c846cd4882efec4bf07e44ebdad495c94f4b88ac", + "0x41 0xa594654c074e82156a9d47a46fd78f105e0d200eae1fb198c95edb297fbf4bbbe7292da1c68fa7563ee1f448ffb1cc00757c4e9b52930bef0bcef3cc7f044ce701 0x19 0x76a9147cf9c846cd4882efec4bf07e44ebdad495c94f4b88ac", "HASH160 0x14 0x2df519943d5acc0ef5222091f9dfe3543f489a82 EQUAL", "", "P2SH(P2PKH), bad sig but no VERIFY_P2SH" ], [ - "0 0x41 0x434260ba2a37f605c8c5959abd764d1785ed5678f5112875e8d708db790e0f4d6d7b42b291b2a66dae09140852f60e6ee37ab2c031387a6e8e2ba15179463bae01 0x41 0xe64e579c3cdb1c5d99ed3ac4dd73095554860eec64ac40924772138eb3e3765675decfb264e69865465fe3e7d84992791ed23be1d96b1b49f3eb5e6866ab83e601 0x41 0x095bce722466be45b3b110f8e92be4c3ae17abefccb73c84fbdd458b667646ea8b3dea40fccf036985e5dcd43ef1e6c781c99bcea36691d9f90ae958307cc48901", + "0 0x41 0xb852c8c7207c813acd1e002fb98a63327324db6474782558f1726750df6544a3b898c43bb0ddee5848c34e45b719cee1559d8d74b789eef83665d43dca5f243c01 0x41 0xd8bf0745999d38500ecc503ca0941c5d7103272428ca6733cad1ae4b19e97d0b021479b53242476dbab1b19d10c065d0373ffa01f0bfeb15e72c941ab7bc8c1b01 0x41 0xaaa573ffdcf283a4aa608b81540e0bab4a8d2aa2e8bffe030736831c3399e360c78eab9ebf8da9d98c6306409ad752fcbc762222828dc3e54a7d2594d7fb728b01", "3 0x21 0x0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 0x21 0x03363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640 3 CHECKMULTISIG", "", "3-of-3" ], [ - "0 0x41 0x8b03faf3dcd30dde4ec45aa313a51de01769d1e25233eb68b732f45b3949cfb4f77c5ad4629ce73a310d449cae3bd4449b0a10fa07112cdbfb2cee2025b2691b01 0x41 0xd1f2e618b835f2d0dbb42dbbe2318d80be504088489b5db168ba94beea2faa7dc2f614b5ba609bd51b9cee9709da4cef54e45a153c69193e487c29ec102f04a901 0x4c69 0x52210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179821038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f515082103363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff464053ae", + "0 0x41 0xc98cdd05746c1232eee979e134680a47b53f14f484a35aaf4ece9487e1010f4240ed76d2acf6dc641b66ed1c1d331d663ff47ba749f8f50f7188f9e6c230944b01 0x41 0xe586a5bd52a49f3a7be3dbd3d03f5401f8d0d5b512e0d338a594cd09caad40234af81dca46da41e9926ec601655635af8d1ec75e8864808885ecf1c2555afdf801 0x4c69 0x52210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179821038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f515082103363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff464053ae", "HASH160 0x14 0xc9e4a896d149702d0d1695434feddd52e24ad78d EQUAL", "P2SH", "P2SH(2-of-3)" ], [ - "0x41 0x98b330e1a8662c34ec3982e1db35a1409a7a472db6bcb0db7af4a02bf00b051affd2a4dfd70a96aea9b08e64e984e79c963407f62d9b7ff622dfd4438468b88801", + "0x41 0x4196ce2d3cfbb5f81aa894153cbf59a6a07281a8b2beb14f0d5ba034f9a5c41de0f5f4a2d9d932c961e1e500bdae14dac64cc0ed5ede10cb7df62a2616a618cd01", "0x41 0x0679be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 CHECKSIG", "", "P2PK with hybrid pubkey but no STRICTENC" ], [ - "0 0x41 0x881e9d32f9d565dd4097fe5816bfb1d7196a27b4e83cb246f061f37844418d972d9feb51be3d6308061841284143cd72223a09afce1817b6377e4fd430da105301", + "0 0x41 0x5d781335e74c423e6b5b26b20b3fe6760e0ce4395f16462a8f69c019661618af0550aad9d20c56b8b156a33aa428f3b026a4b79c807a500df5f9c4de3b3cc21d01", "1 0x41 0x0679be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 2 CHECKMULTISIG", "", "1-of-2 with the second 1 hybrid pubkey and no STRICTENC" ], [ - "0 0x41 0x881e9d32f9d565dd4097fe5816bfb1d7196a27b4e83cb246f061f37844418d972d9feb51be3d6308061841284143cd72223a09afce1817b6377e4fd430da105301", + "0 0x41 0x5d781335e74c423e6b5b26b20b3fe6760e0ce4395f16462a8f69c019661618af0550aad9d20c56b8b156a33aa428f3b026a4b79c807a500df5f9c4de3b3cc21d01", "1 0x41 0x0679be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 2 CHECKMULTISIG", "STRICTENC", "1-of-2 with the second 1 hybrid pubkey" ], [ - "0x41 0x3e97989da4fd193f094caaebbdb75522564604f90673bf276164522d3c0528003d039e65ced8d9a3b52299f75f25344b33a1b6d36f1946e3e62392f10a86677005", + "0x41 0x91896eb451aa34bedeedeb8e042c5de0d1774fa6151705eec402aa949523fad55c7067d80542f01892ff89ba1a703aca6adc9038f1d4e8541c66212512f4620505", "0x41 0x048282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f5150811f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf CHECKSIG", "", "P2PK with undefined hashtype but no STRICTENC" ], [ - "1 0x41 0x434260ba2a37f605c8c5959abd764d1785ed5678f5112875e8d708db790e0f4d6d7b42b291b2a66dae09140852f60e6ee37ab2c031387a6e8e2ba15179463bae01 0x41 0xe64e579c3cdb1c5d99ed3ac4dd73095554860eec64ac40924772138eb3e3765675decfb264e69865465fe3e7d84992791ed23be1d96b1b49f3eb5e6866ab83e601 0x41 0x095bce722466be45b3b110f8e92be4c3ae17abefccb73c84fbdd458b667646ea8b3dea40fccf036985e5dcd43ef1e6c781c99bcea36691d9f90ae958307cc48901", + "1 0x41 0xb852c8c7207c813acd1e002fb98a63327324db6474782558f1726750df6544a3b898c43bb0ddee5848c34e45b719cee1559d8d74b789eef83665d43dca5f243c01 0x41 0xd8bf0745999d38500ecc503ca0941c5d7103272428ca6733cad1ae4b19e97d0b021479b53242476dbab1b19d10c065d0373ffa01f0bfeb15e72c941ab7bc8c1b01 0x41 0xaaa573ffdcf283a4aa608b81540e0bab4a8d2aa2e8bffe030736831c3399e360c78eab9ebf8da9d98c6306409ad752fcbc762222828dc3e54a7d2594d7fb728b01", "3 0x21 0x0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 0x21 0x03363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640 3 CHECKMULTISIG", "", "3-of-3 with nonzero dummy but no NULLDUMMY" ], [ - "0 0x41 0x2d35edb5b8539821925fd0315e30882e7db9a1b4b697a0f339b77a3835216ffae2d196dd275901c78877942a44da3ad91bc9702e134545c5a7f4b5da4170fd8301 DUP", + "0 0x41 0xde2fb5c3ac521e16c92a44a31bffc213dbafbf39fc370ec3aab76e2af7e4be6d33f1dea322991d3921ca483fd3db8b9f5f3f9a42b6ca3e9b561d963887d7c8b101 DUP", "2 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 2 CHECKMULTISIG", "", "2-of-2 with two identical keys and sigs pushed using OP_DUP but no SIGPUSHONLY" ], [ - "0 0x41 0x2d35edb5b8539821925fd0315e30882e7db9a1b4b697a0f339b77a3835216ffae2d196dd275901c78877942a44da3ad91bc9702e134545c5a7f4b5da4170fd8301 0x41 0x2d35edb5b8539821925fd0315e30882e7db9a1b4b697a0f339b77a3835216ffae2d196dd275901c78877942a44da3ad91bc9702e134545c5a7f4b5da4170fd8301", + "0 0x41 0xde2fb5c3ac521e16c92a44a31bffc213dbafbf39fc370ec3aab76e2af7e4be6d33f1dea322991d3921ca483fd3db8b9f5f3f9a42b6ca3e9b561d963887d7c8b101 0x41 0xde2fb5c3ac521e16c92a44a31bffc213dbafbf39fc370ec3aab76e2af7e4be6d33f1dea322991d3921ca483fd3db8b9f5f3f9a42b6ca3e9b561d963887d7c8b101", "2 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 2 CHECKMULTISIG", "SIGPUSHONLY", "2-of-2 with two identical keys and sigs pushed" diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp index 9d9c2f9a41..e0b349b22d 100644 --- a/src/test/key_tests.cpp +++ b/src/test/key_tests.cpp @@ -172,11 +172,11 @@ BOOST_AUTO_TEST_CASE(key_test1) BOOST_CHECK(key1.Sign(hashMsg, detsig)); BOOST_CHECK(key1C.Sign(hashMsg, detsigc)); BOOST_CHECK(detsig == detsigc); - BOOST_CHECK_EQUAL(HexStr(detsig), "12cb87b6c94fab15d458e97ed5eeffdd6d0253c0711c5ee3097da3cef1c8ef071ec0f7f495ccb15d41cca8d371901fa5a649bd06d15e7f78b1627cceef333b11"); + BOOST_CHECK_EQUAL(HexStr(detsig), "66fd0c716c5d11ecc91fc2197af0e66cfd262ec2e6fb2819706930532d07b0236e43dd1586d12b6498173318c99e95413c8e9763b59a33cccd1328e880151e57"); BOOST_CHECK(key2.Sign(hashMsg, detsig)); BOOST_CHECK(key2C.Sign(hashMsg, detsigc)); BOOST_CHECK(detsig == detsigc); - BOOST_CHECK_EQUAL(HexStr(detsig), "7f4d0435d40be2a2c20a55720e901acf1ec5fc574fd04c41417c5f625d688be0939ec6f72a4823744cfa24c24dc98a6a9015dc391ace1c27d10db7abbbdca8f9"); + BOOST_CHECK_EQUAL(HexStr(detsig), "f7a0ff919b2c2282846f60bc319b99ddd82ee7f88b75a053a5005de5a992eea56413aa2f5c6167babac05c8a2171253aa63b6b16a0a1e72587bfc4c5e6c32547"); BOOST_CHECK(key1.SignCompact(hashMsg, detsig)); BOOST_CHECK(key1C.SignCompact(hashMsg, detsigc)); BOOST_CHECK_EQUAL(HexStr(detsig), "1c5dbbddda71772d95ce91cd2d14b592cfbc1dd0aabd6a394b6c2d377bbe59d31d14ddda21494a4e221f0824f0b8b924c43fa43c0ad57dccdaa11f81a6bd4582f6");