test: check for all possible OP_CLTV fail reasons in feature_cltv.py (BIP 65) #19801

pull theStack wants to merge 4 commits into bitcoin:master from theStack:20200825-test-check-all-failure-reasons-for-CLTV changing 1 files +111 −61
  1. theStack commented at 1:52 PM on August 25, 2020: member

    The functional test for BIP65 / OP_CHECKLOCKTIMEVERIFY (feature_cltv.py) currently only tests one out of five conditions that lead to failure of the op-code -- by prepending the script OP_1NEGATE OP_CHECKLOCKTIMEVERIFY OP_DROP to a tx's first input's scriptSig, the case of "the top item on the stack is less than 0" is checked:

    https://github.com/bitcoin/bitcoin/blob/f8462a6d2794be728cf8550f45d19a354aae59cf/test/functional/feature_cltv.py#L26-L35

    This PR adds the other cases (5 in total) by taking an integer argument to the function cltv_invalidate that is called in a loop instead of only once per testing scenario. Here is the full list of failure conditions and how they are tested (note that the scriptSig should still be valid before activation of BIP65, when OP_CLTV is simply a no-op):

    • the stack is empty ➡️ prepending OP_CHECKLOCKTIMEVERIFY to scriptSig
    • the top item on the stack is less than 0 ➡️ prepending OP_1NEGATE OP_CHECKLOCKTIMEVERIFY OP_DROP to scriptSig
    • the lock-time type (height vs. timestamp) of the top stack item and the nLockTime field are not the same ➡️ prepending OPNum(1000) OP_CHECKLOCKTIMEVERIFY OP_DROP to scriptSig ➡️ setting tx.vin[0].nSequence=0 and tx.nCheckTimeLock=1296688602 (genesis block timestamp)
    • the top stack item is greater than the transaction's nLockTime field ➡️ prepending OPNum(1000) OP_CHECKLOCKTIMEVERIFY OP_DROP to scriptSig ➡️ setting tx.vin[0].nSequence=0 and tx.nCheckTimeLock=500
    • the nSequence field of the txin is 0xffffffff ➡️ prepending OPNum(500) OP_CHECKLOCKTIMEVERIFY OP_DROP to scriptSig ➡️ setting tx.vin[0].nSequence=0xffffffff and tx.nCheckTimeLock=500

    The first commit creates a helper function for the tx modification and also includes some tidying up like turning single-line to multi-line Python imports where necessary and cleaning up some PEP8 warnings. The second commit prepares the invalidation function cltv_invalidate and the third and the fourth use it and check for the expected reject reason strings ("Operation not valid with the current stack size", "Negative locktime" and "Locktime requirement not satisfied").

  2. fanquake added the label Tests on Aug 25, 2020
  3. DrahtBot commented at 2:49 PM on August 25, 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.

  4. instagibbs commented at 2:58 PM on August 25, 2020: member

    concept ACK

  5. DrahtBot added the label Needs rebase on Aug 26, 2020
  6. theStack force-pushed on Aug 26, 2020
  7. theStack commented at 3:35 PM on August 26, 2020: member

    Rebased on master.

  8. DrahtBot removed the label Needs rebase on Aug 26, 2020
  9. DrahtBot added the label Needs rebase on Sep 25, 2020
  10. theStack force-pushed on Sep 27, 2020
  11. theStack commented at 6:20 PM on September 27, 2020: member

    Rebased on master again.

  12. DrahtBot removed the label Needs rebase on Sep 27, 2020
  13. DrahtBot added the label Needs rebase on Jan 15, 2021
  14. test: add tx modfication helper function in feature_cltv.py
    + reformat python imports
    + fix PEP8 warnings (all except E501 line too long)
    ce994e1202
  15. test: prepare cltv_invalidate to test all failure reasons in feature_cltv.py
    only the "top item on the stack is less than 0" is used in the test right now
    8d0ce50c48
  16. test: check that _all_ invalid-CLTV txs are allowed in a block pre-BIP65 dbc1981474
  17. test: check that _all_ invalid-CLTV txs are rejected after BIP65 activation b01cd9471f
  18. theStack force-pushed on Mar 31, 2021
  19. theStack commented at 7:42 PM on March 31, 2021: member

    Rebased on master.

  20. DrahtBot removed the label Needs rebase on Mar 31, 2021
  21. sipa commented at 11:21 PM on March 31, 2021: member

    Concept ACK

  22. MarcoFalke approved
  23. MarcoFalke commented at 10:58 AM on April 22, 2021: member

    review ACK b01cd9471f435bb36b8ed5211a56baad51111ad2 🐣

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

    Signature:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    review ACK b01cd9471f435bb36b8ed5211a56baad51111ad2 🐣
    -----BEGIN PGP SIGNATURE-----
    
    iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
    pUiGwwv/ehsKGNFfYIyNn3Pb7H8mC7j6SfFijNHeg+rDldGw1lNA3MLjMvPGhs4v
    +uuAbS74JCv4T6fEjw8K4ODx6ZU/+fyckT8HL2Qxx9TbqPN9+3Gc5Ww68137+RRW
    mOzNy1S4Z6MPu3OtBZxkHSKHXPKF6sSTDyqjrxgslpOFNDceirBIahFTHPXy2geh
    gZYLsQYtbY0kDJBLcfCh4vvPW5IpLO2Cr5iRQkVmj31upzvYniKmWtuCwmwrXZG9
    mAKP0o9AGnfYWCufH1NpDBp4/JBrRITk+nz0bOgxYO99FiJMalX+YTP6xlkOIGgI
    ChrXmz7/qe3FXypz9lA+hL44R7/ApLWhCfc4oK9bbHwSVqbjnTh5V20+EjYSK3ER
    5IPjBDjbTN1768iQMRIjq2Aj9zQFrVwCkzlW56zwlECZoFHGEzDOWimHkVWd1vZR
    qSvVIya8GmuqwWpEASi9O5yXArtqF+Vzr7s9Ki8TiTbGFOQFFlNFLgTXkOXi4Mrr
    DC1R6djf
    =TLhB
    -----END PGP SIGNATURE-----
    

    Timestamp of file with hash 0aea310db82e5dcfdbcc25d7e801d24635a1a608c8b997bbb98494c524f90747 -

    </details>

  24. MarcoFalke merged this on Apr 22, 2021
  25. MarcoFalke closed this on Apr 22, 2021

  26. MarcoFalke commented at 3:27 PM on April 22, 2021: member

    Reworked the test some more in #21754

  27. sidhujag referenced this in commit bccee7ae09 on Apr 22, 2021
  28. gwillen referenced this in commit 827081b134 on Jun 1, 2022
  29. 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-13 15:14 UTC

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