From 910fc6fe37bd2da5ffe97ed3e7e913aa31c6c6c7 Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Mon, 23 Dec 2024 19:47:03 +0900 Subject: [PATCH 1/3] EELC2: improve validation of `Fraction` Signed-off-by: Jun Kimura --- crates/ibc/Cargo.toml | 6 +++--- crates/ibc/src/client_state.rs | 9 +++++---- crates/ibc/src/header.rs | 2 +- crates/ibc/src/misbehaviour.rs | 2 +- crates/ibc/src/update.rs | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/crates/ibc/Cargo.toml b/crates/ibc/Cargo.toml index 8b93e39..505794b 100644 --- a/crates/ibc/Cargo.toml +++ b/crates/ibc/Cargo.toml @@ -16,10 +16,10 @@ ssz-rs = { git = "https://github.com/bluele/ssz_rs", branch = "serde-no-std", de hex = { version = "0.4.3", default-features = false } ethereum-ibc-proto = { path = "../../proto", default-features = false } -ethereum-consensus = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "v0.1.7", default-features = false } -ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "v0.1.7", default-features = false } +ethereum-consensus = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "a9a27ae291c716c68ea3bce9882c849a349b7e9f", default-features = false } +ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "a9a27ae291c716c68ea3bce9882c849a349b7e9f", default-features = false } [dev-dependencies] time = { version = "0.3", default-features = false, features = ["macros", "parsing"] } hex-literal = "0.4.1" -ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "v0.1.7", default-features = false, features = ["test-utils"] } +ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "a9a27ae291c716c68ea3bce9882c849a349b7e9f", default-features = false, features = ["test-utils"] } diff --git a/crates/ibc/src/client_state.rs b/crates/ibc/src/client_state.rs index 1967107..9f10da2 100644 --- a/crates/ibc/src/client_state.rs +++ b/crates/ibc/src/client_state.rs @@ -813,7 +813,8 @@ impl TryFrom epochs_per_sync_committee_period: value.epochs_per_sync_committee_period.into(), ibc_address: value.ibc_address.as_slice().try_into()?, ibc_commitments_slot: H256::from_slice(&value.ibc_commitments_slot), - trust_level: Fraction::new(trust_level.numerator, trust_level.denominator), + trust_level: Fraction::new(trust_level.numerator, trust_level.denominator) + .map_err(Error::VerificationError)?, trusting_period: value .trusting_period .ok_or(Error::MissingTrustingPeriod)? @@ -879,8 +880,8 @@ impl From> fo ibc_address: value.ibc_address.0.to_vec(), ibc_commitments_slot: value.ibc_commitments_slot.as_bytes().to_vec(), trust_level: Some(ProtoFraction { - numerator: value.trust_level.numerator, - denominator: value.trust_level.denominator, + numerator: value.trust_level.numerator(), + denominator: value.trust_level.denominator(), }), trusting_period: Some(value.trusting_period.into()), max_clock_drift: Some(value.max_clock_drift.into()), @@ -1059,7 +1060,7 @@ mod tests { epochs_per_sync_committee_period: PRESET.EPOCHS_PER_SYNC_COMMITTEE_PERIOD, ibc_address: Address(hex!("ff77D90D6aA12db33d3Ba50A34fB25401f6e4c4F")), ibc_commitments_slot: keccak256("ibc_commitments_slot"), - trust_level: Fraction::new(2, 3), + trust_level: Fraction::new(2, 3).unwrap(), trusting_period: Duration::from_secs(60 * 60 * 27), max_clock_drift: Duration::from_secs(60), latest_execution_block_number: 1.into(), diff --git a/crates/ibc/src/header.rs b/crates/ibc/src/header.rs index 45f1a7d..7042853 100644 --- a/crates/ibc/src/header.rs +++ b/crates/ibc/src/header.rs @@ -224,7 +224,7 @@ mod tests { config::minimal::get_config(), Default::default(), Default::default(), - Fraction::new(2, 3), + Fraction::new(2, 3).unwrap(), SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap() diff --git a/crates/ibc/src/misbehaviour.rs b/crates/ibc/src/misbehaviour.rs index c12c6e2..a29fe78 100644 --- a/crates/ibc/src/misbehaviour.rs +++ b/crates/ibc/src/misbehaviour.rs @@ -229,7 +229,7 @@ mod tests { config::minimal::get_config(), Default::default(), Default::default(), - Fraction::new(2, 3), + Fraction::new(2, 3).unwrap(), SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap() diff --git a/crates/ibc/src/update.rs b/crates/ibc/src/update.rs index 8c4dde9..b59fa01 100644 --- a/crates/ibc/src/update.rs +++ b/crates/ibc/src/update.rs @@ -110,7 +110,7 @@ mod tests { config::minimal::get_config(), Default::default(), Default::default(), - Fraction::new(2, 3), + Fraction::new(2, 3).unwrap(), SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap() @@ -149,7 +149,7 @@ mod tests { epochs_per_sync_committee_period: PRESET.EPOCHS_PER_SYNC_COMMITTEE_PERIOD, ibc_address: Address(hex!("ff77D90D6aA12db33d3Ba50A34fB25401f6e4c4F")), ibc_commitments_slot: keccak256("ibc_commitments_slot"), - trust_level: Fraction::new(2, 3), + trust_level: Fraction::new(2, 3).unwrap(), trusting_period: Duration::from_secs(60 * 60 * 27), max_clock_drift: Duration::from_secs(60), latest_execution_block_number: 1.into(), From 12857652c77a46eb4c4754f67cc1a40e8e8e7e6b Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Mon, 23 Dec 2024 20:04:48 +0900 Subject: [PATCH 2/3] EELC5: improve consensus state validation Signed-off-by: Jun Kimura --- crates/ibc/src/consensus_state.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/ibc/src/consensus_state.rs b/crates/ibc/src/consensus_state.rs index 08162d9..bd8af2b 100644 --- a/crates/ibc/src/consensus_state.rs +++ b/crates/ibc/src/consensus_state.rs @@ -53,6 +53,10 @@ impl ConsensusState { Err(Error::UninitializedConsensusStateField( "current_sync_committee", )) + } else if self.next_sync_committee == PublicKey::default() { + Err(Error::UninitializedConsensusStateField( + "next_sync_committee", + )) } else { Ok(()) } From 008ba4f1b9a012aae29a5d488f18f01c685ec36d Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Mon, 23 Dec 2024 23:34:08 +0900 Subject: [PATCH 3/3] bump ethereum-light-client to v0.2.0 Signed-off-by: Jun Kimura --- crates/ibc/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ibc/Cargo.toml b/crates/ibc/Cargo.toml index 505794b..5baf155 100644 --- a/crates/ibc/Cargo.toml +++ b/crates/ibc/Cargo.toml @@ -16,10 +16,10 @@ ssz-rs = { git = "https://github.com/bluele/ssz_rs", branch = "serde-no-std", de hex = { version = "0.4.3", default-features = false } ethereum-ibc-proto = { path = "../../proto", default-features = false } -ethereum-consensus = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "a9a27ae291c716c68ea3bce9882c849a349b7e9f", default-features = false } -ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "a9a27ae291c716c68ea3bce9882c849a349b7e9f", default-features = false } +ethereum-consensus = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "v0.2.0", default-features = false } +ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "v0.2.0", default-features = false } [dev-dependencies] time = { version = "0.3", default-features = false, features = ["macros", "parsing"] } hex-literal = "0.4.1" -ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "a9a27ae291c716c68ea3bce9882c849a349b7e9f", default-features = false, features = ["test-utils"] } +ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "v0.2.0", default-features = false, features = ["test-utils"] }