Skip to content

Add EXP and SIGNEXTEND. #43

Merged
tcrypt25519 merged 9 commits into
masterfrom
ts/exp
Feb 10, 2026
Merged

Add EXP and SIGNEXTEND. #43
tcrypt25519 merged 9 commits into
masterfrom
ts/exp

Conversation

@tcrypt25519

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings February 8, 2026 18:02
@semanticdiff-com

semanticdiff-com Bot commented Feb 8, 2026

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  .github/workflows/ci.yml  19% smaller
  crates/jet/tests/test_roms.rs  1% smaller
  Cargo.lock Unsupported file format
  crates/jet/src/builder/env.rs  0% smaller
  crates/jet/src/builder/ops.rs  0% smaller
  crates/jet/src/engine/mod.rs  0% smaller
  crates/jet/tests/roms/mod.rs  0% smaller
  crates/jet_runtime/Cargo.toml Unsupported file format
  crates/jet_runtime/src/builtins.rs  0% smaller
  crates/jet_runtime/src/runtime_builder.rs  0% smaller
  crates/jet_runtime/src/symbols.rs  0% smaller
  docs/process/new-opcode.md Unsupported file format
  scripts/install-llvm.sh Unsupported file format

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @tcrypt25519, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the arithmetic capabilities of the system by adding a new EXP (exponentiation) operation and completing the implementation of the SIGNEXTEND operation. These changes enable more complex mathematical computations, particularly involving large integers, within the JIT execution environment. The integration of the ruint library underpins these new functionalities, providing robust support for arbitrary-precision arithmetic.

Highlights

  • New EXP (Exponentiation) Operation: Introduced a new EXP operation to perform modular exponentiation on 256-bit integers within the JIT execution environment.
  • SIGNEXTEND Implementation: The SIGNEXTEND operation, previously a placeholder, has been fully implemented to correctly handle sign extension for 256-bit integers.
  • Ruint Library Integration: Integrated the ruint library for arbitrary-precision unsigned integers, which is fundamental for handling large number arithmetic in the new EXP operation.
Changelog
  • Cargo.lock
    • Added numerous new dependencies, including alloy-rlp, ark-ff (multiple versions), bitvec, bytes, fastrlp (multiple versions), num-bigint, num-traits, parity-scale-codec, proptest, rand (multiple versions), ruint, uint, and zerocopy, to support the new arithmetic operations.
    • Updated several syn and semver related dependencies to specific versions (e.g., syn 2.0.114, semver 0.11.0, semver 1.0.27).
  • crates/jet/src/builder/env.rs
    • Added exp: FunctionValue<'ctx> to the Symbols struct.
    • Initialized the exp function by retrieving jet_runtime::symbols::FN_EXP from the module.
    • Provided a public getter exp() for the new exponentiation function.
  • crates/jet/src/builder/ops.rs
    • Implemented the exp function to pop base and exponent from the stack, call the runtime exp function, and push the result.
    • Provided a full implementation for the signextend function, including logic for clamping and arithmetic shifts to achieve proper sign extension for 256-bit integers.
  • crates/jet/src/engine/mod.rs
    • Mapped the exp symbol to the builtins::jet_ops_exp runtime function within the JIT engine.
  • crates/jet_runtime/Cargo.toml
    • Added ruint = "1" as a direct dependency to enable arbitrary-precision integer arithmetic.
  • crates/jet_runtime/src/builtins.rs
    • Implemented the jet_ops_exp extern "C" function, which performs exponentiation using ruint::aliases::U256 and stores the result in a 32-byte array.
  • crates/jet_runtime/src/runtime_builder.rs
    • Added the jet.ops.exp function to the LLVM module with its specified signature.
  • crates/jet_runtime/src/symbols.rs
    • Defined the symbolic constant FN_EXP as 'jet.ops.exp'.
Activity
  • The pull request introduces a new EXP operation and completes the SIGNEXTEND implementation.
  • Significant changes were made to dependency management, particularly the addition of the ruint library and its transitive dependencies, to support large integer arithmetic.
  • Modifications span across the jet and jet_runtime crates, affecting the JIT builder, engine, runtime functions, and symbol definitions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces implementations for the EXP and SIGNEXTEND EVM opcodes. While the SIGNEXTEND implementation appears correct, a critical endianness mismatch has been identified in the jet_ops_exp builtin function. The EXP implementation incorrectly treats values as big-endian, despite the VM using host-endianness (little-endian) for stack and memory. This will lead to incorrect results for the EXP instruction on little-endian platforms and must be addressed. The overall structure of the changes is good, with one minor suggestion for readability.

Comment thread crates/jet_runtime/src/builtins.rs

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.

Pull request overview

Adds runtime/JIT plumbing to support the EVM EXP opcode by introducing a new runtime symbol and builtin, wiring it into the JIT symbol map, and updating the IR builder to call it. The PR also includes an implementation of SIGNEXTEND in the IR builder.

Changes:

  • Add new runtime symbol jet.ops.exp and declare it in the runtime LLVM module.
  • Implement jet_ops_exp builtin and link it into the JIT symbol mapping.
  • Implement SIGNEXTEND IR generation in crates/jet/src/builder/ops.rs.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
