Skip to content
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

avoid BASIC_DATA branch edit for free in existent accounts #513

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions core/state/access_witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,7 @@ func (aw *AccessWitness) TouchTxOriginAndComputeGas(originAddr []byte) {

func (aw *AccessWitness) TouchTxTarget(targetAddr []byte, sendsValue bool) {
aw.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, utils.BasicDataLeafKey, sendsValue, nil)
// Note that we do a write-event in CodeHash without distinguishing if the tx target account
// exists or not. Pre-7702, there's no situation in which an existing codeHash can be mutated, thus
// doing a write-event shouldn't cause an observable difference in gas usage.
// TODO(7702): re-check this in the spec and implementation to be sure is a correct solution after
// EIP-7702 is implemented.
aw.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, utils.CodeHashLeafKey, true, nil)
aw.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, utils.CodeHashLeafKey, false, nil)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverting this to the way it was pre-yesterday PR. (Still keeping the renaming since it was a useful change).

}

func (aw *AccessWitness) TouchSlotAndChargeGas(addr []byte, slot common.Hash, isWrite bool, useGasFn UseGasFn, warmCostCharging bool) bool {
Expand Down
3 changes: 3 additions & 0 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {

if msg.To != nil {
st.evm.Accesses.TouchTxTarget(targetAddr.Bytes(), msg.Value.Sign() != 0)
if !st.state.Exist(*targetAddr) {
st.evm.Accesses.TouchCodeHash(targetAddr.Bytes(), true, nil, false)
}
Comment on lines 399 to +402
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out that the logic I made yesterday reg CODEHASH being immutable (before 7702) was fine. But this free CODEHASH write we did before is also giving for free a BRANCH_EDIT unconditionally.

This means that for existing addresses, the unconditional free write-event on CODEHASH made writes in BASIC_DATA cheaper (since CODEHASH got that for free, which attempted to be a simplification but is wrong).


// ensure the code size ends up in the access witness
st.evm.StateDB.GetCodeSize(*targetAddr)
Expand Down
Loading