Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(EVM): Fix CALL in static context #1091

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions system-contracts/contracts/EvmEmulator.yul
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ object "EvmEmulator" {
// CALLS FUNCTIONALITY
////////////////////////////////////////////////////////////////

function performCall(oldSp, evmGasLeft, oldStackHead) -> newGasLeft, sp, stackHead {
function performCall(oldSp, evmGasLeft, oldStackHead, isStatic) -> newGasLeft, sp, stackHead {
let gasToPass, addr, value, argsOffset, argsSize, retOffset, retSize

popStackCheck(oldSp, 7)
Expand Down Expand Up @@ -676,6 +676,10 @@ object "EvmEmulator" {
gasUsed := add(gasUsed, expandMemory2(retOffset, retSize, argsOffset, argsSize))

if gt(value, 0) {
if isStatic {
panic()
}

gasUsed := add(gasUsed, 9000) // positive_value_cost

if isAddrEmpty(addr) {
Expand All @@ -699,7 +703,7 @@ object "EvmEmulator" {
argsSize,
add(retOffset, MEM_OFFSET()),
retSize,
false
isStatic
)

newGasLeft := add(evmGasLeft, frameGasLeft)
Expand Down Expand Up @@ -2648,13 +2652,7 @@ object "EvmEmulator" {
}
case 0xF1 { // OP_CALL
// A function was implemented in order to avoid stack depth errors.
switch isStatic
case 0 {
evmGasLeft, sp, stackHead := performCall(sp, evmGasLeft, stackHead)
}
default {
evmGasLeft, sp, stackHead := performStaticCall(sp, evmGasLeft, stackHead)
}
evmGasLeft, sp, stackHead := performCall(sp, evmGasLeft, stackHead, isStatic)
ip := add(ip, 1)
}
case 0xF3 { // OP_RETURN
Expand Down Expand Up @@ -3692,7 +3690,7 @@ object "EvmEmulator" {
// CALLS FUNCTIONALITY
////////////////////////////////////////////////////////////////

function performCall(oldSp, evmGasLeft, oldStackHead) -> newGasLeft, sp, stackHead {
function performCall(oldSp, evmGasLeft, oldStackHead, isStatic) -> newGasLeft, sp, stackHead {
let gasToPass, addr, value, argsOffset, argsSize, retOffset, retSize

popStackCheck(oldSp, 7)
Expand Down Expand Up @@ -3724,6 +3722,10 @@ object "EvmEmulator" {
gasUsed := add(gasUsed, expandMemory2(retOffset, retSize, argsOffset, argsSize))

if gt(value, 0) {
if isStatic {
panic()
}

gasUsed := add(gasUsed, 9000) // positive_value_cost

if isAddrEmpty(addr) {
Expand All @@ -3747,7 +3749,7 @@ object "EvmEmulator" {
argsSize,
add(retOffset, MEM_OFFSET()),
retSize,
false
isStatic
)

newGasLeft := add(evmGasLeft, frameGasLeft)
Expand Down Expand Up @@ -5696,13 +5698,7 @@ object "EvmEmulator" {
}
case 0xF1 { // OP_CALL
// A function was implemented in order to avoid stack depth errors.
switch isStatic
case 0 {
evmGasLeft, sp, stackHead := performCall(sp, evmGasLeft, stackHead)
}
default {
evmGasLeft, sp, stackHead := performStaticCall(sp, evmGasLeft, stackHead)
}
evmGasLeft, sp, stackHead := performCall(sp, evmGasLeft, stackHead, isStatic)
ip := add(ip, 1)
}
case 0xF3 { // OP_RETURN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ function resetEvmFrame() {
// CALLS FUNCTIONALITY
////////////////////////////////////////////////////////////////

function performCall(oldSp, evmGasLeft, oldStackHead) -> newGasLeft, sp, stackHead {
function performCall(oldSp, evmGasLeft, oldStackHead, isStatic) -> newGasLeft, sp, stackHead {
let gasToPass, addr, value, argsOffset, argsSize, retOffset, retSize

popStackCheck(oldSp, 7)
Expand Down Expand Up @@ -614,6 +614,10 @@ function performCall(oldSp, evmGasLeft, oldStackHead) -> newGasLeft, sp, stackHe
gasUsed := add(gasUsed, expandMemory2(retOffset, retSize, argsOffset, argsSize))

if gt(value, 0) {
if isStatic {
panic()
}

gasUsed := add(gasUsed, 9000) // positive_value_cost

if isAddrEmpty(addr) {
Expand All @@ -637,7 +641,7 @@ function performCall(oldSp, evmGasLeft, oldStackHead) -> newGasLeft, sp, stackHe
argsSize,
add(retOffset, MEM_OFFSET()),
retSize,
false
isStatic
)

newGasLeft := add(evmGasLeft, frameGasLeft)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1423,13 +1423,7 @@ for { } true { } {
}
case 0xF1 { // OP_CALL
// A function was implemented in order to avoid stack depth errors.
switch isStatic
case 0 {
evmGasLeft, sp, stackHead := performCall(sp, evmGasLeft, stackHead)
}
default {
evmGasLeft, sp, stackHead := performStaticCall(sp, evmGasLeft, stackHead)
}
evmGasLeft, sp, stackHead := performCall(sp, evmGasLeft, stackHead, isStatic)
ip := add(ip, 1)
}
case 0xF3 { // OP_RETURN
Expand Down
Loading