Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: gravity-bridge is not audited #171

Merged
merged 4 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## UNRELEASED

### Consensus breaking changes

- [cronos#171](https://github.com/crypto-org-chain/cronos/pull/171) remove gravity-bridge for mainnet launch

### Bug Fixes
- [cronos#144](https://github.com/crypto-org-chain/cronos/pull/144) fix events in autodeploy crc20 module contract
- [gravity-bridge#17](https://github.com/crypto-org-chain/gravity-bridge/pull/17) processEthereumEvent does not persist hooks emitted event
Expand Down
31 changes: 1 addition & 30 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ 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
cronos "github.com/crypto-org-chain/cronos/x/cronos"
cronosclient "github.com/crypto-org-chain/cronos/x/cronos/client"
Expand Down Expand Up @@ -171,7 +167,6 @@ var (
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
evm.AppModuleBasic{},
gravity.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
cronos.AppModuleBasic{},
)
Expand All @@ -186,7 +181,6 @@ 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},
cronostypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}
// Module configurator
Expand Down Expand Up @@ -249,9 +243,6 @@ type App struct {
// Ethermint keepers
EvmKeeper *evmkeeper.Keeper

// Gravity module
GravityKeeper gravitykeeper.Keeper

// this line is used by starport scaffolding # stargate/app/keeperDeclaration

CronosKeeper cronoskeeper.Keeper
Expand Down Expand Up @@ -294,7 +285,6 @@ func New(
ibchost.StoreKey, ibctransfertypes.StoreKey,
// ethermint keys
evmtypes.StoreKey,
gravitytypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
cronostypes.StoreKey,
)
Expand Down Expand Up @@ -388,16 +378,6 @@ func New(
tracer, bApp.Trace(), // debug EVM based on Baseapp options
)

gravityKeeper := gravitykeeper.NewKeeper(
appCodec,
keys[gravitytypes.StoreKey],
app.GetSubspace(gravitytypes.ModuleName),
app.AccountKeeper,
stakingKeeper,
app.BankKeeper,
app.SlashingKeeper,
sdk.DefaultPowerReduction,
)
// this line is used by starport scaffolding # stargate/app/keeperDefinition

app.CronosKeeper = *cronoskeeper.NewKeeper(
Expand All @@ -407,7 +387,6 @@ func New(
app.GetSubspace(cronostypes.ModuleName),
app.BankKeeper,
app.TransferKeeper,
gravityKeeper,
app.EvmKeeper,
)
cronosModule := cronos.NewAppModule(appCodec, app.CronosKeeper)
Expand All @@ -430,11 +409,9 @@ func New(
&stakingKeeper, govRouter,
)

app.GravityKeeper = *gravityKeeper.SetHooks(app.CronosKeeper)

app.EvmKeeper.SetHooks(cronoskeeper.NewLogProcessEvmHook(
cronoskeeper.NewSendToAccountHandler(app.BankKeeper, app.CronosKeeper),
cronoskeeper.NewSendToEthereumHandler(gravitykeeper.NewMsgServerImpl(app.GravityKeeper), app.CronosKeeper),
cronoskeeper.NewSendToEthereumHandler(app.CronosKeeper),
cronoskeeper.NewSendToIbcHandler(app.BankKeeper, app.CronosKeeper),
cronoskeeper.NewSendCroToIbcHandler(app.BankKeeper, app.CronosKeeper),
))
Expand All @@ -445,7 +422,6 @@ func New(
stakingtypes.NewMultiStakingHooks(
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
app.GravityKeeper.Hooks(),
),
)

Expand Down Expand Up @@ -488,7 +464,6 @@ 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,
)
Expand All @@ -503,13 +478,11 @@ 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
Expand All @@ -534,7 +507,6 @@ func New(
authz.ModuleName,
feegrant.ModuleName,
evmtypes.ModuleName,
gravitytypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
cronostypes.ModuleName,
)
Expand Down Expand Up @@ -763,7 +735,6 @@ 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(cronostypes.ModuleName)

Expand Down
2 changes: 0 additions & 2 deletions cmd/cronosd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ 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"
Expand Down Expand Up @@ -130,7 +129,6 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
queryCommand(),
txCommand(),
ethermintclient.KeyCommands(app.DefaultNodeHome),
gravitycmd.Commands(app.DefaultNodeHome),
)

// add rosetta
Expand Down
5 changes: 0 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/peggyjv/gravity-bridge/module v0.2.0
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.2.1
Expand All @@ -35,10 +34,6 @@ replace github.com/99designs/keyring => github.com/crypto-org-chain/keyring v1.1
// TODO: remove when middleware will be implemented
replace github.com/cosmos/ibc-go => github.com/crypto-org-chain/ibc-go v1.2.1-hooks

// FIXME: update after PR merged: https://github.com/PeggyJV/gravity-bridge/pull/182
// https://github.com/crypto-org-chain/gravity-bridge/tree/cronos
replace github.com/peggyjv/gravity-bridge/module => github.com/crypto-org-chain/gravity-bridge/module v0.1.22-0.20211011065300-a09cf050d304

replace github.com/cosmos/iavl => github.com/cosmos/iavl v0.17.1

replace github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.3-patched
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/crypto-org-chain/go-ethereum v1.10.3-patched h1:kr6oQIYOi2VC8SZwkhlUDZE1Omit/YHVysKMgCB2nes=
github.com/crypto-org-chain/go-ethereum v1.10.3-patched/go.mod h1:99onQmSd1GRGOziyGldI41YQb7EESX3Q4H41IfJgIQQ=
github.com/crypto-org-chain/gravity-bridge/module v0.1.22-0.20211011065300-a09cf050d304 h1:5A6pzj5uQPQCCO96SqsCCoar/DfjOxIdadBHX3ncotU=
github.com/crypto-org-chain/gravity-bridge/module v0.1.22-0.20211011065300-a09cf050d304/go.mod h1:7sqblrhSS7+I94DDIWz98N2mcXR5hL7f+EaV054sBMQ=
github.com/crypto-org-chain/ibc-go v1.2.1-hooks h1:wuWaQqm/TFKJQwuFgjCPiPumQio+Yik5Z1DObDExrrU=
github.com/crypto-org-chain/ibc-go v1.2.1-hooks/go.mod h1:YieSs25Y0TSFR67qg6Elge34yJNEOjYhYB+HNQQLoSQ=
github.com/crypto-org-chain/keyring v1.1.6-fixes h1:AUFSu56NY6XobY6XfRoDx6v3loiOrHK5MNUm32GEjwA=
Expand Down
10 changes: 0 additions & 10 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3872,16 +3872,6 @@
rev = "8b1b92947f46224e3b97bb1a3a5b0382be00d31e"
sha256 = "0f146yjqwx2mr110kl8scjhqd08hys7vr5z0d0a3lskb6yy22gfg"

["github.com/peggyjv/gravity-bridge/module"]
sumVersion = "v0.1.22-0.20211011065300-a09cf050d304"
relPath = "module"
vendorPath = "github.com/crypto-org-chain/gravity-bridge/module"
["github.com/peggyjv/gravity-bridge/module".fetch]
type = "git"
url = "https://github.com/crypto-org-chain/gravity-bridge"
rev = "a09cf050d304156a7b6db5f95bcb31bad3681c33"
sha256 = "03fdvfpzb7bqzqpgw7chd8rm6dsk6a2vybr5pvmg3h4nm5v9wm3l"

["github.com/pelletier/go-toml"]
sumVersion = "v1.9.4"
["github.com/pelletier/go-toml".fetch]
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_gravity.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
wait_for_new_blocks,
)

