tests: Add fuzzing harness for CScript and CScriptNum operations #18176

pull practicalswift wants to merge 4 commits into bitcoin:master from practicalswift:fuzzers-script_ops changing 6 files +239 −3
  1. practicalswift commented at 7:23 PM on February 18, 2020: contributor

    Add fuzzing harness for CScript and CScriptNum operations.

    Test this PR using:

    $ make distclean
    $ ./autogen.sh
    $ CC=clang CXX=clang++ ./configure --enable-fuzz \
          --with-sanitizers=address,fuzzer,undefined
    $ make
    $ src/test/fuzz/script_ops
    …
    $ src/test/fuzz/scriptnum_ops
    …
    
  2. practicalswift force-pushed on Feb 18, 2020
  3. DrahtBot added the label Build system on Feb 18, 2020
  4. DrahtBot added the label Tests on Feb 18, 2020
  5. MarcoFalke removed the label Build system on Feb 18, 2020
  6. MarcoFalke commented at 7:51 PM on February 18, 2020: member

    ACK 0730ac98c61f895893d40cb0fdff4cd7339a11b0

  7. DrahtBot commented at 9:30 PM on February 18, 2020: member

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

  8. practicalswift force-pushed on Feb 19, 2020
  9. practicalswift force-pushed on Feb 19, 2020
  10. practicalswift renamed this:
    tests: Add fuzzing harness for CScript operations
    tests: Add fuzzing harness for CScript and CScriptNum operations
    on Feb 19, 2020
  11. practicalswift commented at 4:52 PM on February 19, 2020: contributor

    @MarcoFalke Added CScriptNum fuzzer too. Moved common functions to fuzz.h. Please re-review :)

  12. practicalswift force-pushed on Feb 19, 2020
  13. practicalswift force-pushed on Feb 26, 2020
  14. in src/test/fuzz/scriptnum_ops.cpp:37 in f137f64cde outdated
      32 | +        switch (fuzzed_data_provider.ConsumeIntegralInRange(0, 26)) {
      33 | +        case 0:
      34 | +            (void)(script_num == fuzzed_data_provider.ConsumeIntegral<int64_t>());
      35 | +            break;
      36 | +        case 1:
      37 | +            (void)(script_num != fuzzed_data_provider.ConsumeIntegral<int64_t>());
    


    MarcoFalke commented at 10:19 PM on March 7, 2020:

    Can combine case 0 and 1?

    const auto int = fuzzed_data_provider.ConsumeIntegral<int64_t>()
    (script_num == int) != (script_num != int)
    

    practicalswift commented at 4:57 PM on March 9, 2020:

    Fixed!

  15. in src/test/fuzz/scriptnum_ops.cpp:46 in f137f64cde outdated
      41 | +            break;
      42 | +        case 3:
      43 | +            (void)(script_num < fuzzed_data_provider.ConsumeIntegral<int64_t>());
      44 | +            break;
      45 | +        case 4:
      46 | +            (void)(script_num >= fuzzed_data_provider.ConsumeIntegral<int64_t>());
    


    MarcoFalke commented at 10:19 PM on March 7, 2020:

    Same here:

    (s_n < int) != (s_n >= int)
    

    practicalswift commented at 4:58 PM on March 9, 2020:

    Fixed!

  16. in src/test/fuzz/scriptnum_ops.cpp:49 in f137f64cde outdated
      44 | +            break;
      45 | +        case 4:
      46 | +            (void)(script_num >= fuzzed_data_provider.ConsumeIntegral<int64_t>());
      47 | +            break;
      48 | +        case 5:
      49 | +            (void)(script_num > fuzzed_data_provider.ConsumeIntegral<int64_t>());
    


    MarcoFalke commented at 10:20 PM on March 7, 2020:

    Same here:

    (s_n > int ) != (s_n <= int)
    

    practicalswift commented at 4:57 PM on March 9, 2020:

    Fixed!

  17. in src/test/fuzz/scriptnum_ops.cpp:67 in f137f64cde outdated
      62 | +            break;
      63 | +        case 10:
      64 | +            (void)(script_num >= ConsumeScriptNum(fuzzed_data_provider));
      65 | +            break;
      66 | +        case 11:
      67 | +            (void)(script_num > ConsumeScriptNum(fuzzed_data_provider));
    


    MarcoFalke commented at 10:20 PM on March 7, 2020:

    Same for all of these


    practicalswift commented at 4:58 PM on March 9, 2020:

    Fixed!

  18. in src/test/fuzz/scriptnum_ops.cpp:73 in f137f64cde outdated
      68 | +            break;
      69 | +        case 12:
      70 | +            script_num = script_num + fuzzed_data_provider.ConsumeIntegral<int64_t>();
      71 | +            break;
      72 | +        case 13:
      73 | +            script_num = script_num - fuzzed_data_provider.ConsumeIntegral<int64_t>();
    


    MarcoFalke commented at 10:22 PM on March 7, 2020:

    Could combine these?

    (script_num - int ) + int == script_num
    (script_num + int ) - int == script_num
    

    practicalswift commented at 4:57 PM on March 9, 2020:

    Fixed!

  19. in src/test/fuzz/scriptnum_ops.cpp:79 in f137f64cde outdated
      74 | +            break;
      75 | +        case 14:
      76 | +            script_num = script_num + ConsumeScriptNum(fuzzed_data_provider);
      77 | +            break;
      78 | +        case 15:
      79 | +            script_num = script_num - ConsumeScriptNum(fuzzed_data_provider);
    


    MarcoFalke commented at 10:23 PM on March 7, 2020:

    Same here and below?


    practicalswift commented at 4:57 PM on March 9, 2020:

    Fixed!

  20. MarcoFalke approved
  21. MarcoFalke commented at 10:25 PM on March 7, 2020: member

    ACK

  22. practicalswift force-pushed on Mar 9, 2020
  23. practicalswift commented at 4:58 PM on March 9, 2020: contributor

    @MarcoFalke Thanks for reviewing. All feedback addressed. Please re-review :)

  24. DrahtBot added the label Needs rebase on Mar 9, 2020
  25. tests: Add common Consume* fuzzing functions eb7c50ca1f
  26. tests: Add fuzzing harness for CScript operations 65a52a0024
  27. practicalswift force-pushed on Mar 9, 2020
  28. practicalswift commented at 7:25 PM on March 9, 2020: contributor

    Rebased again :)

  29. in src/test/fuzz/scriptnum_ops.cpp:37 in 4532649328 outdated
      40 | +            assert((script_num <= i) != script_num > i);
      41 | +            break;
      42 | +        }
      43 | +        case 2: {
      44 | +            const int64_t i = fuzzed_data_provider.ConsumeIntegral<int64_t>();
      45 | +            assert((script_num >= i) != (script_num < i));
    


    MarcoFalke commented at 8:08 PM on March 9, 2020:

    in commit 4532649328ad5056f9ae2bf99f3aba2212bdc785:

    Any reason those are separate cases for the fuzzer to find? They can all be executed in the same case:

                 assert((script_num == i) != (script_num != i));
                 assert((script_num <= i) != script_num > i);
                 assert((script_num >= i) != (script_num < i));
    

    practicalswift commented at 8:40 PM on March 9, 2020:

    Oh, of course. Now fixed. Thanks!

  30. in src/test/fuzz/scriptnum_ops.cpp:60 in 4532649328 outdated
      55 | +            assert((script_num <= sn) != (script_num > sn));
      56 | +            break;
      57 | +        }
      58 | +        case 5: {
      59 | +            const CScriptNum sn = ConsumeScriptNum(fuzzed_data_provider);
      60 | +            assert((script_num >= sn) != (script_num < sn));
    


    MarcoFalke commented at 8:08 PM on March 9, 2020:

    Same here

  31. in src/test/fuzz/scriptnum_ops.cpp:82 in 4532649328 outdated
      77 | +        case 7: {
      78 | +            const CScriptNum sn = ConsumeScriptNum(fuzzed_data_provider);
      79 | +            // Avoid signed integer overflow:
      80 | +            // script/script.h:264:93: runtime error: signed integer overflow: -9223126527765971126 + -9223372036854756825 cannot be represented in type 'long'
      81 | +            if (IsValidAddition(script_num, sn)) {
      82 | +                assert((script_num + sn) - sn == script_num);
    


    MarcoFalke commented at 8:11 PM on March 9, 2020:

    Same here

  32. in src/test/fuzz/scriptnum_ops.cpp:160 in 4532649328 outdated
     155 | +            // Avoid negation failure:
     156 | +            // script/script.h:332:35: runtime error: negation of -9223372036854775808 cannot be represented in type 'int64_t' (aka 'long'); cast to an unsigned type to negate this value to itself
     157 | +            if (script_num == CScriptNum{std::numeric_limits<int64_t>::min()}) {
     158 | +                break;
     159 | +            }
     160 | +            (void)script_num.getvch();
    


    MarcoFalke commented at 8:13 PM on March 9, 2020:

    Also in commit 4532649:

    No input is consumed from the fuzzer, so this doesn't need to be special cased and can be executed unconditionally?


    practicalswift commented at 8:40 PM on March 9, 2020:

    True! Fixed.

  33. MarcoFalke approved
  34. MarcoFalke commented at 8:14 PM on March 9, 2020: member

    ACK ad040fc2a503a0a5c7097dfe8aa6d341901436d9 👦

    <details><summary>Show signature and timestamp</summary>

    Signature:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    ACK ad040fc2a503a0a5c7097dfe8aa6d341901436d9 👦
    -----BEGIN PGP SIGNATURE-----
    
    iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
    pUgKHwv+OE49ZDbtGMchMWXzOuFyxStj7biNTlNtYQH2AIBvgxPl2zZbczejRMMA
    xbUrKDh3SiE+mzPNyzOZ69XejxNGCTX1Kfel22F/XIwbKDw2kFv0v1F39pYyp4ZV
    j7/CLVpqZaWdgqcdFvE5tYCBcflm/6bU95TabNkv3yjsZ0XEy7WGaGJTRsgeMoQd
    wHIOc6kZerms8G04U/84PtHJBO4x0pU4zk2PRiEv9IcYYkAUFh1NDgIoJ+8MH9bt
    uuSjVmOzKmbuc5mrq8VFbvgeHJlIBWtjNP7Ux2OkvUCxGeUDoMOluO4MlME/tZVQ
    VJAQ6ZdOHSp032e5aOs9A9rwU+S6SlGxuoBlrjvK5vZm/nTwM8QXTU+hgza8hcdj
    7IWPhHIFiEExdYRd31q/aZ7kU4fpp9GaD4jXq+5hiAFso2jkWTxAIH3sdIn0ilKp
    +XxdLNNDSevd2KlCZK/DiwtTvU/Hp6WDPG9JW1YG0DS6jV1VeDmoacoN5M1hMYQz
    8kqbBKQP
    =dRzS
    -----END PGP SIGNATURE-----
    

    Timestamp of file with hash 009db7b3b5d4284568143d3ed9fcbb2849ef578b5853b7f040cd0dd8c4f64f5f -

    </details>

  35. tests: Add fuzzing harness for CScriptNum operations e7ddbd9893
  36. Make lifetime correctness easier to see (avoid reference lifetime extension) e37f53648e
  37. practicalswift force-pushed on Mar 9, 2020
  38. DrahtBot removed the label Needs rebase on Mar 9, 2020
  39. MarcoFalke commented at 3:01 AM on March 10, 2020: member

    ACK e37f53648e3acc6aea75adafec4de2bdbd8cb293 🦂

    <details><summary>Show signature and timestamp</summary>

    Signature:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    ACK e37f53648e3acc6aea75adafec4de2bdbd8cb293 🦂
    -----BEGIN PGP SIGNATURE-----
    
    iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
    pUiTxwv/fFqtr5Cy14W/HZr4I58Tpz3S86mobLUDaulSWhFpMz8b38ilBC5ltwIH
    rOznRDmgl46dP3YPMU07vCM2LS39DZyQH8uLTbECZw1aP5/x+XHb7me4aN/Ws1hB
    tvD5zKvFcFnw+wbmkStYqDMaNKH2vFOSJKhWckcRouaB+fwZLNMzps1CH7tqixVg
    Yo6i/PfETRSK9FveNFzbhSvhpGozLuFkqr0p5XyVWG42DxyOfe61VJP+e5RtlUFb
    QUPiEZnm2UFgy3DFhPGw0y2Gz81kDvW5H3RD+nKxg2FmXeBuQlNpos/naAqq1pQ1
    WsNtbwzJw5mrvxWvtALFFzvkBOv1W7kjes987ojGLQscMCtb1N/ZTb81sUSRzkW/
    L5AkNgnyP8d6WFvzuztTgLt7ZxM/0hTJtIO3x1qC/VySZKR2Enhh/DrOACKQ8u0s
    x3uTHh0e4qcOMz/6gKlMO2Boq48EUmUTNOSNY/95XY+0A5J7c6v6NuFIvhHq8Jfj
    1N+3Xt0G
    =AMUq
    -----END PGP SIGNATURE-----
    

    Timestamp of file with hash de3f5a712c02cb66b6ad6e76c0ec5a38c880d09962e085e811ec889daf153c65 -

    </details>

  40. MarcoFalke merged this on Mar 10, 2020
  41. MarcoFalke closed this on Mar 10, 2020

  42. sidhujag referenced this in commit 779929e7d8 on Mar 11, 2020
  43. sidhujag referenced this in commit cdb0fd7821 on Nov 10, 2020
  44. Fabcien referenced this in commit 829a5e64a8 on Jan 19, 2021
  45. practicalswift deleted the branch on Apr 10, 2021
  46. kittywhiskers referenced this in commit 99f7cb8537 on May 7, 2022
  47. kittywhiskers referenced this in commit d25b4b381f on May 7, 2022
  48. kittywhiskers referenced this in commit d096c9e8d2 on Jun 14, 2022
  49. kittywhiskers referenced this in commit d59f912263 on Jun 14, 2022
  50. kittywhiskers referenced this in commit a28b3141f6 on Jun 18, 2022
  51. kittywhiskers referenced this in commit ce5b149c68 on Jul 4, 2022
  52. kittywhiskers referenced this in commit b6199c79fb on Jul 4, 2022
  53. kittywhiskers referenced this in commit a1808aa93f on Jul 6, 2022
  54. kittywhiskers referenced this in commit f319ddbe85 on Jul 6, 2022
  55. PastaPastaPasta referenced this in commit eefdae1a53 on Jul 12, 2022
  56. knst referenced this in commit 0a9addaff7 on Jul 21, 2022
  57. DrahtBot locked this on Aug 18, 2022

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-04-16 15:14 UTC

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