Skip to content

Commit 7200a6a

Browse files
authored
feat: add memory component to BrainfuckComponents (#103)
1 parent 4ac232a commit 7200a6a

File tree

1 file changed

+31
-11
lines changed
  • crates/brainfuck_prover/src/brainfuck_air

1 file changed

+31
-11
lines changed

crates/brainfuck_prover/src/brainfuck_air/mod.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
use crate::components::{
22
memory::{
33
self,
4+
component::{MemoryComponent, MemoryEval},
45
table::{interaction_trace_evaluation, MemoryElements, MemoryTable},
56
},
67
MemoryClaim,
78
};
89
use brainfuck_vm::machine::Machine;
910
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+
},
1115
core::{
1216
air::{Component, ComponentProver},
1317
backend::simd::SimdBackend,
@@ -90,26 +94,43 @@ pub fn lookup_sum_valid(
9094
///
9195
/// Components are used by the prover as a `ComponentProver`,
9296
/// and by the verifier as a `Component`.
93-
pub struct BrainfuckComponents;
97+
pub struct BrainfuckComponents {
98+
memory: MemoryComponent,
99+
}
94100

95101
impl BrainfuckComponents {
96102
/// Initializes all the Brainfuck components from the claims generated from the trace.
97103
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,
101107
) -> 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 }
103124
}
104125

105126
/// Returns the `ComponentProver` of each components, used by the prover.
106127
pub fn provers(&self) -> Vec<&dyn ComponentProver<SimdBackend>> {
107-
todo!();
128+
vec![&self.memory]
108129
}
109130

110131
/// Returns the `Component` of each components, used by the verifier.
111132
pub fn components(&self) -> Vec<&dyn Component> {
112-
todo!();
133+
self.provers().into_iter().map(|component| component as &dyn Component).collect()
113134
}
114135
}
115136

@@ -194,10 +215,9 @@ pub fn prove_brainfuck(
194215
let component_builder =
195216
BrainfuckComponents::new(&claim, &interaction_elements, &interaction_claim);
196217
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)?;
198219

199-
// Ok(BrainfuckProof { claim, interaction_claim, proof })
200-
todo!();
220+
Ok(BrainfuckProof { claim, interaction_claim, proof })
201221
}
202222

203223
/// Verify a given STARK proof of a Brainfuck program execution with corresponding claim.

0 commit comments

Comments
 (0)