From 34ec8f3bcae73afdc5236c1b009735846c6b472d Mon Sep 17 00:00:00 2001 From: Kristian Sosnin <48099298+slumber@users.noreply.github.com> Date: Fri, 16 Feb 2024 14:11:59 +0400 Subject: [PATCH] workspace tweaks (#67) * rename supernova -> nexus-nova * rename entry -> main * single rustfmt file * document factorial example --- .rustfmt.toml | 8 ++- Cargo.lock | 62 +++++++++---------- Cargo.toml | 6 +- config/.rustfmt.toml | 0 config/bases/rust.toml | 4 +- examples/src/bin/fact.rs | 11 ++-- examples/src/bin/fail.rs | 4 +- examples/src/bin/fib.rs | 4 +- examples/src/bin/fib1000.rs | 4 +- examples/src/bin/fmt.rs | 7 +-- examples/src/main.rs | 4 +- network/src/api.rs | 2 +- network/src/bin.rs | 4 +- network/src/bin/client.rs | 2 +- network/src/bin/pcdnode/db.rs | 2 +- network/src/bin/pcdnode/main.rs | 8 +-- network/src/bin/pcdnode/post.rs | 20 ++---- network/src/bin/pcdnode/workers.rs | 6 +- network/src/client.rs | 4 +- network/src/lib.rs | 6 +- network/src/pcd.rs | 14 ++--- .../.gitignore | 0 .../Cargo.toml | 6 +- .../benches/recursive-snark.rs | 2 +- {supernova => nova}/.gitignore | 0 {supernova => nova}/Cargo.toml | 2 +- {supernova => nova}/src/absorb.rs | 0 {supernova => nova}/src/circuits/mod.rs | 0 {supernova => nova}/src/circuits/nova/mod.rs | 0 .../src/circuits/nova/pcd/augmented.rs | 6 +- .../nova/pcd/compression/commitment_utils.rs | 0 .../nova/pcd/compression/conversion.rs | 11 +--- .../circuits/nova/pcd/compression/error.rs | 0 .../src/circuits/nova/pcd/compression/mod.rs | 0 .../pcd/compression/secondary/conversion.rs | 0 .../nova/pcd/compression/secondary/mod.rs | 0 .../src/circuits/nova/pcd/mod.rs | 24 +++---- .../src/circuits/nova/public_params.rs | 0 .../src/circuits/nova/sequential/augmented.rs | 6 +- .../src/circuits/nova/sequential/mod.rs | 21 ++----- {supernova => nova}/src/commitment.rs | 0 .../hypernova/ml_sumcheck/data_structures.rs | 0 .../src/folding/hypernova/ml_sumcheck/mod.rs | 0 .../hypernova/ml_sumcheck/protocol/mod.rs | 0 .../hypernova/ml_sumcheck/protocol/prover.rs | 4 +- .../ml_sumcheck/protocol/verifier.rs | 0 .../folding/hypernova/ml_sumcheck/tests.rs | 0 .../src/folding/hypernova/mod.rs | 0 {supernova => nova}/src/folding/mod.rs | 0 .../src/folding/nova/cyclefold/mod.rs | 0 .../src/folding/nova/cyclefold/nimfs/mod.rs | 15 +---- .../folding/nova/cyclefold/nimfs/relaxed.rs | 10 +-- .../folding/nova/cyclefold/secondary/mod.rs | 9 +-- {supernova => nova}/src/folding/nova/mod.rs | 0 {supernova => nova}/src/folding/nova/nifs.rs | 0 .../src/gadgets/cyclefold/mod.rs | 0 .../src/gadgets/cyclefold/primary.rs | 5 +- .../src/gadgets/cyclefold/secondary.rs | 6 +- {supernova => nova}/src/gadgets/mod.rs | 0 .../src/gadgets/nonnative/mod.rs | 0 .../gadgets/nonnative/short_weierstrass.rs | 0 {supernova => nova}/src/lib.rs | 2 +- {supernova => nova}/src/provider/mod.rs | 0 {supernova => nova}/src/provider/pedersen.rs | 0 {supernova => nova}/src/provider/poseidon.rs | 0 {supernova => nova}/src/r1cs/mod.rs | 26 ++------ {supernova => nova}/src/r1cs/sparse.rs | 7 +-- {supernova => nova}/src/test_utils/mod.rs | 4 +- {supernova => nova}/src/utils.rs | 0 prover/Cargo.toml | 4 +- prover/src/circuit.rs | 16 ++--- prover/src/error.rs | 8 +-- prover/src/lib.rs | 14 ++--- prover/src/main.rs | 6 +- prover/src/pp.rs | 8 +-- prover/src/types.rs | 52 +++++----------- riscv/src/lib.rs | 4 +- riscv/src/machines.rs | 2 +- riscv/src/vm.rs | 2 +- riscv/src/vm/eval.rs | 2 +- runtime/README.md | 10 +-- runtime/examples/basic.rs | 4 +- runtime/macros/src/lib.rs | 7 +-- runtime/src/ecalls.rs | 2 +- runtime/src/lib.rs | 6 +- supernova/README.md | 1 - supernova/rustfmt.toml | 0 tools/src/command/mod.rs | 10 ++- tools/src/command/prove.rs | 6 +- tools/src/command/public_params.rs | 6 +- tools/src/command/request.rs | 2 +- tools/src/command/verify.rs | 6 +- tools/src/lib.rs | 2 +- tools/tools-dev/.rustfmt.toml | 0 .../src/command/dev/common_impl/prove.rs | 6 +- .../src/command/dev/common_impl/run.rs | 6 +- .../src/command/dev/common_impl/verify.rs | 6 +- tools/tools-dev/src/command/dev/node.rs | 6 +- vm/src/ark_serde.rs | 4 +- vm/src/circuit.rs | 4 +- vm/src/circuit/nvm.rs | 2 +- vm/src/circuit/r1cs.rs | 2 +- vm/src/circuit/step.rs | 16 ++--- vm/src/circuit/test.rs | 9 +-- vm/src/eval.rs | 4 +- vm/src/instructions.rs | 2 +- vm/src/lib.rs | 6 +- vm/src/memory/cacheline.rs | 2 +- vm/src/memory/path.rs | 8 +-- vm/src/memory/trie.rs | 8 +-- vm/src/riscv.rs | 20 +++--- vm/src/trace.rs | 6 +- 112 files changed, 252 insertions(+), 393 deletions(-) delete mode 100644 config/.rustfmt.toml rename {supernova-benches => nova-benches}/.gitignore (100%) rename {supernova-benches => nova-benches}/Cargo.toml (90%) rename {supernova-benches => nova-benches}/benches/recursive-snark.rs (99%) rename {supernova => nova}/.gitignore (100%) rename {supernova => nova}/Cargo.toml (98%) rename {supernova => nova}/src/absorb.rs (100%) rename {supernova => nova}/src/circuits/mod.rs (100%) rename {supernova => nova}/src/circuits/nova/mod.rs (100%) rename {supernova => nova}/src/circuits/nova/pcd/augmented.rs (99%) rename {supernova => nova}/src/circuits/nova/pcd/compression/commitment_utils.rs (100%) rename {supernova => nova}/src/circuits/nova/pcd/compression/conversion.rs (96%) rename {supernova => nova}/src/circuits/nova/pcd/compression/error.rs (100%) rename {supernova => nova}/src/circuits/nova/pcd/compression/mod.rs (100%) rename {supernova => nova}/src/circuits/nova/pcd/compression/secondary/conversion.rs (100%) rename {supernova => nova}/src/circuits/nova/pcd/compression/secondary/mod.rs (100%) rename {supernova => nova}/src/circuits/nova/pcd/mod.rs (96%) rename {supernova => nova}/src/circuits/nova/public_params.rs (100%) rename {supernova => nova}/src/circuits/nova/sequential/augmented.rs (99%) rename {supernova => nova}/src/circuits/nova/sequential/mod.rs (97%) rename {supernova => nova}/src/commitment.rs (100%) rename {supernova => nova}/src/folding/hypernova/ml_sumcheck/data_structures.rs (100%) rename {supernova => nova}/src/folding/hypernova/ml_sumcheck/mod.rs (100%) rename {supernova => nova}/src/folding/hypernova/ml_sumcheck/protocol/mod.rs (100%) rename {supernova => nova}/src/folding/hypernova/ml_sumcheck/protocol/prover.rs (98%) rename {supernova => nova}/src/folding/hypernova/ml_sumcheck/protocol/verifier.rs (100%) rename {supernova => nova}/src/folding/hypernova/ml_sumcheck/tests.rs (100%) rename {supernova => nova}/src/folding/hypernova/mod.rs (100%) rename {supernova => nova}/src/folding/mod.rs (100%) rename {supernova => nova}/src/folding/nova/cyclefold/mod.rs (100%) rename {supernova => nova}/src/folding/nova/cyclefold/nimfs/mod.rs (97%) rename {supernova => nova}/src/folding/nova/cyclefold/nimfs/relaxed.rs (98%) rename {supernova => nova}/src/folding/nova/cyclefold/secondary/mod.rs (98%) rename {supernova => nova}/src/folding/nova/mod.rs (100%) rename {supernova => nova}/src/folding/nova/nifs.rs (100%) rename {supernova => nova}/src/gadgets/cyclefold/mod.rs (100%) rename {supernova => nova}/src/gadgets/cyclefold/primary.rs (98%) rename {supernova => nova}/src/gadgets/cyclefold/secondary.rs (99%) rename {supernova => nova}/src/gadgets/mod.rs (100%) rename {supernova => nova}/src/gadgets/nonnative/mod.rs (100%) rename {supernova => nova}/src/gadgets/nonnative/short_weierstrass.rs (100%) rename {supernova => nova}/src/lib.rs (89%) rename {supernova => nova}/src/provider/mod.rs (100%) rename {supernova => nova}/src/provider/pedersen.rs (100%) rename {supernova => nova}/src/provider/poseidon.rs (100%) rename {supernova => nova}/src/r1cs/mod.rs (98%) rename {supernova => nova}/src/r1cs/sparse.rs (98%) rename {supernova => nova}/src/test_utils/mod.rs (96%) rename {supernova => nova}/src/utils.rs (100%) delete mode 100644 supernova/README.md delete mode 100644 supernova/rustfmt.toml delete mode 100644 tools/tools-dev/.rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml index 094abe94b..e4097fc63 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,3 +1,7 @@ +# format_code_in_doc_comments = true +# group_imports = "StdExternalCrate" +# wrap_comments = true + +use_field_init_shorthand = true struct_lit_width = 40 -reorder_imports = false -reorder_modules = false +single_line_let_else_max_width = 60 diff --git a/Cargo.lock b/Cargo.lock index b14424398..69de0a891 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1524,6 +1524,36 @@ dependencies = [ "tracing-subscriber 0.3.18", ] +[[package]] +name = "nexus-nova" +version = "0.1.0" +dependencies = [ + "ark-bn254", + "ark-crypto-primitives", + "ark-ec", + "ark-ff", + "ark-grumpkin", + "ark-pallas", + "ark-poly", + "ark-poly-commit", + "ark-r1cs-std", + "ark-relations", + "ark-serialize", + "ark-spartan", + "ark-std", + "ark-test-curves", + "ark-vesta", + "ff", + "halo2_proofs", + "halo2curves 0.3.3", + "hex", + "merlin", + "rayon", + "sha3 0.10.8", + "tracing", + "tracing-subscriber 0.3.18", +] + [[package]] name = "nexus-prover" version = "0.1.0" @@ -1538,9 +1568,9 @@ dependencies = [ "ark-serialize", "ark-std", "clap 4.4.18", + "nexus-nova", "nexus-vm", "snmalloc-rs", - "supernova", "tracing", "tracing-subscriber 0.3.18", "zstd", @@ -2306,36 +2336,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" -[[package]] -name = "supernova" -version = "0.1.0" -dependencies = [ - "ark-bn254", - "ark-crypto-primitives", - "ark-ec", - "ark-ff", - "ark-grumpkin", - "ark-pallas", - "ark-poly", - "ark-poly-commit", - "ark-r1cs-std", - "ark-relations", - "ark-serialize", - "ark-spartan", - "ark-std", - "ark-test-curves", - "ark-vesta", - "ff", - "halo2_proofs", - "halo2curves 0.3.3", - "hex", - "merlin", - "rayon", - "sha3 0.10.8", - "tracing", - "tracing-subscriber 0.3.18", -] - [[package]] name = "syn" version = "1.0.109" diff --git a/Cargo.toml b/Cargo.toml index edd6f70f7..a1f912145 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ "config/serde_wrapper", "prover", "network", - "supernova", + "nova", "spartan", ] default-members = [ @@ -20,10 +20,10 @@ default-members = [ "tools", "prover", "network", - "supernova", + "nova", "spartan", ] -exclude = ["supernova-benches"] +exclude = ["nova-benches"] [workspace.package] edition = "2021" diff --git a/config/.rustfmt.toml b/config/.rustfmt.toml deleted file mode 100644 index e69de29bb..000000000 diff --git a/config/bases/rust.toml b/config/bases/rust.toml index 4bb9e6d18..9c3cc29cb 100644 --- a/config/bases/rust.toml +++ b/config/bases/rust.toml @@ -2,8 +2,8 @@ RUST_LOG="""\ nexus-network=debug,\ nexus-prover=info,\ nexus-tools-dev=debug,\ -supernova::sequential=debug,\ -supernova::pcd=debug\ +nexus-nova::sequential=debug,\ +nexus-nova::pcd=debug\ """ RUST_BACKTRACE="full" diff --git a/examples/src/bin/fact.rs b/examples/src/bin/fact.rs index 402c3fde1..2c935a1f5 100644 --- a/examples/src/bin/fact.rs +++ b/examples/src/bin/fact.rs @@ -1,17 +1,20 @@ #![no_std] #![no_main] -use nexus_rt::*; +use nexus_rt::{println, Write}; -#[entry] +#[nexus_rt::main] fn main() { fn f(n: u32) -> u32 { if n <= 1 { 1 } else { - n * f(n - 1) + // n * f(n - 1) would panic if the factorial overflows u32::MAX in debug build, + // and wrap around in release. Therefore, use built-in checked methods to make + // the output deterministic. + n.saturating_mul(f(n - 1)) } } - let n = 15; + let n = 12; println!("fact {n} = {}", f(n)) } diff --git a/examples/src/bin/fail.rs b/examples/src/bin/fail.rs index bb02f780c..2ad46624f 100644 --- a/examples/src/bin/fail.rs +++ b/examples/src/bin/fail.rs @@ -1,9 +1,7 @@ #![no_std] #![no_main] -use nexus_rt::entry; - -#[entry] +#[nexus_rt::main] fn main() { panic!(); } diff --git a/examples/src/bin/fib.rs b/examples/src/bin/fib.rs index fbad21a29..096501b69 100644 --- a/examples/src/bin/fib.rs +++ b/examples/src/bin/fib.rs @@ -1,7 +1,7 @@ #![no_std] #![no_main] -use nexus_rt::*; +use nexus_rt::{println, Write}; fn fib(n: u32) -> u32 { match n { @@ -11,7 +11,7 @@ fn fib(n: u32) -> u32 { } } -#[entry] +#[nexus_rt::main] fn main() { for n in 0..10 { println!("fib({n}) = {}", fib(n)); diff --git a/examples/src/bin/fib1000.rs b/examples/src/bin/fib1000.rs index f018d36cd..8d948bccc 100644 --- a/examples/src/bin/fib1000.rs +++ b/examples/src/bin/fib1000.rs @@ -1,7 +1,7 @@ #![no_std] #![no_main] -use nexus_rt::*; +use nexus_rt::{println, Write}; use core::ops::Add; @@ -44,7 +44,7 @@ fn fib_iter(n: u32) -> BN { b } -#[entry] +#[nexus_rt::main] fn main() { let b = fib_iter(1000); diff --git a/examples/src/bin/fmt.rs b/examples/src/bin/fmt.rs index b976c9cd2..d471f6f54 100644 --- a/examples/src/bin/fmt.rs +++ b/examples/src/bin/fmt.rs @@ -6,15 +6,14 @@ extern crate alloc; use alloc::format; use nexus_rt::{ - entry, // proc macro to specify entry point + print, // macro similar to std::print! + println, // macro similar to std::println! write_log, // primitive string printing function NexusLog, // Type implementing core::fmt::Write Write, // re-export or core::fmt::Write for convenience - print, // macro similar to std::print! - println, // macro similar to std::println! }; -#[entry] +#[nexus_rt::main] fn main() { // basic output of strings write_log("Hello\n"); diff --git a/examples/src/main.rs b/examples/src/main.rs index 99401bab5..69a7814f6 100644 --- a/examples/src/main.rs +++ b/examples/src/main.rs @@ -1,9 +1,9 @@ #![no_std] #![no_main] -use nexus_rt::{entry, write_log}; +use nexus_rt::write_log; -#[entry] +#[nexus_rt::main] fn main() { write_log("Hello, World!\n"); } diff --git a/network/src/api.rs b/network/src/api.rs index cc5380eda..c89be250a 100644 --- a/network/src/api.rs +++ b/network/src/api.rs @@ -1,4 +1,4 @@ -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] pub enum NexusAPI { diff --git a/network/src/bin.rs b/network/src/bin.rs index 4591ccfa9..b750301a0 100644 --- a/network/src/bin.rs +++ b/network/src/bin.rs @@ -1,15 +1,15 @@ use std::future::Future; use tokio::io::{AsyncReadExt, AsyncWriteExt}; +use http::uri; use hyper::{ header::{CONNECTION, UPGRADE}, upgrade::Upgraded, Body, Client, Request, Response, StatusCode, }; -use http::uri; -use super::*; use super::pcd::*; +use super::*; const MAX_SIZE: u32 = 40 * 1024 * 1024; diff --git a/network/src/bin/client.rs b/network/src/bin/client.rs index 0ac605de6..6ac182003 100644 --- a/network/src/bin/client.rs +++ b/network/src/bin/client.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use clap::{Parser, Subcommand, Args}; +use clap::{Args, Parser, Subcommand}; use tracing_subscriber::EnvFilter; use nexus_network::client::{self, Client}; diff --git a/network/src/bin/pcdnode/db.rs b/network/src/bin/pcdnode/db.rs index c18eb532a..c892a5b94 100644 --- a/network/src/bin/pcdnode/db.rs +++ b/network/src/bin/pcdnode/db.rs @@ -1,5 +1,5 @@ -use std::sync::{Arc, Mutex}; use std::collections::HashMap; +use std::sync::{Arc, Mutex}; use nexus_network::api::Proof; diff --git a/network/src/bin/pcdnode/main.rs b/network/src/bin/pcdnode/main.rs index 12a33d8b7..d106067e7 100644 --- a/network/src/bin/pcdnode/main.rs +++ b/network/src/bin/pcdnode/main.rs @@ -2,27 +2,27 @@ #[global_allocator] static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; -mod workers; -mod post; mod db; +mod post; +mod workers; use std::net::SocketAddr; use clap::Parser; +use http::uri; use hyper::{ header::UPGRADE, service::{make_service_fn, service_fn}, Body, Method, Request, Response, Server, StatusCode, }; -use http::uri; use tracing_subscriber::EnvFilter; use nexus_prover::pp::gen_or_load; use nexus_network::*; -use workers::*; use post::*; +use workers::*; fn r404() -> Result> { Ok(Response::builder() diff --git a/network/src/bin/pcdnode/post.rs b/network/src/bin/pcdnode/post.rs index f72a341e7..b43b7e92b 100644 --- a/network/src/bin/pcdnode/post.rs +++ b/network/src/bin/pcdnode/post.rs @@ -1,19 +1,15 @@ -use std::sync::Arc; use std::collections::VecDeque; +use std::sync::Arc; use sha2::{Digest, Sha256}; use hyper::{header, Body, Request, Response, StatusCode}; use tokio::task::JoinHandle; -use nexus_vm::{ - eval::{NexusVM}, - trace::trace, - riscv::translate_elf_bytes, -}; -use nexus_network::*; -use nexus_network::pcd::*; use nexus_network::api::*; +use nexus_network::pcd::*; +use nexus_network::*; +use nexus_vm::{eval::NexusVM, riscv::translate_elf_bytes, trace::trace}; use crate::workers::*; @@ -76,12 +72,8 @@ pub fn manage_proof(mut state: WorkerState, hash: String, mut vm: NexusVM) -> Re let r = v.pop_front().unwrap(); let trace = trace.clone(); v2.push_back(tokio::spawn(async move { - let PCDRes(l) = l.await.unwrap() else { - panic!() - }; - let PCDRes(r) = r.await.unwrap() else { - panic!() - }; + let PCDRes(l) = l.await.unwrap() else { panic!() }; + let PCDRes(r) = r.await.unwrap() else { panic!() }; state.db.update_complete(hash.to_string(), 2); let ltr = trace.get(l.j as usize).unwrap(); let rtr = trace.get(r.j as usize).unwrap(); diff --git a/network/src/bin/pcdnode/workers.rs b/network/src/bin/pcdnode/workers.rs index e3a3551d7..422f937c2 100644 --- a/network/src/bin/pcdnode/workers.rs +++ b/network/src/bin/pcdnode/workers.rs @@ -11,11 +11,11 @@ use hyper::upgrade::Upgraded; use async_channel::{unbounded, Receiver, Sender}; -use nexus_vm::trace::{Trace}; -use nexus_prover::{error::ProofError, types::*, circuit::Tr}; +use nexus_prover::{circuit::Tr, error::ProofError, types::*}; +use nexus_vm::trace::Trace; -use nexus_network::*; use nexus_network::pcd::*; +use nexus_network::*; use crate::db::DB; diff --git a/network/src/client.rs b/network/src/client.rs index c1efd5088..ee90e0f6b 100644 --- a/network/src/client.rs +++ b/network/src/client.rs @@ -1,12 +1,12 @@ use std::path::Path; -use hyper::body::{HttpBody, Buf}; use http::uri; +use hyper::body::{Buf, HttpBody}; use hyper::client::HttpConnector; use tokio::runtime; -use crate::Result; use crate::api::*; +use crate::Result; pub const LOG_TARGET: &str = "nexus-network::client"; diff --git a/network/src/lib.rs b/network/src/lib.rs index 6378e4a64..9f5d75b98 100644 --- a/network/src/lib.rs +++ b/network/src/lib.rs @@ -1,8 +1,8 @@ -pub mod bin; -pub mod ws; -pub mod pcd; pub mod api; +pub mod bin; pub mod client; +pub mod pcd; +pub mod ws; pub type DynError = Box; pub type Result = std::result::Result; diff --git a/network/src/pcd.rs b/network/src/pcd.rs index 0aa8716b2..a11edb08f 100644 --- a/network/src/pcd.rs +++ b/network/src/pcd.rs @@ -1,9 +1,9 @@ use std::net::SocketAddr; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; -use nexus_vm::trace::Trace; use nexus_prover::types::*; +use nexus_vm::trace::Trace; use crate::Result; @@ -32,9 +32,9 @@ pub enum NexusMsg { pub use NexusMsg::*; mod scalars { + use ark_ff::{BigInt, Fp256, MontBackend, MontConfig, PrimeField}; + use serde::{de::Visitor, ser::SerializeSeq, Deserializer, Serializer}; use std::fmt; - use serde::{Serializer, Deserializer, ser::SerializeSeq, de::Visitor}; - use ark_ff::{BigInt, PrimeField, Fp256, MontBackend, MontConfig}; type F = Fp256>; type T = Vec>; @@ -97,9 +97,9 @@ mod scalars { } mod ark { + use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; + use serde::{de::Visitor, Deserializer, Serializer}; use std::fmt; - use serde::{Serializer, Deserializer, de::Visitor}; - use ark_serialize::{CanonicalSerialize, CanonicalDeserialize}; pub fn serialize(t: &T, s: S) -> Result where @@ -186,8 +186,8 @@ mod test { use super::*; use ark_ff::fields::AdditiveGroup; - use nexus_prover::pp::gen_pp; use nexus_prover::circuit::nop_circuit; + use nexus_prover::pp::gen_pp; fn round_trip(msg: &NexusMsg) { let v = encode_lz4(msg).unwrap(); diff --git a/supernova-benches/.gitignore b/nova-benches/.gitignore similarity index 100% rename from supernova-benches/.gitignore rename to nova-benches/.gitignore diff --git a/supernova-benches/Cargo.toml b/nova-benches/Cargo.toml similarity index 90% rename from supernova-benches/Cargo.toml rename to nova-benches/Cargo.toml index f170c01a7..60ad193d5 100644 --- a/supernova-benches/Cargo.toml +++ b/nova-benches/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "supernova-benches" +name = "nova-benches" version = "0.1.0" edition = "2021" @@ -15,11 +15,11 @@ ark-vesta = "0.4.0" criterion = "0.5" pprof = { version = "0.13", features = ["criterion", "flamegraph"] } -supernova = { path = "../supernova", default-features = false } +nexus-nova = { path = "../nova", default-features = false } [features] default = ["parallel"] -parallel = ["supernova/parallel"] +parallel = ["nexus-nova/parallel"] [[bench]] name = "recursive-snark" diff --git a/supernova-benches/benches/recursive-snark.rs b/nova-benches/benches/recursive-snark.rs similarity index 99% rename from supernova-benches/benches/recursive-snark.rs rename to nova-benches/benches/recursive-snark.rs index 01e5a7c4b..279b022f9 100644 --- a/supernova-benches/benches/recursive-snark.rs +++ b/nova-benches/benches/recursive-snark.rs @@ -16,7 +16,7 @@ use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; use criterion::*; use pprof::criterion::{Output, PProfProfiler}; -use supernova::{ +use nexus_nova::{ nova::sequential::{IVCProof, PublicParams}, pedersen::PedersenCommitment, poseidon_config, StepCircuit, diff --git a/supernova/.gitignore b/nova/.gitignore similarity index 100% rename from supernova/.gitignore rename to nova/.gitignore diff --git a/supernova/Cargo.toml b/nova/Cargo.toml similarity index 98% rename from supernova/Cargo.toml rename to nova/Cargo.toml index a293f0db7..a8d23c315 100644 --- a/supernova/Cargo.toml +++ b/nova/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "supernova" +name = "nexus-nova" authors = { workspace = true } version = { workspace = true } edition = { workspace = true } diff --git a/supernova/src/absorb.rs b/nova/src/absorb.rs similarity index 100% rename from supernova/src/absorb.rs rename to nova/src/absorb.rs diff --git a/supernova/src/circuits/mod.rs b/nova/src/circuits/mod.rs similarity index 100% rename from supernova/src/circuits/mod.rs rename to nova/src/circuits/mod.rs diff --git a/supernova/src/circuits/nova/mod.rs b/nova/src/circuits/nova/mod.rs similarity index 100% rename from supernova/src/circuits/nova/mod.rs rename to nova/src/circuits/nova/mod.rs diff --git a/supernova/src/circuits/nova/pcd/augmented.rs b/nova/src/circuits/nova/pcd/augmented.rs similarity index 99% rename from supernova/src/circuits/nova/pcd/augmented.rs rename to nova/src/circuits/nova/pcd/augmented.rs index b9ea9729e..b9a86b0c4 100644 --- a/supernova/src/circuits/nova/pcd/augmented.rs +++ b/nova/src/circuits/nova/pcd/augmented.rs @@ -430,11 +430,7 @@ where step_circuit: &'a SC, input: NovaAugmentedCircuitInput, ) -> Self { - Self { - ro_config, - step_circuit, - input, - } + Self { ro_config, step_circuit, input } } } diff --git a/supernova/src/circuits/nova/pcd/compression/commitment_utils.rs b/nova/src/circuits/nova/pcd/compression/commitment_utils.rs similarity index 100% rename from supernova/src/circuits/nova/pcd/compression/commitment_utils.rs rename to nova/src/circuits/nova/pcd/compression/commitment_utils.rs diff --git a/supernova/src/circuits/nova/pcd/compression/conversion.rs b/nova/src/circuits/nova/pcd/compression/conversion.rs similarity index 96% rename from supernova/src/circuits/nova/pcd/compression/conversion.rs rename to nova/src/circuits/nova/pcd/compression/conversion.rs index 0baee1c13..1daad8abc 100644 --- a/supernova/src/circuits/nova/pcd/compression/conversion.rs +++ b/nova/src/circuits/nova/pcd/compression/conversion.rs @@ -75,11 +75,7 @@ where fn try_from( instance: RelaxedR1CSInstance, PC>>, ) -> Result { - let RelaxedR1CSInstance { - commitment_W, - commitment_E, - X, - } = instance; + let RelaxedR1CSInstance { commitment_W, commitment_E, X } = instance; Ok(CRR1CSInstance { input: Assignment::new(&X[1..])?, u: X[0], @@ -96,10 +92,7 @@ where type Error = ConversionError; fn try_from(witness: RelaxedR1CSWitness) -> Result { let RelaxedR1CSWitness { W, E } = witness; - Ok(CRR1CSWitness { - W: Assignment::new(&W)?, - E, - }) + Ok(CRR1CSWitness { W: Assignment::new(&W)?, E }) } } diff --git a/supernova/src/circuits/nova/pcd/compression/error.rs b/nova/src/circuits/nova/pcd/compression/error.rs similarity index 100% rename from supernova/src/circuits/nova/pcd/compression/error.rs rename to nova/src/circuits/nova/pcd/compression/error.rs diff --git a/supernova/src/circuits/nova/pcd/compression/mod.rs b/nova/src/circuits/nova/pcd/compression/mod.rs similarity index 100% rename from supernova/src/circuits/nova/pcd/compression/mod.rs rename to nova/src/circuits/nova/pcd/compression/mod.rs diff --git a/supernova/src/circuits/nova/pcd/compression/secondary/conversion.rs b/nova/src/circuits/nova/pcd/compression/secondary/conversion.rs similarity index 100% rename from supernova/src/circuits/nova/pcd/compression/secondary/conversion.rs rename to nova/src/circuits/nova/pcd/compression/secondary/conversion.rs diff --git a/supernova/src/circuits/nova/pcd/compression/secondary/mod.rs b/nova/src/circuits/nova/pcd/compression/secondary/mod.rs similarity index 100% rename from supernova/src/circuits/nova/pcd/compression/secondary/mod.rs rename to nova/src/circuits/nova/pcd/compression/secondary/mod.rs diff --git a/supernova/src/circuits/nova/pcd/mod.rs b/nova/src/circuits/nova/pcd/mod.rs similarity index 96% rename from supernova/src/circuits/nova/pcd/mod.rs rename to nova/src/circuits/nova/pcd/mod.rs index e90ecb7df..03dd888d7 100644 --- a/supernova/src/circuits/nova/pcd/mod.rs +++ b/nova/src/circuits/nova/pcd/mod.rs @@ -32,7 +32,7 @@ use augmented::{ NovaAugmentedCircuit, NovaAugmentedCircuitInput, NovaAugmentedCircuitNonBaseInput, PCDNodeInput, }; -const LOG_TARGET: &str = "supernova::pcd"; +const LOG_TARGET: &str = "nexus-nova::pcd"; #[doc(hidden)] pub struct SetupParams(PhantomData); @@ -204,9 +204,7 @@ where }; let cs = ConstraintSystem::new_ref(); - cs.set_mode(SynthesisMode::Prove { - construct_matrices: false, - }); + cs.set_mode(SynthesisMode::Prove { construct_matrices: false }); let circuit = NovaAugmentedCircuit::new(¶ms.ro_config, step_circuit, input); let z_next = tracing::debug_span!(target: LOG_TARGET, "satisfying_assignment") @@ -219,10 +217,7 @@ where let w = R1CSWitness:: { W: witness }; let commitment_W = commit_fn(¶ms.pp, &w); - let u = R1CSInstance:: { - commitment_W, - X: pub_io, - }; + let u = R1CSInstance:: { commitment_W, X: pub_io }; let z_j = z_next .iter() .map(R1CSVar::value) @@ -335,9 +330,7 @@ where }; let cs = ConstraintSystem::new_ref(); - cs.set_mode(SynthesisMode::Prove { - construct_matrices: false, - }); + cs.set_mode(SynthesisMode::Prove { construct_matrices: false }); let circuit = NovaAugmentedCircuit::new( ¶ms.ro_config, @@ -354,10 +347,7 @@ where let w = R1CSWitness:: { W: witness }; let commitment_W = commit_fn(¶ms.pp, &w); - let u = R1CSInstance:: { - commitment_W, - X: pub_io, - }; + let u = R1CSInstance:: { commitment_W, X: pub_io }; Ok(Self { i, @@ -435,7 +425,7 @@ mod tests { use super::*; use crate::{ circuits::nova::sequential::tests::CubicCircuit, pedersen::PedersenCommitment, - poseidon_config, LOG_TARGET as SUPERNOVA_TARGET, + poseidon_config, LOG_TARGET as NOVA_TARGET, }; use ark_crypto_primitives::sponge::poseidon::PoseidonSponge; @@ -508,7 +498,7 @@ mod tests { C1: CommitmentScheme, SetupAux = ()>, C2: CommitmentScheme, SetupAux = ()>, { - let filter = filter::Targets::new().with_target(SUPERNOVA_TARGET, tracing::Level::DEBUG); + let filter = filter::Targets::new().with_target(NOVA_TARGET, tracing::Level::DEBUG); let _guard = tracing_subscriber::registry() .with( tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ENTER | FmtSpan::CLOSE), diff --git a/supernova/src/circuits/nova/public_params.rs b/nova/src/circuits/nova/public_params.rs similarity index 100% rename from supernova/src/circuits/nova/public_params.rs rename to nova/src/circuits/nova/public_params.rs diff --git a/supernova/src/circuits/nova/sequential/augmented.rs b/nova/src/circuits/nova/sequential/augmented.rs similarity index 99% rename from supernova/src/circuits/nova/sequential/augmented.rs rename to nova/src/circuits/nova/sequential/augmented.rs index 8d997f169..96ab0628b 100644 --- a/supernova/src/circuits/nova/sequential/augmented.rs +++ b/nova/src/circuits/nova/sequential/augmented.rs @@ -244,11 +244,7 @@ where step_circuit: &'a SC, input: NovaAugmentedCircuitInput, ) -> Self { - Self { - ro_config, - step_circuit, - input, - } + Self { ro_config, step_circuit, input } } } diff --git a/supernova/src/circuits/nova/sequential/mod.rs b/nova/src/circuits/nova/sequential/mod.rs similarity index 97% rename from supernova/src/circuits/nova/sequential/mod.rs rename to nova/src/circuits/nova/sequential/mod.rs index 42b12eca7..0ba3965f3 100644 --- a/supernova/src/circuits/nova/sequential/mod.rs +++ b/nova/src/circuits/nova/sequential/mod.rs @@ -29,7 +29,7 @@ use augmented::{ NovaAugmentedCircuit, NovaAugmentedCircuitInput, NovaAugmentedCircuitNonBaseInput, }; -const LOG_TARGET: &str = "supernova::sequential"; +const LOG_TARGET: &str = "nexus-nova::sequential"; #[doc(hidden)] pub struct SetupParams(PhantomData); @@ -228,11 +228,7 @@ where step_num = %self.step_num(), ) .entered(); - let IVCProof { - params, - z_0, - non_base, - } = self; + let IVCProof { params, z_0, non_base } = self; let (i_next, input, U, W, U_secondary, W_secondary) = if let Some(non_base) = non_base { let IVCProofNonBase { @@ -290,9 +286,7 @@ where }; let cs = ConstraintSystem::new_ref(); - cs.set_mode(SynthesisMode::Prove { - construct_matrices: false, - }); + cs.set_mode(SynthesisMode::Prove { construct_matrices: false }); let circuit = NovaAugmentedCircuit::new(¶ms.ro_config, step_circuit, input); @@ -306,10 +300,7 @@ where let w = R1CSWitness:: { W: witness }; let commitment_W = w.commit::(¶ms.pp); - let u = R1CSInstance:: { - commitment_W, - X: pub_io, - }; + let u = R1CSInstance:: { commitment_W, X: pub_io }; let z_i = z_i.iter().map(R1CSVar::value).collect::>()?; @@ -389,7 +380,7 @@ where #[cfg(test)] pub(crate) mod tests { use super::*; - use crate::{pedersen::PedersenCommitment, poseidon_config, LOG_TARGET as SUPERNOVA_TARGET}; + use crate::{pedersen::PedersenCommitment, poseidon_config, LOG_TARGET as NOVA_TARGET}; use ark_crypto_primitives::sponge::poseidon::PoseidonSponge; use ark_ff::Field; @@ -489,7 +480,7 @@ pub(crate) mod tests { C1: CommitmentScheme, SetupAux = ()>, C2: CommitmentScheme, SetupAux = ()>, { - let filter = filter::Targets::new().with_target(SUPERNOVA_TARGET, tracing::Level::DEBUG); + let filter = filter::Targets::new().with_target(NOVA_TARGET, tracing::Level::DEBUG); let _guard = tracing_subscriber::registry() .with( tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ENTER | FmtSpan::CLOSE), diff --git a/supernova/src/commitment.rs b/nova/src/commitment.rs similarity index 100% rename from supernova/src/commitment.rs rename to nova/src/commitment.rs diff --git a/supernova/src/folding/hypernova/ml_sumcheck/data_structures.rs b/nova/src/folding/hypernova/ml_sumcheck/data_structures.rs similarity index 100% rename from supernova/src/folding/hypernova/ml_sumcheck/data_structures.rs rename to nova/src/folding/hypernova/ml_sumcheck/data_structures.rs diff --git a/supernova/src/folding/hypernova/ml_sumcheck/mod.rs b/nova/src/folding/hypernova/ml_sumcheck/mod.rs similarity index 100% rename from supernova/src/folding/hypernova/ml_sumcheck/mod.rs rename to nova/src/folding/hypernova/ml_sumcheck/mod.rs diff --git a/supernova/src/folding/hypernova/ml_sumcheck/protocol/mod.rs b/nova/src/folding/hypernova/ml_sumcheck/protocol/mod.rs similarity index 100% rename from supernova/src/folding/hypernova/ml_sumcheck/protocol/mod.rs rename to nova/src/folding/hypernova/ml_sumcheck/protocol/mod.rs diff --git a/supernova/src/folding/hypernova/ml_sumcheck/protocol/prover.rs b/nova/src/folding/hypernova/ml_sumcheck/protocol/prover.rs similarity index 98% rename from supernova/src/folding/hypernova/ml_sumcheck/protocol/prover.rs rename to nova/src/folding/hypernova/ml_sumcheck/protocol/prover.rs index db51deb71..4c4affd67 100644 --- a/supernova/src/folding/hypernova/ml_sumcheck/protocol/prover.rs +++ b/nova/src/folding/hypernova/ml_sumcheck/protocol/prover.rs @@ -161,8 +161,6 @@ impl IPForMLSumcheck { }, ); - ProverMsg { - evaluations: products_sum, - } + ProverMsg { evaluations: products_sum } } } diff --git a/supernova/src/folding/hypernova/ml_sumcheck/protocol/verifier.rs b/nova/src/folding/hypernova/ml_sumcheck/protocol/verifier.rs similarity index 100% rename from supernova/src/folding/hypernova/ml_sumcheck/protocol/verifier.rs rename to nova/src/folding/hypernova/ml_sumcheck/protocol/verifier.rs diff --git a/supernova/src/folding/hypernova/ml_sumcheck/tests.rs b/nova/src/folding/hypernova/ml_sumcheck/tests.rs similarity index 100% rename from supernova/src/folding/hypernova/ml_sumcheck/tests.rs rename to nova/src/folding/hypernova/ml_sumcheck/tests.rs diff --git a/supernova/src/folding/hypernova/mod.rs b/nova/src/folding/hypernova/mod.rs similarity index 100% rename from supernova/src/folding/hypernova/mod.rs rename to nova/src/folding/hypernova/mod.rs diff --git a/supernova/src/folding/mod.rs b/nova/src/folding/mod.rs similarity index 100% rename from supernova/src/folding/mod.rs rename to nova/src/folding/mod.rs diff --git a/supernova/src/folding/nova/cyclefold/mod.rs b/nova/src/folding/nova/cyclefold/mod.rs similarity index 100% rename from supernova/src/folding/nova/cyclefold/mod.rs rename to nova/src/folding/nova/cyclefold/mod.rs diff --git a/supernova/src/folding/nova/cyclefold/nimfs/mod.rs b/nova/src/folding/nova/cyclefold/nimfs/mod.rs similarity index 97% rename from supernova/src/folding/nova/cyclefold/nimfs/mod.rs rename to nova/src/folding/nova/cyclefold/nimfs/mod.rs index 2f60d2ec9..1f684f645 100644 --- a/supernova/src/folding/nova/cyclefold/nimfs/mod.rs +++ b/nova/src/folding/nova/cyclefold/nimfs/mod.rs @@ -159,10 +159,7 @@ where let U_secondary_temp = U_secondary.fold(&E_comm_trace.0, &commitment_T, &r_1)?; let W_secondary_temp = W_secondary.fold(&E_comm_trace.1, &T, &r_1)?; - let commitment_E_proof = secondary::Proof { - commitment_T, - U: E_comm_trace.0, - }; + let commitment_E_proof = secondary::Proof { commitment_T, U: E_comm_trace.0 }; let (T, commitment_T) = r1cs::commit_T( shape_secondary, @@ -182,10 +179,7 @@ where let U_secondary = U_secondary_temp.fold(&W_comm_trace.0, &commitment_T, &r_2)?; let W_secondary = W_secondary_temp.fold(&W_comm_trace.1, &T, &r_2)?; - let commitment_W_proof = secondary::Proof { - commitment_T, - U: W_comm_trace.0, - }; + let commitment_W_proof = secondary::Proof { commitment_T, U: W_comm_trace.0 }; let proof = Self { commitment_T: _commitment_T, @@ -219,10 +213,7 @@ where let r_0_scalar: G1::ScalarField = unsafe { cast_field_element::(&r_0) }; - let secondary::Proof { - U: comm_E_proof, - commitment_T, - } = &self.commitment_E_proof[0]; + let secondary::Proof { U: comm_E_proof, commitment_T } = &self.commitment_E_proof[0]; let pub_io = comm_E_proof .parse_secondary_io::() .ok_or(Error::InvalidPublicInput)?; diff --git a/supernova/src/folding/nova/cyclefold/nimfs/relaxed.rs b/nova/src/folding/nova/cyclefold/nimfs/relaxed.rs similarity index 98% rename from supernova/src/folding/nova/cyclefold/nimfs/relaxed.rs rename to nova/src/folding/nova/cyclefold/nimfs/relaxed.rs index 02ae62c15..63bd8d587 100644 --- a/supernova/src/folding/nova/cyclefold/nimfs/relaxed.rs +++ b/nova/src/folding/nova/cyclefold/nimfs/relaxed.rs @@ -170,10 +170,7 @@ where let U_secondary = U_secondary_temp.fold(&W_comm_trace.0, &commitment_T, &r_3)?; let W_secondary = W_secondary_temp.fold(&W_comm_trace.1, &T, &r_3)?; - let commitment_W_proof = secondary::Proof { - commitment_T, - U: W_comm_trace.0, - }; + let commitment_W_proof = secondary::Proof { commitment_T, U: W_comm_trace.0 }; random_oracle.absorb(&cast_field_element_unique::(&r_3)); let (proof_secondary, (U_secondary, W_secondary)) = NIFSProof::prove_with_relaxed( @@ -217,10 +214,7 @@ where let r_0_scalar: G1::ScalarField = unsafe { cast_field_element::(&r_0) }; - let secondary::Proof { - U: comm_E_proof_0, - commitment_T, - } = &self.commitment_E_proof[0]; + let secondary::Proof { U: comm_E_proof_0, commitment_T } = &self.commitment_E_proof[0]; let pub_io = comm_E_proof_0 .parse_secondary_io::() .ok_or(Error::InvalidPublicInput)?; diff --git a/supernova/src/folding/nova/cyclefold/secondary/mod.rs b/nova/src/folding/nova/cyclefold/secondary/mod.rs similarity index 98% rename from supernova/src/folding/nova/cyclefold/secondary/mod.rs rename to nova/src/folding/nova/cyclefold/secondary/mod.rs index f1e835841..b8179bdcf 100644 --- a/supernova/src/folding/nova/cyclefold/secondary/mod.rs +++ b/nova/src/folding/nova/cyclefold/secondary/mod.rs @@ -104,9 +104,7 @@ where C2: CommitmentScheme>, { let cs = ConstraintSystem::::new_ref(); - cs.set_mode(SynthesisMode::Prove { - construct_matrices: false, - }); + cs.set_mode(SynthesisMode::Prove { construct_matrices: false }); circuit.generate_constraints(cs.clone())?; @@ -119,10 +117,7 @@ where let W = R1CSWitness:: { W: witness }; let commitment_W = W.commit::(pp_secondary); - let U = R1CSInstance:: { - commitment_W, - X: pub_io, - }; + let U = R1CSInstance:: { commitment_W, X: pub_io }; Ok((U, W)) } diff --git a/supernova/src/folding/nova/mod.rs b/nova/src/folding/nova/mod.rs similarity index 100% rename from supernova/src/folding/nova/mod.rs rename to nova/src/folding/nova/mod.rs diff --git a/supernova/src/folding/nova/nifs.rs b/nova/src/folding/nova/nifs.rs similarity index 100% rename from supernova/src/folding/nova/nifs.rs rename to nova/src/folding/nova/nifs.rs diff --git a/supernova/src/gadgets/cyclefold/mod.rs b/nova/src/gadgets/cyclefold/mod.rs similarity index 100% rename from supernova/src/gadgets/cyclefold/mod.rs rename to nova/src/gadgets/cyclefold/mod.rs diff --git a/supernova/src/gadgets/cyclefold/primary.rs b/nova/src/gadgets/cyclefold/primary.rs similarity index 98% rename from supernova/src/gadgets/cyclefold/primary.rs rename to nova/src/gadgets/cyclefold/primary.rs index 826b4d929..0e02010ff 100644 --- a/supernova/src/gadgets/cyclefold/primary.rs +++ b/nova/src/gadgets/cyclefold/primary.rs @@ -67,10 +67,7 @@ where fn value(&self) -> Result { let commitment_W = self.commitment_W.value()?; let X = self.X.value()?; - Ok(R1CSInstance { - commitment_W: commitment_W.into(), - X, - }) + Ok(R1CSInstance { commitment_W: commitment_W.into(), X }) } } diff --git a/supernova/src/gadgets/cyclefold/secondary.rs b/nova/src/gadgets/cyclefold/secondary.rs similarity index 99% rename from supernova/src/gadgets/cyclefold/secondary.rs rename to nova/src/gadgets/cyclefold/secondary.rs index ddc3333f3..141b1b396 100644 --- a/supernova/src/gadgets/cyclefold/secondary.rs +++ b/nova/src/gadgets/cyclefold/secondary.rs @@ -242,11 +242,7 @@ where let commitment_E = self.commitment_E.value()?.into(); let X = self.X.value()?; - Ok(RelaxedR1CSInstance { - commitment_W, - commitment_E, - X, - }) + Ok(RelaxedR1CSInstance { commitment_W, commitment_E, X }) } } diff --git a/supernova/src/gadgets/mod.rs b/nova/src/gadgets/mod.rs similarity index 100% rename from supernova/src/gadgets/mod.rs rename to nova/src/gadgets/mod.rs diff --git a/supernova/src/gadgets/nonnative/mod.rs b/nova/src/gadgets/nonnative/mod.rs similarity index 100% rename from supernova/src/gadgets/nonnative/mod.rs rename to nova/src/gadgets/nonnative/mod.rs diff --git a/supernova/src/gadgets/nonnative/short_weierstrass.rs b/nova/src/gadgets/nonnative/short_weierstrass.rs similarity index 100% rename from supernova/src/gadgets/nonnative/short_weierstrass.rs rename to nova/src/gadgets/nonnative/short_weierstrass.rs diff --git a/supernova/src/lib.rs b/nova/src/lib.rs similarity index 89% rename from supernova/src/lib.rs rename to nova/src/lib.rs index cbb4fb166..7f3e92b4e 100644 --- a/supernova/src/lib.rs +++ b/nova/src/lib.rs @@ -21,4 +21,4 @@ pub mod r1cs; pub use circuits::{nova, StepCircuit}; pub use provider::{pedersen, poseidon::poseidon_config}; -pub(crate) const LOG_TARGET: &str = "supernova"; +pub(crate) const LOG_TARGET: &str = "nexus-nova"; diff --git a/supernova/src/provider/mod.rs b/nova/src/provider/mod.rs similarity index 100% rename from supernova/src/provider/mod.rs rename to nova/src/provider/mod.rs diff --git a/supernova/src/provider/pedersen.rs b/nova/src/provider/pedersen.rs similarity index 100% rename from supernova/src/provider/pedersen.rs rename to nova/src/provider/pedersen.rs diff --git a/supernova/src/provider/poseidon.rs b/nova/src/provider/poseidon.rs similarity index 100% rename from supernova/src/provider/poseidon.rs rename to nova/src/provider/poseidon.rs diff --git a/supernova/src/r1cs/mod.rs b/nova/src/r1cs/mod.rs similarity index 98% rename from supernova/src/r1cs/mod.rs rename to nova/src/r1cs/mod.rs index ad984a354..3a5b4e220 100644 --- a/supernova/src/r1cs/mod.rs +++ b/nova/src/r1cs/mod.rs @@ -502,11 +502,7 @@ impl> RelaxedR1CSInstance { // Note that U2 is not relaxed, thus E2 = 0 and u2 = 1. let commitment_E = comm_E1 + *comm_T * *r; - Ok(Self { - commitment_W, - commitment_E, - X, - }) + Ok(Self { commitment_W, commitment_E, X }) } /// Folds an incoming [`RelaxedR1CSInstance`] into the current one. @@ -526,11 +522,7 @@ impl> RelaxedR1CSInstance { let commitment_W = comm_W1 + *comm_W2 * *r; let commitment_E = comm_E1 + *comm_T * *r + *comm_E2 * r.square(); - Ok(Self { - commitment_W, - commitment_E, - X, - }) + Ok(Self { commitment_W, commitment_E, X }) } } @@ -659,13 +651,8 @@ mod tests { #[test] fn invalid_input() { - #[rustfmt::skip] let a = { - let a: &[&[u64]] = &[ - &[1, 2, 3], - &[3, 4, 5], - &[6, 7, 8], - ]; + let a: &[&[u64]] = &[&[1, 2, 3], &[3, 4, 5], &[6, 7, 8]]; to_field_sparse::(a) }; @@ -681,13 +668,8 @@ mod tests { #[test] fn zero_instance_is_satisfied() -> Result<(), Error> { - #[rustfmt::skip] let a = { - let a: &[&[u64]] = &[ - &[1, 2, 3], - &[3, 4, 5], - &[6, 7, 8], - ]; + let a: &[&[u64]] = &[&[1, 2, 3], &[3, 4, 5], &[6, 7, 8]]; to_field_sparse::(a) }; diff --git a/supernova/src/r1cs/sparse.rs b/nova/src/r1cs/sparse.rs similarity index 98% rename from supernova/src/r1cs/sparse.rs rename to nova/src/r1cs/sparse.rs index 29976eef9..5c81ea578 100644 --- a/supernova/src/r1cs/sparse.rs +++ b/nova/src/r1cs/sparse.rs @@ -66,12 +66,7 @@ impl SparseMatrix { data.extend(val); } - SparseMatrix { - data, - indices, - indptr, - cols, - } + SparseMatrix { data, indices, indptr, cols } } /// Retrieves the data for row slice [i..j] from `ptrs`. diff --git a/supernova/src/test_utils/mod.rs b/nova/src/test_utils/mod.rs similarity index 96% rename from supernova/src/test_utils/mod.rs rename to nova/src/test_utils/mod.rs index d51251d1b..7826fac24 100644 --- a/supernova/src/test_utils/mod.rs +++ b/nova/src/test_utils/mod.rs @@ -59,9 +59,7 @@ where let circuit = CubicCircuit { x }; let cs = ConstraintSystem::::new_ref(); - cs.set_mode(SynthesisMode::Prove { - construct_matrices: true, - }); + cs.set_mode(SynthesisMode::Prove { construct_matrices: true }); circuit.generate_constraints(cs.clone()).unwrap(); assert!(cs.is_satisfied().unwrap()); diff --git a/supernova/src/utils.rs b/nova/src/utils.rs similarity index 100% rename from supernova/src/utils.rs rename to nova/src/utils.rs diff --git a/prover/Cargo.toml b/prover/Cargo.toml index 2d0d5929e..62adf5fa4 100644 --- a/prover/Cargo.toml +++ b/prover/Cargo.toml @@ -18,7 +18,7 @@ snmalloc-rs = { version = "0.3.4", optional = true } zstd = { version = "0.12", default-features = false } nexus-vm = { path = "../vm" } -supernova = { path = "../supernova", features = ["spartan"] } +nexus-nova = { path = "../nova", features = ["spartan"] } tracing = "0.1" tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } @@ -42,6 +42,6 @@ parallel = [ "ark-std/parallel", "ark-crypto-primitives/parallel", "ark-r1cs-std/parallel", - "supernova/parallel", + "nexus-nova/parallel", ] snmalloc = ["snmalloc-rs"] diff --git a/prover/src/circuit.rs b/prover/src/circuit.rs index b28cc8883..7687558b4 100644 --- a/prover/src/circuit.rs +++ b/prover/src/circuit.rs @@ -1,21 +1,21 @@ use ark_ff::BigInt; -pub use ark_relations::{ - lc, - r1cs::{Variable, SynthesisMode, SynthesisError}, -}; pub use ark_r1cs_std::{ - R1CSVar, alloc::AllocVar, fields::{ - fp::{FpVar, AllocatedFp}, + fp::{AllocatedFp, FpVar}, FieldVar, }, + R1CSVar, +}; +pub use ark_relations::{ + lc, + r1cs::{SynthesisError, SynthesisMode, Variable}, }; use nexus_vm::{ + circuit::{build_constraints, ARITY}, eval::halt_vm, - trace::{Trace, trace}, - circuit::{ARITY, build_constraints}, + trace::{trace, Trace}, }; use crate::error::*; diff --git a/prover/src/error.rs b/prover/src/error.rs index 17a8feb33..09d5666e6 100644 --- a/prover/src/error.rs +++ b/prover/src/error.rs @@ -1,11 +1,11 @@ use std::error::Error; use std::fmt::{self, Debug, Display, Formatter}; -pub use nexus_vm::error::NexusVMError; -pub use ark_serialize::SerializationError; pub use ark_relations::r1cs::SynthesisError; -pub use supernova::nova::Error as NovaError; -pub use supernova::r1cs::Error as R1CSError; +pub use ark_serialize::SerializationError; +pub use nexus_nova::nova::Error as NovaError; +pub use nexus_nova::r1cs::Error as R1CSError; +pub use nexus_vm::error::NexusVMError; /// Errors related to proof generation #[derive(Debug)] diff --git a/prover/src/lib.rs b/prover/src/lib.rs index 49aba99af..b71e25ba3 100644 --- a/prover/src/lib.rs +++ b/prover/src/lib.rs @@ -1,20 +1,20 @@ -pub mod error; -pub mod types; pub mod circuit; +pub mod error; pub mod pp; +pub mod types; -use std::time::Instant; use std::io::{self, Write}; +use std::time::Instant; use nexus_vm::{ - riscv::{VMOpts, load_nvm}, - trace::{Trace, trace}, + riscv::{load_nvm, VMOpts}, + trace::{trace, Trace}, }; use crate::{ - error::ProofError, - types::{SeqPP, ParPP, IVCProof, PCDNode}, circuit::Tr, + error::ProofError, + types::{IVCProof, PCDNode, ParPP, SeqPP}, }; const LOG_TARGET: &str = "nexus-prover"; diff --git a/prover/src/main.rs b/prover/src/main.rs index 58c3eaa71..30e64f82d 100644 --- a/prover/src/main.rs +++ b/prover/src/main.rs @@ -5,12 +5,12 @@ static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; use clap::{Parser, Subcommand}; use tracing_subscriber::EnvFilter; -use nexus_vm::riscv::VMOpts; use nexus_prover::{ - run, prove_seq, prove_par, error::ProofError, - pp::{gen_to_file, gen_or_load}, + pp::{gen_or_load, gen_to_file}, + prove_par, prove_seq, run, }; +use nexus_vm::riscv::VMOpts; #[derive(Debug, Parser)] #[command(author, version, about, long_about = None)] diff --git a/prover/src/pp.rs b/prover/src/pp.rs index ba893b30b..61828ae1f 100644 --- a/prover/src/pp.rs +++ b/prover/src/pp.rs @@ -1,11 +1,11 @@ use std::fs::File; -use zstd::stream::{Encoder, Decoder}; +use zstd::stream::{Decoder, Encoder}; -pub use ark_serialize::{CanonicalSerialize, CanonicalDeserialize}; +pub use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; -use crate::types::*; +use crate::circuit::{nop_circuit, Tr}; use crate::error::*; -use crate::circuit::{Tr, nop_circuit}; +use crate::types::*; use crate::LOG_TARGET; pub fn gen_pp(circuit: &SC) -> Result, ProofError> diff --git a/prover/src/types.rs b/prover/src/types.rs index 3c6909ac8..86fdec688 100644 --- a/prover/src/types.rs +++ b/prover/src/types.rs @@ -1,49 +1,27 @@ //! Concrete types and traits used by zkVM -#![cfg_attr(rustfmt, rustfmt_skip)] - pub use std::marker::PhantomData; -pub use ark_ff::{ - Field, - PrimeField -}; +pub use ark_ff::{Field, PrimeField}; // concrete fields used -pub use ark_bn254::{ - Fr as F1, - g1::Config as G1, - G1Projective as P1, - G1Affine as A1, -}; -pub use ark_grumpkin::{ - Fr as F2, - GrumpkinConfig as G2, - Projective as P2, - Affine as A2, -}; +pub use ark_bn254::{g1::Config as G1, Fr as F1, G1Affine as A1, G1Projective as P1}; +pub use ark_grumpkin::{Affine as A2, Fr as F2, GrumpkinConfig as G2, Projective as P2}; // concrete sponge used -pub use ark_crypto_primitives::{ - sponge::{ - poseidon::{ - PoseidonConfig, - PoseidonSponge, - } - } -}; +pub use ark_crypto_primitives::sponge::poseidon::{PoseidonConfig, PoseidonSponge}; pub use ark_relations::r1cs::ConstraintSystemRef; // types and traits from nexus prover -pub use supernova::{ - r1cs::{R1CSShape, R1CSWitness}, +pub use nexus_nova::{ commitment::CommitmentScheme, - pedersen::PedersenCommitment, - StepCircuit, + nova::pcd, nova::public_params::{PublicParams, SetupParams}, nova::sequential as seq, - nova::pcd, + pedersen::PedersenCommitment, + r1cs::{R1CSShape, R1CSWitness}, + StepCircuit, }; // concrete constraint system @@ -52,7 +30,7 @@ pub type CS = ConstraintSystemRef; // random oracle pub type ROConfig = PoseidonConfig; pub type RO = PoseidonSponge; -pub use supernova::poseidon_config as ro_config; +pub use nexus_nova::poseidon_config as ro_config; // commitment scheme @@ -62,10 +40,10 @@ pub type C2 = PedersenCommitment; pub type SC = crate::circuit::Tr; // concrete public parameters -pub type PP = PublicParams; +pub type PP = PublicParams; -pub type SeqPP = seq::PublicParams; -pub type ParPP = pcd::PublicParams; +pub type SeqPP = seq::PublicParams; +pub type ParPP = pcd::PublicParams; -pub type IVCProof<'a> = seq::IVCProof<'a,G1,G2,C1,C2,RO,SC>; -pub type PCDNode = pcd::PCDNode; +pub type IVCProof<'a> = seq::IVCProof<'a, G1, G2, C1, C2, RO, SC>; +pub type PCDNode = pcd::PCDNode; diff --git a/riscv/src/lib.rs b/riscv/src/lib.rs index 0777b5738..f592e4360 100644 --- a/riscv/src/lib.rs +++ b/riscv/src/lib.rs @@ -3,9 +3,9 @@ #![allow(non_snake_case)] mod error; +pub mod machines; pub mod rv32; pub mod vm; -pub mod machines; use clap::Args; use elf::{abi::PT_LOAD, endian::LittleEndian, segment::ProgramHeader, ElfBytes}; @@ -17,7 +17,7 @@ use rv32::*; use vm::eval::*; // don't break API -pub use machines::{nop_vm, loop_vm}; +pub use machines::{loop_vm, nop_vm}; /// Load a VM state from an ELF file pub fn load_elf(path: &PathBuf) -> Result { diff --git a/riscv/src/machines.rs b/riscv/src/machines.rs index 1bf4a0bb2..db4807f7c 100644 --- a/riscv/src/machines.rs +++ b/riscv/src/machines.rs @@ -3,7 +3,7 @@ #![allow(clippy::field_reassign_with_default)] #![allow(clippy::identity_op)] -use crate::{VM, Regs}; +use crate::{Regs, VM}; /// An array of test machines, useful for debugging and developemnt. #[allow(clippy::type_complexity)] diff --git a/riscv/src/vm.rs b/riscv/src/vm.rs index 53ad05e32..1813f929c 100644 --- a/riscv/src/vm.rs +++ b/riscv/src/vm.rs @@ -1,4 +1,4 @@ //! A Virtual Machine for RISC-V -pub mod memory; pub mod eval; +pub mod memory; diff --git a/riscv/src/vm/eval.rs b/riscv/src/vm/eval.rs index 8ef6bf3f2..63f6fbf0f 100644 --- a/riscv/src/vm/eval.rs +++ b/riscv/src/vm/eval.rs @@ -1,8 +1,8 @@ //! A Virtual Machine for RISC-V +use super::memory::*; use crate::error::*; use crate::rv32::{parse::*, *}; -use super::memory::*; use VMError::*; // for ecall diff --git a/runtime/README.md b/runtime/README.md index 006c0aa0d..3076a79c0 100644 --- a/runtime/README.md +++ b/runtime/README.md @@ -54,9 +54,7 @@ Finally, a minimal `main.rs` file may look like: #![no_std] #![no_main] -use nexus_rt::entry; - -#[entry] +#[nexus_rt::main] fn main() {} ``` @@ -64,7 +62,5 @@ The first two lines declare that our program will not link against the `std` crate, and that we do not want the compiler to emit the standard start-up code to process command-line arguments and call `main`. The Nexus Runtime has a minimal start-up process and will call your entry -function directly. The fourth line brings the nexux-rt `entry` macro -into scope. This macro is used to mark the `main` function as the -starting point of the program. - +function directly. The `nexus_rt::main` macro is used to mark the `main` +function as the starting point of the program. diff --git a/runtime/examples/basic.rs b/runtime/examples/basic.rs index 63572d83c..4f2c3ef75 100644 --- a/runtime/examples/basic.rs +++ b/runtime/examples/basic.rs @@ -4,9 +4,9 @@ // optional, for use of collections, etc. extern crate alloc; -use nexus_rt::{write_log, entry}; +use nexus_rt::write_log; -#[entry] +#[nexus_rt::main] fn main() { write_log("Hello World\n"); } diff --git a/runtime/macros/src/lib.rs b/runtime/macros/src/lib.rs index 75cdd846f..4df16bbd3 100644 --- a/runtime/macros/src/lib.rs +++ b/runtime/macros/src/lib.rs @@ -16,14 +16,14 @@ use syn::{parse, spanned::Spanned, FnArg, ItemFn, PathArguments, ReturnType, Typ use proc_macro::TokenStream; #[proc_macro_attribute] -pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { +pub fn main(args: TokenStream, input: TokenStream) -> TokenStream { let f = parse_macro_input!(input as ItemFn); // check the function arguments if f.sig.inputs.len() > 3 { return parse::Error::new( f.sig.inputs.last().unwrap().span(), - "`#[entry]` function has too many arguments", + "function has too many arguments", ) .to_compile_error() .into(); @@ -61,7 +61,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { if !valid_signature { return parse::Error::new( f.span(), - "`#[entry]` function must have signature `fn([arg0: u32, ...]) [-> u32]`", + "function must have signature `fn([arg0: u32, ...]) [-> u32]`", ) .to_compile_error() .into(); @@ -90,7 +90,6 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { .into() } -#[allow(unused)] fn is_simple_type(ty: &Type, name: &str) -> bool { if let Type::Path(p) = ty { if p.qself.is_none() && p.path.leading_colon.is_none() && p.path.segments.len() == 1 { diff --git a/runtime/src/ecalls.rs b/runtime/src/ecalls.rs index cefd96042..7474e05e4 100644 --- a/runtime/src/ecalls.rs +++ b/runtime/src/ecalls.rs @@ -1,4 +1,4 @@ -pub use core::{fmt::Write}; +pub use core::fmt::Write; // To simplify calling out to the environment, we keep the // argument registers intact, and place the function number diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index c5482d607..ec046d59b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -4,10 +4,10 @@ // Nexus VM runtime environment // Note: adapted from riscv-rt, which was adapted from cortex-m. -use core::panic::PanicInfo; use core::alloc::{GlobalAlloc, Layout}; +use core::panic::PanicInfo; -pub use nexus_rt_macros::entry; +pub use nexus_rt_macros::main; mod ecalls; pub use ecalls::*; @@ -56,7 +56,7 @@ unsafe impl GlobalAlloc for Heap { #[export_name = "_start_rust"] pub unsafe extern "C" fn start_rust(a0: u32, a1: u32, a2: u32) -> u32 { extern "Rust" { - // This symbol will be provided by the user via `#[entry]` + // This symbol will be provided by the user via `#[nexus_rt::main]` fn main(a0: u32, a1: u32, a2: u32) -> u32; } main(a0, a1, a2) diff --git a/supernova/README.md b/supernova/README.md deleted file mode 100644 index 376fca0c4..000000000 --- a/supernova/README.md +++ /dev/null @@ -1 +0,0 @@ -# SuperNova diff --git a/supernova/rustfmt.toml b/supernova/rustfmt.toml deleted file mode 100644 index e69de29bb..000000000 diff --git a/tools/src/command/mod.rs b/tools/src/command/mod.rs index 3fd9177ca..e38ec2390 100644 --- a/tools/src/command/mod.rs +++ b/tools/src/command/mod.rs @@ -1,12 +1,12 @@ -use nexus_tools_dev::{Command, command::common::Command as CommonCommand}; use nexus_config::vm as vm_config; +use nexus_tools_dev::{command::common::Command as CommonCommand, Command}; pub mod new; -pub mod run; pub mod prove; +pub mod public_params; pub mod request; +pub mod run; pub mod verify; -pub mod public_params; // TODO: handle default values. const DEFAULT_K: usize = 1; @@ -15,9 +15,7 @@ const DEFAULT_NOVA_IMPL: vm_config::NovaImpl = vm_config::NovaImpl::Parallel; pub fn handle_command(cmd: Command) -> anyhow::Result<()> { #![allow(irrefutable_let_patterns)] // rust-analyzer may give a false warning in a workspace. - let Command::Common(cmd) = cmd else { - unreachable!() - }; + let Command::Common(cmd) = cmd else { unreachable!() }; match cmd { CommonCommand::New(args) => new::handle_command(args), CommonCommand::Run(args) => run::handle_command(args), diff --git a/tools/src/command/prove.rs b/tools/src/command/prove.rs index 28d303d92..69cfb54b2 100644 --- a/tools/src/command/prove.rs +++ b/tools/src/command/prove.rs @@ -6,6 +6,8 @@ use std::{ use anyhow::Context; use ark_serialize::CanonicalSerialize; +use nexus_config::vm as vm_config; +use nexus_network::client::Client; use nexus_tools_dev::{ command::common::{ prove::{CommonProveArgs, LocalProveArgs, ProveArgs}, @@ -13,12 +15,10 @@ use nexus_tools_dev::{ }, utils::{cargo, path_to_artifact}, }; -use nexus_network::client::Client; -use nexus_config::vm as vm_config; use crate::{ + command::{public_params::setup_params, DEFAULT_K, DEFAULT_NOVA_IMPL}, LOG_TARGET, - command::{DEFAULT_K, DEFAULT_NOVA_IMPL, public_params::setup_params}, }; pub fn handle_command(args: ProveArgs) -> anyhow::Result<()> { diff --git a/tools/src/command/public_params.rs b/tools/src/command/public_params.rs index 522d63682..bdc2ab6d8 100644 --- a/tools/src/command/public_params.rs +++ b/tools/src/command/public_params.rs @@ -2,14 +2,14 @@ use std::path::{Path, PathBuf}; use anyhow::Context; +use nexus_config::vm as vm_config; use nexus_tools_dev::command::common::public_params::{ - PublicParamsAction, PublicParamsArgs, SetupArgs, format_params_file, + format_params_file, PublicParamsAction, PublicParamsArgs, SetupArgs, }; -use nexus_config::vm as vm_config; use crate::{ - LOG_TARGET, command::{DEFAULT_K, DEFAULT_NOVA_IMPL}, + LOG_TARGET, }; pub fn handle_command(args: PublicParamsArgs) -> anyhow::Result<()> { diff --git a/tools/src/command/request.rs b/tools/src/command/request.rs index 2e5ef9c9a..79ac4cb16 100644 --- a/tools/src/command/request.rs +++ b/tools/src/command/request.rs @@ -1,7 +1,7 @@ use anyhow::Context; -use nexus_tools_dev::command::common::RequestArgs; use nexus_network::client::Client; +use nexus_tools_dev::command::common::RequestArgs; use crate::LOG_TARGET; diff --git a/tools/src/command/verify.rs b/tools/src/command/verify.rs index 30921e8ea..7c5701897 100644 --- a/tools/src/command/verify.rs +++ b/tools/src/command/verify.rs @@ -5,12 +5,12 @@ use std::{ }; use anyhow::Context; -use nexus_prover::types::PCDNode; -use nexus_tools_dev::command::common::{public_params::format_params_file, VerifyArgs}; use ark_serialize::CanonicalDeserialize; use nexus_config::vm as vm_config; +use nexus_prover::types::PCDNode; +use nexus_tools_dev::command::common::{public_params::format_params_file, VerifyArgs}; -use crate::{LOG_TARGET, command::DEFAULT_K}; +use crate::{command::DEFAULT_K, LOG_TARGET}; pub fn handle_command(args: VerifyArgs) -> anyhow::Result<()> { let VerifyArgs { pp_file, k, file } = args; diff --git a/tools/src/lib.rs b/tools/src/lib.rs index 14c93b203..0da6a7629 100644 --- a/tools/src/lib.rs +++ b/tools/src/lib.rs @@ -1,4 +1,4 @@ -pub use nexus_tools_dev::{Cli, setup_logger}; +pub use nexus_tools_dev::{setup_logger, Cli}; pub mod command; diff --git a/tools/tools-dev/.rustfmt.toml b/tools/tools-dev/.rustfmt.toml deleted file mode 100644 index e69de29bb..000000000 diff --git a/tools/tools-dev/src/command/dev/common_impl/prove.rs b/tools/tools-dev/src/command/dev/common_impl/prove.rs index 07f32b766..174b4560f 100644 --- a/tools/tools-dev/src/command/dev/common_impl/prove.rs +++ b/tools/tools-dev/src/command/dev/common_impl/prove.rs @@ -49,11 +49,7 @@ pub fn handle_command(args: ProveArgs) -> anyhow::Result<()> { }; request_prove(&path, &url) } else { - let LocalProveArgs { - k, - pp_file, - nova_impl, - } = local_args; + let LocalProveArgs { k, pp_file, nova_impl } = local_args; let k = k.unwrap_or(vm_config.k); let nova_impl = nova_impl.unwrap_or(vm_config.nova_impl); local_prove(&path, k, nova_impl, pp_file) diff --git a/tools/tools-dev/src/command/dev/common_impl/run.rs b/tools/tools-dev/src/command/dev/common_impl/run.rs index 3a0d6a15f..68a16b4d8 100644 --- a/tools/tools-dev/src/command/dev/common_impl/run.rs +++ b/tools/tools-dev/src/command/dev/common_impl/run.rs @@ -6,11 +6,7 @@ use crate::{ }; pub fn handle_command(args: RunArgs) -> anyhow::Result<()> { - let RunArgs { - verbose, - release, - bin, - } = args; + let RunArgs { verbose, release, bin } = args; run_vm(bin, verbose, release) } diff --git a/tools/tools-dev/src/command/dev/common_impl/verify.rs b/tools/tools-dev/src/command/dev/common_impl/verify.rs index 12f3373e4..0aacaa337 100644 --- a/tools/tools-dev/src/command/dev/common_impl/verify.rs +++ b/tools/tools-dev/src/command/dev/common_impl/verify.rs @@ -5,11 +5,7 @@ use nexus_config::{Config, VmConfig}; use crate::command::{common::VerifyArgs, dev::compile_env_configs}; pub fn handle_command(args: VerifyArgs) -> anyhow::Result<()> { - let VerifyArgs { - pp_file, - file, - k: _k, - } = args; + let VerifyArgs { pp_file, file, k: _k } = args; // make sure configs are compiled compile_env_configs(false)?; diff --git a/tools/tools-dev/src/command/dev/node.rs b/tools/tools-dev/src/command/dev/node.rs index a966d49a0..18f3a8d88 100644 --- a/tools/tools-dev/src/command/dev/node.rs +++ b/tools/tools-dev/src/command/dev/node.rs @@ -41,11 +41,7 @@ pub fn handle_command(args: NodeArgs) -> anyhow::Result<()> { } fn launch_node(args: NodeArgs, config: NetworkConfig, pp_file: &Path) -> anyhow::Result<()> { - let NodeArgs { - mut well_known, - pcd, - msm, - } = args; + let NodeArgs { mut well_known, pcd, msm } = args; if !(well_known || pcd || msm) { well_known = true; } diff --git a/vm/src/ark_serde.rs b/vm/src/ark_serde.rs index 2d2713dca..2e22d2642 100644 --- a/vm/src/ark_serde.rs +++ b/vm/src/ark_serde.rs @@ -1,6 +1,6 @@ +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; +use serde::{de::Visitor, Deserializer, Serializer}; use std::fmt; -use serde::{Serializer, Deserializer, de::Visitor}; -use ark_serialize::{CanonicalSerialize, CanonicalDeserialize}; pub fn serialize(t: &T, s: S) -> Result where diff --git a/vm/src/circuit.rs b/vm/src/circuit.rs index 5a6fcd9fc..4d2a178a9 100644 --- a/vm/src/circuit.rs +++ b/vm/src/circuit.rs @@ -1,10 +1,10 @@ -mod r1cs; mod nvm; +mod r1cs; mod step; #[cfg(test)] mod test; -pub use r1cs::F; pub use nvm::ARITY; +pub use r1cs::F; pub use step::build_constraints; diff --git a/vm/src/circuit/nvm.rs b/vm/src/circuit/nvm.rs index 5f71f7777..8b84e2008 100644 --- a/vm/src/circuit/nvm.rs +++ b/vm/src/circuit/nvm.rs @@ -2,7 +2,7 @@ use ark_ff::{BigInt, PrimeField}; -use crate::instructions::{*, Opcode::*}; +use crate::instructions::{Opcode::*, *}; use crate::memory::path::Path; use crate::trace::Witness; diff --git a/vm/src/circuit/r1cs.rs b/vm/src/circuit/r1cs.rs index e5ae0402a..7333a5bb3 100644 --- a/vm/src/circuit/r1cs.rs +++ b/vm/src/circuit/r1cs.rs @@ -17,8 +17,8 @@ use std::collections::HashMap; use std::ops::Range; -use ark_ff::{BigInt, Fp, MontConfig}; use ark_bn254::FrConfig; +use ark_ff::{BigInt, Fp, MontConfig}; pub use ark_bn254::Fr as F; diff --git a/vm/src/circuit/step.rs b/vm/src/circuit/step.rs index 56c93849c..568f0f2c5 100644 --- a/vm/src/circuit/step.rs +++ b/vm/src/circuit/step.rs @@ -1,24 +1,24 @@ //! Integration with ArkWorks R1CS circuits. -use ark_relations::{ - lc, - r1cs::{ConstraintSystemRef, Variable, SynthesisError}, -}; use ark_r1cs_std::{ alloc::AllocVar, - fields::fp::{FpVar, AllocatedFp}, + fields::fp::{AllocatedFp, FpVar}, +}; +use ark_relations::{ + lc, + r1cs::{ConstraintSystemRef, SynthesisError, Variable}, }; use crate::{ error::Result, memory::path::{poseidon_config, ParamsVar}, - trace::{Trace, Block, Witness}, + trace::{Block, Trace, Witness}, }; use super::{ + nvm::{step, ARITY}, + r1cs::{R1CS, V, ZERO}, F, - r1cs::{ZERO, V, R1CS}, - nvm::{ARITY, step}, }; type CS = ConstraintSystemRef; diff --git a/vm/src/circuit/test.rs b/vm/src/circuit/test.rs index 46ba35733..899cf703a 100644 --- a/vm/src/circuit/test.rs +++ b/vm/src/circuit/test.rs @@ -1,17 +1,14 @@ +use ark_r1cs_std::{alloc::AllocVar, fields::fp::FpVar}; use ark_relations::r1cs::ConstraintSystem; -use ark_r1cs_std::{ - alloc::AllocVar, - fields::fp::{FpVar}, -}; use crate::{ error::Result, + eval::{halt_vm, NexusVM}, riscv::test::test_machines, - eval::{NexusVM, halt_vm}, trace::trace, }; -use super::{F, r1cs::R1CS, nvm::step, step::build_constraints}; +use super::{nvm::step, r1cs::R1CS, step::build_constraints, F}; // generate R1CS matrices fn vm_circuit(k: usize) -> Result { diff --git a/vm/src/eval.rs b/vm/src/eval.rs index 942044ac9..62c43dd04 100644 --- a/vm/src/eval.rs +++ b/vm/src/eval.rs @@ -2,9 +2,9 @@ use num_traits::FromPrimitive; -use crate::error::{Result, NexusVMError::InvalidInstruction}; +use crate::error::{NexusVMError::InvalidInstruction, Result}; use crate::instructions::{Inst, Opcode, Opcode::*, Width}; -use crate::memory::{Memory, path::Path}; +use crate::memory::{path::Path, Memory}; /// State of a running Nexus VM program. #[derive(Default)] diff --git a/vm/src/instructions.rs b/vm/src/instructions.rs index 04b5435ba..68ee41e2e 100644 --- a/vm/src/instructions.rs +++ b/vm/src/instructions.rs @@ -13,8 +13,8 @@ //! The opcode specifies the instruction; the availabe opcodes are contained //! in the `Opcode` enumeration. -use num_traits::FromPrimitive; use num_derive::FromPrimitive; +use num_traits::FromPrimitive; /// Instruction opcodes for the Nexus VM. #[repr(u8)] diff --git a/vm/src/lib.rs b/vm/src/lib.rs index 06e75d338..b73809eac 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -4,12 +4,12 @@ #![allow(clippy::field_reassign_with_default)] pub mod error; -pub mod instructions; -mod memory; pub mod eval; +pub mod instructions; +pub mod riscv; pub mod trace; mod ark_serde; -pub mod riscv; +mod memory; pub mod circuit; diff --git a/vm/src/memory/cacheline.rs b/vm/src/memory/cacheline.rs index 97508f6b7..08ad6340e 100644 --- a/vm/src/memory/cacheline.rs +++ b/vm/src/memory/cacheline.rs @@ -1,6 +1,6 @@ //! Memory cache lines -use std::fmt::{Debug, Formatter, Error}; +use std::fmt::{Debug, Error, Formatter}; use ark_bn254::Fr as F; use ark_ff::PrimeField; diff --git a/vm/src/memory/path.rs b/vm/src/memory/path.rs index 289f06183..9d02c1513 100644 --- a/vm/src/memory/path.rs +++ b/vm/src/memory/path.rs @@ -5,15 +5,15 @@ // https://github.com/arkworks-rs/crypto-primitives use ark_crypto_primitives::{ - sponge::poseidon::{PoseidonConfig, find_poseidon_ark_and_mds}, - crh::{TwoToOneCRHScheme, CRHScheme, poseidon, TwoToOneCRHSchemeGadget, CRHSchemeGadget}, + crh::{poseidon, CRHScheme, CRHSchemeGadget, TwoToOneCRHScheme, TwoToOneCRHSchemeGadget}, + sponge::poseidon::{find_poseidon_ark_and_mds, PoseidonConfig}, }; -use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; use ark_r1cs_std::{alloc::AllocVar, boolean::Boolean, fields::fp::FpVar, prelude::*}; +use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; -use crate::error::NexusVMError; use super::cacheline::*; +use crate::error::NexusVMError; use NexusVMError::HashError; pub type F = ark_bn254::Fr; diff --git a/vm/src/memory/trie.rs b/vm/src/memory/trie.rs index f26cb751e..adde3ad25 100644 --- a/vm/src/memory/trie.rs +++ b/vm/src/memory/trie.rs @@ -1,9 +1,9 @@ //! A sparse trie of `CacheLine` structures which hold the memory of the //! machine. -use crate::error::*; use super::cacheline::*; use super::path::*; +use crate::error::*; /// A sparse Trie of `CacheLines` with merkle hashing. pub struct MerkleTrie { @@ -215,9 +215,7 @@ impl MerkleTrie { if self.root.is_none() { self.root = Some(Box::new(Node::new_node())); } - let Some(ref mut b) = self.root else { - unreachable!() - }; + let Some(ref mut b) = self.root else { unreachable!() }; // Note: root is never accessed through self in update_, // so we can safely make the following optimization @@ -261,8 +259,8 @@ impl MerkleTrie { #[cfg(test)] mod test { - use super::*; use super::super::path::test::*; + use super::*; #[test] #[should_panic] diff --git a/vm/src/riscv.rs b/vm/src/riscv.rs index 88aa5fa9b..396ebb7b5 100644 --- a/vm/src/riscv.rs +++ b/vm/src/riscv.rs @@ -1,27 +1,29 @@ //! Translation of RISC-V ro NexusVM. -use std::path::Path; -use std::fs::read; use num_traits::FromPrimitive; +use std::fs::read; +use std::path::Path; use elf::{ - abi::{PT_LOAD, PF_X}, + abi::{PF_X, PT_LOAD}, endian::LittleEndian, segment::ProgramHeader, ElfBytes, }; +pub use nexus_riscv::VMOpts; use nexus_riscv::{ - nop_vm, loop_vm, VMError, + loop_vm, machines::lookup_test_machine, + nop_vm, + rv32::{parse::parse_inst, Inst as RVInst, RV32}, vm::eval::VM, - rv32::{RV32, Inst as RVInst, parse::parse_inst}, + VMError, }; -pub use nexus_riscv::VMOpts; -use crate::error::{Result, NexusVMError::ELFFormat}; -use crate::instructions::{Inst, Opcode, Opcode::*, Width::BU}; +use crate::error::{NexusVMError::ELFFormat, Result}; use crate::eval::NexusVM; +use crate::instructions::{Inst, Opcode, Opcode::*, Width::BU}; #[inline] fn add32(a: u32, b: u32) -> u32 { @@ -228,8 +230,8 @@ pub fn load_nvm(opts: &VMOpts) -> Result { pub mod test { use super::*; use crate::eval::eval; - use nexus_riscv::rv32::{BOP, LOP, SOP, AOP}; use nexus_riscv::machines::MACHINES; + use nexus_riscv::rv32::{AOP, BOP, LOP, SOP}; // this function is used by other test crates pub fn test_machines() -> Vec<(&'static str, NexusVM)> { diff --git a/vm/src/trace.rs b/vm/src/trace.rs index ac80c6189..7f8cde511 100644 --- a/vm/src/trace.rs +++ b/vm/src/trace.rs @@ -16,14 +16,14 @@ use num_traits::FromPrimitive; use crate::error::Result; +use crate::eval::{eval_step, NexusVM}; use crate::instructions::{Inst, Opcode::HALT}; -use crate::eval::{NexusVM, eval_step}; use crate::memory::path::Path; use ark_bn254::Fr as F; -use serde::{Serialize, Deserialize}; -use ark_serialize::{CanonicalSerialize, CanonicalDeserialize}; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; +use serde::{Deserialize, Serialize}; /// Represents a program trace. #[derive(Default, Clone, Serialize, Deserialize, CanonicalSerialize, CanonicalDeserialize)]