Skip to content

ipc: crash on submitSolution call with invalid coinbase #33341

Closed

Description

@marcofleon

There seems to be an unhandled exception when deserializing an invalid coinbase in submitSolution.

log
node0 2025-09-08T11:26:56.165687Z [capnp-loop] [../../../src/ipc/capnp/protocol.cpp:35] [void ipc::capnp::(anonymous namespace)::IpcLogFn(bool, std::string)] [ipc] {bitcoin-node-166995/b-capnp-loop-166997} IPC server recv request  #14 BlockTemplate.submitSolution$Params (context = (thread = <external capability>), version = 0, timestamp = 0, nonce = 0, coinbase = "") 
 node0 2025-09-08T11:26:56.165711Z [capnp-loop] [../../../src/ipc/capnp/protocol.cpp:35] [void ipc::capnp::(anonymous namespace)::IpcLogFn(bool, std::string)] [ipc] {bitcoin-node-166995/b-capnp-loop-166997} IPC server post request  #14 {bitcoin-node-166995/b-capnp-loop-167036 (from pythread)} 
 test  2025-09-08T11:26:56.207859Z TestFramework (ERROR): Unexpected exception 
                                   Traceback (most recent call last):
                                     File "/root/bitcoin/test/functional/test_framework/test_framework.py", line 199, in main
                                       self.run_test()
                                     File "/root/bitcoin/./debugbuild/test/functional/interface_ipc.py", line 186, in run_test
                                       self.run_mining_test()
                                     File "/root/bitcoin/./debugbuild/test/functional/interface_ipc.py", line 182, in run_mining_test
                                       asyncio.run(capnp.run(async_routine()))
                                     File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
                                       return runner.run(main)
                                              ^^^^^^^^^^^^^^^^
                                     File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
                                       return self._loop.run_until_complete(task)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                     File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
                                       return future.result()
                                              ^^^^^^^^^^^^^^^
                                     File "capnp/lib/capnp.pyx", line 1965, in run
                                     File "capnp/lib/capnp.pyx", line 1966, in capnp.lib.capnp.run
                                     File "/root/bitcoin/./debugbuild/test/functional/interface_ipc.py", line 128, in async_routine
                                       result = await template.result.submitSolution(ctx, 0, 0, 0, b"")
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                   capnp.lib.capnp.KjException: capnp/rpc.c++:2778: disconnected: Peer disconnected.
                                   stack: 7fd1cba914c4 7fd1cba87d10 7fd1cba777c0 7fd1cb9164f0 7fd1cb9187d0
 test  2025-09-08T11:26:56.218026Z TestFramework (DEBUG): Closing down network thread 
 test  2025-09-08T11:26:56.268255Z TestFramework (INFO): Not stopping nodes as test failed. The dangling processes will be cleaned up later. 
 test  2025-09-08T11:26:56.268354Z TestFramework (WARNING): Not cleaning up dir /tmp/bitcoin_func_test_jp4hfh13 
 test  2025-09-08T11:26:56.268384Z TestFramework (ERROR): Test failed. Test logging available at /tmp/bitcoin_func_test_jp4hfh13/test_framework.log 
 test  2025-09-08T11:26:56.268453Z TestFramework (ERROR): 
 test  2025-09-08T11:26:56.268517Z TestFramework (ERROR): Hint: Call /root/bitcoin/test/functional/combine_logs.py '/tmp/bitcoin_func_test_jp4hfh13' to consolidate all logs 
 test  2025-09-08T11:26:56.268547Z TestFramework (ERROR): 
 test  2025-09-08T11:26:56.268569Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log. 
 test  2025-09-08T11:26:56.268603Z TestFramework (ERROR): https://github.com/bitcoin/bitcoin/issues 
 test  2025-09-08T11:26:56.268627Z TestFramework (ERROR): 

 node0 stderr terminate called after throwing an instance of 'std::ios_base::failure[abi:cxx11]'
  what():  SpanReader::read(): end of data: iostream error 

