Skip to content

Commit 125d092

Browse files
committed
wip
1 parent 1ea218c commit 125d092

File tree

12 files changed

+346
-242
lines changed

12 files changed

+346
-242
lines changed

ceno_zkvm/src/keygen.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ impl<E: ExtensionField> ZKVMConstraintSystem<E> {
1414
) -> Result<ZKVMProvingKey<E, PCS>, ZKVMError> {
1515
let mut vm_pk = ZKVMProvingKey::new(pp.clone(), vp);
1616
let mut fixed_traces = Vec::with_capacity(self.circuit_css.len());
17+
let mut fixed_trace_index = Vec::with_capacity(self.circuit_css.len());
1718

1819
for (c_name, cs) in self.circuit_css {
1920
// fixed_traces is optional
@@ -25,7 +26,10 @@ impl<E: ExtensionField> ZKVMConstraintSystem<E> {
2526
.remove(&c_name)
2627
.flatten()
2728
.ok_or(ZKVMError::FixedTraceNotFound(c_name.clone()))?,
28-
)
29+
);
30+
fixed_trace_index.push(Some(fixed_trace_index.len()))
31+
} else {
32+
fixed_trace_index.push(None)
2933
};
3034

3135
let circuit_pk = cs.key_gen();
@@ -36,6 +40,7 @@ impl<E: ExtensionField> ZKVMConstraintSystem<E> {
3640

3741
vm_pk.initial_global_state_expr = self.initial_global_state_expr;
3842
vm_pk.finalize_global_state_expr = self.finalize_global_state_expr;
43+
vm_pk.fixed_trace_index = fixed_trace_index;
3944

4045
Ok(vm_pk)
4146
}

ceno_zkvm/src/scheme.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ mod tests;
2929
serialize = "E::BaseField: Serialize",
3030
deserialize = "E::BaseField: DeserializeOwned"
3131
))]
32-
pub struct ZKVMOpcodeProof<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> {
32+
pub struct ZKVMOpcodeProof<E: ExtensionField> {
3333
// TODO support >1 opcodes
3434
pub num_instances: usize,
3535

@@ -51,7 +51,6 @@ pub struct ZKVMOpcodeProof<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>
5151
pub w_records_in_evals: Vec<E>,
5252
pub lk_records_in_evals: Vec<E>,
5353

54-
pub wits_commit: PCS::Commitment,
5554
pub wits_in_evals: Vec<E>,
5655
}
5756

@@ -60,7 +59,7 @@ pub struct ZKVMOpcodeProof<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>
6059
serialize = "E::BaseField: Serialize",
6160
deserialize = "E::BaseField: DeserializeOwned"
6261
))]
63-
pub struct ZKVMTableProof<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> {
62+
pub struct ZKVMTableProof<E: ExtensionField> {
6463
// tower evaluation at layer 1
6564
pub r_out_evals: Vec<[E; 2]>,
6665
pub w_out_evals: Vec<[E; 2]>,
@@ -76,10 +75,7 @@ pub struct ZKVMTableProof<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>>
7675
pub rw_hints_num_vars: Vec<usize>,
7776

7877
pub fixed_in_evals: Vec<E>,
79-
pub fixed_opening_proof: Option<PCS::Proof>,
80-
pub wits_commit: PCS::Commitment,
8178
pub wits_in_evals: Vec<E>,
82-
pub wits_opening_proof: PCS::Proof,
8379
}
8480

8581
/// each field will be interpret to (constant) polynomial
@@ -143,14 +139,30 @@ pub struct ZKVMProof<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> {
143139
pub raw_pi: Vec<Vec<E::BaseField>>,
144140
// the evaluation of raw_pi.
145141
pub pi_evals: Vec<E>,
146-
opcode_proofs: BTreeMap<String, (usize, ZKVMOpcodeProof<E, PCS>)>,
147-
table_proofs: BTreeMap<String, (usize, ZKVMTableProof<E, PCS>)>,
142+
opcode_proofs: BTreeMap<String, (usize, ZKVMOpcodeProof<E>)>,
143+
table_proofs: BTreeMap<String, (usize, ZKVMTableProof<E>)>,
144+
pub fixed_witin_opening_proof: PCS::Proof,
148145
}
149146

150147
impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProof<E, PCS> {
151-
pub fn empty(pv: PublicValues<u32>) -> Self {
152-
let raw_pi = pv.to_vec::<E>();
153-
let pi_evals = raw_pi
148+
pub fn new(
149+
raw_pi: Vec<Vec<E::BaseField>>,
150+
pi_evals: Vec<E>,
151+
opcode_proofs: BTreeMap<String, (usize, ZKVMOpcodeProof<E>)>,
152+
table_proofs: BTreeMap<String, (usize, ZKVMTableProof<E>)>,
153+
fixed_witin_opening_proof: PCS::Proof,
154+
) -> Self {
155+
Self {
156+
raw_pi,
157+
pi_evals,
158+
opcode_proofs,
159+
table_proofs,
160+
fixed_witin_opening_proof,
161+
}
162+
}
163+
164+
pub fn pi_evals(raw_pi: &Vec<Vec<E::BaseField>>) -> Vec<E> {
165+
raw_pi
154166
.iter()
155167
.map(|pv| {
156168
if pv.len() == 1 {
@@ -162,13 +174,7 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProof<E, PCS> {
162174
E::ZERO
163175
}
164176
})
165-
.collect_vec();
166-
Self {
167-
raw_pi,
168-
pi_evals,
169-
opcode_proofs: BTreeMap::new(),
170-
table_proofs: BTreeMap::new(),
171-
}
177+
.collect_vec()
172178
}
173179

174180
pub fn update_pi_eval(&mut self, idx: usize, v: E) {

0 commit comments

Comments
 (0)