Skip to content

[mlir][Sol] Keep the panics of div, mod and constant indexing - #192

Merged
hedgar2017 merged 1 commit into
mainfrom
sol-op-lowering-checks
Nov 5, 2026
Merged

hedgar2017 merged 1 commit into
mainfrom
sol-op-lowering-checks

Conversation

@hedgar2017

Copy link
Copy Markdown
Contributor

Restores three checks legacy solc performs and the Sol lowering dropped:

  • an unused a % b or unchecked a / b panics 0x12 on a zero divisor
  • b[uint8(i)] on fixed bytes checks the cleaned index
  • a constant index past the end of a fixed-size array panics 0x32 in storage, memory and calldata

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The restored panic semantics lack regression coverage across the affected lowering and optimization paths.

4 open findings
What changed in this PR

Restores legacy Solidity panic behavior for division, modulo, fixed-byte indexing, and fixed-array indexing.

Changes:

  • Preserves unused division/modulo operations so zero divisors still panic.
  • Cleans fixed-byte indices before bounds checks.
  • Adds constant-index bounds checks across storage, memory, and calldata.
File Description
mlir/​include/​mlir/​Dialect/​Sol/​SolOps.td Makes division and modulo non-pure.
mlir/​lib/​Conversion/​SolToYul/​SolToYul.cpp Cleans indices and emits unconditional array bounds checks.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread mlir/include/mlir/Dialect/Sol/SolOps.td Resolved

@abinavpp abinavpp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! Could you add lit tests here as well?

@hedgar2017
hedgar2017 force-pushed the sol-op-lowering-checks branch from 6690a40 to ef858e0 Compare November 5, 2026 14:17
@hedgar2017

hedgar2017 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Added the LIT tests.

An unused sol.div or sol.mod was erased with its division-by-zero panic, a fixed-bytes index was bounds-checked with dirty upper bits, and a constant index past the end of a fixed-size array was never bounds-checked.
@hedgar2017
hedgar2017 force-pushed the sol-op-lowering-checks branch from ef858e0 to cbcbf89 Compare November 5, 2026 19:21
@hedgar2017
hedgar2017 merged commit aa85cc0 into main Nov 5, 2026
4 checks passed
@hedgar2017
hedgar2017 deleted the sol-op-lowering-checks branch November 5, 2026 20:15
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.

3 participants