Skip to content

Commit

Permalink
Merge pull request #677 from lambdaclass/dont-charge-the-regular-cost…
Browse files Browse the repository at this point in the history
…-of-calls-for-precompiles

[EVM Equivalence in Yul] fix: Don't charge the regular cost of the call when calling precompiles
  • Loading branch information
jrchatruc authored Aug 20, 2024
2 parents 36c03ec + 5a3e3f5 commit 74767c1
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 18 deletions.
31 changes: 25 additions & 6 deletions system-contracts/contracts/EvmInterpreterFunctions.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,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 @@ -1031,8 +1038,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 @@ -1095,8 +1108,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 @@ -978,8 +978,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 @@ -1102,8 +1109,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 @@ -1166,8 +1179,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 @@ -3928,8 +3947,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 @@ -4052,8 +4078,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 @@ -4116,8 +4148,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

0 comments on commit 74767c1

Please sign in to comment.