forked from BCWResearch/zero-bin-bcw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
113 lines (101 loc) · 3.25 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use anyhow::Result;
use ethereum_types::U256;
#[cfg(feature = "test_only")]
use futures::stream::TryStreamExt;
use ops::TxProof;
use paladin::{
directive::{Directive, IndexedStream},
runtime::Runtime,
};
use proof_gen::{proof_types::GeneratedBlockProof, types::PlonkyProofIntern};
use serde::{Deserialize, Serialize};
use trace_decoder::{
processed_block_trace::ProcessingMeta,
trace_protocol::BlockTrace,
types::{CodeHash, OtherBlockData},
};
#[cfg(feature = "test_only")]
use tracing::info;
#[derive(Debug, Deserialize, Serialize)]
pub struct ProverInput {
pub block_trace: BlockTrace,
pub other_data: OtherBlockData,
}
fn resolve_code_hash_fn(_: &CodeHash) -> Vec<u8> {
todo!()
}
impl ProverInput {
pub fn get_block_number(&self) -> U256 {
self.other_data.b_data.b_meta.block_number
}
/// Evaluates a singular block
#[cfg(not(feature = "test_only"))]
pub async fn prove(
self,
runtime: &Runtime,
previous: Option<PlonkyProofIntern>,
save_inputs_on_error: bool,
) -> Result<GeneratedBlockProof> {
let block_number = self.get_block_number();
let other_data = self.other_data;
let txs = self.block_trace.into_txn_proof_gen_ir(
&ProcessingMeta::new(resolve_code_hash_fn),
other_data.clone(),
)?;
let agg_proof = IndexedStream::from(txs)
.map(&TxProof {
save_inputs_on_error,
})
.fold(&ops::AggProof {
save_inputs_on_error,
})
.run(runtime)
.await?;
if let proof_gen::proof_types::AggregatableProof::Agg(proof) = agg_proof {
let prev = previous.map(|p| GeneratedBlockProof {
b_height: block_number.as_u64() - 1,
intern: p,
});
let block_proof = paladin::directive::Literal(proof)
.map(&ops::BlockProof {
prev,
save_inputs_on_error,
})
.run(runtime)
.await?;
// Return the block proof
Ok(block_proof.0)
} else {
anyhow::bail!("AggProof is is not GeneratedAggProof")
}
}
#[cfg(feature = "test_only")]
pub async fn prove(
self,
runtime: &Runtime,
_previous: Option<PlonkyProofIntern>,
save_inputs_on_error: bool,
) -> Result<GeneratedBlockProof> {
let block_number = self.get_block_number();
info!("Testing witness generation for block {block_number}.");
let other_data = self.other_data;
let txs = self.block_trace.into_txn_proof_gen_ir(
&ProcessingMeta::new(resolve_code_hash_fn),
other_data.clone(),
)?;
IndexedStream::from(txs)
.map(&TxProof {
save_inputs_on_error,
})
.run(runtime)
.await?
.try_collect::<Vec<_>>()
.await?;
info!("Successfully generated witness for block {block_number}.");
// Dummy proof to match expected output type.
Ok(GeneratedBlockProof {
b_height: block_number.as_u64(),
intern: proof_gen::proof_gen::dummy_proof()?,
})
}
}