Clean up nits

This commit is contained in:
Aaron Buchwald
2022-02-24 14:49:41 -05:00
parent 61ee61b04b
commit d351a38527
7 changed files with 39 additions and 14 deletions
+2 -3
View File
@@ -41,7 +41,6 @@ import (
"github.com/ava-labs/subnet-evm/core/types"
"github.com/ava-labs/subnet-evm/ethdb"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/precompile"
"github.com/ava-labs/subnet-evm/trie"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -270,8 +269,8 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
}
genesisTimestamp := new(big.Int).SetUint64(g.Timestamp)
// Configure the AllowList if enabled from genesis
precompile.CheckConfigure(nil, genesisTimestamp, g.Config.AllowListConfig, statedb)
// Configure any stateful precompiles that should be enabled in the genesis.
g.Config.CheckConfigurePrecompiles(nil, genesisTimestamp, statedb)
// Do cusotm allocation after airdrop in case an address shows up in standard
// allocation
+2 -3
View File
@@ -35,7 +35,6 @@ import (
"github.com/ava-labs/subnet-evm/core/types"
"github.com/ava-labs/subnet-evm/core/vm"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/precompile"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
@@ -78,8 +77,8 @@ func (p *StateProcessor) Process(block *types.Block, parent *types.Header, state
timestamp = new(big.Int).SetUint64(header.Time)
)
// Configure the allow list if it goes into effect during the transition from [parent] to [block].
precompile.CheckConfigure(new(big.Int).SetUint64(parent.Time), timestamp, p.config.AllowListConfig, statedb)
// Configure any stateful precompiles that should go into effect during this block.
p.config.CheckConfigurePrecompiles(new(big.Int).SetUint64(parent.Time), timestamp, statedb)
blockContext := NewEVMBlockContext(header, p.bc, nil)
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, p.config, cfg)
+2
View File
@@ -161,6 +161,8 @@ func (w *worker) commitNewWork() (*types.Block, error) {
if err != nil {
return nil, fmt.Errorf("failed to create new current environment: %w", err)
}
// Configure any stateful precompiles that should go into effect during this block.
w.chainConfig.CheckConfigurePrecompiles(new(big.Int).SetUint64(parent.Time()), bigTimestamp, env.state)
// Fill the block with all available pending transactions.
pending := w.eth.TxPool().Pending(true)
+22 -1
View File
@@ -207,7 +207,7 @@ func (c *ChainConfig) IsSubnetEVM(blockTimestamp *big.Int) bool {
return utils.IsForked(c.SubnetEVMTimestamp, blockTimestamp)
}
// IsSubnetEVM returns whether [blockTimestamp] is either equal to the AllowList fork block timestamp or greater.
// IsAllowList returns whether [blockTimestamp] is either equal to the AllowList fork block timestamp or greater.
func (c *ChainConfig) IsAllowList(blockTimestamp *big.Int) bool {
// If [AllowListConfig] is nil, then this upgrade is not enabled.
if c.AllowListConfig == nil {
@@ -463,3 +463,24 @@ func (c *ChainConfig) AvalancheRules(blockNum, blockTimestamp *big.Int) Rules {
rules.IsAllowListEnabled = c.IsAllowList(blockTimestamp)
return rules
}
// enabledStatefulPrecompiles returns a list of stateful precompile configs in the order that they are enabled
// by block timestamp.
func (c *ChainConfig) enabledStatefulPrecompiles() []precompile.StatefulPrecompileConfig {
statefulPrecompileConfigs := make([]precompile.StatefulPrecompileConfig, 0)
if c.AllowListConfig != nil {
statefulPrecompileConfigs = append(statefulPrecompileConfigs, c.AllowListConfig)
}
return statefulPrecompileConfigs
}
// CheckConfigurePrecompiles iterates over any stateful precompile configs that go into effect at some point and configures them
// if they are activated between [parentTimestamp] and [currentTimestamp].
func (c *ChainConfig) CheckConfigurePrecompiles(parentTimestamp *big.Int, currentTimestamp *big.Int, statedb precompile.StateDB) {
// Iterate the enabled stateful precompiles and configure them if needed
for _, config := range c.enabledStatefulPrecompiles() {
precompile.CheckConfigure(parentTimestamp, currentTimestamp, config, statedb)
}
}
+3 -6
View File
@@ -93,7 +93,7 @@ func PackModifyAllowList(address common.Address, status AllowListRole) ([]byte,
input := make([]byte, modifyAllowListInputLength)
copy(input, address[:])
copy(input[20:], status[:])
copy(input[common.AddressLength:], status[:])
return input, nil
}
@@ -117,13 +117,12 @@ func UnpackModifyAllowList(input []byte) (common.Address, common.Hash, error) {
// setAllowListStatus sets the permissions of [address] to [status]
// assumes [status] has already been verified as valid.
func setAllowListStatus(stateDB StateDB, address common.Address, status common.Hash) error {
func setAllowListStatus(stateDB StateDB, address common.Address, status common.Hash) {
// Generate the state key for [address]
addressKey := CreateAddressKey(address)
log.Info("modify allow list", "address", address, "role", status)
// Assign [role] to the address
stateDB.SetState(ModifyAllowListAddress, addressKey, status)
return nil
}
// allowListPrecompile implements StatefulPrecompiledContract and can be used as a thread-safe singleton.
@@ -153,9 +152,7 @@ func (al *allowListPrecompile) Run(evm PrecompileAccessibleState, callerAddr com
return nil, remainingGas, fmt.Errorf("failed to unpack modify allow list input: %w", err)
}
if err := setAllowListStatus(evm.GetStateDB(), address, status); err != nil {
return nil, remainingGas, err
}
setAllowListStatus(evm.GetStateDB(), address, status)
// Return an empty output and the remaining gas
return []byte{}, remainingGas, nil
+7
View File
@@ -11,6 +11,13 @@ const (
)
// Designated addresses of stateful precompiles
// Note: it is important that none of these addresses conflict with each other or any other precompiles
// in core/vm/contracts.go.
// We start at 0x0200000000000000000000000000000000000000 and will increment by 1 from here to reduce
// the risk of conflicts.
// For forks of subnet-evm, users should start at 0x0300000000000000000000000000000000000000 to ensure
// that their own modifications do not conflict with stateful precompiles that may be added to subnet-evm
// in the future.
var (
ModifyAllowListAddress = common.HexToAddress("0x0200000000000000000000000000000000000000")
)
+1 -1
View File
@@ -21,7 +21,7 @@ type StatefulPrecompileConfig interface {
// This function must be deterministic since it will impact the EVM state. If a change to the
// config causes a change to the state modifications made in Configure, then it cannot be safely
// made to the config after the network upgrade has gone into effect.
//
// Configure is called on the first block where the stateful precompile should be enabled. This
// provides the config the ability to set its initial state and should only modify the state within
// its own address space.