Skip to content

Commit

Permalink
Add stack overflow check in dupStackItem
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Nov 13, 2024
1 parent 397092d commit 7815225
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 @@ -479,6 +479,11 @@ object "EvmEmulator" {

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

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

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

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

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

if iszero(lt(sp, BYTECODE_LEN_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 @@ -417,6 +417,11 @@ function performSystemCallRevertable(to, dataLength) -> success {

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

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

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

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

0 comments on commit 7815225

Please sign in to comment.