Skip to content

Commit

Permalink
Add VerifyCommit check
Browse files Browse the repository at this point in the history
  • Loading branch information
hu55a1n1 committed Nov 16, 2022
1 parent a3a56b7 commit 0af89b0
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion crates/ibc/src/clients/ics07_tendermint/misbehaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use ibc_proto::ibc::lightclients::tendermint::v1::Misbehaviour as RawMisbehaviou
use ibc_proto::protobuf::Protobuf;
use prost::Message;
use serde::{Deserialize, Serialize};
use tendermint_light_client_verifier::types::UntrustedBlockState;
use tendermint_light_client_verifier::{ProdVerifier, Verdict, Verifier};

use crate::clients::ics07_tendermint::error::Error;
use crate::clients::ics07_tendermint::header::Header;
Expand Down Expand Up @@ -38,7 +40,8 @@ impl Misbehaviour {
)));
}

// TODO(hu55a1n1): validCommit()
Self::ensure_valid_commit(&header1)?;
Self::ensure_valid_commit(&header2)?;

Ok(Self {
client_id,
Expand All @@ -58,6 +61,29 @@ impl Misbehaviour {
pub fn header2(&self) -> &Header {
&self.header2
}

fn ensure_valid_commit(header: &Header) -> Result<(), Error> {
let untrusted_state = UntrustedBlockState {
signed_header: &header.signed_header,
validators: &header.validator_set,
next_validators: None,
};

let verdict = ProdVerifier::default().verify_light(untrusted_state);
match verdict {
Verdict::Success => {}
Verdict::NotEnoughTrust(voting_power_tally) => {
return Err(Error::not_enough_trusted_vals_signed(format!(
"voting power tally: {}",
voting_power_tally
))
.into());
}
Verdict::Invalid(detail) => return Err(Error::verification_error(detail).into()),
}

Ok(())
}
}

impl crate::core::ics02_client::misbehaviour::Misbehaviour for Misbehaviour {
Expand Down

0 comments on commit 0af89b0

Please sign in to comment.