Skip to content

Commit 4ecd713

Browse files
committed
call gas
Signed-off-by: Ignacio Hagopian <[email protected]>
1 parent ed4e5e5 commit 4ecd713

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

core/vm/gas_table.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -403,25 +403,6 @@ func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize
403403
return 0, ErrGasUintOverflow
404404
}
405405

406-
if evm.chainRules.IsEIP4762 {
407-
// If value is transferred, it is charged before 1/64th
408-
// is subtracted from the available gas pool.
409-
if transfersValue {
410-
gas, overflow = math.SafeAdd(gas, evm.Accesses.TouchAndChargeValueTransfer(contract.Address().Bytes()[:], address.Bytes()[:]))
411-
if overflow {
412-
return 0, ErrGasUintOverflow
413-
}
414-
}
415-
}
416-
417-
evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, contract.Gas, gas, stack.Back(0))
418-
if err != nil {
419-
return 0, err
420-
}
421-
if gas, overflow = math.SafeAdd(gas, evm.callGasTemp); overflow {
422-
return 0, ErrGasUintOverflow
423-
}
424-
425406
return gas, nil
426407
}
427408

core/vm/instructions.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,28 @@ func opCreate2(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]
756756
}
757757

758758
func chargeCallVariantEIP4762(evm *EVM, scope *ScopeContext) bool {
759+
if evm.chainRules.IsEIP4762 {
760+
address := common.Address(scope.Stack.Back(1).Bytes20())
761+
transfersValue := !scope.Stack.Back(2).IsZero()
762+
763+
// If value is transferred, it is charged before 1/64th
764+
// is subtracted from the available gas pool.
765+
if transfersValue {
766+
if !evm.Accesses.TouchAndChargeValueTransfer(scope.Contract.Address().Bytes()[:], address.Bytes()[:], scope.Contract.UseGas) {
767+
return false
768+
}
769+
}
770+
}
771+
772+
var err error
773+
evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, scope.Contract.Gas, 0, scope.Stack.Back(0))
774+
if err != nil {
775+
return false
776+
}
777+
if scope.Contract.UseGas(evm.callGasTemp) {
778+
return false
779+
}
780+
759781
target := common.Address(scope.Stack.Back(1).Bytes20())
760782
if _, isPrecompile := evm.precompile(target); isPrecompile {
761783
return true

0 commit comments

Comments
 (0)