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

docs: add fibonacci documentation #217

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target

*_proof.json
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 19th Fibonacci number:

```shell
./target/release/brainfuck_prover verify hello_kakarot.json
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

Forgot to change the sentence while changing the program to be verified

Copy link
Member Author

Choose a reason for hiding this comment

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

nice catch thx


### 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 20
```

You should be able to see:

```shell
[M31(0), M31(2584), M31(4181), M31(0), M31(0), M31(0), M31(0), M31(0), M31(0), M31(0), M31(0), M31(0), M31(0), M31(0), M31(0), M31(0), M31(0), M31(0), 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.
Expand Down
File renamed without changes.
8 changes: 6 additions & 2 deletions crates/brainfuck_vm/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading