Skip to content

Commit

Permalink
Allowlist package refactor and blocklist implementation (#1388)
Browse files Browse the repository at this point in the history
* Allowlist package refactor and blocklist implementation

This is a refactor of the allowlist package to make it more generic as it's now used for both allowlist and blocklist. It also adds the blocklist implementation.
  • Loading branch information
vcastellm committed Apr 20, 2023
1 parent 5feb7f6 commit fee5ae0
Show file tree
Hide file tree
Showing 15 changed files with 614 additions and 306 deletions.
10 changes: 6 additions & 4 deletions chain/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ type Params struct {
Whitelists *Whitelists `json:"whitelists,omitempty"`
BlockGasTarget uint64 `json:"blockGasTarget"`

// AllowList configuration
ContractDeployerAllowList *AllowListConfig `json:"contractDeployerAllowList,omitempty"`
TransactionsAllowList *AllowListConfig `json:"transactionsAllowList,omitempty"`
// Access control configuration
ContractDeployerAllowList *AddressListConfig `json:"contractDeployerAllowList,omitempty"`
ContractDeployerBlockList *AddressListConfig `json:"contractDeployerBlockList,omitempty"`
TransactionsAllowList *AddressListConfig `json:"transactionsAllowList,omitempty"`
TransactionsBlockList *AddressListConfig `json:"transactionsBlockList,omitempty"`
}

type AllowListConfig struct {
type AddressListConfig struct {
// AdminAddresses is the list of the initial admin addresses
AdminAddresses []types.Address `json:"adminAddresses,omitempty"`

Expand Down
30 changes: 29 additions & 1 deletion command/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func setFlags(cmd *cobra.Command) {
)
}

// Allow list
// Access Control Lists
{
cmd.Flags().StringArrayVar(
&params.contractDeployerAllowListAdmin,
Expand All @@ -243,6 +243,20 @@ func setFlags(cmd *cobra.Command) {
"list of addresses to enable by default in the contract deployer allow list",
)

cmd.Flags().StringArrayVar(
&params.contractDeployerBlockListAdmin,
contractDeployerBlockListAdminFlag,
[]string{},
"list of addresses to use as admin accounts in the contract deployer block list",
)

cmd.Flags().StringArrayVar(
&params.contractDeployerBlockListEnabled,
contractDeployerBlockListEnabledFlag,
[]string{},
"list of addresses to enable by default in the contract deployer block list",
)

cmd.Flags().StringArrayVar(
&params.transactionsAllowListAdmin,
transactionsAllowListAdminFlag,
Expand All @@ -256,6 +270,20 @@ func setFlags(cmd *cobra.Command) {
[]string{},
"list of addresses to enable by default in the transactions allow list",
)

cmd.Flags().StringArrayVar(
&params.transactionsBlockListAdmin,
transactionsBlockListAdminFlag,
[]string{},
"list of addresses to use as admin accounts in the transactions block list",
)

cmd.Flags().StringArrayVar(
&params.transactionsBlockListEnabled,
transactionsBlockListEnabledFlag,
[]string{},
"list of addresses to enable by default in the transactions block list",
)
}
}

Expand Down
6 changes: 5 additions & 1 deletion command/genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,15 @@ type genesisParams struct {

initialStateRoot string

// allowlist
// access lists
contractDeployerAllowListAdmin []string
contractDeployerAllowListEnabled []string
contractDeployerBlockListAdmin []string
contractDeployerBlockListEnabled []string
transactionsAllowListAdmin []string
transactionsAllowListEnabled []string
transactionsBlockListAdmin []string
transactionsBlockListEnabled []string

mintableNativeToken bool
nativeTokenConfigRaw string
Expand Down
26 changes: 24 additions & 2 deletions command/genesis/polybft_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ const (

contractDeployerAllowListAdminFlag = "contract-deployer-allow-list-admin"
contractDeployerAllowListEnabledFlag = "contract-deployer-allow-list-enabled"
contractDeployerBlockListAdminFlag = "contract-deployer-block-list-admin"
contractDeployerBlockListEnabledFlag = "contract-deployer-block-list-enabled"
transactionsAllowListAdminFlag = "transactions-allow-list-admin"
transactionsAllowListEnabledFlag = "transactions-allow-list-enabled"
transactionsBlockListAdminFlag = "transactions-block-list-admin"
transactionsBlockListEnabledFlag = "transactions-block-list-enabled"

bootnodePortStart = 30301

Expand Down Expand Up @@ -183,21 +187,39 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
if len(p.contractDeployerAllowListAdmin) != 0 {
// only enable allow list if there is at least one address as **admin**, otherwise
// the allow list could never be updated
chainConfig.Params.ContractDeployerAllowList = &chain.AllowListConfig{
chainConfig.Params.ContractDeployerAllowList = &chain.AddressListConfig{
AdminAddresses: stringSliceToAddressSlice(p.contractDeployerAllowListAdmin),
EnabledAddresses: stringSliceToAddressSlice(p.contractDeployerAllowListEnabled),
}
}

if len(p.contractDeployerBlockListAdmin) != 0 {
// only enable block list if there is at least one address as **admin**, otherwise
// the block list could never be updated
chainConfig.Params.ContractDeployerBlockList = &chain.AddressListConfig{
AdminAddresses: stringSliceToAddressSlice(p.contractDeployerBlockListAdmin),
EnabledAddresses: stringSliceToAddressSlice(p.contractDeployerBlockListEnabled),
}
}

if len(p.transactionsAllowListAdmin) != 0 {
// only enable allow list if there is at least one address as **admin**, otherwise
// the allow list could never be updated
chainConfig.Params.TransactionsAllowList = &chain.AllowListConfig{
chainConfig.Params.TransactionsAllowList = &chain.AddressListConfig{
AdminAddresses: stringSliceToAddressSlice(p.transactionsAllowListAdmin),
EnabledAddresses: stringSliceToAddressSlice(p.transactionsAllowListEnabled),
}
}

if len(p.transactionsBlockListAdmin) != 0 {
// only enable block list if there is at least one address as **admin**, otherwise
// the block list could never be updated
chainConfig.Params.TransactionsBlockList = &chain.AddressListConfig{
AdminAddresses: stringSliceToAddressSlice(p.transactionsBlockListAdmin),
EnabledAddresses: stringSliceToAddressSlice(p.transactionsBlockListEnabled),
}
}

return helper.WriteGenesisConfigToDisk(chainConfig, params.genesisPath)
}

Expand Down
4 changes: 4 additions & 0 deletions contracts/system_addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ var (
ConsolePrecompile = types.StringToAddress("0x000000000000000000636F6e736F6c652e6c6f67")
// AllowListContractsAddr is the address of the contract deployer allow list
AllowListContractsAddr = types.StringToAddress("0x0200000000000000000000000000000000000000")
// BlockListContractsAddr is the address of the contract deployer block list
BlockListContractsAddr = types.StringToAddress("0x0300000000000000000000000000000000000000")
// AllowListTransactionsAddr is the address of the transactions allow list
AllowListTransactionsAddr = types.StringToAddress("0x0200000000000000000000000000000000000002")
// BlockListTransactionsAddr is the address of the transactions block list
BlockListTransactionsAddr = types.StringToAddress("0x0300000000000000000000000000000000000002")
)
Loading

0 comments on commit fee5ae0

Please sign in to comment.