diff --git a/cmd/blockchaincmd/create.go b/cmd/blockchaincmd/create.go index e945bea63..9705df9a0 100644 --- a/cmd/blockchaincmd/create.go +++ b/cmd/blockchaincmd/create.go @@ -47,6 +47,7 @@ type CreateFlags struct { useLatestReleasedVMVersion bool useLatestPreReleasedVMVersion bool useExternalGasToken bool + addICMRegistryToGenesis bool proofOfStake bool proofOfAuthority bool } @@ -106,6 +107,7 @@ configuration, pass the -f flag.`, cmd.Flags().BoolVar(&createFlags.useWarp, "warp", true, "generate a vm with warp support (needed for teleporter)") cmd.Flags().BoolVar(&createFlags.useTeleporter, "teleporter", false, "interoperate with other blockchains using teleporter") cmd.Flags().BoolVar(&createFlags.useExternalGasToken, "external-gas-token", false, "use a gas token from another blockchain") + 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") return cmd @@ -291,6 +293,7 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error { blockchainName, params, teleporterInfo, + createFlags.addICMRegistryToGenesis, ) if err != nil { return err diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index 01516cc0a..c8af0bf16 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -101,7 +101,8 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`, cmd.Flags().BoolVar(&icmSpec.SkipICMDeploy, "skip-local-teleporter", false, "skip automatic teleporter deploy on local networks [to be deprecated]") cmd.Flags().BoolVar(&icmSpec.SkipICMDeploy, "skip-teleporter-deploy", false, "skip automatic teleporter deploy") cmd.Flags().BoolVar(&icmSpec.SkipRelayerDeploy, "skip-relayer", false, "skip relayer deploy") - cmd.Flags().StringVar(&icmSpec.Version, "teleporter-version", "latest", "teleporter version to deploy") + cmd.Flags().StringVar(&icmSpec.ICMVersion, "teleporter-version", "latest", "teleporter version to deploy") + cmd.Flags().StringVar(&icmSpec.RelayerVersion, "relayer-version", "latest", "relayer version to deploy") cmd.Flags().StringVar(&icmSpec.MessengerContractAddressPath, "teleporter-messenger-contract-address-path", "", "path to an interchain messenger contract address file") cmd.Flags().StringVar(&icmSpec.MessengerDeployerAddressPath, "teleporter-messenger-deployer-address-path", "", "path to an interchain messenger deployer address file") cmd.Flags().StringVar(&icmSpec.MessengerDeployerTxPath, "teleporter-messenger-deployer-tx-path", "", "path to an interchain messenger deployer tx file") diff --git a/cmd/blockchaincmd/describe.go b/cmd/blockchaincmd/describe.go index 83ac2a5b8..1feb69028 100644 --- a/cmd/blockchaincmd/describe.go +++ b/cmd/blockchaincmd/describe.go @@ -17,6 +17,7 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/networkoptions" "github.com/ava-labs/avalanche-cli/pkg/subnet" + icmgenesis "github.com/ava-labs/avalanche-cli/pkg/teleporter/genesis" "github.com/ava-labs/avalanche-cli/pkg/txutils" "github.com/ava-labs/avalanche-cli/pkg/utils" "github.com/ava-labs/avalanche-cli/pkg/ux" @@ -216,6 +217,7 @@ func PrintSubnetInfo(blockchainName string, onlyLocalnetInfo bool) error { if err := printAllocations(sc, genesis); err != nil { return err } + printSmartContracts(genesis) printPrecompiles(genesis) } @@ -275,8 +277,12 @@ func printAllocations(sc models.Sidecar, genesis core.Genesis) error { t.Style().Options.SeparateRows = true t.SetTitle("Initial Token Allocation") t.AppendHeader(table.Row{"Description", "Address and Private Key", "Amount (10^18)", "Amount (wei)"}) - for address := range genesis.Alloc { - amount := genesis.Alloc[address].Balance + for address, allocation := range genesis.Alloc { + amount := allocation.Balance + // we are only interested in supply distribution here + if amount == nil || big.NewInt(0).Cmp(amount) == 0 { + continue + } formattedAmount := new(big.Int).Div(amount, big.NewInt(params.Ether)) description := "" privKey := "" @@ -298,6 +304,31 @@ func printAllocations(sc models.Sidecar, genesis core.Genesis) error { return nil } +func printSmartContracts(genesis core.Genesis) { + if len(genesis.Alloc) == 0 { + return + } + ux.Logger.PrintToUser("") + t := table.NewWriter() + t.Style().Title.Align = text.AlignCenter + t.Style().Title.Format = text.FormatUpper + t.Style().Options.SeparateRows = true + t.SetTitle("Smart Contracts") + t.AppendHeader(table.Row{"Description", "Address", "Deployer"}) + for address, allocation := range genesis.Alloc { + if len(allocation.Code) == 0 { + continue + } + var description, deployer string + if address == common.HexToAddress(icmgenesis.MessengerContractAddress) { + description = "ICM Messenger" + deployer = icmgenesis.MessengerDeployerAddress + } + t.AppendRow(table.Row{description, address.Hex(), deployer}) + } + ux.Logger.PrintToUser(t.Render()) +} + func printPrecompiles(genesis core.Genesis) { ux.Logger.PrintToUser("") t := table.NewWriter() diff --git a/cmd/nodecmd/wiz.go b/cmd/nodecmd/wiz.go index 61cf9e63c..640241782 100644 --- a/cmd/nodecmd/wiz.go +++ b/cmd/nodecmd/wiz.go @@ -395,6 +395,7 @@ func wiz(cmd *cobra.Command, args []string) error { }, DeployMessenger: deployTeleporterMessenger, DeployRegistry: deployTeleporterRegistry, + ForceRegistryDeploy: true, Version: teleporterVersion, MessengerContractAddressPath: teleporterMessengerContractAddressPath, MessengerDeployerAddressPath: teleporterMessengerDeployerAddressPath, diff --git a/cmd/teleportercmd/deploy.go b/cmd/teleportercmd/deploy.go index fef0f1061..2671b16a1 100644 --- a/cmd/teleportercmd/deploy.go +++ b/cmd/teleportercmd/deploy.go @@ -25,6 +25,7 @@ type DeployFlags struct { GenesisKey bool DeployMessenger bool DeployRegistry bool + ForceRegistryDeploy bool RPCURL string Version string MessengerContractAddressPath string @@ -62,6 +63,7 @@ func newDeployCmd() *cobra.Command { deployFlags.ChainFlags.AddToCmd(cmd, "deploy ICM", true) cmd.Flags().BoolVar(&deployFlags.DeployMessenger, "deploy-messenger", true, "deploy Teleporter Messenger") cmd.Flags().BoolVar(&deployFlags.DeployRegistry, "deploy-registry", true, "deploy Teleporter Registry") + cmd.Flags().BoolVar(&deployFlags.ForceRegistryDeploy, "force-registry-deploy", false, "deploy Teleporter Registry even if Messenger has already been deployed") cmd.Flags().StringVar(&deployFlags.RPCURL, "rpc-url", "", "use the given RPC URL to connect to the subnet") cmd.Flags().StringVar(&deployFlags.Version, "version", "latest", "version to deploy") cmd.Flags().StringVar(&deployFlags.MessengerContractAddressPath, "messenger-contract-address-path", "", "path to a messenger contract address file") @@ -188,6 +190,7 @@ func CallDeploy(_ []string, flags DeployFlags) error { privateKey, flags.DeployMessenger, flags.DeployRegistry, + flags.ForceRegistryDeploy, ) if err != nil { return err @@ -224,6 +227,7 @@ func CallDeploy(_ []string, flags DeployFlags) error { ewoq.PrivKeyHex(), flags.DeployMessenger, flags.DeployRegistry, + false, ) if err != nil { return err diff --git a/pkg/contract/allocations.go b/pkg/contract/allocations.go index 84b810bc2..9543ba227 100644 --- a/pkg/contract/allocations.go +++ b/pkg/contract/allocations.go @@ -235,3 +235,19 @@ func GetEVMSubnetGenesisNativeMinterAdmin( } return getGenesisNativeMinterAdmin(app, network, genesisData) } + +func ContractAddressIsInGenesisData( + genesisData []byte, + contractAddress common.Address, +) (bool, error) { + genesis, err := utils.ByteSliceToSubnetEvmGenesis(genesisData) + if err != nil { + return false, err + } + for address, allocation := range genesis.Alloc { + if address == contractAddress { + return len(allocation.Code) > 0, nil + } + } + return false, nil +} diff --git a/pkg/contract/allocations_test.go b/pkg/contract/allocations_test.go new file mode 100644 index 000000000..07577ce94 --- /dev/null +++ b/pkg/contract/allocations_test.go @@ -0,0 +1,194 @@ +// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. +package contract + +import ( + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" +) + +func TestContractAddressIsInGenesisData(t *testing.T) { + require := require.New(t) + + type test struct { + desc string + genesisData []byte + contractAddress common.Address + expected bool + shouldErr bool + } + + tests := []test{ + { + desc: "nil data", + genesisData: nil, + contractAddress: common.Address{}, + expected: false, + shouldErr: true, + }, + { + desc: "not json", + genesisData: []byte("not json"), + contractAddress: common.Address{}, + expected: false, + shouldErr: true, + }, + { + desc: "not evm", + genesisData: []byte("{}"), + contractAddress: common.Address{}, + expected: false, + shouldErr: true, + }, + { + desc: "no allocs", + genesisData: []byte(` +{ + "config": { + "byzantiumBlock": 0, "chainId": 1, "constantinopleBlock": 0, "eip150Block": 0, + "eip155Block": 0, "eip158Block": 0, + "feeConfig": { + "gasLimit": 12000000, "targetBlockRate": 2, "minBaseFee": 25000000000, + "targetGas": 60000000, "baseFeeChangeDenominator": 36, "minBlockGasCost": 0, + "maxBlockGasCost": 1000000, "blockGasCostStep": 200000 + }, + "homesteadBlock": 0, "istanbulBlock": 0, "muirGlacierBlock": 0, "petersburgBlock": 0, + "warpConfig": { + "blockTimestamp": 1727309619, "quorumNumerator": 67 + } + }, + "nonce": "0x0", "timestamp": "0x66f4a733", "extraData": "0x", "gasLimit": "0xb71b00", "difficulty": "0x0", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x0000000000000000000000000000000000000000", + "airdropHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "airdropAmount": null, "number": "0x0", "gasUsed": "0x0", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "baseFeePerGas": null, "excessBlobGas": null, "blobGasUsed": null, + "alloc": {} +} + `), + contractAddress: common.Address{}, + expected: false, + shouldErr: false, + }, + { + desc: "good path", + genesisData: []byte(` +{ + "config": { + "byzantiumBlock": 0, "chainId": 1, "constantinopleBlock": 0, "eip150Block": 0, + "eip155Block": 0, "eip158Block": 0, + "feeConfig": { + "gasLimit": 12000000, "targetBlockRate": 2, "minBaseFee": 25000000000, + "targetGas": 60000000, "baseFeeChangeDenominator": 36, "minBlockGasCost": 0, + "maxBlockGasCost": 1000000, "blockGasCostStep": 200000 + }, + "homesteadBlock": 0, "istanbulBlock": 0, "muirGlacierBlock": 0, "petersburgBlock": 0, + "warpConfig": { + "blockTimestamp": 1727309619, "quorumNumerator": 67 + } + }, + "nonce": "0x0", "timestamp": "0x66f4a733", "extraData": "0x", "gasLimit": "0xb71b00", "difficulty": "0x0", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x0000000000000000000000000000000000000000", + "airdropHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "airdropAmount": null, "number": "0x0", "gasUsed": "0x0", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "baseFeePerGas": null, "excessBlobGas": null, "blobGasUsed": null, + "alloc": { + "253b2784c75e510dd0ff1da844684a1ac0aa5fcf": { + "code": "0xfe", + "balance": "0x2086ac351052600000" + } + } +} + `), + contractAddress: common.HexToAddress("0x253b2784c75e510dd0ff1da844684a1ac0aa5fcf"), + expected: true, + shouldErr: false, + }, + { + desc: "no code", + genesisData: []byte(` +{ + "config": { + "byzantiumBlock": 0, "chainId": 1, "constantinopleBlock": 0, "eip150Block": 0, + "eip155Block": 0, "eip158Block": 0, + "feeConfig": { + "gasLimit": 12000000, "targetBlockRate": 2, "minBaseFee": 25000000000, + "targetGas": 60000000, "baseFeeChangeDenominator": 36, "minBlockGasCost": 0, + "maxBlockGasCost": 1000000, "blockGasCostStep": 200000 + }, + "homesteadBlock": 0, "istanbulBlock": 0, "muirGlacierBlock": 0, "petersburgBlock": 0, + "warpConfig": { + "blockTimestamp": 1727309619, "quorumNumerator": 67 + } + }, + "nonce": "0x0", "timestamp": "0x66f4a733", "extraData": "0x", "gasLimit": "0xb71b00", "difficulty": "0x0", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x0000000000000000000000000000000000000000", + "airdropHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "airdropAmount": null, "number": "0x0", "gasUsed": "0x0", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "baseFeePerGas": null, "excessBlobGas": null, "blobGasUsed": null, + "alloc": { + "253b2784c75e510dd0ff1da844684a1ac0aa5fcf": { + "balance": "0x2086ac351052600000" + } + } +} + `), + contractAddress: common.HexToAddress("0x253b2784c75e510dd0ff1da844684a1ac0aa5fcf"), + expected: false, + shouldErr: false, + }, + { + desc: "diff addr", + genesisData: []byte(` +{ + "config": { + "byzantiumBlock": 0, "chainId": 1, "constantinopleBlock": 0, "eip150Block": 0, + "eip155Block": 0, "eip158Block": 0, + "feeConfig": { + "gasLimit": 12000000, "targetBlockRate": 2, "minBaseFee": 25000000000, + "targetGas": 60000000, "baseFeeChangeDenominator": 36, "minBlockGasCost": 0, + "maxBlockGasCost": 1000000, "blockGasCostStep": 200000 + }, + "homesteadBlock": 0, "istanbulBlock": 0, "muirGlacierBlock": 0, "petersburgBlock": 0, + "warpConfig": { + "blockTimestamp": 1727309619, "quorumNumerator": 67 + } + }, + "nonce": "0x0", "timestamp": "0x66f4a733", "extraData": "0x", "gasLimit": "0xb71b00", "difficulty": "0x0", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x0000000000000000000000000000000000000000", + "airdropHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "airdropAmount": null, "number": "0x0", "gasUsed": "0x0", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "baseFeePerGas": null, "excessBlobGas": null, "blobGasUsed": null, + "alloc": { + "253b2784c75e510dd0ff1da844684a1ac0aa5fcf": { + "code": "0xfe", + "balance": "0x2086ac351052600000" + } + } +} + `), + contractAddress: common.HexToAddress("0x253b2724c75e510dd0ff1da844684a1ac0aa5fcc"), + expected: false, + shouldErr: false, + }, + } + + for _, t := range tests { + b, err := ContractAddressIsInGenesisData(t.genesisData, t.contractAddress) + if t.shouldErr { + require.Error(err, t.desc) + } else { + require.NoError(err, t.desc) + } + require.Equal(t.expected, b, t.desc) + } +} diff --git a/pkg/subnet/local.go b/pkg/subnet/local.go index cd6efa2af..0e420d3c1 100644 --- a/pkg/subnet/local.go +++ b/pkg/subnet/local.go @@ -24,6 +24,7 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/localnet" "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/utils" "github.com/ava-labs/avalanche-cli/pkg/ux" "github.com/ava-labs/avalanche-network-runner/client" @@ -81,11 +82,12 @@ type setDefaultSnapshotFunc func(string, bool, string, bool) (bool, error) type ICMSpec struct { SkipICMDeploy bool SkipRelayerDeploy bool - Version string + ICMVersion string MessengerContractAddressPath string MessengerDeployerAddressPath string MessengerDeployerTxPath string RegistryBydecodePath string + RelayerVersion string } type DeployInfo struct { @@ -99,7 +101,7 @@ type DeployInfo struct { // * it checks the gRPC is running, if not, it starts it // * kicks off the actual deployment func (d *LocalDeployer) DeployToLocalNetwork( - chain string, + blockchainName string, genesisPath string, icmSpec ICMSpec, subnetIDStr string, @@ -107,7 +109,7 @@ func (d *LocalDeployer) DeployToLocalNetwork( if err := d.StartServer(); err != nil { return nil, err } - return d.doDeploy(chain, genesisPath, icmSpec, subnetIDStr) + return d.doDeploy(blockchainName, genesisPath, icmSpec, subnetIDStr) } func (d *LocalDeployer) StartServer() error { @@ -151,7 +153,7 @@ func (d *LocalDeployer) BackendStartedHere() bool { // - deploy a new blockchain for the given VM ID, genesis, and available subnet ID // - waits completion of operation // - show status -func (d *LocalDeployer) doDeploy(chain string, genesisPath string, icmSpec ICMSpec, subnetIDStr string) (*DeployInfo, error) { +func (d *LocalDeployer) doDeploy(blockchainName string, genesisPath string, icmSpec ICMSpec, subnetIDStr string) (*DeployInfo, error) { needsRestart, avalancheGoBinPath, err := d.SetupLocalEnv() if err != nil { return nil, err @@ -174,7 +176,7 @@ func (d *LocalDeployer) doDeploy(chain string, genesisPath string, icmSpec ICMSp defer cancel() // loading sidecar before it's needed so we catch any error early - sc, err := d.app.LoadSidecar(chain) + sc, err := d.app.LoadSidecar(blockchainName) if err != nil { return nil, fmt.Errorf("failed to load sidecar: %w", err) } @@ -192,9 +194,9 @@ func (d *LocalDeployer) doDeploy(chain string, genesisPath string, icmSpec ICMSp } } - chainVMID, err := anrutils.VMID(chain) + chainVMID, err := anrutils.VMID(blockchainName) if err != nil { - return nil, fmt.Errorf("failed to create VM ID from %s: %w", chain, err) + return nil, fmt.Errorf("failed to create VM ID from %s: %w", blockchainName, err) } d.app.Log.Debug("this VM will get ID", zap.String("vm-id", chainVMID.String())) @@ -253,7 +255,7 @@ func (d *LocalDeployer) doDeploy(chain string, genesisPath string, icmSpec ICMSp logRootDir = clusterInfo.GetLogRootDir() if alreadyDeployed(chainVMID, clusterInfo) { - return nil, fmt.Errorf("subnet %s has already been deployed", chain) + return nil, fmt.Errorf("subnet %s has already been deployed", blockchainName) } numBlockchains := len(clusterInfo.CustomChains) @@ -278,11 +280,11 @@ func (d *LocalDeployer) doDeploy(chain string, genesisPath string, icmSpec ICMSp // if a chainConfig has been configured var ( chainConfig string - chainConfigFile = filepath.Join(d.app.GetSubnetDir(), chain, constants.ChainConfigFileName) + chainConfigFile = filepath.Join(d.app.GetSubnetDir(), blockchainName, constants.ChainConfigFileName) perNodeChainConfig string - perNodeChainConfigFile = filepath.Join(d.app.GetSubnetDir(), chain, constants.PerNodeChainConfigFileName) + perNodeChainConfigFile = filepath.Join(d.app.GetSubnetDir(), blockchainName, constants.PerNodeChainConfigFileName) subnetConfig string - subnetConfigFile = filepath.Join(d.app.GetSubnetDir(), chain, constants.SubnetConfigFileName) + subnetConfigFile = filepath.Join(d.app.GetSubnetDir(), blockchainName, constants.SubnetConfigFileName) ) if _, err := os.Stat(chainConfigFile); err == nil { // currently the ANR only accepts the file as a path, not its content @@ -307,14 +309,14 @@ func (d *LocalDeployer) doDeploy(chain string, genesisPath string, icmSpec ICMSp // the given VM ID, genesis, and available subnet ID blockchainSpecs := []*rpcpb.BlockchainSpec{ { - VmName: chain, + VmName: blockchainName, Genesis: genesisPath, SubnetId: &subnetIDStr, SubnetSpec: &rpcpb.SubnetSpec{ SubnetConfig: subnetConfig, }, ChainConfig: chainConfig, - BlockchainAlias: chain, + BlockchainAlias: blockchainName, PerNodeChainConfig: perNodeChainConfig, }, } @@ -384,8 +386,8 @@ func (d *LocalDeployer) doDeploy(chain string, genesisPath string, icmSpec ICMSp } else { icmVersion := "" switch { - case icmSpec.Version != "" && icmSpec.Version != "latest": - icmVersion = icmSpec.Version + case icmSpec.ICMVersion != "" && icmSpec.ICMVersion != "latest": + icmVersion = icmSpec.ICMVersion case sc.TeleporterVersion != "": icmVersion = sc.TeleporterVersion default: @@ -412,6 +414,7 @@ func (d *LocalDeployer) doDeploy(chain string, genesisPath string, icmSpec ICMSp cChainKey.PrivKeyHex(), true, true, + false, ) if err != nil { return nil, err @@ -423,35 +426,65 @@ func (d *LocalDeployer) doDeploy(chain string, genesisPath string, icmSpec ICMSp } // deploy current blockchain ux.Logger.PrintToUser("") - subnetID, blockchainID, err := utils.GetChainIDs(network.Endpoint, chain) + subnetID, blockchainID, err := utils.GetChainIDs(network.Endpoint, blockchainName) if err != nil { return nil, err } - teleporterKeyName := sc.TeleporterKey - if teleporterKeyName == "" { - genesisData, err := d.app.LoadRawGenesis(chain) + blockchainKeyName := sc.TeleporterKey + if blockchainKeyName == "" { + genesisData, err := d.app.LoadRawGenesis(blockchainName) if err != nil { return nil, err } - teleporterKeyName, _, _, err = GetSubnetAirdropKeyInfo(d.app, network, chain, genesisData) + blockchainKeyName, _, _, err = GetSubnetAirdropKeyInfo(d.app, network, blockchainName, genesisData) if err != nil { return nil, err } } - blockchainKey, err := key.LoadSoft(network.ID, d.app.GetKeyPath(teleporterKeyName)) + blockchainKey, err := key.LoadSoft(network.ID, d.app.GetKeyPath(blockchainKeyName)) if err != nil { return nil, err } - _, icmMessengerAddress, icmRegistryAddress, err = icmd.Deploy( - chain, - network.BlockchainEndpoint(blockchainID), - blockchainKey.PrivKeyHex(), - true, - true, - ) + genesisData, err := os.ReadFile(genesisPath) + if err != nil { + return nil, err + } + messengerAtGenesis, registryAtGenesis, err := icmgenesis.ICMAtGenesis(genesisData) if err != nil { return nil, err } + switch { + case registryAtGenesis: + ux.Logger.PrintToUser("Teleporter Messenger and Registry already included in %s's Genesis", blockchainName) + icmMessengerAddress = icmgenesis.MessengerContractAddress + icmRegistryAddress = icmgenesis.RegistryContractAddress + case messengerAtGenesis: + ux.Logger.PrintToUser("Teleporter Messenger already included in %s's Genesis", blockchainName) + icmMessengerAddress = icmgenesis.MessengerContractAddress + _, _, icmRegistryAddress, err = icmd.Deploy( + blockchainName, + network.BlockchainEndpoint(blockchainID), + blockchainKey.PrivKeyHex(), + false, + true, + false, + ) + if err != nil { + return nil, err + } + default: + _, icmMessengerAddress, icmRegistryAddress, err = icmd.Deploy( + blockchainName, + network.BlockchainEndpoint(blockchainID), + blockchainKey.PrivKeyHex(), + true, + true, + false, + ) + if err != nil { + return nil, err + } + } if sc.RunRelayer && !icmSpec.SkipRelayerDeploy { if !cchainAlreadyDeployed { if err := teleporter.FundRelayer( @@ -502,7 +535,7 @@ func (d *LocalDeployer) doDeploy(chain string, genesisPath string, icmSpec ICMSp ux.Logger.PrintToUser("") // start relayer if err := teleporter.DeployRelayer( - "latest", + icmSpec.RelayerVersion, d.app.GetAWMRelayerBinDir(), relayerConfigPath, d.app.GetLocalRelayerLogPath(models.Local), diff --git a/pkg/teleporter/genesis/deployed_messenger_bytecode.txt b/pkg/teleporter/genesis/deployed_messenger_bytecode.txt new file mode 100644 index 000000000..aa3ae3c6c --- /dev/null +++ b/pkg/teleporter/genesis/deployed_messenger_bytecode.txt @@ -0,0 +1 @@ +0x608060405234801561001057600080fd5b506004361061014d5760003560e01c8063a8898181116100c3578063df20e8bc1161007c578063df20e8bc1461033b578063e69d606a1461034e578063e6e67bd5146103b6578063ebc3b1ba146103f2578063ecc7042814610415578063fc2d61971461041e57600080fd5b8063a8898181146102b2578063a9a85614146102c5578063b771b3bc146102d8578063c473eef8146102e6578063ccb5f8091461031f578063d127dc9b1461033257600080fd5b8063399b77da11610115578063399b77da1461021957806362448850146102395780638245a1b01461024c578063860a3b061461025f578063892bf4121461027f5780638ac0fd041461029f57600080fd5b80630af5b4ff1461015257806322296c3a1461016d5780632bc8b0bf146101825780632ca40f55146101955780632e27c223146101ee575b600080fd5b61015a610431565b6040519081526020015b60405180910390f35b61018061017b366004612251565b610503565b005b61015a61019036600461226e565b6105f8565b6101e06101a336600461226e565b6005602090815260009182526040918290208054835180850190945260018201546001600160a01b03168452600290910154918301919091529082565b604051610164929190612287565b6102016101fc36600461226e565b610615565b6040516001600160a01b039091168152602001610164565b61015a61022736600461226e565b60009081526005602052604090205490565b61015a6102473660046122ae565b61069e565b61018061025a366004612301565b6106fc565b61015a61026d36600461226e565b60066020526000908152604090205481565b61029261028d366004612335565b6108a7565b6040516101649190612357565b6101806102ad366004612377565b6108da565b61015a6102c03660046123af565b610b19565b61015a6102d3366004612426565b610b5c565b6102016005600160991b0181565b61015a6102f43660046124be565b6001600160a01b03918216600090815260096020908152604080832093909416825291909152205490565b61018061032d3660046124f7565b610e03565b61015a60025481565b61015a61034936600461226e565b61123d565b61039761035c36600461226e565b600090815260056020908152604091829020825180840190935260018101546001600160a01b03168084526002909101549290910182905291565b604080516001600160a01b039093168352602083019190915201610164565b6103dd6103c436600461226e565b6004602052600090815260409020805460019091015482565b60408051928352602083019190915201610164565b61040561040036600461226e565b611286565b6040519015158152602001610164565b61015a60035481565b61018061042c36600461251e565b61129c565b600254600090806104fe576005600160991b016001600160a01b0316634213cf786040518163ffffffff1660e01b8152600401602060405180830381865afa158015610481573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104a59190612564565b9050806104cd5760405162461bcd60e51b81526004016104c49061257d565b60405180910390fd5b600281905560405181907f1eac640109dc937d2a9f42735a05f794b39a5e3759d681951d671aabbce4b10490600090a25b919050565b3360009081526009602090815260408083206001600160a01b0385168452909152902054806105855760405162461bcd60e51b815260206004820152602860248201527f54656c65706f727465724d657373656e6765723a206e6f2072657761726420746044820152676f2072656465656d60c01b60648201526084016104c4565b3360008181526009602090815260408083206001600160a01b03871680855290835281842093909355518481529192917f3294c84e5b0f29d9803655319087207bc94f4db29f7927846944822773780b88910160405180910390a36105f46001600160a01b03831633836114f7565b5050565b600081815260046020526040812061060f9061155f565b92915050565b6000818152600760205260408120546106825760405162461bcd60e51b815260206004820152602960248201527f54656c65706f727465724d657373656e6765723a206d657373616765206e6f74604482015268081c9958d95a5d995960ba1b60648201526084016104c4565b506000908152600860205260409020546001600160a01b031690565b60006001600054146106c25760405162461bcd60e51b81526004016104c4906125c4565b60026000556106f16106d383612804565b833560009081526004602052604090206106ec90611572565b61167c565b600160005592915050565b60016000541461071e5760405162461bcd60e51b81526004016104c4906125c4565b6002600081815590546107379060408401358435610b19565b6000818152600560209081526040918290208251808401845281548152835180850190945260018201546001600160a01b03168452600290910154838301529081019190915280519192509061079f5760405162461bcd60e51b81526004016104c4906128a7565b6000836040516020016107b29190612b42565b60408051601f19818403018152919052825181516020830120919250146107eb5760405162461bcd60e51b81526004016104c490612b55565b8360400135837f2a211ad4a59ab9d003852404f9c57c690704ee755f3c79d2c2812ad32da99df8868560200151604051610826929190612b9e565b60405180910390a360405163ee5b48eb60e01b81526005600160991b019063ee5b48eb90610858908490600401612c23565b6020604051808303816000875af1158015610877573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061089b9190612564565b50506001600055505050565b604080518082019091526000808252602082015260008381526004602052604090206108d390836118bc565b9392505050565b6001600054146108fc5760405162461bcd60e51b81526004016104c4906125c4565b600260005560018054146109225760405162461bcd60e51b81526004016104c490612c36565b60026001558061098c5760405162461bcd60e51b815260206004820152602f60248201527f54656c65706f727465724d657373656e6765723a207a65726f2061646469746960448201526e1bdb985b0819995948185b5bdd5b9d608a1b60648201526084016104c4565b6001600160a01b0382166109b25760405162461bcd60e51b81526004016104c490612c7b565b6000838152600560205260409020546109dd5760405162461bcd60e51b81526004016104c4906128a7565b6000838152600560205260409020600101546001600160a01b03838116911614610a6f5760405162461bcd60e51b815260206004820152603760248201527f54656c65706f727465724d657373656e6765723a20696e76616c69642066656560448201527f20617373657420636f6e7472616374206164647265737300000000000000000060648201526084016104c4565b6000610a7b8383611981565b600085815260056020526040812060020180549293508392909190610aa1908490612ce5565b909155505060008481526005602052604090819020905185917fc1bfd1f1208927dfbd414041dcb5256e6c9ad90dd61aec3249facbd34ff7b3e191610b03916001019081546001600160a01b0316815260019190910154602082015260400190565b60405180910390a2505060018080556000555050565b60408051306020820152908101849052606081018390526080810182905260009060a0016040516020818303038152906040528051906020012090509392505050565b6000600160005414610b805760405162461bcd60e51b81526004016104c4906125c4565b60026000818155905490866001600160401b03811115610ba257610ba2612607565b604051908082528060200260200182016040528015610be757816020015b6040805180820190915260008082526020820152815260200190600190039081610bc05790505b5090508660005b81811015610d6c5760008a8a83818110610c0a57610c0a612cf8565b90506020020135905060006007600083815260200190815260200160002054905080600003610c8a5760405162461bcd60e51b815260206004820152602660248201527f54656c65706f727465724d657373656e6765723a2072656365697074206e6f7460448201526508199bdd5b9960d21b60648201526084016104c4565b610c958d8783610b19565b8214610d095760405162461bcd60e51b815260206004820152603a60248201527f54656c65706f727465724d657373656e6765723a206d6573736167652049442060448201527f6e6f742066726f6d20736f7572636520626c6f636b636861696e00000000000060648201526084016104c4565b6000828152600860209081526040918290205482518084019093528383526001600160a01b03169082018190528651909190879086908110610d4d57610d4d612cf8565b602002602001018190525050505080610d6590612d0e565b9050610bee565b506040805160c0810182528b815260006020820152610df0918101610d96368b90038b018b612d27565b8152602001600081526020018888808060200260200160405190810160405280939291908181526020018383602002808284376000920182905250938552505060408051928352602080840190915290920152508361167c565b60016000559a9950505050505050505050565b6001805414610e245760405162461bcd60e51b81526004016104c490612c36565b60026001556040516306f8253560e41b815263ffffffff8316600482015260009081906005600160991b0190636f82535090602401600060405180830381865afa158015610e76573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610e9e9190810190612da3565b9150915080610f015760405162461bcd60e51b815260206004820152602960248201527f54656c65706f727465724d657373656e6765723a20696e76616c69642077617260448201526870206d65737361676560b81b60648201526084016104c4565b60208201516001600160a01b03163014610f785760405162461bcd60e51b815260206004820152603260248201527f54656c65706f727465724d657373656e6765723a20696e76616c6964206f726960448201527167696e2073656e646572206164647265737360701b60648201526084016104c4565b60008260400151806020019051810190610f929190612f40565b90506000610f9e610431565b90508082604001511461100d5760405162461bcd60e51b815260206004820152603160248201527f54656c65706f727465724d657373656e6765723a20696e76616c6964206465736044820152701d1a5b985d1a5bdb8818da185a5b881251607a1b60648201526084016104c4565b8351825160009161101f918490610b19565b600081815260076020526040902054909150156110945760405162461bcd60e51b815260206004820152602d60248201527f54656c65706f727465724d657373656e6765723a206d65737361676520616c7260448201526c1958591e481c9958d95a5d9959609a1b60648201526084016104c4565b6110a2338460a00151611ae9565b6111005760405162461bcd60e51b815260206004820152602960248201527f54656c65706f727465724d657373656e6765723a20756e617574686f72697a6560448201526832103932b630bcb2b960b91b60648201526084016104c4565b61110e818460000151611b61565b6001600160a01b0386161561114557600081815260086020526040902080546001600160a01b0319166001600160a01b0388161790555b60c08301515160005b81811015611192576111828488600001518760c00151848151811061117557611175612cf8565b6020026020010151611bd3565b61118b81612d0e565b905061114e565b50604080518082018252855181526001600160a01b038916602080830191909152885160009081526004909152919091206111cc91611cfb565b336001600160a01b03168660000151837f292ee90bbaf70b5d4936025e09d56ba08f3e421156b6a568cf3c2840d9343e348a8860405161120d929190613150565b60405180910390a460e0840151511561122f5761122f82876000015186611d57565b505060018055505050505050565b600254600090806112605760405162461bcd60e51b81526004016104c49061257d565b600060035460016112719190612ce5565b905061127e828583610b19565b949350505050565b600081815260076020526040812054151561060f565b60018054146112bd5760405162461bcd60e51b81526004016104c490612c36565b60026001819055546000906112d59084908435610b19565b600081815260066020526040902054909150806113045760405162461bcd60e51b81526004016104c4906128a7565b80836040516020016113169190612b42565b60405160208183030381529060405280519060200120146113495760405162461bcd60e51b81526004016104c490612b55565b600061135b6080850160608601612251565b6001600160a01b03163b116113cf5760405162461bcd60e51b815260206004820152603460248201527f54656c65706f727465724d657373656e6765723a2064657374696e6174696f6e604482015273206164647265737320686173206e6f20636f646560601b60648201526084016104c4565b604051849083907f34795cc6b122b9a0ae684946319f1e14a577b4e8f9b3dda9ac94c21a54d3188c90600090a360008281526006602090815260408083208390558691611420918701908701612251565b61142d60e0870187613174565b60405160240161144094939291906131ba565b60408051601f198184030181529190526020810180516001600160e01b031663643477d560e11b179052905060006114886114816080870160608801612251565b5a84611e8a565b9050806114eb5760405162461bcd60e51b815260206004820152602b60248201527f54656c65706f727465724d657373656e6765723a20726574727920657865637560448201526a1d1a5bdb8819985a5b195960aa1b60648201526084016104c4565b50506001805550505050565b6040516001600160a01b03831660248201526044810182905261155a90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611ea4565b505050565b8054600182015460009161060f916131e5565b6060600061158960056115848561155f565b611f76565b9050806000036115d85760408051600080825260208201909252906115d0565b60408051808201909152600080825260208201528152602001906001900390816115a95790505b509392505050565b6000816001600160401b038111156115f2576115f2612607565b60405190808252806020026020018201604052801561163757816020015b60408051808201909152600080825260208201528152602001906001900390816116105790505b50905060005b828110156115d05761164e85611f8c565b82828151811061166057611660612cf8565b60200260200101819052508061167590612d0e565b905061163d565b600080611687610431565b9050600060036000815461169a90612d0e565b919050819055905060006116b383876000015184610b19565b90506000604051806101000160405280848152602001336001600160a01b031681526020018860000151815260200188602001516001600160a01b0316815260200188606001518152602001886080015181526020018781526020018860a00151815250905060008160405160200161172c91906131f8565b60405160208183030381529060405290506000808960400151602001511115611794576040890151516001600160a01b031661177a5760405162461bcd60e51b81526004016104c490612c7b565b604089015180516020909101516117919190611981565b90505b6040805180820182528a820151516001600160a01b039081168252602080830185905283518085018552865187830120815280820184815260008a815260058452869020915182555180516001830180546001600160a01b03191691909516179093559101516002909101558a51915190919086907f2a211ad4a59ab9d003852404f9c57c690704ee755f3c79d2c2812ad32da99df890611838908890869061320b565b60405180910390a360405163ee5b48eb60e01b81526005600160991b019063ee5b48eb9061186a908690600401612c23565b6020604051808303816000875af1158015611889573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118ad9190612564565b50939998505050505050505050565b60408051808201909152600080825260208201526118d98361155f565b82106119315760405162461bcd60e51b815260206004820152602160248201527f5265636569707451756575653a20696e646578206f7574206f6620626f756e646044820152607360f81b60648201526084016104c4565b8260020160008385600001546119479190612ce5565b81526020808201929092526040908101600020815180830190925280548252600101546001600160a01b0316918101919091529392505050565b6040516370a0823160e01b815230600482015260009081906001600160a01b038516906370a0823190602401602060405180830381865afa1580156119ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119ee9190612564565b9050611a056001600160a01b038516333086612058565b6040516370a0823160e01b81523060048201526000906001600160a01b038616906370a0823190602401602060405180830381865afa158015611a4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a709190612564565b9050818111611ad65760405162461bcd60e51b815260206004820152602c60248201527f5361666545524332305472616e7366657246726f6d3a2062616c616e6365206e60448201526b1bdd081a5b98dc99585cd95960a21b60648201526084016104c4565b611ae082826131e5565b95945050505050565b60008151600003611afc5750600161060f565b815160005b81811015611b5657846001600160a01b0316848281518110611b2557611b25612cf8565b60200260200101516001600160a01b031603611b465760019250505061060f565b611b4f81612d0e565b9050611b01565b506000949350505050565b80600003611bc15760405162461bcd60e51b815260206004820152602760248201527f54656c65706f727465724d657373656e6765723a207a65726f206d657373616760448201526665206e6f6e636560c81b60648201526084016104c4565b60009182526007602052604090912055565b6000611be484848460000151610b19565b6000818152600560209081526040918290208251808401845281548152835180850190945260018201546001600160a01b031684526002909101548383015290810191909152805191925090611c3b575050505050565b60008281526005602090815260408083208381556001810180546001600160a01b03191690556002018390558382018051830151878401516001600160a01b0390811686526009855283862092515116855292528220805491929091611ca2908490612ce5565b9250508190555082602001516001600160a01b031684837fd13a7935f29af029349bed0a2097455b91fd06190a30478c575db3f31e00bf578460200151604051611cec919061321e565b60405180910390a45050505050565b6001820180548291600285019160009182611d1583612d0e565b90915550815260208082019290925260400160002082518155910151600190910180546001600160a01b0319166001600160a01b039092169190911790555050565b80608001515a1015611db95760405162461bcd60e51b815260206004820152602560248201527f54656c65706f727465724d657373656e6765723a20696e73756666696369656e604482015264742067617360d81b60648201526084016104c4565b80606001516001600160a01b03163b600003611dda5761155a838383612096565b602081015160e0820151604051600092611df892869260240161323e565b60408051601f198184030181529190526020810180516001600160e01b031663643477d560e11b17905260608301516080840151919250600091611e3d919084611e8a565b905080611e5657611e4f858585612096565b5050505050565b604051849086907f34795cc6b122b9a0ae684946319f1e14a577b4e8f9b3dda9ac94c21a54d3188c90600090a35050505050565b60008060008084516020860160008989f195945050505050565b6000611ef9826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661210b9092919063ffffffff16565b80519091501561155a5780806020019051810190611f179190613268565b61155a5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016104c4565b6000818310611f8557816108d3565b5090919050565b604080518082019091526000808252602082015281546001830154819003611ff65760405162461bcd60e51b815260206004820152601960248201527f5265636569707451756575653a20656d7074792071756575650000000000000060448201526064016104c4565b60008181526002840160208181526040808420815180830190925280548252600180820180546001600160a01b03811685870152888852959094529490556001600160a01b031990921690559061204e908390612ce5565b9093555090919050565b6040516001600160a01b03808516602483015283166044820152606481018290526120909085906323b872dd60e01b90608401611523565b50505050565b806040516020016120a791906131f8565b60408051601f1981840301815282825280516020918201206000878152600690925291902055829084907f4619adc1017b82e02eaefac01a43d50d6d8de4460774bc370c3ff0210d40c985906120fe9085906131f8565b60405180910390a3505050565b606061127e848460008585600080866001600160a01b031685876040516121329190613283565b60006040518083038185875af1925050503d806000811461216f576040519150601f19603f3d011682016040523d82523d6000602084013e612174565b606091505b509150915061218587838387612190565b979650505050505050565b606083156121ff5782516000036121f8576001600160a01b0385163b6121f85760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016104c4565b508161127e565b61127e83838151156122145781518083602001fd5b8060405162461bcd60e51b81526004016104c49190612c23565b6001600160a01b038116811461224357600080fd5b50565b80356104fe8161222e565b60006020828403121561226357600080fd5b81356108d38161222e565b60006020828403121561228057600080fd5b5035919050565b828152606081016108d3602083018480516001600160a01b03168252602090810151910152565b6000602082840312156122c057600080fd5b81356001600160401b038111156122d657600080fd5b820160e081850312156108d357600080fd5b600061010082840312156122fb57600080fd5b50919050565b60006020828403121561231357600080fd5b81356001600160401b0381111561232957600080fd5b61127e848285016122e8565b6000806040838503121561234857600080fd5b50508035926020909101359150565b815181526020808301516001600160a01b0316908201526040810161060f565b60008060006060848603121561238c57600080fd5b83359250602084013561239e8161222e565b929592945050506040919091013590565b6000806000606084860312156123c457600080fd5b505081359360208301359350604090920135919050565b60008083601f8401126123ed57600080fd5b5081356001600160401b0381111561240457600080fd5b6020830191508360208260051b850101111561241f57600080fd5b9250929050565b60008060008060008086880360a081121561244057600080fd5b8735965060208801356001600160401b038082111561245e57600080fd5b61246a8b838c016123db565b90985096508691506040603f198401121561248457600080fd5b60408a01955060808a013592508083111561249e57600080fd5b50506124ac89828a016123db565b979a9699509497509295939492505050565b600080604083850312156124d157600080fd5b82356124dc8161222e565b915060208301356124ec8161222e565b809150509250929050565b6000806040838503121561250a57600080fd5b823563ffffffff811681146124dc57600080fd5b6000806040838503121561253157600080fd5b8235915060208301356001600160401b0381111561254e57600080fd5b61255a858286016122e8565b9150509250929050565b60006020828403121561257657600080fd5b5051919050565b60208082526027908201527f54656c65706f727465724d657373656e6765723a207a65726f20626c6f636b636040820152661a185a5b88125160ca1b606082015260800190565b60208082526023908201527f5265656e7472616e63794775617264733a2073656e646572207265656e7472616040820152626e637960e81b606082015260800190565b634e487b7160e01b600052604160045260246000fd5b604080519081016001600160401b038111828210171561263f5761263f612607565b60405290565b60405160c081016001600160401b038111828210171561263f5761263f612607565b60405161010081016001600160401b038111828210171561263f5761263f612607565b604051601f8201601f191681016001600160401b03811182821017156126b2576126b2612607565b604052919050565b6000604082840312156126cc57600080fd5b6126d461261d565b905081356126e18161222e565b808252506020820135602082015292915050565b60006001600160401b0382111561270e5761270e612607565b5060051b60200190565b600082601f83011261272957600080fd5b8135602061273e612739836126f5565b61268a565b82815260059290921b8401810191818101908684111561275d57600080fd5b8286015b848110156127815780356127748161222e565b8352918301918301612761565b509695505050505050565b60006001600160401b038211156127a5576127a5612607565b50601f01601f191660200190565b600082601f8301126127c457600080fd5b81356127d26127398261278c565b8181528460208386010111156127e757600080fd5b816020850160208301376000918101602001919091529392505050565b600060e0823603121561281657600080fd5b61281e612645565b8235815261282e60208401612246565b602082015261284036604085016126ba565b60408201526080830135606082015260a08301356001600160401b038082111561286957600080fd5b61287536838701612718565b608084015260c085013591508082111561288e57600080fd5b5061289b368286016127b3565b60a08301525092915050565b60208082526026908201527f54656c65706f727465724d657373656e6765723a206d657373616765206e6f7460408201526508199bdd5b9960d21b606082015260800190565b6000808335601e1984360301811261290457600080fd5b83016020810192503590506001600160401b0381111561292357600080fd5b8060051b360382131561241f57600080fd5b8183526000602080850194508260005b858110156129735781356129588161222e565b6001600160a01b031687529582019590820190600101612945565b509495945050505050565b6000808335601e1984360301811261299557600080fd5b83016020810192503590506001600160401b038111156129b457600080fd5b8060061b360382131561241f57600080fd5b8183526000602080850194508260005b858110156129735781358752828201356129ef8161222e565b6001600160a01b03168784015260409687019691909101906001016129d6565b6000808335601e19843603018112612a2657600080fd5b83016020810192503590506001600160401b03811115612a4557600080fd5b80360382131561241f57600080fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6000610100823584526020830135612a948161222e565b6001600160a01b0316602085015260408381013590850152612ab860608401612246565b6001600160a01b0316606085015260808381013590850152612add60a08401846128ed565b8260a0870152612af08387018284612935565b92505050612b0160c084018461297e565b85830360c0870152612b148382846129c6565b92505050612b2560e0840184612a0f565b85830360e0870152612b38838284612a54565b9695505050505050565b6020815260006108d36020830184612a7d565b60208082526029908201527f54656c65706f727465724d657373656e6765723a20696e76616c6964206d65736040820152680e6c2ceca40d0c2e6d60bb1b606082015260800190565b606081526000612bb16060830185612a7d565b90506108d3602083018480516001600160a01b03168252602090810151910152565b60005b83811015612bee578181015183820152602001612bd6565b50506000910152565b60008151808452612c0f816020860160208601612bd3565b601f01601f19169290920160200192915050565b6020815260006108d36020830184612bf7565b60208082526025908201527f5265656e7472616e63794775617264733a207265636569766572207265656e7460408201526472616e637960d81b606082015260800190565b60208082526034908201527f54656c65706f727465724d657373656e6765723a207a65726f2066656520617360408201527373657420636f6e7472616374206164647265737360601b606082015260800190565b634e487b7160e01b600052601160045260246000fd5b8082018082111561060f5761060f612ccf565b634e487b7160e01b600052603260045260246000fd5b600060018201612d2057612d20612ccf565b5060010190565b600060408284031215612d3957600080fd5b6108d383836126ba565b80516104fe8161222e565b600082601f830112612d5f57600080fd5b8151612d6d6127398261278c565b818152846020838601011115612d8257600080fd5b61127e826020830160208701612bd3565b805180151581146104fe57600080fd5b60008060408385031215612db657600080fd5b82516001600160401b0380821115612dcd57600080fd5b9084019060608287031215612de157600080fd5b604051606081018181108382111715612dfc57612dfc612607565b604052825181526020830151612e118161222e565b6020820152604083015182811115612e2857600080fd5b612e3488828601612d4e565b6040830152509350612e4b91505060208401612d93565b90509250929050565b600082601f830112612e6557600080fd5b81516020612e75612739836126f5565b82815260059290921b84018101918181019086841115612e9457600080fd5b8286015b84811015612781578051612eab8161222e565b8352918301918301612e98565b600082601f830112612ec957600080fd5b81516020612ed9612739836126f5565b82815260069290921b84018101918181019086841115612ef857600080fd5b8286015b848110156127815760408189031215612f155760008081fd5b612f1d61261d565b8151815284820151612f2e8161222e565b81860152835291830191604001612efc565b600060208284031215612f5257600080fd5b81516001600160401b0380821115612f6957600080fd5b908301906101008286031215612f7e57600080fd5b612f86612667565b82518152612f9660208401612d43565b602082015260408301516040820152612fb160608401612d43565b60608201526080830151608082015260a083015182811115612fd257600080fd5b612fde87828601612e54565b60a08301525060c083015182811115612ff657600080fd5b61300287828601612eb8565b60c08301525060e08301518281111561301a57600080fd5b61302687828601612d4e565b60e08301525095945050505050565b600081518084526020808501945080840160005b838110156129735781516001600160a01b031687529582019590820190600101613049565b600081518084526020808501945080840160005b83811015612973576130a8878351805182526020908101516001600160a01b0316910152565b6040969096019590820190600101613082565b60006101008251845260018060a01b0360208401511660208501526040830151604085015260608301516130fa60608601826001600160a01b03169052565b506080830151608085015260a08301518160a086015261311c82860182613035565b91505060c083015184820360c0860152613136828261306e565b91505060e083015184820360e0860152611ae08282612bf7565b6001600160a01b038316815260406020820181905260009061127e908301846130bb565b6000808335601e1984360301811261318b57600080fd5b8301803591506001600160401b038211156131a557600080fd5b60200191503681900382131561241f57600080fd5b8481526001600160a01b0384166020820152606060408201819052600090612b389083018486612a54565b8181038181111561060f5761060f612ccf565b6020815260006108d360208301846130bb565b606081526000612bb160608301856130bb565b81516001600160a01b03168152602080830151908201526040810161060f565b8381526001600160a01b0383166020820152606060408201819052600090611ae090830184612bf7565b60006020828403121561327a57600080fd5b6108d382612d93565b60008251613295818460208701612bd3565b919091019291505056fea2646970667358221220586881dd1413fe17197100ceb55646481dae802ef65d37df603c3915f51a4b6364736f6c63430008120033 diff --git a/pkg/teleporter/genesis/deployed_registry_bytecode.txt b/pkg/teleporter/genesis/deployed_registry_bytecode.txt new file mode 100644 index 000000000..7b1a0502b --- /dev/null +++ b/pkg/teleporter/genesis/deployed_registry_bytecode.txt @@ -0,0 +1 @@ +0x608060405234801561001057600080fd5b506004361061009e5760003560e01c8063ac473ac311610066578063ac473ac314610124578063b771b3bc1461012d578063c07f47d41461013b578063d127dc9b14610144578063d820e64f1461016b57600080fd5b80630731775d146100a3578063215abce9146100c857806341f34ed9146100db57806346f9ef49146100f05780634c1f08ce14610103575b600080fd5b6100ab600081565b6040516001600160a01b0390911681526020015b60405180910390f35b6100ab6100d63660046107c5565b610173565b6100ee6100e93660046107de565b610184565b005b6100ab6100fe3660046107c5565b6103f9565b610116610111366004610823565b6104be565b6040519081526020016100bf565b6101166101f481565b6100ab6005600160991b0181565b61011660005481565b6101167f000000000000000000000000000000000000000000000000000000000000000081565b6100ab610566565b600061017e826103f9565b92915050565b6040516306f8253560e41b815263ffffffff8216600482015260009081906005600160991b0190636f82535090602401600060405180830381865afa1580156101d1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526101f991908101906108c5565b91509150806102605760405162461bcd60e51b815260206004820152602860248201527f54656c65706f7274657252656769737472793a20696e76616c69642077617270604482015267206d65737361676560c01b60648201526084015b60405180910390fd5b81517f0000000000000000000000000000000000000000000000000000000000000000146102e45760405162461bcd60e51b815260206004820152602b60248201527f54656c65706f7274657252656769737472793a20696e76616c696420736f757260448201526a18d94818da185a5b88125160aa1b6064820152608401610257565b60208201516001600160a01b0316156103595760405162461bcd60e51b815260206004820152603160248201527f54656c65706f7274657252656769737472793a20696e76616c6964206f726967604482015270696e2073656e646572206164647265737360781b6064820152608401610257565b600080836040015180602001905181019061037491906109cd565b90925090506001600160a01b03811630146103e95760405162461bcd60e51b815260206004820152602f60248201527f54656c65706f7274657252656769737472793a20696e76616c6964206465737460448201526e696e6174696f6e206164647265737360881b6064820152608401610257565b6103f282610578565b5050505050565b60008160000361044b5760405162461bcd60e51b815260206004820181905260248201527f54656c65706f7274657252656769737472793a207a65726f2076657273696f6e6044820152606401610257565b6000828152600160205260409020546001600160a01b03168061017e5760405162461bcd60e51b815260206004820152602560248201527f54656c65706f7274657252656769737472793a2076657273696f6e206e6f7420604482015264199bdd5b9960da1b6064820152608401610257565b60006001600160a01b0382166104e65760405162461bcd60e51b815260040161025790610a49565b6001600160a01b0382166000908152600260205260408120549081900361017e5760405162461bcd60e51b815260206004820152602e60248201527f54656c65706f7274657252656769737472793a2070726f746f636f6c2061646460448201526d1c995cdcc81b9bdd08199bdd5b9960921b6064820152608401610257565b60006105736000546103f9565b905090565b80516000036105c95760405162461bcd60e51b815260206004820181905260248201527f54656c65706f7274657252656769737472793a207a65726f2076657273696f6e6044820152606401610257565b80516000908152600160205260409020546001600160a01b0316156106435760405162461bcd60e51b815260206004820152602a60248201527f54656c65706f7274657252656769737472793a2076657273696f6e20616c72656044820152696164792065786973747360b01b6064820152608401610257565b60208101516001600160a01b031661066d5760405162461bcd60e51b815260040161025790610a49565b60005461067c6101f482610a92565b825111156106e35760405162461bcd60e51b815260206004820152602e60248201527f54656c65706f7274657252656769737472793a2076657273696f6e20696e637260448201526d0cadacadce840e8dede40d0d2ced60931b6064820152608401610257565b602082810180518451600090815260018452604080822080546001600160a01b0319166001600160a01b039485161790559251909116815260029092529020548251111561074c5781516020808401516001600160a01b03166000908152600290915260409020555b602082015182516040516001600160a01b03909216917fa5eed93d951a9603d5f7c0a57de79a299dd3dbd5e51429be209d8053a42ab43a90600090a381518110156107c1578151600081815560405183917f30623e953733f6474dabdfbef1103ce15ab73cdc77c6dfad0f9874d167e8a9b091a35b5050565b6000602082840312156107d757600080fd5b5035919050565b6000602082840312156107f057600080fd5b813563ffffffff8116811461080457600080fd5b9392505050565b6001600160a01b038116811461082057600080fd5b50565b60006020828403121561083557600080fd5b81356108048161080b565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff8111828210171561087957610879610840565b60405290565b604051601f8201601f1916810167ffffffffffffffff811182821017156108a8576108a8610840565b604052919050565b805180151581146108c057600080fd5b919050565b600080604083850312156108d857600080fd5b825167ffffffffffffffff808211156108f057600080fd5b908401906060828703121561090457600080fd5b61090c610856565b8251815260208084015161091f8161080b565b8282015260408401518381111561093557600080fd5b80850194505087601f85011261094a57600080fd5b83518381111561095c5761095c610840565b61096e601f8201601f1916830161087f565b9350808452888282870101111561098457600080fd5b60005b818110156109a2578581018301518582018401528201610987565b506000828286010152508260408301528195506109c08188016108b0565b9450505050509250929050565b60008082840360608112156109e157600080fd5b60408112156109ef57600080fd5b506040516040810181811067ffffffffffffffff82111715610a1357610a13610840565b604052835181526020840151610a288161080b565b60208201526040840151909250610a3e8161080b565b809150509250929050565b60208082526029908201527f54656c65706f7274657252656769737472793a207a65726f2070726f746f636f6040820152686c206164647265737360b81b606082015260800190565b8082018082111561017e57634e487b7160e01b600052601160045260246000fdfea2646970667358221220147aa4bf673206f63959dca6bf01bb7ab5e23e6ff9c146a03a27caed9a8296ef64736f6c63430008120033 diff --git a/pkg/teleporter/genesis/genesis.go b/pkg/teleporter/genesis/genesis.go new file mode 100644 index 000000000..2afbc67f9 --- /dev/null +++ b/pkg/teleporter/genesis/genesis.go @@ -0,0 +1,129 @@ +// Copyright (C) 2022, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. +package genesis + +import ( + _ "embed" + "encoding/hex" + "fmt" + "math/big" + "strings" + + "github.com/ava-labs/avalanche-cli/pkg/contract" + "github.com/ava-labs/avalanche-cli/pkg/utils" + "github.com/ava-labs/subnet-evm/core" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" +) + +const ( + messengerVersion = "0x1" + MessengerContractAddress = "0x253b2784c75e510dD0fF1da844684a1aC0aa5fcf" + RegistryContractAddress = "0xF86Cb19Ad8405AEFa7d09C778215D2Cb6eBfB228" + MessengerDeployerAddress = "0x618FEdD9A45a8C456812ecAAE70C671c6249DfaC" +) + +//go:embed deployed_messenger_bytecode.txt +var deployedMessengerBytecode []byte + +//go:embed deployed_registry_bytecode.txt +var deployedRegistryBytecode []byte + +func setSimpleStorageValue( + storage map[common.Hash]common.Hash, + slot string, + value string, +) { + storage[common.HexToHash(slot)] = common.HexToHash(value) +} + +func hexFill32(s string) string { + return fmt.Sprintf("%064s", utils.TrimHexa(s)) +} + +func setMappingStorageValue( + storage map[common.Hash]common.Hash, + slot string, + key string, + value string, +) error { + slot = hexFill32(slot) + key = hexFill32(key) + storageKey := key + slot + storageKeyBytes, err := hex.DecodeString(storageKey) + if err != nil { + return err + } + storage[crypto.Keccak256Hash(storageKeyBytes)] = common.HexToHash(value) + return nil +} + +func AddICMMessengerContractToAllocations( + allocs core.GenesisAlloc, +) { + const ( + blockchainIDSlot = "0x0" + messageNonceSlot = "0x1" + ) + storage := map[common.Hash]common.Hash{} + setSimpleStorageValue(storage, blockchainIDSlot, "0x1") + setSimpleStorageValue(storage, messageNonceSlot, "0x1") + deployedMessengerBytes := common.FromHex(strings.TrimSpace(string(deployedMessengerBytecode))) + allocs[common.HexToAddress(MessengerContractAddress)] = core.GenesisAccount{ + Balance: big.NewInt(0), + Code: deployedMessengerBytes, + Storage: storage, + Nonce: 1, + } + allocs[common.HexToAddress(MessengerDeployerAddress)] = core.GenesisAccount{ + Balance: big.NewInt(0), + Nonce: 1, + } +} + +func AddICMRegistryContractToAllocations( + allocs core.GenesisAlloc, +) error { + const ( + latestVersionSlot = "0x0" + versionToAddressSlot = "0x1" + addressToVersionSlot = "0x2" + ) + storage := map[common.Hash]common.Hash{} + setSimpleStorageValue(storage, latestVersionSlot, messengerVersion) + if err := setMappingStorageValue(storage, versionToAddressSlot, messengerVersion, MessengerContractAddress); err != nil { + return err + } + if err := setMappingStorageValue(storage, addressToVersionSlot, MessengerContractAddress, messengerVersion); err != nil { + return err + } + deployedRegistryBytes := common.FromHex(strings.TrimSpace(string(deployedRegistryBytecode))) + allocs[common.HexToAddress(RegistryContractAddress)] = core.GenesisAccount{ + Balance: big.NewInt(0), + Code: deployedRegistryBytes, + Storage: storage, + Nonce: 1, + } + return nil +} + +// check if [genesisData] has +// smart contracts (len(alloc.Code)>0) allocated for +// ICM Messenger and ICM registry, +// based on their expected addresses [MessengerContractAddress] and +// [RegistryContractAddress] +// to be used by local blockchain deploy to determine if a teleporter deploy +// or a registry deploy is needed +func ICMAtGenesis( + genesisData []byte, +) (bool, bool, error) { + messengerAtGenesis, err := contract.ContractAddressIsInGenesisData(genesisData, common.HexToAddress(MessengerContractAddress)) + if err != nil { + return false, false, err + } + registryAtGenesis, err := contract.ContractAddressIsInGenesisData(genesisData, common.HexToAddress(RegistryContractAddress)) + if err != nil { + return false, false, err + } + return messengerAtGenesis, registryAtGenesis, nil +} diff --git a/pkg/teleporter/teleporter.go b/pkg/teleporter/teleporter.go index 05f5ab288..c4d73481b 100644 --- a/pkg/teleporter/teleporter.go +++ b/pkg/teleporter/teleporter.go @@ -240,6 +240,7 @@ func (t *Deployer) Deploy( privateKey string, deployMessenger bool, deployRegistry bool, + forceRegistryDeploy bool, ) (bool, string, string, error) { var ( messengerAddress string @@ -255,7 +256,7 @@ func (t *Deployer) Deploy( ) } if err == nil && deployRegistry { - if !deployMessenger || !alreadyDeployed { + if !deployMessenger || !alreadyDeployed || forceRegistryDeploy { registryAddress, err = t.DeployRegistry(subnetName, rpcURL, privateKey) } } @@ -404,24 +405,23 @@ func DeployAndFundRelayer( privKeyStr, true, true, + true, ) if err != nil { return false, "", "", err } - if !alreadyDeployed { - // get relayer address - relayerAddress, _, err := GetRelayerKeyInfo(app.GetKeyPath(constants.AWMRelayerKeyName)) - if err != nil { - return false, "", "", err - } - // fund relayer - if err := FundRelayer( - endpoint, - privKeyStr, - relayerAddress, - ); err != nil { - return false, "", "", err - } + // get relayer address + relayerAddress, _, err := GetRelayerKeyInfo(app.GetKeyPath(constants.AWMRelayerKeyName)) + if err != nil { + return false, "", "", err + } + // fund relayer + if err := FundRelayer( + endpoint, + privKeyStr, + relayerAddress, + ); err != nil { + return false, "", "", err } return alreadyDeployed, messengerAddress, registryAddress, err } diff --git a/pkg/utils/strings.go b/pkg/utils/strings.go index a6ff8cb34..ad78d1377 100644 --- a/pkg/utils/strings.go +++ b/pkg/utils/strings.go @@ -71,3 +71,8 @@ func FormatAmount(amount *big.Int, decimals uint8) string { val := new(big.Float).Quo(amountFloat, divisor) return fmt.Sprintf("%.*f", decimals, val) } + +// Removes the leading 0x/0X part of a hexadecimal string representation +func TrimHexa(s string) string { + return strings.TrimPrefix(strings.TrimPrefix(s, "0x"), "0X") +} diff --git a/pkg/vm/create_evm.go b/pkg/vm/create_evm.go index eb947a38e..5bddffefb 100644 --- a/pkg/vm/create_evm.go +++ b/pkg/vm/create_evm.go @@ -14,6 +14,7 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/binutils" "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" blockchainSDK "github.com/ava-labs/avalanche-cli/sdk/blockchain" "github.com/ava-labs/subnet-evm/core" @@ -75,6 +76,7 @@ func CreateEVMGenesis( blockchainName string, params SubnetEVMGenesisParams, teleporterInfo *teleporter.Info, + addICMRegistryToGenesis bool, ) ([]byte, error) { ux.Logger.PrintToUser("creating genesis for blockchain %s", blockchainName) @@ -103,6 +105,13 @@ func CreateEVMGenesis( params.initialTokenAllocation[common.HexToAddress(teleporterInfo.FundedAddress)] = core.GenesisAccount{ Balance: balance, } + icmgenesis.AddICMMessengerContractToAllocations(params.initialTokenAllocation) + if addICMRegistryToGenesis { + // experimental + if err := icmgenesis.AddICMRegistryContractToAllocations(params.initialTokenAllocation); err != nil { + return nil, err + } + } } if params.UseExternalGasToken {