mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-16 21:16:37 +00:00
only perform state reads in selfdestruct if we have sufficient gas to cover the state access costs
This commit is contained in:
parent
c112198644
commit
00136d1735
3 changed files with 14 additions and 4 deletions
|
|
@ -143,10 +143,10 @@ func (r *BALReader) ModifiedAccounts() (res []common.Address) {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *BALReader) ValidateStateReads(allReads bal.StateAccesses) error {
|
func (r *BALReader) ValidateStateReads(computedReads bal.StateAccesses) error {
|
||||||
// 1. remove any slots from 'allReads' which were written
|
// 1. remove any slots from 'allReads' which were written
|
||||||
// 2. validate that the read set in the BAL matches 'allReads' exactly
|
// 2. validate that the read set in the BAL matches 'allReads' exactly
|
||||||
for addr, reads := range allReads {
|
for addr, reads := range computedReads {
|
||||||
balAcctDiff := r.readAccountDiff(addr, len(r.block.Transactions())+2)
|
balAcctDiff := r.readAccountDiff(addr, len(r.block.Transactions())+2)
|
||||||
if balAcctDiff != nil {
|
if balAcctDiff != nil {
|
||||||
for writeSlot := range balAcctDiff.StorageWrites {
|
for writeSlot := range balAcctDiff.StorageWrites {
|
||||||
|
|
@ -154,7 +154,7 @@ func (r *BALReader) ValidateStateReads(allReads bal.StateAccesses) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, ok := r.accesses[addr]; !ok {
|
if _, ok := r.accesses[addr]; !ok {
|
||||||
return fmt.Errorf("%x wasn't in BAL", addr)
|
return fmt.Errorf("account %x was accessed during execution but is not present in the access list", addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedReads := r.accesses[addr].StorageReads
|
expectedReads := r.accesses[addr].StorageReads
|
||||||
|
|
|
||||||
|
|
@ -538,11 +538,19 @@ func gasStaticCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memo
|
||||||
|
|
||||||
func gasSelfdestruct(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
func gasSelfdestruct(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
||||||
var gas uint64
|
var gas uint64
|
||||||
|
fmt.Println("gasSelfdestruct")
|
||||||
|
|
||||||
// EIP150 homestead gas reprice fork:
|
// EIP150 homestead gas reprice fork:
|
||||||
if evm.chainRules.IsEIP150 {
|
if evm.chainRules.IsEIP150 {
|
||||||
gas = params.SelfdestructGasEIP150
|
gas = params.SelfdestructGasEIP150
|
||||||
var address = common.Address(stack.Back(0).Bytes20())
|
var address = common.Address(stack.Back(0).Bytes20())
|
||||||
|
|
||||||
|
fmt.Println("okay we're")
|
||||||
|
if gas > contract.Gas {
|
||||||
|
fmt.Println("here")
|
||||||
|
return gas, nil
|
||||||
|
}
|
||||||
|
|
||||||
if evm.chainRules.IsEIP158 {
|
if evm.chainRules.IsEIP158 {
|
||||||
// if empty and transfers value
|
// if empty and transfers value
|
||||||
if evm.StateDB.Empty(address) && evm.StateDB.GetBalance(contract.Address()).Sign() != 0 {
|
if evm.StateDB.Empty(address) && evm.StateDB.GetBalance(contract.Address()).Sign() != 0 {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/math"
|
"github.com/ethereum/go-ethereum/common/math"
|
||||||
"github.com/ethereum/go-ethereum/core/tracing"
|
"github.com/ethereum/go-ethereum/core/tracing"
|
||||||
|
|
@ -269,6 +268,9 @@ func makeSelfdestructGasFn(refundsEnabled bool) gasFunc {
|
||||||
evm.StateDB.AddAddressToAccessList(address)
|
evm.StateDB.AddAddressToAccessList(address)
|
||||||
gas = params.ColdAccountAccessCostEIP2929
|
gas = params.ColdAccountAccessCostEIP2929
|
||||||
}
|
}
|
||||||
|
if contract.Gas < gas {
|
||||||
|
return gas, nil
|
||||||
|
}
|
||||||
// if empty and transfers value
|
// if empty and transfers value
|
||||||
if evm.StateDB.Empty(address) && evm.StateDB.GetBalance(contract.Address()).Sign() != 0 {
|
if evm.StateDB.Empty(address) && evm.StateDB.GetBalance(contract.Address()).Sign() != 0 {
|
||||||
gas += params.CreateBySelfdestructGas
|
gas += params.CreateBySelfdestructGas
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue