Skip to content

Commit

Permalink
fea(EVM): Optimize JUMP gas charge (#1025)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov authored Oct 27, 2024
1 parent 646a408 commit 5d6830c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
8 changes: 2 additions & 6 deletions system-contracts/contracts/EvmEmulator.yul
Original file line number Diff line number Diff line change
Expand Up @@ -1954,10 +1954,9 @@ object "EvmEmulator" {
// NOTE: We don't currently do full jumpdest validation
// (i.e. validating a jumpdest isn't in PUSH data)
case 0x56 { // OP_JUMP
evmGasLeft := chargeGas(evmGasLeft, 8)
evmGasLeft := chargeGas(evmGasLeft, 9) // charge for OP_JUMP (8) and OP_JUMPDEST (1) immediately

let counter

counter, sp, stackHead := popStackItem(sp, stackHead)

ip := add(add(BYTECODE_OFFSET(), 32), counter)
Expand All @@ -1969,7 +1968,6 @@ object "EvmEmulator" {
}

// execute JUMPDEST immediately
evmGasLeft := chargeGas(evmGasLeft, 1)
ip := add(ip, 1)
}
case 0x57 { // OP_JUMPI
Expand Down Expand Up @@ -4973,10 +4971,9 @@ object "EvmEmulator" {
// NOTE: We don't currently do full jumpdest validation
// (i.e. validating a jumpdest isn't in PUSH data)
case 0x56 { // OP_JUMP
evmGasLeft := chargeGas(evmGasLeft, 8)
evmGasLeft := chargeGas(evmGasLeft, 9) // charge for OP_JUMP (8) and OP_JUMPDEST (1) immediately

let counter

counter, sp, stackHead := popStackItem(sp, stackHead)

ip := add(add(BYTECODE_OFFSET(), 32), counter)
Expand All @@ -4988,7 +4985,6 @@ object "EvmEmulator" {
}

// execute JUMPDEST immediately
evmGasLeft := chargeGas(evmGasLeft, 1)
ip := add(ip, 1)
}
case 0x57 { // OP_JUMPI
Expand Down
4 changes: 1 addition & 3 deletions system-contracts/evm-emulator/EvmEmulatorLoop.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,9 @@ for { } true { } {
// NOTE: We don't currently do full jumpdest validation
// (i.e. validating a jumpdest isn't in PUSH data)
case 0x56 { // OP_JUMP
evmGasLeft := chargeGas(evmGasLeft, 8)
evmGasLeft := chargeGas(evmGasLeft, 9) // charge for OP_JUMP (8) and OP_JUMPDEST (1) immediately

let counter

counter, sp, stackHead := popStackItem(sp, stackHead)

ip := add(add(BYTECODE_OFFSET(), 32), counter)
Expand All @@ -721,7 +720,6 @@ for { } true { } {
}

// execute JUMPDEST immediately
evmGasLeft := chargeGas(evmGasLeft, 1)
ip := add(ip, 1)
}
case 0x57 { // OP_JUMPI
Expand Down

0 comments on commit 5d6830c

Please sign in to comment.