Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
213c816
chore: try bls12381
manishbista28 May 19, 2025
ba0d825
fix: use correct field inside NewSP1Groth16Proof
manishbista28 May 20, 2025
84ea846
wip: dump r1cs to file
manishbista28 May 23, 2025
3bfcc09
feat: pack to 224 bits
manishbista28 May 24, 2025
361d916
fix: limb bit packing on prover utils
manishbista28 May 24, 2025
3cee52c
chore: comment out r1cs writer
manishbista28 May 25, 2025
a4b1739
chore(rust): replace p3-bls12 with p3-sect
manishbista28 May 25, 2025
d4468c7
updates to go r1cs builder
manishbista28 May 25, 2025
9b28875
bump: gnark version
manishbista28 May 25, 2025
2592eb8
fix: gnark load from r1cs
manishbista28 Jul 7, 2025
2bb40d9
feat: add sect witness gen
manishbista28 Jul 8, 2025
401ca9f
init: prover for cuda
manishbista28 Jul 8, 2025
d010c59
test_e2e_prove_plonk uses cuda
manishbista28 Jul 10, 2025
abe4ed7
wip: undocumented mask top 32 bits
manishbista28 Jul 20, 2025
ab45f57
feat: directly dump r1cs if gnark file exists
manishbista28 Aug 18, 2025
283a9ce
fix: point to correct witness path
manishbista28 Aug 20, 2025
afb0bb0
fix: avoid build_contracts in build fn
manishbista28 Aug 20, 2025
effa1cb
sectfr expose to_biguint
manishbista28 Aug 21, 2025
4fc22d5
include public value in returned proof type
manishbista28 Aug 21, 2025
a8ed390
compilation fixes
manishbista28 Aug 27, 2025
60dbdd5
feat: expose receiving compressed proof as input
manishbista28 Aug 27, 2025
e7075bc
chore: untrack proof dump
manishbista28 Sep 1, 2025
30ba639
chore: revert to bn254 in unused go functions
manishbista28 Sep 1, 2025
0be369c
chore: cargo fmt
manishbista28 Sep 1, 2025
61d8446
fix comments
manishbista28 Sep 1, 2025
a11fe4f
return sp1public values in single step proof generation
manishbista28 Sep 3, 2025
42240a2
add comments
manishbista28 Sep 4, 2025
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
66 changes: 46 additions & 20 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ members = [
"crates/stark",
"crates/zkvm/*",
"crates/test-artifacts",
"crates/p3-sect-fr",
]
exclude = ["examples/target"]
resolver = "2"
Expand Down Expand Up @@ -69,6 +70,7 @@ sp1-cuda = { path = "crates/cuda", version = "5.0.0" }
sp1-stark = { path = "crates/stark", version = "5.0.0" }
sp1-lib = { path = "crates/zkvm/lib", version = "5.0.0", default-features = false }
sp1-zkvm = { path = "crates/zkvm/entrypoint", version = "5.0.0", default-features = false }
p3-sect-fr = { path = "crates/p3-sect-fr" }

# For testing.
test-artifacts = { path = "crates/test-artifacts" }
Expand Down
70 changes: 46 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,62 @@
# SP1
# SP1 Fork

![SP1](./assets/sp1.png)
This fork of SP1 includes changes to generate R1CS and satisfying witness of a stark-proof-verifier program over sect233k1. This way you can write arbitrary program in rust and have it validated by `dv-pari`.

SP1 is the fastest, most-feature complete zero-knowledge virtual machine (zkVM) that can prove the execution of arbitrary Rust (or any LLVM-compiled language) programs. SP1 makes ZK accessible to *any developer*, by making it easy to write ZKP programs in normal Rust code.
SP1 generates Inner Proof (core proof and compressed proof), wraps it over a scalar field (e.g bn254) and then generates snark proof (e.g. groth16). Here wrapping means you represent stark-proof-verifier in R1CS constraints over scalar field. Generating SNARK means you use this R1CS representation and stark-proof (Inner Proof) as an input to generate a succinct proof using systems like groth16.

