Review report

bitcoin/bitcoin: PR #36721

2 suggestions

Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · EvalScript allocates Boolean result elements even when unused

Native Taproot key-path verification pays for six unused allocations whenever VerifyScript runs, because both preliminary EvalScript calls eagerly create true and false elements.

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

Details and suggested fix

The two MakeStackElem calls and valtype(1, 1)'s one-byte buffer replace the former static vectors with three allocations per call. VerifyScript evaluates the empty scriptSig and OP_1 <32-byte program> scriptPubKey before reaching the direct key-path Schnorr check. Those scripts never use elemFalse or elemTrue; OP_1 builds a separate numeric element. Start with empty execution-local handles and create the selected Boolean on first use through a push_bool helper. This avoids unused allocations while preserving immutable per-execution sharing without cross-thread reference-count contention. Full-script-cache hits bypass VerifyScript entirely. Lazy initialization adds a null check per Boolean push, and its wall-clock benefit remains unmeasured.


Link

[suggestion] · Saved element handles incur redundant reference-count updates

Copying each saved shared_ptr into its final stack slot adds a redundant reference-count increment/decrement pair that moving the local handle would avoid.

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

Details and suggested fix

OP_DUP copies the top handle into elem, copies elem into the new slot, then destroys elem. Use stack.push_back(std::move(elem)) for that last insertion, following OP_TUCK's existing pattern. The same last-use copies occur in OP_2DUP, OP_3DUP, OP_2OVER, OP_2ROT, OP_IFDUP, OP_OVER and OP_PICK/OP_ROLL. Keep the initial copies from stack slots: they preserve ownership across vector reallocation and keep erased source elements alive in OP_2ROT and OP_ROLL. Moving only the saved locals preserves final stack bytes, element identities and owner counts while removing redundant reference-count operations on duplication-heavy paths. The timing benefit is platform-dependent and unmeasured.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.