Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
delete the validateProxyContractsAdmin and make a general helper function in the commands that checks if address is valid;
validate that the governance address != proxy contracts admin;
update docs;
  • Loading branch information
Vitomir2 committed Dec 2, 2024
1 parent 500a6eb commit 68be40c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
24 changes: 24 additions & 0 deletions command/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package command

import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/0xPolygon/polygon-edge/contracts"
"github.com/0xPolygon/polygon-edge/crypto"
"github.com/0xPolygon/polygon-edge/helper/common"
"github.com/0xPolygon/polygon-edge/secrets"
Expand Down Expand Up @@ -185,3 +187,25 @@ func getBLSPublicKeyBytesFromSecretManager(manager secrets.SecretsManager) ([]by

return pubKeyBytes, nil
}

// ValidateAddress checks if address is provided, is a valid Ethereum address, is not zero address, nor system caller
func ValidateAddress(name string, address string) error {
if err := types.IsValidAddress(address); err != nil {
return err
}

if strings.TrimSpace(address) == "" {
return fmt.Errorf("%s address must be set", name)
}

governanceAddr := types.StringToAddress(address)
if governanceAddr == types.ZeroAddress {
return fmt.Errorf("%s address must not be zero address", name)
}

if governanceAddr == contracts.SystemCaller {
return fmt.Errorf("%s address must not be system caller address", name)
}

return nil
}
34 changes: 5 additions & 29 deletions command/genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"os"
"strings"
"time"

"github.com/0xPolygon/polygon-edge/chain"
Expand All @@ -14,7 +13,6 @@ import (
"github.com/0xPolygon/polygon-edge/consensus/ibft/fork"
"github.com/0xPolygon/polygon-edge/consensus/ibft/signer"
"github.com/0xPolygon/polygon-edge/consensus/polybft"
"github.com/0xPolygon/polygon-edge/contracts"
"github.com/0xPolygon/polygon-edge/contracts/staking"
stakingHelper "github.com/0xPolygon/polygon-edge/helper/staking"
"github.com/0xPolygon/polygon-edge/secrets"
Expand Down Expand Up @@ -171,7 +169,7 @@ func (p *genesisParams) validateFlags() error {
// return err
// }

if err := p.validateProxyContractsAdmin(); err != nil {
if err := command.ValidateAddress("proxy contracts admin", p.proxyContractsAdmin); err != nil {
return err
}

Expand Down Expand Up @@ -566,23 +564,6 @@ func (p *genesisParams) validateGenesisBaseFeeConfig() error {
return nil
}

func (p *genesisParams) validateProxyContractsAdmin() error {
if strings.TrimSpace(p.proxyContractsAdmin) == "" {
return errors.New("proxy contracts admin address must be set")
}

proxyContractsAdminAddr := types.StringToAddress(p.proxyContractsAdmin)
if proxyContractsAdminAddr == types.ZeroAddress {
return errors.New("proxy contracts admin address must not be zero address")
}

if proxyContractsAdminAddr == contracts.SystemCaller {
return errors.New("proxy contracts admin address must not be system caller address")
}

return nil
}

// isBurnContractEnabled returns true in case burn contract info is provided
func (p *genesisParams) isBurnContractEnabled() bool {
return p.burnContract != ""
Expand All @@ -607,17 +588,12 @@ func (p *genesisParams) getResult() command.CommandResult {
}

func (p *genesisParams) validateGovernanceAddress() error {
if strings.TrimSpace(p.governance) == "" {
return errors.New("governance address must be set")
}

proxyContractsAdminAddr := types.StringToAddress(p.proxyContractsAdmin)
if proxyContractsAdminAddr == types.ZeroAddress {
return errors.New("governance address must not be zero address")
if err := command.ValidateAddress("governance", p.governance); err != nil {
return err
}

if proxyContractsAdminAddr == contracts.SystemCaller {
return errors.New("governance address must not be system caller address")
if p.proxyContractsAdmin == p.governance {
return errors.New("governance address must be different than the proxy contracts admin")
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion h_docs/polybft_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ I am describing our custom process, because it is different.
We need to set native token to be mintable, so we can premine balances to different addresses. Keep in mind that the validators need some premined coins, so, add it before generating the genesis. They are needed in order validators to feed the Price Oracle (executing transactions). Use the command below to generate the file. Make sure to update the proxy contracts admin and governance flags according to your requirements.

```
./hydra genesis --block-gas-limit 10000000 --epoch-size 10 --validators-path ./ --validators-prefix test-chain- --consensus polybft --native-token-config Hydra:HDR:18:true:0x211881Bb4893dd733825A2D97e48bFc38cc70a0c --premine 0x211881Bb4893dd733825A2D97e48bFc38cc70a0c:70000000000000000000000 --premine 0xdC3312E368A178e24850C6dAC169646c5fD14b93:30000000000000000000000 --proxy-contracts-admin 0x211881Bb4893dd733825A2D97e48bFc38cc70a0c --governance 0x0000000000000000000000000000000000000000 --chain-id 8844
./hydra genesis --block-gas-limit 10000000 --epoch-size 10 --validators-path ./ --validators-prefix test-chain- --consensus polybft --native-token-config Hydra:HDR:18:true:0x211881Bb4893dd733825A2D97e48bFc38cc70a0c --premine 0x211881Bb4893dd733825A2D97e48bFc38cc70a0c:70000000000000000000000 --premine 0xdC3312E368A178e24850C6dAC169646c5fD14b93:30000000000000000000000 --proxy-contracts-admin 0x211881Bb4893dd733825A2D97e48bFc38cc70a0c --governance <governance-address-here> --chain-id 8844
```

4. Run the chain
Expand Down

0 comments on commit 68be40c

Please sign in to comment.