Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 0 additions & 1 deletion Cargo.lock

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

15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ark-bls12-381 = "0.5" # bls12-381 curve for r1cs backend
ark-relations = "0.5"
ark-bn254 = "0.5" # bn128 curve for r1cs backend
ark-serialize = "0.5" # serialization of arkworks types
axum = { version = "0.7.7", features = ["macros"] } # web server
axum = { version = "0.7.7", features = ["macros"], optional = true } # web server
base64 = "0.22.1" # for base64 encoding
educe = { version = "0.6", default-features = false, features = [
"Hash",
Expand All @@ -32,7 +32,7 @@ camino = "1.1.1" # to replace Path and PathBuf
clap = { version = "4.0.5", features = ["derive"] } # CLI library
dirs = "4.0.0" # helper functions (e.g. getting the home directory)
itertools = "0.10.3" # useful iter traits
kimchi = { git = "https://github.com/o1-labs/proof-systems", rev = "c1803e0a480172c193ba67c826110980303a172f" } # ZKP
kimchi = { git = "https://github.com/o1-labs/proof-systems", rev = "c1803e0a480172c193ba67c826110980303a172f", optional = true } # ZKP
miette = { version = "5.0.0", features = ["fancy"] } # nice errors
num-traits = "0.2.15" # useful traits on big ints
once_cell = "1.15.0" # for lazy statics
Expand All @@ -51,7 +51,12 @@ rug = "1.26.1"
circ = { git = "https://github.com/circify/circ", rev = "8140b1369edd5992ede038d2e9e5721510ae7065" } # for compiling to circ IR
circ_fields = { git = "https://github.com/circify/circ", rev = "8140b1369edd5992ede038d2e9e5721510ae7065", subdir = "circ_fields" } # for field types supported by circ
fxhash = "0.2.1" # hash algorithm used by circ
tokio = { version = "1.41.0", features = ["full"] }
tower = "0.5.1"
tower-http = { version = "0.6.1", features = ["trace", "fs"] }
tokio = { version = "1.41.0", features = ["sync", "rt"] }
tower-http = { version = "0.6.1", features = ["trace", "fs"], optional = true }
tracing-subscriber = "0.3.18"

[features]
default = ["cli"]
cli = ["kimchi", "server"]
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to have a cli feature? Maybe call this full instead?

server = ["tokio/full", "tower-http", "axum"]
kimchi = ["dep:kimchi"]
6 changes: 2 additions & 4 deletions src/backends/kimchi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ use std::{
};

use itertools::{izip, Itertools};
use kimchi::{
circuits::polynomials::generic::{GENERIC_COEFFS, GENERIC_REGISTERS},
o1_utils::FieldHelpers,
};
use kimchi::circuits::polynomials::generic::{GENERIC_COEFFS, GENERIC_REGISTERS};
use serde::{Deserialize, Serialize};

use crate::{
Expand All @@ -28,6 +25,7 @@ use crate::{
constants::Span,
error::{Error, ErrorKind, Result},
helpers::PrettyField,
utils::FieldHelpers,
var::{Value, Var},
witness::WitnessEnv,
};
Expand Down
12 changes: 7 additions & 5 deletions src/backends/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{fmt::Debug, str::FromStr};

use ::kimchi::o1_utils::FieldHelpers;
use ark_ff::{Field, One, PrimeField, Zero};
use circ::ir::term::precomp::PreComp;
use fxhash::FxHashMap;
Expand All @@ -17,15 +16,16 @@ use crate::{
utils::{log_array_or_tuple_type, log_custom_type, log_string_type},
var::{ConstOrCell, Value, Var},
witness::WitnessEnv,
utils::FieldHelpers,
};

use self::{
kimchi::KimchiVesta,
r1cs::{R1csBls12381Field, R1csBn254Field, R1CS},
};
#[cfg(feature = "kimchi")]
use self::kimchi::KimchiVesta;
use self::r1cs::{R1csBls12381Field, R1csBn254Field, R1CS};

use crate::mast::Mast;

#[cfg(feature = "kimchi")]
pub mod kimchi;
pub mod r1cs;

Expand All @@ -42,12 +42,14 @@ pub trait BackendField:
pub trait BackendVar: Clone + Debug + PartialEq + Eq {}

pub enum BackendKind {
#[cfg(feature = "kimchi")]
KimchiVesta(KimchiVesta),
R1csBls12_381(R1CS<R1csBls12381Field>),
R1csBn254(R1CS<R1csBn254Field>),
}

impl BackendKind {
#[cfg(feature = "kimchi")]
pub fn new_kimchi_vesta(use_double_generic: bool) -> Self {
Self::KimchiVesta(KimchiVesta::new(use_double_generic))
}
Expand Down
3 changes: 1 addition & 2 deletions src/backends/r1cs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::helpers::PrettyField;
use circ::cfg::{CircCfg, CircOpt};
use circ_fields::FieldV;
use itertools::{izip, Itertools as _};
use kimchi::o1_utils::FieldHelpers;
use num_bigint::BigUint;
use num_traits::One;
use rug::Integer;
Expand All @@ -20,7 +19,7 @@ use crate::mast::Mast;
use crate::parser::types::{ModulePath, TyKind};
use crate::type_checker::FullyQualified;
use crate::var::ConstOrCell;
use crate::{circuit_writer::DebugInfo, var::Value};
use crate::{circuit_writer::DebugInfo, utils::FieldHelpers, var::Value};

use super::{Backend, BackendField, BackendVar};

Expand Down
9 changes: 9 additions & 0 deletions src/bin/noname.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
use clap::Parser as _;
use miette::Result;
#[cfg(feature = "cli")]
use noname::cli::{
cmd_build, cmd_check, cmd_init, cmd_new, cmd_prove, cmd_run, cmd_test, cmd_verify, CmdBuild,
CmdCheck, CmdInit, CmdNew, CmdProve, CmdRun, CmdTest, CmdVerify,
};

#[cfg(feature = "cli")]
#[derive(clap::Parser)]
#[clap(author, version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}

#[cfg(feature = "cli")]
#[derive(clap::Subcommand)]
enum Commands {
/// Create a new noname package
Expand Down Expand Up @@ -48,6 +51,7 @@ enum Commands {
Test(CmdTest),
}

#[cfg(feature = "cli")]
fn main() -> Result<()> {
let cli = Cli::parse();

Expand All @@ -66,3 +70,8 @@ fn main() -> Result<()> {
Commands::Test(args) => cmd_test(args),
}
}

#[cfg(not(feature = "cli"))]
fn main() {
panic!("This binary requires the 'cli' feature to be enabled");
}
4 changes: 3 additions & 1 deletion src/circuit_writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use crate::{
pub use fn_env::{FnEnv, VarInfo};
use serde::{Deserialize, Serialize};
//use serde::{Deserialize, Serialize};
pub use writer::{Gate, GateKind, Wiring};
#[cfg(feature = "kimchi")]
pub use writer::Gate;
pub use writer::{GateKind, Wiring};

pub mod fn_env;
pub mod ir;
Expand Down
9 changes: 8 additions & 1 deletion src/circuit_writer/writer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use std::fmt::{self, Display, Formatter};

use ark_ff::{One, Zero};
#[cfg(feature = "kimchi")]
use kimchi::circuits::wires::Wire;
use num_bigint::BigUint;
use serde::{Deserialize, Serialize};

#[cfg(feature = "kimchi")]
use crate::backends::kimchi::VestaField;
use crate::{
backends::{kimchi::VestaField, Backend},
backends::Backend,
circuit_writer::{CircuitWriter, DebugInfo, FnEnv, VarInfo},
constants::Span,
constraints::{boolean, field},
Expand All @@ -32,6 +35,7 @@ pub enum GateKind {
Poseidon,
}

#[cfg(feature = "kimchi")]
impl From<GateKind> for kimchi::circuits::gate::GateType {
fn from(gate_kind: GateKind) -> Self {
use kimchi::circuits::gate::GateType::*;
Expand All @@ -44,6 +48,7 @@ impl From<GateKind> for kimchi::circuits::gate::GateType {
}

// TODO: this could also contain the span that defined the gate!
#[cfg(feature = "kimchi")]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Gate {
/// Type of gate
Expand All @@ -54,6 +59,7 @@ pub struct Gate {
pub coeffs: Vec<VestaField>,
}

#[cfg(feature = "kimchi")]
impl Gate {
pub fn to_kimchi_gate(&self, row: usize) -> kimchi::circuits::gate::CircuitGate<VestaField> {
kimchi::circuits::gate::CircuitGate {
Expand Down Expand Up @@ -920,6 +926,7 @@ impl<B: Backend> CircuitWriter<B> {
}
}

#[cfg(feature = "kimchi")]
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
pub(crate) struct PendingGate {
pub label: &'static str,
Expand Down
6 changes: 6 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#[cfg(feature = "cli")]
pub mod cmd_build_and_check;
#[cfg(feature = "cli")]
pub mod cmd_new_and_init;
#[cfg(feature = "cli")]
pub mod cmd_prove_and_verify;
pub mod manifest;
pub mod packages;

#[cfg(feature = "cli")]
pub use cmd_build_and_check::{
cmd_build, cmd_check, cmd_run, cmd_test, CmdBuild, CmdCheck, CmdRun, CmdTest,
};
#[cfg(feature = "cli")]
pub use cmd_new_and_init::{cmd_init, cmd_new, CmdInit, CmdNew};
#[cfg(feature = "cli")]
pub use cmd_prove_and_verify::{cmd_prove, cmd_verify, CmdProve, CmdVerify};

/// The directory under the user home directory containing all noname-related files.
Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,15 @@ pub enum ErrorKind {
#[error("array indexes must be constants in circuits")]
ExpectedConstant,

#[cfg(feature = "kimchi")]
#[error("kimchi setup: {0}")]
KimchiSetup(#[from] kimchi::error::SetupError),

#[cfg(feature = "kimchi")]
#[error("kimchi prover: {0}")]
KimchiProver(#[from] kimchi::error::ProverError),

#[cfg(feature = "kimchi")]
#[error("kimchi verifier: {0}")]
KimchiVerifier(#[from] kimchi::error::VerifyError),

Expand Down
10 changes: 6 additions & 4 deletions src/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
use std::{collections::HashMap, fs::File, io::Read, str::FromStr};

use ark_ff::{One, Zero};
use kimchi::o1_utils::FieldHelpers;
use miette::Diagnostic;
use num_bigint::BigUint;
use thiserror::Error;

#[cfg(feature = "kimchi")]
use crate::backends::kimchi::VestaField;
use crate::{
backends::{kimchi::VestaField, Backend},
parser::types::TyKind,
type_checker::FullyQualified,
backends::Backend, parser::types::TyKind, type_checker::FullyQualified,
witness::CompiledCircuit,
utils::FieldHelpers,
};

//
Expand Down Expand Up @@ -185,6 +185,7 @@ pub trait ExtField /* : PrimeField*/ {
fn to_dec_string(&self) -> String;
}

#[cfg(feature = "kimchi")]
impl ExtField for VestaField {
fn to_dec_string(&self) -> String {
let biguint: BigUint = self.to_biguint();
Expand All @@ -197,6 +198,7 @@ mod tests {
use super::*;

#[test]
#[cfg(feature = "kimchi")]
fn test_extfield() {
let field = VestaField::from(42);
assert_eq!(field.to_dec_string(), "42");
Expand Down
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ pub mod negative_tests;
//

pub mod helpers {
#[cfg(feature = "kimchi")]
use kimchi::mina_poseidon::{
constants::PlonkSpongeConstantsKimchi,
pasta::fp_kimchi,
poseidon::{ArithmeticSponge, Sponge},
};

use crate::backends::{
kimchi::VestaField,
r1cs::{R1csBls12381Field, R1csBn254Field},
};
#[cfg(feature = "kimchi")]
use crate::backends::kimchi::VestaField;
use crate::backends::r1cs::{R1csBls12381Field, R1csBn254Field};

/// A trait to display [Field] in pretty ways.
pub trait PrettyField: ark_ff::PrimeField {
Expand All @@ -60,10 +60,12 @@ pub mod helpers {
}
}

#[cfg(feature = "kimchi")]
impl PrettyField for VestaField {}
impl PrettyField for R1csBls12381Field {}
impl PrettyField for R1csBn254Field {}

#[cfg(feature = "kimchi")]
pub fn poseidon(input: [VestaField; 2]) -> VestaField {
let mut sponge: ArithmeticSponge<VestaField, PlonkSpongeConstantsKimchi> =
ArithmeticSponge::new(fp_kimchi::static_params());
Expand Down
5 changes: 4 additions & 1 deletion src/name_resolution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ impl<B: Backend> NAST<B> {

#[cfg(test)]
mod tests {
#[cfg(feature = "kimchi")]
use crate::backends::kimchi::KimchiVesta;
use crate::{
backends::kimchi::KimchiVesta,
lexer::Token,
parser::{
types::{ModulePath, StmtKind},
Expand All @@ -104,6 +105,7 @@ mod tests {
}
"#;

#[cfg(feature = "kimchi")]
#[test]
fn test_name_res() {
let tokens = Token::parse(0, CODE).unwrap();
Expand Down Expand Up @@ -149,6 +151,7 @@ mod tests {
};
}

#[cfg(feature = "kimchi")]
#[test]
fn test_name_res_for_library() {
let user_repo = UserRepo::new("mimoo/example");
Expand Down
Loading