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

Bypass AccessList enforcement for ETXs #2396

Merged
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
19 changes: 13 additions & 6 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ type StateDB struct {
preimages map[common.Hash][]byte

// Per-transaction access list
accessList *accessList
accessListDebug bool // used for simulating the EVM to create an access list
accessList *accessList
bypassAccessListCheck bool // used for simulating the EVM to create an access list, and allowing ETXs which do not contain an access list
// Journal of state modifications. This is the backbone of
// Snapshot and RevertToSnapshot.
journal *journal
Expand Down Expand Up @@ -446,6 +446,13 @@ func (s *StateDB) HasSuicided(addr common.InternalAddress) bool {
* SETTERS
*/

// ConfigureAccessListChecks enables or disables accessList checking
func (s *StateDB) ConfigureAccessListChecks(enable bool) bool {
orig := s.bypassAccessListCheck
s.bypassAccessListCheck = !enable
return orig
}

// AddBalance adds amount to the account associated with addr.
func (s *StateDB) AddBalance(addr common.InternalAddress, amount *big.Int) {
stateObject := s.GetOrNewStateObject(addr)
Expand Down Expand Up @@ -936,7 +943,7 @@ func (s *StateDB) Copy() *StateDB {
// However, it doesn't cost us much to copy an empty list, so we do it anyway
// to not blow up if we ever decide copy it in the middle of a transaction
state.accessList = s.accessList.Copy()
state.accessListDebug = s.accessListDebug
state.bypassAccessListCheck = s.bypassAccessListCheck
// If there's a prefetcher running, make an inactive copy of it that can
// only access data but does not actively preload (since the user will not
// know that they need to explicitly terminate an active copy).
Expand Down Expand Up @@ -1234,7 +1241,7 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) {
// - Add precompiles to access list
// - Add the contents of the optional tx access list
func (s *StateDB) PrepareAccessList(sender common.Address, dst *common.Address, precompiles []common.Address, list types.AccessList, debug bool) {
s.accessListDebug = debug
s.bypassAccessListCheck = debug
s.AddAddressToAccessList(sender.Bytes20())
if dst != nil {
s.AddAddressToAccessList(dst.Bytes20())
Expand Down Expand Up @@ -1278,15 +1285,15 @@ func (s *StateDB) AddSlotToAccessList(addr common.AddressBytes, slot common.Hash

// AddressInAccessList returns true if the given address is in the access list.
func (s *StateDB) AddressInAccessList(addr common.AddressBytes) bool {
if s.accessListDebug {
if s.bypassAccessListCheck {
return true
}
return s.accessList.ContainsAddress(addr)
}

// SlotInAccessList returns true if the given (address, slot)-tuple is in the access list.
func (s *StateDB) SlotInAccessList(addr common.AddressBytes, slot common.Hash) (addressPresent bool, slotPresent bool) {
if s.accessListDebug {
if s.bypassAccessListCheck {
return true, true
}
return s.accessList.Contains(addr, slot)
Expand Down
6 changes: 6 additions & 0 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
// 5. there is no overflow when calculating intrinsic gas
// 6. caller has enough balance to cover asset transfer for **topmost** call

// If ETX, bypass accessList enforcement
if st.msg.IsETX() {
orig := st.state.ConfigureAccessListChecks(false)
jdowning100 marked this conversation as resolved.
Show resolved Hide resolved
defer st.state.ConfigureAccessListChecks(orig)
gameofpointers marked this conversation as resolved.
Show resolved Hide resolved
}

// Check clauses 1-3, buy gas if everything is correct
if !st.msg.IsETX() {
if err := st.preCheck(); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions core/vm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
type StateDB interface {
CreateAccount(common.InternalAddress)

ConfigureAccessListChecks(bool) bool

SubBalance(common.InternalAddress, *big.Int)
AddBalance(common.InternalAddress, *big.Int)
GetBalance(common.InternalAddress) *big.Int
Expand Down
Loading