mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-24 19:02:42 +02:00
test: add script compression coverage for not-on-curve P2PK outputs
This commit is contained in:
parent
651fb034d8
commit
28287cfbe1
@ -4,6 +4,7 @@
|
||||
|
||||
#include <compressor.h>
|
||||
#include <script/script.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
#include <stdint.h>
|
||||
@ -131,4 +132,36 @@ BOOST_AUTO_TEST_CASE(compress_script_to_uncompressed_pubkey_id)
|
||||
BOOST_CHECK_EQUAL(out[0], 0x04 | (script[65] & 0x01)); // least significant bit (lsb) of last char of pubkey is mapped into out[0]
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compress_p2pk_scripts_not_on_curve)
|
||||
{
|
||||
XOnlyPubKey x_not_on_curve;
|
||||
do {
|
||||
x_not_on_curve = XOnlyPubKey(g_insecure_rand_ctx.randbytes(32));
|
||||
} while (x_not_on_curve.IsFullyValid());
|
||||
|
||||
// Check that P2PK script with uncompressed pubkey [=> OP_PUSH65 <0x04 .....> OP_CHECKSIG]
|
||||
// which is not fully valid (i.e. point is not on curve) can't be compressed
|
||||
std::vector<unsigned char> pubkey_raw(65, 0);
|
||||
pubkey_raw[0] = 4;
|
||||
std::copy(x_not_on_curve.begin(), x_not_on_curve.end(), &pubkey_raw[1]);
|
||||
CPubKey pubkey_not_on_curve(pubkey_raw);
|
||||
assert(pubkey_not_on_curve.IsValid());
|
||||
assert(!pubkey_not_on_curve.IsFullyValid());
|
||||
CScript script = CScript() << ToByteVector(pubkey_not_on_curve) << OP_CHECKSIG;
|
||||
BOOST_CHECK_EQUAL(script.size(), 67U);
|
||||
|
||||
CompressedScript out;
|
||||
bool done = CompressScript(script, out);
|
||||
BOOST_CHECK_EQUAL(done, false);
|
||||
|
||||
// Check that compressed P2PK script with uncompressed pubkey that is not fully
|
||||
// valid (i.e. x coordinate of the pubkey is not on curve) can't be decompressed
|
||||
CompressedScript compressed_script(x_not_on_curve.begin(), x_not_on_curve.end());
|
||||
for (unsigned int compression_id : {4, 5}) {
|
||||
CScript uncompressed_script;
|
||||
bool success = DecompressScript(uncompressed_script, compression_id, compressed_script);
|
||||
BOOST_CHECK_EQUAL(success, false);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
x
Reference in New Issue
Block a user