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 interaction trace to prove_brainfuck entrypoint #97

Merged
merged 2 commits into from
Nov 27, 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
46 changes: 34 additions & 12 deletions crates/brainfuck_prover/src/brainfuck_air/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use crate::components::{memory::table::MemoryTable, MemoryClaim};
use crate::components::{
memory::{
self,
table::{interaction_trace_evaluation, MemoryElements, MemoryTable},
},
MemoryClaim,
};
use brainfuck_vm::machine::Machine;
use stwo_prover::core::{
air::{Component, ComponentProver},
Expand Down Expand Up @@ -42,22 +48,29 @@ impl BrainfuckClaim {

/// All the interaction elements (drawn from the channel)
/// required by the various components during the interaction phase.
pub struct BrainfuckInteractionElements;
pub struct BrainfuckInteractionElements {
pub memory_lookup_elements: MemoryElements,
}

impl BrainfuckInteractionElements {
pub fn draw(_channel: &mut impl Channel) -> Self {
todo!();
/// Draw all the interaction elements needed for
/// all the components of the Brainfuck ZK-VM.
pub fn draw(channel: &mut impl Channel) -> Self {
Self { memory_lookup_elements: MemoryElements::draw(channel) }
}
}

/// All the claims from the second phase (interaction phase 1).
/// All the claims from the second phase (interaction phase 2).
///
/// Mainly the claims on global relations (lookup, permutation, evaluation).
pub struct BrainfuckInteractionClaim;
pub struct BrainfuckInteractionClaim {
memory: memory::component::InteractionClaim,
}

impl BrainfuckInteractionClaim {
pub fn mix_into(&self, _channel: &mut impl Channel) {
todo!();
/// Mix the claimed sums of every components in the Fiat-Shamir [`Channel`].
pub fn mix_into(&self, channel: &mut impl Channel) {
self.memory.mix_into(channel);
}
}

Expand Down Expand Up @@ -141,12 +154,13 @@ pub fn prove_brainfuck(
let vm_trace = inputs.trace();
let (memory_trace, memory_claim) = MemoryTable::from(vm_trace).trace_evaluation().unwrap();

tree_builder.extend_evals(memory_trace);
tree_builder.extend_evals(memory_trace.clone());

let claim = BrainfuckClaim { memory: memory_claim };

// Commit to the claim and the trace.
// Mix the claim into the Fiat-Shamir channel.
claim.mix_into(channel);
// Commit the main trace.
tree_builder.commit(channel);

// ┌───────────────────────────────────────────────┐
Expand All @@ -157,10 +171,18 @@ pub fn prove_brainfuck(
let interaction_elements = BrainfuckInteractionElements::draw(channel);

// Generate the interaction trace and the BrainfuckInteractionClaim
let tree_builder = commitment_scheme.tree_builder();
let mut tree_builder = commitment_scheme.tree_builder();

let (memory_interaction_trace_eval, memory_interaction_claim) =
interaction_trace_evaluation(&memory_trace, &interaction_elements.memory_lookup_elements);

tree_builder.extend_evals(memory_interaction_trace_eval);

let interaction_claim = BrainfuckInteractionClaim { memory: memory_interaction_claim };

let interaction_claim = BrainfuckInteractionClaim {};
// Mix the interaction claim into the Fiat-Shamir channel.
interaction_claim.mix_into(channel);
// Commit the interaction trace.
tree_builder.commit(channel);

// ┌──────────────────────────┐
Expand Down