Skip to content

fix(bitvec): return 0 for concrete ADDMOD/MULMOD with a zero modulus - #598

Open
mayuriphad wants to merge 2 commits into
a16z:mainfrom
mayuriphad:fix/addmod-mulmod-zero-modulus
Open

mayuriphad wants to merge 2 commits into
a16z:mainfrom
mayuriphad:fix/addmod-mulmod-zero-modulus

Conversation

@mayuriphad

Copy link
Copy Markdown

The EVM defines ADDMOD and MULMOD with a zero modulus as 0. The fully concrete fast path in HalmosBitVec.addmod and HalmosBitVec.mulmod computed (a + b) % modulus.value directly, so a zero modulus raised ZeroDivisionError and aborted execution. The symbolic path already goes through mod, which returns 0.

Both fast paths now return 0 when the modulus is 0. The bytecode 6000600260030800 (PUSH1 0, PUSH1 2, PUSH1 3, ADDMOD, STOP) from the issue now finishes, and the same holds for MULMOD.

Fixes #595

Added concrete addmod/mulmod cases to tests/test_bitvec.py that fail with ZeroDivisionError without the change.

Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 21, 2026 04:29
Signed-off-by: mayuriphad <mayuriphad656@gmail.com>

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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.

ADDMOD and MULMOD crash when the modulus is zero

2 participants