mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-08 09:11:34 +00:00
core/vm: fix gas charging for sstore
This commit is contained in:
parent
ed2f476da8
commit
1ef86906fc
1 changed files with 13 additions and 1 deletions
|
|
@ -666,6 +666,9 @@ func gasSelfdestruct8037(evm *EVM, contract *Contract, stack *Stack, mem *Memory
|
||||||
}
|
}
|
||||||
|
|
||||||
func gasSStore8037(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (GasCosts, error) {
|
func gasSStore8037(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (GasCosts, error) {
|
||||||
|
if evm.readOnly {
|
||||||
|
return GasCosts{}, ErrWriteProtection
|
||||||
|
}
|
||||||
// If we fail the minimum gas availability invariant, fail (0)
|
// If we fail the minimum gas availability invariant, fail (0)
|
||||||
if contract.Gas.RegularGas <= params.SstoreSentryGasEIP2200 {
|
if contract.Gas.RegularGas <= params.SstoreSentryGasEIP2200 {
|
||||||
return GasCosts{}, errors.New("not enough gas for reentrancy sentry")
|
return GasCosts{}, errors.New("not enough gas for reentrancy sentry")
|
||||||
|
|
@ -692,7 +695,16 @@ func gasSStore8037(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memo
|
||||||
}
|
}
|
||||||
if original == current {
|
if original == current {
|
||||||
if original == (common.Hash{}) { // create slot (2.1.1)
|
if original == (common.Hash{}) { // create slot (2.1.1)
|
||||||
return GasCosts{RegularGas: cost.RegularGas + params.SstoreResetGasEIP2200 - params.ColdSloadCostEIP2929, StateGas: params.StorageCreationSize * evm.Context.CostPerGasByte}, nil
|
// EIP-8037: Charge state gas first (before regular gas), matching the
|
||||||
|
// spec's charge_state_gas → charge_gas ordering. This ensures that
|
||||||
|
// state_gas_used is recorded even if the subsequent regular gas charge
|
||||||
|
// fails with OOG.
|
||||||
|
stateGas := GasCosts{StateGas: params.StorageCreationSize * evm.Context.CostPerGasByte}
|
||||||
|
if contract.Gas.Underflow(stateGas) {
|
||||||
|
return GasCosts{}, errors.New("out of gas for state gas")
|
||||||
|
}
|
||||||
|
contract.Gas.Sub(stateGas)
|
||||||
|
return GasCosts{RegularGas: cost.RegularGas + params.SstoreResetGasEIP2200 - params.ColdSloadCostEIP2929}, nil
|
||||||
}
|
}
|
||||||
if value == (common.Hash{}) { // delete slot (2.1.2b)
|
if value == (common.Hash{}) { // delete slot (2.1.2b)
|
||||||
evm.StateDB.AddRefund(params.SstoreClearsScheduleRefundEIP3529)
|
evm.StateDB.AddRefund(params.SstoreClearsScheduleRefundEIP3529)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue