Review report

bitcoin/bitcoin: PR #36721

3 suggestions

Optional improvements

Link

[suggestion] · Shared-owner allocations increase push-heavy allocation counts

Small-number results and witness arguments gain shared-owner allocations, while repeated data pushes lose buffer reuse; the net throughput tradeoff against duplication savings needs current-workload benchmarks.

Location: src/script/interpreter.cpp:498 (head).

Details and suggested fix

MakeStackElem allocates a shared owner separately from any byte buffer. OP_0, small-number and numeric results, and witness arguments gain this allocation compared with base. Moving vchPushValue also prevents GetScriptOp from reusing its capacity across executed data pushes, increasing allocation work for repeated nonempty pushes, though an isolated push need not allocate more overall. The existing VerifyNestedIfScript benchmark executes 1,100 OP_1 pushes, each gaining an owner allocation. Duplication, altstack transfers and boolean results save allocations or copies, so allocation counts alone do not establish a net slowdown. Compare base and head on the existing VerifyScript* and VerifyNestedIfScript benchmarks plus a DUP-heavy case. If push-heavy cases regress materially, an element representation that co-allocates ownership and bytes could avoid the extra allocation while preserving immutability and stable identity.


Link

[suggestion] · Global boolean owners introduce cross-worker reference-count writes

Uncached script checks running in parallel now update the same two shared ownership counters, introducing a contention point whose net throughput cost needs a multi-worker comparison.

Location: src/script/interpreter.cpp:429 (head).

Details and suggested fix

elemTrue and elemFalse are process-wide owners. Boolean-result pushes and subsequent copies or drops atomically update their shared control blocks. Base only read static vectors and copied their bytes into storage owned by the executing thread. ConnectBlock can execute these operations concurrently through CCheckQueue. A committed, signature-free tapscript such as OP_1 OP_DUP OP_EQUAL followed by repeated OP_DUP OP_DROP repeatedly touches the global true owner without the legacy opcode limit or signature-weight charges. Full-script cache hits skip execution, and ordinary signature spends already synchronize in the signature cache. Compare multi-worker throughput for standard spends and a boolean-DUP-heavy tapscript against lazily created per-EvalScript boolean owners. Execution-local owners remove process-wide sharing while preserving immutable values, stable identities and ownership-backed lifetimes for returned stacks, but add per-call allocations.


Link

[suggestion] · Oversized P2WSH witnesses allocate an owner per item before rejection

An oversized P2WSH witness can add millions of transient allocations before rejection in block validation; default relay policy rejects it before script execution.

Location: src/script/interpreter.cpp:1874 (head).

Details and suggested fix

For a P2WSH witness matching its program, WITNESS_V0 bypasses the Tapscript-only initial count check. Millions of empty arguments pass the element-size check and each receives a separate make_shared before EvalScript rejects, for example after OP_TRUE. Base copied empty vectors without per-item allocations. The 4,000,000-weight block limit permits millions of these one-byte encodings. Default relay rejects more than 100 arguments; normal network block processing requires valid proof of work, a correct witness commitment and the preceding checks, while test chains configured for nonstandard relay can reach script execution without a block. The added work is linear, freed on return, and unmeasured. Head also improves the oversized-element case by checking element sizes before copying. Use bulk-owned immutable initial storage with aliasing handles to avoid per-item owner allocations while retaining distinct stable addresses and ownership-backed lifetimes. Do not copy Tapscript's 1,000-item precheck to v0: a first opcode such as CHECKMULTISIG can consume arguments before the size check.


Coverage details