Documentation ¶
Index ¶
- Constants
- Variables
- func AllowListConfigEqualTests(t testing.TB, module modules.Module) map[string]testutils.ConfigEqualTest
- func AllowListConfigVerifyTests(t testing.TB, module modules.Module) map[string]testutils.ConfigVerifyTest
- func AllowListTests(t testing.TB, module modules.Module) map[string]testutils.PrecompileTest
- func BenchPrecompileWithAllowList(b *testing.B, module modules.Module, ...)
- func CreateAllowListFunctions(precompileAddr common.Address) []*contract.StatefulPrecompileFunction
- func CreateAllowListPrecompile(precompileAddr common.Address) contract.StatefulPrecompiledContract
- func EqualPrecompileWithAllowListTests(t *testing.T, module modules.Module, ...)
- func PackModifyAllowList(address common.Address, role Role) ([]byte, error)
- func PackReadAllowList(address common.Address) []byte
- func RunPrecompileWithAllowListTests(t *testing.T, module modules.Module, ...)
- func SetAllowListRole(stateDB contract.StateDB, precompileAddr, address common.Address, role Role)
- func SetDefaultRoles(contractAddress common.Address) func(t testing.TB, state contract.StateDB)
- func VerifyPrecompileWithAllowListTests(t *testing.T, module modules.Module, ...)
- type AllowListConfig
- type Role
Constants ¶
const ( SetAdminFuncKey = "setAdmin" SetManagerFuncKey = "setManager" SetEnabledFuncKey = "setEnabled" SetNoneFuncKey = "setNone" ReadAllowListFuncKey = "readAllowList" ModifyAllowListGasCost = contract.WriteGasCostPerSlot ReadAllowListGasCost = contract.ReadGasCostPerSlot )
Variables ¶
var ( AllowListFuncKeys = []string{ SetAdminFuncKey, SetManagerFuncKey, SetEnabledFuncKey, SetNoneFuncKey, ReadAllowListFuncKey, } // Error returned when an invalid write is attempted ErrCannotModifyAllowList = errors.New("cannot modify allow list") )
var ( NoRole = Role(common.BigToHash(common.Big0)) EnabledRole = Role(common.BigToHash(common.Big1)) AdminRole = Role(common.BigToHash(common.Big2)) ManagerRole = Role(common.BigToHash(common.Big3)) )
1. NoRole - this is equivalent to common.Hash{} and deletes the key from the DB when set 2. EnabledRole - allowed to call the precompile 3. Admin - allowed to both modify the allowlist and call the precompile 4. Manager - allowed to add and remove only enabled addresses and also call the precompile. (only after DUpgrade)
var ( TestAdminAddr = common.HexToAddress("0x0000000000000000000000000000000000000011") TestEnabledAddr = common.HexToAddress("0x0000000000000000000000000000000000000022") TestNoRoleAddr = common.HexToAddress("0x0000000000000000000000000000000000000033") TestManagerAddr = common.HexToAddress("0x0000000000000000000000000000000000000044") )
var ErrCannotAddManagersBeforeDUpgrade = fmt.Errorf("cannot add managers before DUpgrade")
Functions ¶
func AllowListTests ¶
func CreateAllowListFunctions ¶
func CreateAllowListFunctions(precompileAddr common.Address) []*contract.StatefulPrecompileFunction
func CreateAllowListPrecompile ¶
func CreateAllowListPrecompile(precompileAddr common.Address) contract.StatefulPrecompiledContract
CreateAllowListPrecompile returns a StatefulPrecompiledContract with R/W control of an allow list at [precompileAddr]
func PackModifyAllowList ¶
PackModifyAllowList packs [address] and [role] into the appropriate arguments for modifying the allow list. Note: [role] is not packed in the input value returned, but is instead used as a selector for the function selector that should be encoded in the input.
func PackReadAllowList ¶
PackReadAllowList packs [address] into the input data to the read allow list function
func SetAllowListRole ¶
SetAllowListRole sets the permissions of [address] to [role] for the precompile at [precompileAddr]. assumes [role] has already been verified as valid.
func SetDefaultRoles ¶
SetDefaultRoles returns a BeforeHook that sets roles TestAdminAddr and TestEnabledAddr to have the AdminRole and EnabledRole respectively.
Types ¶
type AllowListConfig ¶
type AllowListConfig struct { AdminAddresses []common.Address `json:"adminAddresses,omitempty"` // initial admin addresses ManagerAddresses []common.Address `json:"managerAddresses,omitempty"` // initial manager addresses EnabledAddresses []common.Address `json:"enabledAddresses,omitempty"` // initial enabled addresses }
AllowListConfig specifies the initial set of addresses with Admin or Enabled roles.
func (*AllowListConfig) Configure ¶
func (c *AllowListConfig) Configure(chainConfig precompileconfig.ChainConfig, precompileAddr common.Address, state contract.StateDB, blockContext contract.ConfigurationBlockContext) error
Configure initializes the address space of [precompileAddr] by initializing the role of each of the addresses in [AllowListAdmins].
func (*AllowListConfig) Equal ¶
func (c *AllowListConfig) Equal(other *AllowListConfig) bool
Equal returns true iff [other] has the same admins in the same order in its allow list.
func (*AllowListConfig) Verify ¶
func (c *AllowListConfig) Verify(chainConfig precompileconfig.ChainConfig, upgrade precompileconfig.Upgrade) error
Verify returns an error if there is an overlapping address between admin and enabled roles
type Role ¶
Enum constants for valid Role
func GetAllowListStatus ¶
func GetAllowListStatus(state contract.StateDB, precompileAddr common.Address, address common.Address) Role
GetAllowListStatus returns the allow list role of [address] for the precompile at [precompileAddr]
func (Role) IsAdmin ¶
IsAdmin returns true if [r] indicates the permission to modify the allow list.
func (Role) IsEnabled ¶
IsEnabled returns true if [r] indicates that it has permission to access the resource.