Skip to content

Commit

Permalink
Merge 4a77890 into 00f8d03
Browse files Browse the repository at this point in the history
  • Loading branch information
seemenkina authored Jan 30, 2025
2 parents 00f8d03 + 4a77890 commit 3dd5515
Show file tree
Hide file tree
Showing 8 changed files with 3,086 additions and 1,010 deletions.
3,977 changes: 3,013 additions & 964 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ ifeq ($(shell uname),Darwin)
# commented due to https://github.com/orgs/Homebrew/discussions/4612
# @brew update
@brew install cmake ninja
@git -C "wabt" pull || git clone --recursive https://github.com/WebAssembly/wabt.git "wabt"
@cd wabt && mkdir -p build && make
else ifeq ($(shell uname),Linux)
@sudo apt-get update
@sudo apt-get install -y cmake ninja-build
endif
@git -C "wabt" pull || git clone --recursive https://github.com/WebAssembly/wabt.git "wabt"
@cd wabt && mkdir -p build && cd build && cmake .. -GNinja && ninja && sudo ninja install
endif
@which wasm-pack || cargo install wasm-pack
# nvm already checks if it's installed, and no-ops if it is
@curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Expand Down
10 changes: 5 additions & 5 deletions rln-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ edition = "2021"

[dependencies]
rln = { path = "../rln", default-features = true, features = ["arkzkey"] }
clap = { version = "4.2.7", features = ["cargo", "derive", "env"]}
clap_derive = { version = "=4.2.0" }
color-eyre = "=0.6.2"
clap = { version = "4.5.0", features = ["cargo", "derive", "env"]}
clap_derive = { version = "4.5.0" }
color-eyre = "0.6.2"
# serialization
serde_json = "1.0.48"
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }

[features]
arkzkey = []
4 changes: 2 additions & 2 deletions rln-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ num-bigint = { version = "0.4", default-features = false, features = [
"rand",
"serde",
] }
wasmer = { version = "2.3", default-features = false, features = ["js", "std"] }
wasmer = { version = "4.4.0", default-features = false, features = ["js", "std"] }
web-sys = { version = "0.3", features = ["console"] }
getrandom = { version = "0.2.7", default-features = false, features = ["js"] }
wasm-bindgen = "0.2.63"
serde-wasm-bindgen = "0.4"
js-sys = "0.3.59"
serde_json = "1.0.85"
serde_json = "1.0"

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
Expand Down
49 changes: 26 additions & 23 deletions rln/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ doctest = false

