This introduces versions of GetScriptOp
, EvalScript
, and VerifyScript
that operate on scripts represented by Span<const unsigned char>
. This makes it possible to use different representation types for scripts, as Spans can be used to refer to scripts stored in any continuous fashion in memory, regardless of the container.
This is also a step towards reducing the consensus-criticalness of CScript, but not entirely. The interpreter code still uses CScript internally for a few purposes (notably DecodeOP_N
, and operator<<
).
Longer term, the goal is removing the need for all scripts to share the same representation. Currently CScript
is a prevector with 28 preallocated bytes - a choice we need because it’s favorable for scriptPubKeys in the UTXO cache, but it’s pretty terrible for storing scriptSigs. With this change, separate (or even custom) data structures can be used for UTXO scriptPubKeys, and scriptPubKeys/scriptSigs in transactions. One possibility for the latter is storing all scripts in a transaction concatenated in a single allocated area, rather than using separate allocations for each.