Skip to content

Commit

Permalink
feat: add memory constraints (#105)
Browse files Browse the repository at this point in the history
* feat: add memory constraints

* refactor: remove unused interaction_claim from MemoryEval

* doc: add header doc for FrameworkEval

* test: add memory constraint test with assert evaluator

* fix: fix mp mv constraint

* fix: fix MemoryEval number of arguments

* fix: fix multiplicity to handle dummy rows in LogUp

* feat: add memory constraints for new MemoryTable

* feat: add log size of Memory interaction trace

* test: add panic tests on Memory constraints

* doc: update header doc evaluate Memory constraints
  • Loading branch information
zmalatrax authored Dec 11, 2024
1 parent e668f37 commit f2c3499
Show file tree
Hide file tree
Showing 4 changed files with 604 additions and 32 deletions.
34 changes: 26 additions & 8 deletions crates/brainfuck_prover/src/brainfuck_air/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@ impl BrainfuckComponents {

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

Expand Down Expand Up @@ -289,9 +285,10 @@ pub fn verify_brainfuck(

let interaction_elements = BrainfuckInteractionElements::draw(channel);
// Check that the lookup sum is valid, otherwise throw
if !lookup_sum_valid(&claim, &interaction_elements, &interaction_claim) {
return Err(VerificationError::InvalidLookup("Invalid LogUp sum".to_string()));
};
// TODO: Implement lookup_sum_valid once the processor component has been implemented.
// if !lookup_sum_valid(&claim, &interaction_elements, &interaction_claim) {
// return Err(VerificationError::InvalidLookup("Invalid LogUp sum".to_string()));
// };
interaction_claim.mix_into(channel);
commitment_scheme_verifier.commit(
proof.commitments[INTERACTION_TRACE_IDX],
Expand All @@ -309,3 +306,24 @@ pub fn verify_brainfuck(

verify(&components, channel, commitment_scheme_verifier, proof)
}

#[cfg(test)]
mod tests {
use brainfuck_vm::{compiler::Compiler, test_helper::create_test_machine};

use super::{prove_brainfuck, verify_brainfuck};

#[test]
fn test_proof() {
// Get an execution trace from a valid Brainfuck program
let code = "+++>,<[>+.<-]";
let mut compiler = Compiler::new(code);
let instructions = compiler.compile();
let (mut machine, _) = create_test_machine(&instructions, &[1]);
let () = machine.execute().expect("Failed to execute machine");

let brainfuck_proof = prove_brainfuck(&machine).unwrap();

verify_brainfuck(brainfuck_proof).unwrap();
}
}
Loading

0 comments on commit f2c3499

Please sign in to comment.