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

chore: bump ics29 to tip of main #900

Merged
merged 60 commits into from
Feb 10, 2022
Merged
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
0a7ad9b
removing unused proto imports in interchain-accounts (#718)
damiannolan Jan 12, 2022
dd9c385
Merge pull request #721 from cosmos/colin/694-fix-err-msg
colin-axner Jan 13, 2022
d882b43
refactor: move ica connection identifiers from port to version metada…
damiannolan Jan 13, 2022
a4b9517
make IsValidAddr private and extend regex to account for 0 length str…
colin-axner Jan 13, 2022
5f4a90c
Update LICENSE (#728)
Jan 13, 2022
5b7d362
refactor: allow ICA authentication module provided timeout timestamp …
colin-axner Jan 13, 2022
b0b52a3
Fix ambiguity in TimeoutTimestamp docs (#715)
assafmo Jan 13, 2022
e2693b0
bump docs json lock file to fix security vulnerability (#727)
colin-axner Jan 14, 2022
e28b6d1
fix: gogoproto yaml (#732)
seantking Jan 14, 2022
7415da7
refactor: no longer removing active channel mapping on close channel …
seantking Jan 14, 2022
8924ee6
refactor: reusable metadata validation (#729)
damiannolan Jan 14, 2022
e2ac503
remove amino, enforce serialize and deserialize functions to only acc…
colin-axner Jan 14, 2022
87bb391
fix: update IsRevisionFormat and IsClientIDFormat to account for newl…
colin-axner Jan 17, 2022
87b058d
add goreleaser github action to attach simd binary to releases and pr…
Jan 18, 2022
bfcf9ab
docs: ica tx atomicity docs and code snippet updates (#719)
damiannolan Jan 18, 2022
89ffaaf
deps: bump vuepress-theme-cosmos (#754)
Jan 18, 2022
4fb75e8
fix: remove error from ics27 channel ack (#751)
damiannolan Jan 20, 2022
60ed992
feat: adding helper fn to generate capability name for testing (#776)
seantking Jan 21, 2022
a6656a0
test: adding test for accessing interchain account after closing chan…
seantking Jan 21, 2022
f822756
Replace github.com/pkg/errors with stdlib errors (#775)
dkmccandless Jan 21, 2022
01c5848
update roadmap (#735)
Jan 22, 2022
e19623f
fix: resolve proto lint failure - buf.yaml (#781)
damiannolan Jan 24, 2022
d7bf2a8
feat: query host chain msg events via cli (#782)
damiannolan Jan 24, 2022
1da4885
docs: add MakeFile command to view docs locally (#788)
seantking Jan 26, 2022
8dfbc9c
fix: support custom chain IDs for testing (#774)
ramacarlucho Jan 26, 2022
3e6464b
chore: renaming API fns (#786)
seantking Jan 27, 2022
640ba14
build(deps): bump google.golang.org/grpc from 1.43.0 to 1.44.0 (#796)
dependabot[bot] Jan 27, 2022
4f70554
chore: restructure code logically (#804)
colin-axner Jan 27, 2022
19b5b5f
refactor: construct ics27 error acknowledgement with determinstic ABC…
colin-axner Jan 28, 2022
3c2f2eb
docs: active channel description (#787)
seantking Jan 28, 2022
54dc848
add helper function in testing package: RecvPacketWithResult (#810)
colin-axner Jan 28, 2022
f393893
chore: use connection ID in interchain account store keys (#791)
damiannolan Jan 28, 2022
90a175e
chore: remove unnecessary arg from RelayPacket testing function (#813)
colin-axner Jan 28, 2022
1c0bee5
chore: use host chain connection id in ica address generation (#790)
damiannolan Jan 28, 2022
d8c74f4
docs: adding ica docs for exclusive submodule app wiring (#809)
damiannolan Jan 28, 2022
25fb89d
Defensive checks for active channel (#785)
seantking Jan 31, 2022
20e5dd9
Add stable release policy (#685)
colin-axner Feb 1, 2022
f7bb142
build(deps): bump github.com/cosmos/cosmos-sdk from 0.44.5 to 0.45.0 …
dependabot[bot] Feb 2, 2022
8cba0eb
rename portid and port prefix for interchain accounts submodules (#779)
Feb 2, 2022
83c3e41
test: adding ica test for multiple controllers, single host (#816)
damiannolan Feb 2, 2022
142056f
the ica_auth page was renamed to auth-modules (#792)
Feb 2, 2022
ac46ac0
chore: replace error string in transfer acks with const (#818)
damiannolan Feb 2, 2022
4c28c1c
refactor: active channel key format (#823)
seantking Feb 2, 2022
fed6a86
refactor: RegisterInterchainAccount (#814)
seantking Feb 2, 2022
bbcc09c
refactor: reformat KeyOwnerAccount (#833)
seantking Feb 2, 2022
5ae8e35
chore: adding encoding and txType fields to metadata (#824)
damiannolan Feb 2, 2022
6c48f7e
refactor: include transaction response in ics27 channel acknowledgeme…
colin-axner Feb 2, 2022
1021617
ADR 003: ICS27 Ack format (#812)
colin-axner Feb 3, 2022
c7ea0e8
test: ensure ics27 optimistic packet sends are disallowed (#842)
damiannolan Feb 3, 2022
ec36c75
docs: add security model to ics27 docs (#841)
colin-axner Feb 3, 2022
f6a9279
test: Register using same owner address on multiple connections (#846)
seantking Feb 4, 2022
81b619d
Move emissions to functions (#783)
nir1218 Feb 7, 2022
7b7eb9f
Added ChannelId to MsgChannelOpenInitResponse (#848)
rigelrozanski Feb 7, 2022
c378ff3
build(deps): bump github.com/cosmos/cosmos-sdk from 0.45.0 to 0.45.1 …
dependabot[bot] Feb 7, 2022
31487bc
fix: ica host OnRecvPacket error acknowledgement (#885)
damiannolan Feb 8, 2022
482b7ab
chore: add defensive check to ensure metadata does not change when re…
colin-axner Feb 8, 2022
acbc9b6
refactor: WriteAcknowledgement API (#882)
seantking Feb 9, 2022
d5e2ba5
bug: use custom ante handler to reject redundant transactions in sima…
Feb 9, 2022
8f62a47
refactor: allow the mock module to be used multiple times as base ibc…
colin-axner Feb 10, 2022
e0161a7
Merge branch 'main' of github.com:cosmos/ibc-go into ics29-fee-middle…
colin-axner Feb 10, 2022
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
Prev Previous commit
Next Next commit
chore: add defensive check to ensure metadata does not change when re…
…opening an active channel (#847)

## Description



closes: #795 

---

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

- [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
- [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md).
- [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing)
- [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`)
- [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code).
- [ ] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md`
- [ ] Re-reviewed `Files changed` in the Github PR explorer
- [ ] Review `Codecov Report` in the comment section below once CI passes
  • Loading branch information
colin-axner authored Feb 8, 2022
commit 482b7abb097488b3931637e43fa5a958e3af5e07
16 changes: 14 additions & 2 deletions modules/apps/27-interchain-accounts/controller/keeper/handshake.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
@@ -49,9 +50,20 @@ func (k Keeper) OnChanOpenInit(
return err
}

activeChannelID, found := k.GetOpenActiveChannel(ctx, connectionHops[0], portID)
activeChannelID, found := k.GetActiveChannelID(ctx, connectionHops[0], portID)
if found {
return sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s", activeChannelID, portID)
channel, found := k.channelKeeper.GetChannel(ctx, portID, activeChannelID)
if !found {
panic(fmt.Sprintf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID))
}

if channel.State == channeltypes.OPEN {
return sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID)
}

if !icatypes.IsPreviousMetadataEqual(channel.Version, metadata) {
return sdkerrors.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version")
}
}

return nil
Original file line number Diff line number Diff line change
@@ -30,6 +30,51 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
},
true,
},
{
"success - previous active channel closed",
func() {
suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
channel := channeltypes.Channel{
State: channeltypes.CLOSED,
Ordering: channeltypes.ORDERED,
Counterparty: counterparty,
ConnectionHops: []string{path.EndpointA.ConnectionID},
Version: TestVersion,
}

path.EndpointA.SetChannel(channel)
},
true,
},
{
"invalid metadata - previous metadata is different",
func() {
// set active channel to closed
suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
closedChannel := channeltypes.Channel{
State: channeltypes.CLOSED,
Ordering: channeltypes.ORDERED,
Counterparty: counterparty,
ConnectionHops: []string{path.EndpointA.ConnectionID},
Version: TestVersion,
}

path.EndpointA.SetChannel(closedChannel)

// modify metadata
metadata.Version = "ics27-2"

versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata)
suite.Require().NoError(err)

channel.Version = string(versionBytes)
},
false,
},
{
"invalid order - UNORDERED",
func() {
21 changes: 17 additions & 4 deletions modules/apps/27-interchain-accounts/host/keeper/handshake.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
@@ -47,8 +48,20 @@ func (k Keeper) OnChanOpenTry(
return "", err
}

if activeChannelID, found := k.GetOpenActiveChannel(ctx, connectionHops[0], counterparty.PortId); found {
return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s", activeChannelID, portID)
activeChannelID, found := k.GetActiveChannelID(ctx, connectionHops[0], counterparty.PortId)
if found {
channel, found := k.channelKeeper.GetChannel(ctx, portID, activeChannelID)
if !found {
panic(fmt.Sprintf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID))
}

if channel.State == channeltypes.OPEN {
return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID)
}

if !icatypes.IsPreviousMetadataEqual(channel.Version, metadata) {
return "", sdkerrors.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version")
}
}

// On the host chain the capability may only be claimed during the OnChanOpenTry
@@ -83,9 +96,9 @@ func (k Keeper) OnChanOpenConfirm(
}

// It is assumed the controller chain will not allow multiple active channels to be created for the same connectionID/portID
// If the controller chain does allow multiple active channels to be created for the same connectionID/portID,
// If the controller chain does allow multiple active channels to be created for the same connectionID/portID,
// disallowing overwriting the current active channel guarantees the channel can no longer be used as the controller
// and host will disagree on what the currently active channel is
// and host will disagree on what the currently active channel is
k.SetActiveChannelID(ctx, channel.ConnectionHops[0], channel.Counterparty.PortId, channelID)

return nil
Original file line number Diff line number Diff line change
@@ -30,6 +30,36 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
},
true,
},
{
"success - reopening closed active channel",
func() {
// create a new channel and set it in state
ch := channeltypes.NewChannel(channeltypes.CLOSED, channeltypes.ORDERED, channeltypes.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID), []string{path.EndpointA.ConnectionID}, TestVersion)
suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, ch)

// set the active channelID in state
suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID)
}, true,
},
{
"invalid metadata - previous metadata is different",
func() {
// create a new channel and set it in state
ch := channeltypes.NewChannel(channeltypes.CLOSED, channeltypes.ORDERED, channeltypes.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID), []string{path.EndpointA.ConnectionID}, TestVersion)
suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, ch)

// set the active channelID in state
suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID)

// modify metadata
metadata.Version = "ics27-2"

versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata)
suite.Require().NoError(err)

path.EndpointA.ChannelConfig.Version = string(versionBytes)
}, false,
},
{
"invalid order - UNORDERED",
func() {
@@ -140,7 +170,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
func() {
// create a new channel and set it in state
ch := channeltypes.NewChannel(channeltypes.OPEN, channeltypes.ORDERED, channeltypes.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID), []string{path.EndpointA.ConnectionID}, ibctesting.DefaultChannelVersion)
suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID, ch)
suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, ch)

// set the active channelID in state
suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID)
15 changes: 15 additions & 0 deletions modules/apps/27-interchain-accounts/types/metadata.go
Original file line number Diff line number Diff line change
@@ -27,6 +27,21 @@ func NewMetadata(version, controllerConnectionID, hostConnectionID, accAddress,
}
}

// IsPreviousMetadataEqual compares a metadata to a previous version string set in a channel struct.
// It ensures all fields are equal except the Address string
func IsPreviousMetadataEqual(previousVersion string, metadata Metadata) bool {
var previousMetadata Metadata
if err := ModuleCdc.UnmarshalJSON([]byte(previousVersion), &previousMetadata); err != nil {
return false
}

return (previousMetadata.Version == metadata.Version &&
previousMetadata.ControllerConnectionId == metadata.ControllerConnectionId &&
previousMetadata.HostConnectionId == metadata.HostConnectionId &&
previousMetadata.Encoding == metadata.Encoding &&
previousMetadata.TxType == metadata.TxType)
}

// ValidateControllerMetadata performs validation of the provided ICS27 controller metadata parameters
func ValidateControllerMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connectionHops []string, metadata Metadata) error {
if !isSupportedEncoding(metadata.Encoding) {
121 changes: 121 additions & 0 deletions modules/apps/27-interchain-accounts/types/metadata_test.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,127 @@ import (
ibctesting "github.com/cosmos/ibc-go/v3/testing"
)

// use TestVersion as metadata being compared against
func (suite *TypesTestSuite) TestIsPreviousMetadataEqual() {

var (
metadata types.Metadata
previousVersion string
)

testCases := []struct {
name string
malleate func()
expEqual bool
}{
{
"success",
func() {
versionBytes, err := types.ModuleCdc.MarshalJSON(&metadata)
suite.Require().NoError(err)
previousVersion = string(versionBytes)
},
true,
},
{
"success with empty account address",
func() {
metadata.Address = ""

versionBytes, err := types.ModuleCdc.MarshalJSON(&metadata)
suite.Require().NoError(err)
previousVersion = string(versionBytes)
},
true,
},
{
"cannot decode previous version",
func() {
previousVersion = "invalid previous version"
},
false,
},
{
"unequal encoding format",
func() {
metadata.Encoding = "invalid-encoding-format"

versionBytes, err := types.ModuleCdc.MarshalJSON(&metadata)
suite.Require().NoError(err)
previousVersion = string(versionBytes)
},
false,
},
{
"unequal transaction type",
func() {
metadata.TxType = "invalid-tx-type"

versionBytes, err := types.ModuleCdc.MarshalJSON(&metadata)
suite.Require().NoError(err)
previousVersion = string(versionBytes)
},
false,
},
{
"unequal controller connection",
func() {
metadata.ControllerConnectionId = "connection-10"

versionBytes, err := types.ModuleCdc.MarshalJSON(&metadata)
suite.Require().NoError(err)
previousVersion = string(versionBytes)
},
false,
},
{
"unequal host connection",
func() {
metadata.HostConnectionId = "connection-10"

versionBytes, err := types.ModuleCdc.MarshalJSON(&metadata)
suite.Require().NoError(err)
previousVersion = string(versionBytes)
},
false,
},
{
"unequal version",
func() {
metadata.Version = "invalid version"

versionBytes, err := types.ModuleCdc.MarshalJSON(&metadata)
suite.Require().NoError(err)
previousVersion = string(versionBytes)
},
false,
},
}

for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
suite.SetupTest() // reset

path := ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.SetupConnections(path)

expectedMetadata := types.NewMetadata(types.Version, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID, TestOwnerAddress, types.EncodingProtobuf, types.TxTypeSDKMultiMsg)
metadata = expectedMetadata // default success case

tc.malleate() // malleate mutates test data

equal := types.IsPreviousMetadataEqual(previousVersion, expectedMetadata)

if tc.expEqual {
suite.Require().True(equal)
} else {
suite.Require().False(equal)
}
})
}
}

func (suite *TypesTestSuite) TestValidateControllerMetadata() {

var metadata types.Metadata