I found this while using fuzzamoto to test the mining interface, but the easiest way to reproduce would be to just add

await template.result.submitSolution(ctx, 0, 0, 0, b"")

after creating the block template in the IPC functional test (interface_ipc.py).

Activity

  1. fanquake commented on Sep 8, 2025

    @fanquake
    Member
  2. Sjors commented on Sep 8, 2025

    @Sjors
    Member

    Thanks, I was able to reproduce that. Will add a guard and test.

  3. Sjors commented on Sep 8, 2025

    @Sjors
    Member

    @ryanofsky looks like libmultiprocess needs to catch this earlier, because even if I make bool submitSolution immediately return false it crashes.

    The node crashes with:

    libc++abi: terminating due to uncaught exception of type std::__1::ios_base::failure: SpanReader::read(): end of data: unspecified iostream_category error
    
  4. ryanofsky commented on Sep 8, 2025

    @ryanofsky
    Contributor

    Nice find. This behavior is expected but should be improved, and shouldn't be hard to improve.

    It's similar to bitcoin-core/libmultiprocess#206 in that if a bad request is sent to the node, the node will crash instead of returning an error, when it could just as easily return an error, and it would make sense to do that for the sake of stability and to make development easier with other languages like rust and python.

    Similar to bitcoin-core/libmultiprocess#206 this type of error is difficult to trigger from c++ unless you call the function with an argument that can only be serialized but not deserialized.

    It should not be hard to add some code to serverInvoke to catch and log uncaught exceptions and reject the request. I can follow up with a PR to address this and bitcoin-core/libmultiprocess#206

  5. marcofleon commented on Feb 27, 2026

    @marcofleon
    ContributorAuthor
  6. ryanofsky commented on Feb 27, 2026

    @ryanofsky
    Contributor

    It should not be hard to add some code to serverInvoke to catch and log uncaught exceptions and reject the request. I can follow up with a PR to address this [...]

    The uncaught exceptions should now be caught with bitcoin-core/libmultiprocess@c4762c7 in bitcoin-core/libmultiprocess#240 and #34422. So this issue should be resolved #34422 although it might be good to add a test to check the error message that's returned.

  7. ryanofsky commented on Feb 27, 2026

    @ryanofsky
    Contributor

    Confirmed following test passes locally with #34422

    --- a/test/functional/interface_ipc_mining.py
    +++ b/test/functional/interface_ipc_mining.py
    @@ -277,6 +277,14 @@ class IPCMiningTest(BitcoinTestFramework):
                     block.hashMerkleRoot = block.calc_merkle_root()
                     original_version = block.nVersion
     
    +                self.log.debug("Submit solution that can't be deserialized")
    +                try:
    +                    await template.submitSolution(ctx, 0, 0, 0, b"")
    +                    raise AssertionError("submitSolution unexpectedly succeeded")
    +                except capnp.lib.capnp.KjException as e:
    +                    assert_equal(e.description, "remote exception: std::exception: SpanReader::read(): end of data: iostream error")
    +                    assert_equal(e.type, "FAILED")
    +
                     self.log.debug("Submit a block with a bad version")
                     block.nVersion = 0
                     block.solve()

    I think this would be good to add as a followup to #34422, maybe bundled with other followups already discussed
    #34422 (comment). The test might also need to be adjusted to work on different CI jobs

  8. Sjors commented on Mar 13, 2026

    @Sjors
    Member

    #34727 adds test coverage for this

  9. added this to the 31.0 milestone on Mar 23, 2026
  10. hodlinator commented on Mar 23, 2026

    @hodlinator
    Contributor

    #33341 adds test coverage for this

    Correction: #34727

  11. added a commit that references this issue on Mar 24, 2026
  12. ryanofsky commented on Apr 8, 2026

    @ryanofsky
    Contributor

    #34644 (comment) reports a similar issue probably caused by the same bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions