Skip to content

Commit

Permalink
call gas
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign committed Sep 19, 2024
1 parent ed4e5e5 commit 4ecd713
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
19 changes: 0 additions & 19 deletions core/vm/gas_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,25 +403,6 @@ func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize
return 0, ErrGasUintOverflow
}

if evm.chainRules.IsEIP4762 {
// If value is transferred, it is charged before 1/64th
// is subtracted from the available gas pool.
if transfersValue {
gas, overflow = math.SafeAdd(gas, evm.Accesses.TouchAndChargeValueTransfer(contract.Address().Bytes()[:], address.Bytes()[:]))
if overflow {
return 0, ErrGasUintOverflow
}
}
}

evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, contract.Gas, gas, stack.Back(0))
if err != nil {
return 0, err
}
if gas, overflow = math.SafeAdd(gas, evm.callGasTemp); overflow {
return 0, ErrGasUintOverflow
}

return gas, nil
}

Expand Down
22 changes: 22 additions & 0 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,28 @@ func opCreate2(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]
}

func chargeCallVariantEIP4762(evm *EVM, scope *ScopeContext) bool {
if evm.chainRules.IsEIP4762 {
address := common.Address(scope.Stack.Back(1).Bytes20())
transfersValue := !scope.Stack.Back(2).IsZero()

// If value is transferred, it is charged before 1/64th
// is subtracted from the available gas pool.
if transfersValue {
if !evm.Accesses.TouchAndChargeValueTransfer(scope.Contract.Address().Bytes()[:], address.Bytes()[:], scope.Contract.UseGas) {
return false
}
}
}

var err error
evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, scope.Contract.Gas, 0, scope.Stack.Back(0))
if err != nil {
return false
}
if scope.Contract.UseGas(evm.callGasTemp) {
return false
}

target := common.Address(scope.Stack.Back(1).Bytes20())
if _, isPrecompile := evm.precompile(target); isPrecompile {
return true
Expand Down

0 comments on commit 4ecd713

Please sign in to comment.