test: remove unused function xor_bytes #21100

pull theStack wants to merge 1 commits into bitcoin:master from theStack:2021-test-remove_unused_xor_bytes changing 1 files +1 −5
  1. theStack commented at 1:15 PM on February 7, 2021: member

    The function xor_bytes was introduced in commit 3c226639eb134314a0640d34e4ccb6148dbde22f (#19953, BIP340-342 validation), even code-reviewed, but actually never used. The default signing algorithm in BIP340 needs a xor operation, but this step is currently done by a single xor operation on large integer operands:

    t = (sec ^ int.from_bytes(TaggedHash("BIP0340/aux", aux), 'big')).to_bytes(32, 'big')
    

    Alternatively, we could keep the function and as well use it:

    --- a/test/functional/test_framework/key.py
    +++ b/test/functional/test_framework/key.py
    @@ -492,7 +492,7 @@ def sign_schnorr(key, msg, aux=None, flip_p=False, flip_r=False):
         P = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, sec)]))
         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')
    +    t = xor_bytes(sec.to_bytes(32, 'big'), TaggedHash("BIP0340/aux", aux))
         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)]))
    
  2. fanquake added the label Tests on Feb 7, 2021
  3. fanquake commented at 3:35 AM on February 9, 2021: member

    According to vulture there is more unused code in the same file:

    bitcoin/test/functional/test_framework/key.py:27: unused function 'xor_bytes' (60% confidence)
    bitcoin/test/functional/test_framework/key.py:277: unused method 'verify_ecdsa' (60% confidence)
    bitcoin/test/functional/test_framework/key.py:517: unused variable 'sign_pubkey' (60% confidence)
    
  4. test: remove unused function xor_bytes f64adc1eed
  5. theStack commented at 9:45 PM on February 9, 2021: member

    @fanquake: Thanks for pointing out. verify_ecdsa is indeed unused, but was in the dead-code linters whitelist since its introduction (removed recently in https://github.com/bitcoin/bitcoin/pull/16961/commits/f4beb4996d27f2cdaf4f0a63e7dc044bf17decce), so I guess the community's wish is to keep it (to have a complete Python ECDSA implementation)? Force-pushed now with the change of replacing sign_pubkey with an underscore.

  6. theStack force-pushed on Feb 9, 2021
  7. practicalswift commented at 9:11 PM on February 10, 2021: contributor

    cr ACK f64adc1eedff9d342b49d7e6428b2da21130c23c: untested unused code should be removed

  8. MarcoFalke merged this on Feb 15, 2021
  9. MarcoFalke closed this on Feb 15, 2021

  10. sidhujag referenced this in commit a8d91fa832 on Feb 15, 2021
  11. DrahtBot locked this on Aug 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 21:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me