Skip to content

Commit 09c6def

Browse files
edg-lazteca1998
andauthored
perf(levm): process JUMPDEST gas and pc together within the given JUMP/JUMPI opcode (#4220)
**Motivation** It's basically #3763 without the nop slide, see the discussion there. It only skips 1 jumpdest if coming from a jump, but doesn't slide if there are a lot of sequential jumpdests afterwards. Still has improvements overall to a lot of benches <img width="1405" height="4352" alt="image" src="https://github.com/user-attachments/assets/88748fd2-f2b0-436b-bed0-33d163779872" /> --------- Co-authored-by: Esteve Soler Arderiu <[email protected]>
1 parent 0299d04 commit 09c6def

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Perf
44

5+
### 2025-09-01
6+
7+
- Process JUMPDEST gas and pc together with the given JUMP JUMPI opcode, improving performance. #[4220](https://github.com/lambdaclass/ethrex/pull/4220)
8+
59
### 2025-08-29
610

711
- Improve P2P mempool gossip performance [#4205](https://github.com/lambdaclass/ethrex/pull/4205)
@@ -53,7 +57,6 @@
5357
- Make `JUMPDEST` blacklist lazily generated on-demand [#3812](https://github.com/lambdaclass/ethrex/pull/3812)
5458
- Rewrite Blake2 AVX2 implementation (avoid gather instructions and better loop handling).
5559

56-
5760
### 2025-07-30
5861

5962
- Add a secondary index keyed by sender+nonce to the mempool to avoid linear lookups [#3865](https://github.com/lambdaclass/ethrex/pull/3865)

crates/vm/levm/src/opcode_handlers/stack_memory_storage_flow.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,11 @@ impl<'a> VM<'a> {
330330
.try_into()
331331
.map_err(|_err| ExceptionalHalt::VeryLargeNumber)?;
332332

333+
#[expect(clippy::arithmetic_side_effects)]
333334
if Self::target_address_is_valid(call_frame, jump_address_usize) {
334-
call_frame.pc = jump_address_usize;
335+
call_frame.increase_consumed_gas(gas_cost::JUMPDEST)?;
336+
337+
call_frame.pc = jump_address_usize + 1;
335338
Ok(())
336339
} else {
337340
Err(ExceptionalHalt::InvalidJump.into())
@@ -340,14 +343,14 @@ impl<'a> VM<'a> {
340343

341344
// JUMPI operation
342345
pub fn op_jumpi(&mut self) -> Result<OpcodeResult, VMError> {
343-
let current_call_frame = &mut self.current_call_frame;
344-
let [jump_address, condition] = *current_call_frame.stack.pop()?;
346+
let [jump_address, condition] = *self.current_call_frame.stack.pop()?;
345347

346-
current_call_frame.increase_consumed_gas(gas_cost::JUMPI)?;
348+
self.current_call_frame
349+
.increase_consumed_gas(gas_cost::JUMPI)?;
347350

348351
let pc_increment = if !condition.is_zero() {
349352
// Move the PC but don't increment it afterwards
350-
Self::jump(current_call_frame, jump_address)?;
353+
Self::jump(&mut self.current_call_frame, jump_address)?;
351354
0
352355
} else {
353356
1
@@ -357,8 +360,9 @@ impl<'a> VM<'a> {
357360

358361
// JUMPDEST operation
359362
pub fn op_jumpdest(&mut self) -> Result<OpcodeResult, VMError> {
360-
let current_call_frame = &mut self.current_call_frame;
361-
current_call_frame.increase_consumed_gas(gas_cost::JUMPDEST)?;
363+
self.current_call_frame
364+
.increase_consumed_gas(gas_cost::JUMPDEST)?;
365+
362366
Ok(OpcodeResult::Continue { pc_increment: 1 })
363367
}
364368

0 commit comments

Comments
 (0)