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

[EVM Equivalence in Yul] fix: Don't charge the regular cost of the call when calling precompiles #677

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
31 changes: 25 additions & 6 deletions system-contracts/contracts/EvmInterpreterFunctions.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,15 @@ function performStaticCall(oldSp,evmGasLeft) -> extraCost, sp {
}
}

extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize))
let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize)
switch iszero(precompileCost)
case 1 {
extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
}
default {
extraCost := add(extraCost, precompileCost)
}

sp := pushStackItem(sp, success, evmGasLeft)
}
function capGas(evmGasLeft,oldGasToPass) -> gasToPass {
Expand Down Expand Up @@ -1086,8 +1093,14 @@ function performCall(oldSp, evmGasLeft, isStatic) -> extraCost, sp {
isStatic
)

extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize))
let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize)
switch iszero(precompileCost)
case 1 {
extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
}
default {
extraCost := add(extraCost, precompileCost)
}
sp := pushStackItem(sp,success, evmGasLeft)
}

Expand Down Expand Up @@ -1150,8 +1163,14 @@ function delegateCall(oldSp, oldIsStatic, evmGasLeft) -> sp, isStatic, extraCost

_popEVMFrame()

extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize))
let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize)
switch iszero(precompileCost)
case 1 {
extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
}
default {
extraCost := add(extraCost, precompileCost)
}
sp := pushStackItem(sp, success, evmGasLeft)
}

Expand Down
62 changes: 50 additions & 12 deletions system-contracts/contracts/EvmInterpreterPreprocessed.yul
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,15 @@ object "EVMInterpreter" {
}
}

extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize))
let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize)
switch iszero(precompileCost)
case 1 {
extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
}
default {
extraCost := add(extraCost, precompileCost)
}

sp := pushStackItem(sp, success, evmGasLeft)
}
function capGas(evmGasLeft,oldGasToPass) -> gasToPass {
Expand Down Expand Up @@ -1160,8 +1167,14 @@ object "EVMInterpreter" {
isStatic
)

extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize))
let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize)
switch iszero(precompileCost)
case 1 {
extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
}
default {
extraCost := add(extraCost, precompileCost)
}
sp := pushStackItem(sp,success, evmGasLeft)
}

Expand Down Expand Up @@ -1224,8 +1237,14 @@ object "EVMInterpreter" {

_popEVMFrame()

extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize))
let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize)
switch iszero(precompileCost)
case 1 {
extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
}
default {
extraCost := add(extraCost, precompileCost)
}
sp := pushStackItem(sp, success, evmGasLeft)
}

Expand Down Expand Up @@ -4031,8 +4050,15 @@ object "EVMInterpreter" {
}
}

extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize))
let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize)
switch iszero(precompileCost)
case 1 {
extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
}
default {
extraCost := add(extraCost, precompileCost)
}

sp := pushStackItem(sp, success, evmGasLeft)
}
function capGas(evmGasLeft,oldGasToPass) -> gasToPass {
Expand Down Expand Up @@ -4155,8 +4181,14 @@ object "EVMInterpreter" {
isStatic
)

extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize))
let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize)
switch iszero(precompileCost)
case 1 {
extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
}
default {
extraCost := add(extraCost, precompileCost)
}
sp := pushStackItem(sp,success, evmGasLeft)
}

Expand Down Expand Up @@ -4219,8 +4251,14 @@ object "EVMInterpreter" {

_popEVMFrame()

extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize))
let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize)
switch iszero(precompileCost)
case 1 {
extraCost := add(extraCost,sub(gasToPass,frameGasLeft))
}
default {
extraCost := add(extraCost, precompileCost)
}
sp := pushStackItem(sp, success, evmGasLeft)
}

Expand Down
Loading