|
1 | 1 | use crate::components::{
|
2 | 2 | memory::{
|
3 | 3 | self,
|
| 4 | + component::{MemoryComponent, MemoryEval}, |
4 | 5 | table::{interaction_trace_evaluation, MemoryElements, MemoryTable},
|
5 | 6 | },
|
6 | 7 | MemoryClaim,
|
7 | 8 | };
|
8 | 9 | use brainfuck_vm::machine::Machine;
|
9 | 10 | use stwo_prover::{
|
10 |
| - constraint_framework::{INTERACTION_TRACE_IDX, ORIGINAL_TRACE_IDX, PREPROCESSED_TRACE_IDX}, |
| 11 | + constraint_framework::{ |
| 12 | + preprocessed_columns::PreprocessedColumn, TraceLocationAllocator, INTERACTION_TRACE_IDX, |
| 13 | + ORIGINAL_TRACE_IDX, PREPROCESSED_TRACE_IDX, |
| 14 | + }, |
11 | 15 | core::{
|
12 | 16 | air::{Component, ComponentProver},
|
13 | 17 | backend::simd::SimdBackend,
|
@@ -90,26 +94,43 @@ pub fn lookup_sum_valid(
|
90 | 94 | ///
|
91 | 95 | /// Components are used by the prover as a `ComponentProver`,
|
92 | 96 | /// and by the verifier as a `Component`.
|
93 |
| -pub struct BrainfuckComponents; |
| 97 | +pub struct BrainfuckComponents { |
| 98 | + memory: MemoryComponent, |
| 99 | +} |
94 | 100 |
|
95 | 101 | impl BrainfuckComponents {
|
96 | 102 | /// Initializes all the Brainfuck components from the claims generated from the trace.
|
97 | 103 | pub fn new(
|
98 |
| - _claim: &BrainfuckClaim, |
99 |
| - _interaction_elements: &BrainfuckInteractionElements, |
100 |
| - _interaction_claim: &BrainfuckInteractionClaim, |
| 104 | + claim: &BrainfuckClaim, |
| 105 | + interaction_elements: &BrainfuckInteractionElements, |
| 106 | + interaction_claim: &BrainfuckInteractionClaim, |
101 | 107 | ) -> Self {
|
102 |
| - todo!(); |
| 108 | + let memory_is_first_column = PreprocessedColumn::IsFirst(claim.memory.log_size); |
| 109 | + |
| 110 | + let tree_span_provider = |
| 111 | + &mut TraceLocationAllocator::new_with_preproccessed_columnds(&[memory_is_first_column]); |
| 112 | + |
| 113 | + let memory = MemoryComponent::new( |
| 114 | + tree_span_provider, |
| 115 | + MemoryEval::new( |
| 116 | + &claim.memory, |
| 117 | + interaction_elements.memory_lookup_elements.clone(), |
| 118 | + &interaction_claim.memory, |
| 119 | + ), |
| 120 | + (interaction_claim.memory.claimed_sum, None), |
| 121 | + ); |
| 122 | + |
| 123 | + Self { memory } |
103 | 124 | }
|
104 | 125 |
|
105 | 126 | /// Returns the `ComponentProver` of each components, used by the prover.
|
106 | 127 | pub fn provers(&self) -> Vec<&dyn ComponentProver<SimdBackend>> {
|
107 |
| - todo!(); |
| 128 | + vec![&self.memory] |
108 | 129 | }
|
109 | 130 |
|
110 | 131 | /// Returns the `Component` of each components, used by the verifier.
|
111 | 132 | pub fn components(&self) -> Vec<&dyn Component> {
|
112 |
| - todo!(); |
| 133 | + self.provers().into_iter().map(|component| component as &dyn Component).collect() |
113 | 134 | }
|
114 | 135 | }
|
115 | 136 |
|
@@ -194,10 +215,9 @@ pub fn prove_brainfuck(
|
194 | 215 | let component_builder =
|
195 | 216 | BrainfuckComponents::new(&claim, &interaction_elements, &interaction_claim);
|
196 | 217 | let components = component_builder.provers();
|
197 |
| - let _proof = prover::prove::<SimdBackend, _>(&components, channel, commitment_scheme)?; |
| 218 | + let proof = prover::prove::<SimdBackend, _>(&components, channel, commitment_scheme)?; |
198 | 219 |
|
199 |
| - // Ok(BrainfuckProof { claim, interaction_claim, proof }) |
200 |
| - todo!(); |
| 220 | + Ok(BrainfuckProof { claim, interaction_claim, proof }) |
201 | 221 | }
|
202 | 222 |
|
203 | 223 | /// Verify a given STARK proof of a Brainfuck program execution with corresponding claim.
|
|
0 commit comments