Skip to content

Test signed right shift on pre-Constantinople EVMs via IR codegen#16755

Open
msooseth wants to merge 1 commit into
developfrom
shift-right-signed-pre-constantinople-test
Open

Test signed right shift on pre-Constantinople EVMs via IR codegen#16755
msooseth wants to merge 1 commit into
developfrom
shift-right-signed-pre-constantinople-test

Conversation

@msooseth
Copy link
Copy Markdown
Contributor

Summary

  • YulUtilFunctions::shiftRightSignedFunctionDynamic has two arms: sar(bits, value) on Constantinople+, and a manual xor(div(xor(value, mask), divisor), mask) fallback on earlier EVMs.
  • The fallback arm was not directly exercised by any existing semantic test under via-IR:
    • operators/shifts/shift_right_garbled_signed_v1.sol is explicitly compileViaYul: false.
    • operators/shifts/bitwise_shifting_constantinople*.sol are >=constantinople.
  • This PR adds operators/shifts/shift_right_signed_pre_constantinople.sol with EVMVersion: <constantinople and compileViaYul: also, covering int8 and int256 boundaries (sign bit set/unset, INT*_MIN, INT*_MAX, shift amounts 0, 1, type-bits-1, type-bits, and ≥ 256).
  • For the int8 cases the byte is placed into the local via inline assembly (matching shift_right_garbled_signed_v2.sol) so Solidity's cleanup-on-read does the sign extension — avoiding the ABI v2 decoder rejecting non-sign-extended int8 calldata.

No production code changes; this is pure coverage.

Test plan

  • Local run: isoltest --evm-version byzantium -t "semanticTests/operators/shifts/shift_right_signed_pre_constantinople" → OK (both legacy and via-IR pipelines).
  • CI runs the test on a pre-Constantinople EVM batch.

YulUtilFunctions::shiftRightSignedFunctionDynamic emits either sar(bits, value)
on Constantinople+ or a manual xor/div/xor fallback on earlier EVMs. The
fallback path was not directly exercised by any existing semantic test under
via-IR: shift_right_garbled_signed_v1.sol is explicitly compileViaYul: false,
and bitwise_shifting_constantinople*.sol are >=constantinople. Add a test
that pins down signed right shift semantics on <constantinople with
compileViaYul: also, covering int8 and int256 boundaries (sign bit set/unset,
INT*_MIN, INT*_MAX, shift amounts 0, 1, type bits-1, type bits, and >= 256).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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