Repository navigation
Conversation
|
Wouldn't it be easier to disallow the coinbase for The spec requires excluding it: https://stratumprotocol.org/specification/07-template-distribution-protocol/#75-requesttransactiondata-client---server |
Yes, that's easier. The coinbase is already left out of |
bdc1ee6 to
28a2c2f
Compare
28a2c2f to
7e83533
Compare
|
Needs another rebase, probably because I merged #136. |
Bitcoin Core's submitSolution() stores the submitted coinbase in the template whether or not the block is accepted. Add a mock switch that does the same, and a tester helper to send SubmitSolution with a given coinbase.
After a SubmitSolution the template holds the client's coinbase, which may have no inputs. Stop reading its witness and send excess_data empty, like bitcoin_core_sv2 in sv2-apps. The coinbase was already excluded from transaction_list. Add a regression test.
7e83533 to
87b3307
Compare
|
Rebased on top of #136. |
Sjors
left a comment
There was a problem hiding this comment.
Thinking about this a bit more:
-
I think it's better to check if the coinbase transaction is present and we can obtain its witness. Only if not, set excess data to empty.
-
We should rethink the excess data field in the spec, there's been discussion about that before.
| //! Make submitSolution() store the submitted coinbase in the template, like | ||
| //! Bitcoin Core does (AddMerkleRootAndCoinbase) whether or not the block is | ||
| //! accepted. | ||
| std::atomic<bool> store_submitted_coinbase{false}; |
There was a problem hiding this comment.
Do we even need a switch here?
There was a problem hiding this comment.
No. Core stores it unconditionally, so the switch only hid that from tests. One difference to keep in mind: the mock's getCoinbaseTx() is derived from block.vtx[0], so with an always-store mock it follows the submitted coinbase, while Core's returns the unchanged m_coinbase_tx. Nothing calls it after a submit today.
|
Let's await the discussion in stratum-mining/sv2-spec#241. I'll open a PR to implement that approach, but you can leave this open. |
Sounds good, happy to wait for sv2-spec#241. If #241 doesn't go through, it might be better to take the witness from That would also fix the crash now without changing what goes on the wire, in case you'd rather not have it wait on the spec discussion. Happy to push that here, or keep this open as is, will go with one you prefer. |
That's a good idea.
Let's give it a week or so. Since SRI leave the field empty, we could do #141 anyway, but I prefer to change the spec. |
Submit an empty coinbase over the SV2 connection, then request transaction data for the same template. Check that the provider responds successfully with empty excess_data and no transactions instead of reading vin[0]. Adapt the regression test and SendSubmitSolutionCoinbase helper from stratum-mining#138, omitting the mock switch because submitted coinbases are already retained unconditionally. Co-authored-by: Толли <ziphyr.xyeag@gmail.com>
No excess data is currently defined, and the coinbase witness does not belong in this field. Always send empty excess_data, as proposed in: stratum-mining/sv2-spec#241 This also avoids reading the coinbase after a submitted solution has replaced it with a transaction that may have no inputs, fixing the crash described in stratum-mining#138.
Submit an empty coinbase over the SV2 connection, then request transaction data for the same template. Check that the provider responds successfully with empty excess_data and no transactions instead of reading vin[0]. Adapt the regression test and SendSubmitSolutionCoinbase helper from stratum-mining#138, omitting the mock switch because submitted coinbases are already retained unconditionally. Co-authored-by: Толли <ziphyr.xyeag@gmail.com>
a32129b test: cover transaction requests after an inputless coinbase (Sjors Provoost) 6fa70e6 sv2: leave transaction response excess_data empty (Sjors Provoost) 4d6920d test: retain submitted coinbases in the mining mock (Sjors Provoost) Pull request description: Depends on: - stratum-mining/sv2-spec#241 The SRI version already does this. Alternative to #138. ACKs for top commit: xyephy: tACK a32129b Tree-SHA512: 1b788dda5e490f4d9a75ff341395ff6b45013f87aa5a0600fb2dbef1e0bb35af9dfdd0c6872e57d0f3ea374c38db3e519e0c3b84843e49062a42a56786444052
|
I ended up merging #141, so closing this. |
After a
SubmitSolution, Bitcoin Core stores the submitted coinbase in the template, even if it rejects the block.RequestTransactionDatathen readvin[0]of that coinbase without checking that it has an input, so a coinbase with no inputs led to an out-of-bounds read and crashed sv2-tp.RequestTransactionDataand sendexcess_dataempty, likebitcoin_core_sv2in sv2-apps. The coinbase was already excluded fromtransaction_list. The solution is still forwarded, as in Never drop SubmitSolution in the network layer #120.The new regression test crashes on master and passes with the fix. Also ran on signet with jd-client and the SRI pool's JDS: every
RequestTransactionDatasucceeded and the JDS accepted every declared job.