[dependencies]
# ZKP Generation
ark-ec = { version = "=0.4.1", default-features = false }
ark-ff = { version = "=0.4.1", default-features = false, features = ["asm"] }
ark-ec = { version = "=0.4.2", default-features = false }
ark-ff = { version = "=0.4.2", default-features = false, features = ["asm"] }
ark-std = { version = "=0.4.0", default-features = false }
ark-bn254 = { version = "=0.4.0" }
ark-groth16 = { version = "=0.4.0", features = [
Expand All @@ -28,39 +28,42 @@ ark-groth16 = { version = "=0.4.0", features = [
ark-relations = { version = "=0.4.0", default-features = false, features = [
"std",
] }
ark-serialize = { version = "=0.4.1", default-features = false }
ark-circom = { version = "=0.1.0", default-features = false, features = [
"circom-2",
] }
ark-zkey = { version = "0.1.0", optional = true, default-features = false }
ark-serialize = { version = "=0.4.2", default-features = false }
# v0.5.0 use all other ark 0.5.0 versions and they are not compatible with current code
ark-circom = { git = "https://github.com/gakonst/ark-circom.git" }

# WASM
wasmer = { version = "=2.3.0", default-features = false }
wasmer = { version = "4.4.0", default-features = false }

# error handling
color-eyre = "=0.6.2"
thiserror = "=1.0.39"
color-eyre = "0.6.2"
thiserror = "2.0.11"

# utilities
byteorder = "1.4.3"
cfg-if = "=1.0"
num-bigint = { version = "=0.4.3", default-features = false, features = [
cfg-if = "1.0"
num-bigint = { version = "0.4.3", default-features = false, features = [
"rand",
] }
num-traits = "0.2.19"
once_cell = "1.19.0"
lazy_static = "1.4.0"
rand = "0.8.5"
rand_chacha = "0.3.1"
ruint = { version = "1.10.0", features = [
"rand",
"serde",
"ark-ff-04",
"num-bigint",
] }
num-traits = "=0.2.15"
once_cell = "=1.17.1"
lazy_static = "=1.4.0"
rand = "=0.8.5"
rand_chacha = "=0.3.1"
ruint = { version = "1.10.0", features = ["rand", "serde", "ark-ff-04", "num-bigint"] }
tiny-keccak = { version = "=2.0.2", features = ["keccak"] }
utils = { package = "zerokit_utils", version = "=0.5.1", path = "../utils/", default-features = false }
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
utils = { package = "zerokit_utils", path = "../utils/", default-features = false }


# serialization
prost = "0.13.1"
serde_json = "=1.0.96"
serde = { version = "=1.0.163", features = ["derive"] }
serde_json = "1.0.138"
serde = { version = "1.0.217", features = ["derive"] }

document-features = { version = "=0.2.10", optional = true }

Expand All @@ -79,7 +82,7 @@ parallel = [
]
wasm = ["wasmer/js", "wasmer/std"]
fullmerkletree = ["default"]
arkzkey = ["ark-zkey"]
arkzkey = []
stateless = []

# Note: pmtree feature is still experimental
Expand Down
34 changes: 28 additions & 6 deletions rln/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ use num_bigint::BigInt;
use ::lazy_static::lazy_static;

#[cfg(feature = "arkzkey")]
use {
ark_zkey::{read_arkzkey_from_bytes, SerializableConstraintMatrices, SerializableProvingKey},
color_eyre::eyre::WrapErr,
};
use {ark_ff::Field, ark_serialize::CanonicalSerialize, color_eyre::eyre::WrapErr};

#[cfg(not(feature = "arkzkey"))]
use {ark_circom::read_zkey, std::io::Cursor};
Expand Down Expand Up @@ -73,7 +70,7 @@ pub fn zkey_from_raw(zkey_data: &[u8]) -> Result<(ProvingKey<Curve>, ConstraintM

let proving_key_and_matrices = match () {
#[cfg(feature = "arkzkey")]
() => read_arkzkey_from_bytes(zkey_data)?,
() => read_arkzkey_from_bytes_uncompressed(zkey_data)?,
#[cfg(not(feature = "arkzkey"))]
() => {
let mut reader = Cursor::new(zkey_data);
Expand Down Expand Up @@ -133,9 +130,34 @@ pub fn check_vk_from_zkey(verifying_key: VerifyingKey<Curve>) -> Result<()> {
}

////////////////////////////////////////////////////////
// Functions from [arkz-key](https://github.com/zkmopro/ark-zkey/blob/main/src/lib.rs#L106)
// Functions and structs from [arkz-key](https://github.com/zkmopro/ark-zkey/blob/main/src/lib.rs#L106)
// without print and allow to choose between compressed and uncompressed arkzkey
////////////////////////////////////////////////////////

#[cfg(feature = "arkzkey")]
#[derive(CanonicalSerialize, CanonicalDeserialize, Clone, Debug, PartialEq)]
pub struct SerializableProvingKey(pub ProvingKey<Bn254>);

#[cfg(feature = "arkzkey")]
#[derive(CanonicalSerialize, CanonicalDeserialize, Clone, Debug, PartialEq)]
pub struct SerializableConstraintMatrices<F: Field> {
pub num_instance_variables: usize,
pub num_witness_variables: usize,
pub num_constraints: usize,
pub a_num_non_zero: usize,
pub b_num_non_zero: usize,
pub c_num_non_zero: usize,
pub a: SerializableMatrix<F>,
pub b: SerializableMatrix<F>,
pub c: SerializableMatrix<F>,
}

#[cfg(feature = "arkzkey")]
#[derive(CanonicalSerialize, CanonicalDeserialize, Clone, Debug, PartialEq)]
pub struct SerializableMatrix<F: Field> {
pub data: Vec<Vec<(F, usize)>>,
}

#[cfg(feature = "arkzkey")]
pub fn read_arkzkey_from_bytes_uncompressed(
arkzkey_data: &[u8],
Expand Down
2 changes: 1 addition & 1 deletion rln/tests/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ mod test {
let root_rln_folder = get_tree_root(rln_pointer);

#[cfg(feature = "arkzkey")]
let zkey_path = "./resources/tree_height_20/rln_final.arkzkey";
let zkey_path = "./resources/tree_height_20/rln_final_uncompr.arkzkey";
#[cfg(not(feature = "arkzkey"))]
let zkey_path = "./resources/tree_height_20/rln_final.zkey";
let mut zkey_file = File::open(&zkey_path).expect("no file found");
Expand Down
16 changes: 8 additions & 8 deletions utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ repository = "https://github.com/vacp2p/zerokit"
bench = false

[dependencies]
ark-ff = { version = "=0.4.1", default-features = false, features = ["asm"] }
num-bigint = { version = "=0.4.3", default-features = false, features = [
ark-ff = { version = "=0.4.2", default-features = false, features = ["asm"] }
num-bigint = { version = "0.4.3", default-features = false, features = [
"rand",
] }
color-eyre = "=0.6.2"
color-eyre = "0.6.2"
pmtree = { package = "vacp2p_pmtree", version = "=2.0.2", optional = true }
sled = "=0.34.7"
serde = "=1.0.163"
serde = "1.0"
lazy_static = "1.4.0"
hex = "0.4"

[dev-dependencies]
ark-bn254 = "=0.4.0"
num-traits = "=0.2.15"
hex-literal = "=0.3.4"
tiny-keccak = { version = "=2.0.2", features = ["keccak"] }
criterion = { version = "=0.4.0", features = ["html_reports"] }
num-traits = "0.2.19"
hex-literal = "0.3.4"
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
criterion = { version = "0.4.0", features = ["html_reports"] }

[features]
default = ["parallel"]
Expand Down

0 comments on commit 3dd5515

Please sign in to comment.