Skip to content

Commit

Permalink
feat: add interaction trace to prove_brainfuck entrypoint (#97)
Browse files Browse the repository at this point in the history
* feat: add memory to BrainfuckInteractionElements

* feat: add interaction trace evaluation to prove_brainfuck
  • Loading branch information
zmalatrax authored Nov 27, 2024
1 parent 0b521b4 commit 76bda39
Showing 1 changed file with 34 additions and 12 deletions.
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::{
constraint_framework::{INTERACTION_TRACE_IDX, ORIGINAL_TRACE_IDX, PREPROCESSED_TRACE_IDX},
Expand Down Expand Up @@ -45,22 +51,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 @@ -144,12 +157,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 @@ -160,10 +174,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

0 comments on commit 76bda39

Please sign in to comment.