Skip to content

Commit 81cc068

Browse files
committed
fix misbehaviour validation and tests
Signed-off-by: Jun Kimura <[email protected]>
1 parent e1d8017 commit 81cc068

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

crates/ibc/src/client_state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ impl<const SYNC_COMMITTEE_SIZE: usize> Ics2ClientState for ClientState<SYNC_COMM
423423
return Err(ClientError::ClientFrozen { client_id }.into());
424424
}
425425
let misbehaviour = Misbehaviour::<SYNC_COMMITTEE_SIZE>::try_from(misbehaviour)?;
426+
misbehaviour.validate()?;
426427
let consensus_state = match maybe_consensus_state(
427428
ctx,
428429
&ClientConsensusStatePath::new(&client_id, &misbehaviour.trusted_sync_committee.height),

crates/ibc/src/header.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub fn decode_header<const SYNC_COMMITTEE_SIZE: usize, B: Buf>(
7777

7878
impl<const SYNC_COMMITTEE_SIZE: usize> Header<SYNC_COMMITTEE_SIZE> {
7979
pub fn validate<C: ChainContext>(&self, ctx: &C) -> Result<(), Error> {
80-
self.trusted_sync_committee.sync_committee.validate()?;
80+
self.trusted_sync_committee.validate()?;
8181
if self.timestamp.into_tm_time().is_none() {
8282
return Err(Error::ZeroTimestampError);
8383
}
@@ -198,6 +198,7 @@ impl<const SYNC_COMMITTEE_SIZE: usize> From<Header<SYNC_COMMITTEE_SIZE>> for IBC
198198
#[cfg(test)]
199199
mod tests {
200200
use super::*;
201+
use crate::client_state::ETHEREUM_CLIENT_REVISION_NUMBER;
201202
use ethereum_consensus::context::ChainContext;
202203
use ethereum_consensus::{config, types::U64};
203204
use ethereum_light_client_verifier::{
@@ -246,7 +247,7 @@ mod tests {
246247
let update = to_consensus_update_info(update);
247248
let header = Header {
248249
trusted_sync_committee: TrustedSyncCommittee {
249-
height: ibc::Height::new(1, 1).unwrap(),
250+
height: ibc::Height::new(ETHEREUM_CLIENT_REVISION_NUMBER, 1).unwrap(),
250251
sync_committee: current_sync_committee.to_committee().clone(),
251252
is_next: true,
252253
},
@@ -267,7 +268,7 @@ mod tests {
267268

268269
let header = Header {
269270
trusted_sync_committee: TrustedSyncCommittee {
270-
height: ibc::Height::new(1, 1).unwrap(),
271+
height: ibc::Height::new(ETHEREUM_CLIENT_REVISION_NUMBER, 1).unwrap(),
271272
sync_committee: current_sync_committee.to_committee().clone(),
272273
is_next: true,
273274
},
@@ -296,7 +297,7 @@ mod tests {
296297
let update = to_consensus_update_info(update);
297298
let header = Header {
298299
trusted_sync_committee: TrustedSyncCommittee {
299-
height: ibc::Height::new(1, 1).unwrap(),
300+
height: ibc::Height::new(ETHEREUM_CLIENT_REVISION_NUMBER, 1).unwrap(),
300301
sync_committee: current_sync_committee.to_committee().clone(),
301302
is_next: true,
302303
},

crates/ibc/src/misbehaviour.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ pub struct Misbehaviour<const SYNC_COMMITTEE_SIZE: usize> {
3636
pub data: MisbehaviourData<SYNC_COMMITTEE_SIZE, ConsensusUpdateInfo<SYNC_COMMITTEE_SIZE>>,
3737
}
3838

39+
impl<const SYNC_COMMITTEE_SIZE: usize> Misbehaviour<SYNC_COMMITTEE_SIZE> {
40+
pub fn validate(&self) -> Result<(), Error> {
41+
self.trusted_sync_committee.validate()?;
42+
Ok(())
43+
}
44+
}
45+
3946
impl<const SYNC_COMMITTEE_SIZE: usize> Ics02Misbehaviour for Misbehaviour<SYNC_COMMITTEE_SIZE> {
4047
fn client_id(&self) -> &ibc::core::ics24_host::identifier::ClientId {
4148
&self.client_id

crates/ibc/src/types.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::client_state::ETHEREUM_CLIENT_REVISION_NUMBER;
12
use crate::commitment::decode_eip1184_rlp_proof;
23
use crate::errors::Error;
34
use crate::internal_prelude::*;
@@ -110,6 +111,19 @@ pub struct TrustedSyncCommittee<const SYNC_COMMITTEE_SIZE: usize> {
110111
pub is_next: bool,
111112
}
112113

114+
impl<const SYNC_COMMITTEE_SIZE: usize> TrustedSyncCommittee<SYNC_COMMITTEE_SIZE> {
115+
pub fn validate(&self) -> Result<(), Error> {
116+
if self.height.revision_number() != ETHEREUM_CLIENT_REVISION_NUMBER {
117+
return Err(Error::UnexpectedHeightRevisionNumber {
118+
expected: ETHEREUM_CLIENT_REVISION_NUMBER,
119+
got: self.height.revision_number(),
120+
});
121+
}
122+
self.sync_committee.validate()?;
123+
Ok(())
124+
}
125+
}
126+
113127
impl<const SYNC_COMMITTEE_SIZE: usize> TryFrom<ProtoTrustedSyncCommittee>
114128
for TrustedSyncCommittee<SYNC_COMMITTEE_SIZE>
115129
{

0 commit comments

Comments
 (0)