Review report

core: PR #32468

Provider refusals

write_verifier: Provider declined the request because of a cybersecurity restriction. Experiments remain incomplete; static verification can continue.

1 major finding · 2 minor findings · 4 suggestions

Findings

Link

[major] · A commitment-shaped payout script can leave the block with an invalid witness commitment

On regtest with SegWit active, a deliberately commitment-shaped payout script can make generateblock connect an invalid block or return hex that fails fresh validation; no current test or caller is known to use such a script.

Location: src/rpc/mining.cpp:507 (head).

Details and suggested fix

With SegWit active, pass an ordinary first output followed by a raw descriptor whose script starts with the witness-commitment prefix, such as [addr, "raw(6a24aa21a9ed<64 hex zeros>)"]. CreateNewTemplate validates a coinbase that pays only the first script, setting m_checked_witness_commitment; copying the template block preserves that cached flag. The RPC then rebuilds the coinbase with the requested outputs and the template commitment. RegenerateCommitments erases the last matching output, which is the real commitment, and GenerateCoinbaseCommitment sees the caller's output and does not add a replacement. The caller's incorrect hash is therefore treated as the commitment. Later validation returns early on the cached flag, so submit=true connects the block on this node even though other nodes reject it with bad-witness-merkle-match. With submit=false, the RPC returns hex that fails fresh validation. This does not affect the base RPC, whose only output was present during template validation. Reset fChecked, m_checked_witness_commitment, and m_checked_merkle_root after replacing the coinbase, as AddMerkleRootAndCoinbase does. Also prevent requested scripts from matching the commitment prefix or ensure a freshly computed commitment is appended last. Add a regression that generates with submit=false and passes the hex to submitblock.


Link

[minor] · Extra coinbase outputs are not included in the mempool template's weight and sigops reservations

With a nearly full mempool, enough requested outputs can make generateblock fail final validation with bad-blk-weight or bad-blk-sigops, although a valid block could include fewer transactions.

Location: src/rpc/mining.cpp:457 (head).

Details and suggested fix

When transactions is omitted, CreateNewTemplate fills the block from the mempool using the default block_reserved_weight of 8000 WU and coinbase_output_max_additional_sigops of 400, sized for a coinbase paying only the first script. The RPC then replaces that coinbase with all requested outputs without increasing either reservation. A P2WPKH output adds 124 WU and a P2TR output adds 172 WU; about 50 to 60 P2WPKH outputs can use the remaining weight slack. If the mempool fills the template close to the limit, final TestBlockValidity fails with bad-blk-weight; enough legacy-sigop outputs can similarly cause bad-blk-sigops. Retrying fails the same way, even though a valid block could include fewer mempool transactions. Raising -blockreservedweight works around the weight case. Before calling CreateNewTemplate, compute the extra outputs' serialized weight and legacy sigops, then pass correspondingly larger reservation values.


Link

[minor] · The OpenRPC schema does not describe the supported output forms

Clients validating against getopenrpcinfo(true) would reject supported requests, including the existing single-address form, while accepting a top-level object that the RPC rejects.

Location: src/rpc/mining.cpp:339 (head).

Details and suggested fix

output is declared as an array of strings with skip_type_check. For that shape, OpenRPC emits a oneOf schema allowing an array of strings or an object. The handler instead accepts a top-level string, as well as arrays containing strings or one-key {"address/descriptor": amount} objects; it rejects a top-level object. The published schema therefore rejects valid single-address and custom-reward-array requests, and permits an invalid top-level object. Because generateblock is hidden, this affects only callers that request hidden methods. Add an object alternative with an amount value alongside the string item, as createrawtransaction does, and represent the top-level string-or-array union, extending OpenRPCArgSchema if needed. Add an rpc_openrpc.py check.


Optional improvements

Link

[suggestion] · Custom amounts are added to an equal share instead of setting exact payouts

Callers cannot request exact payouts or direct only the remainder to selected recipients, limiting the pool-payout simulations this change targets.

Location: src/rpc/mining.cpp:499 (head).

Details and suggested fix

The help and release note describe an {"address/descriptor": amount} entry as assigning a fixed amount, but the code adds reward_parted to every custom amount. The test expects an entry for 8 BTC to receive 13.66666667 BTC. Callers therefore cannot set exact outputs or send the remainder only to chosen recipients unless the custom amounts sum to the total reward. In mempool mode, that total includes fees the caller does not know in advance. Should explicit amounts be exact, with the remainder split only among entries without amounts? If every entry has an amount, the call could be rejected or the remainder left unclaimed. If the additive behavior is intended, remove “fixed” from the help and release note and explain that the amount is added to an equal share, including any collected fees.


Link

[suggestion] · Help omits that explicit transaction lists forfeit transaction fees

Payout totals differ between explicit and mempool transaction selection, but the help no longer explains this distinction.

Location: src/rpc/mining.cpp:337 (head).

Details and suggested fix

The base help said, “Transaction fees are not collected in the block reward.” That remains true when transactions is supplied: the template uses use_mempool = false, so the reward is the subsidy alone and fees from appended transactions go unclaimed. When transactions is omitted, the block assembler includes selected fees in the reward. The same transactions can therefore produce different payout totals depending on how they are selected. In explicit mode, custom amounts above the subsidy but within the subsidy-plus-fees total are rejected as exceeding “the total block reward.” State in the help and release note that omitted transactions distributes the subsidy plus selected fees, while an explicit list distributes only the subsidy.


Link

[suggestion] · Multi-recipient tests reuse the same address for every output

The new assertions would still pass if every output were paid to the first destination.

Location: test/functional/rpc_generate.py:54 (head).

Details and suggested fix

address, address2, and address3 all come from miniwallet.get_address(), which returns the same fixed self._address. The per-output address assertions therefore cannot detect outputs sent to the wrong destination. Use distinct deterministic addresses, such as addresses from MiniWallet instances with different tag_name values. Assert that the addresses differ and retain the per-output address and amount checks.


Link

[suggestion] · Mempool-mode tests do not check fee payouts across multiple outputs or fresh witness validation

The tests would miss a regression that drops mempool fees or breaks the witness commitment in a multi-output mempool block.

Location: test/functional/rpc_generate.py:130 (head).

Details and suggested fix

The only mempool-mode case mines ten MiniWallet transactions to one output and checks only that the block has 11 transactions. Every multi-output and custom-reward case uses transactions=[]. Add a case that mines fee-paying MiniWallet transactions, which are witness spends, from the mempool to several outputs. Assert that the coinbase outputs sum to the subsidy plus the mined transactions' fees. Generate the block with submit=false and pass its hex to submitblock so the witness commitment is checked on a freshly deserialized block, without cached validation flags.


Coverage details