-
Notifications
You must be signed in to change notification settings - Fork 21.4k
[wip] implement FILL_COST #30201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[wip] implement FILL_COST #30201
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,13 +28,15 @@ import ( | |
"sync/atomic" | ||
"time" | ||
|
||
"github.com/cockroachdb/pebble" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/rawdb" | ||
"github.com/ethereum/go-ethereum/core/state/snapshot" | ||
"github.com/ethereum/go-ethereum/core/stateless" | ||
"github.com/ethereum/go-ethereum/core/tracing" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/ethdb/memorydb" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/params" | ||
"github.com/ethereum/go-ethereum/trie" | ||
|
@@ -1484,3 +1486,13 @@ func (s *StateDB) PointCache() *utils.PointCache { | |
func (s *StateDB) Witness() *stateless.Witness { | ||
return s.witness | ||
} | ||
|
||
func (s *StateDB) IsSlotFilled(addr common.Address, slot common.Hash) bool { | ||
// The snapshot can not be used, because it uses the old encoding where | ||
// no difference is made between 0 and no data. | ||
_, err := s.db.DiskDB().Get(utils.StorageSlotKeyWithEvaluatedAddress(s.accessList.pointCache.GetTreeKeyHeader(addr[:]), slot[:])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should go through the reader abstaction, because it might have been written in a previous block but not in the db / also we want to use the layers to build the witness if we can. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rjl493456442 |
||
// The error needs to be checked because we want to be future-proof | ||
// and not rely on the length of the encoding, in case 0-values are | ||
// somehow compressed later. | ||
return errors.Is(pebble.ErrNotFound, err) || errors.Is(memorydb.ErrMemorydbNotFound, err) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,15 +23,19 @@ import ( | |
) | ||
|
||
func gasSStore4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { | ||
gas := evm.AccessEvents.SlotGas(contract.Address(), stack.peek().Bytes32(), true) | ||
var ( | ||
addr = contract.Address() | ||
slot = common.Hash(stack.peek().Bytes32()) | ||
) | ||
gas := evm.AccessEvents.SlotGas(addr, slot, true, evm.StateDB.IsSlotFilled(addr, slot)) | ||
if gas == 0 { | ||
gas = params.WarmStorageReadCostEIP2929 | ||
} | ||
return gas, nil | ||
} | ||
|
||
func gasSLoad4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { | ||
gas := evm.AccessEvents.SlotGas(contract.Address(), stack.peek().Bytes32(), false) | ||
gas := evm.AccessEvents.SlotGas(contract.Address(), stack.peek().Bytes32(), false, false) | ||
if gas == 0 { | ||
gas = params.WarmStorageReadCostEIP2929 | ||
} | ||
|
@@ -40,7 +44,7 @@ func gasSLoad4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memor | |
|
||
func gasBalance4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { | ||
address := stack.peek().Bytes20() | ||
gas := evm.AccessEvents.BalanceGas(address, false) | ||
gas := evm.AccessEvents.BalanceGas(address, false, false) | ||
if gas == 0 { | ||
gas = params.WarmStorageReadCostEIP2929 | ||
} | ||
|
@@ -104,15 +108,15 @@ func gasSelfdestructEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Mem | |
contractAddr := contract.Address() | ||
statelessGas := evm.AccessEvents.VersionGas(contractAddr, false) | ||
statelessGas += evm.AccessEvents.CodeSizeGas(contractAddr, false) | ||
statelessGas += evm.AccessEvents.BalanceGas(contractAddr, false) | ||
statelessGas += evm.AccessEvents.BalanceGas(contractAddr, false, false) | ||
if contractAddr != beneficiaryAddr { | ||
statelessGas += evm.AccessEvents.BalanceGas(beneficiaryAddr, false) | ||
statelessGas += evm.AccessEvents.BalanceGas(beneficiaryAddr, false, false) | ||
} | ||
// Charge write costs if it transfers value | ||
if evm.StateDB.GetBalance(contractAddr).Sign() != 0 { | ||
statelessGas += evm.AccessEvents.BalanceGas(contractAddr, true) | ||
statelessGas += evm.AccessEvents.BalanceGas(contractAddr, true, false) | ||
if contractAddr != beneficiaryAddr { | ||
statelessGas += evm.AccessEvents.BalanceGas(beneficiaryAddr, true) | ||
statelessGas += evm.AccessEvents.BalanceGas(beneficiaryAddr, true, !evm.StateDB.Exist(beneficiaryAddr)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same point by @jsign : the account will need to be created so the fill might be more than just the balance There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one should be fixed by just charging the empty code hash as well from here |
||
} | ||
} | ||
return statelessGas, nil | ||
|
@@ -133,7 +137,7 @@ func gasCodeCopyEip4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, | |
} | ||
_, copyOffset, nonPaddedCopyLength := getDataAndAdjustedBounds(contract.Code, uint64CodeOffset, length.Uint64()) | ||
if !contract.IsDeployment { | ||
gas += evm.AccessEvents.CodeChunksRangeGas(contract.Address(), copyOffset, nonPaddedCopyLength, uint64(len(contract.Code)), false) | ||
gas += evm.AccessEvents.CodeChunksRangeGas(contract.Address(), copyOffset, nonPaddedCopyLength, uint64(len(contract.Code)), false, false) | ||
} | ||
return gas, nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsign correctly points out that if
isFill
is true, then the whole account will be created.