Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alexandrosfilios
Copy link

No description provided.

@cla-bot cla-bot bot added the s CLA signed label Aug 14, 2025
@alexandrosfilios alexandrosfilios force-pushed the nit-3478-instrument-the-sloadopcode branch from 568a6b2 to a327833 Compare August 15, 2025 07:48
@alexandrosfilios alexandrosfilios marked this pull request as ready for review August 15, 2025 07:49
@alexandrosfilios alexandrosfilios force-pushed the nit-3478-instrument-the-sloadopcode branch from a327833 to 042c464 Compare August 15, 2025 07:56
@@ -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) {
Copy link
Contributor

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

Copy link
Author

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()
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor

@MishkaRogachev MishkaRogachev left a 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 {
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s CLA signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants