-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
WIP: Fix ICS23-Proofs #6178
WIP: Fix ICS23-Proofs #6178
Changes from 1 commit
73462b2
59d5fd1
567fc51
2da7b0d
4c38f3e
dba44d8
d26a2d8
f605880
6c66834
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ import ( | |
|
||
"github.com/tendermint/tendermint/crypto/merkle" | ||
|
||
"github.com/cosmos/cosmos-sdk/store/rootmulti" | ||
ics23 "github.com/confio/ics23/go" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" | ||
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" | ||
) | ||
|
@@ -145,7 +146,8 @@ var _ exported.Proof = MerkleProof{} | |
// verifiable in conjunction with a known commitment root. Proofs should be | ||
// succinct. | ||
type MerkleProof struct { | ||
Proof *merkle.Proof `json:"proof" yaml:"proof"` | ||
Proof *ics23.CommitmentProof `json:"proof" yaml:"proof"` | ||
Spec *ics23.ProofSpec `json:"spec" yaml:"spec"` | ||
} | ||
|
||
// GetCommitmentType implements ProofI | ||
|
@@ -156,26 +158,31 @@ func (MerkleProof) GetCommitmentType() exported.Type { | |
// VerifyMembership verifies the membership pf a merkle proof against the given root, path, and value. | ||
func (proof MerkleProof) VerifyMembership(root exported.Root, path exported.Path, value []byte) error { | ||
if proof.IsEmpty() || root == nil || root.IsEmpty() || path == nil || path.IsEmpty() || len(value) == 0 { | ||
return errors.New("empty params or proof") | ||
return sdkerrors.Wrap(ErrInvalidProof, "empty params or proof") | ||
} | ||
|
||
runtime := rootmulti.DefaultProofRuntime() | ||
return runtime.VerifyValue(proof.Proof, root.GetHash(), path.String(), value) | ||
if !ics23.VerifyMembership(proof.Spec, root.GetHash(), proof.Proof, []byte(path.String()), value) { | ||
return sdkerrors.Wrapf(ErrInvalidProof, "invalid proof for path: %s", path.String()) | ||
} | ||
return nil | ||
} | ||
|
||
// VerifyNonMembership verifies the absence of a merkle proof against the given root and path. | ||
func (proof MerkleProof) VerifyNonMembership(root exported.Root, path exported.Path) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently VerifyNonMembership will verify absence at the smallest subtree, and then prove inclusion of all subtree upto the root. Thus in the multistore example, we can prove absence of a value in the ibc store, but we can't use this to prove that That seems sufficient for all ibc usecases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine, let's just make sure we panic if we ever try to check a proof of absence of |
||
if proof.IsEmpty() || root == nil || root.IsEmpty() || path == nil || path.IsEmpty() { | ||
return errors.New("empty params or proof") | ||
return sdkerrors.Wrap(ErrInvalidProof, "empty params or proof") | ||
} | ||
|
||
runtime := rootmulti.DefaultProofRuntime() | ||
return runtime.VerifyAbsence(proof.Proof, root.GetHash(), path.String()) | ||
if !ics23.VerifyNonMembership(proof.Spec, root.GetHash(), proof.Proof, []byte(path.String())) { | ||
return sdkerrors.Wrapf(ErrInvalidProof, "invalid proof for path: %s", path.String()) | ||
} | ||
return nil | ||
|
||
} | ||
|
||
// IsEmpty returns true if the root is empty | ||
fedekunze marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func (proof MerkleProof) IsEmpty() bool { | ||
return (proof == MerkleProof{}) || proof.Proof == nil | ||
return proof.Proof == nil || proof.Spec == nil | ||
} | ||
|
||
// ValidateBasic checks if the proof is empty. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the
key
in the confioVerifyMembership
function the path? Or is it the last element of the path?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume it's the full path