test: fix length of R check in key_signature_tests #20248

pull dgpv wants to merge 1 commits into bitcoin:master from dgpv:fix-test-key-signature-low-r changing 1 files +16 −6
  1. dgpv commented at 5:07 PM on October 26, 2020: contributor

    The code before the fix only checked the length of R value of the last signature in the loop, and only for equality (but the length can be less than 32)

    The fixed code checks that length of the R value is less than or equal to 32 on each iteration of the loop

  2. DrahtBot added the label Tests on Oct 26, 2020
  3. fanquake renamed this:
    Fix test: length of R check in test/key_tests.cpp:key_signature_tests
    test: fix length of R check in key_signature_tests
    on Oct 27, 2020
  4. theStack approved
  5. theStack commented at 8:58 PM on November 15, 2020: member

    ACK 0d96e2ff6fd68324dedf9b0963c775cc01c29998

  6. in src/test/key_tests.cpp:183 in 0d96e2ff6f outdated
     180 |          sig.clear();
     181 |          std::string msg = "A message to be signed" + ToString(i);
     182 |          msg_hash = Hash(msg);
     183 |          BOOST_CHECK(key.Sign(msg_hash, sig));
     184 | -        found = sig[3] == 0x20;
     185 | +        BOOST_CHECK(sig[3] <= 0x20);
    


    laanwj commented at 11:13 AM on November 19, 2020:

    BOOST_CHECK is fairly slow, this is likely why it is not used in the inner loop directly.


    dgpv commented at 11:32 AM on November 19, 2020:

    Do you think it would be better to do

    if( sig[3] > 0x20 ) {
        found_big = true;
        break;
    }
    

    and then BOOST_CHECK(!found_big) after the loop ?

    Also there is BOOST_CHECK for key.Sign() inside the loop, do you think it should be taken outside the loop, too ?


    laanwj commented at 3:08 PM on November 23, 2020:

    Yes, I think it's better to keep it in a similar way as it is now, assign to a boolean then assert that after the loop.

    Also there is BOOST_CHECK for key.Sign() inside the loop, do you think it should be taken outside the loop, too ?

    Probably! I mean, a loop of 256 isn't that bad, I guess, but there's no reason a tl east to make things worse.

  7. dgpv force-pushed on Nov 25, 2020
  8. Fix length of R check in test/key_tests.cpp:key_signature_tests
    The code before the fix only checked the length of R value of the last
    signature in the loop, and only for equality (but the length can be
    less than 32)
    
    The fixed code checks that length of the R value is less than or equal
    to 32 on each iteration of the loop
    
    The BOOST_CHECK(sig.size() <= 70) is merged with sig[3] <= 32 check,
    and BOOST_CHECKs are moved outside the loop, for efficiency
    89895773b7
  9. dgpv commented at 1:07 PM on November 25, 2020: contributor

    rebased

    merged checks of sig.size() <= 70 and sig[3] <= 32 (with added comment)

    moved BOOST_CHECKs out of the loop

    fixed a comment ("less than or equal to 70", not "less than 70")

  10. laanwj commented at 6:23 PM on December 16, 2020: member

    ACK 89895773b72275a620951730aef0b52e9437bc13

  11. laanwj merged this on Dec 16, 2020
  12. laanwj closed this on Dec 16, 2020

  13. sidhujag referenced this in commit 9e877e8f71 on Dec 17, 2020
  14. DrahtBot locked this on Feb 15, 2022
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-05-02 03:14 UTC

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