pytestmark = pytest.mark.gravity
pytestmark = pytest.mark.skip

Account.enable_unaudited_hdwallet_features()

Expand Down
18 changes: 4 additions & 14 deletions x/cronos/keeper/evm_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package keeper_test

import (
"fmt"
"math/big"

"github.com/crypto-org-chain/cronos/app"
keepertest "github.com/crypto-org-chain/cronos/x/cronos/keeper/mock"
"github.com/crypto-org-chain/cronos/x/cronos/types"
"math/big"

sdk "github.com/cosmos/cosmos-sdk/types"
cronosmodulekeeper "github.com/crypto-org-chain/cronos/x/cronos/keeper"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
gravitytypes "github.com/peggyjv/gravity-bridge/module/x/gravity/types"

"github.com/crypto-org-chain/cronos/x/cronos/keeper"
)
Expand Down Expand Up @@ -125,7 +125,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
},
},
{
"success send to ethereum",
"fail send to ethereum", // gravity feature is removed
func() {
suite.SetupTest()
denom := "gravity0x0000000000000000000000000000000000000000"
Expand All @@ -152,16 +152,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
},
}
err = suite.app.EvmKeeper.PostTxProcessing(txHash, logs)
suite.Require().NoError(err)

// sender's balance deducted
balance = suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(contract.Bytes()), denom)
suite.Require().Equal(sdk.NewCoin(denom, sdk.NewInt(0)), balance)
// query unbatched SendToEthereum message exist
rsp, err := suite.app.GravityKeeper.UnbatchedSendToEthereums(sdk.WrapSDKContext(suite.ctx), &gravitytypes.UnbatchedSendToEthereumsRequest{
SenderAddress: sdk.AccAddress(contract.Bytes()).String(),
})
suite.Require().Equal(1, len(rsp.SendToEthereums))
suite.Require().Error(err)
},
},
{
Expand All @@ -176,7 +167,6 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
suite.app.GetSubspace(types.ModuleName),
suite.app.BankKeeper,
keepertest.IbcKeeperMock{},
suite.app.GravityKeeper,
suite.app.EvmKeeper,
)
suite.app.CronosKeeper = cronosKeeper
Expand Down
40 changes: 5 additions & 35 deletions x/cronos/keeper/evm_log_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
gravitytypes "github.com/peggyjv/gravity-bridge/module/x/gravity/types"