crates/jet_runtime/src/symbols.rs Adds FN_EXP symbol name for runtime lookup.
crates/jet_runtime/src/runtime_builder.rs Declares external builtin jet.ops.exp in the runtime module.
crates/jet_runtime/src/builtins.rs Adds jet_ops_exp runtime implementation.
crates/jet_runtime/Cargo.toml Introduces ruint dependency for U256 math.
crates/jet/src/engine/mod.rs Maps jet.ops.exp symbol to the Rust builtin in the JIT engine.
crates/jet/src/builder/ops.rs Emits IR to call EXP builtin and implements SIGNEXTEND in IR.
crates/jet/src/builder/env.rs Loads and exposes the new exp runtime function symbol.
Cargo.lock Updates lockfile for the new dependency graph.

Comment thread crates/jet/src/builder/ops.rs
Comment thread crates/jet/src/builder/ops.rs
Comment thread crates/jet_runtime/Cargo.toml
Comment thread crates/jet/src/builder/ops.rs
Comment thread crates/jet_runtime/src/builtins.rs Outdated
Comment thread crates/jet/src/builder/ops.rs
@tcrypt25519 tcrypt25519 changed the title Add EXP. Add EXP and SIGNEXTEND. Feb 8, 2026
tcrypt25519 and others added 6 commits February 8, 2026 21:20
The cache was hitting old entries built for static linking, causing
"unable to find library -lLLVM-21" errors after adding the
llvm21-1-prefer-dynamic feature to inkwell. Adding v2 prefix to force
a fresh LLVM installation with dynamic libraries.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The llvm-21-dev package only provides static libraries and headers.
When inkwell uses llvm21-1-prefer-dynamic, the linker needs the shared
library libLLVM-21.so, which comes from the libllvm21 package.

This was causing intermittent "unable to find library -lLLVM-21" errors
because the cached LLVM installations didn't include the shared library.

Changes:
- Add libllvm21 to apt-get install in scripts/install-llvm.sh
- Bump CI cache key to v3 to force fresh installation with shared lib

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Track EVM memory length correctly by expanding memory before writes and
updating memory_len to match EVM semantics (32-byte word-aligned).

Implementation:
- Add jet_mem_expand builtin that:
  * Checks for offset + size overflow
  * Rounds up to 32-byte boundaries
  * Updates memory_len monotonically
  * Reallocates and zeros new memory if needed
- Hook MSTORE (32 bytes) and MSTORE8 (1 byte) to call expansion before write
- Add memory_len field to TestContractRun for validation

Tests (all passing):
- MSTORE at offsets 0, 31, 32 expands to 32, 64, 64 bytes
- MSTORE8 at offsets 0, 31, 32 expands to 32, 32, 64 bytes
- Memory expansion is word-aligned and monotonic

Closes #41

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@tcrypt25519
tcrypt25519 merged commit 63b533d into master Feb 10, 2026
1 check failed
@tcrypt25519 tcrypt25519 linked an issue Feb 10, 2026 that may be closed by this pull request
tcrypt25519 added a commit that referenced this pull request Feb 16, 2026
* Add EXP.

* style: apply rustfmt formatting 🤖

* fixes

* ci: force LLVM cache invalidation for dynamic linking

The cache was hitting old entries built for static linking, causing
"unable to find library -lLLVM-21" errors after adding the
llvm21-1-prefer-dynamic feature to inkwell. Adding v2 prefix to force
a fresh LLVM installation with dynamic libraries.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix: install libllvm21 for dynamic linking support

The llvm-21-dev package only provides static libraries and headers.
When inkwell uses llvm21-1-prefer-dynamic, the linker needs the shared
library libLLVM-21.so, which comes from the libllvm21 package.

This was causing intermittent "unable to find library -lLLVM-21" errors
because the cached LLVM installations didn't include the shared library.

Changes:
- Add libllvm21 to apt-get install in scripts/install-llvm.sh
- Bump CI cache key to v3 to force fresh installation with shared lib

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* feat: implement memory expansion tracking for MSTORE and MSTORE8

Track EVM memory length correctly by expanding memory before writes and
updating memory_len to match EVM semantics (32-byte word-aligned).

Implementation:
- Add jet_mem_expand builtin that:
  * Checks for offset + size overflow
  * Rounds up to 32-byte boundaries
  * Updates memory_len monotonically
  * Reallocates and zeros new memory if needed
- Hook MSTORE (32 bytes) and MSTORE8 (1 byte) to call expansion before write
- Add memory_len field to TestContractRun for validation

Tests (all passing):
- MSTORE at offsets 0, 31, 32 expands to 32, 64, 64 bytes
- MSTORE8 at offsets 0, 31, 32 expands to 32, 32, 64 bytes
- Memory expansion is word-aligned and monotonic

Closes #41

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* ci: bump LLVM cache to v4

* fix: use div_ceil for memory expansion rounding

* docs: Add process doc for adding opcodes.

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
@tcrypt25519
tcrypt25519 deleted the ts/exp branch February 16, 2026 20:03
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.

Implement EXP and SIGNEXTEND opcodes

2 participants