allowlist

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2023 License: GPL-3.0, LGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SetAdminFuncKey      = "setAdmin"
	SetEnabledFuncKey    = "setEnabled"
	SetNoneFuncKey       = "setNone"
	ReadAllowListFuncKey = "readAllowList"

	ModifyAllowListGasCost = contract.WriteGasCostPerSlot
	ReadAllowListGasCost   = contract.ReadGasCostPerSlot
)

Variables

View Source
var (
	NoRole      = Role(common.BigToHash(common.Big0)) // NoRole - this is equivalent to common.Hash{} and deletes the key from the DB when set
	EnabledRole = Role(common.BigToHash(common.Big1)) // EnabledRole - allowed to call the precompile
	AdminRole   = Role(common.BigToHash(common.Big2)) // Admin - allowed to both modify the allowlist and call the precompile

	// Error returned when an invalid write is attempted
	ErrCannotModifyAllowList = errors.New("non-admin cannot modify allow list")
)
View Source
var (
	TestAdminAddr   = common.HexToAddress("0x0000000000000000000000000000000000000011")
	TestEnabledAddr = common.HexToAddress("0x0000000000000000000000000000000000000022")
	TestNoRoleAddr  = common.HexToAddress("0x0000000000000000000000000000000000000033")
)

Functions

func AllowListConfigEqualTests

func AllowListConfigEqualTests(module modules.Module) map[string]testutils.ConfigEqualTest

func AllowListConfigVerifyTests

func AllowListConfigVerifyTests(module modules.Module) map[string]testutils.ConfigVerifyTest

func AllowListTests

func AllowListTests(module modules.Module) map[string]testutils.PrecompileTest

func BenchPrecompileWithAllowList

func BenchPrecompileWithAllowList(b *testing.B, module modules.Module, newStateDB func(t testing.TB) contract.StateDB, contractTests map[string]testutils.PrecompileTest)

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 EqualPrecompileWithAllowListTests

func EqualPrecompileWithAllowListTests(t *testing.T, module modules.Module, equalTests map[string]testutils.ConfigEqualTest)

func PackModifyAllowList

func PackModifyAllowList(address common.Address, role Role) ([]byte, error)

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

func PackReadAllowList(address common.Address) []byte

PackReadAllowList packs [address] into the input data to the read allow list function

func RunPrecompileWithAllowListTests

func RunPrecompileWithAllowListTests(t *testing.T, module modules.Module, newStateDB func(t testing.TB) contract.StateDB, contractTests map[string]testutils.PrecompileTest)

func SetAllowListRole

func SetAllowListRole(stateDB contract.StateDB, precompileAddr, address common.Address, role Role)

SetAllowListRole sets the permissions of [address] to [role] for the precompile at [precompileAddr]. assumes [role] has already been verified as valid.

func SetDefaultRoles

func SetDefaultRoles(contractAddress common.Address) func(t testing.TB, state contract.StateDB)

SetDefaultRoles returns a BeforeHook that sets roles TestAdminAddr and TestEnabledAddr to have the AdminRole and EnabledRole respectively.

func VerifyPrecompileWithAllowListTests

func VerifyPrecompileWithAllowListTests(t *testing.T, module modules.Module, verifyTests map[string]testutils.ConfigVerifyTest)

Types

type AllowListConfig

type AllowListConfig struct {
	AdminAddresses   []common.Address `json:"adminAddresses,omitempty"`   // initial admin 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(state contract.StateDB, precompileAddr common.Address) 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() error

Verify returns an error if there is an overlapping address between admin and enabled roles

type Role

type Role common.Hash

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

func (s Role) IsAdmin() bool

IsAdmin returns true if [s] indicates the permission to modify the allow list.

func (Role) IsEnabled

func (s Role) IsEnabled() bool

IsEnabled returns true if [s] indicates that it has permission to access the resource.

func (Role) IsNoRole

func (s Role) IsNoRole() bool

IsNoRole returns true if [s] indicates no specific role.

func (Role) String

func (s Role) String() string

String returns a string representation of [s].

func (Role) Valid

func (s Role) Valid() bool

Valid returns true iff [s] represents a valid role.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL