Skip to content

Commit

Permalink
Add srcOffset overflow handling
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Oct 30, 2024
1 parent 8e0ec51 commit a186279
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions system-contracts/contracts/EvmEmulator.yul
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ object "EvmEmulator" {
max_uint := 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
}

function MAX_UINT64() -> max {
max := sub(shl(64, 1), 1)
}

// Each evm gas is 5 zkEVM one
function GAS_DIVISOR() -> gas_div { gas_div := 5 }

Expand Down Expand Up @@ -1657,6 +1661,10 @@ object "EvmEmulator" {

evmGasLeft := chargeGas(evmGasLeft, dynamicGas)

if gt(srcOffset, MAX_UINT64()) {
srcOffset := MAX_UINT64()
}

if gt(len, 0) {
let realCodeLen
if getRawCodeHash(addr) {
Expand Down Expand Up @@ -3177,6 +3185,10 @@ object "EvmEmulator" {
max_uint := 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
}

function MAX_UINT64() -> max {
max := sub(shl(64, 1), 1)
}

// Each evm gas is 5 zkEVM one
function GAS_DIVISOR() -> gas_div { gas_div := 5 }

Expand Down Expand Up @@ -4659,6 +4671,10 @@ object "EvmEmulator" {

evmGasLeft := chargeGas(evmGasLeft, dynamicGas)

if gt(srcOffset, MAX_UINT64()) {
srcOffset := MAX_UINT64()
}

if gt(len, 0) {
let realCodeLen
if getRawCodeHash(addr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ function MAX_UINT() -> max_uint {
max_uint := 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
}

function MAX_UINT64() -> max {
max := sub(shl(64, 1), 1)
}

// Each evm gas is 5 zkEVM one
function GAS_DIVISOR() -> gas_div { gas_div := 5 }

Expand Down
4 changes: 4 additions & 0 deletions system-contracts/evm-emulator/EvmEmulatorLoop.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ for { } true { } {

evmGasLeft := chargeGas(evmGasLeft, dynamicGas)

if gt(srcOffset, MAX_UINT64()) {
srcOffset := MAX_UINT64()
}

if gt(len, 0) {
let realCodeLen
if getRawCodeHash(addr) {
Expand Down

0 comments on commit a186279

Please sign in to comment.