Skip to content

Commit

Permalink
Bypass AccessList enforcement for ETXs
Browse files Browse the repository at this point in the history
  • Loading branch information
wizeguyy committed Dec 10, 2024
1 parent e844225 commit 9dc7043
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
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)
defer st.state.ConfigureAccessListChecks(orig)
}

// 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

0 comments on commit 9dc7043

Please sign in to comment.