Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add memory component to BrainfuckComponents #103

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions crates/brainfuck_prover/src/brainfuck_air/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use crate::components::{
memory::{
self,
component::{MemoryComponent, MemoryEval},
table::{interaction_trace_evaluation, MemoryElements, MemoryTable},
},
MemoryClaim,
};
use brainfuck_vm::machine::Machine;
use stwo_prover::{
constraint_framework::{INTERACTION_TRACE_IDX, ORIGINAL_TRACE_IDX, PREPROCESSED_TRACE_IDX},
constraint_framework::{
preprocessed_columns::PreprocessedColumn, TraceLocationAllocator, INTERACTION_TRACE_IDX,
ORIGINAL_TRACE_IDX, PREPROCESSED_TRACE_IDX,
},
core::{
air::{Component, ComponentProver},
backend::simd::SimdBackend,
Expand Down Expand Up @@ -90,26 +94,43 @@ pub fn lookup_sum_valid(
///
/// Components are used by the prover as a `ComponentProver`,
/// and by the verifier as a `Component`.
pub struct BrainfuckComponents;
pub struct BrainfuckComponents {
memory: MemoryComponent,
}

impl BrainfuckComponents {
/// Initializes all the Brainfuck components from the claims generated from the trace.
pub fn new(
_claim: &BrainfuckClaim,
_interaction_elements: &BrainfuckInteractionElements,
_interaction_claim: &BrainfuckInteractionClaim,
claim: &BrainfuckClaim,
interaction_elements: &BrainfuckInteractionElements,
interaction_claim: &BrainfuckInteractionClaim,
) -> Self {
todo!();
let memory_is_first_column = PreprocessedColumn::IsFirst(claim.memory.log_size);

let tree_span_provider =
&mut TraceLocationAllocator::new_with_preproccessed_columnds(&[memory_is_first_column]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related here but just PRed Stwo to fix the typo starkware-libs/stwo#910


let memory = MemoryComponent::new(
tree_span_provider,
MemoryEval::new(
&claim.memory,
interaction_elements.memory_lookup_elements.clone(),
&interaction_claim.memory,
),
(interaction_claim.memory.claimed_sum, None),
);

Self { memory }
}

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

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

Expand Down Expand Up @@ -194,10 +215,9 @@ pub fn prove_brainfuck(
let component_builder =
BrainfuckComponents::new(&claim, &interaction_elements, &interaction_claim);
let components = component_builder.provers();
let _proof = prover::prove::<SimdBackend, _>(&components, channel, commitment_scheme)?;
let proof = prover::prove::<SimdBackend, _>(&components, channel, commitment_scheme)?;

// Ok(BrainfuckProof { claim, interaction_claim, proof })
todo!();
Ok(BrainfuckProof { claim, interaction_claim, proof })
}

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