mirror of
https://github.com/arnaucube/sonobe.git
synced 2026-01-08 15:01:30 +01:00
Enable WASM-compat and monitor it in the CI (#142)
* fix: Use `target_pointer_size` conditional compilation There are some parts of the code where is needed to de/serialze `usize`s. These, have sizes that vary depending on the target achitecture the code is compiled for. Hence, this adapts the de/serialization to the specific pointer size for which the crate is being compiled to. * change: Support WASM-compatibility and polish Cargo.toml In order to support Wasm-compat and to simplify and improve `Cargo.toml` readability, the follwing changes have been made: - All the deps that can use `parallel` feature, do so. As `rayon` supports non-threaded targets with a fallback option. See: https://docs.rs/rayon-core/1.12.1/rayon_core/index.html#global-fallback-when-threading-is-unsupported - `ark-grumpking` has been brought to `0.5.0-alpha.0` as `0.4.0` appears to not be in `crates.io` anymore. See: https://crates.io/crates/ark-grumpkin/versions - By default, the crate uses `"ark-circom/default"` which selects the `wasmer/sys` feature such that it knows where wasmer is suposed to be run`. - Added a `wasm` feature which forces `ark-circom/wasm` to be used instead. Which internally selects the `wasmer/js` backend to be used such that in-browser execution is possible. - Added `getrandom` with `js` feature as dependency when `wasm32-unknown-unknown` target is selected such that compilation of the crate for testing or simply building is possible. Notice that with `wasi` and other wasm targets, this is not the case as they're automatically supported. For more info, please check: https://docs.rs/getrandom/latest/getrandom/#webassembly-support * feat: Support WASM-compatibility tests in CI Add support for both testing the build of `sonobe/folding-schemes` for WASM-targets and also, it's build as a dependency for a WASM-crate. This includes a build job for the three main supported rust-WASM targets and the same but for a thrid crate creted on-the-fly which uses `sonobe/folding-schemes` as a dependency. * chore: Add README docs about WASM-compat & feats * ci: don't run WASM-compat job if PR is draft * chore: depend on `arnaucube/circom-compat` fork. Since https://github.com/arnaucube/circom-compat/pull/2 was merged, we can already switch to it as we were depending before. * chore: minimal build/test instructions * fix: CI typos * fix: Update CI to use correct feature sets * fix: `ark-grumpkin` versioning issues As mentioned in https://github.com/privacy-scaling-explorations/sonobe/issues/146 there's a big issue that involves some dependencies of the crate. As a temporary fix, this forces the workspace to rely on a "non-existing" version of `ark-grumpkin` which is immediately patched at workspace-level for a custom version that @arnaucube owns with some cherry-picked commits. While this allows the CI to pass and crate to build, a better solution is needed. * fix: Clippy CI avoiding --all-targets * fix: use `wasm` feat only with folding-schemes
This commit is contained in:
@@ -4,25 +4,26 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
ark-ec = "^0.4.0"
|
||||
ark-ff = "^0.4.0"
|
||||
ark-poly = "^0.4.0"
|
||||
ark-std = "^0.4.0"
|
||||
ark-crypto-primitives = { version = "^0.4.0", default-features = false, features = ["r1cs", "sponge", "crh"] }
|
||||
ark-grumpkin = {version="0.4.0"}
|
||||
ark-poly-commit = "^0.4.0"
|
||||
ark-ec = { version = "^0.4.0", default-features = false, features = ["parallel"] }
|
||||
ark-ff = { version = "^0.4.0", default-features = false, features = ["parallel", "asm"] }
|
||||
ark-poly = { version = "^0.4.0", default-features = false, features = ["parallel"] }
|
||||
ark-std = { version = "^0.4.0", default-features = false, features = ["parallel"] }
|
||||
ark-crypto-primitives = { version = "^0.4.0", default-features = false, features = ["r1cs", "sponge", "crh", "parallel"] }
|
||||
ark-grumpkin = { version = "0.4.0", default-features = false }
|
||||
ark-poly-commit = { version = "^0.4.0", default-features = false, features = ["parallel"] }
|
||||
ark-relations = { version = "^0.4.0", default-features = false }
|
||||
ark-r1cs-std = { version = "0.4.0", default-features = false } # this is patched at the workspace level
|
||||
ark-snark = { version = "^0.4.0"}
|
||||
ark-serialize = "^0.4.0"
|
||||
ark-circom = { git = "https://github.com/arnaucube/circom-compat" }
|
||||
# this is patched at the workspace level
|
||||
ark-r1cs-std = { version = "0.4.0", default-features = false, features = ["parallel"] }
|
||||
ark-snark = { version = "^0.4.0", default-features = false }
|
||||
ark-serialize = { version = "^0.4.0", default-features = false }
|
||||
ark-circom = { git = "https://github.com/arnaucube/circom-compat", default-features = false }
|
||||
ark-groth16 = { version = "^0.4.0", default-features = false, features = ["parallel"]}
|
||||
ark-bn254 = { version = "^0.4.0", default-features = false }
|
||||
thiserror = "1.0"
|
||||
rayon = "1.7.0"
|
||||
rayon = "1"
|
||||
num-bigint = "0.4"
|
||||
num-integer = "0.1"
|
||||
color-eyre = "=0.6.2"
|
||||
ark-bn254 = {version="0.4.0"}
|
||||
ark-groth16 = { version = "^0.4.0" }
|
||||
sha3 = "0.10"
|
||||
ark-noname = { git = "https://github.com/dmpierre/ark-noname", branch="feat/sonobe-integration" }
|
||||
noname = { git = "https://github.com/dmpierre/noname" }
|
||||
@@ -44,18 +45,16 @@ rand = "0.8.5"
|
||||
tracing = { version = "0.1", default-features = false, features = [ "attributes" ] }
|
||||
tracing-subscriber = { version = "0.2" }
|
||||
|
||||
[features]
|
||||
default = ["parallel"]
|
||||
light-test = []
|
||||
# This allows the crate to be built when targeting WASM.
|
||||
# See more at: https://docs.rs/getrandom/#webassembly-support
|
||||
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
|
||||
getrandom = { version = "0.2", features = ["js"] }
|
||||
|
||||
parallel = [
|
||||
"ark-std/parallel",
|
||||
"ark-ff/parallel",
|
||||
"ark-ec/parallel",
|
||||
"ark-poly/parallel",
|
||||
"ark-crypto-primitives/parallel",
|
||||
"ark-r1cs-std/parallel",
|
||||
]
|
||||
[features]
|
||||
default = ["ark-circom/default", "parallel"]
|
||||
parallel = []
|
||||
wasm = ["ark-circom/wasm"]
|
||||
light-test = []
|
||||
|
||||
|
||||
[[example]]
|
||||
|
||||
@@ -593,9 +593,21 @@ where
|
||||
return Err(Error::MaxStep);
|
||||
}
|
||||
|
||||
let mut i_bytes: [u8; 8] = [0; 8];
|
||||
i_bytes.copy_from_slice(&self.i.into_bigint().to_bytes_le()[..8]);
|
||||
let i_usize: usize = usize::from_le_bytes(i_bytes);
|
||||
let i_usize;
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
{
|
||||
let mut i_bytes: [u8; 8] = [0; 8];
|
||||
i_bytes.copy_from_slice(&self.i.into_bigint().to_bytes_le()[..8]);
|
||||
i_usize = usize::from_le_bytes(i_bytes);
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
{
|
||||
let mut i_bytes: [u8; 4] = [0; 4];
|
||||
i_bytes.copy_from_slice(&self.i.into_bigint().to_bytes_le()[..4]);
|
||||
i_usize = usize::from_le_bytes(i_bytes);
|
||||
}
|
||||
|
||||
let z_i1 = self
|
||||
.F
|
||||
|
||||
@@ -201,7 +201,7 @@ where
|
||||
let (cmW_x, cmW_y) = NonNativeAffineVar::inputize(U.cmW)?;
|
||||
let (cmT_x, cmT_y) = NonNativeAffineVar::inputize(proof.cmT)?;
|
||||
|
||||
let public_input: Vec<C1::ScalarField> = vec![
|
||||
let public_input: Vec<C1::ScalarField> = [
|
||||
vec![pp_hash, i],
|
||||
z_0,
|
||||
z_i,
|
||||
|
||||
@@ -502,9 +502,22 @@ where
|
||||
if self.i > C1::ScalarField::from_le_bytes_mod_order(&usize::MAX.to_le_bytes()) {
|
||||
return Err(Error::MaxStep);
|
||||
}
|
||||
let mut i_bytes: [u8; 8] = [0; 8];
|
||||
i_bytes.copy_from_slice(&self.i.into_bigint().to_bytes_le()[..8]);
|
||||
let i_usize: usize = usize::from_le_bytes(i_bytes);
|
||||
|
||||
let i_usize;
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
{
|
||||
let mut i_bytes: [u8; 8] = [0; 8];
|
||||
i_bytes.copy_from_slice(&self.i.into_bigint().to_bytes_le()[..8]);
|
||||
i_usize = usize::from_le_bytes(i_bytes);
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
{
|
||||
let mut i_bytes: [u8; 4] = [0; 4];
|
||||
i_bytes.copy_from_slice(&self.i.into_bigint().to_bytes_le()[..4]);
|
||||
i_usize = usize::from_le_bytes(i_bytes);
|
||||
}
|
||||
|
||||
let z_i1 = self
|
||||
.F
|
||||
|
||||
Reference in New Issue
Block a user