allowlist

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: GPL-3.0, LGPL-3.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ModifyAllowListGasCost = contract.WriteGasCostPerSlot
	ReadAllowListGasCost   = contract.ReadGasCostPerSlot
)
View Source
const (
	// AllowListEventGasCost is the gas cost of a call to the AllowList contract's event.
	// It is the base gas cost + the gas cost of the topics (signature, role, account, caller)
	// and the gas cost of the non-indexed data (oldRole).
	AllowListEventGasCost = contract.LogGas + contract.LogTopicGas*4 + contract.LogDataGas*common.HashLength
)

Variables

View Source
var (
	// Error returned when an invalid write is attempted
	ErrCannotModifyAllowList = errors.New("cannot modify allow list")

	// AllowListRawABI contains the raw ABI of AllowList library interface.
	//go:embed allowlist.abi
	AllowListRawABI string

	AllowListABI = contract.ParseABI(AllowListRawABI)
)
View Source
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))

	ErrInvalidRole = errors.New("invalid role")
)

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 Durango)

View Source
var (
	TestAdminAddr   = common.HexToAddress("0x0000000000000000000000000000000000000011")
	TestEnabledAddr = common.HexToAddress("0x0000000000000000000000000000000000000022")
	TestNoRoleAddr  = common.HexToAddress("0x0000000000000000000000000000000000000033")
	TestManagerAddr = common.HexToAddress("0x0000000000000000000000000000000000000044")
)
View Source
var ErrCannotAddManagersBeforeDurango = fmt.Errorf("cannot add managers before Durango")

Functions

func AllowListConfigEqualTests added in v0.5.0

func AllowListConfigEqualTests(t testing.TB, module modules.Module) map[string]testutils.ConfigEqualTest

func AllowListConfigVerifyTests added in v0.5.0

func AllowListConfigVerifyTests(t testing.TB, module modules.Module) map[string]testutils.ConfigVerifyTest

func AllowListTests

func AllowListTests(t testing.TB, module modules.Module) map[string]testutils.PrecompileTest

func BenchPrecompileWithAllowList added in v0.5.0

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 added in v0.5.0

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

func PackModifyAllowList

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

func PackReadAllowList

func PackReadAllowList(address common.Address) ([]byte, error)

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

func PackReadAllowListOutput added in v0.5.11

func PackReadAllowListOutput(roleNumber *big.Int) ([]byte, error)

func PackRoleSetEvent added in v0.5.11

func PackRoleSetEvent(role Role, account common.Address, caller common.Address, oldRole Role) ([]common.Hash, []byte, error)

PackRoleSetEvent packs the event into the appropriate arguments for RoleSet. It returns topic hashes and the encoded non-indexed data.

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 UnpackModifyAllowListInput added in v0.5.11

func UnpackModifyAllowListInput(input []byte, r Role, useStrictMode bool) (common.Address, error)

func UnpackReadAllowListInput added in v0.5.11

func UnpackReadAllowListInput(input []byte, useStrictMode bool) (common.Address, error)

func VerifyPrecompileWithAllowListTests added in v0.5.0

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

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 FromBig added in v0.5.11

func FromBig(b *big.Int) (Role, error)

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 UnpackRoleSetEventData added in v0.5.11

func UnpackRoleSetEventData(dataBytes []byte) (Role, error)

UnpackRoleSetEventData attempts to unpack non-indexed [dataBytes].

func (Role) Big added in v0.5.11

func (r Role) Big() *big.Int

func (Role) Bytes added in v0.5.11

func (r Role) Bytes() []byte

func (Role) CanModify added in v0.5.6

func (r Role) CanModify(from, target Role) bool

func (Role) GetSetterFunctionName added in v0.5.11

func (r Role) GetSetterFunctionName() (string, error)

func (Role) Hash added in v0.5.11

func (r Role) Hash() common.Hash

func (Role) IsAdmin

func (r Role) IsAdmin() bool

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

func (Role) IsEnabled

func (r Role) IsEnabled() bool

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

func (Role) IsNoRole

func (r Role) IsNoRole() bool

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

func (Role) String

func (r Role) String() string

String returns a string representation of [r].

Jump to

Keyboard shortcuts

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