-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle predicates outside of core/state.StateDB
- Loading branch information
Showing
10 changed files
with
537 additions
and
501 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,54 @@ | ||
// (c) 2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package extstate | ||
|
||
import ( | ||
"github.com/ava-labs/coreth/core/types" | ||
"github.com/ava-labs/coreth/core/vm" | ||
"github.com/ava-labs/coreth/params" | ||
"github.com/ava-labs/coreth/predicate" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type StateDB struct { | ||
vm.StateDB | ||
|
||
// Ordered storage slots to be used in predicate verification as set in the tx access list. | ||
// Only set in PrepareAccessList, and un-modified through execution. | ||
predicateStorageSlots map[common.Address][][]byte | ||
} | ||
|
||
func (s *StateDB) Prepare(rules params.Rules, sender, coinbase common.Address, dst *common.Address, precompiles []common.Address, list types.AccessList) { | ||
s.predicateStorageSlots = predicate.PreparePredicateStorageSlots(rules, list) | ||
s.StateDB.Prepare(rules, sender, coinbase, dst, precompiles, list) | ||
} | ||
|
||
// GetPredicateStorageSlots returns the storage slots associated with the address, index pair. | ||
// A list of access tuples can be included within transaction types post EIP-2930. The address | ||
// is declared directly on the access tuple and the index is the i'th occurrence of an access | ||
// tuple with the specified address. | ||
// | ||
// Ex. AccessList[[AddrA, Predicate1], [AddrB, Predicate2], [AddrA, Predicate3]] | ||
// In this case, the caller could retrieve predicates 1-3 with the following calls: | ||
// GetPredicateStorageSlots(AddrA, 0) -> Predicate1 | ||
// GetPredicateStorageSlots(AddrB, 0) -> Predicate2 | ||
// GetPredicateStorageSlots(AddrA, 1) -> Predicate3 | ||
func (s *StateDB) GetPredicateStorageSlots(address common.Address, index int) ([]byte, bool) { | ||
predicates, exists := s.predicateStorageSlots[address] | ||
if !exists { | ||
return nil, false | ||
} | ||
if index >= len(predicates) { | ||
return nil, false | ||
} | ||
return predicates[index], true | ||
} | ||
|
||
// SetPredicateStorageSlots sets the predicate storage slots for the given address | ||
func (s *StateDB) SetPredicateStorageSlots(address common.Address, predicates [][]byte) { | ||
if s.predicateStorageSlots == nil { | ||
s.predicateStorageSlots = make(map[common.Address][][]byte) | ||
} | ||
s.predicateStorageSlots[address] = predicates | ||
} |
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 |
---|---|---|
@@ -1,19 +1,20 @@ | ||
// (c) 2023, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
package state | ||
package extstate | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ava-labs/coreth/core/rawdb" | ||
"github.com/ava-labs/coreth/core/state" | ||
"github.com/ava-labs/coreth/precompile/contract" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func NewTestStateDB(t testing.TB) contract.StateDB { | ||
db := rawdb.NewMemoryDatabase() | ||
stateDB, err := New(common.Hash{}, NewDatabase(db), nil) | ||
stateDB, err := state.New(common.Hash{}, state.NewDatabase(db), nil) | ||
require.NoError(t, err) | ||
return stateDB | ||
return &StateDB{StateDB: stateDB} | ||
} |
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
Oops, something went wrong.