Skip to content

Commit

Permalink
fix: move 1/64 before gas call
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Oct 22, 2024
1 parent c190328 commit bcc8795
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions core/vm/operations_verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,29 @@ func gasExtCodeHash4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory,

func makeCallVariantGasEIP4762(oldCalculator gasFunc) gasFunc {
return func(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
gas, err := oldCalculator(evm, contract, stack, mem, memorySize)
if err != nil {
return 0, err
}
target := common.Address(stack.Back(1).Bytes20())

_, isPrecompile := evm.precompile(target)
isSystemContract := evm.isSystemContract(target)
if isPrecompile || isSystemContract {
var overflow bool
if gas, overflow = math.SafeAdd(gas, params.WarmStorageReadCostEIP2929); overflow {
return 0, ErrGasUintOverflow
}
return gas, nil
return params.WarmStorageReadCostEIP2929, nil
}

// The charging for the value transfer is done BEFORE subtracting
// the 1/64th gas, as this is considered part of the CALL instruction.
// (so before we get to this point)
// But the message call is part of the subcall, for which only 63/64th
// of the gas should be available.
wgas := evm.Accesses.TouchAndChargeMessageCall(target.Bytes(), contract.Gas-gas)
return wgas + gas, nil
wantedWitnessGas := evm.Accesses.TouchAndChargeMessageCall(target.Bytes(), contract.Gas)
if wantedWitnessGas > contract.Gas {
return wantedWitnessGas, nil
}

gas, err := oldCalculator(evm, contract, stack, mem, memorySize)
if err != nil {
return 0, err
}
return wantedWitnessGas + gas, nil
}
}

Expand Down

0 comments on commit bcc8795

Please sign in to comment.