Skip to content

Commit

Permalink
Don't charge the regular cost of the call when calling precompiles
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchatruc committed Aug 5, 2024
1 parent 97a8c94 commit 5a3e3f5
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 @@ -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

0 comments on commit 5a3e3f5

Please sign in to comment.