Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
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
311 changes: 184 additions & 127 deletions Cargo.lock

Large diffs are not rendered by default.

30 changes: 18 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ fs_extra = "1.3.0"
dirs = "4.0"

[dependencies]
ark-ec = "0.4.2" # elliptic curve library
ark-ff = "0.4.2"
ark-bls12-381 = "0.4.0" # bls12-381 curve for r1cs backend
ark-relations = "0.4.0"
ark-bn254 = "0.4.0" # bn128 curve for r1cs backend
ark-serialize = "0.4.2" # serialization of arkworks types
axum = { version = "0.7.7", features = ["macros"] } # web server
ark-ec = "0.5" # elliptic curve library
ark-ff = "0.5"
ark-bls12-381 = { version = "0.5", optional = true } # bls12-381 curve for r1cs backend
ark-relations = { version = "0.5", optional = true }
ark-bn254 = { version = "0.5", optional = true } # bn128 curve for r1cs backend
ark-serialize = "0.5" # serialization of arkworks types
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 = "5b4ac1437e7912237be88d97b4b4891b22e3e61f" } # 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 @@ -43,15 +43,21 @@ serde_json = "1.0.85"
serde = "1.0.144" # to (de)serialize objects
thiserror = "1.0.31" # helpful error traits
toml = "0.8.8" # to parse manifest files
constraint_writers = { git = "https://github.com/iden3/circom.git", tag = "v2.1.8" } # to generate r1cs file
constraint_writers = { git = "https://github.com/iden3/circom.git", tag = "v2.1.8", optional = true } # to generate r1cs file
num-bigint-dig = "0.6.0" # to adapt for circom lib
rand = "0.8.5"
rstest = "0.19.0" # for testing different backend cases
rug = "1.26.1" # circ uses this for integer type
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", "r1cs", "server"]
server = ["tokio/full", "dep:tower-http", "dep:axum"]
kimchi = ["dep:kimchi"]
r1cs = ["dep:constraint_writers", "dep:ark-bls12-381", "dep:ark-bn254", "dep:ark-relations"]
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
2 changes: 1 addition & 1 deletion src/backends/kimchi/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl KimchiVesta {
let (endo_q, _endo_r) = kimchi::poly_commitment::ipa::endos::<OtherCurve>();

let prover_index = kimchi::prover_index::ProverIndex::<Curve, OpeningProof<Curve>>::create(
cs, endo_q, srs,
cs, endo_q, srs, false,
);
let verifier_index = prover_index.verifier_index();

Expand Down
19 changes: 13 additions & 6 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 @@ -14,19 +13,21 @@ use crate::{
helpers::PrettyField,
imports::FnHandle,
parser::types::TyKind,
utils::{log_array_or_tuple_type, log_custom_type, log_string_type},
utils::{log_array_or_tuple_type, log_custom_type, log_string_type, FieldHelpers},
var::{ConstOrCell, Value, Var},
witness::WitnessEnv,
};

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

use crate::mast::Mast;

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

/// This trait serves as an alias for a bundle of traits
Expand All @@ -42,20 +43,26 @@ pub trait BackendField:
pub trait BackendVar: Clone + Debug + PartialEq + Eq {}

pub enum BackendKind {
#[cfg(feature = "kimchi")]
KimchiVesta(KimchiVesta),
#[cfg(feature = "r1cs")]
R1csBls12_381(R1CS<R1csBls12381Field>),
#[cfg(feature = "r1cs")]
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))
}

#[cfg(feature = "r1cs")]
pub fn new_r1cs_bls12_381() -> Self {
Self::R1csBls12_381(R1CS::new())
}

#[cfg(feature = "r1cs")]
pub fn new_r1cs_bn254() -> Self {
Self::R1csBn254(R1CS::new())
}
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
15 changes: 10 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,25 @@ pub mod witness;
#[cfg(test)]
pub mod tests;

#[cfg(test)]
#[cfg(all(test, feature = "r1cs"))]
pub mod negative_tests;

//
// Helpers
//

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;
#[cfg(feature = "r1cs")]
use crate::backends::r1cs::{R1csBls12381Field, R1csBn254Field};

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

#[cfg(feature = "kimchi")]
impl PrettyField for VestaField {}
#[cfg(feature = "r1cs")]
impl PrettyField for R1csBls12381Field {}
#[cfg(feature = "r1cs")]
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
Loading