Skip to content

Commit

Permalink
chore: sdk tweaks (#653)
Browse files Browse the repository at this point in the history
Co-authored-by: Uma Roy <[email protected]>
  • Loading branch information
jtguibas and puma314 authored May 6, 2024
1 parent 4f393a9 commit c01d575
Show file tree
Hide file tree
Showing 29 changed files with 1,014 additions and 593 deletions.
40 changes: 0 additions & 40 deletions .github/workflows/groth16.yml

This file was deleted.

93 changes: 1 addition & 92 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,105 +36,14 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: -p sp1-core -p sp1-recursion-compiler -p sp1-recursion-program -p sp1-recursion-circuit --release
args: -p sp1-core -p sp1-recursion-compiler -p sp1-recursion-program -p sp1-recursion-circuit -p sp1-sdk --release
env:
RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0 -C target-cpu=native
RUST_LOG: 1
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: 1
FRI_QUERIES: 1

e2e:
name: End to end with toolchain installation.
runs-on: warp-ubuntu-latest-arm64-8x
env:
CARGO_NET_GIT_FETCH_WITH_CLI: "true"
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Setup CI
uses: ./.github/actions/setup
with:
pull_token: ${{ secrets.PULL_TOKEN }}

- name: Install sp1 toolchain
run: |
curl -L https://sp1.succinct.xyz | bash
echo "/root/.sp1/bin" >> $GITHUB_PATH
/root/.sp1/bin/sp1up
- name: Run Fibonacci example main.rs
uses: actions-rs/cargo@v1
with:
command: run
args: --release --manifest-path examples/fibonacci/script/Cargo.toml --bin fibonacci-script
env:
RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0 -Ctarget-cpu=native
RUST_LOG: 1
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: 1

- name: Run Fibonacci example compressed.rs
uses: actions-rs/cargo@v1
with:
command: run
args: --release --manifest-path examples/fibonacci/script/Cargo.toml --bin compressed
env:
RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0 -Ctarget-cpu=native
RUST_LOG: 1
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: 1

# - name: Run Fibonacci example groth16.rs
# uses: actions-rs/cargo@v1
# with:
# command: run
# args: --release --manifest-path examples/fibonacci/script/Cargo.toml --bin groth16
# env:
# RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0 -Ctarget-cpu=native
# RUST_LOG: 1
# RUST_BACKTRACE: 1
# CARGO_INCREMENTAL: 1

- name: Run cargo prove new
run: |
cargo prove new cargo-prove-test
cd cargo-prove-test
cd script
cargo run --release
misc:
name: Miscellaneous
runs-on: warp-ubuntu-latest-arm64-8x
env:
CARGO_NET_GIT_FETCH_WITH_CLI: "true"
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Setup CI
uses: ./.github/actions/setup
with:
pull_token: ${{ secrets.PULL_TOKEN }}

- name: Run cargo test with no default features
uses: actions-rs/cargo@v1
with:
command: test
args: -p sp1-core --release --no-default-features --features debug -- cpu::trace::tests::generate_trace
env:
RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0 -Ctarget-cpu=native
RUST_LOG: 1
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: 1

- name: Install sp1 toolchain
run: |
curl -L https://sp1.succinct.xyz | bash
echo "/root/.sp1/bin" >> $GITHUB_PATH
/root/.sp1/bin/sp1up
lints:
name: Formatting & Clippy
runs-on: warp-ubuntu-latest-arm64-8x
Expand Down
5 changes: 5 additions & 0 deletions Cargo.lock

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

19 changes: 11 additions & 8 deletions core/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
use serde::{de::DeserializeOwned, Deserialize, Serialize};

/// Standard input for the prover.
#[derive(Serialize, Deserialize, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SP1Stdin {
/// Input stored as a vec of vec of bytes. It's stored this way because the read syscall reads
/// a vec of bytes at a time.
Expand All @@ -18,10 +18,9 @@ pub struct SP1Stdin {
}

/// Public values for the prover.
#[derive(Serialize, Deserialize, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SP1PublicValues {
// TODO: fix
pub buffer: Buffer,
buffer: Buffer,
}

impl SP1Stdin {
Expand Down Expand Up @@ -97,6 +96,14 @@ impl SP1PublicValues {
}
}

pub fn as_slice(&self) -> &[u8] {
self.buffer.data.as_slice()
}

pub fn to_vec(&self) -> Vec<u8> {
self.buffer.data.clone()
}

