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 9325266
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 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
18 changes: 10 additions & 8 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 @@ -327,13 +327,12 @@ impl core::ClientUpdate {

header_mmr_index = curr_cached_header.inner.slot - client.minimal_slot;

let position = leaf_index_to_pos(header_mmr_index);
trace!(
"first header (slot: {}) in MMR on index {header_mmr_index}, position {position}",
"first header (slot: {}) in MMR on index {header_mmr_index}",
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 @@ -368,13 +367,12 @@ impl core::ClientUpdate {
curr_tip_valid_header_root = curr_cached_header.root;
}

let position = leaf_index_to_pos(header_mmr_index);
trace!(
"current header (slot: {}) in MMR on index {header_mmr_index}, position {position}",
"current header (slot: {}) in MMR on index {header_mmr_index}",
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 +395,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 9325266

Please sign in to comment.