Skip to content

Commit

Permalink
feat: merkle tree proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrltrent committed Dec 21, 2024
1 parent 176d7e6 commit 6abcc1b
Show file tree
Hide file tree
Showing 19 changed files with 272 additions and 472 deletions.
46 changes: 20 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["lib", "lib2", "lib3", "program", "script"]
members = ["lib", "lib3", "program", "script"]
resolver = "2"

[workspace.dependencies]
Expand Down
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.PHONY: test-merkle-tree-lib build-program run-program execute-program-gen-core-proof-groth16 execute-program-gen-core-proof-plonk

test-merkle-tree-lib:
@cd lib3 && cargo test

build-program:
@cd program && cargo prove build

run-program:
@cd script && cargo run --release -- --execute --data "a b c d" --index 2

# for these two cmds below, have Docker funning; also, know it might take a few minutes
#
# they could also auto-download image: "ghcr.io/succinctlabs/sp1-gnark:v3.0.0"
#
# from what I can see... if you don't have enough memory, docker run will fail after about ~10 minutes on my machine
execute-program-gen-core-proof-groth16:
@cd script && RUST_LOG=info cargo run --release --bin evm -- --data "a b c d" --index 2 --groth16
execute-program-gen-core-proof-plonk:
@cd script && RUST_LOG=info cargo run --release --bin evm -- --data "a b c d" --index 2 --plonk
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,34 @@
This is a template for creating an end-to-end [SP1](https://github.com/succinctlabs/sp1) project
that can generate a proof of any RISC-V program.

# Shorthands

Use the `Makefile` to run the following commands from the root directory of the project:

```sh
# runs tests on the merkle tree lib
make test-merkle-tree-lib

# builds the main program (creates and sets `SP1_ELF_merkle-tree-program`)
make build-program

# runs the main program with dummy data
make run-program

### these output fixtures for evm-compatible proofs into
### the ~/contracts/fixtures directory upon succesfully completing
#
# generates a core proof (more time-consuming) for groth16 + you need Docker running
make execute-program-gen-core-proof-groth16
# generates a core proof (more time-consuming) for plonk + you need Docker running
make execute-program-gen-core-proof-plonk
```

## Requirements

- [Rust](https://rustup.rs/)
- [SP1](https://docs.succinct.xyz/getting-started/install.html)
- Docker (for core proof generation)

## Running the Project

Expand Down Expand Up @@ -73,7 +97,7 @@ cargo prove vkey --program fibonacci-program

## Using the Prover Network

We highly recommend using the Succinct prover network for any non-trivial programs or benchmarking purposes. For more information, see the [setup guide](https://docs.succinct.xyz/generating-proofs/prover-network.html).
We highly recommend using the Succinct prover network for any non-trivial programs or benchmarking purposes. For more information, see ~~the [setup guide](https://docs.succinct.xyz/generating-proofs/prover-network.html).~~ [this setup guide](https://docs.succinct.xyz/docs/generating-proofs/prover-network/key-setup).

To get started, copy the example environment file:

Expand All @@ -91,6 +115,14 @@ command:
SP1_PROVER=network SP1_PRIVATE_KEY=... cargo run --release --bin evm
```

## Debugging Note
## Notes

- If you are running this on MacOS M1 aarch64, don't use `zsh` as your shell. Use `bash` instead; `zsh` throws unintelligible errors.

## Next Steps

- Right now `~/lib` contains the old fibonacci program. `/~lib3` is the current refactoring effort to make this work for Merkle Trees.
- There are some `.expect()` and `.unwrap()` calls in the code that should be handled more gracefully (marked with `// todo ...`s).
- The `evm.rs` file should be generating fixtures for the EVM-compatible proof (output in `~/contracts/fixtures`), but I think my computer is running out of memory to do so; everything code-wise *seems* correct.
- To deploy on their [Prover Network](https://docs.succinct.xyz/docs/generating-proofs/prover-network) you need to sign up for beta access! So, it could be worth [signing up for that](https://docs.google.com/forms/d/e/1FAIpQLSd-X9uH7G0bvXH_kjptnQtNil8L4dumrVPpFE4t8Ci1XT1GaQ/viewform) in case it takes a while. They claim this network is the best way to generate proofs for large, complex programs.

If you are running this on MacOS M1 aarch64, don't use `zsh` as your shell. Use `bash` instead; `zsh` throws unintelligible errors.
Binary file modified elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
10 changes: 0 additions & 10 deletions lib2/Cargo.toml

This file was deleted.

59 changes: 0 additions & 59 deletions lib2/src/hash.rs

This file was deleted.

5 changes: 0 additions & 5 deletions lib2/src/lib.rs

This file was deleted.

16 changes: 0 additions & 16 deletions lib2/src/merkle_proof.rs

This file was deleted.

19 changes: 0 additions & 19 deletions lib2/src/merkle_tree.rs

This file was deleted.

70 changes: 0 additions & 70 deletions lib2/src/node.rs

This file was deleted.

17 changes: 0 additions & 17 deletions lib2/src/solidity.rs

This file was deleted.

2 changes: 2 additions & 0 deletions lib3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ alloy-sol-types = "0.7"
rs_merkle = "1.4.2"
sha2 = "0.10"
hex = "0.4"
serde = { version = "1.0", features = ["derive"] }

Loading

0 comments on commit 6abcc1b

Please sign in to comment.