Skip to content
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

feat: verifies new MMR = old MMR + all incremental headers #13

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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