Skip to content

Commit

Permalink
fix(EVM): Add stack overflow check in dup (#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Dec 6, 2024
1 parent 5baae31 commit b1e69d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions system-contracts/contracts/EvmEmulator.yul
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ object "EvmEmulator" {

function dupStackItem(sp, evmGas, position, oldStackHead) -> newSp, evmGasLeft, stackHead {
evmGasLeft := chargeGas(evmGas, 3)

if iszero(lt(sp, MAX_STACK_SLOT_OFFSET())) {
panic()
}

let tempSp := sub(sp, mul(0x20, sub(position, 1)))

if lt(tempSp, STACK_OFFSET()) {
Expand Down Expand Up @@ -3497,6 +3502,11 @@ object "EvmEmulator" {

function dupStackItem(sp, evmGas, position, oldStackHead) -> newSp, evmGasLeft, stackHead {
evmGasLeft := chargeGas(evmGas, 3)

if iszero(lt(sp, MAX_STACK_SLOT_OFFSET())) {
panic()
}

let tempSp := sub(sp, mul(0x20, sub(position, 1)))

if lt(tempSp, STACK_OFFSET()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ function performSystemCallRevertable(to, dataLength) -> success {

function dupStackItem(sp, evmGas, position, oldStackHead) -> newSp, evmGasLeft, stackHead {
evmGasLeft := chargeGas(evmGas, 3)

if iszero(lt(sp, MAX_STACK_SLOT_OFFSET())) {
panic()
}

let tempSp := sub(sp, mul(0x20, sub(position, 1)))

if lt(tempSp, STACK_OFFSET()) {
Expand Down

0 comments on commit b1e69d0

Please sign in to comment.