1 major finding · 1 minor finding · 6 suggestions
Earlier concerns neither republished nor resolved: 1 major finding · 1 minor finding · 1 suggestion. See the Run archive for their assessments.
Findings
[major] · Kernel witness enumeration becomes quadratic
The C++ kernel Items() range now repeatedly scans witness prefixes, making sequential enumeration quadratic, while the C witness API offers no linear traversal.
Location: src/kernel/bitcoinkernel.cpp:892 (head).
Details and suggested fix
Items() calls GetItem(m_idx) on each dereference, which reaches CScriptWitness::operator[] through this accessor. Every lookup except the last starts again at begin(), so enumerating n items performs about n²/2 element decodes instead of the previous linear traversal. A roughly four-million-element witness therefore requires on the order of 10^13 iterator steps. Such witnesses can be consensus-valid when spending an unknown witness-version or P2A output, although including the nonstandard spend requires mining it. The public transaction constructor also accepts them directly from caller-supplied bytes through unbudgeted TX_WITH_WITNESS. Add forward traversal to the C API, for example a cursor backed by the witness iterator, and build Items() on it; indexed access can remain linear. No checked-in caller enumerates a large witness, so production impact depends on whether kernel consumers enumerate witness items from untrusted transactions or blocks.
[minor] · Witness verification expands the whole stack before dispatch
VerifyWitnessProgram needlessly materializes witnesses on non-execution paths, adding allocations to Taproot key-path checks and temporarily restoring roughly the old worst-case witness footprint.
Location: src/script/interpreter.cpp:1933 (head).
Details and suggested fix
witness.ToVectors() runs before version and program-size dispatch, reserving one vector object per element and copying every non-empty element. This is unnecessary for ignored witness versions and P2A, wrong-count P2WPKH spends, and several other early returns. Taproot key-path verification also needs only read access to the signature. For a mined unknown-version spend carrying roughly four million empty elements, the copy temporarily reconstructs about 96 MB of vector objects on a typical 64-bit build. This is an estimate, not a measurement, and roughly matches storage base already held after deserialization rather than exceeding it. Use witness accessors and spans for dispatch and auxiliary checks, and create the owned execution stack only immediately before ExecuteWitnessScript. Preserve existing error ordering and OP_SUCCESS precedence. If the annex becomes a span, explicitly retain its CompactSize prefix in m_annex_hash, since byte-span serialization writes raw bytes. The large example requires a mined nonstandard spend; no such block was identified.
Optional improvements
[suggestion] · Oversized-block tests stop covering the consensus limits
Both oversized-block fixtures now fail in P2P deserialization, so their assertions no longer protect the consensus size and weight checks still used by unbudgeted paths such as submitblock.
Location: test/functional/feature_block.py:379 (head).
Details and suggested fix
The non-witness b24 fixture previously exercised CheckBlock's serialized-size branch of bad-blk-length, while test_witness_block_size exercised ContextualCheckBlock's bad-blk-weight. Both helpers submit only through P2P, so expecting Weight limit exceeded now stops these cases before validation. The remaining bad-blk-length expectations cover empty transaction vectors, not excessive serialized size. submitblock still decodes through unbudgeted TX_WITH_WITNESS and depends on the consensus checks. Retain the P2P assertions and add unbudgeted submitblock coverage asserting bad-blk-length and bad-blk-weight for these two fixtures.
[suggestion] · Budget tests do not protect early count rejection
The budget tests check totals or exceptions on complete serializations, so moving charging after deserialization would leave the early memory-bounding behavior unprotected.
Location: src/test/transaction_tests.cpp:1557 (head).
Details and suggested fix
UnserializeTransaction charges input and output counts and their minimum weight before resizing the vectors. The new unit test, compact-block test, and transaction fuzz checks do not distinguish this early rejection from charging after reading the whole transaction. The truncated cases in too_many_inputs_or_outputs use no budget. Add truncated prefixes with counts below the unconditional limits but above the remaining weight budget, and assert Weight limit exceeded. For example, a version followed by an input count of 2 with a 363-WU budget leaves 331 WU after the fixed charge, short of the 332-WU input charge. Moving that charge after reading would instead produce an end-of-data error. Add an analogous output-count case after one complete minimal input.
[suggestion] · Deserialization benchmarks skip the weight-budgeted P2P path
The new benchmarks omit the per-input, per-output, and per-witness weight accounting used when receiving P2P transactions and blocks.
Location: src/bench/block_deserialize.cpp:111 (head).
Details and suggested fix
Every timed run uses TX_WITH_WITNESS, leaving weight_left null. The tx, block, cmpctblock, and blocktxn handlers instead enable budget accounting, including conditional GetSerializeSize calls that these benchmarks never measure. Add a budgeted DeserializeBlock variant that resets weight_left inside each timed iteration to MAX_BLOCK_WEIGHT - WITNESS_SCALE_FACTOR * (80 + 1), matching net processing. Keep the current runs as the disk/RPC baseline. The existing synthetic blocks can be reused unchanged.
[suggestion] · Stricter transaction decoding lacks a release note
RPC decoding now rejects impossible input/output counts, and P2P rejects some invalid data during deserialization, but these visible compatibility changes have no PR-specific release note.
Location: src/primitives/transaction.h:256 (head).
Details and suggested fix
The input/output count limits are unconditional, so raw transactions exceeding them now fail RPC decoding rather than reaching validation. The updated mempool_accept.py case demonstrates the expected TX decode failed error (-22). The P2P-only empty-transaction and weight checks also change rejection handling, with the updated block tests expecting deserialization failures without peer disconnection. Add a short PR-specific release note covering the stricter RPC decoding and changed malformed-P2P-message handling, as requested by doc/developer-notes.md for visible API changes.
[suggestion] · SpanReader::Remaining() is only used by its own test
The final witness implementation no longer needs this new public stream method, leaving its dedicated test as its only caller.
Location: src/streams.h:104 (head).
Details and suggested fix
Remaining() supported witness element lookup through SpanReader, but the later DecodeCompactSize change removed that use. At head, only streams_span_reader_remaining calls this method; the similarly named calls on other reader types do not depend on it. Remove the method and its dedicated test from the final diff, squashing or reordering intermediate commits as needed to keep them buildable.
[suggestion] · The P2WPKH benchmark uses a 72-byte public key
The fixture labelled a typical P2WPKH block gives both witness items 72 bytes, overstating the public-key slot and changing the block's transaction density.
Location: src/bench/block_deserialize.cpp:124 (head).
Details and suggested fix
WriteTx gives every witness element the same size_wit_item, so this shape emits a 72-byte public-key slot instead of a 33-byte compressed key. That changes witness allocation sizes and how many transactions fit near the weight limit. Allow per-item sizes for this shape, emit roughly 72-byte signatures and 33-byte keys, and recompute num_txn to retain the near-full-block workload. Valid signatures are not needed for a deserialization benchmark.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [suggestion]: Reuse the witness-item buffer in benchmark setup
- [major]: The witness-size guard is tautological on 32-bit builds
- [minor]: The input-count cutoff admits an impossible boundary count