diff --git a/.gitignore b/.gitignore index ea8c4bf..cfce873 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target + +*_proof.json diff --git a/README.md b/README.md index 6f1e146..5cab96f 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ brainfuck_prover prove --file my_program.bf --output my_program_proof.json Or if you built from source, ```shell -./target/release/brainfuck_prover prove --file my_program.bf --output my_program_proof.json +./target/release/brainfuck_prover prove --file ./brainfuck_programs/hello_kakarot.bf --output hello_kakarot_proof.json ``` ### Verify @@ -89,6 +89,30 @@ To verify a proof, the proof must be stored in a JSON file (`--output` flag from brainfuck_prover verify my_program_proof.json ``` +Or if you built from source and previously generated the proof of the `hello_kakarot` example: + +```shell +./target/release/brainfuck_prover verify hello_kakarot_proof.json +``` + +### Visualizing the memory + +To visualize the memory of the Brainfuck VM, use the `--memory` flag of the `brainfuck_prover`, and reduce the RAM size to avoid printing too much memory cells to your terminal with the `--ram-size` flag. + +Let's try it with a Brainfuck program that yields the 19th Fibonacci number. Note that it is a bit more resource intensive than the other example programs. + +```shell +./target/release/brainfuck_prover prove --file ./brainfuck_programs/fib19.bf --output fib19_proof.json --memory --ram-size 5 +``` + +You should be able to see: + +```shell +[M31(0), M31(2584), M31(4181), M31(0), M31(0)] +``` + +The third memory cell contains the desired output: `Fibonacci(19) = 4181`. + ## Project Objectives - Capacity of generating and verifying a proof for arbitrary Brainfuck programs. diff --git a/brainfuck_programs/fib.bf b/brainfuck_programs/fib19.bf similarity index 100% rename from brainfuck_programs/fib.bf rename to brainfuck_programs/fib19.bf diff --git a/crates/brainfuck_vm/tests/integration.rs b/crates/brainfuck_vm/tests/integration.rs index f84189f..26f5b9e 100644 --- a/crates/brainfuck_vm/tests/integration.rs +++ b/crates/brainfuck_vm/tests/integration.rs @@ -89,12 +89,16 @@ fn test_hello_kakarot_world() { } #[test] -fn test_fib_19() { - let path = "../../brainfuck_programs/fib.bf"; +fn test_fib19() { + let path = "../../brainfuck_programs/fib19.bf"; let code = compile_from_path(path); let (mut machine, output) = create_test_machine(&code, &[]); machine.execute().unwrap(); + // 19th Fibonacci number is 4181 + // Output is misleading as the I/O of Brainfuck is only 1 byte, + // so the memory values are truncated + // (hence the output of 85, 4181 % 256 = 85) let expected_output = [85]; assert_eq!(output.output(), expected_output); }