8000 fix: intrarelayer testnet bugs by fedekunze · Pull Request #169 · evmos/evmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: intrarelayer testnet bugs #169

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

Merged
merged 13 commits into from
Dec 12, 2021
67 changes: 42 additions & 25 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,85 +39,102 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (security & performance) [\#165](https://github.com/tharsis/evmos/pull/165) Add replace statements to avoid importing legacy software versions.
* (security, performance) [\#165](https://github.com/tharsis/evmos/pull/165) Add replace statements to avoid importing legacy software versions.

* (build) [\#143](https://github.com/tharsis/evmos/pull/143) Added `build-reproducible` rule in `Makefile` to build docker containers
### Bug Fixes

- (intrarelayer) [\#169](https://github.com/tharsis/evmos/pull/169) Fixes several testnet bugs:
- Check if supply exists for a token before when submitting a `RegisterCoinProposal`, allowing users to create an ERC20 representation of an invalid Cosmos Coin.
- Sanitize the ERC20 token name when creating coin metadata on ER `RegisterERC20Proposal`.
- Fix coin metadata validation error when registering an ERC20 with 0 denom units.

## [v0.4.2] - 2021-12-11

### Bug Fixes

- (app) [\#166](https://github.com/tharsis/evmos/pull/166) Fix `UpgradeHandler`.

## [v0.4.1] - 2021-12-07

### Improvements

- (build) [\#143](https://github.com/tharsis/evmos/pull/143) Added `build-reproducible` rule in `Makefile` to build docker containers

### Bug Fixes

* (build) [\#151](https://github.com/tharsis/evmos/pull/151) Fixes `version` command by picking the latest tag in the current branch instead of across all branches as the current version
- (build) [\#151](https://github.com/tharsis/evmos/pull/151) Fixes `version` command by picking the latest tag in the current branch instead of across all branches as the current version

## [v0.4.0] - 2021-12-02

### State Machine Breaking

* (intrarelayer) [\#119](https://github.com/tharsis/evmos/issues/119) Register `x/intrarelayer` proposal types on governance module.
- (intrarelayer) [\#119](https://github.com/tharsis/evmos/issues/119) Register `x/intrarelayer` proposal types on governance module.

### Improvements

* (app) [\#128](https://github.com/tharsis/evmos/pull/128) Add ibc-go `TestingApp` interface.
* (ci) [\#117](https://github.com/tharsis/evmos/pull/117) Enable automatic backport of PRs.
* (deps) [\#135](https://github.com/tharsis/evmos/pull/135) Bump Ethermint version to [`v0.9.0`](https://github.com/tharsis/ethermint/releases/tag/v0.9.0)
* (ci) [\#136](https://github.com/tharsis/evmos/pull/136) Deploy `evmos` docker container to [docker hub](https://hub.docker.com/u/tharsishq) for every versioned releases
- (app) [\#128](https://github.com/tharsis/evmos/pull/128) Add ibc-go `TestingApp` interface.
- (ci) [\#117](https://github.com/tharsis/evmos/pull/117) Enable automatic backport of PRs.
- (deps) [\#135](https://github.com/tharsis/evmos/pull/135) Bump Ethermint version to [`v0.9.0`](https://github.com/tharsis/ethermint/releases/tag/v0.9.0)
- (ci) [\#136](https://github.com/tharsis/evmos/pull/136) Deploy `evmos` docker container to [docker hub](https://hub.docker.com/u/tharsishq) for every versioned releases

### Bug Fixes

* (build) [\#116](https://github.com/tharsis/evmos/pull/116) Fix `build-docker` command
- (build) [\#116](https://github.com/tharsis/evmos/pull/116) Fix `build-docker` command

## [v0.3.0] - 2021-11-24

### API Breaking

* (intrarelayer) [\#99](https://github.com/tharsis/evmos/pull/99) Rename `enable_e_v_m_hook` json parameter to `enable_evm_hook`.
- (intrarelayer) [\#99](https://github.com/tharsis/evmos/pull/99) Rename `enable_e_v_m_hook` json parameter to `enable_evm_hook`.

### Improvements

* (deps) [\#110](https://github.com/tharsis/evmos/pull/110) Bump Ethermint version to [`v0.8.1`](https://github.com/tharsis/ethermint/releases/tag/v0.8.1)
* (intrarelayer) [\#107](https://github.com/tharsis/evmos/pull/107) Add IBC validation
* (cmd) [\#105](https://github.com/tharsis/evmos/pull/105) Improve testnet command to include JSON-RPC client.
- (deps) [\#110](https://github.com/tharsis/evmos/pull/110) Bump Ethermint version to [`v0.8.1`](https://github.com/tharsis/ethermint/releases/tag/v0.8.1)
- (intrarelayer) [\#107](https://github.com/tharsis/evmos/pull/107) Add IBC validation
- (cmd) [\#105](https://github.com/tharsis/evmos/pull/105) Improve testnet command to include JSON-RPC client.

## Bug Fixes

* (intrarelayer) [\#109](https://github.com/tharsis/evmos/pull/109) Fix hardcoded intrarelayer nonce and `UpdateTokenPairERC20` proposal to support ERC20s with 0 decimals.
* (intrarelayer) [\#102](https://github.com/tharsis/evmos/pull/102) Add `convert-erc20` cmd
- (intrarelayer) [\#109](https://github.com/tharsis/evmos/pull/109) Fix hardcoded intrarelayer nonce and `UpdateTokenPairERC20` proposal to support ERC20s with 0 decimals.
- (intrarelayer) [\#102](https://github.com/tharsis/evmos/pull/102) Add `convert-erc20` cmd

## [v0.2.0] - 2021-11-17

### Features

* (intrarelayer) [\#82](https://github.com/tharsis/evmos/pull/82) Intrarelayer module
* (cmd) [\#32](https://github.com/tharsis/evmos/pull/32) Create `testnet` command that spins up a new local testnet with N nodes.
- (intrarelayer) [\#82](https://github.com/tharsis/evmos/pull/82) Intrarelayer module
- (cmd) [\#32](https://github.com/tharsis/evmos/pull/32) Create `testnet` command that spins up a new local testnet with N nodes.

### Improvements

* (deps) [\#94](https://github.com/tharsis/evmos/pull/94) Bump Ethermint version to [`v0.8.0`](https://github.com/tharsis/ethermint/releases/tag/v0.8.0)
* (deps) [\#80](https://github.com/tharsis/evmos/pull/80) Bump ibc-go to [`v2.0.0`](https://github.com/cosmos/ibc-go/releases/tag/v2.0.0)
- (deps) [\#94](https://github.com/tharsis/evmos/pull/94) Bump Ethermint version to [`v0.8.0`](https://github.com/tharsis/ethermint/releases/tag/v0.8.0)
- (deps) [\#80](https://github.com/tharsis/evmos/pull/80) Bump ibc-go to [`v2.0.0`](https://github.com/cosmos/ibc-go/releases/tag/v2.0.0)

## [v0.1.3] - 2021-10-24

### Improvements

* (deps) [\#64](https://github.com/tharsis/evmos/pull/64) Bump Ethermint version to `v0.7.2`
- (deps) [\#64](https://github.com/tharsis/evmos/pull/64) Bump Ethermint version to `v0.7.2`

### Bug Fixes

* (cmd) [\#41](https://github.com/tharsis/evmos/pull/41) Fix `debug` command.
- (cmd) [\#41](https://github.com/tharsis/evmos/pull/41) Fix `debug` command.

## [v0.1.2] - 2021-10-08

### Improvements

* (deps) [\#34](https://github.com/tharsis/evmos/pull/34) Bump Ethermint version to `v0.7.1`
- (deps) [\#34](https://github.com/tharsis/evmos/pull/34) Bump Ethermint version to `v0.7.1`

## [v0.1.1] - 2021-10-07

### Bug Fixes

* (build) [\#30](https://github.com/tharsis/evmos/pull/30) Fix `version` command.
- (build) [\#30](https://github.com/tharsis/evmos/pull/30) Fix `version` command.

## [v0.1.0] - 2021-10-07

### Improvements

* (cmd) [\#26](https://github.com/tharsis/evmos/pull/26) Use config on genesis accounts.
* (deps) [\#28](https://github.com/tharsis/evmos/pull/28) Bump Ethermint version to `v0.7.0`
- (cmd) [\#26](https://github.com/tharsis/evmos/pull/26) Use config on genesis accounts.
- (deps) [\#28](https://github.com/tharsis/evmos/pull/28) Bump Ethermint version to `v0.7.0`
11 changes: 9 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ func init() {
DefaultNodeHome = filepath.Join(userHomeDir, ".evmosd")
}

// Name defines the application binary name
const Name = "evmosd"
const (
// Name defines the application binary name
Name = "evmosd"
// latest software upgrade name
upgradeName = "Olympus-Mons-v0.4.1"
)

var (
// DefaultNodeHome default home directories for the application daemon
Expand Down Expand Up @@ -507,6 +511,9 @@ func NewEvmos(
app.mm.RegisterInvariants(&app.CrisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.UpgradeKeeper.SetUpgradeHandler(upgradeName, func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, app.configurator, vm)
})
app.mm.RegisterServices(app.configurator)

// add test gRPC service for testing gRPC queries in isolation
Expand Down
4 changes: 2 additions & 2 deletions x/intrarelayer/keeper/evm_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ func (suite *KeeperTestSuite) TestEvmHooksRegisterCoin() {
sender := sdk.AccAddress(suite.address.Bytes())
contractAddr := common.HexToAddress(pair.Erc20Address)

coins := sdk.NewCoins(sdk.NewCoin(cosmosTokenName, sdk.NewInt(tc.mint)))
coins := sdk.NewCoins(sdk.NewCoin(cosmosTokenBase, sdk.NewInt(tc.mint)))
suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, coins)
suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, sender, coins)

convertCoin := types.NewMsgConvertCoin(
sdk.NewCoin(cosmosTokenName, sdk.NewInt(tc.burn)),
sdk.NewCoin(cosmosTokenBase, sdk.NewInt(tc.burn)),
suite.address,
sender,
)
Expand Down
7 changes: 3 additions & 4 deletions x/intrarelayer/keeper/mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ func (k Keeper) MintingEnabled(ctx sdk.Context, sender, receiver sdk.AccAddress,
}

id := k.GetTokenPairID(ctx, token)

if len(id) == 0 {
return types.TokenPair{}, sdkerrors.Wrapf(types.ErrInternalTokenPair, "token %s not registered", token)
return types.TokenPair{}, sdkerrors.Wrapf(types.ErrInternalTokenPair, "token '%s' not registered", token)
}

pair, found := k.GetTokenPair(ctx, id)
Expand All @@ -30,7 +29,7 @@ func (k Keeper) MintingEnabled(ctx sdk.Context, sender, receiver sdk.AccAddress,
}

if !pair.Enabled {
return types.TokenPair{}, sdkerrors.Wrapf(types.ErrNotAllowedBridge, "minting token %s is not enabled by governance", token)
return types.TokenPair{}, sdkerrors.Wrapf(types.ErrNotAllowedBridge, "minting token '%s' is not enabled by governance", token)
}

if k.bankKeeper.BlockedAddr(receiver.Bytes()) {
Expand All @@ -42,7 +41,7 @@ func (k Keeper) MintingEnabled(ctx sdk.Context, sender, receiver sdk.AccAddress,

// check if minting to a recipient address other than the sender is enabled for for the given coin denom
if !sender.Equals(receiver) && !k.bankKeeper.IsSendEnabledCoin(ctx, coin) {
return types.TokenPair{}, sdkerrors.Wrapf(banktypes.ErrSendDisabled, "minting %s coins to an external address is currently disabled", token)
return types.TokenPair{}, sdkerrors.Wrapf(banktypes.ErrSendDisabled, "minting '%s' coins to an external address is currently disabled", token)
}

return pair, nil
Expand Down
27 changes: 15 additions & 12 deletions x/intrarelayer/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/ethereum/go-ethereum/common"
"github.com/tharsis/evmos/x/intrarelayer/types"
)
Expand Down Expand Up @@ -44,10 +45,10 @@ func (suite *KeeperTestSuite) TestConvertCoinNativeCoin() {
suite.Commit()

ctx := sdk.WrapSDKContext(suite.ctx)
coins := sdk.NewCoins(sdk.NewCoin(cosmosTokenName, sdk.NewInt(tc.mint)))
coins := sdk.NewCoins(sdk.NewCoin(cosmosTokenBase, sdk.NewInt(tc.mint)))
sender := sdk.AccAddress(suite.address.Bytes())
msg := types.NewMsgConvertCoin(
sdk.NewCoin(cosmosTokenName, sdk.NewInt(tc.burn)),
sdk.NewCoin(cosmosTokenBase, sdk.NewInt(tc.burn)),
suite.address,
sender,
)
Expand Down Expand Up @@ -95,12 +96,12 @@ func (suite *KeeperTestSuite) TestConvertECR20NativeCoin() {
suite.Require().NotNil(pair)

// Precondition: Convert Coin to ERC20
coins := sdk.NewCoins(sdk.NewCoin(cosmosTokenName, sdk.NewInt(tc.mint)))
coins := sdk.NewCoins(sdk.NewCoin(cosmosTokenBase, sdk.NewInt(tc.mint)))
sender := sdk.AccAddress(suite.address.Bytes())
suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, coins)
suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, sender, coins)
msg := types.NewMsgConvertCoin(
sdk.NewCoin(cosmosTokenName, sdk.NewInt(tc.burn)),
sdk.NewCoin(cosmosTokenBase, sdk.NewInt(tc.burn)),
suite.address,
sender,
)
Expand Down Expand Up @@ -275,25 +276,27 @@ func (suite *KeeperTestSuite) TestConvertCoinNativeERC20() {

func (suite *KeeperTestSuite) TestConvertNativeIBC() {
suite.SetupTest()
base := "ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2"

validMetadata := banktypes.Metadata{
Description: "ATOM IBC voucher (channel 14)",
Base: "ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2",
Base: base,
// NOTE: Denom units MUST be increasing
DenomUnits: []*banktypes.DenomUnit{
{
Denom: "ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2",
Denom: base,
Exponent: 0,
},
{
Denom: "coin2",
Exponent: uint32(18),
},
},
Name: "ATOM channel-14",
Symbol: "ibcATOM-14",
Display: "ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2",
Display: base,
}
_, err := suite.app.IntrarelayerKeeper.RegisterCoin(suite.ctx, validMetadata)

err := suite.app.BankKeeper.MintCoins(suite.ctx, minttypes.ModuleName, sdk.Coins{sdk.NewInt64Coin(base, 1)})
suite.Require().NoError(err)

_, err = suite.app.IntrarelayerKeeper.RegisterCoin(suite.ctx, validMetadata)
suite.Require().NoError(err)
suite.Commit()
}
44 changes: 35 additions & 9 deletions x/intrarelayer/keeper/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,27 @@ import (
"github.com/tharsis/evmos/x/intrarelayer/types/contracts"
)

// RegisterCoin deploys an erc20 contract and creates the token pair for the cosmos coin
// RegisterCoin deploys an erc20 contract and creates the token pair for the existing cosmos coin
func (k Keeper) RegisterCoin(ctx sdk.Context, coinMetadata banktypes.Metadata) (*types.TokenPair, error) {
// check if the conversion is globally enabled
params := k.GetParams(ctx)
if !params.EnableIntrarelayer {
return nil, sdkerrors.Wrap(types.ErrInternalTokenPair, "intrarelaying is currently disabled by governance")
}

// check if the denomination already registered
if k.IsDenomRegistered(ctx, coinMetadata.Name) {
return nil, sdkerrors.Wrapf(types.ErrInternalTokenPair, "coin denomination already registered: %s", coinMetadata.Name)
}

// check if the coin exists by ensuring the supply is set
if !k.bankKeeper.HasSupply(ctx, coinMetadata.Base) {
return nil, sdkerrors.Wrapf(
sdkerrors.ErrInvalidCoins,
"base denomination '%s' cannot have a supply of 0", coinMetadata.Base,
)
}

if err := k.verifyMetadata(ctx, coinMetadata); err != nil {
return nil, sdkerrors.Wrapf(types.ErrInternalTokenPair, "coin metadata is invalid %s", coinMetadata.Name)
}
Expand All @@ -39,14 +50,15 @@ func (k Keeper) RegisterCoin(ctx sdk.Context, coinMetadata banktypes.Metadata) (
return &pair, nil
}

// verify if the metadata matches the existing one, if not it sets it to the store
func (k Keeper) verifyMetadata(ctx sdk.Context, coinMetadata banktypes.Metadata) error {
meta, found := k.bankKeeper.GetDenomMetaData(ctx, coinMetadata.Base)
if !found {
k.bankKeeper.SetDenomMetaData(ctx, coinMetadata)
return nil
}
// If it already existed, Check that is equal to what is stored
return equalMetadata(meta, coinMetadata)
return types.EqualMetadata(meta, coinMetadata)
}

// DeployERC20Contract creates and deploys an ERC20 contract on the EVM with the intrarelayer module account as owner
Expand Down Expand Up @@ -116,24 +128,38 @@ func (k Keeper) CreateCoinMetadata(ctx sdk.Context, contract common.Address) (*b
return nil, sdkerrors.Wrapf(types.ErrInternalTokenPair, "coin denomination already registered: %s", erc20Data.Name)
}

// base denomination
base := types.CreateDenom(strContract)

// create a bank denom metadata based on the ERC20 token ABI details
// metadata name is should always be the contract since it's the key
// to the bank store
metadata := banktypes.Metadata{
Description: types.CreateDenomDescription(strContract),
Base: types.CreateDenom(strContract),
Base: base,
// NOTE: Denom units MUST be increasing
DenomUnits: []*banktypes.DenomUnit{
{
Denom: types.CreateDenom(strContract),
Denom: base,
Exponent: 0,
},
{
Denom: erc20Data.Name,
Exponent: uint32(erc20Data.Decimals),
},
},
Name: types.CreateDenom(strContract),
Symbol: erc20Data.Symbol,
Display: erc20Data.Name,
Display: base,
}

// only append metadata if decimals > 0, otherwise validation fails
if erc20Data.Decimals > 0 {
nameSanitized := types.SanitizeERC20Name(erc20Data.Name)
metadata.DenomUnits = append(
metadata.DenomUnits,
&banktypes.DenomUnit{
Denom: nameSanitized,
Exponent: uint32(erc20Data.Decimals),
},
)
metadata.Display = nameSanitized
}

if err := metadata.Validate(); err != nil {
Expand Down
Loading
0