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g4ODg4ODg4OAA4ODg4ODg4AADAwy8vLy9PLy8vLy8t+y8vLy8vLy8vLy8vLDg5ycnJycnJycnJycnJycnJycnJycnJycnJycnJycnJycg4ODg4OBg4ODv9cbP+JdGmhiX+JiYlgAPYAAAAAAGxByon68P90/2kDMTMkiYmJicqJ+g==" | base64 --decode > rpc-36c31074f1f8e97885c2957d0b327b2e7f334cbc.crash
    1$ FUZZ=rpc ./src/test/fuzz/fuzz rpc-36c31074f1f8e97885c2957d0b327b2e7f334cbc.crash
    2fuzz_libfuzzer: test/fuzz/rpc.cpp:385: void rpc_fuzz_target(FuzzBufferType): Assertion `error_msg.find("trigger_internal_bug") != std::string::npos' failed.
    
  2. achow101 commented at 12:58 pm on April 11, 2024: member

    The CHECK_NONFATAL is in FromPKBytes: https://github.com/bitcoin/bitcoin/blob/bdb33ec51986570ea17406c83bad2c955ae23186/src/script/sign.cpp#L298 which is called when getting the miniscript for a script.

    This particular script is 173d36c8c9c9c9ffffffffffff0200000000021e1e37373721361818181818181e1e1e1e19000000000000000000b19292929292926b006c9b9b9292

  3. achow101 commented at 12:59 pm on April 11, 2024: member
  4. maflcko added the label RPC/REST/ZMQ on Apr 11, 2024
  5. maflcko added the label Bug on Apr 11, 2024
  6. maflcko commented at 1:03 pm on April 11, 2024: member
    I don’t think this is a fuzz issue. The RPC is finalizepsbt and it should be possible to hit it in finalizepsbt RPC as well.
  7. dergoegge renamed this:
    fuzz: Crash in `rpc` "CHECK_NONFATAL(last - first == 32)"
    fuzz, rpc: Internal bug in `finalizepsbt` "CHECK_NONFATAL(last - first == 32)"
    on Apr 11, 2024
  8. maflcko commented at 1:18 pm on April 11, 2024: member

    Somewhat smaller input for the RPC:

    0$ ./src/bitcoin-cli finalizepsbt cHNidP8BAKOro2MDAwMDA5gAAAbVAAUAAGNsZWFyYgwAAAAAAAAAYAD1////AOgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkwAAAAAAAAAAAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAADwAAAAAAAAAAAAAAAAAAAAAAAAMKAwMDAwMDAwMDAwMACvMBAwBxZAAAAAAAAAAAAGUAAAAODgAAAAEBKwL/ZABlcAAAIlEgAwMcHBwDAwAL8wEDJnBmAQAAAAAAAAAAAAAAAAAAgACiFQILCwsAAAAAAAAAAP////8AAACODg4ODg4ODg4ODgAADg5wAAAiUSADAxwcHAMDAAvzAQMmcGYBAAAAAAAAAAAAAAAAAACAAAAAAAAAACSJiYmJyon6AAAAgAAAAAAAAADw/3T/aQMxMySJiYmJyon6AGxByon68P90/2kDMTMkiYmJicqJ+tzc3MnJycnCwsLCwsLCwsLCwsLCwsI8PT09PRc9NsjJycn///////8CAAAAAAIeHjc3NyE2GBgYGBgYHh4eHhkAAAAAAAAAAACxkpKSkpKSawBsm5uSksAAAAAAAAA= 
    1
    2error code: -1
    3error message:
    4Internal bug detected: last - first == 32
    5script/sign.cpp:298 (FromPKBytes)
    6Bitcoin Core v27.99.0-3f6a6da3b08d-dirty
    
  9. darosior commented at 2:01 pm on April 11, 2024: member

    A repro as a unit test:

     0BOOST_AUTO_TEST_CASE(sign_invalid_miniscript)
     1{
     2    FillableSigningProvider keystore;
     3    SignatureData sig_data;
     4    CMutableTransaction prev, curr;
     5
     6    const auto invalid_pubkey{ParseHex("173d36c8c9c9c9ffffffffffff0200000000021e1e37373721361818181818181e1e1e1e19000000000000000000b19292929292926b006c9b9b9292")};
     7    TaprootBuilder builder;
     8    builder.Add(0, {invalid_pubkey}, 0xc0);
     9    XOnlyPubKey dummy{ParseHex("50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0")};
    10    builder.Finalize(dummy);
    11    prev.vout.emplace_back(0, GetScriptForDestination(builder.GetOutput()));
    12    curr.vin.emplace_back(COutPoint{prev.GetHash(), 0});
    13    sig_data.tr_spenddata = builder.GetSpendData();
    14
    15    SignSignature(keystore, CTransaction(prev), curr, 0, SIGHASH_ALL, sig_data);
    16}
    
  10. fanquake closed this on Apr 24, 2024

  11. fanquake referenced this in commit c143244ce3 on Apr 24, 2024

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: 2024-11-21 15:12 UTC

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