-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
EIP-2929: Gas cost increases for state access opcodes + YoloV2 #21509
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d990f93
core/vm, core/state: implement EIP-2929 + YOLOv2
holiman 6a45194
core/state, core/vm: fix some review concerns
holiman 551be8e
core/state, core/vm: address review concerns
holiman e4cd150
core/vm: address review concerns
holiman f66f4e5
core/vm: better documentation
holiman 9cb1204
core/vm: unify sload cost as fully dynamic
holiman 014f98d
core/vm: fix typo
holiman 032e673
core/vm/runtime: fix compilation flaw
holiman d8bf9ea
core/vm/runtime: fix renaming-err leftovers
holiman e429b73
core/vm: renaming
holiman a31b156
params/config: use correct yolov2 chainid for config
holiman 2e177d5
core, params: use a proper new genesis for yolov2
holiman 0efc69a
core/state/tests: golinter nitpicks
holiman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Copyright 2020 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package state | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type accessList struct { | ||
addresses map[common.Address]int | ||
slots []map[common.Hash]struct{} | ||
} | ||
|
||
// ContainsAddress returns true if the address is in the access list. | ||
func (al *accessList) ContainsAddress(address common.Address) bool { | ||
_, ok := al.addresses[address] | ||
return ok | ||
} | ||
|
||
// Contains checks if a slot within an account is present in the access list, returning | ||
// separate flags for the presence of the account and the slot respectively. | ||
func (al *accessList) Contains(address common.Address, slot common.Hash) (addressPresent bool, slotPresent bool) { | ||
holiman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
idx, ok := al.addresses[address] | ||
if !ok { | ||
// no such address (and hence zero slots) | ||
return false, false | ||
} | ||
if idx == -1 { | ||
// address yes, but no slots | ||
return true, false | ||
} | ||
_, slotPresent = al.slots[idx][slot] | ||
return true, slotPresent | ||
} | ||
|
||
// newAccessList creates a new accessList. | ||
func newAccessList() *accessList { | ||
return &accessList{ | ||
addresses: make(map[common.Address]int), | ||
} | ||
} | ||
|
||
// Copy creates an independent copy of an accessList. | ||
func (a *accessList) Copy() *accessList { | ||
cp := newAccessList() | ||
for k, v := range a.addresses { | ||
cp.addresses[k] = v | ||
} | ||
cp.slots = make([]map[common.Hash]struct{}, len(a.slots)) | ||
for i, slotMap := range a.slots { | ||
newSlotmap := make(map[common.Hash]struct{}, len(slotMap)) | ||
for k := range slotMap { | ||
newSlotmap[k] = struct{}{} | ||
} | ||
cp.slots[i] = newSlotmap | ||
} | ||
return cp | ||
} | ||
|
||
// AddAddress adds an address to the access list, and returns 'true' if the operation | ||
// caused a change (addr was not previously in the list). | ||
holiman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func (al *accessList) AddAddress(address common.Address) bool { | ||
if _, present := al.addresses[address]; present { | ||
return false | ||
} | ||
al.addresses[address] = -1 | ||
return true | ||
} | ||
|
||
// AddSlot adds the specified (addr, slot) combo to the access list. | ||
// Return values are: | ||
// - address added | ||
// - slot added | ||
// For any 'true' value returned, a corresponding journal entry must be made. | ||
func (al *accessList) AddSlot(address common.Address, slot common.Hash) (addrChange bool, slotChange bool) { | ||
idx, addrPresent := al.addresses[address] | ||
if !addrPresent || idx == -1 { | ||
// Address not present, or addr present but no slots there | ||
al.addresses[address] = len(al.slots) | ||
slotmap := map[common.Hash]struct{}{slot: {}} | ||
al.slots = append(al.slots, slotmap) | ||
holiman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return !addrPresent, true | ||
} | ||
// There is already an (address,slot) mapping | ||
slotmap := al.slots[idx] | ||
if _, ok := slotmap[slot]; !ok { | ||
slotmap[slot] = struct{}{} | ||
// Journal add slot change | ||
return false, true | ||
} | ||
// No changes required | ||
return false, false | ||
} | ||
|
||
// DeleteSlot removes an (address, slot)-tuple from the access list. | ||
// This operation needs to be performed in the same order as the addition happened. | ||
// This method is meant to be used by the journal, which maintains ordering of | ||
// operations. | ||
func (al *accessList) DeleteSlot(address common.Address, slot common.Hash) { | ||
idx, addrOk := al.addresses[address] | ||
// There are two ways this can fail | ||
if !addrOk { | ||
panic("reverting slot change, address not present in list") | ||
} | ||
slotmap := al.slots[idx] | ||
delete(slotmap, slot) | ||
// If that was the last (first) slot, remove it | ||
// Since additions and rollbacks are always performed in order, | ||
// we can delete the item without worrying about screwing up later indices | ||
if len(slotmap) == 0 { | ||
al.slots = al.slots[:idx] | ||
al.addresses[address] = -1 | ||
} | ||
} | ||
|
||
// DeleteAddress removes an address from the access list. This operation | ||
// needs to be performed in the same order as the addition happened. | ||
// This method is meant to be used by the journal, which maintains ordering of | ||
// operations. | ||
func (al *accessList) DeleteAddress(address common.Address) { | ||
delete(al.addresses, address) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
IMHO this
map
+slice
combo makes things more complicated than they should be. Wouldn't using amap[common.Address]map[common.Hash]struct{}
be simpler? Yes, it looks a bit unwieldy, but code handling wise IMHO almost all the code below could be simplified.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'm not sure if the
bool
has any meaning other than "present". If only that,struct{}
is better because it doesn't use any memory to store an extratrue
value.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.
Yes, it would be easier. I was just trying to keep the memory down. I can change it if you prefer
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'd still have made it even smaller :))
That would have avoided the need for the
-1
index special marker.