Skip to content

Commit

Permalink
Remove bridge allow/block list admin vars (#1482)
Browse files Browse the repository at this point in the history
* Specific error for bridge test
* Remove BridgeAllowListAdmin BridgeBlockListAdmin param
It's redundant as we already have all necessary data in chain config.
* Update core-contracts branch
  • Loading branch information
vcastellm committed May 9, 2023
1 parent 055e0ae commit 7747e12
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 71 deletions.
22 changes: 4 additions & 18 deletions command/genesis/polybft_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,17 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
}
}

// check if there are Bridge Allow List Admins and Bridge Block List Admins
// and if there are, get the first address as the Admin
var bridgeAllowListAdmin types.Address
if len(p.bridgeAllowListAdmin) > 0 {
bridgeAllowListAdmin = types.StringToAddress(p.bridgeAllowListAdmin[0])
}

var bridgeBlockListAdmin types.Address
if len(p.bridgeBlockListAdmin) > 0 {
bridgeBlockListAdmin = types.StringToAddress(p.bridgeBlockListAdmin[0])
}

polyBftConfig := &polybft.PolyBFTConfig{
InitialValidatorSet: initialValidators,
BlockTime: common.Duration{Duration: p.blockTime},
EpochSize: p.epochSize,
SprintSize: p.sprintSize,
EpochReward: p.epochReward,
// use 1st account as governance address
Governance: initialValidators[0].Address,
InitialTrieRoot: types.StringToHash(p.initialStateRoot),
NativeTokenConfig: p.nativeTokenConfig,
BridgeAllowListAdmin: bridgeAllowListAdmin,
BridgeBlockListAdmin: bridgeBlockListAdmin,
MaxValidatorSetSize: p.maxNumValidators,
Governance: initialValidators[0].Address,
InitialTrieRoot: types.StringToHash(p.initialStateRoot),
NativeTokenConfig: p.nativeTokenConfig,
MaxValidatorSetSize: p.maxNumValidators,
RewardConfig: &polybft.RewardsConfig{
TokenAddress: rewardTokenAddr,
WalletAddress: walletPremineInfo.address,
Expand Down
56 changes: 16 additions & 40 deletions consensus/polybft/contracts_initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func getInitChildERC20PredicateInput(config *BridgeConfig) ([]byte, error) {
}

// getInitChildERC20PredicateAccessListInput builds input parameters for ChildERC20PredicateAccessList SC initialization
func getInitChildERC20PredicateAccessListInput(config PolyBFTConfig) ([]byte, error) {
func getInitChildERC20PredicateAccessListInput(config *BridgeConfig, owner types.Address) ([]byte, error) {
//nolint:godox
// to be fixed with EVM-541
// TODO: @Stefan-Ethernal Temporary workaround just to be able to run cluster in non-bridge mode, until SC is fixed
Expand All @@ -86,17 +86,9 @@ func getInitChildERC20PredicateAccessListInput(config PolyBFTConfig) ([]byte, er

//nolint:godox
// TODO: This can be removed as we'll always have a bridge config
if config.Bridge != nil {
rootERC20PredicateAddr = config.Bridge.RootERC20PredicateAddr
rootERC20Addr = config.Bridge.RootNativeERC20Addr
}

// The owner of the contract will be the allow list admin or the block list admin, if any of them is set.
owner := contracts.SystemCaller
if config.BridgeAllowListAdmin != types.ZeroAddress {
owner = config.BridgeAllowListAdmin
} else if config.BridgeBlockListAdmin != types.ZeroAddress {
owner = config.BridgeBlockListAdmin
if config != nil {
rootERC20PredicateAddr = config.RootERC20PredicateAddr
rootERC20Addr = config.RootNativeERC20Addr
}

params := &contractsapi.InitializeChildERC20PredicateAccessListFn{
Expand All @@ -105,8 +97,8 @@ func getInitChildERC20PredicateAccessListInput(config PolyBFTConfig) ([]byte, er
NewRootERC20Predicate: rootERC20PredicateAddr,
NewChildTokenTemplate: contracts.ChildERC20Contract,
NewNativeTokenRootAddress: rootERC20Addr,
UseAllowList: config.BridgeAllowListAdmin != types.ZeroAddress,
UseBlockList: config.BridgeBlockListAdmin != types.ZeroAddress,
UseAllowList: owner != contracts.SystemCaller,
UseBlockList: owner != contracts.SystemCaller,
NewOwner: owner,
}

Expand All @@ -133,28 +125,20 @@ func getInitChildERC721PredicateInput(config *BridgeConfig) ([]byte, error) {

// getInitChildERC721PredicateAccessListInput builds input parameters
// for ChildERC721PredicateAccessList SC initialization
func getInitChildERC721PredicateAccessListInput(config PolyBFTConfig) ([]byte, error) {
func getInitChildERC721PredicateAccessListInput(config *BridgeConfig, owner types.Address) ([]byte, error) {
rootERC721PredicateAccessListAddr := types.StringToAddress(disabledBridgeRootPredicateAddr)

if config.Bridge != nil {
rootERC721PredicateAccessListAddr = config.Bridge.RootERC721PredicateAddr
}

// The owner of the contract will be the allow list admin or the block list admin, if any of them is set.
owner := contracts.SystemCaller
if config.BridgeAllowListAdmin != types.ZeroAddress {
owner = config.BridgeAllowListAdmin
} else if config.BridgeBlockListAdmin != types.ZeroAddress {
owner = config.BridgeBlockListAdmin
if config != nil {
rootERC721PredicateAccessListAddr = config.RootERC721PredicateAddr
}

params := &contractsapi.InitializeChildERC721PredicateAccessListFn{
NewL2StateSender: contracts.L2StateSenderContract,
NewStateReceiver: contracts.StateReceiverContract,
NewRootERC721Predicate: rootERC721PredicateAccessListAddr,
NewChildTokenTemplate: contracts.ChildERC721Contract,
UseAllowList: config.BridgeAllowListAdmin != types.ZeroAddress,
UseBlockList: config.BridgeBlockListAdmin != types.ZeroAddress,
UseAllowList: owner != contracts.SystemCaller,
UseBlockList: owner != contracts.SystemCaller,
NewOwner: owner,
}

Expand All @@ -181,28 +165,20 @@ func getInitChildERC1155PredicateInput(config *BridgeConfig) ([]byte, error) {

// getInitChildERC1155PredicateAccessListInput builds input parameters
// for ChildERC1155PredicateAccessList SC initialization
func getInitChildERC1155PredicateAccessListInput(config PolyBFTConfig) ([]byte, error) {
func getInitChildERC1155PredicateAccessListInput(config *BridgeConfig, owner types.Address) ([]byte, error) {
rootERC1155PredicateAccessListAddr := types.StringToAddress(disabledBridgeRootPredicateAddr)

if config.Bridge != nil {
rootERC1155PredicateAccessListAddr = config.Bridge.RootERC1155PredicateAddr
}

// The owner of the contract will be the allow list admin or the block list admin, if any of them is set.
owner := contracts.SystemCaller
if config.BridgeAllowListAdmin != types.ZeroAddress {
owner = config.BridgeAllowListAdmin
} else if config.BridgeBlockListAdmin != types.ZeroAddress {
owner = config.BridgeBlockListAdmin
if config != nil {
rootERC1155PredicateAccessListAddr = config.RootERC1155PredicateAddr
}

params := &contractsapi.InitializeChildERC1155PredicateAccessListFn{
NewL2StateSender: contracts.L2StateSenderContract,
NewStateReceiver: contracts.StateReceiverContract,
NewRootERC1155Predicate: rootERC1155PredicateAccessListAddr,
NewChildTokenTemplate: contracts.ChildERC1155Contract,
UseAllowList: config.BridgeAllowListAdmin != types.ZeroAddress,
UseBlockList: config.BridgeBlockListAdmin != types.ZeroAddress,
UseAllowList: owner != contracts.SystemCaller,
UseBlockList: owner != contracts.SystemCaller,
NewOwner: owner,
}

Expand Down
29 changes: 24 additions & 5 deletions consensus/polybft/polybft.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,29 @@ func GenesisPostHookFactory(config *chain.Chain, engineName string) func(txn *st
return err
}

// check if there are Bridge Allow List Admins and Bridge Block List Admins
// and if there are, get the first address as the Admin
var bridgeAllowListAdmin types.Address
if config.Params.BridgeAllowList != nil && len(config.Params.BridgeAllowList.AdminAddresses) > 0 {
bridgeAllowListAdmin = config.Params.BridgeAllowList.AdminAddresses[0]
}

var bridgeBlockListAdmin types.Address
if config.Params.BridgeBlockList != nil && len(config.Params.BridgeBlockList.AdminAddresses) > 0 {
bridgeBlockListAdmin = config.Params.BridgeBlockList.AdminAddresses[0]
}

// initialize Predicate SCs
if polyBFTConfig.BridgeAllowListAdmin != types.ZeroAddress ||
polyBFTConfig.BridgeBlockListAdmin != types.ZeroAddress {
input, err = getInitChildERC20PredicateAccessListInput(polyBFTConfig)
if bridgeAllowListAdmin != types.ZeroAddress || bridgeBlockListAdmin != types.ZeroAddress {
// The owner of the contract will be the allow list admin or the block list admin, if any of them is set.
owner := contracts.SystemCaller
if bridgeAllowListAdmin != types.ZeroAddress {
owner = bridgeAllowListAdmin
} else if bridgeBlockListAdmin != types.ZeroAddress {
owner = bridgeBlockListAdmin
}

input, err = getInitChildERC20PredicateAccessListInput(polyBFTConfig.Bridge, owner)
if err != nil {
return err
}
Expand All @@ -157,7 +176,7 @@ func GenesisPostHookFactory(config *chain.Chain, engineName string) func(txn *st
return err
}

input, err = getInitChildERC721PredicateAccessListInput(polyBFTConfig)
input, err = getInitChildERC721PredicateAccessListInput(polyBFTConfig.Bridge, owner)
if err != nil {
return err
}
Expand All @@ -167,7 +186,7 @@ func GenesisPostHookFactory(config *chain.Chain, engineName string) func(txn *st
return err
}

input, err = getInitChildERC1155PredicateAccessListInput(polyBFTConfig)
input, err = getInitChildERC1155PredicateAccessListInput(polyBFTConfig.Bridge, owner)
if err != nil {
return err
}
Expand Down
6 changes: 0 additions & 6 deletions consensus/polybft/polybft_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ type PolyBFTConfig struct {
// NativeTokenConfig defines name, symbol and decimal count of the native token
NativeTokenConfig *TokenConfig `json:"nativeTokenConfig"`

// BridgeAllowListAdmin indicates whether bridge allow list is active
BridgeAllowListAdmin types.Address `json:"bridgeAllowListAdmin"`

// BridgeBlockListAdmin indicates whether bridge block list is active
BridgeBlockListAdmin types.Address `json:"bridgeBlockListAdmin"`

InitialTrieRoot types.Hash `json:"initialTrieRoot"`

// MaxValidatorSetSize indicates the maximum size of validator set
Expand Down
2 changes: 1 addition & 1 deletion core-contracts
2 changes: 1 addition & 1 deletion e2e-polybft/e2e/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ func TestE2E_Bridge_Transfers_AccessLists(t *testing.T) {
"",
validatorSrv.JSONRPCAddr(),
contracts.NativeERC20TokenContract)
require.Error(t, err)
require.ErrorContains(t, err, "failed to execute withdrawal")

currentBlock, err := childEthEndpoint.GetBlockByNumber(ethgo.Latest, false)
require.NoError(t, err)
Expand Down

0 comments on commit 7747e12

Please sign in to comment.