"github.com/crypto-org-chain/cronos/x/cronos/types"
)
Expand Down Expand Up @@ -161,13 +160,11 @@ func (h SendToAccountHandler) Handle(ctx sdk.Context, contract common.Address, d

// SendToEthereumHandler handles `__CronosSendToEthereum` log
type SendToEthereumHandler struct {
gravitySrv gravitytypes.MsgServer
cronosKeeper Keeper
}

func NewSendToEthereumHandler(gravitySrv gravitytypes.MsgServer, cronosKeeper Keeper) *SendToEthereumHandler {
func NewSendToEthereumHandler(cronosKeeper Keeper) *SendToEthereumHandler {
return &SendToEthereumHandler{
gravitySrv: gravitySrv,
cronosKeeper: cronosKeeper,
}
}
Expand All @@ -176,38 +173,11 @@ func (h SendToEthereumHandler) EventID() common.Hash {
return SendToEthereumEvent.ID
}

// Handle returns error unconditionally.
// Since gravity bridge is removed and could be added later,
// we keep this event handler, but returns error unconditionally to prevent accidental access.
func (h SendToEthereumHandler) Handle(ctx sdk.Context, contract common.Address, data []byte) error {
unpacked, err := SendToEthereumEvent.Inputs.Unpack(data)
if err != nil {
// log and ignore
h.cronosKeeper.Logger(ctx).Info("log signature matches but failed to decode")
return nil
}

denom, found := h.cronosKeeper.GetDenomByContract(ctx, contract)
if !found {
return fmt.Errorf("contract %s is not connected to native token", contract)
}

if !types.IsValidGravityDenom(denom) {
return fmt.Errorf("the native token associated with the contract %s is not a gravity voucher", contract)
}

contractAddr := sdk.AccAddress(contract.Bytes())
ethRecipient := unpacked[0].(common.Address)
amount := sdk.NewIntFromBigInt(unpacked[1].(*big.Int))
bridgeFee := sdk.NewIntFromBigInt(unpacked[2].(*big.Int))
msg := gravitytypes.MsgSendToEthereum{
Sender: contractAddr.String(),
EthereumRecipient: ethRecipient.Hex(),
Amount: sdk.NewCoin(denom, amount),
BridgeFee: sdk.NewCoin(denom, bridgeFee),
}
_, err = h.gravitySrv.SendToEthereum(sdk.WrapSDKContext(ctx), &msg)
if err != nil {
return err
}
return nil
return fmt.Errorf("native action %s is not implemented", SendToEthereumEventName)
}

// SendToIbcHandler handles `__CronosSendToIbc` log
Expand Down
Loading