test: reduce hash mod n for RFC6979 nonce #36634

pull fametrano wants to merge 1 commits into bitcoin:master from fametrano:test-rfc6979-bits2octets changing 1 files +14 −1
  1. fametrano commented at 10:41 PM on October 23, 2026: contributor

    sign_ecdsa(..., rfc6979=True) in the test framework derives the nonce from the raw message hash. RFC6979 section 2.3.4 (bits2octets) reduces the hash mod n first. libsecp256k1 has done so since 0.2.0. So for a hash >= n the framework's signature differs from libsecp256k1's, though it is still valid.

    This is a small, correct fix with a test. The test checks two signatures computed with libsecp256k1, one of them for a hash >= n, and fails without the fix. The change has no practical effect on current tests: the only caller, feature_taproot.py, signs double-SHA256 sighashes, which are >= n with probability about 2^-128. If reviewers see no benefit, feel free to close it.

    This is one of several PRs from a large audit of Bitcoin Core that I did with the help of LLM tools. The audit produced its evidence all at once, which is why the PRs arrive together. I understand each change fully and will answer review questions myself.

  2. test: reduce hash mod n for RFC6979 nonce
    RFC6979 section 2.3.4 (bits2octets) reduces the message hash modulo the
    group order before it enters the nonce derivation. libsecp256k1 has
    done so since 0.2.0. The test framework used the raw hash, so for a
    hash >= n its deterministic signature differed from libsecp256k1's.
    
    Add a test with signatures computed by libsecp256k1, one of them for a
    hash >= n.
    bb96838c9d
  3. DrahtBot added the label Tests on Oct 23, 2026
  4. DrahtBot commented at 10:41 PM on October 23, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

Contributors
Labels

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-10-29 06:51 UTC

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