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

imp: added more assertions in verify_header #415

Merged
merged 4 commits into from
Mar 17, 2025
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
Binary file modified e2e/interchaintestv8/wasm/cw_ics08_wasm_eth.wasm.gz
Binary file not shown.
15 changes: 14 additions & 1 deletion packages/ethereum/ethereum-light-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ pub enum EthereumIBCError {
)]
ExpectedCurrentSyncCommittee,

#[error("expected next sync committee to be provided since `update_period > current_period`")]
#[error("expected next sync committee to be provided for signature verification`")]
ExpectedNextSyncCommittee,

#[error("expected next sync committee to be provided in the update since `update_period > current_period`")]
ExpectedNextSyncCommitteeUpdate,

#[error("expected next sync committee to be known and stored in state")]
NextSyncCommitteeUnknown,

Expand Down Expand Up @@ -164,6 +167,16 @@ pub enum EthereumIBCError {

#[error("storage roots are not conflicting: {0} == {0}")]
MisbehaviourStorageRootsMatch(B256),

#[error(
"historical updates are not allowed: \
stored consensus state slot: {consensus_state_slot}, \
update finalized header slot: {update_finalized_slot}"
)]
HistoricalUpdateNotAllowed {
consensus_state_slot: u64,
update_finalized_slot: u64,
},
}

#[derive(Debug, PartialEq, Eq, Clone, thiserror::Error)]
Expand Down
28 changes: 23 additions & 5 deletions packages/ethereum/ethereum-light-client/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,26 @@ pub fn verify_header<V: BlsVerify>(
EthereumIBCError::NotEnoughSignatures
);

let proof_data = header.account_update.account_proof.clone();
print!("{proof_data:?}");
// check whether the update is for a newer height
ensure!(
header.consensus_update.finalized_header.beacon.slot > consensus_state.slot,
EthereumIBCError::HistoricalUpdateNotAllowed {
consensus_state_slot: consensus_state.slot,
update_finalized_slot: header.consensus_update.finalized_header.beacon.slot
}
);

// check that if the period changes, then the next sync committee is provided
let update_finalized_period = client_state.compute_sync_committee_period_at_slot(
header.consensus_update.finalized_header.beacon.slot,
);
let store_period = client_state.compute_sync_committee_period_at_slot(consensus_state.slot);
if update_finalized_period > store_period {
ensure!(
header.consensus_update.next_sync_committee_branch.is_some(),
EthereumIBCError::ExpectedNextSyncCommitteeUpdate
);
}

verify_account_storage_root(
header
Expand All @@ -100,8 +118,8 @@ pub fn verify_header<V: BlsVerify>(
.execution
.state_root,
client_state.ibc_contract_address,
&proof_data.proof,
proof_data.storage_root,
&header.account_update.account_proof.proof,
header.account_update.account_proof.storage_root,
)
.map_err(|err| EthereumIBCError::VerifyStorageProof(err.to_string()))
}
Expand Down Expand Up @@ -246,7 +264,7 @@ pub fn validate_light_client_update<V: BlsVerify>(
FINALITY_BRANCH_DEPTH,
get_subtree_index(finalized_root_gindex_at_slot(
client_state,
update.finalized_header.beacon.slot,
update.attested_header.beacon.slot,
)?),
update.attested_header.beacon.state_root,
)
Expand Down
Loading