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

dev2main #843

Merged
merged 33 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
712f765
prover type
ratankaliani May 30, 2024
b954a47
update comments
ratankaliani May 30, 2024
52c9c94
prover type
ratankaliani May 30, 2024
74fe3de
lint
ratankaliani May 30, 2024
be2ce85
change to network
ratankaliani May 30, 2024
573a764
fix
ratankaliani May 30, 2024
2325a9c
fix: gnark-ffi linking on mac
ctian1 May 30, 2024
d1ca91f
clean
ratankaliani May 30, 2024
5f46fb0
feat: add `prover_type` (#838)
ratankaliani May 30, 2024
1b9a0ae
feat: enforce only `dev` can merge into `main` (#844)
ratankaliani May 30, 2024
891acb8
fix: gnark-ffi linking on mac (#842)
ratankaliani May 30, 2024
83ea9ff
Merge branch 'main' into dev
ratankaliani May 30, 2024
1d8aa1b
feat: runtime instruction/syscall report (#839)
tqn May 30, 2024
507b67c
chore: add network requester to requested proof (#845)
ctian1 May 30, 2024
dffe9e6
chore: default reconstruct commitments = true
ctian1 May 30, 2024
99effb1
feat: execute() exposes ExecutionReport (#847)
mattstam May 30, 2024
0c8d1bd
fix: remove aggregation programs (#849)
ratankaliani May 31, 2024
89dbb60
chore: default reconstruct commitments = true (#846)
ratankaliani May 31, 2024
af7c26c
fix: plonk feature off by default (#852)
ctian1 May 31, 2024
27c1741
feat: generic const expr (#854)
ratankaliani May 31, 2024
8ef12a5
doc: recursive program docs (#855)
tamirhemo May 31, 2024
e48c01e
feat: feature flag `alloy_sol_types` (#850)
ratankaliani May 31, 2024
896ee50
contracts
ratankaliani May 31, 2024
90d97e2
clean
ratankaliani May 31, 2024
8a9f0c2
chore: bump plonk artifacts (#864)
ctian1 May 31, 2024
166e243
fix
ratankaliani May 31, 2024
5e15886
clean
ratankaliani May 31, 2024
47b8901
try permalink
ratankaliani May 31, 2024
362e397
fix
ratankaliani May 31, 2024
66ffc3f
chore: program doc and remove unnecessary clones (#857)
tamirhemo May 31, 2024
86f5789
docs: Instructions for installing SP1 contracts (#859)
ratankaliani May 31, 2024
ce2cf6b
feat: check version for proof requests (#862)
mattstam May 31, 2024
20e36b7
feat(sdk): add explorer link (#858)
ctian1 Jun 1, 2024
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
11 changes: 10 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,13 @@ jobs:
args: --release -p sp1-sdk --features plonk -- test_e2e_prove_plonk --nocapture
env:
RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0 -C target-cpu=native
RUST_BACKTRACE: 1
RUST_BACKTRACE: 1
check-branch:
name: Check branch
runs-on: ubuntu-latest
steps:
- name: Check branch
if: github.head_ref != 'dev'
run: |
echo "ERROR: You can only merge to main from dev."
exit 1
3 changes: 2 additions & 1 deletion Cargo.lock

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

4 changes: 3 additions & 1 deletion book/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@

- [Recommended Settings](./developers/recommended-settings.md)

- [Building Plonk Bn254 Artifacts](./developers/building-plonk-artifacts.md)
- [Building Plonk Bn254 Artifacts](./developers/building-plonk-artifacts.md)

- [Common Issues](./developers/common-issues.md)
18 changes: 18 additions & 0 deletions book/developers/common-issues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Alloy Errors

If you are using a library that depends on `alloy_sol_types`, and encounter an error like this:

```
perhaps two different versions of crate `alloy_sol_types` are being used?
```

This is likely due to two different versions of `alloy_sol_types` being used. To fix this, you can set `default-features` to `false` for the `sp1-sdk` dependency in your `Cargo.toml`.

```toml
[dependencies]
sp1-sdk = { version = "0.1.0", default-features = false }
```

This will configure out the `network` feature which will remove the dependency on `alloy_sol_types`
and configure out the `NetworkProver`.

53 changes: 34 additions & 19 deletions book/verifying-proofs/solidity-and-evm.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ To use PLONK proving & verification locally, enable the `plonk` feature flag in
sp1-sdk = { features = ["plonk"] }
```


### Example

```rust,noplayground
Expand All @@ -23,25 +22,41 @@ sp1-sdk = { features = ["plonk"] }

You can run the above script with `RUST_LOG=info cargo run --bin plonk_bn254 --release` in `examples/fibonacci/script`.

## Exporting the Verifier Contract
## Install SP1 Contracts

To export the verifier contract, you can use the export function in the `sp1_sdk` crate.
# SP1 Contracts

### Example
This repository contains the smart contracts for verifying [SP1](https://github.com/succinctlabs/sp1) EVM proofs.

```rust,noplayground
//! Builds the proving artifacts and exports the solidity verifier.
//!
//! You can run this script using the following command:
//! ```shell
//! RUST_LOG=info cargo run --package fibonacci-script --bin artifacts --release
//! ```

use std::path::PathBuf;

fn main() {
let contracts_src_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../contracts/src");
sp1_sdk::artifacts::export_solidity_plonk_bn254_verifier(contracts_src_dir)
.expect("failed to export verifier");
## Installation

> [!WARNING]
> [Foundry](https://github.com/foundry-rs/foundry) installs the latest release version initially, but subsequent `forge update` commands will use the `main` branch. This branch is the development branch and should be avoided in favor of tagged releases. The release process matches a specific SP1 version.

To install the latest release version:

```bash
forge install succinctlabs/sp1-contracts
```

To install a specific version:
```bash
forge install succinctlabs/sp1-contracts@<version>
```

Add `@sp1-contracts/=lib/sp1-contracts/contracts/src/` in `remappings.txt.`

### Usage

Once installed, you can use the contracts in the library by importing them:

```solidity
pragma solidity ^0.8.25;

import {SP1Verifier} from "@sp1-contracts/SP1Verifier.sol";

contract MyContract is SP1Verifier {
}
```
```

For more details on the contracts, refer to the [sp1-contracts](https://github.com/succinctlabs/sp1-contracts) repo.
3 changes: 0 additions & 3 deletions core/benches/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use sp1_core::io::SP1Stdin;
use sp1_core::runtime::{Program, Runtime};
Expand Down
1 change: 0 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
deprecated,
incomplete_features
)]
#![feature(generic_const_exprs)]
#![warn(unused_extern_crates)]

extern crate alloc;
Expand Down
121 changes: 121 additions & 0 deletions core/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub use utils::*;

use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::fmt::{Display, Formatter, Result as FmtResult};
use std::fs::File;
use std::io::BufWriter;
use std::io::Write;
Expand Down Expand Up @@ -81,6 +82,54 @@ pub struct Runtime {
pub max_syscall_cycles: u32,

pub emit_events: bool,

/// Report of the program execution.
pub report: ExecutionReport,

/// Whether we should write to the report.
pub should_report: bool,
}

#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct ExecutionReport {
pub instruction_counts: HashMap<Opcode, u64>,
pub syscall_counts: HashMap<SyscallCode, u64>,
}

impl ExecutionReport {
pub fn total_instruction_count(&self) -> u64 {
self.instruction_counts.values().sum()
}

pub fn total_syscall_count(&self) -> u64 {
self.syscall_counts.values().sum()
}
}

impl Display for ExecutionReport {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
writeln!(f, "Instruction Counts:")?;
let mut sorted_instructions = self.instruction_counts.iter().collect::<Vec<_>>();

// Sort instructions by opcode name
sorted_instructions.sort_by_key(|&(opcode, _)| opcode.to_string());
for (opcode, count) in sorted_instructions {
writeln!(f, " {}: {}", opcode, count)?;
}
writeln!(f, "Total Instructions: {}", self.total_instruction_count())?;

writeln!(f, "Syscall Counts:")?;
let mut sorted_syscalls = self.syscall_counts.iter().collect::<Vec<_>>();

// Sort syscalls by syscall name
sorted_syscalls.sort_by_key(|&(syscall, _)| format!("{:?}", syscall));
for (syscall, count) in sorted_syscalls {
writeln!(f, " {}: {}", syscall, count)?;
}
writeln!(f, "Total Syscall Count: {}", self.total_syscall_count())?;

Ok(())
}
}

#[derive(Error, Debug)]
Expand Down Expand Up @@ -140,6 +189,8 @@ impl Runtime {
syscall_map,
emit_events: true,
max_syscall_cycles,
report: Default::default(),
should_report: false,
}
}

Expand Down Expand Up @@ -535,6 +586,14 @@ impl Runtime {
let mut memory_store_value: Option<u32> = None;
self.memory_accesses = MemoryAccessRecord::default();

if self.should_report && !self.unconstrained {
self.report
.instruction_counts
.entry(instruction.opcode)
.and_modify(|c| *c += 1)
.or_insert(1);
}

match instruction.opcode {
// Arithmetic instructions.
Opcode::ADD => {
Expand Down Expand Up @@ -749,6 +808,14 @@ impl Runtime {
b = self.rr(Register::X10, MemoryAccessPosition::B);
let syscall = SyscallCode::from_u32(syscall_id);

if self.should_report && !self.unconstrained {
self.report
.syscall_counts
.entry(syscall)
.and_modify(|c| *c += 1)
.or_insert(1);
}

let syscall_impl = self.get_syscall(syscall).cloned();
let mut precompile_rt = SyscallContext::new(self);
let (precompile_next_pc, precompile_cycles, returned_exit_code) =
Expand Down Expand Up @@ -956,12 +1023,14 @@ impl Runtime {

pub fn run_untraced(&mut self) -> Result<(), ExecutionError> {
self.emit_events = false;
self.should_report = true;
while !self.execute()? {}
Ok(())
}

pub fn run(&mut self) -> Result<(), ExecutionError> {
self.emit_events = true;
self.should_report = true;
while !self.execute()? {}
Ok(())
}
Expand Down Expand Up @@ -1110,6 +1179,58 @@ pub mod tests {
assert_eq!(runtime.register(Register::X31), 42);
}

#[test]
fn test_ssz_withdrawals_program_run_report() {
let program = ssz_withdrawals_program();
let mut runtime = Runtime::new(program, SP1CoreOpts::default());
runtime.run().unwrap();
assert_eq!(runtime.report, {
use super::Opcode::*;
use super::SyscallCode::*;
super::ExecutionReport {
instruction_counts: [
(LB, 10723),
(DIVU, 6),
(LW, 237094),
(JALR, 38749),
(XOR, 242242),
(BEQ, 26917),
(AND, 151701),
(SB, 58448),
(MUL, 4036),
(SLTU, 16766),
(ADD, 583439),
(JAL, 5372),
(LBU, 57950),
(SRL, 293010),
(SW, 312781),
(ECALL, 2264),
(BLTU, 43457),
(BGEU, 5917),
(BLT, 1141),
(SUB, 12382),
(BGE, 237),
(MULHU, 1152),
(BNE, 51442),
(AUIPC, 19488),
(OR, 301944),
(SLL, 278698),
]
.into(),
syscall_counts: [
(COMMIT_DEFERRED_PROOFS, 8),
(SHA_EXTEND, 1091),
(COMMIT, 8),
(WRITE, 65),
(SHA_COMPRESS, 1091),
(HALT, 1),
]
.into(),
}
});
assert_eq!(runtime.report.total_instruction_count(), 2757356);
}

#[test]
#[should_panic]
fn test_panic() {
Expand Down
9 changes: 8 additions & 1 deletion core/src/runtime/syscall.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::fmt;
use std::sync::Arc;

use strum_macros::EnumIter;
Expand Down Expand Up @@ -28,7 +29,7 @@ use crate::{runtime::ExecutionRecord, runtime::MemoryReadRecord, runtime::Memory
/// - The second byte is 0/1 depending on whether the syscall has a separate table. This is used
/// in the CPU table to determine whether to lookup the syscall using the syscall interaction.
/// - The third byte is the number of additional cycles the syscall uses.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, EnumIter)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, EnumIter, Ord, PartialOrd)]
#[allow(non_camel_case_types)]
pub enum SyscallCode {
/// Halts the program.
Expand Down Expand Up @@ -149,6 +150,12 @@ impl SyscallCode {
}
}

impl fmt::Display for SyscallCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}

pub trait Syscall: Send + Sync {
/// Execute the syscall and return the resulting value of register a0. `arg1` and `arg2` are the
/// values in registers X10 and X11, respectively. While not a hard requirement, the convention
Expand Down
12 changes: 6 additions & 6 deletions core/src/stark/permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub(crate) fn generate_permutation_trace<F: PrimeField, EF: ExtensionField<F>>(
sends: &[Interaction<F>],
receives: &[Interaction<F>],
preprocessed: Option<&RowMajorMatrix<F>>,
main: &mut RowMajorMatrix<F>,
main: &RowMajorMatrix<F>,
random_elements: &[EF],
batch_size: usize,
) -> RowMajorMatrix<EF> {
Expand Down Expand Up @@ -96,13 +96,13 @@ pub(crate) fn generate_permutation_trace<F: PrimeField, EF: ExtensionField<F>>(
Some(prep) => {
permutation_trace
.par_rows_mut()
.zip_eq(prep.par_rows())
.zip_eq(main.par_rows())
.zip_eq(prep.par_row_slices())
.zip_eq(main.par_row_slices())
.for_each(|((row, prep_row), main_row)| {
populate_permutation_row(
row,
prep_row.collect::<Vec<_>>().as_slice(),
main_row.collect::<Vec<_>>().as_slice(),
prep_row,
main_row,
sends,
receives,
alpha,
Expand All @@ -114,7 +114,7 @@ pub(crate) fn generate_permutation_trace<F: PrimeField, EF: ExtensionField<F>>(
None => {
permutation_trace
.par_rows_mut()
.zip_eq(main.par_rows_mut())
.zip_eq(main.par_row_slices())
.for_each(|(row, main_row)| {
populate_permutation_row(
row,
Expand Down
Loading
Loading