Skip to content

Commit 404b168

Browse files
committed
test: Add functionality to extract FRI proof from STARK proof
This functionality might belong in the Triton VM repository. See <TritonVM/triton-vm#258> for thoughts about this problem.
1 parent 524b07e commit 404b168

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

src/tests_and_benchmarks/ozk/programs/recufier/fri_verify.rs

+105
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
use tasm_lib::prelude::TasmObject;
22
use tasm_lib::triton_vm::prelude::*;
3+
use tasm_lib::triton_vm::stark::StarkProofStream;
4+
use tasm_lib::triton_vm::table::challenges::Challenges;
5+
use tasm_lib::triton_vm::table::extension_table::Quotientable;
6+
use tasm_lib::triton_vm::table::master_table::MasterExtTable;
7+
use tasm_lib::triton_vm::table::*;
38

49
use super::arithmetic_domain::*;
510

@@ -38,9 +43,91 @@ fn main() {
3843
return;
3944
}
4045

46+
/// Extracts a proof stream that will work for FRI verification from a proof stream that works for
47+
/// the whole STARK verification.
48+
pub(super) fn extract_fri_proof(
49+
proof_stream: &StarkProofStream,
50+
claim: &Claim,
51+
) -> StarkProofStream {
52+
let mut proof_stream = proof_stream.to_owned();
53+
proof_stream
54+
.dequeue()
55+
.unwrap()
56+
.try_into_log2_padded_height()
57+
.unwrap();
58+
proof_stream.alter_fiat_shamir_state_with(claim);
59+
60+
// Base-table Merkle root
61+
proof_stream
62+
.dequeue()
63+
.unwrap()
64+
.try_into_merkle_root()
65+
.unwrap();
66+
67+
// Extension challenge weights
68+
proof_stream.sample_scalars(Challenges::SAMPLE_COUNT);
69+
70+
// Extension-table Merkle root
71+
proof_stream
72+
.dequeue()
73+
.unwrap()
74+
.try_into_merkle_root()
75+
.unwrap();
76+
77+
// Quotient codeword weights
78+
proof_stream.sample_scalars(MasterExtTable::NUM_CONSTRAINTS);
79+
80+
// Quotient codeword Merkle root
81+
proof_stream
82+
.dequeue()
83+
.unwrap()
84+
.try_into_merkle_root()
85+
.unwrap();
86+
87+
// Out-of-domain point current row
88+
proof_stream.sample_scalars(1);
89+
90+
// Five out-of-domain values
91+
proof_stream
92+
.dequeue()
93+
.unwrap()
94+
.try_into_out_of_domain_base_row()
95+
.unwrap();
96+
proof_stream
97+
.dequeue()
98+
.unwrap()
99+
.try_into_out_of_domain_ext_row()
100+
.unwrap();
101+
proof_stream
102+
.dequeue()
103+
.unwrap()
104+
.try_into_out_of_domain_base_row()
105+
.unwrap();
106+
proof_stream
107+
.dequeue()
108+
.unwrap()
109+
.try_into_out_of_domain_ext_row()
110+
.unwrap();
111+
proof_stream
112+
.dequeue()
113+
.unwrap()
114+
.try_into_out_of_domain_quot_segments()
115+
.unwrap();
116+
117+
// `base_and_ext_and_quotient_segment_codeword_weights`
118+
proof_stream.sample_scalars(NUM_BASE_COLUMNS + NUM_EXT_COLUMNS + NUM_QUOTIENT_SEGMENTS);
119+
120+
// Deep codeword weights
121+
const NUM_DEEP_CODEWORD_COMPONENTS: usize = 3;
122+
proof_stream.sample_scalars(NUM_DEEP_CODEWORD_COMPONENTS);
123+
124+
proof_stream
125+
}
126+
41127
#[cfg(test)]
42128
mod test {
43129
use rand::random;
130+
use tasm_lib::triton_vm;
44131

45132
use crate::tests_and_benchmarks::ozk::ozk_parsing;
46133
use crate::tests_and_benchmarks::ozk::ozk_parsing::EntrypointLocation;
@@ -73,4 +160,22 @@ mod test {
73160

74161
assert_eq!(native_output, vm_output.output);
75162
}
163+
164+
#[test]
165+
fn extract_fri_proof_works() {
166+
let simple_program = triton_program!(halt);
167+
let public_input = [];
168+
let non_determinism = NonDeterminism::default();
169+
let (stark, claim, proof) =
170+
triton_vm::prove_program(&simple_program, &public_input, &non_determinism).unwrap();
171+
let padded_height = proof.padded_height().unwrap();
172+
let fri = stark.derive_fri(padded_height).unwrap();
173+
174+
let proof_stream = StarkProofStream::try_from(&proof).unwrap();
175+
let mut fri_proof_stream = extract_fri_proof(&proof_stream, &claim);
176+
assert!(
177+
fri.verify(&mut fri_proof_stream, &mut None).is_ok(),
178+
"Proof must verify"
179+
);
180+
}
76181
}

0 commit comments

Comments
 (0)