Skip to content

Commit 5717246

Browse files
committed
Merge branch 'feature/verify_block_hash' into feature/for_op_elc
2 parents e7bc1fb + 981970d commit 5717246

File tree

9 files changed

+64
-11
lines changed

9 files changed

+64
-11
lines changed

crates/ibc/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ ssz-rs = { git = "https://github.com/bluele/ssz_rs", branch = "serde-no-std", de
1616
hex = { version = "0.4.3", default-features = false }
1717

1818
ethereum-ibc-proto = { path = "../../proto", default-features = false }
19-
ethereum-consensus = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "v0.1.7", default-features = false }
20-
ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "v0.1.7", default-features = false }
19+
ethereum-consensus = { git = "https://github.com/yoshidan/ethereum-light-client-rs", branch = "feature/verify_block_hash", default-features = false }
20+
ethereum-light-client-verifier = { git = "https://github.com/yoshidan/ethereum-light-client-rs", branch = "feature/verify_block_hash", default-features = false }
2121

2222
[dev-dependencies]
2323
time = { version = "0.3", default-features = false, features = ["macros", "parsing"] }
2424
hex-literal = "0.4.1"
25-
ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "v0.1.7", default-features = false, features = ["test-utils"] }
25+
ethereum-light-client-verifier = { git = "https://github.com/yoshidan/ethereum-light-client-rs", branch = "feature/verify_block_hash", default-features = false, features = ["test-utils"] }
26+

