test: allow 3 bytes of fee overestimate in assert_fee_amount #36408

pull fametrano wants to merge 1 commits into bitcoin:master from fametrano:test-fee-tolerance-short-sig changing 1 files +3 −2
  1. fametrano commented at 6:53 AM on October 2, 2026: contributor

    The wallet sizes a transaction assuming a 71-byte low-R ECDSA signature. A signature whose r or s has leading zero bytes is shorter, so the fee can cover a few bytes more than the signed transaction needs. In #36394 the wallet estimated 219 bytes and paid 438 sat at 2 sat/vB, but the signed transaction was 216 bytes: the signature was 3 bytes short. That happens about once in 4 million signatures. assert_fee_amount allows only 2 bytes of overestimate, so the test failed.

    I raise the allowance to 3 bytes, which makes the failure about 200 times rarer. The check that the fee is not too low is unchanged. maflcko suggested 3 bytes in #24151 and #25164.

    Fixes #36394.

    Made with my usual tools: a computer, the Internet and an LLM. The mistakes, as usual, are all mine.

  2. test: allow 3 bytes of fee overestimate in assert_fee_amount
    The wallet sizes a transaction assuming 71-byte low-R ECDSA signatures.
    A signature whose r or s has leading zero bytes is shorter, so the fee
    can cover a few bytes more than the signed transaction needs. A
    signature 3 bytes short (about 1 in 4 million) made wallet_send.py fail
    with an estimate of 219 bytes for a 216-byte transaction.
    
    Allowing 3 bytes instead of 2 makes this about 200 times rarer. The
    check that the fee is not too low is unchanged.
    
    Fixes #36394.
    050409b2c5
  3. DrahtBot added the label Tests on Oct 2, 2026
  4. DrahtBot commented at 6:53 AM on October 2, 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.

    Type Reviewers
    ACK Ayoazeez26, ismaelsadeeq, sedited

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. Ayoazeez26 commented at 4:17 PM on October 4, 2026: none

    tACK 050409b2c5522eff0dc37c00a6d1225a8a437e17

    Tested on macOS with Python 3.14. wallet_send.py passes on this commit.

    I read through #36394 and the CI log there. Since running the test won't reproduce it (a 3-byte short signature is roughly 1 in 4 million), so I forced it instead by bumping the signature size in PKHDescriptor::MaxSatSize() from 71 to 74. That makes the wallet overestimate by 3 bytes on every run.

    On master with that change, wallet_send.py fails at the fee_rate=7 check:

    AssertionError: Fee of 0.00001554 BTC too high! (Should be 0.00001533 BTC)

    With 73 (+2) instead, the old check passes, as expected.

    With this PR and the same +3 change, all the assert_fee_amount checks pass. One more thing I noticed, with the +3 change, the run gets past all the fee checks but then fails in test_maxfeerate() with this error:

     test_framework.util.JSONRPCException: Fee rate exceeds maximum configured by user (maxfeerate) (-6)  [http_status=200]

    This is most likely from my +3 change but I thought it's worth noting.

  6. fametrano commented at 7:04 PM on November 1, 2026: contributor

    The test_maxfeerate() failure comes from your +3 change in MaxSatSize(), not from this PR. Thanks for testing.

    I ran wallet_send.py on 050409b2c5: unchanged it passes; with PKHDescriptor::MaxSatSize() bumped from 71 to 74 it fails as yours did. The fee_rate=7 check passes (1554 sat for 222 estimated vbytes, against 1533), and test_maxfeerate() fails at its last call, fee_rate=1.000 under -maxfeerate=0.00001009. The wallet sets the fee from the estimated size, but checks -maxfeerate against the signed one, here 218 or 219 vbytes: 222 sat is at least 1.013 sat/vB, over the 1.009 cap. This PR only changes assert_fee_amount, which test_maxfeerate() does not call.

  7. sedited requested review from ismaelsadeeq on Nov 6, 2026
  8. in test/functional/test_framework/util.py:66 in 050409b2c5
      62 | @@ -63,8 +63,9 @@ def assert_fee_amount(fee, tx_size, feerate_BTC_kvB):
      63 |      target_fee = get_fee(tx_size, feerate_BTC_kvB)
      64 |      if fee < target_fee:
      65 |          raise AssertionError("Fee of %s BTC too low! (Should be %s BTC)" % (str(fee), str(target_fee)))
      66 | -    # allow the wallet's estimation to be at most 2 bytes off
      67 | -    high_fee = get_fee(tx_size + 2, feerate_BTC_kvB)
      68 | +    # Allow the wallet's estimate to be up to 3 bytes over: a low-R ECDSA
    


    ismaelsadeeq commented at 2:46 PM on November 9, 2026:

    nit: comment here does not need to be adjusted, generic is fine.


    fametrano commented at 8:15 PM on November 10, 2026:

    Thanks. I'll change it back if I need to push again, or if it's needed for merge.

  9. ismaelsadeeq commented at 2:47 PM on November 9, 2026: member

    ACK 050409b2c5522eff0dc37c00a6d1225a8a437e17

    The change is correct. I did not verify the numbers claimed in OP and commit message.

  10. sedited approved
  11. sedited commented at 3:47 PM on November 12, 2026: contributor

    ACK 050409b2c5522eff0dc37c00a6d1225a8a437e17

  12. sedited commented at 3:52 PM on November 12, 2026: contributor

    @fametrano please do not tag people in pull request descriptions. The description is written into the git history.

  13. sedited merged this on Nov 12, 2026
  14. sedited closed this on Nov 12, 2026


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-11-18 16:51 UTC

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