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

Move Towards Generic API #170

Merged
merged 48 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
58ae580
Start to rearrange code to concentrate under api.
sjudson May 30, 2024
f2b72f4
More moving.
sjudson May 30, 2024
0fdb20b
More renaming.
sjudson May 30, 2024
027403b
Push more stuff through the api.
sjudson May 31, 2024
ed738ef
Ditto.
sjudson May 31, 2024
0727d51
Remove backups accidently committed.
sjudson Jun 3, 2024
8b6556e
Start to reorganize.
sjudson Jun 5, 2024
3d831f3
More work on new abstractions.
sjudson Jun 5, 2024
b311d02
Yet more.
sjudson Jun 5, 2024
f37e9b5
More generics.
sjudson Jun 5, 2024
565c127
Finish converting key.
sjudson Jun 6, 2024
724c4ec
Various fixes to bounds.
sjudson Jun 6, 2024
7abe4db
Revert circuit.
sjudson Jun 6, 2024
a098ae6
Revert key.
sjudson Jun 6, 2024
cbe79c8
Revert mod, partially.
sjudson Jun 6, 2024
94268d5
Finish most of the conversion.
sjudson Jun 7, 2024
767d547
Format.
sjudson Jun 7, 2024
38e9ef7
Finish conversion.
sjudson Jun 7, 2024
8d5ed5c
Significant cleanup.
sjudson Jun 7, 2024
d56dc70
Getting there.
sjudson Jun 7, 2024
76de249
Closer.
sjudson Jun 7, 2024
b8693bd
Mostly clippy.
sjudson Jun 7, 2024
1d186a8
More clippy.
sjudson Jun 7, 2024
8ed3702
Pass Jolt interfaces through the API as well.
sjudson Jun 7, 2024
d4e1fe3
Improve misuse resistance.
sjudson Jun 10, 2024
9922deb
Minor.
sjudson Jun 10, 2024
29bd92d
Format.
sjudson Jun 10, 2024
49dad42
Restore independent config crate.
sjudson Jun 10, 2024
f621dd5
Clippy.
sjudson Jun 10, 2024
447773a
Format again.
sjudson Jun 10, 2024
2bcb1f7
Remove tools-dev accidently restored.
sjudson Jun 18, 2024
06ac774
Post-rebase cleanup.
sjudson Jun 18, 2024
7044e03
Push RPC through API.
sjudson Jun 18, 2024
8d5ca3c
Formatting.
sjudson Jun 18, 2024
6973670
Fix reversion of config.
sjudson Jun 18, 2024
5b02f25
Further cleanup.
sjudson Jun 18, 2024
1260ad3
Cleanup cargo.
sjudson Jun 20, 2024
a27bb31
Fix rpc building.
sjudson Jun 20, 2024
a17df18
Formatting.
sjudson Jun 20, 2024
64050fe
Adapt to removal of tools-dev.
sjudson Jun 20, 2024
f76193f
Fix imports.
sjudson Jun 20, 2024
709edf8
Move to purer reexport model for Jolt.
sjudson Jun 20, 2024
2eaf91b
Formatting.
sjudson Jun 20, 2024
045f9d3
Fix rebasing mistake.
sjudson Jun 21, 2024
4cb619a
Remove unnecessary imports.
sjudson Jun 21, 2024
fde39c0
Add feature gating.
sjudson Jun 21, 2024
577798d
Formatting.
sjudson Jun 21, 2024
a52fd62
Remove unnecessary imports.
sjudson Jun 21, 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
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ members = [
"tools/tui",
"config",
"config/serde_wrapper",
"prover",
"network",
"network/rpc/common",
"network/rpc/server",
Expand All @@ -21,7 +20,6 @@ members = [
default-members = [
"vm",
"tools",
"prover",
"network",
"nova",
"spartan",
Expand Down
36 changes: 34 additions & 2 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,38 @@ keywords = { workspace = true }
categories = { workspace = true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs a cleanup, e.g. I don't think it should depend on tui and have verbose feature anymore


[dependencies]
nexus-config = { path = "../config" }
anyhow = "1.0"

zstd = { version = "0.12", default-features = false }

nexus-config = { path = "../config", features = ["clap_derive"] }
nexus-vm = { path = "../vm" }
nexus-prover = { path = "../prover" }
nexus-jolt = { path = "../jolt", optional = true }
spartan = { path = "../spartan", package = "ark-spartan", optional = true }
nexus-nova = { path = "../nova", optional = true }

tracing = "0.1"

ark-ff.workspace = true
ark-ec.workspace = true
ark-std.workspace = true
ark-crypto-primitives.workspace = true
ark-relations.workspace = true
ark-r1cs-std.workspace = true
ark-serialize.workspace = true

ark-bn254.workspace = true
ark-grumpkin.workspace = true

[features]
default = ["parallel", "prover_nova"]
parallel = [
"ark-ff/parallel",
"ark-ec/parallel",
"ark-std/parallel",
"ark-crypto-primitives/parallel",
"ark-r1cs-std/parallel",
"nexus-nova/parallel",
]
prover_nova = ["dep:nexus-nova", "dep:spartan", "nexus-nova/spartan"]
prover_jolt = ["dep:nexus-jolt"]
7 changes: 4 additions & 3 deletions api/examples/prover_run.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// An example of loading and running the NVM.

use nexus_api::config::vm::NovaImpl;
use nexus_api::{
config::vm::{ProverImpl, VmConfig},
nvm::{self, memory::MerkleTrie, NexusVM},
prover::{self},
};
use nexus_config::vm::NovaImpl;
use std::path::PathBuf;

const CONFIG: VmConfig = VmConfig {
Expand All @@ -21,7 +21,7 @@ fn main() {

println!("Setting up public parameters...");
let public_params =
prover::setup::gen_vm_pp(CONFIG.k, &()).expect("error generating public parameters");
prover::nova::pp::gen_vm_pp(CONFIG.k, &()).expect("error generating public parameters");

println!("Reading and translating vm...");
let mut vm: NexusVM<MerkleTrie> =
Expand All @@ -40,7 +40,8 @@ fn main() {
println!("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");

println!("Proving execution of length {}...", trace.blocks.len());
let proof = prover::prove::prove_seq(&public_params, trace).expect("error proving execution");
let proof =
nexus_api::prover::nova::prove_seq(&public_params, trace).expect("error proving execution");

print!("Verifying execution...");
proof
Expand Down
24 changes: 7 additions & 17 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,24 @@

/// Configurations
pub mod config {
pub use nexus_config::{Config, MiscConfig};
pub mod vm {
pub use nexus_config::vm::*;
}
pub mod network {
pub use nexus_config::network::*;
}
}

/// RISC-V processing
pub mod nvm {
pub mod interactive {
pub use nexus_vm::{eval, load_elf, parse_elf, trace::trace};
pub use nexus_vm::{eval, load_elf, parse_elf, trace::trace, trace::Trace};
}
pub use nexus_vm::{error::NexusVMError, eval::NexusVM, run_vm, trace_vm, VMOpts};
pub mod memory {
pub use nexus_vm::memory::{paged::Paged, trie::MerkleTrie};
pub use nexus_vm::memory::{paged::Paged, path::Path, trie::MerkleTrie};
}
}

/// Nova-based provers
pub mod prover {
pub use nexus_prover::error::ProofError;
pub mod setup {
pub use nexus_prover::pp::{gen_or_load, gen_pp, gen_to_file, gen_vm_pp, load_pp, save_pp};
}
pub mod prove {
pub use nexus_prover::{
compress, load_proof, prove_par, prove_par_com, prove_seq, run, save_proof,
};
}
pub mod verify {
pub use nexus_prover::verify_compressed;
}
}
pub mod prover;
3 changes: 3 additions & 0 deletions api/src/prover/jolt/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub use nexus_jolt::{parse, preprocess, prove, trace, verify, VM};

pub mod types;
3 changes: 3 additions & 0 deletions api/src/prover/jolt/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Default types and traits for use by zkVM + Jolt pipeline

pub use nexus_jolt::{JoltCommitments, JoltPreprocessing, JoltProof, F, PCS};
4 changes: 4 additions & 0 deletions api/src/prover/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[cfg(feature = "prover_jolt")]
pub mod jolt;
#[cfg(feature = "prover_nova")]
pub mod nova;
19 changes: 11 additions & 8 deletions prover/src/circuit.rs → api/src/prover/nova/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ pub use ark_relations::{
use nexus_vm::{
circuit::{build_constraints, ARITY},
machines::nop_vm,
memory::{path::Path, trie::MerkleTrie},
memory::Memory,
trace::{trace, Trace},
};

use crate::error::*;
use crate::types::*;
use super::error::*;
use super::types::*;

pub struct Tr(pub Trace<Path>);
pub struct Tr<M: Memory>(pub Trace<M::Proof>);
sjudson marked this conversation as resolved.
Show resolved Hide resolved

impl Tr {
impl<M: Memory> Tr<M> {
pub fn steps(&self) -> usize {
self.0.blocks.len()
}
Expand All @@ -38,13 +38,16 @@ impl Tr {
}
}

pub fn nop_circuit(k: usize) -> Result<Tr, ProofError> {
let mut vm = nop_vm::<MerkleTrie>(1);
pub fn nop_circuit<M: Memory>(k: usize) -> Result<Tr<M>, ProofError> {
let mut vm = nop_vm::<M>(1);
let trace = trace(&mut vm, k, false)?;
Ok(Tr(trace))
}

impl StepCircuit<F1> for Tr {
impl<M: Memory> StepCircuit<F1> for Tr<M>
where
M::Proof: Send + Sync,
{
const ARITY: usize = ARITY;

fn generate_constraints(
Expand Down
File renamed without changes.
52 changes: 52 additions & 0 deletions api/src/prover/nova/key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::fs::File;
use zstd::stream::{Decoder, Encoder};

pub use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use nexus_nova::nova::pcd::compression::SNARK;

use super::error::*;
use super::types::*;
use super::LOG_TARGET;

pub fn gen_key(pp: &ComPP, srs: &SRS) -> Result<SpartanKey, ProofError> {
tracing::info!(
target: LOG_TARGET,
"Generating Spartan key parameters",
);

let key = SNARK::setup(pp, srs)?;
Ok(key)
}

pub fn save_key(key: SpartanKey, file: &str) -> Result<(), ProofError> {
tracing::info!(
target: LOG_TARGET,
pp_file =?file,
"Saving Spartan key parameters",
);

let f = File::create(file)?;
let mut enc = Encoder::new(&f, 0)?;
key.serialize_compressed(&mut enc)?;
enc.finish()?;
f.sync_all()?;
Ok(())
}

pub fn load_key(file: &str) -> Result<SpartanKey, ProofError> {
tracing::info!(
target: LOG_TARGET,
pp_file =?file,
"Loading Spartan key parameters",
);

let f = File::open(file)?;
let mut dec = Decoder::new(&f)?;
let key = SpartanKey::deserialize_compressed_unchecked(&mut dec)?;
Ok(key)
}

pub fn gen_key_to_file(pp: &ComPP, srs: &SRS, key_file: &str) -> Result<(), ProofError> {
let key: SpartanKey = gen_key(pp, srs)?;
save_key(key, key_file)
}
Loading