crates/ibc/src/client_state.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ impl<const SYNC_COMMITTEE_SIZE: usize> TryFrom<RawClientState>
722722
execution_payload_state_root_gindex: spec.execution_payload_state_root_gindex,
723723
execution_payload_block_number_gindex: spec
724724
.execution_payload_block_number_gindex,
725+
execution_payload_block_hash_gindex: spec.execution_payload_block_hash_gindex,
725726
})
726727
} else {
727728
Err(Error::proto_missing(&format!("forks[{}].spec", idx)))
@@ -765,7 +766,8 @@ impl<const SYNC_COMMITTEE_SIZE: usize> TryFrom<RawClientState>
765766
epochs_per_sync_committee_period: value.epochs_per_sync_committee_period.into(),
766767
ibc_address: value.ibc_address.as_slice().try_into()?,
767768
ibc_commitments_slot: H256::from_slice(&value.ibc_commitments_slot),
768-
trust_level: Fraction::new(trust_level.numerator, trust_level.denominator),
769+
trust_level: Fraction::new(trust_level.numerator, trust_level.denominator)
770+
.map_err(Error::VerificationError)?,
769771
trusting_period: value
770772
.trusting_period
771773
.ok_or(Error::MissingTrustingPeriod)?
@@ -803,6 +805,7 @@ impl<const SYNC_COMMITTEE_SIZE: usize> From<ClientState<SYNC_COMMITTEE_SIZE>> fo
803805
execution_payload_state_root_gindex: spec.execution_payload_state_root_gindex,
804806
execution_payload_block_number_gindex: spec
805807
.execution_payload_block_number_gindex,
808+
execution_payload_block_hash_gindex: spec.execution_payload_block_hash_gindex,
806809
}),
807810
}
808811
}
@@ -831,8 +834,8 @@ impl<const SYNC_COMMITTEE_SIZE: usize> From<ClientState<SYNC_COMMITTEE_SIZE>> fo
831834
ibc_address: value.ibc_address.0.to_vec(),
832835
ibc_commitments_slot: value.ibc_commitments_slot.as_bytes().to_vec(),
833836
trust_level: Some(ProtoFraction {
834-
numerator: value.trust_level.numerator,
835-
denominator: value.trust_level.denominator,
837+
numerator: value.trust_level.numerator(),
838+
denominator: value.trust_level.denominator(),
836839
}),
837840
trusting_period: Some(value.trusting_period.into()),
838841
max_clock_drift: Some(value.max_clock_drift.into()),
@@ -1072,7 +1075,7 @@ mod tests {
10721075
epochs_per_sync_committee_period: PRESET.EPOCHS_PER_SYNC_COMMITTEE_PERIOD,
10731076
ibc_address: Address(hex!("ff77D90D6aA12db33d3Ba50A34fB25401f6e4c4F")),
10741077
ibc_commitments_slot: keccak256("ibc_commitments_slot"),
1075-
trust_level: Fraction::new(2, 3),
1078+
trust_level: Fraction::new(2, 3).unwrap(),
10761079
trusting_period: Duration::from_secs(60 * 60 * 27),
10771080
max_clock_drift: Duration::from_secs(60),
10781081
latest_execution_block_number: 1.into(),

crates/ibc/src/consensus_state.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ impl ConsensusState {
5353
Err(Error::UninitializedConsensusStateField(
5454
"current_sync_committee",
5555
))
56+
} else if self.next_sync_committee == PublicKey::default() {
57+
Err(Error::UninitializedConsensusStateField(
58+
"next_sync_committee",
59+
))
5660
} else {
5761
Ok(())
5862
}

crates/ibc/src/header.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ mod tests {
224224
config::minimal::get_config(),
225225
Default::default(),
226226
Default::default(),
227-
Fraction::new(2, 3),
227+
Fraction::new(2, 3).unwrap(),
228228
SystemTime::now()
229229
.duration_since(SystemTime::UNIX_EPOCH)
230230
.unwrap()
@@ -239,6 +239,7 @@ mod tests {
239239
let base_finalized_epoch = base_attested_slot / ctx.slots_per_epoch();
240240
let dummy_execution_state_root = [1u8; 32].into();
241241
let dummy_execution_block_number = 1;
242+
let dummy_execution_block_hash = [1u8; 32].into();
242243

243244
for b in [false, true] {
244245
let (update, _) = gen_light_client_update_with_params::<32, _>(
@@ -248,6 +249,7 @@ mod tests {
248249
base_finalized_epoch,
249250
dummy_execution_state_root,
250251
dummy_execution_block_number.into(),
252+
dummy_execution_block_hash,
251253
current_sync_committee,
252254
scm.get_committee(2),
253255
b,
@@ -304,6 +306,7 @@ mod tests {
304306
base_finalized_epoch,
305307
dummy_execution_state_root,
306308
dummy_execution_block_number.into(),
309+
dummy_execution_block_hash,
307310
current_sync_committee,
308311
scm.get_committee(2),
309312
true,

crates/ibc/src/misbehaviour.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ mod tests {
229229
config::minimal::get_config(),
230230
Default::default(),
231231
Default::default(),
232-
Fraction::new(2, 3),
232+
Fraction::new(2, 3).unwrap(),
233233
SystemTime::now()
234234
.duration_since(SystemTime::UNIX_EPOCH)
235235
.unwrap()
@@ -244,6 +244,7 @@ mod tests {
244244
let base_finalized_epoch = base_attested_slot / ctx.slots_per_epoch();
245245
let dummy_execution_state_root = [1u8; 32].into();
246246
let dummy_execution_block_number = 1;
247+
let dummy_execution_block_hash = [1u8; 32].into();
247248

248249
let (update_1, _) = gen_light_client_update_with_params::<32, _>(
249250
&ctx,
@@ -252,6 +253,7 @@ mod tests {
252253
base_finalized_epoch,
253254
dummy_execution_state_root,
254255
dummy_execution_block_number.into(),
256+
dummy_execution_block_hash,
255257
current_sync_committee,
256258
scm.get_committee(2),
257259
true,
@@ -264,6 +266,7 @@ mod tests {
264266
base_finalized_epoch,
265267
dummy_execution_state_root,
266268
dummy_execution_block_number.into(),
269+
dummy_execution_block_hash,
267270
current_sync_committee,
268271
scm.get_committee(3),
269272
true,
@@ -295,6 +298,7 @@ mod tests {
295298
base_finalized_epoch,
296299
different_dummy_execution_state_root,
297300
dummy_execution_block_number.into(),
301+
dummy_execution_block_hash,
298302
current_sync_committee,
299303
scm.get_committee(2),
300304
true,

crates/ibc/src/types.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ pub struct ExecutionUpdateInfo {
8181
pub block_number: U64,
8282
/// Branch indicating the block number in the tree corresponding to the execution payload
8383
pub block_number_branch: Vec<H256>,
84+
/// Block hash of the execution payload
85+
pub block_hash: H256,
86+
/// Branch indicating the block hash in the tree corresponding to the execution payload
87+
pub block_hash_branch: Vec<H256>,
8488
}
8589

8690
impl ExecutionUpdate for ExecutionUpdateInfo {
@@ -99,6 +103,14 @@ impl ExecutionUpdate for ExecutionUpdateInfo {
99103
fn block_number_branch(&self) -> Vec<H256> {
100104
self.block_number_branch.clone()
101105
}
106+
107+
fn block_hash(&self) -> H256 {
108+
self.block_hash
109+
}
110+
111+
fn block_hash_branch(&self) -> Vec<H256> {
112+
self.block_hash_branch.clone()
113+
}
102114
}
103115

104116
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
@@ -241,6 +253,12 @@ pub fn convert_proto_to_execution_update(
241253
.into_iter()
242254
.map(|n| H256::from_slice(&n))
243255
.collect(),
256+
block_hash: H256::from_slice(&execution_update.block_hash),
257+
block_hash_branch: execution_update
258+
.block_hash_branch
259+
.into_iter()
260+
.map(|n| H256::from_slice(&n))
261+
.collect(),
244262
}
245263
}
246264

@@ -260,6 +278,12 @@ pub(crate) fn convert_execution_update_to_proto(
260278
.into_iter()
261279
.map(|n| n.as_bytes().to_vec())
262280
.collect(),
281+
block_hash: execution_update.block_hash.as_bytes().into(),
282+
block_hash_branch: execution_update
283+
.block_hash_branch
284+
.into_iter()
285+
.map(|n| n.as_bytes().to_vec())
286+
.collect(),
263287
}
264288
}
265289

crates/ibc/src/update.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ mod tests {
110110
config::minimal::get_config(),
111111
Default::default(),
112112
Default::default(),
113-
Fraction::new(2, 3),
113+
Fraction::new(2, 3).unwrap(),
114114
SystemTime::now()
115115
.duration_since(SystemTime::UNIX_EPOCH)
116116
.unwrap()
@@ -128,6 +128,7 @@ mod tests {
128128
let current_sync_committee = scm.get_committee(base_store_period);
129129
let dummy_execution_state_root = [1u8; 32].into();
130130
let dummy_execution_block_number = 1;
131+
let dummy_execution_block_hash = [1u8; 32].into();
131132

132133
let client_state =
133134
ClientState::<{ ethereum_consensus::preset::minimal::PRESET.SYNC_COMMITTEE_SIZE }> {
@@ -149,7 +150,7 @@ mod tests {
149150
epochs_per_sync_committee_period: PRESET.EPOCHS_PER_SYNC_COMMITTEE_PERIOD,
150151
ibc_address: Address(hex!("ff77D90D6aA12db33d3Ba50A34fB25401f6e4c4F")),
151152
ibc_commitments_slot: keccak256("ibc_commitments_slot"),
152-
trust_level: Fraction::new(2, 3),
153+
trust_level: Fraction::new(2, 3).unwrap(),
153154
trusting_period: Duration::from_secs(60 * 60 * 27),
154155
max_clock_drift: Duration::from_secs(60),
155156
latest_execution_block_number: 1.into(),
@@ -184,6 +185,7 @@ mod tests {
184185
base_finalized_epoch,
185186
dummy_execution_state_root,
186187
dummy_execution_block_number.into(),
188+
dummy_execution_block_hash,
187189
current_sync_committee,
188190
scm.get_committee(base_store_period + 1),
189191
true,
@@ -234,6 +236,7 @@ mod tests {
234236
base_finalized_epoch + ctx.epochs_per_sync_committee_period(),
235237
dummy_execution_state_root,
236238
dummy_execution_block_number.into(),
239+
dummy_execution_block_hash,
237240
current_sync_committee,
238241
scm.get_committee(base_store_period + 2),
239242
true,
@@ -285,6 +288,7 @@ mod tests {
285288
base_finalized_epoch + ctx.epochs_per_sync_committee_period(),
286289
dummy_execution_state_root,
287290
dummy_execution_block_number.into(),
291+
dummy_execution_block_hash,
288292
current_sync_committee,
289293
scm.get_committee(base_store_period + 2),
290294
false,
@@ -324,6 +328,7 @@ mod tests {
324328
base_finalized_epoch - ctx.epochs_per_sync_committee_period(),
325329
dummy_execution_state_root,
326330
dummy_execution_block_number.into(),
331+
dummy_execution_block_hash,
327332
current_sync_committee,
328333
scm.get_committee(base_store_period),
329334
true,

proto/definitions/ibc/lightclients/ethereum/v1/ethereum.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ message ForkSpec {
7272
uint32 execution_payload_gindex = 4;
7373
uint32 execution_payload_state_root_gindex = 5;
7474
uint32 execution_payload_block_number_gindex = 6;
75+
uint32 execution_payload_block_hash_gindex = 7;
7576
}
7677

7778
message ConsensusUpdate {
@@ -101,6 +102,8 @@ message ExecutionUpdate {
101102
repeated bytes state_root_branch = 2;
102103
uint64 block_number = 3;
103104
repeated bytes block_number_branch = 4;
105+
bytes block_hash = 5;
106+
repeated bytes block_hash_branch = 6;
104107
}
105108

106109
message AccountUpdate {

proto/src/prost/ibc.lightclients.ethereum.v1.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ pub struct ForkSpec {
120120
pub execution_payload_state_root_gindex: u32,
121121
#[prost(uint32, tag = "6")]
122122
pub execution_payload_block_number_gindex: u32,
123+
#[prost(uint32, tag = "7")]
124+
pub execution_payload_block_hash_gindex: u32,
123125
}
124126
#[allow(clippy::derive_partial_eq_without_eq)]
125127
#[derive(Clone, PartialEq, ::prost::Message)]
@@ -174,6 +176,10 @@ pub struct ExecutionUpdate {
174176
pub block_number: u64,
175177
#[prost(bytes = "vec", repeated, tag = "4")]
176178
pub block_number_branch: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
179+
#[prost(bytes = "vec", tag = "5")]
180+
pub block_hash: ::prost::alloc::vec::Vec<u8>,
181+
#[prost(bytes = "vec", repeated, tag = "6")]
182+
pub block_hash_branch: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
177183
}
178184
#[allow(clippy::derive_partial_eq_without_eq)]
179185
#[derive(Clone, PartialEq, ::prost::Message)]

0 commit comments

Comments
 (0)