Skip to content

Commit

Permalink
workspace tweaks (nexus-xyz#67)
Browse files Browse the repository at this point in the history
* rename supernova -> nexus-nova

* rename entry -> main

* single rustfmt file

* document factorial example
  • Loading branch information
slumber authored Feb 16, 2024
1 parent 7c69c82 commit 34ec8f3
Show file tree
Hide file tree
Showing 112 changed files with 252 additions and 393 deletions.
8 changes: 6 additions & 2 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -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
62 changes: 31 additions & 31 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ members = [
"config/serde_wrapper",
"prover",
"network",
"supernova",
"nova",
"spartan",
]
default-members = [
Expand All @@ -20,10 +20,10 @@ default-members = [
"tools",
"prover",
"network",
"supernova",
"nova",
"spartan",
]
exclude = ["supernova-benches"]
exclude = ["nova-benches"]

[workspace.package]
edition = "2021"
Expand Down
Empty file removed config/.rustfmt.toml
Empty file.
4 changes: 2 additions & 2 deletions config/bases/rust.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 7 additions & 4 deletions examples/src/bin/fact.rs
Original file line number Diff line number Diff line change
@@ -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))
}
4 changes: 1 addition & 3 deletions examples/src/bin/fail.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#![no_std]
#![no_main]

use nexus_rt::entry;

#[entry]
#[nexus_rt::main]
fn main() {
panic!();
}
4 changes: 2 additions & 2 deletions examples/src/bin/fib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_std]
#![no_main]

use nexus_rt::*;
use nexus_rt::{println, Write};

fn fib(n: u32) -> u32 {
match n {
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions examples/src/bin/fib1000.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_std]
#![no_main]

use nexus_rt::*;
use nexus_rt::{println, Write};

use core::ops::Add;

Expand Down Expand Up @@ -44,7 +44,7 @@ fn fib_iter(n: u32) -> BN {
b
}

#[entry]
#[nexus_rt::main]
fn main() {
let b = fib_iter(1000);

Expand Down
7 changes: 3 additions & 4 deletions examples/src/bin/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions examples/src/main.rs
Original file line number Diff line number Diff line change
@@ -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");
}
2 changes: 1 addition & 1 deletion network/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub enum NexusAPI {
Expand Down
4 changes: 2 additions & 2 deletions network/src/bin.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion network/src/bin/client.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion network/src/bin/pcdnode/db.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::sync::{Arc, Mutex};
use std::collections::HashMap;
use std::sync::{Arc, Mutex};

use nexus_network::api::Proof;

Expand Down
8 changes: 4 additions & 4 deletions network/src/bin/pcdnode/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response<Body>> {
Ok(Response::builder()
Expand Down
20 changes: 6 additions & 14 deletions network/src/bin/pcdnode/post.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions network/src/bin/pcdnode/workers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions network/src/client.rs
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
6 changes: 3 additions & 3 deletions network/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<dyn std::error::Error + Send + Sync>;
pub type Result<T> = std::result::Result<T, DynError>;
Expand Down
Loading

0 comments on commit 34ec8f3

Please sign in to comment.