BIP374: add subtraction operator for GE class #1779

pull VolodymyrBg wants to merge 1 commits into bitcoin:master from VolodymyrBg:AE5959595959 changing 2 files +6 −3
  1. VolodymyrBg commented at 3:19 pm on March 2, 2025: contributor

    This commit implements the subtraction operator (sub) for the GE (Group Element) class in the secp256k1.py file as requested in the TODO comment in reference.py.

    The implementation is straightforward, leveraging the existing neg method to define subtraction as addition with the negated element: self + (-a).

    After implementing the operator, the code in reference.py was simplified by replacing expressions like: s * G + (-e * A) with s * G - e * A

    This makes the code more readable and directly matches the mathematical notation used in the BIP-0374 specification.

  2. jonatack added the label Proposed BIP modification on Mar 10, 2025
  3. jonatack added the label Pending acceptance on Mar 10, 2025
  4. jonatack commented at 9:00 pm on March 10, 2025: member
  5. jonatack commented at 7:03 pm on April 14, 2025: member
    Note that the red CI here can be ignored; it is unrelated to this PR and is fixed on the master branch.
  6. jonatack commented at 7:04 pm on April 14, 2025: member
    Pinging BIP authors @theStack @andrewtoth @RubenSomsen for yay or nay on this change.
  7. in bip-0374/reference.py:90 in 1434c8b49c outdated
    86@@ -87,11 +87,11 @@ def dleq_verify_proof(
    87     s = int.from_bytes(proof[32:], "big")
    88     if s >= GE.ORDER:
    89         return False
    90-    # TODO: implement subtraction operator (__sub__) for GE class to simplify these terms
    91-    R1 = s * G + (-e * A)
    92+    # Implemented subtraction operator (__sub__) for GE class to simplify these terms
    


    theStack commented at 10:48 pm on April 14, 2025:

    After the TODO is implemented, this comment line doesn’t serve a purpose anymore and can just be removed (it sounds more like a commit message).

  8. theStack commented at 11:03 pm on April 14, 2025: contributor

    Concept ACK

    Even though it’s a tiny cosmetic change, it’s slightly more readable as it matches the formula in BIP directly. The subtraction operator implementation matches the one in secp256k1lab, a library which might be used in the future to unify all reference implementations in the BIPs repo that use the secp256k1 curve (it’s still unclear on how to exactly do this though).

    Nit: I think the two commits could just be squashed, with a descriptive commit message? Not sure how strict we are in the BIPs repo, but the new operator shouldn’t be used before it’s introduced, so if you plan to keep it divided into two commits, they should be swapped.

  9. Implement subtraction operator for GE class in BIP-0374 reference code
    This commit implements the subtraction operator (sub) for the GE (Group Element) class in the secp256k1.py file as requested in the TODO comment in reference.py.
    
    The implementation is straightforward, leveraging the existing neg method to define subtraction as addition with the negated element: self + (-a).
    
    After implementing the operator, the code in reference.py was simplified by replacing expressions like:
    s * G + (-e * A) with s * G - e * A
    
    This makes the code more readable and directly matches the mathematical notation used in the BIP-0374 specification.
    
    Co-Authored-By: Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
    7c80a699ff
  10. VolodymyrBg force-pushed on Apr 15, 2025
  11. VolodymyrBg commented at 11:39 am on April 15, 2025: contributor

    Concept ACK

    Even though it’s a tiny cosmetic change, it’s slightly more readable as it matches the formula in BIP directly. The subtraction operator implementation matches the one in secp256k1lab, a library which might be used in the future to unify all reference implementations in the BIPs repo that use the secp256k1 curve (it’s still unclear on how to exactly do this though).

    Nit: I think the two commits could just be squashed, with a descriptive commit message? Not sure how strict we are in the BIPs repo, but the new operator shouldn’t be used before it’s introduced, so if you plan to keep it divided into two commits, they should be swapped.

    Done

  12. VolodymyrBg requested review from theStack on Apr 15, 2025
  13. jonatack renamed this:
    Implement subtraction operator for GE class in BIP-0374 reference code
    BIP374: add subtraction operator for GE class
    on Apr 15, 2025
  14. andrewtoth approved
  15. andrewtoth commented at 1:45 pm on April 16, 2025: contributor
    ACK 7c80a699ffdb3dd5beb292e0b9324acd35c3a79f
  16. jonatack commented at 2:08 pm on April 16, 2025: member
    ACK
  17. jonatack merged this on Apr 16, 2025
  18. jonatack closed this on Apr 16, 2025


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bips. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-04-19 01:10 UTC

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