Skip to content

Ts/instr#50

Merged
tcrypt25519 merged 2 commits into
masterfrom
ts/instr
Feb 12, 2026
Merged

Ts/instr#50
tcrypt25519 merged 2 commits into
masterfrom
ts/instr

Conversation

@tcrypt25519

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings February 12, 2026 01:43
@semanticdiff-com

semanticdiff-com Bot commented Feb 12, 2026

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  crates/jet/src/instructions.rs  24% smaller
  crates/jet/src/builder/contract.rs  0% smaller

@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 refactors the bytecode instruction processing logic within the jet crate. It streamlines the Instruction enum by adding Copy and #[repr(u8)] attributes and introduces const fn for instruction properties. The core change involves redesigning the instruction iterator to yield raw data slices for PUSH operations, shifting the responsibility of data manipulation (such as byte reversal and padding) to the bytecode builder. This improves modularity and efficiency in handling bytecode execution.

Highlights

  • Instruction Iterator Refactoring: The bytecode instruction iterator (instructions::Iter) was refactored to provide raw data slices for PUSH operations, deferring data processing (like byte reversal and padding) to the consumer.
  • PUSH Data Handling Update: The contract builder now explicitly handles byte reversal and padding of PUSH instruction data to a 32-byte array before pushing it onto the stack.
  • Instruction Enum Enhancements: The Instruction enum gained Copy trait derivation, #[repr(u8)] for explicit byte representation, and new const fn methods (opcode, is_push, push_len) for compile-time evaluation and efficiency.
Changelog
  • crates/jet/src/builder/contract.rs
    • Updated imports to use Iter and IterItem from the instructions module.
    • Modified find_code_blocks and build_code_block functions to correctly process the new IterItem variants.
    • Implemented explicit byte reversal and padding for PUSH instruction data before calling ops::push.
  • crates/jet/src/instructions.rs
    • Renamed the Iterator struct to Iter and the IteratorItem enum to IterItem.
    • Added Copy trait derivation and #[repr(u8)] attribute to the Instruction enum for better performance and explicit byte representation.
    • Introduced const fn methods (opcode, is_push, push_len) to the Instruction enum for compile-time evaluation.
    • Modified IterItem::PushData to include the Instruction and a raw byte slice (&'a [u8]) instead of a pre-processed 32-byte array.
    • Simplified the Iter::next method by removing the byte reversal and padding logic for PUSH instructions, deferring it to the consumer.
Activity
  • The pull request was opened by tcrypt25519.
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.

@tcrypt25519
tcrypt25519 merged commit 992dd4d into master Feb 12, 2026
5 checks passed

@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 significantly improves the instruction handling logic. The Instruction enum is now more efficient with Copy and #[repr(u8)]. The instruction iterator has been refactored for better robustness, fixing a potential infinite loop on invalid opcodes and preventing panics from malformed PUSH instructions. The logic for processing PUSH data has been moved and optimized to avoid heap allocations. These are excellent changes that improve performance, correctness, and maintainability.

Comment on lines +34 to 47
#[inline]
pub const fn is_push(self) -> bool {
let op = self.opcode();
op >= 0x5f && op <= 0x7f // PUSH0..PUSH32
}

#[inline]
pub const fn push_len(self) -> usize {
if self.is_push() {
(self.opcode() - 0x5f) as usize
} else {
0
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using magic numbers like 0x5f and 0x7f makes the code harder to read and maintain. It's better to use the Instruction enum variants directly to represent these opcodes. This improves clarity and ensures that if the opcode values ever change, this code will update automatically.

Since opcode() is a const fn, you can use Instruction::PUSH0.opcode() and Instruction::PUSH32.opcode() within these const functions.

Suggested change
#[inline]
pub const fn is_push(self) -> bool {
let op = self.opcode();
op >= 0x5f && op <= 0x7f // PUSH0..PUSH32
}
#[inline]
pub const fn push_len(self) -> usize {
if self.is_push() {
(self.opcode() - 0x5f) as usize
} else {
0
}
}
#[inline]
pub const fn is_push(self) -> bool {
let op = self.opcode();
op >= Self::PUSH0.opcode() && op <= Self::PUSH32.opcode()
}
#[inline]
pub const fn push_len(self) -> usize {
if self.is_push() {
(self.opcode() - Self::PUSH0.opcode()) as usize
} else {
0
}
}

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

This PR refactors the EVM instruction iteration layer in crates/jet to make opcodes cheaper to work with (Copy + repr(u8)) and to change PUSH handling from “materialize a 32-byte immediate in the iterator” to “yield a borrowed slice and let the builder construct the 32-byte word”.

Changes:

  • Make Instruction Copy with #[repr(u8)], and add opcode(), is_push(), and push_len() as const fns.
  • Replace instructions::Iterator/IteratorItem with instructions::Iter/IterItem, and have PUSH yield (pc, instr, &[u8]) rather than [u8; 32].
  • Move PUSH immediate endian conversion/allocation work into builder/contract.rs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crates/jet/src/instructions.rs Refactors instruction enum + introduces Iter/IterItem with borrowed PUSH data slices.
crates/jet/src/builder/contract.rs Updates bytecode walking to use Iter and reconstructs PUSH immediates for ops::push.

Comment on lines +380 to +383
let mut new_data = [0u8; 32];
new_data[..data.len()].copy_from_slice(data);
new_data[..data.len()].reverse();

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

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

PUSH immediate decoding is incorrect when the bytecode ends before all expected immediate bytes are present. data only contains the available bytes, but EVM semantics treat missing PUSH bytes as 0x00 at the end of the immediate (big-endian), which affects the numeric value after reversing to little-endian. Current code reverses only data.len() bytes, so e.g. PUSH2 0xAA would become 0x00AA instead of 0xAA00. Use the included Instruction (push length) to pad missing bytes before reversing / constructing the 32-byte word.

Copilot uses AI. Check for mistakes.
Comment on lines +248 to +257
let push_len = instr.push_len();
let push_start = pc + 1;
let push_end = push_start + push_len;

// Copy the push data into a 32-byte array, converting from big endian to little endian
let push_data = {
let mut data = [0; 32];
match push_len {
0 => (),
_ => {
let reversed = &self.rom[push_start..push_end]
.iter()
.rev()
.cloned()
.collect::<Vec<u8>>();
data[..push_len].copy_from_slice(reversed.as_slice())
}
};
data
};
let push_end = std::cmp::min(push_start + push_len, self.rom.len());

self.pc += push_len + 1;
Some(IteratorItem::PushData(pc, push_data))
self.pc = push_end;
Some(IterItem::PushData(
pc,
instr,
&self.rom[push_start..push_end],
))

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

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

The iterator now yields potentially-short PUSH immediates at EOF (via min(push_start + push_len, rom.len())). Given the subtle semantics around missing PUSH bytes being treated as zero, it would be good to add a ROM test that ends with a truncated PUSHn (e.g. PUSH2 0xAA at EOF) to lock in correct padding/endianness behavior.

Copilot uses AI. Check for mistakes.
tcrypt25519 added a commit that referenced this pull request Feb 16, 2026
* tweak: Better utilize comp-time work.
@tcrypt25519
tcrypt25519 deleted the ts/instr 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.

2 participants