|
1 | 1 | use tasm_lib::prelude::TasmObject;
|
2 | 2 | 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::*; |
3 | 8 |
|
4 | 9 | use super::arithmetic_domain::*;
|
5 | 10 |
|
@@ -38,9 +43,91 @@ fn main() {
|
38 | 43 | return;
|
39 | 44 | }
|
40 | 45 |
|
| 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 | + |
41 | 127 | #[cfg(test)]
|
42 | 128 | mod test {
|
43 | 129 | use rand::random;
|
| 130 | + use tasm_lib::triton_vm; |
44 | 131 |
|
45 | 132 | use crate::tests_and_benchmarks::ozk::ozk_parsing;
|
46 | 133 | use crate::tests_and_benchmarks::ozk::ozk_parsing::EntrypointLocation;
|
@@ -73,4 +160,22 @@ mod test {
|
73 | 160 |
|
74 | 161 | assert_eq!(native_output, vm_output.output);
|
75 | 162 | }
|
| 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 | + } |
76 | 181 | }
|
0 commit comments