Skip to content

Commit

Permalink
feat: verifies new MMR = old MMR + all incremental headers
Browse files Browse the repository at this point in the history
  • Loading branch information
yangby-cryptape committed Jul 19, 2023
1 parent 28d102f commit 0f9febb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion verification/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository = "https://github.com/synapseweb3/eth-light-client-in-ckb"

[dependencies]
molecule = { version = "=0.7.5", default-features = false }
ckb-mmr = { version = "0.5.2", default-features = false, package = "ckb-merkle-mountain-range" }
ckb-mmr = { version = "0.6.0", default-features = false, package = "ckb-merkle-mountain-range" }
rlp = { version = "0.5.2", default-features = false }
ethereum-types = { version = "0.14.1", default-features = false }
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
Expand Down
12 changes: 8 additions & 4 deletions verification/src/types/extension/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl core::ClientUpdate {
let mut prev_cached_header: mmr::HeaderWithCache;
let mut curr_tip_valid_header_root: core::Hash;
let mut header_mmr_index: u64;
let mut digests_with_positions = Vec::with_capacity(headers_count);
let mut digests = Vec::with_capacity(headers_count);

// Check First Header with the Old Client
{
Expand Down Expand Up @@ -333,7 +333,7 @@ impl core::ClientUpdate {
curr_cached_header.inner.slot
);
let digest = curr_cached_header.packed_digest();
digests_with_positions.push((position, digest));
digests.push(digest);

header_mmr_index += 1;
prev_cached_header = curr_cached_header;
Expand Down Expand Up @@ -374,7 +374,7 @@ impl core::ClientUpdate {
curr_cached_header.inner.slot
);
let digest = curr_cached_header.packed_digest();
digests_with_positions.push((position, digest));
digests.push(digest);

header_mmr_index += 1;
prev_cached_header = curr_cached_header;
Expand All @@ -397,7 +397,11 @@ impl core::ClientUpdate {
mmr::MMRProof::new(mmr_size, proof)
};
let result = proof
.verify(new_client.headers_mmr_root.pack(), digests_with_positions)
.verify_incremental(
new_client.headers_mmr_root.pack(),
client.headers_mmr_root.pack(),
digests,
)
.map_err(|_| ClientUpdateError::MmrError)?;
if !result {
warn!(
Expand Down

0 comments on commit 0f9febb

Please sign in to comment.