diff options
author | Pieter Wuille <pieter@wuille.net> | 2020-09-13 22:20:17 -0700 |
---|---|---|
committer | Pieter Wuille <pieter@wuille.net> | 2020-10-12 17:18:47 -0700 |
commit | f06e6d03452cf5e0b1a0863afb08c9e6d3ef452e (patch) | |
tree | 244793b4e215b6a6c0d8fc008530e65bd9f2bd7b /test/functional/test_framework/key.py | |
parent | 3c226639eb134314a0640d34e4ccb6148dbde22f (diff) | |
download | bitcoin-f06e6d03452cf5e0b1a0863afb08c9e6d3ef452e.tar.xz |
tests: functional tests for Schnorr/Taproot/Tapscript
A large functional test is added that automatically generates random transactions which
exercise various aspects of the new rules, and verifies they are accepted into the mempool
(when appropriate), and correctly accepted/rejected in (Python-constructed) blocks.
Includes sighashing code and many tests by Johnson Lau.
Includes a test by Matthew Zipkin.
Includes several tests and improvements by Greg Sanders.
Diffstat (limited to 'test/functional/test_framework/key.py')
-rw-r--r-- | test/functional/test_framework/key.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/test/functional/test_framework/key.py b/test/functional/test_framework/key.py index c9f09a31aa..17b869e542 100644 --- a/test/functional/test_framework/key.py +++ b/test/functional/test_framework/key.py @@ -476,7 +476,7 @@ def verify_schnorr(key, sig, msg): return False return True -def sign_schnorr(key, msg, aux=None): +def sign_schnorr(key, msg, aux=None, flip_p=False, flip_r=False): """Create a Schnorr signature (see BIP 340).""" if aux is None: @@ -490,13 +490,13 @@ def sign_schnorr(key, msg, aux=None): if sec == 0 or sec >= SECP256K1_ORDER: return None P = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, sec)])) - if not SECP256K1.has_even_y(P): + if SECP256K1.has_even_y(P) == flip_p: sec = SECP256K1_ORDER - sec t = (sec ^ int.from_bytes(TaggedHash("BIP0340/aux", aux), 'big')).to_bytes(32, 'big') kp = int.from_bytes(TaggedHash("BIP0340/nonce", t + P[0].to_bytes(32, 'big') + msg), 'big') % SECP256K1_ORDER assert kp != 0 R = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, kp)])) - k = kp if SECP256K1.has_even_y(R) else SECP256K1_ORDER - kp + k = kp if SECP256K1.has_even_y(R) != flip_r else SECP256K1_ORDER - kp e = int.from_bytes(TaggedHash("BIP0340/challenge", R[0].to_bytes(32, 'big') + P[0].to_bytes(32, 'big') + msg), 'big') % SECP256K1_ORDER return R[0].to_bytes(32, 'big') + ((k + e * sec) % SECP256K1_ORDER).to_bytes(32, 'big') |