BIP374: fix division logic in __truediv__ method of FE class #1773

pull brawncode wants to merge 1 commits into bitcoin:master from brawncode:patch-2 changing 1 files +1 −1
  1. brawncode commented at 7:20 PM on February 25, 2025: contributor

    I noticed an issue in the __truediv__ method of the FE class where the division was being performed incorrectly. The method was returning FE(self, a), which doesn’t account for the numerator and denominator fields (_num and _den).

    To fix this, I’ve updated the code to return FE(self._num, self._den * a), which properly creates a new FE object with the same numerator and the denominator multiplied by the given argument a.

  2. fix: Fix division logic in __truediv__ method of FE class e1789b6b5b
  3. jonatack renamed this:
    fix: Fix division logic in __truediv__ method of FE class
    BIP374: fix division logic in __truediv__ method of FE class
    on Feb 25, 2025
  4. jonatack added the label Bug fix on Feb 25, 2025
  5. murchandamus commented at 7:43 PM on February 25, 2025: member
  6. stratospher commented at 3:51 AM on February 26, 2025: contributor

    don't think there's a problem since the initialiser method has support for both FE and int. see code comments in the __init__ method.

    this line - https://github.com/bitcoin/bips/blob/6d2f0d64fc226661bd8dced658aca8c575fb42e1/bip-0374/secp256k1.py#L34-L36 sets the numerator and denominator (_num and _den) with self's numerator and denominator. so we don't need to pass them separately to the initialiser method.

  7. andrewtoth commented at 2:49 PM on February 26, 2025: contributor

    This file was mostly taken from https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/crypto/secp256k1.py#L79-L81, so should likely be fixed upstream if it's a problem.

  8. murchandamus added the label PR Author action required on Feb 26, 2025
  9. jonatack removed the label Bug fix on Feb 26, 2025
  10. jonatack commented at 10:36 PM on February 26, 2025: member

    Seems best to close here unless the reference implementation in libsecp changes or is incorrect, @brawncode what do you think?

  11. murchandamus removed the label PR Author action required on Feb 27, 2025
  12. jonatack commented at 11:48 PM on February 27, 2025: member

    @brawncode feel free to comment here if there is a reason to re-open this.

  13. jonatack closed this on Feb 27, 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: 2026-06-25 09:10 UTC

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