diff --git a/cmd/blockchaincmd/create.go b/cmd/blockchaincmd/create.go index b6b69feea..e82a7fbc2 100644 --- a/cmd/blockchaincmd/create.go +++ b/cmd/blockchaincmd/create.go @@ -48,6 +48,7 @@ type CreateFlags struct { addICMRegistryToGenesis bool proofOfStake bool proofOfAuthority bool + poaValidatorManagerOwner string } var ( @@ -107,6 +108,7 @@ configuration, pass the -f flag.`, cmd.Flags().BoolVar(&createFlags.addICMRegistryToGenesis, "icm-registry-at-genesis", false, "setup ICM registry smart contract on genesis [experimental]") cmd.Flags().BoolVar(&createFlags.proofOfAuthority, "proof-of-authority", false, "use proof of authority for validator management") cmd.Flags().BoolVar(&createFlags.proofOfStake, "proof-of-stake", false, "(coming soon) use proof of stake for validator management") + cmd.Flags().StringVar(&createFlags.poaValidatorManagerOwner, "poa-manager-owner", "", "EVM address that controls Validator Manager Owner (for Proof of Authority only)") return cmd } @@ -204,7 +206,6 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error { var ( genesisBytes []byte - sc *models.Sidecar useTeleporterFlag *bool deployTeleporter bool useExternalGasToken bool @@ -222,7 +223,28 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error { return err } + sc := &models.Sidecar{} + + if err = promptValidatorManagementType(app, sc); err != nil { + return err + } + + if !sc.PoA() && createFlags.poaValidatorManagerOwner != "" { + return errors.New("--poa-manager-owner flag cannot be used when blockchain validator management type is not Proof of Authority") + } + if vmType == models.SubnetEvm { + if sc.PoA() { + if createFlags.poaValidatorManagerOwner == "" { + createFlags.poaValidatorManagerOwner, err = getValidatorContractManagerAddr() + if err != nil { + return err + } + } + sc.PoAValidatorManagerOwner = createFlags.poaValidatorManagerOwner + ux.Logger.GreenCheckmarkToUser("Validator Manager Contract owner address %s", createFlags.poaValidatorManagerOwner) + } + if genesisFile == "" { // Default defaultsKind, err = vm.PromptDefaults(app, defaultsKind) @@ -272,6 +294,7 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error { var params vm.SubnetEVMGenesisParams params, tokenSymbol, err = vm.PromptSubnetEVMGenesisParams( app, + sc, vmVersion, createFlags.chainID, createFlags.tokenSymbol, @@ -287,7 +310,6 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error { deployTeleporter = params.UseTeleporter useExternalGasToken = params.UseExternalGasToken genesisBytes, err = vm.CreateEVMGenesis( - blockchainName, params, teleporterInfo, createFlags.addICMRegistryToGenesis, @@ -296,14 +318,14 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error { return err } } - sc, err = vm.CreateEvmSidecar( + if sc, err = vm.CreateEvmSidecar( + sc, app, blockchainName, vmVersion, tokenSymbol, true, - ) - if err != nil { + ); err != nil { return err } } else { @@ -322,7 +344,8 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error { return err } } - sc, err = vm.CreateCustomSidecar( + if sc, err = vm.CreateCustomSidecar( + sc, app, blockchainName, useRepo, @@ -331,8 +354,7 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error { customVMBuildScript, vmFile, tokenSymbol, - ) - if err != nil { + ); err != nil { return err } } @@ -355,9 +377,6 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error { } } } - if err = promptValidatorManagementType(app, sc); err != nil { - return err - } if err = app.WriteGenesisFile(blockchainName, genesisBytes); err != nil { return err @@ -373,6 +392,7 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error { } } ux.Logger.GreenCheckmarkToUser("Successfully created blockchain configuration") + ux.Logger.PrintToUser("Run 'avalanche blockchain describe' to view all created addresses and what their roles are") return nil } diff --git a/cmd/blockchaincmd/describe.go b/cmd/blockchaincmd/describe.go index 1feb69028..e62ab66f1 100644 --- a/cmd/blockchaincmd/describe.go +++ b/cmd/blockchaincmd/describe.go @@ -21,6 +21,7 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/txutils" "github.com/ava-labs/avalanche-cli/pkg/utils" "github.com/ava-labs/avalanche-cli/pkg/ux" + "github.com/ava-labs/avalanche-cli/pkg/validatormanager" "github.com/ava-labs/avalanche-cli/pkg/vm" anr_utils "github.com/ava-labs/avalanche-network-runner/utils" "github.com/ava-labs/avalanchego/ids" @@ -107,6 +108,7 @@ func PrintSubnetInfo(blockchainName string, onlyLocalnetInfo bool) error { } t.AppendRow(table.Row{"VM ID", vmIDstr, vmIDstr}, rowConfig) t.AppendRow(table.Row{"VM Version", sc.VMVersion, sc.VMVersion}, rowConfig) + t.AppendRow(table.Row{"Validation", sc.ValidatorManagement, sc.ValidatorManagement}, rowConfig) locallyDeployed, err := localnet.Deployed(sc.Name) if err != nil { @@ -217,7 +219,7 @@ func PrintSubnetInfo(blockchainName string, onlyLocalnetInfo bool) error { if err := printAllocations(sc, genesis); err != nil { return err } - printSmartContracts(genesis) + printSmartContracts(sc, genesis) printPrecompiles(genesis) } @@ -256,16 +258,14 @@ func PrintSubnetInfo(blockchainName string, onlyLocalnetInfo bool) error { func printAllocations(sc models.Sidecar, genesis core.Genesis) error { teleporterKeyAddress := "" - teleporterPrivKey := "" if sc.TeleporterReady { k, err := key.LoadSoft(models.NewLocalNetwork().ID, app.GetKeyPath(sc.TeleporterKey)) if err != nil { return err } teleporterKeyAddress = k.C() - teleporterPrivKey = k.PrivKeyHex() } - subnetAirdropKeyName, subnetAirdropAddress, subnetAirdropPrivKey, err := subnet.GetDefaultSubnetAirdropKeyInfo(app, sc.Name) + _, subnetAirdropAddress, _, err := subnet.GetDefaultSubnetAirdropKeyInfo(app, sc.Name) if err != nil { return err } @@ -276,7 +276,12 @@ func printAllocations(sc models.Sidecar, genesis core.Genesis) error { t.Style().Title.Format = text.FormatUpper t.Style().Options.SeparateRows = true t.SetTitle("Initial Token Allocation") - t.AppendHeader(table.Row{"Description", "Address and Private Key", "Amount (10^18)", "Amount (wei)"}) + t.AppendHeader(table.Row{ + "Description", + "Address and Private Key", + fmt.Sprintf("Amount (%s)", sc.TokenSymbol), + "Amount (wei)", + }) for address, allocation := range genesis.Alloc { amount := allocation.Balance // we are only interested in supply distribution here @@ -288,14 +293,24 @@ func printAllocations(sc models.Sidecar, genesis core.Genesis) error { privKey := "" switch address.Hex() { case teleporterKeyAddress: - description = fmt.Sprintf("%s\n%s", sc.TeleporterKey, logging.Orange.Wrap("Teleporter Deploys")) - privKey = teleporterPrivKey + description = logging.Orange.Wrap("Used by ICM") case subnetAirdropAddress: - description = fmt.Sprintf("%s\n%s", subnetAirdropKeyName, logging.Orange.Wrap("Main funded account")) - privKey = subnetAirdropPrivKey + description = logging.Orange.Wrap("Main funded account") case vm.PrefundedEwoqAddress.Hex(): - description = "Main funded account EWOQ" - privKey = vm.PrefundedEwoqPrivate + description = logging.Orange.Wrap("Main funded account") + case sc.PoAValidatorManagerOwner: + description = logging.Orange.Wrap("PoA Validator Manager Owner") + } + var ( + found bool + name string + ) + found, name, _, privKey, err = contract.SearchForManagedKey(app, models.NewLocalNetwork(), address, true) + if err != nil { + return err + } + if found { + description = fmt.Sprintf("%s\n%s", description, name) } t.AppendRow(table.Row{description, address.Hex() + "\n" + privKey, formattedAmount.String(), amount.String()}) } @@ -304,7 +319,7 @@ func printAllocations(sc models.Sidecar, genesis core.Genesis) error { return nil } -func printSmartContracts(genesis core.Genesis) { +func printSmartContracts(sc models.Sidecar, genesis core.Genesis) { if len(genesis.Alloc) == 0 { return } @@ -320,9 +335,16 @@ func printSmartContracts(genesis core.Genesis) { continue } var description, deployer string - if address == common.HexToAddress(icmgenesis.MessengerContractAddress) { + switch { + case address == common.HexToAddress(icmgenesis.MessengerContractAddress): description = "ICM Messenger" deployer = icmgenesis.MessengerDeployerAddress + case address == common.HexToAddress(validatormanager.ValidatorContractAddress): + if sc.PoA() { + description = "PoA Validator Manager" + } else { + description = "PoS Validator Manager" + } } t.AppendRow(table.Row{description, address.Hex(), deployer}) } diff --git a/cmd/blockchaincmd/export_test.go b/cmd/blockchaincmd/export_test.go index c83e0552e..84a3a1188 100644 --- a/cmd/blockchaincmd/export_test.go +++ b/cmd/blockchaincmd/export_test.go @@ -41,6 +41,7 @@ func TestExportImportSubnet(t *testing.T) { ) require.NoError(err) sc, err := vm.CreateEvmSidecar( + nil, app, testSubnet, vmVersion, diff --git a/cmd/blockchaincmd/prompt_genesis_input.go b/cmd/blockchaincmd/prompt_genesis_input.go index 529c9edcf..0ef77f3f7 100644 --- a/cmd/blockchaincmd/prompt_genesis_input.go +++ b/cmd/blockchaincmd/prompt_genesis_input.go @@ -18,6 +18,19 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/signer" ) +func getValidatorContractManagerAddr() (string, error) { + return prompts.PromptAddress( + app.Prompt, + "enable as controller of ValidatorManager contract", + app.GetKeyDir(), + app.GetKey, + "", + models.UndefinedNetwork, + prompts.EVMFormat, + "Enter address", + ) +} + func promptProofOfPossession() (string, string, error) { ux.Logger.PrintToUser("Next, we need the public key and proof of possession of the node's BLS") ux.Logger.PrintToUser("Check https://docs.avax.network/api-reference/info-api#infogetnodeid for instructions on calling info.getNodeID API") @@ -49,6 +62,7 @@ func promptValidatorManagementType( sidecar.ValidatorManagement = models.ProofOfAuthority return nil } + options := []string{models.ProofOfAuthority, models.ProofOfStake, explainOption} for { option, err := app.Prompt.CaptureList( diff --git a/cmd/blockchaincmd/upgradecmd/generate.go b/cmd/blockchaincmd/upgradecmd/generate.go index b4cd36dbd..da8052416 100644 --- a/cmd/blockchaincmd/upgradecmd/generate.go +++ b/cmd/blockchaincmd/upgradecmd/generate.go @@ -598,7 +598,7 @@ func promptAdminManagerAndEnabledAddresses( sc *models.Sidecar, action string, ) ([]common.Address, []common.Address, []common.Address, bool, error) { - allowList, cancelled, err := vm.GenerateAllowList(app, action, sc.VMVersion) + allowList, cancelled, err := vm.GenerateAllowList(app, vm.AllowList{}, action, sc.VMVersion) if cancelled || err != nil { return nil, nil, nil, cancelled, err } diff --git a/pkg/contract/allocations.go b/pkg/contract/allocations.go index 9c756f222..8a097e930 100644 --- a/pkg/contract/allocations.go +++ b/pkg/contract/allocations.go @@ -71,7 +71,7 @@ func GetBlockchainAirdropKeyInfo( } } for address := range genesis.Alloc { - found, keyName, addressStr, privKey, err := searchForManagedKey(app, network, address, false) + found, keyName, addressStr, privKey, err := SearchForManagedKey(app, network, address, false) if err != nil { return "", "", "", err } @@ -82,7 +82,7 @@ func GetBlockchainAirdropKeyInfo( return "", "", "", nil } -func searchForManagedKey( +func SearchForManagedKey( app *application.Avalanche, network models.Network, address common.Address, @@ -204,7 +204,7 @@ func getGenesisNativeMinterAdmin( return false, false, "", "", "", nil } for _, admin := range allowListCfg.AllowListConfig.AdminAddresses { - found, keyName, addressStr, privKey, err := searchForManagedKey(app, network, admin, true) + found, keyName, addressStr, privKey, err := SearchForManagedKey(app, network, admin, true) if err != nil { return false, false, "", "", "", err } @@ -238,7 +238,7 @@ func getGenesisNativeMinterManager( return false, false, "", "", "", nil } for _, admin := range allowListCfg.AllowListConfig.ManagerAddresses { - found, keyName, addressStr, privKey, err := searchForManagedKey(app, network, admin, true) + found, keyName, addressStr, privKey, err := SearchForManagedKey(app, network, admin, true) if err != nil { return false, false, "", "", "", err } diff --git a/pkg/models/sidecar.go b/pkg/models/sidecar.go index 36bd429cb..e165f3a39 100644 --- a/pkg/models/sidecar.go +++ b/pkg/models/sidecar.go @@ -43,7 +43,8 @@ type Sidecar struct { // SubnetEVM based VM's only SubnetEVMMainnetChainID uint // TODO: remove if not needed for subnet acp 77 create flow once avalnache go releases etna - ValidatorManagement ValidatorManagementType + ValidatorManagement ValidatorManagementType + PoAValidatorManagerOwner string } func (sc Sidecar) GetVMID() (string, error) { @@ -65,3 +66,11 @@ func (sc Sidecar) NetworkDataIsEmpty(network string) bool { _, networkExists := sc.Networks[network] return !networkExists } + +func (sc Sidecar) PoA() bool { + return sc.ValidatorManagement == ProofOfAuthority +} + +func (sc Sidecar) PoS() bool { + return sc.ValidatorManagement == ProofOfStake +} diff --git a/pkg/validatormanager/deployed_poa_validator_manager_bytecode.txt b/pkg/validatormanager/deployed_poa_validator_manager_bytecode.txt new file mode 100644 index 000000000..7e19811ae --- /dev/null +++ b/pkg/validatormanager/deployed_poa_validator_manager_bytecode.txt @@ -0,0 +1 @@ +0x608060405234801561000f575f80fd5b506004361061011c575f3560e01c80638994ab49116100a9578063bee0a03f1161006e578063bee0a03f146102b4578063c974d1b6146102c7578063d5f20ff6146102cf578063df93d8de146102ef578063f2fde38b146102f9575f80fd5b80638994ab49146102295780638da5cb5b1461023c57806397fb70d414610280578063a3a65e4814610293578063b771b3bc146102a6575f80fd5b806360305d62116100ef57806360305d62146101ac57806361e2f490146101c957806366435abf146101dc578063715018a6146102075780638280a25a1461020f575f80fd5b80630322ed98146101205780630cdd098514610135578063467ef06f14610186578063580a400614610199575b5f80fd5b61013361012e366004612db8565b61030c565b005b610173610143366004612db8565b5f9081527fe92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb09602052604090205490565b6040519081526020015b60405180910390f35b610133610194366004612de7565b6104ca565b6101336101a7366004612e2a565b6104d8565b6101b4601481565b60405163ffffffff909116815260200161017d565b6101336101d7366004612e60565b6105e6565b6101ef6101ea366004612db8565b610c1a565b6040516001600160401b03909116815260200161017d565b610133610c2e565b610217603081565b60405160ff909116815260200161017d565b610173610237366004612ec0565b610c41565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b03165b6040516001600160a01b03909116815260200161017d565b61013361028e366004612db8565b610c5d565b6101336102a1366004612de7565b610c71565b6102686005600160991b0181565b6101336102c2366004612db8565b610e29565b610217601481565b6102e26102dd366004612db8565b610f38565b60405161017d9190612f19565b6101ef6202a30081565b610133610307366004612fcf565b61102b565b5f8181525f805160206137fa8339815191526020526040808220815160e0810190925280545f805160206137da83398151915293929190829060ff16600581111561035957610359612f05565b600581111561036a5761036a612f05565b81526001820154602082015260028201546001600160401b038082166040840152600160401b820481166060840152600160801b820481166080840152600160c01b909104811660a08301526003928301541660c090910152909150815160058111156103d9576103d9612f05565b146104435760405162461bcd60e51b815260206004820152602f60248201527f56616c696461746f724d616e616765723a2056616c696461746f72206e6f742060448201526e1c195b991a5b99c81c995b5bdd985b608a1b60648201526084015b60405180910390fd5b6005600160991b016001600160a01b031663ee5b48eb6104688584606001515f611065565b6040518263ffffffff1660e01b81526004016104849190613013565b6020604051808303815f875af11580156104a0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104c49190613045565b50505050565b6104d38161128a565b505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b03165f8115801561051c5750825b90505f826001600160401b031660011480156105375750303b155b905081158015610545575080155b156105635760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561058d57845460ff60401b1916600160401b1785555b6105978787611602565b83156105dd57845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50505050505050565b7fe92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb0a545f805160206137da8339815191529060ff16156106835760405162461bcd60e51b815260206004820152603360248201527f56616c696461746f724d616e616765723a20616c726561647920696e697469616044820152721b1a5e9959081d985b1a59185d1bdc881cd95d606a1b606482015260840161043a565b6005600160991b016001600160a01b0316634213cf786040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106c6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106ea9190613045565b83602001351461074c5760405162461bcd60e51b815260206004820152602760248201527f56616c696461746f724d616e616765723a20696e76616c696420626c6f636b636044820152661a185a5b88125160ca1b606482015260840161043a565b3061075d6060850160408601612fcf565b6001600160a01b0316146107cf5760405162461bcd60e51b815260206004820152603360248201527f56616c696461746f724d616e616765723a20696e76616c69642076616c696461604482015272746f72206d616e61676572206164647265737360681b606482015260840161043a565b5f6107dd606085018561305c565b91505f90508435602086013560146107fb6060890160408a01612fcf565b60408051602081019590955284019290925260e090811b6001600160e01b03199081166060808601919091529290921b6bffffffffffffffffffffffff1916606484015284901b166078820152607c0160405160208183030381529060405290505f805b838163ffffffff161015610b2a575f61087b606089018961305c565b8363ffffffff16818110610891576108916130a1565b90506020028101906108a391906130b5565b6108ac90613165565b80515f81815260098901602052604090205491925090156108df5760405162461bcd60e51b815260040161043a906131fc565b84825f0151836020015184604001516040516020016109019493929190613244565b60408051808303601f190181528282528b35602084015260e086901b6001600160e01b031916838301528151602481850301815260449093019182905296505f9160029161094f9190613293565b602060405180830381855afa15801561096a573d5f803e3d5ffd5b5050506040513d601f19601f8201168201806040525081019061098d9190613045565b5f83815260098a0160209081526040808320849055805160e0810182526002815287518184015287830180516001600160401b039081168385015260608301869052905181166080830152421660a082015260c0810184905284845260088d01909252909120815181549394509192909190829060ff19166001836005811115610a1957610a19612f05565b0217905550602082810151600183015560408301516002830180546060860151608087015160a08801516001600160401b039586166001600160801b031990941693909317600160401b92861692909202919091176001600160801b0316600160801b918516919091026001600160c01b031617600160c01b9184169190910217905560c0909301516003909201805467ffffffffffffffff191692841692909217909155840151610acc9116866132b8565b83516020808601516040516001600160401b039091168152929750909183917fb815f891730222788b3f8d66249b3a287ce680c3df13866fd9a4f37743ae1014910160405180910390a350505080610b23906132cb565b905061085f565b50600584018190555f610b3c86611620565b90505f610b4c82604001516117fa565b905080600285604051610b5f9190613293565b602060405180830381855afa158015610b7a573d5f803e3d5ffd5b5050506040513d601f19601f82011682018060405250810190610b9d9190613045565b14610c015760405162461bcd60e51b815260206004820152602e60248201527f56616c696461746f724d616e616765723a20696e76616c6964207375626e657460448201526d0818dbdb9d995c9cda5bdb88125160921b606482015260840161043a565b505050600a909201805460ff1916600117905550505050565b5f610c2482610f38565b6080015192915050565b610c36611963565b610c3f5f6119be565b565b5f610c4a611963565b610c548383611a2e565b90505b92915050565b610c65611963565b610c6e81611f93565b50565b5f805160206137da8339815191525f610c8983611620565b90505f80610c9a8360400151612204565b9150915080610cfc5760405162461bcd60e51b815260206004820152602860248201527f56616c696461746f724d616e616765723a20526567697374726174696f6e206e6044820152671bdd081d985b1a5960c21b606482015260840161043a565b5f82815260078501602052604081208054610d16906132ed565b9050118015610d48575060015f83815260088601602052604090205460ff166005811115610d4657610d46612f05565b145b610d645760405162461bcd60e51b815260040161043a9061331f565b5f8281526007850160205260408120610d7c91612d6e565b5f8281526008850160208181526040808420805460ff191660029081178255810180546001600160401b0342818116600160c01b026001600160c01b03909316929092178355600190930154875260098b0185528387208990559588905293835292548151600160801b90910490931683529082019290925283917ff8fd1c90fb9cfa2ca2358fdf5806b086ad43315d92b221c929efc7f105ce7568910160405180910390a25050505050565b5f8181527fe92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb076020526040812080545f805160206137da833981519152929190610e71906132ed565b9050118015610ea3575060015f83815260088301602052604090205460ff166005811115610ea157610ea1612f05565b145b610ebf5760405162461bcd60e51b815260040161043a9061331f565b5f82815260078201602052604090819020905163ee5b48eb60e01b81526005600160991b019163ee5b48eb91610ef89190600401613366565b6020604051808303815f875af1158015610f14573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104d39190613045565b6040805160e080820183525f8083526020808401829052838501829052606084018290526080840182905260a0840182905260c084018290528582525f805160206137fa83398151915290528390208351918201909352825491925f805160206137da83398151915292829060ff166005811115610fb857610fb8612f05565b6005811115610fc957610fc9612f05565b81526001820154602082015260028201546001600160401b038082166040840152600160401b820481166060840152600160801b820481166080840152600160c01b909104811660a083015260039092015490911660c0909101529392505050565b611033611963565b6001600160a01b03811661105c57604051631e4fbdf760e01b81525f600482015260240161043a565b610c6e816119be565b60408051603680825260608281019093525f91906020820181803683370190505090505f5b60028110156110de5761109e8160016133f0565b6110a9906008613403565b5081515f908390839081106110c0576110c06130a1565b60200101906001600160f81b03191690815f1a90535060010161108a565b505f5b6004811015611149576110f58160036133f0565b611100906008613403565b600263ffffffff16901c60f81b8282600261111b91906132b8565b8151811061112b5761112b6130a1565b60200101906001600160f81b03191690815f1a9053506001016110e1565b505f5b60208110156111ab5761116081601f6133f0565b61116b906008613403565b86901c60f81b8261117d8360066132b8565b8151811061118d5761118d6130a1565b60200101906001600160f81b03191690815f1a90535060010161114c565b505f5b6008811015611216576111c28160076133f0565b6111cd906008613403565b6001600160401b038616901c60f81b826111e88360266132b8565b815181106111f8576111f86130a1565b60200101906001600160f81b03191690815f1a9053506001016111ae565b505f5b60088110156112815761122d8160076133f0565b611238906008613403565b6001600160401b038516901c60f81b8261125383602e6132b8565b81518110611263576112636130a1565b60200101906001600160f81b03191690815f1a905350600101611219565b50949350505050565b6040805160e0810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c081018290525f805160206137da8339815191525f6112d985611620565b90505f806112ea8360400151612204565b91509150801561134f5760405162461bcd60e51b815260206004820152602a60248201527f56616c696461746f724d616e616765723a20726567697374726174696f6e20736044820152691d1a5b1b081d985b1a5960b21b606482015260840161043a565b5f828152600885016020526040808220815160e081019092528054829060ff16600581111561138057611380612f05565b600581111561139157611391612f05565b81526001820154602082015260028201546001600160401b038082166040840152600160401b820481166060840152600160801b820481166080840152600160c01b909104811660a08301526003928301541660c0909101529091505f908251600581111561140257611402612f05565b1480611420575060018251600581111561141e5761141e612f05565b145b61147f5760405162461bcd60e51b815260206004820152602a60248201527f56616c696461746f724d616e616765723a20696e76616c69642076616c696461604482015269746f722073746174757360b01b606482015260840161043a565b60038251600581111561149457611494612f05565b036114a1575060046114a5565b5060055b6020808301515f908152600988019091526040812055818160058111156114ce576114ce612f05565b908160058111156114e1576114e1612f05565b9052505f84815260088701602052604090208251815484929190829060ff1916600183600581111561151557611515612f05565b02179055506020820151600182015560408201516002820180546060850151608086015160a08701516001600160401b039586166001600160801b031990941693909317600160401b92861692909202919091176001600160801b0316600160801b918516919091026001600160c01b031617600160c01b9184169190910217905560c0909201516003909101805467ffffffffffffffff191691909216179055815160058111156115c9576115c9612f05565b60405185907f1c08e59656f1a18dc2da76826cdc52805c43e897a17c50faefb8ab3c1526cc16905f90a350919791965090945050505050565b61160a6123a5565b611613826123ee565b61161c81612407565b5050565b60408051606080820183525f8083526020830181905292820152905f805160206137da8339815191526040516306f8253560e41b815263ffffffff851660048201529091505f9081906005600160991b0190636f825350906024015f60405180830381865afa158015611695573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526116bc9190810190613429565b915091508061171c5760405162461bcd60e51b815260206004820152602660248201527f56616c696461746f724d616e616765723a20696e76616c69642077617270206d60448201526565737361676560d01b606482015260840161043a565b825482511461177f5760405162461bcd60e51b815260206004820152602960248201527f56616c696461746f724d616e616765723a20696e76616c696420736f757263656044820152680818da185a5b88125160ba1b606482015260840161043a565b60208201516001600160a01b0316156117f25760405162461bcd60e51b815260206004820152602f60248201527f56616c696461746f724d616e616765723a20696e76616c6964206f726967696e60448201526e2073656e646572206164647265737360881b606482015260840161043a565b509392505050565b5f815160261461181c5760405162461bcd60e51b815260040161043a906134fb565b5f805b600281101561186b576118338160016133f0565b61183e906008613403565b61ffff16848281518110611854576118546130a1565b016020015160f81c901b919091179060010161181f565b5061ffff81161561188e5760405162461bcd60e51b815260040161043a90613544565b5f805b60048110156118e9576118a58160036133f0565b6118b0906008613403565b63ffffffff16856118c28360026132b8565b815181106118d2576118d26130a1565b016020015160f81c901b9190911790600101611891565b5063ffffffff81161561190e5760405162461bcd60e51b815260040161043a90613587565b5f805b60208110156112815761192581601f6133f0565b611930906008613403565b8661193c8360066132b8565b8151811061194c5761194c6130a1565b016020015160f81c901b9190911790600101611911565b336119957f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b031690565b6001600160a01b031614610c3f5760405163118cdaa760e01b815233600482015260240161043a565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930080546001600160a01b031981166001600160a01b03848116918217845560405192169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a3505050565b7fe92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb0a545f9060ff16611ab95760405162461bcd60e51b815260206004820152602f60248201527f56616c696461746f724d616e616765723a2076616c696461746f72207365742060448201526e1b9bdd081a5b9a5d1a585b1a5e9959608a1b606482015260840161043a565b5f805160206137da83398151915242611ad860408601602087016135ce565b6001600160401b031611611b4a5760405162461bcd60e51b815260206004820152603360248201527f56616c696461746f724d616e616765723a20726567697374726174696f6e20656044820152727870697279206e6f7420696e2066757475726560681b606482015260840161043a565b611b5a60408501602086016135ce565b6001600160401b0316611b706202a300426132b8565b11611be35760405162461bcd60e51b815260206004820152603760248201527f56616c696461746f724d616e616765723a20726567697374726174696f6e206560448201527f787069727920746f6f2066617220696e20667574757265000000000000000000606482015260840161043a565b8335611c3b5760405162461bcd60e51b815260206004820152602160248201527f56616c696461746f724d616e616765723a20696e76616c6964206e6f646520496044820152601160fa1b606482015260840161043a565b83355f90815260098201602052604090205415611c6a5760405162461bcd60e51b815260040161043a906131fc565b6030611c7960408601866135e7565b905014611cde5760405162461bcd60e51b815260206004820152602d60248201527f56616c696461746f724d616e616765723a20696e76616c696420626c7350756260448201526c0d8d2c696caf240d8cadccee8d609b1b606482015260840161043a565b611ce8835f612418565b5f80611d826040518060a0016040528085600101548152602001885f01358152602001876001600160401b03168152602001886020016020810190611d2d91906135ce565b6001600160401b03168152602001611d4860408a018a6135e7565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f920191909152505050915250612626565b5f82815260078601602052604090209193509150611da08282613674565b5060405163ee5b48eb60e01b81525f906005600160991b019063ee5b48eb90611dcd908590600401613013565b6020604051808303815f875af1158015611de9573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e0d9190613045565b6040805160e08101909152909150806001815288356020808301919091526001600160401b03891660408084018290525f60608501819052608085019290925260a0840182905260c0909301819052868152600888019091522081518154829060ff19166001836005811115611e8557611e85612f05565b021790555060208281015160018301556040808401516002840180546060870151608088015160a08901516001600160401b039586166001600160801b031990941693909317600160401b92861692909202919091176001600160801b0316600160801b918516919091026001600160c01b031617600160c01b9184169190910217905560c0909401516003909301805467ffffffffffffffff19169390941692909217909255829189359186917f79b81620b81daf2c08cd5bb3dbb79e75d2d7a87f52171fde5aadc8c47823026e918b91611f65918e01908e016135ce565b604080516001600160401b0393841681529290911660208301520160405180910390a4509095945050505050565b5f8181525f805160206137fa8339815191526020526040808220815160e0810190925280545f805160206137da83398151915293929190829060ff166005811115611fe057611fe0612f05565b6005811115611ff157611ff1612f05565b8152600182015460208201526002808301546001600160401b038082166040850152600160401b820481166060850152600160801b820481166080850152600160c01b909104811660a084015260039093015490921660c0909101529091508151600581111561206357612063612f05565b146120bf5760405162461bcd60e51b815260206004820152602660248201527f56616c696461746f724d616e616765723a2076616c696461746f72206e6f742060448201526561637469766560d01b606482015260840161043a565b60038152426001600160401b031660c08201525f83815260088301602052604090208151815483929190829060ff1916600183600581111561210357612103612f05565b02179055506020820151600182015560408201516002820180546060850151608086015160a08701516001600160401b039586166001600160801b031990941693909317600160401b92861692909202919091176001600160801b0316600160801b918516919091026001600160c01b031617600160c01b9184169190910217905560c0909201516003909101805467ffffffffffffffff1916919092161790555f6121af84826129d5565b6080840151604080516001600160401b03909216825242602083015291935083925086917f13d58394cf269d48bcf927959a29a5ffee7c9924dafff8927ecdf3c48ffa7c67910160405180910390a350505050565b5f8082516027146122275760405162461bcd60e51b815260040161043a906134fb565b5f805b60028110156122765761223e8160016133f0565b612249906008613403565b61ffff1685828151811061225f5761225f6130a1565b016020015160f81c901b919091179060010161222a565b5061ffff8116156122995760405162461bcd60e51b815260040161043a90613544565b5f805b60048110156122f4576122b08160036133f0565b6122bb906008613403565b63ffffffff16866122cd8360026132b8565b815181106122dd576122dd6130a1565b016020015160f81c901b919091179060010161229c565b5063ffffffff811660031461231b5760405162461bcd60e51b815260040161043a90613587565b5f805b60208110156123705761233281601f6133f0565b61233d906008613403565b876123498360066132b8565b81518110612359576123596130a1565b016020015160f81c901b919091179060010161231e565b505f86602681518110612385576123856130a1565b016020015191976001600160f81b03199092161515965090945050505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff16610c3f57604051631afcd79f60e31b815260040160405180910390fd5b6123f66123a5565b6123fe612b2c565b610c6e81612b34565b61240f6123a5565b610c6e81612cd6565b5f805160206137da8339815191525f6001600160401b03808416908516111561244c576124458385613733565b9050612459565b6124568484613733565b90505b6040805160808101825260038401548082526004850154602083015260058501549282019290925260068401546001600160401b03166060820152429115806124bb5750600284015481516124b7916001600160401b0316906132b8565b8210155b156124e1576001600160401b038316606082015281815260408101516020820152612500565b82816060018181516124f39190613753565b6001600160401b03169052505b6060810151612510906064613773565b602082015160028601546001600160401b03929092169161253b9190600160401b900460ff16613403565b101561259f5760405162461bcd60e51b815260206004820152602d60248201527f56616c696461746f724d616e616765723a206d6178696d756d20636875726e2060448201526c1c985d1948195e18d959591959609a1b606482015260840161043a565b856001600160401b0316816040018181516125ba91906132b8565b9052506040810180516001600160401b03871691906125da9083906133f0565b905250805160038501556020810151600485015560408101516005850155606001516006909301805467ffffffffffffffff19166001600160401b039094169390931790925550505050565b5f60608260800151516030146126905760405162461bcd60e51b815260206004820152602960248201527f5374616b696e674d657373616765733a20696e76616c6964207369676e6174756044820152680e4ca40d8cadccee8d60bb1b606482015260840161043a565b60408051608680825260c082019092525f916020820181803683370190505090505f5b6002811015612707576126c78160016133f0565b6126d2906008613403565b5081515f908390839081106126e9576126e96130a1565b60200101906001600160f81b03191690815f1a9053506001016126b3565b505f5b600481101561276f5761271e8160036133f0565b612729906008613403565b600160ff919091161c60f81b826127418360026132b8565b81518110612751576127516130a1565b60200101906001600160f81b03191690815f1a90535060010161270a565b505f5b60208110156127cc578451816020811061278e5761278e6130a1565b1a60f81b8261279e8360066132b8565b815181106127ae576127ae6130a1565b60200101906001600160f81b03191690815f1a905350600101612772565b505f5b602081101561282c57846020015181602081106127ee576127ee6130a1565b1a60f81b826127fe8360266132b8565b8151811061280e5761280e6130a1565b60200101906001600160f81b03191690815f1a9053506001016127cf565b505f5b60088110156128a0576128438160076133f0565b61284e906008613403565b60ff1685604001516001600160401b0316901c60f81b8282604661287291906132b8565b81518110612882576128826130a1565b60200101906001600160f81b03191690815f1a90535060010161282f565b505f5b603081101561290b57846080015181815181106128c2576128c26130a1565b01602001516001600160f81b031916826128dd83604e6132b8565b815181106128ed576128ed6130a1565b60200101906001600160f81b03191690815f1a9053506001016128a3565b505f5b600881101561297d576129228160076133f0565b61292d906008613403565b60608601516001600160401b0390811691161c60f81b8261294f83607e6132b8565b8151811061295f5761295f6130a1565b60200101906001600160f81b03191690815f1a90535060010161290e565b5060028160405161298e9190613293565b602060405180830381855afa1580156129a9573d5f803e3d5ffd5b5050506040513d601f19601f820116820180604052508101906129cc9190613045565b94909350915050565b5f8281525f805160206137fa833981519152602052604081206002015481905f805160206137da83398151915290600160801b90046001600160401b0316612a1d8582612418565b5f612a2787612cde565b5f8881526008850160205260408120600201805467ffffffffffffffff60801b1916600160801b6001600160401b038b16021790559091506005600160991b0163ee5b48eb612a778a858b611065565b6040518263ffffffff1660e01b8152600401612a939190613013565b6020604051808303815f875af1158015612aaf573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ad39190613045565b604080516001600160401b038a811682526020820184905282519394508516928b927f07de5ff35a674a8005e661f3333c907ca6333462808762d19dc7b3abb1a8c1df928290030190a3909450925050505b9250929050565b610c3f6123a5565b612b3c6123a5565b80355f805160206137da83398151915290815560208201357fe92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb01556014612b88608084016060850161379e565b60ff161115612bf55760405162461bcd60e51b815260206004820152603360248201527f56616c696461746f724d616e616765723a206d6178696d756d20636875726e206044820152720e0cae4c6cadce8c2ceca40e8dede40d0d2ced606b1b606482015260840161043a565b5f612c06608084016060850161379e565b60ff1611612c6e5760405162461bcd60e51b815260206004820152602f60248201527f56616c696461746f724d616e616765723a207a65726f206d6178696d756d206360448201526e6875726e2070657263656e7461676560881b606482015260840161043a565b612c7e608083016060840161379e565b60028201805460ff92909216600160401b0260ff60401b19909216919091179055612caf60608301604084016135ce565b600291909101805467ffffffffffffffff19166001600160401b0390921691909117905550565b6110336123a5565b5f8181525f805160206137fa8339815191526020526040812060020180545f805160206137da83398151915291600160401b9091046001600160401b0316906008612d28836137be565b82546101009290920a6001600160401b038181021990931691831602179091555f94855260089290920160205250604090922060020154600160401b9004909116919050565b508054612d7a906132ed565b5f825580601f10612d89575050565b601f0160209004905f5260205f2090810190610c6e91905b80821115612db4575f8155600101612da1565b5090565b5f60208284031215612dc8575f80fd5b5035919050565b803563ffffffff81168114612de2575f80fd5b919050565b5f60208284031215612df7575f80fd5b610c5482612dcf565b5f60808284031215612e10575f80fd5b50919050565b6001600160a01b0381168114610c6e575f80fd5b5f8060a08385031215612e3b575f80fd5b612e458484612e00565b91506080830135612e5581612e16565b809150509250929050565b5f8060408385031215612e71575f80fd5b82356001600160401b03811115612e86575f80fd5b612e9285828601612e00565b925050612ea160208401612dcf565b90509250929050565b80356001600160401b0381168114612de2575f80fd5b5f8060408385031215612ed1575f80fd5b82356001600160401b03811115612ee6575f80fd5b830160608186031215612ef7575f80fd5b9150612ea160208401612eaa565b634e487b7160e01b5f52602160045260245ffd5b815160e082019060068110612f3c57634e487b7160e01b5f52602160045260245ffd5b80835250602083015160208301526001600160401b0360408401511660408301526060830151612f7760608401826001600160401b03169052565b506080830151612f9260808401826001600160401b03169052565b5060a0830151612fad60a08401826001600160401b03169052565b5060c0830151612fc860c08401826001600160401b03169052565b5092915050565b5f60208284031215612fdf575f80fd5b8135612fea81612e16565b9392505050565b5f5b8381101561300b578181015183820152602001612ff3565b50505f910152565b602081525f8251806020840152613031816040850160208701612ff1565b601f01601f19169190910160400192915050565b5f60208284031215613055575f80fd5b5051919050565b5f808335601e19843603018112613071575f80fd5b8301803591506001600160401b0382111561308a575f80fd5b6020019150600581901b3603821315612b25575f80fd5b634e487b7160e01b5f52603260045260245ffd5b5f8235605e198336030181126130c9575f80fd5b9190910192915050565b634e487b7160e01b5f52604160045260245ffd5b604051606081016001600160401b0381118282101715613109576131096130d3565b60405290565b604051601f8201601f191681016001600160401b0381118282101715613137576131376130d3565b604052919050565b5f6001600160401b03821115613157576131576130d3565b50601f01601f191660200190565b5f60608236031215613175575f80fd5b61317d6130e7565b82358152602061318e818501612eaa565b8183015260408401356001600160401b038111156131aa575f80fd5b840136601f8201126131ba575f80fd5b80356131cd6131c88261313f565b61310f565b81815236848385010111156131e0575f80fd5b81848401858301375f9181019093015250604082015292915050565b60208082526028908201527f56616c696461746f724d616e616765723a206e6f646520494420616c72656164604082015267792061637469766560c01b606082015260800190565b5f8551613255818460208a01612ff1565b80830190508581526001600160401b0360c01b8560c01b1660208201528351613285816028840160208801612ff1565b016028019695505050505050565b5f82516130c9818460208701612ff1565b634e487b7160e01b5f52601160045260245ffd5b80820180821115610c5757610c576132a4565b5f63ffffffff8083168181036132e3576132e36132a4565b6001019392505050565b600181811c9082168061330157607f821691505b602082108103612e1057634e487b7160e01b5f52602260045260245ffd5b60208082526027908201527f56616c696461746f724d616e616765723a20696e76616c69642076616c6964616040820152661d1a5bdb88125160ca1b606082015260800190565b5f60208083525f8454613378816132ed565b806020870152604060018084165f811461339957600181146133b5576133e2565b60ff19851660408a0152604084151560051b8a010195506133e2565b895f5260205f205f5b858110156133d95781548b82018601529083019088016133be565b8a016040019650505b509398975050505050505050565b81810381811115610c5757610c576132a4565b8082028115828204841417610c5757610c576132a4565b80518015158114612de2575f80fd5b5f806040838503121561343a575f80fd5b82516001600160401b0380821115613450575f80fd5b9084019060608287031215613463575f80fd5b61346b6130e7565b8251815260208084015161347e81612e16565b82820152604084015183811115613493575f80fd5b80850194505087601f8501126134a7575f80fd5b835192506134b76131c88461313f565b83815288828587010111156134ca575f80fd5b6134d984838301848801612ff1565b806040840152508195506134ee81880161341a565b9450505050509250929050565b60208082526029908201527f56616c696461746f724d657373616765733a20696e76616c6964206d657373616040820152680ceca40d8cadccee8d60bb1b606082015260800190565b60208082526023908201527f56616c696461746f724d657373616765733a20696e76616c696420636f64656360408201526208125160ea1b606082015260800190565b60208082526027908201527f56616c696461746f724d657373616765733a20696e76616c6964206d657373616040820152666765207479706560c81b606082015260800190565b5f602082840312156135de575f80fd5b610c5482612eaa565b5f808335601e198436030181126135fc575f80fd5b8301803591506001600160401b03821115613615575f80fd5b602001915036819003821315612b25575f80fd5b601f8211156104d357805f5260205f20601f840160051c8101602085101561364e5750805b601f840160051c820191505b8181101561366d575f815560010161365a565b5050505050565b81516001600160401b0381111561368d5761368d6130d3565b6136a18161369b84546132ed565b84613629565b602080601f8311600181146136d4575f84156136bd5750858301515b5f19600386901b1c1916600185901b17855561372b565b5f85815260208120601f198616915b82811015613702578886015182559484019460019091019084016136e3565b508582101561371f57878501515f19600388901b60f8161c191681555b505060018460011b0185555b505050505050565b6001600160401b03828116828216039080821115612fc857612fc86132a4565b6001600160401b03818116838216019080821115612fc857612fc86132a4565b6001600160401b03818116838216028082169190828114613796576137966132a4565b505092915050565b5f602082840312156137ae575f80fd5b813560ff81168114612fea575f80fd5b5f6001600160401b038083168181036132e3576132e36132a456fee92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb00e92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb08a164736f6c6343000819000a diff --git a/pkg/validatormanager/validatormanager.go b/pkg/validatormanager/validatormanager.go new file mode 100644 index 000000000..099d78d1f --- /dev/null +++ b/pkg/validatormanager/validatormanager.go @@ -0,0 +1,66 @@ +// Copyright (C) 2022, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. +package validatormanager + +import ( + _ "embed" + "math/big" + "strings" + + "github.com/ava-labs/avalanche-cli/pkg/contract" + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/subnet-evm/core" + "github.com/ethereum/go-ethereum/common" +) + +const ( + ValidatorContractAddress = "0x5F584C2D56B4c356e7d82EC6129349393dc5df17" +) + +//go:embed deployed_poa_validator_manager_bytecode.txt +var deployedPoAValidatorManagerBytecode []byte + +func AddPoAValidatorManagerContractToAllocations( + allocs core.GenesisAlloc, +) { + deployedPoaValidatorManagerBytes := common.FromHex(strings.TrimSpace(string(deployedPoAValidatorManagerBytecode))) + allocs[common.HexToAddress(ValidatorContractAddress)] = core.GenesisAccount{ + Balance: big.NewInt(0), + Code: deployedPoaValidatorManagerBytes, + Nonce: 1, + } +} + +func InitializePoAValidatorManager( + rpcURL string, + remoteAddress common.Address, + privateKey string, + subnetID ids.ID, + initialOwner common.Address, +) error { + pChainBlockchainID := ids.Empty + churnPeriodSeconds := uint64(0) + maximumChurnPercentage := uint8(20) + type Params struct { + PChainBlockchainID [32]byte + SubnetID [32]byte + ChurnPeriodSeconds uint64 + MaximumChurnPercentage uint8 + } + params := Params{ + PChainBlockchainID: pChainBlockchainID, + SubnetID: subnetID, + ChurnPeriodSeconds: churnPeriodSeconds, + MaximumChurnPercentage: maximumChurnPercentage, + } + _, _, err := contract.TxToMethod( + rpcURL, + privateKey, + remoteAddress, + nil, + "initialize((bytes32,bytes32,uint64,uint8),address)", + params, + initialOwner, + ) + return err +} diff --git a/pkg/vm/allowlist.go b/pkg/vm/allowlist.go index 536c7ace1..53851a1bb 100644 --- a/pkg/vm/allowlist.go +++ b/pkg/vm/allowlist.go @@ -98,6 +98,7 @@ func removeAddress( func GenerateAllowList( app *application.Avalanche, + allowList AllowList, action string, evmVersion string, ) (AllowList, bool, error) { @@ -106,8 +107,6 @@ func GenerateAllowList( } managerRoleEnabled := semver.Compare(evmVersion, "v0.6.4") >= 0 - allowList := AllowList{} - promptTemplate := "Configure the addresses that are allowed to %s" prompt := fmt.Sprintf(promptTemplate, action) @@ -122,6 +121,12 @@ func GenerateAllowList( enabledOption := "Enabled" explainOption := "Explain the difference" + if len(allowList.AdminAddresses) != 0 || len(allowList.ManagerAddresses) != 0 || len(allowList.EnabledAddresses) != 0 { + fmt.Println() + fmt.Printf(logging.Bold.Wrap("Addresses automatically allowed to %s\n"), action) + preview(allowList) + } + for { options := []string{addOption, removeOption, previewOption, confirmOption, cancelOption} if len(allowList.AdminAddresses) == 0 && len(allowList.ManagerAddresses) == 0 && len(allowList.EnabledAddresses) == 0 { diff --git a/pkg/vm/create_custom.go b/pkg/vm/create_custom.go index 83b918c63..358820778 100644 --- a/pkg/vm/create_custom.go +++ b/pkg/vm/create_custom.go @@ -17,6 +17,7 @@ import ( ) func CreateCustomSidecar( + sc *models.Sidecar, app *application.Avalanche, subnetName string, useRepo bool, @@ -28,12 +29,14 @@ func CreateCustomSidecar( ) (*models.Sidecar, error) { ux.Logger.PrintToUser("creating custom VM subnet %s", subnetName) - sc := &models.Sidecar{ - Name: subnetName, - VM: models.CustomVM, - Subnet: subnetName, + if sc == nil { + sc = &models.Sidecar{} } + sc.Name = subnetName + sc.VM = models.CustomVM + sc.Subnet = subnetName + if tokenSymbol != "" { sc.TokenSymbol = tokenSymbol sc.TokenName = tokenSymbol + " Token" @@ -48,34 +51,34 @@ func CreateCustomSidecar( options := []string{githubOption, localOption} option, err := app.Prompt.CaptureList("How do you want to set up the VM binary?", options) if err != nil { - return &models.Sidecar{}, err + return nil, err } if option == githubOption { useRepo = true } else { vmPath, err = app.Prompt.CaptureExistingFilepath("Enter path to VM binary") if err != nil { - return &models.Sidecar{}, err + return nil, err } } } if useRepo { if err := SetCustomVMSourceCodeFields(app, sc, customVMRepoURL, customVMBranch, customVMBuildScript); err != nil { - return &models.Sidecar{}, err + return nil, err } if err := BuildCustomVM(app, sc); err != nil { - return &models.Sidecar{}, err + return nil, err } vmPath = app.GetCustomVMPath(subnetName) } else { if err := app.CopyVMBinary(vmPath, subnetName); err != nil { - return &models.Sidecar{}, err + return nil, err } } rpcVersion, err := GetVMBinaryProtocolVersion(vmPath) if err != nil { - return &models.Sidecar{}, fmt.Errorf("unable to get RPC version: %w", err) + return nil, fmt.Errorf("unable to get RPC version: %w", err) } sc.RPCVersion = rpcVersion diff --git a/pkg/vm/create_evm.go b/pkg/vm/create_evm.go index a9a7729d1..68e0305c9 100644 --- a/pkg/vm/create_evm.go +++ b/pkg/vm/create_evm.go @@ -15,7 +15,7 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/teleporter" icmgenesis "github.com/ava-labs/avalanche-cli/pkg/teleporter/genesis" - "github.com/ava-labs/avalanche-cli/pkg/ux" + "github.com/ava-labs/avalanche-cli/pkg/validatormanager" blockchainSDK "github.com/ava-labs/avalanche-cli/sdk/blockchain" "github.com/ava-labs/subnet-evm/core" "github.com/ava-labs/subnet-evm/utils" @@ -32,6 +32,7 @@ var ( ) func CreateEvmSidecar( + sc *models.Sidecar, app *application.Avalanche, subnetName string, subnetEVMVersion string, @@ -43,6 +44,10 @@ func CreateEvmSidecar( rpcVersion int ) + if sc == nil { + sc = &models.Sidecar{} + } + if getRPCVersionFromBinary { _, vmBin, err := binutils.SetupSubnetEVM(app, subnetEVMVersion) if err != nil { @@ -59,27 +64,22 @@ func CreateEvmSidecar( } } - sc := models.Sidecar{ - Name: subnetName, - VM: models.SubnetEvm, - VMVersion: subnetEVMVersion, - RPCVersion: rpcVersion, - Subnet: subnetName, - TokenSymbol: tokenSymbol, - TokenName: tokenSymbol + " Token", - } + sc.Name = subnetName + sc.VM = models.SubnetEvm + sc.VMVersion = subnetEVMVersion + sc.RPCVersion = rpcVersion + sc.Subnet = subnetName + sc.TokenSymbol = tokenSymbol + sc.TokenName = tokenSymbol + " Token" - return &sc, nil + return sc, nil } func CreateEVMGenesis( - blockchainName string, params SubnetEVMGenesisParams, teleporterInfo *teleporter.Info, addICMRegistryToGenesis bool, ) ([]byte, error) { - ux.Logger.PrintToUser("creating genesis for blockchain %s", blockchainName) - feeConfig := getFeeConfig(params) // Validity checks on the parameter settings. @@ -117,6 +117,10 @@ func CreateEVMGenesis( } } + if params.UsePoAValidatorManager { + validatormanager.AddPoAValidatorManagerContractToAllocations(params.initialTokenAllocation) + } + if params.UseExternalGasToken { params.enableNativeMinterPrecompile = true params.nativeMinterPrecompileAllowList.AdminAddresses = append( diff --git a/pkg/vm/evm_prompts.go b/pkg/vm/evm_prompts.go index be886b2ab..461cbf92e 100644 --- a/pkg/vm/evm_prompts.go +++ b/pkg/vm/evm_prompts.go @@ -13,6 +13,7 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/utils" "github.com/ava-labs/avalanche-cli/pkg/ux" + "github.com/ava-labs/avalanche-cli/pkg/validatormanager" "github.com/ava-labs/subnet-evm/core" "github.com/ava-labs/subnet-evm/plugin/evm" "github.com/ethereum/go-ethereum/common" @@ -52,12 +53,6 @@ const ( confirmAddressAllocationOption = "Confirm and finalize the initial token allocation" ) -var DefaultEwoqAllocation = core.GenesisAlloc{ - PrefundedEwoqAddress: { - Balance: defaultEVMAirdropAmount, - }, -} - type FeeConfig struct { lowThroughput bool mediumThroughput bool @@ -90,6 +85,7 @@ type SubnetEVMGenesisParams struct { enableContractDeployerPrecompile bool contractDeployerPrecompileAllowList AllowList enableWarpPrecompile bool + UsePoAValidatorManager bool } func PromptTokenSymbol( @@ -160,6 +156,7 @@ func PromptVMType( // provided in call args func PromptSubnetEVMGenesisParams( app *application.Avalanche, + sc *models.Sidecar, version string, chainID uint64, tokenSymbol string, @@ -173,6 +170,21 @@ func PromptSubnetEVMGenesisParams( err error params SubnetEVMGenesisParams ) + params.initialTokenAllocation = core.GenesisAlloc{} + + if sc.PoA() { + params.UsePoAValidatorManager = true + params.initialTokenAllocation[common.HexToAddress(sc.PoAValidatorManagerOwner)] = core.GenesisAccount{ + Balance: defaultPoAOwnerBalance, + } + } + + if sc.PoS() { + params.enableNativeMinterPrecompile = true + params.nativeMinterPrecompileAllowList.EnabledAddresses = []common.Address{ + common.HexToAddress(validatormanager.ValidatorContractAddress), + } + } // Chain ID params.chainID = chainID @@ -321,47 +333,57 @@ func displayAllocations(alloc core.GenesisAlloc) { table.Render() } -func createNewKeyAllocation(app *application.Avalanche, subnetName string) (core.GenesisAlloc, error) { +func addNewKeyAllocation(allocations core.GenesisAlloc, app *application.Avalanche, subnetName string) error { keyName := utils.GetDefaultBlockchainAirdropKeyName(subnetName) k, err := app.GetKey(keyName, models.NewLocalNetwork(), true) if err != nil { - return core.GenesisAlloc{}, err + return err } ux.Logger.PrintToUser("prefunding address %s with balance %s", k.C(), defaultEVMAirdropAmount) + allocations[common.HexToAddress(k.C())] = core.GenesisAccount{ + Balance: defaultEVMAirdropAmount, + } + return nil +} - return core.GenesisAlloc{ - common.HexToAddress(k.C()): { - Balance: defaultEVMAirdropAmount, - }, - }, nil +func addEwoqAllocation(allocations core.GenesisAlloc) { + allocations[PrefundedEwoqAddress] = core.GenesisAccount{ + Balance: defaultEVMAirdropAmount, + } } func getNativeGasTokenAllocationConfig( + allocations core.GenesisAlloc, app *application.Avalanche, subnetName string, tokenSymbol string, -) (core.GenesisAlloc, error) { +) error { // Get the type of initial token allocation from the user prompt. allocOption, err := app.Prompt.CaptureList( "How should the initial token allocation be structured?", []string{allocateToNewKeyOption, allocateToEwoqOption, customAllocationOption}, ) if err != nil { - return core.GenesisAlloc{}, err + return err } // If the user chooses to allocate to a new key, generate a new key and allocate the default amount to it. if allocOption == allocateToNewKeyOption { - return createNewKeyAllocation(app, subnetName) + return addNewKeyAllocation(allocations, app, subnetName) } if allocOption == allocateToEwoqOption { ux.Logger.PrintToUser("prefunding address %s with balance %s", PrefundedEwoqAddress, defaultEVMAirdropAmount) - return DefaultEwoqAllocation, nil + addEwoqAllocation(allocations) + return nil } if allocOption == customAllocationOption { - res := core.GenesisAlloc{} + if len(allocations) != 0 { + fmt.Println() + fmt.Println(logging.Bold.Wrap("Addresses automatically allocated")) + displayAllocations(allocations) + } for { // Prompt for the action the user wants to take on the allocation list. action, err := app.Prompt.CaptureList( @@ -375,108 +397,118 @@ func getNativeGasTokenAllocationConfig( }, ) if err != nil { - return core.GenesisAlloc{}, err + return err } switch action { case addAddressAllocationOption: address, err := app.Prompt.CaptureAddress("Address to allocate to") if err != nil { - return core.GenesisAlloc{}, err + return err } // Check if the address already has an allocation entry. - if _, ok := res[address]; ok { + if _, ok := allocations[address]; ok { ux.Logger.PrintToUser("Address already has an allocation entry. Use edit or remove to modify.") continue } balance, err := app.Prompt.CaptureUint64(fmt.Sprintf("Amount to allocate (in %s units)", tokenSymbol)) if err != nil { - return core.GenesisAlloc{}, err + return err } - res[address] = core.GenesisAccount{ + allocations[address] = core.GenesisAccount{ Balance: new(big.Int).Mul(new(big.Int).SetUint64(balance), OneAvax), } case changeAddressAllocationOption: address, err := app.Prompt.CaptureAddress("Address to update the allocation of") if err != nil { - return core.GenesisAlloc{}, err + return err } // Check the address has an existing allocation entry. - if _, ok := res[address]; !ok { + if _, ok := allocations[address]; !ok { ux.Logger.PrintToUser("Address not found in the allocation list") continue } balance, err := app.Prompt.CaptureUint64(fmt.Sprintf("Updated amount to allocate (in %s units)", tokenSymbol)) if err != nil { - return core.GenesisAlloc{}, err + return err } - res[address] = core.GenesisAccount{ + allocations[address] = core.GenesisAccount{ Balance: new(big.Int).Mul(new(big.Int).SetUint64(balance), OneAvax), } case removeAddressAllocationOption: address, err := app.Prompt.CaptureAddress("Address to remove from the allocation list") if err != nil { - return core.GenesisAlloc{}, err + return err } // Check the address has an existing allocation entry. - if _, ok := res[address]; !ok { + if _, ok := allocations[address]; !ok { ux.Logger.PrintToUser("Address not found in the allocation list") continue } - delete(res, address) + delete(allocations, address) case previewAddressAllocationOption: - displayAllocations(res) + displayAllocations(allocations) case confirmAddressAllocationOption: - displayAllocations(res) + displayAllocations(allocations) confirm, err := app.Prompt.CaptureYesNo("Are you sure you want to finalize this allocation list?") if err != nil { - return core.GenesisAlloc{}, err + return err } if confirm { - return res, nil + return nil } default: - return core.GenesisAlloc{}, fmt.Errorf("invalid allocation modification option") + return fmt.Errorf("invalid allocation modification option") } } } - return core.GenesisAlloc{}, fmt.Errorf("invalid allocation option") + return fmt.Errorf("invalid allocation option") } -func getNativeMinterPrecompileConfig(app *application.Avalanche, version string) (AllowList, bool, error) { - option, err := app.Prompt.CaptureList( - "Allow minting of new native tokens?", - []string{fixedSupplyOption, dynamicSupplyOption}, - ) - if err != nil { - return AllowList{}, false, err - } - - if option == fixedSupplyOption { - return AllowList{}, false, nil +func getNativeMinterPrecompileConfig( + app *application.Avalanche, + alreadyEnabled bool, + allowList AllowList, + version string, +) (AllowList, bool, error) { + if !alreadyEnabled { + option, err := app.Prompt.CaptureList( + "Allow minting of new native tokens?", + []string{fixedSupplyOption, dynamicSupplyOption}, + ) + if err != nil { + return AllowList{}, false, err + } + if option == fixedSupplyOption { + return AllowList{}, false, nil + } + } else { + confirm, err := app.Prompt.CaptureYesNo("Minting of native tokens automatically enabled. Do you want to configure allow list?") + if err != nil { + return AllowList{}, false, err + } + if !confirm { + return AllowList{}, false, nil + } } - if option == dynamicSupplyOption { - for { - allowList, cancel, err := GenerateAllowList(app, "mint native tokens", version) - if err != nil { - return AllowList{}, false, err - } - if cancel { - continue - } - return allowList, true, nil + for { + allowList, cancel, err := GenerateAllowList(app, allowList, "mint native tokens", version) + if err != nil { + return AllowList{}, false, err } + if cancel { + continue + } + return allowList, true, nil } - - return AllowList{}, false, fmt.Errorf("invalid option") } // prompts for token symbol, initial token allocation, and native minter precompile @@ -502,27 +534,30 @@ func promptNativeGasToken( if defaultsKind == TestDefaults { ux.Logger.PrintToUser("prefunding address %s with balance %s", PrefundedEwoqAddress, defaultEVMAirdropAmount) - params.initialTokenAllocation = DefaultEwoqAllocation + addEwoqAllocation(params.initialTokenAllocation) return params, tokenSymbol, nil } if defaultsKind == ProductionDefaults { - params.initialTokenAllocation, err = createNewKeyAllocation(app, blockchainName) + err = addNewKeyAllocation(params.initialTokenAllocation, app, blockchainName) return params, tokenSymbol, err } // No defaults case. Prompt for initial token allocation and native minter precompile options. - alloc, err := getNativeGasTokenAllocationConfig(app, blockchainName, tokenSymbol) - if err != nil { + if err := getNativeGasTokenAllocationConfig(params.initialTokenAllocation, app, blockchainName, tokenSymbol); err != nil { return SubnetEVMGenesisParams{}, "", err } - allowList, nativeMinterEnabled, err := getNativeMinterPrecompileConfig(app, version) + allowList, nativeMinterEnabled, err := getNativeMinterPrecompileConfig( + app, + params.enableNativeMinterPrecompile, + params.nativeMinterPrecompileAllowList, + version, + ) if err != nil { return SubnetEVMGenesisParams{}, "", err } - params.initialTokenAllocation = alloc params.enableNativeMinterPrecompile = nativeMinterEnabled params.nativeMinterPrecompileAllowList = allowList return params, tokenSymbol, nil @@ -656,7 +691,7 @@ func promptFeeConfig( switch option { case dontChangeFeeSettingsOption: case changeFeeSettingsOption: - params.feeManagerPrecompileAllowList, cancel, err = GenerateAllowList(app, "adjust the gas fees", version) + params.feeManagerPrecompileAllowList, cancel, err = GenerateAllowList(app, AllowList{}, "adjust the gas fees", version) if err != nil { return SubnetEVMGenesisParams{}, err } @@ -684,7 +719,7 @@ func promptFeeConfig( switch option { case burnFees: case distributeFees: - params.rewardManagerPrecompileAllowList, cancel, err = GenerateAllowList(app, "customize gas fees distribution", version) + params.rewardManagerPrecompileAllowList, cancel, err = GenerateAllowList(app, AllowList{}, "customize gas fees distribution", version) if err != nil { return SubnetEVMGenesisParams{}, err } @@ -779,7 +814,7 @@ func promptPermissioning( } switch option { case approvedCanSubmitTransactionsOption: - params.transactionPrecompileAllowList, cancel, err = GenerateAllowList(app, "issue transactions", version) + params.transactionPrecompileAllowList, cancel, err = GenerateAllowList(app, AllowList{}, "issue transactions", version) if err != nil { return SubnetEVMGenesisParams{}, err } @@ -808,7 +843,7 @@ func promptPermissioning( } switch option { case approvedCanDeployContractsOption: - params.contractDeployerPrecompileAllowList, cancel, err = GenerateAllowList(app, "deploy smart contracts", version) + params.contractDeployerPrecompileAllowList, cancel, err = GenerateAllowList(app, AllowList{}, "deploy smart contracts", version) if err != nil { return SubnetEVMGenesisParams{}, err } diff --git a/pkg/vm/evm_settings.go b/pkg/vm/evm_settings.go index f48bb0b28..b16422a9f 100644 --- a/pkg/vm/evm_settings.go +++ b/pkg/vm/evm_settings.go @@ -25,4 +25,5 @@ var ( OneAvax = new(big.Int).SetUint64(1000000000000000000) defaultEVMAirdropAmount = new(big.Int).Exp(big.NewInt(10), big.NewInt(24), nil) // 10^24 + defaultPoAOwnerBalance = new(big.Int).Mul(OneAvax, big.NewInt(10)) // 10 Native Tokens ) diff --git a/tests/e2e/commands/subnet.go b/tests/e2e/commands/subnet.go index e9d39b8e2..c311a49c6 100644 --- a/tests/e2e/commands/subnet.go +++ b/tests/e2e/commands/subnet.go @@ -17,8 +17,9 @@ import ( ) const ( - subnetEVMMainnetChainID = 11 - bootstrapFilepathFlag = "--bootstrap-filepath" + subnetEVMMainnetChainID = 11 + poaValidatorManagerOwner = "0x2e6FcBb9d4E17eC4cF67eddfa7D32eabC4cdCFc6" + bootstrapFilepathFlag = "--bootstrap-filepath" ) /* #nosec G204 */ @@ -47,6 +48,8 @@ func CreateSubnetEvmConfigWithVersion(subnetName string, genesisPath string, ver "--evm", subnetName, "--proof-of-authority", + "--poa-manager-owner", + poaValidatorManagerOwner, "--" + constants.SkipUpdateFlag, "--teleporter=false", "--evm-token", @@ -127,6 +130,8 @@ func CreateCustomVMConfig(subnetName string, genesisPath string, vmPath string) "--genesis", genesisPath, "--proof-of-authority", + "--poa-manager-owner", + poaValidatorManagerOwner, "--custom", subnetName, "--custom-vm-path",