Skip to content

More predictable handling of excessive shifts#2

Merged
bitjson merged 1 commit intomasterfrom
range
Jun 9, 2025
Merged

More predictable handling of excessive shifts#2
bitjson merged 1 commit intomasterfrom
range

Conversation

@bitjson
Copy link
Owner

@bitjson bitjson commented Jun 6, 2025

Predictable Handling of Excessive Shift Operations

This proposal requires only that shift operations specify non-negative bit counts. All shifts greater than or equal to 0 are valid, with clear, consistent behavior: binary shifts continue to "clear" (zero-fill) bits up to and beyond the item's length, excessive right arithmetic shifts correctly result in 0 or -1 (see Behavior of Arithmetic Right Shifts on Negative Values), and left shifts fail only for results which would be rejected due to stack item length limits (matching OP_MUL; implementations may optionally include a fast-failure path).

This proposal's behavior aligns with the existing numeric operations, maximizes the predictability of shift operations (by eliminating potentially-unexpected failures due to excessive shifts by otherwise-valid VM numbers), minimizes room for implementation-specific errors (e.g. the OP_RSHIFT crash and CVE-2010-5137 OP_LSHIFT crash), and reduces overall protocol complexity.

@bitjson bitjson merged commit 1c95458 into master Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant