Skip to content

Commit

Permalink
ibc: proof fixes (#7869)
Browse files Browse the repository at this point in the history
* change proof proto def

* progress fixing tests

* complete proof restructure

* remove use of KeyPath

* improve error msgs

* docs and lint

* Apply suggestions from code review

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* address code review

* fix string tests

* add ConvertProofs tests

* Apply suggestions from code review

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 10, 2020
1 parent 15b285d commit fdcb028
Show file tree
Hide file tree
Showing 19 changed files with 978 additions and 1,275 deletions.
38 changes: 7 additions & 31 deletions proto/ibc/core/commitment/v1/commitment.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package ibc.core.commitment.v1;
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/core/23-commitment/types";

import "gogoproto/gogo.proto";
import "tendermint/crypto/proof.proto";
import "confio/proofs.proto";

// MerkleRoot defines a merkle root hash.
// In the Cosmos SDK, the AppHash of a block header becomes the root.
Expand All @@ -23,42 +23,18 @@ message MerklePrefix {

// MerklePath is the path used to verify commitment proofs, which can be an
// arbitrary structured object (defined by a commitment type).
// MerklePath is represented from root-to-leaf
message MerklePath {
option (gogoproto.goproto_stringer) = false;

KeyPath key_path = 1 [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"key_path\""];
repeated string key_path = 1 [(gogoproto.moretags) = "yaml:\"key_path\""];
}

// MerkleProof is a wrapper type that contains a merkle proof.
// MerkleProof is a wrapper type over a chain of CommitmentProofs.
// It demonstrates membership or non-membership for an element or set of
// elements, verifiable in conjunction with a known commitment root. Proofs
// should be succinct.
// MerkleProofs are ordered from leaf-to-root
message MerkleProof {
tendermint.crypto.ProofOps proof = 1;
}

// KeyPath defines a slice of keys
message KeyPath {
option (gogoproto.goproto_stringer) = false;
option (gogoproto.goproto_getters) = false;

repeated Key keys = 1;
}

// Key defines a proof Key
message Key {
option (gogoproto.goproto_getters) = false;

bytes name = 1;
KeyEncoding enc = 2;
}

// KeyEncoding defines the encoding format of a key's bytes.
enum KeyEncoding {
option (gogoproto.goproto_enum_prefix) = false;

// URL encoding
KEY_ENCODING_URL_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "URL"];
// Hex encoding
KEY_ENCODING_HEX = 1 [(gogoproto.enumvalue_customname) = "HEX"];
}
repeated ics23.CommitmentProof proofs = 1;
}
5 changes: 3 additions & 2 deletions x/ibc/core/03-connection/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ func (suite *MsgTestSuite) SetupTest() {
Prove: true,
})

merkleProof := commitmenttypes.MerkleProof{Proof: res.ProofOps}
merkleProof, err := commitmenttypes.ConvertProofs(res.ProofOps)
suite.Require().NoError(err)
proof, err := app.AppCodec().MarshalBinaryBare(&merkleProof)
suite.NoError(err)
suite.Require().NoError(err)

suite.proof = proof

Expand Down
3 changes: 3 additions & 0 deletions x/ibc/core/04-channel/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2)
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(0))
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(1))
// commit some blocks so that QueryProof returns valid proof (cannot return valid query if height <= 1)
suite.coordinator.CommitNBlocks(suite.chainA, 2)
suite.coordinator.CommitNBlocks(suite.chainB, 2)
}

// TestSetChannel create clients and connections on both chains. It tests for the non-existence
Expand Down
5 changes: 3 additions & 2 deletions x/ibc/core/04-channel/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ func (suite *TypesTestSuite) SetupTest() {
Prove: true,
})

merkleProof := commitmenttypes.MerkleProof{Proof: res.ProofOps}
merkleProof, err := commitmenttypes.ConvertProofs(res.ProofOps)
suite.Require().NoError(err)
proof, err := app.AppCodec().MarshalBinaryBare(&merkleProof)
suite.NoError(err)
suite.Require().NoError(err)

suite.proof = proof
}
Expand Down
Loading

0 comments on commit fdcb028

Please sign in to comment.