test: No unit test covers BIP342 tapscript signatures #32012

issue jirijakes openend this issue on March 7, 2025
  1. jirijakes commented at 4:13 am on March 7, 2025: none

    The following change does not make any unit test fail:

     0diff --git i/src/script/interpreter.cpp w/src/script/interpreter.cpp
     1index a35306b693..d9c119ae77 100644
     2--- i/src/script/interpreter.cpp
     3+++ w/src/script/interpreter.cpp
     4@@ -1484,7 +1484,7 @@ bool SignatureHashSchnorr(uint256& hash_out, ScriptExecutionData& execdata, cons
     5         // key_version is not used and left uninitialized.
     6         break;
     7     case SigVersion::TAPSCRIPT:
     8-        ext_flag = 1;
     9+        ext_flag = 42;
    10         // key_version must be 0 for now, representing the current version of
    11         // 32-byte public keys in the tapscript signature opcode execution.
    12         // An upgradable public key version (with a size not 32-byte) may
    

    This is because, despite BIP342 claiming that “The Taproot (BIP341) test vectors also contain examples for Tapscript execution.”, it does not seem to be the case.

    A similar change to SigVersion::TAPROOT branch causes test failures in script_tests/bip341_keypath_test_vectors as expected. Functional tests fail as expected in any case.

  2. brunoerg commented at 12:53 pm on March 19, 2025: contributor

    Hi, @jirijakes. I’ve tried to reproduce it but the unit test fails when running it with this mutation.

    Without the change:

    0➜  bitcoin-core-dev git:(master)DIR_UNIT_TEST_DATA=qa-assets/unit_test_data ./build/bin/test_bitcoin --run_test=script_tests
    1Running 19 test cases...
    2
    3*** No errors detected
    

    With the change:

     0➜  bitcoin-core-dev git:(master)DIR_UNIT_TEST_DATA=qa-assets/unit_test_data ./build/bin/test_bitcoin --run_test=script_tests
     1Running 19 test cases...
     2test/script_tests.cpp:1582: error: in "script_tests/script_assets_test": check ret has failed
     3test/script_tests.cpp:1582: error: in "script_tests/script_assets_test": check ret has failed
     4test/script_tests.cpp:1582: error: in "script_tests/script_assets_test": check ret has failed
     5test/script_tests.cpp:1582: error: in "script_tests/script_assets_test": check ret has failed
     6test/script_tests.cpp:1582: error: in "script_tests/script_assets_test": check ret has failed
     7test/script_tests.cpp:1582: error: in "script_tests/script_assets_test": check ret has failed
     8test/script_tests.cpp:1582: error: in "script_tests/script_assets_test": check ret has failed
     9test/script_tests.cpp:1582: error: in "script_tests/script_assets_test": check ret has failed
    10test/script_tests.cpp:1582: error: in "script_tests/script_assets_test": check ret has failed
    11...
    
  3. Chand-ra commented at 5:52 pm on March 19, 2025: none

    Hi, @jirijakes. I’ve tried to reproduce it but the unit test fails when running it with this mutation.

    Hmm, I seem to be able to reproduce the bug with the following:

     0$ git diff
     1 diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp
     2index a35306b693..d9c119ae77 100644
     3--- a/src/script/interpreter.cpp
     4+++ b/src/script/interpreter.cpp
     5@@ -1484,7 +1484,7 @@ bool SignatureHashSchnorr(uint256& hash_out, ScriptExecutionData& execdata, cons
     6         // key_version is not used and left uninitialized.
     7         break;
     8     case SigVersion::TAPSCRIPT:
     9-        ext_flag = 1;
    10+        ext_flag = 42;
    11         // key_version must be 0 for now, representing the current version of
    12         // 32-byte public keys in the tapscript signature opcode execution.
    13         // An upgradable public key version (with a size not 32-byte) may
    14
    15$ sudo cmake --build build --parallel 12
    16[  0%] Generating bitcoin-build-info.h
    17[  0%] Built target secp256k1_precomputed
    18[  1%] Built target crc32c
    19[  2%] Built target univalue
    20[  5%] Built target bitcoin_crypto
    21[  5%] Building CXX object src/CMakeFiles/bitcoin_consensus.dir/script/interpreter.cpp.o
    22[ 16%] Built target unitester
    23.
    24.
    25.
    26[ 74%] Built target bitcoind
    27[100%] Built target test_bitcoin
    28
    29$ ./build/bin/test_bitcoin --run_test=script_tests
    30Running 19 test cases...
    31
    32*** No errors detected
    

    Doing the following change:

     0$ git diff
     1diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp
     2index a35306b693..3c95d89187 100644
     3--- a/src/script/interpreter.cpp
     4+++ b/src/script/interpreter.cpp
     5@@ -1480,7 +1480,7 @@ bool SignatureHashSchnorr(uint256& hash_out, ScriptExecutionData& execdata, cons
     6     uint8_t ext_flag, key_version;
     7     switch (sigversion) {
     8     case SigVersion::TAPROOT:
     9-        ext_flag = 0;
    10+        ext_flag = 1;
    11         // key_version is not used and left uninitialized.
    12         break;
    

    Does produce the following error though:

    0Running 19 test cases...
    1./test/script_tests.cpp(1689): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(signature) == input["expected"]["witness"][0].get_str() has failed [ee46ac94633f9f18540147b9c6481e06261afef228655c4c7b6bef994470bf80f65903da6d503195fdbf9e1ae574fa513ef1135fb0f36ffc264e55b95e83a26403 != ed7c1647cb97379e76892be0cacff57ec4a7102aa24296ca39af7541246d8ff14d38958d4cc1e2e478e4d4a764bbfd835b16d4e314b72937b29833060b87276c03]
    2./test/script_tests.cpp(1700): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(sighash) == input["intermediary"]["sigHash"].get_str() has failed [1ef56c28e4b7e596c8c8a7deec429eb23e823f6c8a16fc1799f0063505701cc1 != 2514a6272f85cfa0f45eb907fcb0d121b808ed37c6ea160a5a9046ed5526d555]
    3./test/script_tests.cpp(1689): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(signature) == input["expected"]["witness"][0].get_str() has failed [5847f2545965ce44f7a0ed5ef77959c0470a32454298df1818ea358395e1373417b5dde924b5c8204bbb35f3d8d767070bc7a6655e35ab5a4192f518cd33594783 != 052aedffc554b41f52b521071793a6b88d6dbca9dba94cf34c83696de0c1ec35ca9c5ed4ab28059bd606a4f3a657eec0bb96661d42921b5f50a95ad33675b54f83]
    4.
    5.
    6.
    7*** 14 failures are detected in the test module "Bitcoin Core Test Suite"
    
  4. willcl-ark commented at 9:32 pm on March 19, 2025: member

    I also cannot reproduce OP:

     0will@ubuntu in …/src/core/bitcoin on  master [$!?] via △ v3.31.6 : 🐍 (core)
     1$ git diff -p | cat
     2diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp
     3index a35306b6935..d2904fb3f14 100644
     4--- a/src/script/interpreter.cpp
     5+++ b/src/script/interpreter.cpp
     6@@ -1480,7 +1480,7 @@ bool SignatureHashSchnorr(uint256& hash_out, ScriptExecutionData& execdata, cons
     7     uint8_t ext_flag, key_version;
     8     switch (sigversion) {
     9     case SigVersion::TAPROOT:
    10-        ext_flag = 0;
    11+        ext_flag = 42;
    12         // key_version is not used and left uninitialized.
    13         break;
    14     case SigVersion::TAPSCRIPT:
    15
    16will@ubuntu in …/src/core/bitcoin on  master [$!?] via △ v3.31.6 : 🐍 (core)
    17$ cmake --build build -j17
    18[  0%] Generating bitcoin-build-info.h
    19[  0%] Built target exhaustive_tests
    20[  0%] Built target secp256k1_precomputed
    21[  0%] Built target crc32c
    22[  1%] Built target bitcoin_cli
    23[  2%] Built target univalue
    24[  5%] Built target minisketch
    25[  6%] Built target secp256k1
    26[  6%] Built target noverify_tests
    27[  8%] Built target bitcoin_consensus
    28[  8%] Built target tests
    29[ 12%] Built target bitcoin_crypto
    30[ 23%] Built target unitester
    31[ 23%] Built target object
    32[ 24%] Built target ctime_tests
    33[ 32%] Built target test_util
    34[ 35%] Built target leveldb
    35[ 35%] Built target generate_build_info
    36[ 35%] Built target bitcoin_clientversion
    37[ 41%] Built target bitcoin_util
    38[ 50%] Built target bitcoin_common
    39[ 50%] Built target bitcoin-cli
    40[ 50%] Built target bitcoin-tx
    41[ 51%] Built target bitcoin-util
    42[ 56%] Built target bitcoin_wallet
    43[ 56%] Built target bitcoin-wallet
    44[ 73%] Built target bitcoin_node
    45[ 73%] Built target bitcoind
    46[100%] Built target test_bitcoin
    47
    48will@ubuntu in …/src/core/bitcoin on  master [$!?] via △ v3.31.6 : 🐍 (core)
    49$ ./build/bin/test_bitcoin --run_test=script_tests
    50Running 19 test cases...
    51../../../src/test/script_tests.cpp(1689): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(signature) == input["expected"]["witness"][0].get_str() has failed [fae8e7e3ab84b11f775b62100481ccdaf520a628fc2d2837d308bd93da357af0b707df9292413b574be23e784832cf5cdc565747c7ae15f33a5ac55e21c3f6ef03 != ed7c1647cb97379e76892be0cacff57ec4a7102aa24296ca39af7541246d8ff14d38958d4cc1e2e478e4d4a764bbfd835b16d4e314b72937b29833060b87276c03]
    52../../../src/test/script_tests.cpp(1700): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(sighash) == input["intermediary"]["sigHash"].get_str() has failed [9d6ff1701d2e63eee442eb44ac276a57ae8d2aa5659e5191347c6d7104a325da != 2514a6272f85cfa0f45eb907fcb0d121b808ed37c6ea160a5a9046ed5526d555]
    53../../../src/test/script_tests.cpp(1689): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(signature) == input["expected"]["witness"][0].get_str() has failed [c61b3ba1ff376bc2ba40e91ff108697b9e9500590fe71f59a2b2b38037547c0e32cee0522b9e9caf456c4befc8e6e37502fc14daf3ce48cb8b19f9aa9588481583 != 052aedffc554b41f52b521071793a6b88d6dbca9dba94cf34c83696de0c1ec35ca9c5ed4ab28059bd606a4f3a657eec0bb96661d42921b5f50a95ad33675b54f83]
    54../../../src/test/script_tests.cpp(1700): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(sighash) == input["intermediary"]["sigHash"].get_str() has failed [d8a506a504823d0efed689179e10d9e3b39c4f8d8786a47c0c67d9646be04ecf != 325a644af47e8a5a2591cda0ab0723978537318f10e6a63d4eed783b96a71a4d]
    55../../../src/test/script_tests.cpp(1689): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(signature) == input["expected"]["witness"][0].get_str() has failed [86ea29da1f03effff0c07c978a80ddc6b39cfeccdd6e0ca653143737e63dc48396ea9e9d0ffbf3a65d31d907d7180fb2af1aeda2f11c45cb0e97dcf892f9aa2a01 != ff45f742a876139946a149ab4d9185574b98dc919d2eb6754f8abaa59d18b025637a3aa043b91817739554f4ed2026cf8022dbd83e351ce1fabc272841d2510a01]
    56../../../src/test/script_tests.cpp(1700): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(sighash) == input["intermediary"]["sigHash"].get_str() has failed [f820312567c01b25ac539cf5b41211b0c1c6a909ca88d3eee9d40bff2f26d7b2 != bf013ea93474aa67815b1b6cc441d23b64fa310911d991e713cd34c7f5d46669]
    57../../../src/test/script_tests.cpp(1689): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(signature) == input["expected"]["witness"][0].get_str() has failed [ecb8015cc1c011a06477057e8231bbad668df8d4b0c91e89a8abc6456c87634535238ffa9c91478ee489475fcd58ee9fbfef6cc88b3dce45b59901bfcc5982d6 != b4010dd48a617db09926f729e79c33ae0b4e94b79f04a1ae93ede6315eb3669de185a17d2b0ac9ee09fd4c64b678a0b61a0a86fa888a273c8511be83bfd6810f]
    58../../../src/test/script_tests.cpp(1700): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(sighash) == input["intermediary"]["sigHash"].get_str() has failed [92944e08dc8418331db8fcd5bb2e3d9bd47fc9964fa645a2f5d9b63bc8b0ed49 != 4f900a0bae3f1446fd48490c2958b5a023228f01661cda3496a11da502a7f7ef]
    59../../../src/test/script_tests.cpp(1689): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(signature) == input["expected"]["witness"][0].get_str() has failed [ab59cab477b194e0fd525ce154cb4065c68910543362741c510bc985d3181ab44da832b19d7e304633a0a1d426646e6da6858eac841c2a1f6a444c720292a26702 != a3785919a2ce3c4ce26f298c3d51619bc474ae24014bcdd31328cd8cfbab2eff3395fa0a16fe5f486d12f22a9cedded5ae74feb4bbe5351346508c5405bcfee002]
    60../../../src/test/script_tests.cpp(1700): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(sighash) == input["intermediary"]["sigHash"].get_str() has failed [2ba8f7c285cac54d811eecdd8889cf41197fcd987a42714c85d980de6497b320 != 15f25c298eb5cdc7eb1d638dd2d45c97c4c59dcaec6679cfc16ad84f30876b85]
    61../../../src/test/script_tests.cpp(1689): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(signature) == input["expected"]["witness"][0].get_str() has failed [2e504ddeac339bc97144f6e50906d0233ca059900764062cc762323e4417d6e7da3edfe7c3a2a200beecab40b40a3df73ed14614796ffedfc2aaceee506e618c82 != ea0c6ba90763c2d3a296ad82ba45881abb4f426b3f87af162dd24d5109edc1cdd11915095ba47c3a9963dc1e6c432939872bc49212fe34c632cd3ab9fed429c482]
    62../../../src/test/script_tests.cpp(1700): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(sighash) == input["intermediary"]["sigHash"].get_str() has failed [e97f631b34d19a868bd624ab53a0facc7dba92492222e4b358307b7ad4a62c8f != cd292de50313804dabe4685e83f923d2969577191a3e1d2882220dca88cbeb10]
    63../../../src/test/script_tests.cpp(1689): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(signature) == input["expected"]["witness"][0].get_str() has failed [afef7b48f4945f4df089d699cb58329e5092d2da52bb44fd007e72f14f420f4696ecdf2a740ab92d8a0339c09a4731a88ba6e2e9fbb51f1f05f95f99ba463e3b81 != bbc9584a11074e83bc8c6759ec55401f0ae7b03ef290c3139814f545b58a9f8127258000874f44bc46db7646322107d4d86aec8e73b8719a61fff761d75b5dd981]
    64../../../src/test/script_tests.cpp(1700): error: in "script_tests/bip341_keypath_test_vectors": check HexStr(sighash) == input["intermediary"]["sigHash"].get_str() has failed [b9fdf60d666cd26f852be0de20975d358a294de07fcc029f6bba48f389aa3b44 != cccb739eca6c13a8a89e6e5cd317ffe55669bbda23f2fd37b0f18755e008edd2]
    65
    66*** 14 failures are detected in the test module "Bitcoin Core Test Suite"
    

    I think unless we can get exact reproduction steps this can probably be closed.

  5. willcl-ark added the label Tests on Mar 19, 2025
  6. sipa commented at 9:37 pm on March 19, 2025: member
    @Chand-ra The taproot script unit tests are largely, and don’t live in this repository. You need to clone the QA assets repository (https://github.com/bitcoin-core/qa-assets) and then specify the location of its unit_test_data directory in the DIR_UNIT_TEST_DATA environment variable when running the unit test binary.
  7. Chand-ra commented at 1:01 pm on March 20, 2025: none

    @Chand-ra The taproot script unit tests are largely, and don’t live in this repository. You need to clone the QA assets repository (https://github.com/bitcoin-core/qa-assets) and then specify the location of its unit_test_data directory in the DIR_UNIT_TEST_DATA environment variable when running the unit test binary.

    You’re right, cloning the qa-asserts repo and executing the following command:

    $ DIR_UNIT_TEST_DATA=./qa-assets/unit_test_data ./build/bin/test_bitcoin --run_test=script_tests

    does lead to the same errors as those mentioned by @willcl-ark and @brunoerg .

    The issue can probably be closed as a false positive.

  8. maflcko commented at 3:02 pm on March 20, 2025: member
    related to #31576 ?

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: 2025-03-29 06:12 UTC

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