Skip to content

Add zero-denominator guards to SMOD, ADDMOD, MULMOD#57

Closed
tcrypt25519 with Copilot wants to merge 4 commits into
mainfrom
copilot/guard-smod-addmod-mulmod-zero
Closed

Add zero-denominator guards to SMOD, ADDMOD, MULMOD#57
tcrypt25519 with Copilot wants to merge 4 commits into
mainfrom
copilot/guard-smod-addmod-mulmod-zero

Conversation

Copilot AI commented Feb 13, 2026

Copy link
Copy Markdown

SMOD, ADDMOD, and MULMOD were missing zero-denominator checks required by EVM spec. Per spec, these operations must return 0 when the denominator is 0.

Changes

  • ops.rs: Added zero guards to smod(), addmod(), and mulmod() following existing DIV/MOD pattern
  • test_roms.rs: Added tests verifying zero-denominator behavior

Implementation

Uses LLVM select to conditionally return zero:

let zero = bctx.env.types().i256.const_zero();
let c_is_zero = bctx.builder.build_int_compare(
    inkwell::IntPredicate::EQ, c, zero, "c_is_zero"
)?;

let mod_result = bctx.builder.build_int_unsigned_rem(result, c, "mod_result")?;
let result = bctx.builder.build_select(c_is_zero, zero, mod_result, "final")?;

This matches the pattern already used by DIV (line 381) and MOD (line 411).

Original prompt

This section details on the original issue you should resolve

<issue_title>SMOD/ADDMOD/MULMOD need to guard on 0</issue_title>
<issue_description>SMOD/ADDMOD/MULMOD Must check for the second argument being a zero, and if so, should use zero as the result of the entire operation. This is currently done in DIV, for reference.

Originally posted by @Copilot in #48 (comment)
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@semanticdiff-com

semanticdiff-com Bot commented Feb 13, 2026

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  crates/jet/src/builder/ops.rs  21% smaller
  crates/jet/tests/test_roms.rs  0% smaller

Copilot AI and others added 2 commits February 13, 2026 09:08
Co-authored-by: tcrypt25519 <212655132+tcrypt25519@users.noreply.github.com>
Co-authored-by: tcrypt25519 <212655132+tcrypt25519@users.noreply.github.com>
Copilot AI changed the title [WIP] Add guard on zero for SMOD, ADDMOD, and MULMOD operations Add zero-denominator guards to SMOD, ADDMOD, MULMOD Feb 13, 2026
Copilot AI requested a review from tcrypt25519 February 13, 2026 09:14
@tcrypt25519
tcrypt25519 deleted the copilot/guard-smod-addmod-mulmod-zero branch February 16, 2026 20:02
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.

SMOD/ADDMOD/MULMOD need to guard on 0

2 participants