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

ICS07: Add verification method for client update handler #1321

Merged
merged 84 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
20c5ccf
bla
cezarad Jun 8, 2021
b5b9dcf
on going
cezarad Jun 15, 2021
dae68b1
ongoing
cezarad Jun 17, 2021
1b4ac9f
on going
cezarad Jun 18, 2021
58b5618
on going
cezarad Jun 19, 2021
4fb5a0d
timestamp default changed from none to now
cezarad Jun 19, 2021
1deda2a
failed ping pong - signs
cezarad Jun 20, 2021
cc5780a
Update context.rs
cezarad Jun 21, 2021
e63e5b3
bla
cezarad Jun 22, 2021
2c91fe6
blabla
cezarad Jun 22, 2021
8d4ca79
fixed test client_update_ping_pong
cezarad Jun 22, 2021
87f538a
fmt + clippy
cezarad Jun 22, 2021
3b470cc
Update context.rs
cezarad Jun 22, 2021
0bed49f
Update context.rs
cezarad Jun 22, 2021
437d345
remove comments
cezarad Jun 22, 2021
2d76e27
Update host.rs
cezarad Jun 24, 2021
3417872
Update to tendermint-rs v0.20.0
romac Jun 24, 2021
33fe434
Update changelog
romac Jun 24, 2021
4b3e46c
Fix tendermint-rs version in changelog
romac Jun 24, 2021
315dfc4
Merge branch 'master' into Check-Header-And-Update-State
cezarad Jun 24, 2021
a225b75
merged with #1126 Update to tendermint-rs v0.20.0
cezarad Jun 24, 2021
cff89a8
Update predicates.rs
cezarad Jun 30, 2021
be51b51
Merge branch 'master' into Check-Header-And-Update-State
cezarad Jun 30, 2021
4f47dcf
Update context.rs
cezarad Jul 5, 2021
bc72d52
tests
cezarad Jul 5, 2021
06e44e9
Merge branch 'Check-Header-And-Update-State' of https://github.com/in…
cezarad Jul 5, 2021
cdebb03
Merge branch 'Check-Header-And-Update-State' of https://github.com/in…
cezarad Jul 5, 2021
98f5cb0
tendermint stuff in
cezarad Jul 5, 2021
e1a0f1b
Update Cargo.toml
cezarad Jul 5, 2021
fd7bc2e
clippy + fmt
cezarad Jul 6, 2021
9b59b29
moved predicates into ics07 header.rs
cezarad Jul 13, 2021
08a3027
Merge branch 'master' into Check-Header-And-Update-State
adizere Jul 21, 2021
0c797c8
Adapted to latest TM changes
adizere Jul 21, 2021
f94b42d
Fixed MockHeader test
adizere Jul 21, 2021
de1af84
Fmt & clippy
adizere Jul 21, 2021
d48b185
Removed irrelevant file
adizere Jul 21, 2021
e6ec46f
Bit more cleanup
adizere Jul 21, 2021
b5d14b6
Merge branch 'master' into Check-Header-And-Update-State
adizere Jul 23, 2021
39dd54f
fixed tests
cezarad Jul 30, 2021
86c00f1
Merge branch 'master' into cezara
cezarad Jul 30, 2021
faba4a6
upgraded to new error model
cezarad Jul 30, 2021
05fec7e
fmt
cezarad Jul 30, 2021
0184c05
errors and timestamp changes
cezarad Aug 2, 2021
80b9069
Merge from master and resolve conflicts
thanethomson Sep 3, 2021
174074a
Fix error notation and formatting
thanethomson Sep 3, 2021
54c062b
Upgrade to tendermint-rs master
thanethomson Sep 3, 2021
9390b3e
Use tendermint-rs from branch thane/ibc-1252
thanethomson Sep 4, 2021
cb78022
Refactor ICS07 update handler to reuse light client verifier
thanethomson Sep 9, 2021
cc60358
Merge latest changes from master and fix Cargo.lock conflicts
thanethomson Sep 9, 2021
175cfed
Merge latest changes from master
thanethomson Sep 21, 2021
4ae55b3
Update Cargo.lock to address zeroize issue
thanethomson Sep 24, 2021
2e5d0f4
Merge latest changes from master
thanethomson Sep 24, 2021
cb69ab3
Bump tendermint-light-client dep to v0.22.0 for ibc module
thanethomson Sep 24, 2021
45b7fc4
Refactor to accommodate new context API
thanethomson Sep 24, 2021
40cdfa3
Fix missing import
thanethomson Sep 24, 2021
cd04bf5
Fix imports
thanethomson Sep 24, 2021
fb206af
Fix error check in test
thanethomson Sep 24, 2021
c45178a
Output debug version of error
thanethomson Sep 24, 2021
923dff6
Remove test as per https://github.com/informalsystems/ibc-rs/pull/132…
thanethomson Sep 24, 2021
cb2a11b
Address comments from Adi
thanethomson Sep 24, 2021
7a70a02
Cosmetic tweaks
thanethomson Sep 24, 2021
c6d7a9e
Add revision number check
thanethomson Sep 24, 2021
91f99b8
Fix broken test
thanethomson Sep 24, 2021
79c7831
Check incoming header height against chain ID version from client state
thanethomson Sep 24, 2021
2bbf6f6
Add revision_number consistency check when deserializing header
thanethomson Sep 24, 2021
ae1b2ff
Clarify MismatchedRevisions error message
thanethomson Sep 24, 2021
0cfea03
Merge latest changes from master
thanethomson Oct 4, 2021
c8ab69d
Add changelog entries
thanethomson Oct 4, 2021
d4e66bc
Commented import no longer necessary
thanethomson Oct 5, 2021
1a0a7aa
Add in-the-middle monotonicity checks
thanethomson Oct 5, 2021
1197cd0
Merge latest changes from master
thanethomson Oct 5, 2021
b936f7f
Fix broken dep tree relating to Prometheus
thanethomson Oct 5, 2021
b8f2506
Move next/prev consensus state search functionality to ClientReader t…
thanethomson Oct 11, 2021
5baef8c
Merge latest changes from master and resolve conflict
thanethomson Oct 11, 2021
1503839
Move impl of prev/next to the specific implementation and simplify si…
ancazamfir Oct 12, 2021
83e7b57
Merge branch 'master' into thane/1252-ics07
ancazamfir Oct 12, 2021
ffa8672
Disable `tendermint-light-client` default features, ie. RPC client, s…
romac Oct 12, 2021
5db8b62
Apply suggestions from code review
romac Oct 12, 2021
a795e2f
Fix compilation
romac Oct 12, 2021
4019c7b
Cleanup BTreeMap import
romac Oct 12, 2021
c2ee39f
Always show underlying reason in ics07_tendermint errors
romac Oct 12, 2021
7818a71
Update modules/src/ics02_client/handler/update_client.rs
romac Oct 12, 2021
c637821
Fix compilation
romac Oct 13, 2021
b07e4eb
Merge branch 'master' into thane/1252-ics07
romac Oct 13, 2021
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
3 changes: 3 additions & 0 deletions .changelog/unreleased/breaking-changes/ibc/1214-ics07.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- The `check_header_and_update_state` method of the `ClientDef`
trait (ICS02) has been expanded to facilitate ICS07
([#1214](https://github.com/informalsystems/ibc-rs/issues/1214))
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/ibc/1214-ics07.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add ICS07 verification functionality by using `tendermint-light-client`
([#1214](https://github.com/informalsystems/ibc-rs/issues/1214))
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion modules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ description = """
default = ["std", "eyre_tracer"]
std = ["flex-error/std"]
eyre_tracer = ["flex-error/eyre_tracer"]

# This feature grants access to development-time mocking libraries, such as `MockContext` or `MockHeader`.
# Depends on the `testgen` suite for generating Tendermint light blocks.
mocks = [ "tendermint-testgen", "sha2" ]
mocks = ["tendermint-testgen", "sha2"]

[dependencies]
# Proto definitions for all IBC-related interfaces, e.g., connections or channels.
Expand All @@ -45,6 +46,10 @@ version = "=0.22.0"
[dependencies.tendermint-proto]
version = "=0.22.0"

[dependencies.tendermint-light-client]
version = "=0.22.0"
default-features = false

[dependencies.tendermint-testgen]
version = "=0.22.0"
optional = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,17 @@ impl From<MsgTransfer> for RawMsgTransfer {

#[cfg(test)]
pub mod test_util {
use std::ops::Add;
use std::time::Duration;

use crate::{
ics24_host::identifier::{ChannelId, PortId},
test_utils::get_dummy_account_id,
timestamp::Timestamp,
Height,
};

use super::MsgTransfer;
use crate::timestamp::Timestamp;

// Returns a dummy `RawMsgTransfer`, for testing only!
pub fn get_dummy_msg_transfer(height: u64) -> MsgTransfer {
Expand All @@ -120,7 +123,7 @@ pub mod test_util {
token: None,
sender: id.clone(),
receiver: id,
timeout_timestamp: Timestamp::from_nanoseconds(1).unwrap(),
timeout_timestamp: Timestamp::now().add(Duration::from_secs(10)).unwrap(),
timeout_height: Height {
revision_number: 0,
revision_height: height,
Expand Down
13 changes: 9 additions & 4 deletions modules/src/ics02_client/client_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::downcast;
use crate::ics02_client::client_consensus::{AnyConsensusState, ConsensusState};
use crate::ics02_client::client_state::{AnyClientState, ClientState};
use crate::ics02_client::client_type::ClientType;
use crate::ics02_client::context::ClientReader;
use crate::ics02_client::error::Error;
use crate::ics02_client::header::{AnyHeader, Header};
use crate::ics03_connection::connection::ConnectionEnd;
Expand All @@ -23,13 +24,15 @@ pub trait ClientDef: Clone {
type ClientState: ClientState;
type ConsensusState: ConsensusState;

/// TODO
fn check_header_and_update_state(
&self,
ctx: &dyn ClientReader,
client_id: ClientId,
client_state: Self::ClientState,
header: Self::Header,
) -> Result<(Self::ClientState, Self::ConsensusState), Error>;

/// TODO
fn verify_upgrade_and_update_state(
&self,
client_state: &Self::ClientState,
Expand Down Expand Up @@ -156,7 +159,7 @@ pub enum AnyClient {
impl AnyClient {
pub fn from_client_type(client_type: ClientType) -> AnyClient {
match client_type {
ClientType::Tendermint => Self::Tendermint(TendermintClient),
ClientType::Tendermint => Self::Tendermint(TendermintClient::default()),

#[cfg(any(test, feature = "mocks"))]
ClientType::Mock => Self::Mock(MockClient),
Expand All @@ -173,6 +176,8 @@ impl ClientDef for AnyClient {
/// Validates an incoming `header` against the latest consensus state of this client.
fn check_header_and_update_state(
&self,
ctx: &dyn ClientReader,
client_id: ClientId,
client_state: AnyClientState,
header: AnyHeader,
) -> Result<(AnyClientState, AnyConsensusState), Error> {
Expand All @@ -185,7 +190,7 @@ impl ClientDef for AnyClient {
.ok_or_else(|| Error::client_args_type_mismatch(ClientType::Tendermint))?;

let (new_state, new_consensus) =
client.check_header_and_update_state(client_state, header)?;
client.check_header_and_update_state(ctx, client_id, client_state, header)?;

Ok((
AnyClientState::Tendermint(new_state),
Expand All @@ -202,7 +207,7 @@ impl ClientDef for AnyClient {
.ok_or_else(|| Error::client_args_type_mismatch(ClientType::Mock))?;

let (new_state, new_consensus) =
client.check_header_and_update_state(client_state, header)?;
client.check_header_and_update_state(ctx, client_id, client_state, header)?;

Ok((
AnyClientState::Mock(new_state),
Expand Down
37 changes: 36 additions & 1 deletion modules/src/ics02_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use crate::ics02_client::client_consensus::AnyConsensusState;
use crate::ics02_client::client_state::AnyClientState;
use crate::ics02_client::client_type::ClientType;
use crate::ics02_client::error::Error;
use crate::ics02_client::error::{Error, ErrorDetail};
use crate::ics02_client::handler::ClientResult::{self, Create, Update, Upgrade};
use crate::ics24_host::identifier::ClientId;
use crate::Height;
Expand All @@ -14,12 +14,47 @@ use crate::Height;
pub trait ClientReader {
fn client_type(&self, client_id: &ClientId) -> Result<ClientType, Error>;
fn client_state(&self, client_id: &ClientId) -> Result<AnyClientState, Error>;

/// Retrieve the consensus state for the given client ID at the specified
/// height.
///
/// Returns an error if no such state exists.
fn consensus_state(
&self,
client_id: &ClientId,
height: Height,
) -> Result<AnyConsensusState, Error>;

/// Similar to `consensus_state`, attempt to retrieve the consensus state,
/// but return `None` if no state exists at the given height.
fn maybe_consensus_state(
&self,
client_id: &ClientId,
height: Height,
) -> Result<Option<AnyConsensusState>, Error> {
match self.consensus_state(client_id, height) {
Ok(cs) => Ok(Some(cs)),
Err(e) => match e.detail() {
ErrorDetail::ConsensusStateNotFound(_) => Ok(None),
_ => Err(e),
},
}
}

/// Search for the lowest consensus state higher than `height`.
fn next_consensus_state(
&self,
client_id: &ClientId,
height: Height,
) -> Result<Option<AnyConsensusState>, Error>;

/// Search for the highest consensus state lower than `height`.
fn prev_consensus_state(
&self,
client_id: &ClientId,
height: Height,
) -> Result<Option<AnyConsensusState>, Error>;

/// Returns a natural number, counting how many clients have been created thus far.
/// The value of this counter should increase only via method `ClientKeeper::increase_client_counter`.
fn client_counter(&self) -> Result<u64, Error>;
Expand Down
51 changes: 45 additions & 6 deletions modules/src/ics02_client/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ use crate::ics07_tendermint::error::Error as Ics07Error;
use crate::ics23_commitment::error::Error as Ics23Error;
use crate::ics24_host::error::ValidationError;
use crate::ics24_host::identifier::ClientId;
use crate::timestamp::Timestamp;
use crate::Height;

use tendermint::Error as TendermintError;
use tendermint_proto::Error as TendermintProtoError;

define_error! {
#[derive(Debug, PartialEq, Eq)]
Error {
Expand Down Expand Up @@ -58,7 +62,7 @@ define_error! {

FailedTrustThresholdConversion
{ numerator: u64, denominator: u64 }
[ tendermint::Error ]
[ TendermintError ]
| e | { format_args!("failed to build Tendermint domain type trust threshold from fraction: {}/{}", e.numerator, e.denominator) },

UnknownClientStateType
Expand Down Expand Up @@ -105,14 +109,14 @@ define_error! {
},

DecodeRawClientState
[ TraceError<tendermint_proto::Error> ]
[ TraceError<TendermintProtoError> ]
| _ | { "error decoding raw client state" },

MissingRawClientState
| _ | { "missing raw client state" },

InvalidRawConsensusState
[ TraceError<tendermint_proto::Error> ]
[ TraceError<TendermintProtoError> ]
| _ | { "invalid raw client consensus state" },

MissingRawConsensusState
Expand All @@ -134,14 +138,14 @@ define_error! {
| _ | { "invalid client identifier" },

InvalidRawHeader
[ TraceError<tendermint_proto::Error> ]
[ TraceError<TendermintProtoError> ]
| _ | { "invalid raw header" },

MissingRawHeader
| _ | { "missing raw header" },

DecodeRawMisbehaviour
[ TraceError<tendermint_proto::Error> ]
[ TraceError<TendermintProtoError> ]
| _ | { "invalid raw misbehaviour" },

InvalidRawMisbehaviour
Expand Down Expand Up @@ -180,6 +184,12 @@ define_error! {
e.client_type)
},

InsufficientVotingPower
romac marked this conversation as resolved.
Show resolved Hide resolved
{ reason: String }
| e | {
format_args!("Insufficient overlap {}", e.reason)
},

RawClientAndConsensusStateTypesMismatch
{
state_type: ClientType,
Expand All @@ -206,8 +216,37 @@ define_error! {
client_height: Height,
}
| e | {
format_args!("upgraded client height {0} must be at greater than current client height {1}",
format_args!("upgraded client height {} must be at greater than current client height {}",
e.upgraded_height, e.client_height)
},

InvalidConsensusStateTimestamp
{
time1: Timestamp,
time2: Timestamp,
}
| e | {
format_args!("timestamp is invalid or missing, timestamp={0}, now={1}", e.time1, e.time2)
},

HeaderNotWithinTrustPeriod
{
latest_time:Timestamp,
update_time: Timestamp,
}
| e | {
format_args!("header not withing trusting period: expires_at={0} now={1}", e.latest_time, e.update_time)
},

TendermintHandlerError
[ Ics07Error ]
| _ | { format_args!("Tendermint-specific handler error") },

}
}

impl From<Ics07Error> for Error {
fn from(e: Ics07Error) -> Error {
Error::tendermint_handler_error(e)
}
}
Loading