Skip to content

fix: handle division by zero#115

Merged
wjmelements merged 1 commit into
masterfrom
fix/div-by-zero
May 7, 2026
Merged

fix: handle division by zero#115
wjmelements merged 1 commit into
masterfrom
fix/div-by-zero

Conversation

@wjmelements
Copy link
Copy Markdown
Owner

Per EVM spec, DIV/MOD/SDIV/SMOD with a zero divisor must return 0. Previously divmod256 was called unconditionally, causing an infinite loop in the shift-and-subtract implementation.

Changes

  • Guard DIV, SDIV, MOD, SMOD with zero256 check; skip divmod256 when divisor is zero (result slot already holds 0)
  • Add test_div_zero covering all six division/modulo opcodes (DIV, SDIV, MOD, SMOD, ADDMOD, MULMOD) with zero divisor/modulus

@wjmelements wjmelements changed the title Fix Div By Zero fix: handle division by zero May 7, 2026
@wjmelements wjmelements added the bug Something isn't working label May 7, 2026
@wjmelements wjmelements merged commit 17eb57f into master May 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant