Skip to content

Commit

Permalink
EELC2: improve validation of Fraction
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Dec 23, 2024
1 parent 06864ca commit 910fc6f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions crates/ibc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
9 changes: 5 additions & 4 deletions crates/ibc/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,8 @@ impl<const SYNC_COMMITTEE_SIZE: usize> TryFrom<RawClientState>
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)?
Expand Down Expand Up @@ -879,8 +880,8 @@ impl<const SYNC_COMMITTEE_SIZE: usize> From<ClientState<SYNC_COMMITTEE_SIZE>> 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()),
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion crates/ibc/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion crates/ibc/src/misbehaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 910fc6f

Please sign in to comment.