-
Notifications
You must be signed in to change notification settings - Fork 144
Instrument the SLOADopcode #507
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?
Conversation
568a6b2
to
a327833
Compare
a327833
to
042c464
Compare
core/state/access_events.go
Outdated
@@ -151,6 +153,36 @@ func (ae *AccessEvents) AddTxDestination(addr common.Address, sendsValue bool) { | |||
ae.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.CodeHashLeafKey, false) | |||
} | |||
|
|||
// SlotMultigas returns the amount of gas to be charged for a cold storage access. | |||
func (ae *AccessEvents) SlotMultigas(addr common.Address, slot common.Hash, isWrite bool) (*multigas.MultiGas, error) { |
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.
I would suggest fixing the existing functions in access_events.go
instead of adding a new so that it will be easier to track changes in the next update from the go-ethereum upstream
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.
Thanks I wasnt sure what the usual approach is
func (ae *AccessEvents) touchAddressAndChargeMultigas(addr common.Address, treeIndex uint256.Int, subIndex byte, isWrite bool) (*multigas.MultiGas, error) { | ||
stemRead, selectorRead, stemWrite, selectorWrite, selectorFill := ae.touchAddress(addr, treeIndex, subIndex, isWrite) | ||
|
||
gas := multigas.ZeroGas() |
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.
It is worth adding a short comment explaining the choice of resource type
@@ -122,11 +122,9 @@ func gasSLoadEIP2929(evm *EVM, contract *Contract, stack *Stack, mem *Memory, me | |||
// If the caller cannot afford the cost, this change will be rolled back | |||
// If he does afford it, we can skip checking the same thing later on, during execution | |||
evm.StateDB.AddSlotToAccessList(contract.Address(), slot) | |||
// TODO(NIT-3484): Update multi dimensional gas here | |||
return multigas.UnknownGas(params.ColdSloadCostEIP2929), nil | |||
return multigas.StorageAccessGas(params.ColdSloadCostEIP2929), 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.
And here a comment is needed too, based on how it's done in other places
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.
Nice!
// access cost to be charged, if need be. | ||
func (ae *AccessEvents) touchAddressAndChargeGas(addr common.Address, treeIndex uint256.Int, subIndex byte, isWrite bool) uint64 { | ||
multiGas, err := ae.touchAddressAndChargeMultigas(addr, treeIndex, subIndex, isWrite) | ||
if err != 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.
nit: log an error just in case
No description provided.