Skip to content

Commit

Permalink
validate-delay (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
mina86 authored Mar 15, 2024
1 parent 7b2b8f0 commit 30789ef
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
11 changes: 0 additions & 11 deletions light-clients/cf-guest/src/client_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,6 @@ fn verify_delay_passed<Ctx: ReaderContext, PK: PubKey>(
.map_err(|e| e.into())
}

impl<PK: PubKey> GuestClient<PK> {
pub fn verify_delay_passed(
ctx: &impl ReaderContext,
height: ibc::Height,
delay_time_period: u64,
delay_block_period: u64,
) -> Result<(), Ics02ClientError> {
todo!()
}
}

impl<PK: PubKey> Verifier<PK> for GuestClient<PK> {
fn verify(&self, message: &[u8], pubkey: &PK, signature: &PK::Signature) -> bool {
let pubkey_in_bytes = pubkey.to_vec();
Expand Down
4 changes: 2 additions & 2 deletions light-clients/ics07-guest-cw/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn process_message(
.client_state(&client_id)
.map_err(|e| ContractError::Tendermint(e.to_string()))?;
let msg = VerifyMembershipMsg::try_from(msg)?;
GuestClient::<crate::crypto::PubKey>::verify_delay_passed(
crate::helpers::verify_delay_passed(
ctx,
msg.height,
msg.delay_time_period,
Expand All @@ -120,7 +120,7 @@ fn process_message(
.client_state(&client_id)
.map_err(|e| ContractError::Tendermint(e.to_string()))?;
let msg = VerifyNonMembershipMsg::try_from(msg)?;
GuestClient::<crate::crypto::PubKey>::verify_delay_passed(
crate::helpers::verify_delay_passed(
ctx,
msg.height,
msg.delay_time_period,
Expand Down
23 changes: 23 additions & 0 deletions light-clients/ics07-guest-cw/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,26 @@ pub fn prune_oldest_consensus_state(
}
}
}

pub fn verify_delay_passed(
ctx: &Context,
height: Height,
delay_period_time: u64,
delay_period_height: u64,
) -> Result<(), Ics02Error> {
let current_timestamp = ctx.host_timestamp();
let current_height = ctx.host_height();

let processed_time = ctx.processed_timestamp(height)?;
let processed_height = ctx.processed_height(height)?;

ClientState::<crate::crypto::PubKey>::verify_delay_passed(
current_timestamp,
current_height,
processed_time,
processed_height,
delay_period_time,
delay_period_height,
)
.map_err(|e| e.into())
}

0 comments on commit 30789ef

Please sign in to comment.