diff --git a/CHANGELOG.md b/CHANGELOG.md index 81bb0292e8..93abd2b3d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,9 @@ This version is a new scaffolding of cronos project where ethermint is included - (ethermint) [tharsis#383](https://github.com/tharsis/ethermint/pull/383) `GetCommittedState` use the original context. ### Features + +- [#11](https://github.com/crypto-org-chain/cronos/pull/11) embed gravity bridge module + ### Improvements - (ethermint) [tharsis#425](https://github.com/tharsis/ethermint/pull/425) Support build on linux arm64 diff --git a/app/app.go b/app/app.go index 8982c589de..247f2484d2 100644 --- a/app/app.go +++ b/app/app.go @@ -24,6 +24,7 @@ import ( servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" @@ -101,13 +102,24 @@ import ( evmkeeper "github.com/tharsis/ethermint/x/evm/keeper" evmtypes "github.com/tharsis/ethermint/x/evm/types" + "github.com/peggyjv/gravity-bridge/module/x/gravity" + gravitykeeper "github.com/peggyjv/gravity-bridge/module/x/gravity/keeper" + gravitytypes "github.com/peggyjv/gravity-bridge/module/x/gravity/types" + // this line is used by starport scaffolding # stargate/app/moduleImport cronosmodule "github.com/crypto-org-chain/cronos/x/cronos" cronosmodulekeeper "github.com/crypto-org-chain/cronos/x/cronos/keeper" cronosmoduletypes "github.com/crypto-org-chain/cronos/x/cronos/types" ) -const Name = "cronos" +const ( + Name = "cronos" + + // AddrLen is the allowed length (in bytes) for an address. + // + // NOTE: In the SDK, the default value is 255. + AddrLen = 20 +) // this line is used by starport scaffolding # stargate/wasm/app/enabledProposals @@ -154,6 +166,7 @@ var ( transfer.AppModuleBasic{}, vesting.AppModuleBasic{}, evm.AppModuleBasic{}, + gravity.AppModuleBasic{}, // this line is used by starport scaffolding # stargate/app/moduleBasic cronosmodule.AppModuleBasic{}, ) @@ -168,6 +181,7 @@ var ( govtypes.ModuleName: {authtypes.Burner}, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account + gravitytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, } // Module configurator @@ -229,6 +243,9 @@ type App struct { // Ethermint keepers EvmKeeper *evmkeeper.Keeper + // Gravity module + GravityKeeper gravitykeeper.Keeper + // this line is used by starport scaffolding # stargate/app/keeperDeclaration CronosKeeper cronosmodulekeeper.Keeper @@ -271,6 +288,7 @@ func New( ibchost.StoreKey, ibctransfertypes.StoreKey, // ethermint keys evmtypes.StoreKey, + gravitytypes.StoreKey, // this line is used by starport scaffolding # stargate/app/storeKey cronosmoduletypes.StoreKey, ) @@ -338,7 +356,11 @@ func New( // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks app.StakingKeeper = *stakingKeeper.SetHooks( - stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), + stakingtypes.NewMultiStakingHooks( + app.DistrKeeper.Hooks(), + app.SlashingKeeper.Hooks(), + app.GravityKeeper.Hooks(), + ), ) // ... other modules keepers @@ -393,6 +415,18 @@ func New( &stakingKeeper, govRouter, ) + gravityKeeper := gravitykeeper.NewKeeper( + appCodec, + keys[gravitytypes.StoreKey], + app.GetSubspace(gravitytypes.ModuleName), + app.AccountKeeper, + app.StakingKeeper, + app.BankKeeper, + app.SlashingKeeper, + sdk.DefaultPowerReduction, + ) + app.GravityKeeper = *gravityKeeper.SetHooks(app.CronosKeeper) + // Create static IBC router, add transfer route, then set and seal it ibcRouter := porttypes.NewRouter() ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferModule) @@ -432,6 +466,7 @@ func New( transferModule, evm.NewAppModule(app.EvmKeeper, app.AccountKeeper), + gravity.NewAppModule(app.GravityKeeper, app.BankKeeper), // this line is used by starport scaffolding # stargate/app/appModule cronosModule, ) @@ -446,11 +481,13 @@ func New( evmtypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, + gravitytypes.ModuleName, ) app.mm.SetOrderEndBlockers( crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName, evmtypes.ModuleName, + gravitytypes.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are @@ -475,6 +512,7 @@ func New( authz.ModuleName, feegrant.ModuleName, evmtypes.ModuleName, + gravitytypes.ModuleName, // this line is used by starport scaffolding # stargate/app/initGenesis cronosmoduletypes.ModuleName, ) @@ -691,8 +729,24 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibchost.ModuleName) paramsKeeper.Subspace(evmtypes.ModuleName) + paramsKeeper.Subspace(gravitytypes.ModuleName) // this line is used by starport scaffolding # stargate/app/paramSubspace paramsKeeper.Subspace(cronosmoduletypes.ModuleName) return paramsKeeper } + +// VerifyAddressFormat verifis the address is compatible with ethereum +func VerifyAddressFormat(bz []byte) error { + if len(bz) == 0 { + return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "invalid address; cannot be empty") + } + if len(bz) != AddrLen { + return sdkerrors.Wrapf( + sdkerrors.ErrUnknownAddress, + "invalid address length; got: %d, expect: %d", len(bz), AddrLen, + ) + } + + return nil +} diff --git a/app/prefix.go b/app/prefix.go index b898d5fcb4..54b31ee31d 100644 --- a/app/prefix.go +++ b/app/prefix.go @@ -10,5 +10,7 @@ func SetConfig() { // use the configurations from ethermint cmdcfg.SetBech32Prefixes(config) cmdcfg.SetBip44CoinType(config) + // Make sure address is compatible with ethereum + config.SetAddressVerifier(VerifyAddressFormat) config.Seal() } diff --git a/cmd/cronosd/cmd/root.go b/cmd/cronosd/cmd/root.go index 491f25485d..a8135e466f 100644 --- a/cmd/cronosd/cmd/root.go +++ b/cmd/cronosd/cmd/root.go @@ -33,6 +33,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/crisis" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" + gravitycmd "github.com/peggyjv/gravity-bridge/module/cmd/gravity/cmd" ethermintclient "github.com/tharsis/ethermint/client" "github.com/tharsis/ethermint/crypto/hd" ethermintserver "github.com/tharsis/ethermint/server" @@ -110,7 +111,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { ), genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome), genutilcli.MigrateGenesisCmd(), - genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome), + gravitycmd.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome), genutilcli.ValidateGenesisCmd(app.ModuleBasics), AddGenesisAccountCmd(app.DefaultNodeHome), tmcli.NewCompletionCmd(rootCmd, true), @@ -129,6 +130,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { queryCommand(), txCommand(), ethermintclient.KeyCommands(app.DefaultNodeHome), + gravitycmd.Commands(app.DefaultNodeHome), ) // add rosetta diff --git a/go.mod b/go.mod index 3181d0e804..8a883e5b9f 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,8 @@ require ( github.com/google/go-cmp v0.5.6 // indirect github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 + github.com/peggyjv/gravity-bridge/module v0.1.21 + github.com/pkg/errors v0.9.1 github.com/spf13/cast v1.4.1 github.com/spf13/cobra v1.2.1 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index 925fdfa37c..407723ebe6 100644 --- a/go.sum +++ b/go.sum @@ -764,6 +764,8 @@ github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144T github.com/paulbellamy/ratecounter v0.2.0/go.mod h1:Hfx1hDpSGoqxkVVpBi/IlYD7kChlfo5C6hzIHwPqfFE= github.com/pborman/uuid v0.0.0-20170112150404-1b00554d8222/go.mod h1:VyrYX9gd7irzKovcSS6BIIEwPRkP2Wm2m9ufcdFSJ34= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= +github.com/peggyjv/gravity-bridge/module v0.1.21 h1:5QBK682gf67vQoCpedeJYzTPPLWvZJtmqLxj7lWEJ+o= +github.com/peggyjv/gravity-bridge/module v0.1.21/go.mod h1:Key1D2z/KaJ5A206L3EQW6RWo4q8w+Jpl+p5HMm896g= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= diff --git a/gomod2nix.toml b/gomod2nix.toml index ff878f051d..aaefedf297 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -2995,6 +2995,15 @@ rev = "8b1b92947f46224e3b97bb1a3a5b0382be00d31e" sha256 = "0f146yjqwx2mr110kl8scjhqd08hys7vr5z0d0a3lskb6yy22gfg" +["github.com/peggyjv/gravity-bridge/module"] + sumVersion = "v0.1.21" + relPath = "module" + ["github.com/peggyjv/gravity-bridge/module".fetch] + type = "git" + url = "https://github.com/peggyjv/gravity-bridge" + rev = "755156abff254420eec2c4e54fb6e8d189556ee2" + sha256 = "1fjkq0jv42pq7fsah4chk2d1xkrdnkb9x52lkyagzlykw08ywcvr" + ["github.com/pelletier/go-toml"] sumVersion = "v1.9.3" ["github.com/pelletier/go-toml".fetch] diff --git a/nix/default.nix b/nix/default.nix index f8f4d15542..1fdb5882af 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -18,6 +18,21 @@ import sources.nixpkgs { }; } ) + (_: pkgs: { + orchestrator = pkgs.rustPlatform.buildRustPackage rec { + name = "orchestrator"; + src = sources.gravity-bridge; + sourceRoot = "gravity-bridge-src/${name}"; + cargoSha256 = sha256:1sp1f959qzigrpxi3qz33sr4cbl7s805p72nhv7gymjzjscr578z; + cargoBuildFlags = "-p ${name}"; + doCheck = false; + OPENSSL_NO_VENDOR = "1"; + OPENSSL_DIR = pkgs.symlinkJoin { + name = "openssl"; + paths = with pkgs.openssl; [ out dev ]; + }; + }; + }) ]; config = { }; inherit system; diff --git a/nix/sources.json b/nix/sources.json index 47339f72d7..fc98bb0ad1 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -11,6 +11,19 @@ "url": "https://github.com/tweag/gomod2nix/archive/67f22dd738d092c6ba88e420350ada0ed4992ae8.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, + "gravity-bridge": { + "branch": "main", + "description": "A CosmosSDK application for moving assets on and off of EVM based, POW chains", + "homepage": "", + "owner": "PeggyJV", + "repo": "gravity-bridge", + "rev": "755156abff254420eec2c4e54fb6e8d189556ee2", + "sha256": "1fjkq0jv42pq7fsah4chk2d1xkrdnkb9x52lkyagzlykw08ywcvr", + "type": "tarball", + "url": "https://github.com/PeggyJV/gravity-bridge/archive/refs/tags/v0.1.21.tar.gz", + "url_template": "https://github.com/PeggyJV/gravity-bridge/archive/refs/tags/v0.1.21.tar.gz", + "version": "0.1.21" + }, "niv": { "branch": "master", "description": "Easy dependency management for Nix projects", diff --git a/x/cronos/keeper/hooks.go b/x/cronos/keeper/hooks.go new file mode 100644 index 0000000000..3c6c02fc25 --- /dev/null +++ b/x/cronos/keeper/hooks.go @@ -0,0 +1,19 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + gravitytypes "github.com/peggyjv/gravity-bridge/module/x/gravity/types" +) + +// TODO Implements GravityHooks interface +func (k Keeper) AfterContractCallExecutedEvent(ctx sdk.Context, event gravitytypes.ContractCallExecutedEvent) { +} + +func (k Keeper) AfterERC20DeployedEvent(ctx sdk.Context, event gravitytypes.ERC20DeployedEvent) {} + +func (k Keeper) AfterSignerSetExecutedEvent(ctx sdk.Context, event gravitytypes.SignerSetTxExecutedEvent) { +} + +func (k Keeper) AfterBatchExecutedEvent(ctx sdk.Context, event gravitytypes.BatchExecutedEvent) {} + +func (k Keeper) AfterSendToCosmosEvent(ctx sdk.Context, event gravitytypes.SendToCosmosEvent) {}