Skip to content

Commit 01660a9

Browse files
authored
Merge pull request #2 from lambdaclass/forger_poc
Forger prover
2 parents 563ede1 + b3e9ed1 commit 01660a9

File tree

9 files changed

+646
-162
lines changed

9 files changed

+646
-162
lines changed

README.md

+6-34
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,9 @@
1-
# SP1
1+
# SP1 Forger
22

3-
![SP1](./assets/sp1.png)
3+
This is a forger prover for SP1 3.4, that allows creating proofs of false statements.
44

5-
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.
5+
Made by a joint effort of:
66

7-
**[Install](https://succinctlabs.github.io/sp1/getting-started/install.html)**
8-
| [Docs](https://succinctlabs.github.io/sp1)
9-
| [Examples](https://github.com/succinctlabs/sp1/tree/main/examples)
10-
| [Telegram Chat](https://t.me/+AzG4ws-kD24yMGYx)
11-
12-
## Getting Started
13-
14-
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.
15-
16-
To get started, make sure you have [Rust](https://www.rust-lang.org/tools/install) installed. Then follow the [installation](https://succinctlabs.github.io/sp1/getting-started/install.html) guide in the SP1 book and read the [getting started](https://succinctlabs.github.io/sp1/getting-started/quickstart.html) section.
17-
18-
## Security
19-
20-
SP1 has undergone audits from [Veridise](https://www.veridise.com/), [Cantina](https://cantina.xyz/),
21-
and [KALOS](https://kalos.xyz/) and is recommended for production use. The audit reports are available [here](./audits).
22-
23-
24-
## For Contributors
25-
26-
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).
27-
28-
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!
29-
30-
## Acknowledgements
31-
32-
We would like to acknowledge the projects below whose previous work has been instrumental in making this project a reality.
33-
34-
- [Plonky3](https://github.com/Plonky3/Plonky3): The SP1's prover is powered by the Plonky3 toolkit.
35-
- [Valida](https://github.com/valida-xyz/valida): The SP1 cross-table lookups, prover, borrow macro, and chip design, including constraints, are inspired by Valida.
36-
- [RISC0](https://github.com/risc0/risc0): The SP1 rust toolchain, install/build scripts, and our RISCV runtime borrow code from RISC0.
37-
- [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.
7+
[3MILabs](https://www.3milabs.tech)
8+
[Aligned Layer](https://alignedlayer.com)
9+
[LambdaClass](https://lambdaclass.com)

crates/core/executor/src/executor.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,8 @@ impl<'a> Executor<'a> {
13781378

13791379
let done = self.state.pc == 0
13801380
|| self.state.pc.wrapping_sub(self.program.pc_base)
1381-
>= (self.program.instructions.len() * 4) as u32;
1381+
>= (self.program.instructions.len() * 4) as u32
1382+
|| self.state.pc == 2100032; // The address of `main`; should maybe not be exactly hardcoded :)
13821383
if done && self.unconstrained {
13831384
log::error!("program ended in unconstrained mode at clk {}", self.state.global_clk);
13841385
return Err(ExecutionError::EndInUnconstrained());

crates/core/machine/src/utils/prove.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,19 @@ where
853853
runtime.subproof_verifier = Arc::new(NoOpSubproofVerifier);
854854

855855
// Execute from the checkpoint.
856-
let (records, _) = runtime.execute_record().unwrap();
856+
// let (records, _) = runtime.execute_record().unwrap();
857+
let (mut records, _) = runtime.execute_record().unwrap();
858+
records.iter_mut().for_each(|rec| {
859+
use k256::sha2::Digest;
860+
let mut hasher = k256::sha2::Sha256::new();
861+
// We read the desired committed data from stdin, as that's unused otherwise anyway
862+
hasher.update(runtime.state.input_stream.iter().flatten().copied().collect::<Vec<_>>());
863+
let hash = hasher.finalize().to_vec();
864+
for i in 0..8 {
865+
rec.public_values.committed_value_digest[i] =
866+
u32::from_le_bytes(hash[i * 4..(i + 1) * 4].try_into().unwrap());
867+
}
868+
});
857869

858870
(records, runtime.report)
859871
}

crates/prover/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,8 @@ impl<C: SP1ProverComponents> SP1Prover<C> {
712712
"get program and witness stream"
713713
)
714714
.in_scope(|| match input {
715-
SP1CircuitWitness::Core(input) => {
715+
SP1CircuitWitness::Core(mut input) => {
716+
input.is_complete = index == 0; // Yes, the first shard is entirely complete
716717
let mut witness_stream = Vec::new();
717718
Witnessable::<InnerConfig>::write(&input, &mut witness_stream);
718719
(self.recursion_program(&input), witness_stream)
@@ -898,6 +899,7 @@ impl<C: SP1ProverComponents> SP1Prover<C> {
898899
ShardProof<InnerSC>,
899900
)> = Vec::new();
900901
loop {
902+
break; // We only need the first shard :)
901903
let received = { proofs_rx.lock().unwrap().recv() };
902904
if let Ok((index, height, vk, proof)) = received {
903905
batch.push((index, height, vk, proof));

0 commit comments

Comments
 (0)