diff --git a/integration_tests/happy_path_test.go b/integration_tests/happy_path_test.go index c61743208..8a245d5c1 100644 --- a/integration_tests/happy_path_test.go +++ b/integration_tests/happy_path_test.go @@ -294,6 +294,7 @@ func (s *IntegrationTestSuite) TestHappyPath() { s.Run("Test orchestrator EthereumTxConfirmation after transaction execution", func() { val := s.chain.validators[0] keyring, err := val.keyring() + s.Require().NoError(err) clientCtx, err := s.chain.clientContext("tcp://localhost:26657", &keyring, "val", val.address()) s.Require().NoError(err) @@ -309,6 +310,7 @@ func (s *IntegrationTestSuite) TestHappyPath() { testDenomERC20 := common.HexToAddress(gravityResponse.Erc20) initialBalance, err := s.getEthTokenBalanceOf(common.HexToAddress(recipient), testDenomERC20) + s.Require().NoError(err, "error getting initial balance") // Turn off one orchestrator (let's use the second one) s.T().Log("Turning off orchestrator1") err = s.dockerPool.RemoveContainerByName("orchestrator1") diff --git a/integration_tests/setup_test.go b/integration_tests/setup_test.go index 420710f17..652227979 100644 --- a/integration_tests/setup_test.go +++ b/integration_tests/setup_test.go @@ -64,7 +64,6 @@ var ( stakeAmountCoin = sdk.NewCoin(testDenom, stakeAmount) gravityContract = common.HexToAddress("0x04C89607413713Ec9775E14b954286519d836FEf") testERC20contract = common.HexToAddress("0x4C4a2f8c81640e47606d3fd77B353E87Ba015584") - testERC20Denom = fmt.Sprintf("gravity%s", testERC20contract.Hex()) ) type IntegrationTestSuite struct { @@ -347,7 +346,7 @@ func (s *IntegrationTestSuite) initGenesis() { s.Require().NoError(cdc.UnmarshalJSON(appGenState[gravitytypes.ModuleName], &gravityGenState)) gravityGenState.Params.GravityId = "gravitytest" gravityGenState.Params.BridgeEthereumAddress = gravityContract.String() - gravityGenState.Params.ConfirmedOutgoingTxWindow = 1000000 + gravityGenState.Params.ConfirmedOutgoingTxWindow = 300 gravityGenState.Params.TargetEthTxTimeout = 3600000 gravityGenState.Params.AverageBlockTime = 1000 gravityGenState.Params.AverageEthereumBlockTime = 1000 diff --git a/integration_tests/validator_out.go b/integration_tests/validator_out.go index c9167cb25..f2a9fe7ab 100644 --- a/integration_tests/validator_out.go +++ b/integration_tests/validator_out.go @@ -129,33 +129,37 @@ func (s *IntegrationTestSuite) TestValidatorOut() { s.Require().NoError(err) newQ := stakingtypes.NewQueryClient(clientCtx) - val0, err := newQ.Validator(context.Background(), &stakingtypes.QueryValidatorRequest{ValidatorAddr: sdk.ValAddress(s.chain.validators[0].address()).String()}) + val0Address := sdk.ValAddress(s.chain.validators[0].address()).String() + val0, err := newQ.Validator(context.Background(), &stakingtypes.QueryValidatorRequest{ValidatorAddr: val0Address}) if err != nil { s.T().Logf("error: %s", err) return false } s.Require().False(val0.GetValidator().IsJailed()) - val1, err := newQ.Validator(context.Background(), &stakingtypes.QueryValidatorRequest{ValidatorAddr: sdk.ValAddress(s.chain.validators[1].address()).String()}) + val1Address := sdk.ValAddress(s.chain.validators[1].address()).String() + val1, err := newQ.Validator(context.Background(), &stakingtypes.QueryValidatorRequest{ValidatorAddr: val1Address}) if err != nil { s.T().Logf("error: %s", err) return false } s.Require().False(val1.GetValidator().IsJailed()) - val2, err := newQ.Validator(context.Background(), &stakingtypes.QueryValidatorRequest{ValidatorAddr: sdk.ValAddress(s.chain.validators[2].address()).String()}) + val2Address := sdk.ValAddress(s.chain.validators[2].address()).String() + val2, err := newQ.Validator(context.Background(), &stakingtypes.QueryValidatorRequest{ValidatorAddr: val2Address}) if err != nil { s.T().Logf("error: %s", err) return false } s.Require().False(val2.GetValidator().IsJailed()) - val3, err := newQ.Validator(context.Background(), &stakingtypes.QueryValidatorRequest{ValidatorAddr: sdk.ValAddress(s.chain.validators[3].address()).String()}) + val3Address := sdk.ValAddress(s.chain.validators[3].address()).String() + val3, err := newQ.Validator(context.Background(), &stakingtypes.QueryValidatorRequest{ValidatorAddr: val3Address}) if err != nil { s.T().Logf("error: %s", err) return false } return val3.GetValidator().IsJailed() - }, 5*time.Minute, 5*time.Second, "can't confirm jailing status") + }, 8*time.Minute, 5*time.Second, "can't confirm jailing status") }) } diff --git a/module/x/gravity/handler.go b/module/x/gravity/handler.go index 3d6798193..8afbcbdfc 100644 --- a/module/x/gravity/handler.go +++ b/module/x/gravity/handler.go @@ -1,6 +1,7 @@ package gravity import ( + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -42,7 +43,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { return sdk.WrapServiceResult(ctx, res, err) default: - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) + return nil, errors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) } } } @@ -53,7 +54,7 @@ func NewCommunityPoolEthereumSpendProposalHandler(k keeper.Keeper) govtypes.Hand case *types.CommunityPoolEthereumSpendProposal: return k.HandleCommunityPoolEthereumSpendProposal(ctx, c) default: - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized gravity proposal content type: %T", c) + return errors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized gravity proposal content type: %T", c) } } } diff --git a/module/x/gravity/keeper/batch.go b/module/x/gravity/keeper/batch.go index 6b56db24e..32ce26fe3 100644 --- a/module/x/gravity/keeper/batch.go +++ b/module/x/gravity/keeper/batch.go @@ -6,8 +6,8 @@ import ( "sort" "strconv" + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/ethereum/go-ethereum/common" "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types" @@ -79,7 +79,7 @@ func (k Keeper) batchTxExecuted(ctx sdk.Context, tokenContract common.Address, n // If the iterated batches nonce is lower than the one that was just executed, cancel it btx, ok := otx.(*types.BatchTx) if !ok { - panic(sdkerrors.Wrapf(types.ErrInvalid, "couldn't cast to batch tx for %s", otx)) + panic(errors.Wrapf(types.ErrInvalid, "couldn't cast to batch tx for %s", otx)) } if (btx.BatchNonce < batchTx.BatchNonce) && (btx.TokenContract == batchTx.TokenContract) { @@ -173,7 +173,7 @@ func (k Keeper) GetUnsignedBatchTxs(ctx sdk.Context, val sdk.ValAddress) []*type if len(sig) == 0 { batch, ok := cotx.(*types.BatchTx) if !ok { - panic(sdkerrors.Wrapf(types.ErrInvalid, "couldn't cast to batch tx for completed tx %s", cotx)) + panic(errors.Wrapf(types.ErrInvalid, "couldn't cast to batch tx for completed tx %s", cotx)) } unconfirmed = append(unconfirmed, batch) } @@ -184,7 +184,7 @@ func (k Keeper) GetUnsignedBatchTxs(ctx sdk.Context, val sdk.ValAddress) []*type if len(sig) == 0 { batch, ok := otx.(*types.BatchTx) if !ok { - panic(sdkerrors.Wrapf(types.ErrInvalid, "couldn't cast to batch tx for %s", otx)) + panic(errors.Wrapf(types.ErrInvalid, "couldn't cast to batch tx for %s", otx)) } unconfirmed = append(unconfirmed, batch) } diff --git a/module/x/gravity/keeper/contract_call.go b/module/x/gravity/keeper/contract_call.go index 57618d394..f1ba07a91 100644 --- a/module/x/gravity/keeper/contract_call.go +++ b/module/x/gravity/keeper/contract_call.go @@ -5,8 +5,8 @@ import ( "encoding/hex" "sort" + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types" ) @@ -17,7 +17,7 @@ func (k Keeper) GetUnsignedContractCallTxs(ctx sdk.Context, val sdk.ValAddress) if len(sig) == 0 { call, ok := cotx.(*types.ContractCallTx) if !ok { - panic(sdkerrors.Wrapf(types.ErrInvalid, "couldn't cast to contract call for completed tx %s", cotx)) + panic(errors.Wrapf(types.ErrInvalid, "couldn't cast to contract call for completed tx %s", cotx)) } unconfirmed = append(unconfirmed, call) } @@ -29,7 +29,7 @@ func (k Keeper) GetUnsignedContractCallTxs(ctx sdk.Context, val sdk.ValAddress) if len(sig) == 0 { call, ok := otx.(*types.ContractCallTx) if !ok { - panic(sdkerrors.Wrapf(types.ErrInvalid, "couldn't cast to contract call for %s", otx)) + panic(errors.Wrapf(types.ErrInvalid, "couldn't cast to contract call for %s", otx)) } unconfirmed = append(unconfirmed, call) } @@ -53,7 +53,7 @@ func (k Keeper) contractCallExecuted(ctx sdk.Context, invalidationScope []byte, // If the iterated contract call's nonce is lower than the one that was just executed, delete it cctx, ok := otx.(*types.ContractCallTx) if !ok { - panic(sdkerrors.Wrapf(types.ErrInvalid, "couldn't cast to contract call tx for %s", otx)) + panic(errors.Wrapf(types.ErrInvalid, "couldn't cast to contract call tx for %s", otx)) } if (cctx.InvalidationNonce < completedCallTx.InvalidationNonce) && diff --git a/module/x/gravity/keeper/ethereum_event_handler.go b/module/x/gravity/keeper/ethereum_event_handler.go index db240f2da..16ff59d04 100644 --- a/module/x/gravity/keeper/ethereum_event_handler.go +++ b/module/x/gravity/keeper/ethereum_event_handler.go @@ -3,8 +3,8 @@ package keeper import ( "math/big" + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/ethereum/go-ethereum/common" @@ -15,7 +15,7 @@ func (k Keeper) DetectMaliciousSupply(ctx sdk.Context, denom string, amount sdk. currentSupply := k.bankKeeper.GetSupply(ctx, denom) newSupply := new(big.Int).Add(currentSupply.Amount.BigInt(), amount.BigInt()) if newSupply.BitLen() > 256 { - return sdkerrors.Wrapf(types.ErrSupplyOverflow, "malicious supply of %s detected", denom) + return errors.Wrapf(types.ErrSupplyOverflow, "malicious supply of %s detected", denom) } return nil @@ -37,7 +37,7 @@ func (k Keeper) Handle(ctx sdk.Context, eve types.EthereumEvent) (err error) { // if it is not cosmos originated, mint the coins (aka vouchers) if err := k.bankKeeper.MintCoins(ctx, types.ModuleName, coins); err != nil { - return sdkerrors.Wrapf(err, "mint vouchers coins: %s", coins) + return errors.Wrapf(err, "mint vouchers coins: %s", coins) } } @@ -79,13 +79,13 @@ func (k Keeper) Handle(ctx sdk.Context, eve types.EthereumEvent) (err error) { return nil default: - return sdkerrors.Wrapf(types.ErrInvalid, "event type: %T", event) + return errors.Wrapf(types.ErrInvalid, "event type: %T", event) } } func (k Keeper) verifyERC20DeployedEvent(ctx sdk.Context, event *types.ERC20DeployedEvent) error { if existingERC20, exists := k.getCosmosOriginatedERC20(ctx, event.CosmosDenom); exists { - return sdkerrors.Wrapf( + return errors.Wrapf( types.ErrInvalidERC20Event, "ERC20 token %s already exists for denom %s", existingERC20.Hex(), event.CosmosDenom, ) @@ -109,28 +109,28 @@ func (k Keeper) verifyERC20DeployedEvent(ctx sdk.Context, event *types.ERC20Depl } if supply := k.bankKeeper.GetSupply(ctx, event.CosmosDenom); supply.IsZero() { - return sdkerrors.Wrapf( + return errors.Wrapf( types.ErrInvalidERC20Event, "no supply exists for token %s without metadata", event.CosmosDenom, ) } if event.Erc20Name != event.CosmosDenom { - return sdkerrors.Wrapf( + return errors.Wrapf( types.ErrInvalidERC20Event, "invalid ERC20 name for token without metadata; got: %s, expected: %s", event.Erc20Name, event.CosmosDenom, ) } if event.Erc20Symbol != "" { - return sdkerrors.Wrapf( + return errors.Wrapf( types.ErrInvalidERC20Event, "expected empty ERC20 symbol for token without metadata; got: %s", event.Erc20Symbol, ) } if event.Erc20Decimals != 0 { - return sdkerrors.Wrapf( + return errors.Wrapf( types.ErrInvalidERC20Event, "expected zero ERC20 decimals for token without metadata; got: %d", event.Erc20Decimals, ) @@ -141,14 +141,14 @@ func (k Keeper) verifyERC20DeployedEvent(ctx sdk.Context, event *types.ERC20Depl func verifyERC20Token(metadata banktypes.Metadata, event *types.ERC20DeployedEvent) error { if event.Erc20Name != metadata.Display { - return sdkerrors.Wrapf( + return errors.Wrapf( types.ErrInvalidERC20Event, "ERC20 name %s does not match the denom display %s", event.Erc20Name, metadata.Display, ) } if event.Erc20Symbol != metadata.Display { - return sdkerrors.Wrapf( + return errors.Wrapf( types.ErrInvalidERC20Event, "ERC20 symbol %s does not match denom display %s", event.Erc20Symbol, metadata.Display, ) @@ -179,7 +179,7 @@ func verifyERC20Token(metadata banktypes.Metadata, event *types.ERC20DeployedEve } if uint64(decimals) != event.Erc20Decimals { - return sdkerrors.Wrapf( + return errors.Wrapf( types.ErrInvalidERC20Event, "ERC20 decimals %d does not match denom decimals %d", event.Erc20Decimals, decimals, ) diff --git a/module/x/gravity/keeper/ethereum_event_vote.go b/module/x/gravity/keeper/ethereum_event_vote.go index febc418e9..3763f72b8 100644 --- a/module/x/gravity/keeper/ethereum_event_vote.go +++ b/module/x/gravity/keeper/ethereum_event_vote.go @@ -5,9 +5,9 @@ import ( "fmt" "strconv" + "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types" @@ -25,7 +25,7 @@ func (k Keeper) recordEventVote( lastEventNonce := k.getLastEventNonceByValidator(ctx, val) expectedNonce := lastEventNonce + 1 if event.GetEventNonce() != expectedNonce { - return nil, sdkerrors.Wrapf(types.ErrInvalid, + return nil, errors.Wrapf(types.ErrInvalid, "non contiguous event nonce expected %v observed %v for validator %v", expectedNonce, event.GetEventNonce(), diff --git a/module/x/gravity/keeper/genesis.go b/module/x/gravity/keeper/genesis.go index c4bca0d75..15adf3999 100644 --- a/module/x/gravity/keeper/genesis.go +++ b/module/x/gravity/keeper/genesis.go @@ -126,7 +126,11 @@ func ExportGenesis(ctx sdk.Context, k Keeper) types.GenesisState { outgoingTxs = append(outgoingTxs, ota) sstx, _ := otx.(*types.SignerSetTx) k.iterateEthereumSignatures(ctx, sstx.GetStoreIndex(), func(val sdk.ValAddress, sig []byte) bool { - siga, _ := types.PackConfirmation(&types.SignerSetTxConfirmation{sstx.Nonce, k.GetValidatorEthereumAddress(ctx, val).Hex(), sig}) + siga, _ := types.PackConfirmation(&types.SignerSetTxConfirmation{ + SignerSetNonce: sstx.Nonce, + EthereumSigner: k.GetValidatorEthereumAddress(ctx, val).Hex(), + Signature: sig, + }) ethereumTxConfirmations = append(ethereumTxConfirmations, siga) return false }) @@ -139,7 +143,12 @@ func ExportGenesis(ctx sdk.Context, k Keeper) types.GenesisState { outgoingTxs = append(outgoingTxs, ota) btx, _ := otx.(*types.BatchTx) k.iterateEthereumSignatures(ctx, btx.GetStoreIndex(), func(val sdk.ValAddress, sig []byte) bool { - siga, _ := types.PackConfirmation(&types.BatchTxConfirmation{btx.TokenContract, btx.BatchNonce, k.GetValidatorEthereumAddress(ctx, val).Hex(), sig}) + siga, _ := types.PackConfirmation(&types.BatchTxConfirmation{ + TokenContract: btx.TokenContract, + BatchNonce: btx.BatchNonce, + EthereumSigner: k.GetValidatorEthereumAddress(ctx, val).Hex(), + Signature: sig, + }) ethereumTxConfirmations = append(ethereumTxConfirmations, siga) return false }) @@ -152,7 +161,12 @@ func ExportGenesis(ctx sdk.Context, k Keeper) types.GenesisState { outgoingTxs = append(outgoingTxs, ota) btx, _ := otx.(*types.ContractCallTx) k.iterateEthereumSignatures(ctx, btx.GetStoreIndex(), func(val sdk.ValAddress, sig []byte) bool { - siga, _ := types.PackConfirmation(&types.ContractCallTxConfirmation{btx.InvalidationScope, btx.InvalidationNonce, k.GetValidatorEthereumAddress(ctx, val).Hex(), sig}) + siga, _ := types.PackConfirmation(&types.ContractCallTxConfirmation{ + InvalidationScope: btx.InvalidationScope, + InvalidationNonce: btx.InvalidationNonce, + EthereumSigner: k.GetValidatorEthereumAddress(ctx, val).Hex(), + Signature: sig, + }) ethereumTxConfirmations = append(ethereumTxConfirmations, siga) return false }) diff --git a/module/x/gravity/keeper/grpc_query.go b/module/x/gravity/keeper/grpc_query.go index 353cbcfbe..708d98eca 100644 --- a/module/x/gravity/keeper/grpc_query.go +++ b/module/x/gravity/keeper/grpc_query.go @@ -3,6 +3,7 @@ package keeper import ( "context" + "cosmossdk.io/errors" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" @@ -10,7 +11,6 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/ethereum/go-ethereum/common" "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types" ) @@ -105,7 +105,7 @@ func (k Keeper) SignerSetTxs(c context.Context, req *types.SignerSetTxsRequest) pageRes, err := k.PaginateOutgoingTxsByType(sdk.UnwrapSDKContext(c), req.Pagination, types.SignerSetTxPrefixByte, func(_ []byte, otx types.OutgoingTx) (hit bool) { signer, ok := otx.(*types.SignerSetTx) if !ok { - panic(sdkerrors.Wrapf(types.ErrInvalid, "couldn't cast to signer set for %s", otx)) + panic(errors.Wrapf(types.ErrInvalid, "couldn't cast to signer set for %s", otx)) } signers = append(signers, signer) @@ -123,7 +123,7 @@ func (k Keeper) BatchTxs(c context.Context, req *types.BatchTxsRequest) (*types. pageRes, err := k.PaginateOutgoingTxsByType(sdk.UnwrapSDKContext(c), req.Pagination, types.BatchTxPrefixByte, func(_ []byte, otx types.OutgoingTx) (hit bool) { batch, ok := otx.(*types.BatchTx) if !ok { - panic(sdkerrors.Wrapf(types.ErrInvalid, "couldn't cast to batch tx for %s", otx)) + panic(errors.Wrapf(types.ErrInvalid, "couldn't cast to batch tx for %s", otx)) } batches = append(batches, batch) return true @@ -140,7 +140,7 @@ func (k Keeper) ContractCallTxs(c context.Context, req *types.ContractCallTxsReq pageRes, err := k.PaginateOutgoingTxsByType(sdk.UnwrapSDKContext(c), req.Pagination, types.ContractCallTxPrefixByte, func(_ []byte, otx types.OutgoingTx) (hit bool) { call, ok := otx.(*types.ContractCallTx) if !ok { - panic(sdkerrors.Wrapf(types.ErrInvalid, "couldn't cast to contract call for %s", otx)) + panic(errors.Wrapf(types.ErrInvalid, "couldn't cast to contract call for %s", otx)) } calls = append(calls, call) return true @@ -281,7 +281,7 @@ func (k Keeper) ERC20ToDenom(c context.Context, req *types.ERC20ToDenomRequest) func (k Keeper) DenomToERC20Params(c context.Context, req *types.DenomToERC20ParamsRequest) (*types.DenomToERC20ParamsResponse, error) { ctx := sdk.UnwrapSDKContext(c) if existingERC20, exists := k.getCosmosOriginatedERC20(ctx, req.Denom); exists { - return nil, sdkerrors.Wrapf( + return nil, errors.Wrapf( types.ErrInvalidERC20Event, "ERC20 token %s already exists for denom %s", existingERC20.Hex(), req.Denom, ) @@ -306,7 +306,7 @@ func (k Keeper) DenomToERC20Params(c context.Context, req *types.DenomToERC20Par } if supply := k.bankKeeper.GetSupply(ctx, req.Denom); supply.IsZero() { - return nil, sdkerrors.Wrapf( + return nil, errors.Wrapf( types.ErrInvalidERC20Event, "no supply exists for token %s without metadata", req.Denom, ) @@ -394,7 +394,7 @@ func (k Keeper) DelegateKeysByValidator(c context.Context, req *types.DelegateKe func (k Keeper) DelegateKeysByEthereumSigner(c context.Context, req *types.DelegateKeysByEthereumSignerRequest) (*types.DelegateKeysByEthereumSignerResponse, error) { ctx := sdk.UnwrapSDKContext(c) if !common.IsHexAddress(req.EthereumSigner) { - return nil, sdkerrors.Wrapf(types.ErrInvalid, "ethereum signer needs to be a hex address") + return nil, errors.Wrapf(types.ErrInvalid, "ethereum signer needs to be a hex address") } ethAddr := common.HexToAddress(req.EthereumSigner) orchAddr := k.GetEthereumOrchestratorAddress(ctx, ethAddr) diff --git a/module/x/gravity/keeper/msg_server.go b/module/x/gravity/keeper/msg_server.go index bb3a52cd6..2f1c06dcd 100644 --- a/module/x/gravity/keeper/msg_server.go +++ b/module/x/gravity/keeper/msg_server.go @@ -6,8 +6,8 @@ import ( "fmt" "strconv" + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -32,35 +32,35 @@ func (k msgServer) SetDelegateKeys(c context.Context, msg *types.MsgDelegateKeys valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) if err != nil { - return nil, sdkerrors.Wrap(types.ErrInvalidValidatorAddress, err.Error()) + return nil, errors.Wrap(types.ErrInvalidValidatorAddress, err.Error()) } orchAddr, err := sdk.AccAddressFromBech32(msg.OrchestratorAddress) if err != nil { - return nil, sdkerrors.Wrap(types.ErrInvalidOrchestratorAddress, err.Error()) + return nil, errors.Wrap(types.ErrInvalidOrchestratorAddress, err.Error()) } ethAddr := common.HexToAddress(msg.EthereumAddress) // ensure that the validator exists if k.Keeper.StakingKeeper.Validator(ctx, valAddr) == nil { - return nil, sdkerrors.Wrap(stakingtypes.ErrNoValidatorFound, valAddr.String()) + return nil, errors.Wrap(stakingtypes.ErrNoValidatorFound, valAddr.String()) } // check if the Ethereum address is currently not used if k.validatorForEthAddressExists(ctx, ethAddr) { - return nil, sdkerrors.Wrapf(types.ErrDelegateKeys, "ethereum address %s in use", ethAddr) + return nil, errors.Wrapf(types.ErrDelegateKeys, "ethereum address %s in use", ethAddr) } // check if the orchestrator address is currently not used if k.ethAddressForOrchestratorExists(ctx, orchAddr) { - return nil, sdkerrors.Wrapf(types.ErrDelegateKeys, "orchestrator address %s in use", orchAddr) + return nil, errors.Wrapf(types.ErrDelegateKeys, "orchestrator address %s in use", orchAddr) } valAccAddr := sdk.AccAddress(valAddr) valAccSeq, err := k.accountKeeper.GetSequence(ctx, valAccAddr) if err != nil { - return nil, sdkerrors.Wrapf(types.ErrDelegateKeys, "failed to get sequence for validator account %s", valAccAddr) + return nil, errors.Wrapf(types.ErrDelegateKeys, "failed to get sequence for validator account %s", valAccAddr) } var nonce uint64 @@ -78,7 +78,7 @@ func (k msgServer) SetDelegateKeys(c context.Context, msg *types.MsgDelegateKeys hash := crypto.Keccak256Hash(signMsgBz).Bytes() if err = types.ValidateEthereumSignature(hash, msg.EthSignature, ethAddr); err != nil { - return nil, sdkerrors.Wrapf( + return nil, errors.Wrapf( types.ErrDelegateKeys, "failed to validate delegate keys signature for Ethereum address %X; %s ;%d", ethAddr, err, nonce, @@ -125,7 +125,7 @@ func (k msgServer) SubmitEthereumTxConfirmation(c context.Context, msg *types.Ms "store index", fmt.Sprintf("%x", confirmation.GetStoreIndex()), ) - return nil, sdkerrors.Wrap(types.ErrInvalid, "couldn't find outgoing tx") + return nil, errors.Wrap(types.ErrInvalid, "couldn't find outgoing tx") } } @@ -134,7 +134,7 @@ func (k msgServer) SubmitEthereumTxConfirmation(c context.Context, msg *types.Ms ethAddress := k.GetValidatorEthereumAddress(ctx, val) if ethAddress != confirmation.GetSigner() { - return nil, sdkerrors.Wrap(types.ErrInvalid, "eth address does not match signer eth address") + return nil, errors.Wrap(types.ErrInvalid, "eth address does not match signer eth address") } if err = types.ValidateEthereumSignature(checkpoint, confirmation.GetSignature(), ethAddress); err != nil { @@ -145,7 +145,7 @@ func (k msgServer) SubmitEthereumTxConfirmation(c context.Context, msg *types.Ms "type url", msg.Confirmation.TypeUrl, "signature", hex.EncodeToString(confirmation.GetSignature()), "error", err) - return nil, sdkerrors.Wrap(types.ErrInvalid, fmt.Sprintf( + return nil, errors.Wrap(types.ErrInvalid, fmt.Sprintf( "signature verification failed ethAddress %s gravityID %s checkpoint %s typeURL %s signature %s err %s", ethAddress.Hex(), gravityID, @@ -157,7 +157,7 @@ func (k msgServer) SubmitEthereumTxConfirmation(c context.Context, msg *types.Ms } // TODO: should validators be able to overwrite their signatures? if k.getEthereumSignature(ctx, confirmation.GetStoreIndex(), val) != nil { - return nil, sdkerrors.Wrap(types.ErrInvalid, "signature duplicate") + return nil, errors.Wrap(types.ErrInvalid, "signature duplicate") } key := k.SetEthereumSignature(ctx, confirmation, val) @@ -190,7 +190,7 @@ func (k msgServer) SubmitEthereumEvent(c context.Context, msg *types.MsgSubmitEt // Add the claim to the store _, err = k.recordEventVote(ctx, event, val) if err != nil { - return nil, sdkerrors.Wrap(err, "create event vote record") + return nil, errors.Wrap(err, "create event vote record") } // Emit the handle message event @@ -285,7 +285,7 @@ func (k msgServer) SubmitEthereumHeightVote(c context.Context, msg *types.MsgEth func (k Keeper) getSignerValidator(ctx sdk.Context, signerString string) (sdk.ValAddress, error) { signer, err := sdk.AccAddressFromBech32(signerString) if err != nil { - return nil, sdkerrors.Wrap(types.ErrInvalid, "signer address") + return nil, errors.Wrap(types.ErrInvalid, "signer address") } var validatorI stakingtypes.ValidatorI if validator := k.GetOrchestratorValidatorAddress(ctx, signer); validator == nil { @@ -295,9 +295,9 @@ func (k Keeper) getSignerValidator(ctx sdk.Context, signerString string) (sdk.Va } if validatorI == nil { - return nil, sdkerrors.Wrap(types.ErrInvalid, "not orchestrator or validator") + return nil, errors.Wrap(types.ErrInvalid, "not orchestrator or validator") } else if !validatorI.IsBonded() { - return nil, sdkerrors.Wrap(types.ErrInvalid, fmt.Sprintf("validator is not bonded: %s", validatorI.GetOperator())) + return nil, errors.Wrap(types.ErrInvalid, fmt.Sprintf("validator is not bonded: %s", validatorI.GetOperator())) } return validatorI.GetOperator(), nil diff --git a/module/x/gravity/keeper/msg_server_test.go b/module/x/gravity/keeper/msg_server_test.go index 2aac7d9ff..170cd9812 100644 --- a/module/x/gravity/keeper/msg_server_test.go +++ b/module/x/gravity/keeper/msg_server_test.go @@ -10,7 +10,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/crypto" ethCrypto "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/require" @@ -32,7 +31,7 @@ func TestMsgServer_SubmitEthereumSignature(t *testing.T) { orcAddr1, _ = sdk.AccAddressFromBech32("cosmos1dg55rtevlfxh46w88yjpdd08sqhh5cc3xhkcej") valAddr1 = sdk.ValAddress(orcAddr1) - ethAddr1 = crypto.PubkeyToAddress(ethPrivKey.PublicKey) + ethAddr1 = ethCrypto.PubkeyToAddress(ethPrivKey.PublicKey) orcAddr2, _ = sdk.AccAddressFromBech32("cosmos164knshrzuuurf05qxf3q5ewpfnwzl4gj4m4dfy") valAddr2 = sdk.ValAddress(orcAddr2) @@ -154,7 +153,7 @@ func TestMsgServer_SendToEthereum(t *testing.T) { orcAddr1, _ = sdk.AccAddressFromBech32("cosmos1dg55rtevlfxh46w88yjpdd08sqhh5cc3xhkcej") valAddr1 = sdk.ValAddress(orcAddr1) - ethAddr1 = crypto.PubkeyToAddress(ethPrivKey.PublicKey) + ethAddr1 = ethCrypto.PubkeyToAddress(ethPrivKey.PublicKey) orcAddr2, _ = sdk.AccAddressFromBech32("cosmos164knshrzuuurf05qxf3q5ewpfnwzl4gj4m4dfy") valAddr2 = sdk.ValAddress(orcAddr2) @@ -219,7 +218,7 @@ func TestMsgServer_CancelSendToEthereum(t *testing.T) { orcAddr1, _ = sdk.AccAddressFromBech32("cosmos1dg55rtevlfxh46w88yjpdd08sqhh5cc3xhkcej") valAddr1 = sdk.ValAddress(orcAddr1) - ethAddr1 = crypto.PubkeyToAddress(ethPrivKey.PublicKey) + ethAddr1 = ethCrypto.PubkeyToAddress(ethPrivKey.PublicKey) orcAddr2, _ = sdk.AccAddressFromBech32("cosmos164knshrzuuurf05qxf3q5ewpfnwzl4gj4m4dfy") valAddr2 = sdk.ValAddress(orcAddr2) @@ -325,7 +324,7 @@ func TestMsgServer_SubmitEthereumEvent(t *testing.T) { orcAddr1, _ = sdk.AccAddressFromBech32("cosmos1dg55rtevlfxh46w88yjpdd08sqhh5cc3xhkcej") valAddr1 = sdk.ValAddress(orcAddr1) - ethAddr1 = crypto.PubkeyToAddress(ethPrivKey.PublicKey) + ethAddr1 = ethCrypto.PubkeyToAddress(ethPrivKey.PublicKey) orcAddr2, _ = sdk.AccAddressFromBech32("cosmos164knshrzuuurf05qxf3q5ewpfnwzl4gj4m4dfy") valAddr2 = sdk.ValAddress(orcAddr2) @@ -417,7 +416,7 @@ func TestMsgServer_SetDelegateKeys(t *testing.T) { orcAddr1, _ = sdk.AccAddressFromBech32("cosmos1dg55rtevlfxh46w88yjpdd08sqhh5cc3xhkcej") orcAddr2, _ = sdk.AccAddressFromBech32("cosmos164knshrzuuurf05qxf3q5ewpfnwzl4gj4m4dfy") valAddr1 = sdk.ValAddress(orcAddr1) - ethAddr1 = crypto.PubkeyToAddress(ethPrivKey.PublicKey) + ethAddr1 = ethCrypto.PubkeyToAddress(ethPrivKey.PublicKey) ) // setup for getSignerValidator @@ -436,7 +435,7 @@ func TestMsgServer_SetDelegateKeys(t *testing.T) { Nonce: 0, } signMsgBz := env.Marshaler.MustMarshal(ðMsg) - hash := crypto.Keccak256Hash(signMsgBz).Bytes() + hash := ethCrypto.Keccak256Hash(signMsgBz).Bytes() sig, err := types.NewEthereumSignature(hash, ethPrivKey) require.NoError(t, err) @@ -576,18 +575,18 @@ func TestEthVerify(t *testing.T) { privKeyBz, err := hexutil.Decode(privKeyHexStr) require.NoError(t, err) - privKey, err := crypto.ToECDSA(privKeyBz) + privKey, err := ethCrypto.ToECDSA(privKeyBz) require.NoError(t, err) require.NotNil(t, privKey) - require.True(t, bytes.Equal(privKeyBz, crypto.FromECDSA(privKey))) - require.Equal(t, privKeyHexStr, hexutil.Encode(crypto.FromECDSA(privKey))) + require.True(t, bytes.Equal(privKeyBz, ethCrypto.FromECDSA(privKey))) + require.Equal(t, privKeyHexStr, hexutil.Encode(ethCrypto.FromECDSA(privKey))) publicKey := privKey.Public() publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) require.True(t, ok) - address := crypto.PubkeyToAddress(*publicKeyECDSA) + address := ethCrypto.PubkeyToAddress(*publicKeyECDSA) require.Equal(t, addrHexStr, address.Hex()) // ========================================================================== @@ -604,7 +603,7 @@ func TestEthVerify(t *testing.T) { require.NoError(t, err) fmt.Println("MESSAGE BYTES TO SIGN:", hexutil.Encode(signMsgBz)) - hash := crypto.Keccak256Hash(signMsgBz).Bytes() + hash := ethCrypto.Keccak256Hash(signMsgBz).Bytes() sig, err := types.NewEthereumSignature(hash, privKey) sig[64] += 27 // change the V value diff --git a/module/x/gravity/keeper/pool.go b/module/x/gravity/keeper/pool.go index 9fac8171f..22a90e745 100644 --- a/module/x/gravity/keeper/pool.go +++ b/module/x/gravity/keeper/pool.go @@ -4,11 +4,11 @@ import ( "encoding/binary" "fmt" + "cosmossdk.io/errors" "github.com/ethereum/go-ethereum/common" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types" ) @@ -81,7 +81,7 @@ func (k Keeper) cancelSendToEthereum(ctx sdk.Context, id uint64, s string) error } if send == nil { // NOTE: this case will also be hit if the transaction is in a batch - return sdkerrors.Wrap(types.ErrInvalid, "id not found in send to ethereum pool") + return errors.Wrap(types.ErrInvalid, "id not found in send to ethereum pool") } if sender.String() != send.Sender { @@ -95,12 +95,12 @@ func (k Keeper) cancelSendToEthereum(ctx sdk.Context, id uint64, s string) error // If it is not cosmos-originated the coins are minted if !isCosmosOriginated { if err := k.bankKeeper.MintCoins(ctx, types.ModuleName, coinsToRefund); err != nil { - return sdkerrors.Wrapf(err, "mint vouchers coins: %s", coinsToRefund) + return errors.Wrapf(err, "mint vouchers coins: %s", coinsToRefund) } } if err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, sender, coinsToRefund); err != nil { - return sdkerrors.Wrap(err, "sending coins from module account") + return errors.Wrap(err, "sending coins from module account") } k.deleteUnbatchedSendToEthereum(ctx, send.Id, send.Erc20Fee) diff --git a/module/x/gravity/keeper/signer_set.go b/module/x/gravity/keeper/signer_set.go index e80f88b4c..60aea5776 100644 --- a/module/x/gravity/keeper/signer_set.go +++ b/module/x/gravity/keeper/signer_set.go @@ -3,8 +3,8 @@ package keeper import ( "sort" + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types" ) @@ -21,7 +21,7 @@ func (k Keeper) SignerSetExecuted(ctx sdk.Context, nonce uint64) { sstx, ok := otx.(*types.SignerSetTx) if !ok { - panic(sdkerrors.Wrapf(types.ErrInvalid, "couldn't cast to signer set for outgoing tx %s", otx)) + panic(errors.Wrapf(types.ErrInvalid, "couldn't cast to signer set for outgoing tx %s", otx)) } k.setLastObservedSignerSetTx(ctx, *sstx) @@ -38,7 +38,7 @@ func (k Keeper) GetUnsignedSignerSetTxs(ctx sdk.Context, val sdk.ValAddress) []* if len(sig) == 0 { signerSet, ok := cotx.(*types.SignerSetTx) if !ok { - panic(sdkerrors.Wrapf(types.ErrInvalid, "couldn't cast to signer set for completed tx %s", cotx)) + panic(errors.Wrapf(types.ErrInvalid, "couldn't cast to signer set for completed tx %s", cotx)) } unconfirmed = append(unconfirmed, signerSet) } @@ -49,7 +49,7 @@ func (k Keeper) GetUnsignedSignerSetTxs(ctx sdk.Context, val sdk.ValAddress) []* if len(sig) == 0 { signerSet, ok := otx.(*types.SignerSetTx) if !ok { - panic(sdkerrors.Wrapf(types.ErrInvalid, "couldn't cast to signer set for %s", otx)) + panic(errors.Wrapf(types.ErrInvalid, "couldn't cast to signer set for %s", otx)) } unconfirmed = append(unconfirmed, signerSet) } diff --git a/module/x/gravity/types/codec.go b/module/x/gravity/types/codec.go index 67163a57f..e5cb2d9b4 100644 --- a/module/x/gravity/types/codec.go +++ b/module/x/gravity/types/codec.go @@ -1,6 +1,7 @@ package types import ( + "cosmossdk.io/errors" "github.com/cosmos/gogoproto/proto" "github.com/cosmos/cosmos-sdk/codec" @@ -85,12 +86,12 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { func PackEvent(event EthereumEvent) (*types.Any, error) { msg, ok := event.(proto.Message) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", event) + return nil, errors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", event) } anyEvent, err := types.NewAnyWithValue(msg) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrPackAny, err.Error()) + return nil, errors.Wrap(sdkerrors.ErrPackAny, err.Error()) } return anyEvent, nil @@ -100,12 +101,12 @@ func PackEvent(event EthereumEvent) (*types.Any, error) { // event can't be unpacked. func UnpackEvent(any *types.Any) (EthereumEvent, error) { if any == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnpackAny, "protobuf Any message cannot be nil") + return nil, errors.Wrap(sdkerrors.ErrUnpackAny, "protobuf Any message cannot be nil") } event, ok := any.GetCachedValue().(EthereumEvent) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into EthereumEvent %T", any) + return nil, errors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into EthereumEvent %T", any) } return event, nil @@ -114,12 +115,12 @@ func UnpackEvent(any *types.Any) (EthereumEvent, error) { func PackConfirmation(confirmation EthereumTxConfirmation) (*types.Any, error) { msg, ok := confirmation.(proto.Message) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", confirmation) + return nil, errors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", confirmation) } anyEvent, err := types.NewAnyWithValue(msg) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrPackAny, err.Error()) + return nil, errors.Wrap(sdkerrors.ErrPackAny, err.Error()) } return anyEvent, nil @@ -129,12 +130,12 @@ func PackConfirmation(confirmation EthereumTxConfirmation) (*types.Any, error) { // confirmation can't be unpacked. func UnpackConfirmation(any *types.Any) (EthereumTxConfirmation, error) { if any == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnpackAny, "protobuf Any message cannot be nil") + return nil, errors.Wrap(sdkerrors.ErrUnpackAny, "protobuf Any message cannot be nil") } confirm, ok := any.GetCachedValue().(EthereumTxConfirmation) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into EthereumSignature %T", any) + return nil, errors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into EthereumSignature %T", any) } return confirm, nil @@ -143,12 +144,12 @@ func UnpackConfirmation(any *types.Any) (EthereumTxConfirmation, error) { func PackOutgoingTx(outgoing OutgoingTx) (*types.Any, error) { msg, ok := outgoing.(proto.Message) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", outgoing) + return nil, errors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", outgoing) } anyEvent, err := types.NewAnyWithValue(msg) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrPackAny, err.Error()) + return nil, errors.Wrap(sdkerrors.ErrPackAny, err.Error()) } return anyEvent, nil @@ -156,12 +157,12 @@ func PackOutgoingTx(outgoing OutgoingTx) (*types.Any, error) { func UnpackOutgoingTx(any *types.Any) (OutgoingTx, error) { if any == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnpackAny, "protobuf Any message cannot be nil") + return nil, errors.Wrap(sdkerrors.ErrUnpackAny, "protobuf Any message cannot be nil") } confirm, ok := any.GetCachedValue().(OutgoingTx) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into OutgoingTx %T", any) + return nil, errors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into OutgoingTx %T", any) } return confirm, nil diff --git a/module/x/gravity/types/errors.go b/module/x/gravity/types/errors.go index 35ae889b7..2cec13a28 100644 --- a/module/x/gravity/types/errors.go +++ b/module/x/gravity/types/errors.go @@ -1,19 +1,19 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "cosmossdk.io/errors" ) var ( - ErrInvalid = sdkerrors.Register(ModuleName, 3, "invalid") - ErrSupplyOverflow = sdkerrors.Register(ModuleName, 4, "malicious ERC20 with invalid supply sent over bridge") - ErrDelegateKeys = sdkerrors.Register(ModuleName, 5, "failed to delegate keys") - ErrEmptyEthSig = sdkerrors.Register(ModuleName, 6, "empty Ethereum signature") - ErrInvalidERC20Event = sdkerrors.Register(ModuleName, 7, "invalid ERC20 deployed event") - ErrInvalidEthereumProposalRecipient = sdkerrors.Register(ModuleName, 8, "invalid community pool Ethereum spend proposal recipient") - ErrInvalidEthereumProposalAmount = sdkerrors.Register(ModuleName, 9, "invalid community pool Ethereum spend proposal amount") - ErrInvalidEthereumProposalBridgeFee = sdkerrors.Register(ModuleName, 10, "invalid community pool Ethereum spend proposal bridge fee") - ErrEthereumProposalDenomMismatch = sdkerrors.Register(ModuleName, 11, "community pool Ethereum spend proposal amount and bridge fee denom mismatch") - ErrInvalidValidatorAddress = sdkerrors.Register(ModuleName, 12, "invalid validator address") - ErrInvalidOrchestratorAddress = sdkerrors.Register(ModuleName, 13, "invalid orchestrator address") + ErrInvalid = errors.Register(ModuleName, 3, "invalid") + ErrSupplyOverflow = errors.Register(ModuleName, 4, "malicious ERC20 with invalid supply sent over bridge") + ErrDelegateKeys = errors.Register(ModuleName, 5, "failed to delegate keys") + ErrEmptyEthSig = errors.Register(ModuleName, 6, "empty Ethereum signature") + ErrInvalidERC20Event = errors.Register(ModuleName, 7, "invalid ERC20 deployed event") + ErrInvalidEthereumProposalRecipient = errors.Register(ModuleName, 8, "invalid community pool Ethereum spend proposal recipient") + ErrInvalidEthereumProposalAmount = errors.Register(ModuleName, 9, "invalid community pool Ethereum spend proposal amount") + ErrInvalidEthereumProposalBridgeFee = errors.Register(ModuleName, 10, "invalid community pool Ethereum spend proposal bridge fee") + ErrEthereumProposalDenomMismatch = errors.Register(ModuleName, 11, "community pool Ethereum spend proposal amount and bridge fee denom mismatch") + ErrInvalidValidatorAddress = errors.Register(ModuleName, 12, "invalid validator address") + ErrInvalidOrchestratorAddress = errors.Register(ModuleName, 13, "invalid orchestrator address") ) diff --git a/module/x/gravity/types/ethereum_event.go b/module/x/gravity/types/ethereum_event.go index ccc27d1bc..21928d712 100644 --- a/module/x/gravity/types/ethereum_event.go +++ b/module/x/gravity/types/ethereum_event.go @@ -5,6 +5,7 @@ import ( "crypto/sha256" "fmt" + "cosmossdk.io/errors" tmbytes "github.com/cometbft/cometbft/libs/bytes" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -115,16 +116,16 @@ func (stce *SendToCosmosEvent) Validate() error { return fmt.Errorf("event nonce cannot be 0") } if !common.IsHexAddress(stce.TokenContract) { - return sdkerrors.Wrap(ErrInvalid, "ethereum contract address") + return errors.Wrap(ErrInvalid, "ethereum contract address") } if stce.Amount.IsNegative() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "amount must be positive") + return errors.Wrap(sdkerrors.ErrInvalidCoins, "amount must be positive") } if !common.IsHexAddress(stce.EthereumSender) { - return sdkerrors.Wrap(ErrInvalid, "ethereum sender") + return errors.Wrap(ErrInvalid, "ethereum sender") } if _, err := sdk.AccAddressFromBech32(stce.CosmosReceiver); err != nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, stce.CosmosReceiver) + return errors.Wrap(sdkerrors.ErrInvalidAddress, stce.CosmosReceiver) } return nil } @@ -134,7 +135,7 @@ func (bee *BatchExecutedEvent) Validate() error { return fmt.Errorf("event nonce cannot be 0") } if !common.IsHexAddress(bee.TokenContract) { - return sdkerrors.Wrap(ErrInvalid, "ethereum contract address") + return errors.Wrap(ErrInvalid, "ethereum contract address") } return nil } @@ -151,7 +152,7 @@ func (e20de *ERC20DeployedEvent) Validate() error { return fmt.Errorf("event nonce cannot be 0") } if !common.IsHexAddress(e20de.TokenContract) { - return sdkerrors.Wrap(ErrInvalid, "ethereum contract address") + return errors.Wrap(ErrInvalid, "ethereum contract address") } if err := sdk.ValidateDenom(e20de.CosmosDenom); err != nil { return err diff --git a/module/x/gravity/types/ethereum_signature.go b/module/x/gravity/types/ethereum_signature.go index 02cd268dd..79f44852a 100644 --- a/module/x/gravity/types/ethereum_signature.go +++ b/module/x/gravity/types/ethereum_signature.go @@ -3,7 +3,7 @@ package types import ( "fmt" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "cosmossdk.io/errors" "github.com/ethereum/go-ethereum/common" ) @@ -54,7 +54,7 @@ func (u *SignerSetTxConfirmation) Validate() error { return fmt.Errorf("nonce must be set") } if !common.IsHexAddress(u.EthereumSigner) { - return sdkerrors.Wrap(ErrInvalid, "ethereum signer must be address") + return errors.Wrap(ErrInvalid, "ethereum signer must be address") } if u.Signature == nil { return fmt.Errorf("signature must be set") @@ -70,7 +70,7 @@ func (u *ContractCallTxConfirmation) Validate() error { return fmt.Errorf("invalidation scope must be set") } if !common.IsHexAddress(u.EthereumSigner) { - return sdkerrors.Wrap(ErrInvalid, "ethereum signer must be address") + return errors.Wrap(ErrInvalid, "ethereum signer must be address") } if u.Signature == nil { return fmt.Errorf("signature must be set") @@ -86,7 +86,7 @@ func (u *BatchTxConfirmation) Validate() error { return fmt.Errorf("token contract address must be valid ethereum address") } if !common.IsHexAddress(u.EthereumSigner) { - return sdkerrors.Wrap(ErrInvalid, "ethereum signer must be address") + return errors.Wrap(ErrInvalid, "ethereum signer must be address") } if u.Signature == nil { return fmt.Errorf("signature must be set") diff --git a/module/x/gravity/types/ethereum_signer.go b/module/x/gravity/types/ethereum_signer.go index 525583c83..90ead1fc2 100644 --- a/module/x/gravity/types/ethereum_signer.go +++ b/module/x/gravity/types/ethereum_signer.go @@ -6,7 +6,6 @@ import ( "math/big" "cosmossdk.io/errors" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" ) @@ -18,7 +17,7 @@ const ( // NewEthereumSignature creates a new signuature over a given byte array func NewEthereumSignature(hash []byte, privateKey *ecdsa.PrivateKey) ([]byte, error) { if privateKey == nil { - return nil, sdkerrors.Wrap(ErrInvalid, "did not pass in private key") + return nil, errors.Wrap(ErrInvalid, "did not pass in private key") } protectedHash := crypto.Keccak256Hash(append([]byte(signaturePrefix), hash...)) return crypto.Sign(protectedHash.Bytes(), privateKey) @@ -80,11 +79,11 @@ func ValidateEthereumSignature(hash []byte, signature []byte, ethAddress common. pubkey, err := crypto.SigToPub(crypto.Keccak256Hash(hash).Bytes(), sigCopy) if err != nil { - return sdkerrors.Wrapf(err, "signature to public key sig %x hash %x", sigCopy, hash) + return errors.Wrapf(err, "signature to public key sig %x hash %x", sigCopy, hash) } if addr := crypto.PubkeyToAddress(*pubkey); addr != ethAddress { - return sdkerrors.Wrapf(ErrInvalid, "signature not matching addr %x sig %x hash %x", addr, signature, hash) + return errors.Wrapf(ErrInvalid, "signature not matching addr %x sig %x hash %x", addr, signature, hash) } return nil diff --git a/module/x/gravity/types/genesis.go b/module/x/gravity/types/genesis.go index f8de6d063..5839201f8 100644 --- a/module/x/gravity/types/genesis.go +++ b/module/x/gravity/types/genesis.go @@ -5,9 +5,9 @@ import ( "fmt" "time" + "cosmossdk.io/errors" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/ethereum/go-ethereum/common" ) @@ -104,12 +104,12 @@ func EventVoteRecordPowerThreshold(totalPower sdk.Int) sdk.Int { // calling their validation functions func (s GenesisState) ValidateBasic() error { if err := s.Params.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "params") + return errors.Wrap(err, "params") } if len(s.DelegateKeys) != 0 { for _, delegateKey := range s.DelegateKeys { if err := delegateKey.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "delegates") + return errors.Wrap(err, "delegates") } } } @@ -150,55 +150,55 @@ func DefaultParams() *Params { // ValidateBasic checks that the parameters have valid values. func (p Params) ValidateBasic() error { if err := validateGravityID(p.GravityId); err != nil { - return sdkerrors.Wrap(err, "gravity id") + return errors.Wrap(err, "gravity id") } if err := validateContractHash(p.ContractSourceHash); err != nil { - return sdkerrors.Wrap(err, "contract hash") + return errors.Wrap(err, "contract hash") } if err := validateBridgeContractAddress(p.BridgeEthereumAddress); err != nil { - return sdkerrors.Wrap(err, "bridge contract address") + return errors.Wrap(err, "bridge contract address") } if err := validateBridgeChainID(p.BridgeChainId); err != nil { - return sdkerrors.Wrap(err, "bridge chain id") + return errors.Wrap(err, "bridge chain id") } if err := validateTargetEthTxTimeout(p.TargetEthTxTimeout); err != nil { - return sdkerrors.Wrap(err, "Batch timeout") + return errors.Wrap(err, "Batch timeout") } if err := validateAverageBlockTime(p.AverageBlockTime); err != nil { - return sdkerrors.Wrap(err, "Block time") + return errors.Wrap(err, "Block time") } if err := validateAverageEthereumBlockTime(p.AverageEthereumBlockTime); err != nil { - return sdkerrors.Wrap(err, "Ethereum block time") + return errors.Wrap(err, "Ethereum block time") } if err := validateSignedSignerSetTxsWindow(p.SignedSignerSetTxsWindow); err != nil { - return sdkerrors.Wrap(err, "signed blocks window") + return errors.Wrap(err, "signed blocks window") } if err := validateSignedBatchesWindow(p.SignedBatchesWindow); err != nil { - return sdkerrors.Wrap(err, "signed blocks window") + return errors.Wrap(err, "signed blocks window") } if err := validateEthereumSignaturesWindow(p.EthereumSignaturesWindow); err != nil { - return sdkerrors.Wrap(err, "signed blocks window") + return errors.Wrap(err, "signed blocks window") } if err := validateSlashFractionSignerSetTx(p.SlashFractionSignerSetTx); err != nil { - return sdkerrors.Wrap(err, "slash fraction signersettx") + return errors.Wrap(err, "slash fraction signersettx") } if err := validateSlashFractionBatch(p.SlashFractionBatch); err != nil { - return sdkerrors.Wrap(err, "slash fraction batch tx") + return errors.Wrap(err, "slash fraction batch tx") } if err := validateSlashFractionEthereumSignature(p.SlashFractionEthereumSignature); err != nil { - return sdkerrors.Wrap(err, "slash fraction ethereum signature") + return errors.Wrap(err, "slash fraction ethereum signature") } if err := validateSlashFractionConflictingEthereumSignature(p.SlashFractionConflictingEthereumSignature); err != nil { - return sdkerrors.Wrap(err, "slash fraction conflicting ethereum signature") + return errors.Wrap(err, "slash fraction conflicting ethereum signature") } if err := validateUnbondSlashingSignerSetTxsWindow(p.UnbondSlashingSignerSetTxsWindow); err != nil { - return sdkerrors.Wrap(err, "unbond slashing signersettx window") + return errors.Wrap(err, "unbond slashing signersettx window") } if err := validateEthereumEventVoteWindow(p.EthereumEventVoteWindow); err != nil { - return sdkerrors.Wrap(err, "event vote window") + return errors.Wrap(err, "event vote window") } if err := validateConfirmedOutgoingTxWindow(p.ConfirmedOutgoingTxWindow); err != nil { - return sdkerrors.Wrap(err, "confirmed outgoing tx window") + return errors.Wrap(err, "confirmed outgoing tx window") } return nil diff --git a/module/x/gravity/types/msgs.go b/module/x/gravity/types/msgs.go index 60e7657ac..501c6379a 100644 --- a/module/x/gravity/types/msgs.go +++ b/module/x/gravity/types/msgs.go @@ -3,6 +3,7 @@ package types import ( "fmt" + "cosmossdk.io/errors" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -41,13 +42,13 @@ func (msg MsgDelegateKeys) Type() string { return "delegate_keys" } // ValidateBasic performs stateless checks func (msg MsgDelegateKeys) ValidateBasic() (err error) { if _, err = sdk.ValAddressFromBech32(msg.ValidatorAddress); err != nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.ValidatorAddress) + return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.ValidatorAddress) } if _, err = sdk.AccAddressFromBech32(msg.OrchestratorAddress); err != nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.OrchestratorAddress) + return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.OrchestratorAddress) } if !common.IsHexAddress(msg.EthereumAddress) { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "ethereum address") + return errors.Wrap(sdkerrors.ErrInvalidAddress, "ethereum address") } if len(msg.EthSignature) == 0 { return ErrEmptyEthSig @@ -79,7 +80,7 @@ func (msg MsgSubmitEthereumEvent) Type() string { return "submit_ethereum_event" // ValidateBasic performs stateless checks func (msg MsgSubmitEthereumEvent) ValidateBasic() (err error) { if _, err = sdk.AccAddressFromBech32(msg.Signer); err != nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer) + return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer) } event, err := UnpackEvent(msg.Event) @@ -118,7 +119,7 @@ func (msg MsgSubmitEthereumTxConfirmation) Type() string { return "submit_ethere // ValidateBasic performs stateless checks func (msg MsgSubmitEthereumTxConfirmation) ValidateBasic() (err error) { if _, err = sdk.AccAddressFromBech32(msg.Signer); err != nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer) + return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer) } event, err := UnpackConfirmation(msg.Confirmation) @@ -170,24 +171,24 @@ func (msg MsgSendToEthereum) Type() string { return "send_to_eth" } // Checks if the Eth address is valid func (msg MsgSendToEthereum) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Sender) + return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.Sender) } // fee and send must be of the same denom // this check is VERY IMPORTANT if msg.Amount.Denom != msg.BridgeFee.Denom { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, + return errors.Wrap(sdkerrors.ErrInvalidCoins, fmt.Sprintf("fee and amount must be the same type %s != %s", msg.Amount.Denom, msg.BridgeFee.Denom)) } if !msg.Amount.IsValid() || msg.Amount.IsZero() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "amount") + return errors.Wrap(sdkerrors.ErrInvalidCoins, "amount") } if !msg.BridgeFee.IsValid() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "fee") + return errors.Wrap(sdkerrors.ErrInvalidCoins, "fee") } if !common.IsHexAddress(msg.EthereumRecipient) { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "ethereum address") + return errors.Wrap(sdkerrors.ErrInvalidAddress, "ethereum address") } return nil @@ -225,10 +226,10 @@ func (msg MsgCancelSendToEthereum) Type() string { return "cancel_send_to_ethere // ValidateBasic performs stateless checks func (msg MsgCancelSendToEthereum) ValidateBasic() error { if msg.Id == 0 { - return sdkerrors.Wrap(ErrInvalid, "Id cannot be 0") + return errors.Wrap(ErrInvalid, "Id cannot be 0") } if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Sender) + return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.Sender) } return nil } @@ -265,11 +266,11 @@ func (msg MsgEthereumHeightVote) Type() string { return "ethereum_height_vote" } // ValidateBasic performs stateless checks func (msg MsgEthereumHeightVote) ValidateBasic() error { if msg.EthereumHeight == 0 { - return sdkerrors.Wrap(ErrInvalid, "ethereum height cannot be 0") + return errors.Wrap(ErrInvalid, "ethereum height cannot be 0") } if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer) + return errors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer) } return nil diff --git a/module/x/gravity/types/outgoing_tx.go b/module/x/gravity/types/outgoing_tx.go index b9fac385c..a64ed1ffe 100644 --- a/module/x/gravity/types/outgoing_tx.go +++ b/module/x/gravity/types/outgoing_tx.go @@ -4,7 +4,7 @@ import ( "math/big" "strings" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "cosmossdk.io/errors" "github.com/ethereum/go-ethereum/accounts/abi" gethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -210,11 +210,11 @@ func (c ContractCallTx) GetCheckpoint(gravityID []byte) []byte { func packCall(abiString, method string, args []interface{}) []byte { encodedCall, err := abi.JSON(strings.NewReader(abiString)) if err != nil { - panic(sdkerrors.Wrap(err, "bad ABI definition in code")) + panic(errors.Wrap(err, "bad ABI definition in code")) } abiEncodedCall, err := encodedCall.Pack(method, args...) if err != nil { - panic(sdkerrors.Wrap(err, "packing checkpoint")) + panic(errors.Wrap(err, "packing checkpoint")) } return crypto.Keccak256Hash(abiEncodedCall[4:]).Bytes() } diff --git a/module/x/gravity/types/types.go b/module/x/gravity/types/types.go index 6332c12e9..c8b9fa9dc 100644 --- a/module/x/gravity/types/types.go +++ b/module/x/gravity/types/types.go @@ -6,8 +6,8 @@ import ( "math" "sort" + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/ethereum/go-ethereum/common" ) @@ -18,7 +18,7 @@ import ( // ValidateBasic performs stateless checks on validity func (b *EthereumSigner) ValidateBasic() error { if !common.IsHexAddress(b.EthereumAddress) { - return sdkerrors.Wrap(ErrInvalid, "ethereum address") + return errors.Wrap(ErrInvalid, "ethereum address") } return nil }