Skip to content

Commit

Permalink
light-clients: make prefix empty for both cf-solana and cf-guest (#396)
Browse files Browse the repository at this point in the history
Since prefix is expected to be empty, send empty prefixes when verifying
proofs.

---------

Co-authored-by: Michal Nazarewicz <mina86@mina86.com>
  • Loading branch information
dhruvja and mina86 authored Oct 16, 2024
1 parent 6778472 commit 9ef816d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
10 changes: 6 additions & 4 deletions common/cf-guest/src/client/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,17 @@ impl<PK: PubKey> ibc::ClientStateCommon for ClientState<PK> {
/// See [`proof::verify`] for documentation of the proof format.
fn verify_membership(
&self,
prefix: &ibc::CommitmentPrefix,
_prefix: &ibc::CommitmentPrefix,
proof: &ibc::CommitmentProofBytes,
root: &ibc::CommitmentRoot,
path: ibc::path::Path,
value: Vec<u8>,
) -> Result {
let value = Some(value.as_slice());
// TODO: Once IBC is updated everywhere to version which supports empty
// prefixes, change `&[]` with `prefix.as_bytes()`.
proof::verify_for_block(
prefix.as_bytes(),
&[],
proof.as_ref(),
root.as_bytes(),
path,
Expand All @@ -221,13 +223,13 @@ impl<PK: PubKey> ibc::ClientStateCommon for ClientState<PK> {
/// See [`proof::verify`] for documentation of the proof format.
fn verify_non_membership(
&self,
prefix: &ibc::CommitmentPrefix,
_prefix: &ibc::CommitmentPrefix,
proof: &ibc::CommitmentProofBytes,
root: &ibc::CommitmentRoot,
path: ibc::path::Path,
) -> Result {
proof::verify_for_block(
prefix.as_bytes(),
&[],
proof.as_ref(),
root.as_bytes(),
path,
Expand Down
16 changes: 5 additions & 11 deletions common/cf-solana/src/client/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ impl ibc::ClientStateCommon for ClientState {
/// See [`proof::verify`] for documentation of the proof format.
fn verify_membership(
&self,
prefix: &ibc::CommitmentPrefix,
_prefix: &ibc::CommitmentPrefix,
proof: &ibc::CommitmentProofBytes,
root: &ibc::CommitmentRoot,
path: ibc::path::Path,
value: Vec<u8>,
) -> Result {
let value = Some(value.as_slice());
proof::verify_for_trie(
prefix.as_bytes(),
&[],
proof.as_ref(),
root.as_bytes(),
path,
Expand All @@ -154,19 +154,13 @@ impl ibc::ClientStateCommon for ClientState {
/// See [`proof::verify`] for documentation of the proof format.
fn verify_non_membership(
&self,
prefix: &ibc::CommitmentPrefix,
_prefix: &ibc::CommitmentPrefix,
proof: &ibc::CommitmentProofBytes,
root: &ibc::CommitmentRoot,
path: ibc::path::Path,
) -> Result {
proof::verify_for_trie(
prefix.as_bytes(),
proof.as_ref(),
root.as_bytes(),
path,
None,
)
.map_err(Into::into)
proof::verify_for_trie(&[], proof.as_ref(), root.as_bytes(), path, None)
.map_err(Into::into)
}
}

Expand Down

0 comments on commit 9ef816d

Please sign in to comment.