**[Install](https://docs.succinct.xyz/docs/sp1/getting-started/install)**
| [Docs](https://docs.succinct.xyz/docs/sp1/introduction)
| [Examples](https://github.com/succinctlabs/sp1/tree/main/examples)
| [Telegram Chat](https://t.me/+AzG4ws-kD24yMGYx)
Our changes is reserved to wrapping the same R1CS constraints over a prime scalar field of sect233k1. Instead of generating SNARK, we dump R1CS and a satisfying witness (which includes stark proof) to a file. These files are taken as input by the `dv-pari` system.

## Getting Started
Changes include
1. Poseidon2 over sect233k1
2. Fit public input hash and verification key hash in scalar field
3. Generate and dump r1cs constraints to a file
4. Generate satisfying witness to a file
5. Update `gnark` and `gnark-crypto` to be able to handle sect233k1

Today, developers can write programs, including complex, large programs like a ZK Tendermint light client or type-1 zkEVM using Reth, in Rust (with std support), generate proofs and verify them. Most Rust crates should be supported and can be used seamlessly by your program. Example programs can be found in the [examples](https://github.com/succinctlabs/sp1/tree/main/examples) folder.
## General Info

To get started, make sure you have [Rust](https://www.rust-lang.org/tools/install) installed. Then follow the [installation](https://docs.succinct.xyz/docs/sp1/getting-started/install) guide in the SP1 book and read the [getting started](https://docs.succinct.xyz/docs/sp1/getting-started/quickstart) section.
### Running over cluster and then locally
Because SP1 cluster does not handle forked code, we run the expensive InnerProof (core and compressed proof) generation in SP1 Cluster and run the cheaper constant time OuterProof (wrap over sect233k1 scalar field and dump r1cs witness) locally.

## Security
Check `test_generate_sect_proof_single_step` to understand how both of the Outer and Inner proofs can be generated on the same machine. This approach is same as it used to be previously.

SP1 has undergone audits from [Veridise](https://www.veridise.com/), [Cantina](https://cantina.xyz/),
and [KALOS](https://kalos.xyz/) and is recommended for production use. The audit reports are available [here](./audits).
Check `test_generate_sect_proof_step_wise` to understand how Outer and Inner proofs are handled over different machines. In short -- compressed proof generated by SP1 cluster is fed as input through `SP1Stdin` by marking `prove(..).groth16_with_compressed().run()` instead of the usual `prove(..).groth16().run`.

## Supported Rust Versions (MSRV)
### Naming convention preserved to reduce code changes
Note: There are instances like the ones above where the underlying functionality has been changed to adapt for dv-pari repository (i.e generate r1cs, witness over sect233k1) but the name of functions being called appears as a misnomer (e.g. `groth16_with_compressed().run()`). You will find function names and variables whose names haven't been substituted to something like `dv` from `groth16`. This is to reduce the amount of code that do not impact functionality.

The current MSRV (minimum supported Rust version) is 1.79.
### Support for Groth16
As we have substituted groth16 with functionality that fit our purpose, tests which assume `groth16` will fail.

## For Contributors
### Support in dv-pari
`dv-pari` library directly takes `r1cs_to_dvsnark` and `witness_to_dvsnark` as input and proceeds with the expected set of steps.
`dv-pari-demo` library handles the entire set of steps from sp1 to `dv-pari` and `dv-pari-circuit` end to end.

Open-source is a core part of SP1's ethos and key to its advantages. We wish to cultivate a vibrant community of open-source contributors that span individuals, teams and geographies. If you want to contribute, or follow along with contributor discussion, you can use our main Telegram to chat with us. Our contributor guidelines can be found in [CONTRIBUTING.md](./CONTRIBUTING.md). A quick overview of development tips can be found in [DEVELOPMENT.md](./DEVELOPMENT.md).
## Getting Started
1. Build Custom sp1-gnark

We are always looking for contributors interested in tasks big and small, including minor chores across the codebase, optimizing performance, adding precompiles for commonly used cryptographic operations, adding documentation, creating new example programs and more. Please reach out in the Telegram chat if interested!
```bash
docker build -t sp1-gnark -f ./Dockerfile.gnark-ffi .
```

## Acknowledgements
2. Generate R1CS and satisying witness

We would like to acknowledge the projects below whose previous work has been instrumental in making this project a reality.
```bash
RUST_LOG=info cargo test --release --package sp1-sdk --lib -- tests::test_generate_sect_proof_single_step --exact --show-output --ignored --nocapture
```

- [Plonky3](https://github.com/Plonky3/Plonky3): The SP1's prover is powered by the Plonky3 toolkit.
- [Valida](https://github.com/valida-xyz/valida): The SP1 cross-table lookups, prover, borrow macro, and chip design, including constraints, are inspired by Valida.
- [RISC0](https://github.com/risc0/risc0): The SP1 rust toolchain, install/build scripts, and our RISCV runtime borrow code from RISC0.
- [Cairo](https://docs.cairo-lang.org/how_cairo_works/builtins.html): Cairo introduced the idea of "builtins" which allow zkVMs to accelerate certain operations. However, the complexity of "builtins" was embedded in the CPU, limiting their complexity. SP1 extends this idea by executing on a vision of easily extensible "precompiles" that can be added as additional tables alongside the CPU.
This should generate R1CS and witness in file `~/.sp1/circuits/r1cs_to_dvsnark` and `~/.sp1/circuits/witness_to_dvsnark` respectively

Recurring calls to generate proof will only generate proof and reuse pregenerated r1cs cached in the file `~/.sp1/circuits/r1cs_cached`

## System Requirements

Generating R1CS Constraints requires around 30 GB of docker memory. Ensure docker isn't constrained to a lower limit, else container crashes midway. R1CS only has to be generated once. SP1's main fork assumes these artifacts are directly downloaded from a trusted source, we can also opt for a similar approach where pre-generated r1cs of around 1.2 GB can be directly downloaded, its shasum validated and used.

Generating proof requires around 8 GB of docker memory.

## Versioning

SP1 Fork is forked off of v5.0.0 fork from main branch.

Our main branch is `alpen_dev`.
3 changes: 1 addition & 2 deletions crates/core/machine/src/riscv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ impl From<RiscvAirDiscriminants> for RiscvAirId {

#[cfg(test)]
#[allow(non_snake_case)]
#[allow(clippy::print_stdout)]
pub mod tests {

use crate::{
Expand Down Expand Up @@ -612,7 +611,7 @@ pub mod tests {
#[ignore]
fn write_core_air_costs() {
let costs = RiscvAir::<BabyBear>::costs();
println!("{:?}", costs);
tracing::info!("{:?}", costs);
// write to file
// Create directory if it doesn't exist
let dir = std::path::Path::new("../executor/src/artifacts");
Expand Down
34 changes: 34 additions & 0 deletions crates/p3-sect-fr/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "p3-sect-fr"
version.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
keywords.workspace = true
categories.workspace = true
include.workspace = true

[dependencies]
p3-poseidon2.workspace = true
p3-field.workspace = true
p3-symmetric.workspace = true
serde.workspace = true
serde_json.workspace = true
ark-ff = "0.4"
lazy_static = "1.5.0"

rand = "0.8"
num-bigint = "0.4"
ff = { version = "0.13", features = [
"derive",
"derive_bits",
] }
num-traits = "0.2"
zkhash = "0.2"

[dev-dependencies]
p3-field-testing = "=0.2.3-succinct"


[lints]
workspace = true
Loading