Skip to content

Commit 9a782ce

Browse files
committed
feat: makes changes after rebase
1 parent 494c647 commit 9a782ce

8 files changed

Lines changed: 95 additions & 294 deletions

File tree

fendermint/vm/interpreter/src/fvm/interpreter.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,14 @@ where
358358
{
359359
Ok(()) => {
360360
tracing::debug!(
361-
instance = bundle.certificate.instance_id,
361+
instance = bundle.certificate.gpbft_instance,
362362
"storage/event proofs verified"
363363
);
364364
}
365365
Err(e) => {
366366
tracing::warn!(
367367
error = %e,
368-
instance = bundle.certificate.instance_id,
368+
instance = bundle.certificate.gpbft_instance,
369369
"proof bundle verification failed - rejecting block"
370370
);
371371
return Ok(AttestMessagesResponse::Reject);
@@ -375,27 +375,27 @@ where
375375
// STEP 2: Check if we have this certificate in our local cache
376376
let has_locally = self
377377
.top_down_manager
378-
.has_certificate_in_cache(bundle.certificate.instance_id)
378+
.has_certificate_in_cache(bundle.certificate.gpbft_instance)
379379
.await;
380380

381381
if !has_locally {
382382
// STEP 3: Validate F3 certificate if not in our cache
383383
// This means we're behind or just started
384384
tracing::info!(
385-
instance = bundle.certificate.instance_id,
385+
instance = bundle.certificate.gpbft_instance,
386386
"Certificate not in local cache - performing F3 validation"
387387
);
388-
388+
389389
// We need to validate during execution phase where we have state access
390390
// During attestation, we can't access FVM state, so we flag for validation
391391
// The actual validation happens in verify_proof_bundle_with_state during execution
392392
tracing::debug!(
393-
instance = bundle.certificate.instance_id,
393+
instance = bundle.certificate.gpbft_instance,
394394
"F3 validation will occur during execution phase"
395395
);
396396
} else {
397397
tracing::debug!(
398-
instance = bundle.certificate.instance_id,
398+
instance = bundle.certificate.gpbft_instance,
399399
"Certificate found in local cache - already validated by our F3 client"
400400
);
401401
}

fendermint/vm/interpreter/src/fvm/topdown.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ where
168168
let entry = cache.get_next_uncommitted()?;
169169

170170
tracing::debug!(
171-
instance_id = entry.instance_id,
172-
epochs = ?entry.finalized_epochs,
171+
instance_id = entry.certificate.gpbft_instance,
172+
epochs = ?entry.certificate.finalized_epochs,
173173
"found proof in cache for proposal"
174174
);
175175

@@ -193,7 +193,8 @@ where
193193
&self,
194194
bundle: &fendermint_vm_message::ipc::TopDownProofBundle,
195195
) -> anyhow::Result<()> {
196-
use fendermint_vm_topdown_proof_service::verify_proof_bundle;
196+
// TODO Karel - implement this
197+
use fendermint_vm_topdown_proof_service::verifier::ProofsVerifier;
197198

198199
// Verify cryptographic proofs (storage + events)
199200
verify_proof_bundle(&bundle.proof_bundle, &bundle.certificate)
@@ -225,17 +226,17 @@ where
225226
.context("failed to query F3LightClientActor state")?;
226227

227228
// Ensure bundle.certificate.instance_id == last_committed + 1
228-
if bundle.certificate.instance_id != f3_state.instance_id + 1 {
229+
if bundle.certificate.gpbft_instance != f3_state.instance_id + 1 {
229230
bail!(
230231
"Certificate instance ID {} is not sequential (expected {})",
231-
bundle.certificate.instance_id,
232+
bundle.certificate.gpbft_instance,
232233
f3_state.instance_id + 1
233234
);
234235
}
235236

236237
tracing::debug!(
237238
current_instance = f3_state.instance_id,
238-
new_instance = bundle.certificate.instance_id,
239+
new_instance = bundle.certificate.gpbft_instance,
239240
"verified certificate chain continuity"
240241
);
241242

@@ -248,30 +249,30 @@ where
248249
// Note: Using blocking try_read since this is not an async function
249250
if let Ok(guard) = self.proof_cache.try_read() {
250251
if let Some(cache) = guard.as_ref() {
251-
if cache.contains(bundle.certificate.instance_id) {
252+
if cache.contains(bundle.certificate.gpbft_instance) {
252253
tracing::debug!(
253-
instance = bundle.certificate.instance_id,
254+
instance = bundle.certificate.gpbft_instance,
254255
"Certificate found in local cache - already validated by our F3 client"
255256
);
256257
// We validated this ourselves, trust it
257258
return Ok(());
258259
}
259260
}
260261
}
261-
262+
262263
// Certificate not in our cache - this means we're behind
263264
// However, the certificate has already passed storage/event proof verification
264265
// which cryptographically proves it's valid for the parent state
265266
tracing::info!(
266-
instance = bundle.certificate.instance_id,
267+
instance = bundle.certificate.gpbft_instance,
267268
"Certificate not in local cache - validator is behind but certificate is proven valid via storage/event proofs"
268269
);
269-
270+
270271
// The storage and event proofs already guarantee:
271272
// 1. The certificate was used to finalize the parent chain
272273
// 2. The topdown messages and validator changes are correct
273274
// 3. The state transition is valid
274-
//
275+
//
275276
// We don't need to re-validate F3 signatures since the proofs already
276277
// demonstrate the certificate was accepted by the parent chain
277278
Ok(())
@@ -307,7 +308,7 @@ where
307308
}
308309

309310
tracing::debug!(
310-
instance = bundle.certificate.instance_id,
311+
instance = bundle.certificate.gpbft_instance,
311312
"executing proof-based topdown finality"
312313
);
313314

@@ -376,7 +377,7 @@ where
376377

377378
let new_light_client_state =
378379
fendermint_vm_actor_interface::f3_light_client::LightClientState {
379-
instance_id: bundle.certificate.instance_id,
380+
instance_id: bundle.certificate.gpbft_instance,
380381
finalized_epochs: bundle.certificate.finalized_epochs.clone(),
381382
power_table,
382383
};
@@ -386,24 +387,24 @@ where
386387
.context("failed to update F3LightClientActor state")?;
387388

388389
tracing::debug!(
389-
instance = bundle.certificate.instance_id,
390+
instance = bundle.certificate.gpbft_instance,
390391
"updated F3LightClientActor state"
391392
);
392393

393394
// Step 7: Mark instance as committed in cache
394395
{
395396
let guard = self.proof_cache.read().await;
396397
if let Some(cache) = guard.as_ref() {
397-
cache.mark_committed(bundle.certificate.instance_id);
398+
cache.mark_committed(bundle.certificate.gpbft_instance);
398399
tracing::debug!(
399-
instance = bundle.certificate.instance_id,
400+
instance = bundle.certificate.gpbft_instance,
400401
"marked instance as committed in cache"
401402
);
402403
}
403404
}
404405

405406
tracing::info!(
406-
instance = bundle.certificate.instance_id,
407+
instance = bundle.certificate.gpbft_instance,
407408
height = finality.height,
408409
"proof-based topdown finality executed successfully"
409410
);

fendermint/vm/topdown/proof-service/src/assembler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl ProofAssembler {
8080

8181
/// Create a Lotus client for requests
8282
fn create_client(&self) -> Result<LotusClient> {
83-
Ok(LotusClient::new(Url::parse(&self.rpc_url)?, None))
83+
Ok(LotusClient::new(self.rpc_url.clone(), None))
8484
}
8585

8686
/// Generate proof bundle for a certificate
@@ -118,7 +118,7 @@ impl ProofAssembler {
118118
//
119119
// The F3 certificate contains only the tipset CID and epoch, not the full tipset data.
120120
// We fetch the actual tipsets here to extract block headers, state roots, and receipts.
121-
let client = self.create_client();
121+
let client = self.create_client()?;
122122

123123
let parent_tipset = client
124124
.request(
@@ -203,7 +203,7 @@ impl ProofAssembler {
203203
);
204204

205205
// Create LotusClient for this request (not stored due to Rc/RefCell)
206-
let lotus_client = self.create_client();
206+
let lotus_client = self.create_client()?;
207207

208208
// Generate proof bundle in blocking task
209209
// CRITICAL: The proofs library uses Rc/RefCell internally making LotusClient and

fendermint/vm/topdown/proof-service/src/cache.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ impl ProofCache {
9191
/// Returns the proof for (last_committed + 1)
9292
pub fn get_next_uncommitted(&self) -> Option<CacheEntry> {
9393
let last_committed = self.last_committed_instance.load(Ordering::Acquire);
94+
let next_instance = last_committed + 1;
95+
9496
let result = self.entries.read().get(&next_instance).cloned();
9597

9698
// Record cache hit/miss
@@ -281,28 +283,44 @@ impl ProofCache {
281283
#[cfg(test)]
282284
mod tests {
283285
use super::*;
284-
use crate::types::SerializableF3Certificate;
286+
use crate::types::{
287+
CacheEntry, SerializableCacheEntry, SerializableECChainEntry, SerializableF3Certificate,
288+
SerializablePowerEntries, SerializablePowerEntry, SerializableSupplementalData,
289+
};
285290
use proofs::proofs::common::bundle::UnifiedProofBundle;
286291
use std::time::SystemTime;
287292

288293
fn create_test_entry(instance_id: u64, epochs: Vec<i64>) -> CacheEntry {
289-
CacheEntry {
290-
instance_id,
291-
finalized_epochs: epochs.clone(),
292-
proof_bundle: UnifiedProofBundle {
294+
use multihash_codetable::{Code, MultihashDigest};
295+
296+
let power_table_cid = cid::Cid::new_v1(0x55, Code::Blake2b256.digest(b"test")).to_string();
297+
298+
let ec_chain = epochs
299+
.into_iter()
300+
.map(|epoch| SerializableECChainEntry {
301+
epoch,
302+
key: vec!["0".to_string()],
303+
power_table: power_table_cid.clone(),
304+
commitments: vec![0u8; 32],
305+
})
306+
.collect();
307+
308+
let serializable = SerializableCacheEntry {
309+
proof_bundle: Some(UnifiedProofBundle {
293310
storage_proofs: vec![],
294311
event_proofs: vec![],
295312
blocks: vec![],
296-
},
313+
}),
297314
certificate: SerializableF3Certificate {
298-
instance_id,
299-
finalized_epochs: epochs,
300-
power_table_cid: {
301-
use multihash_codetable::{Code, MultihashDigest};
302-
cid::Cid::new_v1(0x55, Code::Blake2b256.digest(b"test")).to_string()
315+
gpbft_instance: instance_id,
316+
ec_chain,
317+
supplemental_data: SerializableSupplementalData {
318+
power_table: power_table_cid.clone(),
319+
commitments: vec![0u8; 32],
303320
},
321+
signers: vec![0],
304322
signature: vec![],
305-
signers: vec![],
323+
power_table_delta: vec![],
306324
},
307325
power_table: SerializablePowerEntries(vec![SerializablePowerEntry {
308326
id: 1,

fendermint/vm/topdown/proof-service/src/lib.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ pub mod verifier;
2525
pub use cache::ProofCache;
2626
pub use config::{CacheConfig, ProofServiceConfig};
2727
pub use service::ProofGeneratorService;
28-
pub use types::{CacheEntry, SerializableF3Certificate, ValidatedCertificate};
29-
pub use verifier::verify_proof_bundle;
28+
pub use types::{CacheEntry, SerializableF3Certificate};
3029

3130
use anyhow::{Context, Result};
3231
use std::sync::Arc;
@@ -103,15 +102,15 @@ pub async fn launch_service(
103102
let cache_clone = cache.clone();
104103
let power_table_clone = initial_power_table.clone();
105104

106-
// Clone what we need for the background task
107-
let config_clone = config.clone();
108-
let cache_clone = cache.clone();
109-
let power_table_clone = power_table.clone();
110-
111105
// Spawn background task
112106
let handle = tokio::spawn(async move {
113-
match ProofGeneratorService::new(config_clone, cache_clone, initial_committed_instance)
114-
.await
107+
match ProofGeneratorService::new(
108+
config_clone,
109+
cache_clone,
110+
initial_committed_instance,
111+
power_table_clone,
112+
)
113+
.await
115114
{
116115
Ok(service) => service.run().await,
117116
Err(e) => {
@@ -130,8 +129,6 @@ mod tests {
130129

131130
#[tokio::test]
132131
async fn test_launch_service_disabled() {
133-
use filecoin_f3_gpbft::PowerEntries;
134-
135132
let config = ProofServiceConfig {
136133
enabled: false,
137134
..Default::default()
@@ -146,7 +143,6 @@ mod tests {
146143
#[tokio::test]
147144
async fn test_launch_service_enabled() {
148145
use crate::config::GatewayId;
149-
use filecoin_f3_gpbft::PowerEntries;
150146

151147
let config = ProofServiceConfig {
152148
enabled: true,

0 commit comments

Comments
 (0)