/// Read a value from the buffer.
pub fn read<T: Serialize + DeserializeOwned>(&mut self) -> T {
self.buffer.read()
Expand All @@ -116,10 +123,6 @@ impl SP1PublicValues {
pub fn write_slice(&mut self, slice: &[u8]) {
self.buffer.write_slice(slice);
}

pub fn to_vec(self) -> Vec<u8> {
self.buffer.data
}
}

impl AsRef<[u8]> for SP1PublicValues {
Expand Down
5 changes: 2 additions & 3 deletions core/src/stark/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ impl<SC: StarkGenericConfig, A: MachineAir<Val<SC>>> StarkMachine<SC, A> {
///
/// Given a proving key `pk` and a matching execution record `record`, this function generates
/// a STARK proof that the execution record is valid.
#[instrument("prove", level = "info", skip_all)]
pub fn prove<P: Prover<SC, A>>(
&self,
pk: &StarkProvingKey<SC>,
Expand All @@ -279,10 +278,10 @@ impl<SC: StarkGenericConfig, A: MachineAir<Val<SC>>> StarkMachine<SC, A> {
+ for<'a> Air<VerifierConstraintFolder<'a, SC>>
+ for<'a> Air<DebugConstraintBuilder<'a, Val<SC>, SC::Challenge>>,
{
let shards = tracing::info_span!("shard execution record")
let shards = tracing::info_span!("shard_record")
.in_scope(|| self.shard(record, &<A::Record as MachineRecord>::Config::default()));

tracing::info_span!("generate shard proofs")
tracing::info_span!("prove_shards")
.in_scope(|| P::prove_shards(self, pk, shards, challenger))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,10 @@ mod tests {

let inputs = SP1Stdin::from(&compressed);

let mut proof = run_test_io(Program::from(SECP256K1_DECOMPRESS_ELF), inputs).unwrap();
let mut public_values =
run_test_io(Program::from(SECP256K1_DECOMPRESS_ELF), inputs).unwrap();
let mut result = [0; 65];
proof.buffer.read_slice(&mut result);
public_values.read_slice(&mut result);
assert_eq!(result, decompressed);
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/utils/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{de::DeserializeOwned, Deserialize, Serialize};

/// A buffer of serializable/deserializable objects.
#[derive(Serialize, Deserialize, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Buffer {
pub data: Vec<u8>,
#[serde(skip)]
Expand Down
3 changes: 1 addition & 2 deletions core/src/utils/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ where
// Prove the program.
let start = Instant::now();
let cycles = runtime.state.global_clk;
let proof = tracing::info_span!("prove")
.in_scope(|| machine.prove::<LocalProver<_, _>>(&pk, runtime.record, &mut challenger));
let proof = machine.prove::<LocalProver<_, _>>(&pk, runtime.record, &mut challenger);
let time = start.elapsed().as_millis();
let nb_bytes = bincode::serialize(&proof).unwrap().len();

Expand Down
1 change: 0 additions & 1 deletion ec_add_test.sh

This file was deleted.

11 changes: 10 additions & 1 deletion prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ sha2 = "0.10.8"
hex = "0.4.3"
anyhow = "1.0.82"
size = "0.4.1"
subtle-encoding = "0.5.1"
dirs = "5.0.1"
tempfile = "3.10.1"
tokio = { version = "1.36.0", features = ["full"] }
reqwest = { version = "0.11.25", features = ["rustls-tls", "trust-dns", "stream"] }
indicatif = "0.17.8"
futures = "0.3.30"
subtle-encoding = "0.5.1"

[[bin]]
name = "fibonacci_sweep"
Expand All @@ -59,5 +64,9 @@ path = "scripts/test_groth16_verification.rs"
name = "build_groth16"
path = "scripts/build_groth16.rs"

[[bin]]
name = "install_groth16"
path = "scripts/install_groth16.rs"

[features]
neon = ["sp1-core/neon"]
4 changes: 2 additions & 2 deletions prover/scripts/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ pub fn main() {
let core_proof = prover.prove_core(&pk, &stdin);

tracing::info!("reduce");
let reduced_proof = prover.reduce(&vk, core_proof.proof, vec![]);
let reduced_proof = prover.compress(&vk, core_proof, vec![]);

tracing::info!("compress");
let compressed_proof = prover.compress(&vk, reduced_proof);
let compressed_proof = prover.shrink(&vk, reduced_proof);

tracing::info!("wrap");
let wrapped_proof = prover.wrap_bn254(&vk, compressed_proof);
Expand Down
2 changes: 1 addition & 1 deletion prover/scripts/fibonacci_groth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn main() {

tracing::info!("proving inner");
let recursion_proving_start = Instant::now();
let _ = prover.reduce(&vk, proof.proof, vec![]);
let _ = prover.compress(&vk, proof, vec![]);
let recursion_proving_duration = recursion_proving_start.elapsed().as_secs_f64();
tracing::info!("recursion_proving_duration={}", recursion_proving_duration);
}
Expand Down
2 changes: 1 addition & 1 deletion prover/scripts/fibonacci_sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn main() {
let leaf_proving_duration = leaf_proving_start.elapsed().as_secs_f64();

let recursion_proving_start = Instant::now();
let _ = prover.reduce(&vk, proof.proof, vec![]);
let _ = prover.compress(&vk, proof, vec![]);
let recursion_proving_duration = recursion_proving_start.elapsed().as_secs_f64();

lines.push(format!(
Expand Down
8 changes: 8 additions & 0 deletions prover/scripts/install_groth16.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

use sp1_prover::install;

pub fn main() {
install::groth16_artifacts();
}
2 changes: 1 addition & 1 deletion prover/scripts/tendermint_sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn main() {
let leaf_proving_duration = leaf_proving_start.elapsed().as_secs_f64();

let recursion_proving_start = Instant::now();
let _ = prover.reduce(&vk, proof.proof, vec![]);
let _ = prover.compress(&vk, proof, vec![]);
let recursion_proving_duration = recursion_proving_start.elapsed().as_secs_f64();

lines.push(format!(
Expand Down
Loading

0 comments on commit c01d575

Please sign in to comment.