diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e694aaae..230795ee 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,5 +1,9 @@ name: Build and Test Spartan +permissions: + contents: read + pull-requests: write + on: push: branches: [ master ] @@ -10,39 +14,112 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Install - run: rustup default stable - - name: Install rustfmt Components - run: rustup component add rustfmt - - name: Install clippy - run: rustup component add clippy - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose - - name: Build examples - run: cargo build --examples --verbose - - name: Check Rustfmt Code Style - run: cargo fmt --all -- --check - - name: Check clippy warnings - run: cargo clippy --all-targets --all-features -- -D warnings - - build_wasm: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install - run: rustup default stable - - name: Build without std - run: cargo build --no-default-features --verbose - - name: Run tests without std - run: cargo test --no-default-features --verbose - - name: Build examples without std - run: cargo build --examples --no-default-features --verbose - - name: Install wasm32-wasi target - run: rustup target add wasm32-wasi - - name: Install wasm32-unknown-unknown target - run: rustup target add wasm32-unknown-unknown - - name: Build for target wasm-wasi - run: RUSTFLAGS="" cargo build --target=wasm32-wasi --no-default-features --verbose + - uses: actions/checkout@v2 + - name: Build + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - uses: actions-rs/cargo@v1 + with: + command: build + args: --examples --benches --verbose + + build-no-default-features: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - uses: actions-rs/cargo@v1 + with: + command: build + args: --no-default-features --examples --benches --verbose + + build-wasm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Wasm build + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: wasm32-unknown-unknown + - uses: actions-rs/cargo@v1 + with: + command: build + args: --no-default-features --target wasm32-unknown-unknown + + build-wasi: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install wasm32-wasip1 target + run: rustup target add wasm32-wasip1 + - uses: actions-rs/cargo@v1 + with: + command: build + args: --no-default-features --target wasm32-wasip1 + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run tests + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - uses: actions-rs/cargo@v1 + with: + command: test + args: --release --verbose + + test-no-default-features: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run tests + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - uses: actions-rs/cargo@v1 + with: + command: test + args: --no-default-features --release --verbose + + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Check Rustfmt Code Style + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Check clippy warnings + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: clippy + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-targets -- -D warnings + + spelling: + runs-on: ubuntu-latest + steps: + - name: Checkout Actions Repository + uses: actions/checkout@v3 + - name: Spell Check Repo + uses: crate-ci/typos@685eb3d55be2f85191e8c84acb9f44d7756f84ab diff --git a/Cargo.toml b/Cargo.toml index e2dabb33..49c3b4d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,8 +17,8 @@ curve25519-dalek = { version = "4.1.1", features = [ "rand_core", ], default-features = false } merlin = { version = "3.0.0", default-features = false } -rand = "0.8" -rand_core = { version = "0.6", default-features = false, features = ["getrandom"] } +rand = "0.8.5" +rand_core = { version = "0.6", default-features = false } digest = { version = "0.8.1", default-features = false } sha3 = { version = "0.8.2", default-features = false } byteorder = { version = "1.3.4", default-features = false } @@ -30,8 +30,12 @@ itertools = { version = "0.10.0", default-features = false } colored = { version = "2.0.0", default-features = false, optional = true } flate2 = { version = "1.0.14" } +[target.'cfg(target_arch = "wasm32")'.dependencies] +getrandom = { version = "0.2.15", default-features = false, features = ["js"] } + [dev-dependencies] criterion = "0.3.1" +typos = "0.10.33" [lib] name = "libspartan" diff --git a/src/lib.rs b/src/lib.rs index 7341fc8a..7425ecdf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,6 @@ extern crate core; extern crate curve25519_dalek; extern crate digest; extern crate merlin; -extern crate rand; extern crate sha3; #[cfg(feature = "multicore")] diff --git a/src/product_tree.rs b/src/product_tree.rs index 3be6bde5..f65fd057 100644 --- a/src/product_tree.rs +++ b/src/product_tree.rs @@ -272,7 +272,7 @@ impl ProductCircuitEvalProofBatched { .collect::>(); let mut rand = Vec::new(); for layer_id in (0..num_layers).rev() { - // prepare paralell instance that share poly_C first + // prepare parallel instance that share poly_C first let len = prod_circuit_vec[0].left_vec[layer_id].len() + prod_circuit_vec[0].right_vec[layer_id].len(); diff --git a/src/r1csproof.rs b/src/r1csproof.rs index 1b3fe2e4..73c2abd2 100644 --- a/src/r1csproof.rs +++ b/src/r1csproof.rs @@ -263,9 +263,9 @@ impl R1CSProof { let timer_sc_proof_phase2 = Timer::new("prove_sc_phase_two"); // combine the three claims into a single claim - let r_A = transcript.challenge_scalar(b"challenege_Az"); - let r_B = transcript.challenge_scalar(b"challenege_Bz"); - let r_C = transcript.challenge_scalar(b"challenege_Cz"); + let r_A = transcript.challenge_scalar(b"challenge_Az"); + let r_B = transcript.challenge_scalar(b"challenge_Bz"); + let r_C = transcript.challenge_scalar(b"challenge_Cz"); let claim_phase2 = r_A * Az_claim + r_B * Bz_claim + r_C * Cz_claim; let blind_claim_phase2 = r_A * Az_blind + r_B * Bz_blind + r_C * Cz_blind; @@ -418,9 +418,9 @@ impl R1CSProof { )?; // derive three public challenges and then derive a joint claim - let r_A = transcript.challenge_scalar(b"challenege_Az"); - let r_B = transcript.challenge_scalar(b"challenege_Bz"); - let r_C = transcript.challenge_scalar(b"challenege_Cz"); + let r_A = transcript.challenge_scalar(b"challenge_Az"); + let r_B = transcript.challenge_scalar(b"challenge_Bz"); + let r_C = transcript.challenge_scalar(b"challenge_Cz"); // r_A * comm_Az_claim + r_B * comm_Bz_claim + r_C * comm_Cz_claim; let comm_claim_phase2 = GroupElement::vartime_multiscalar_mul( diff --git a/src/scalar/ristretto255.rs b/src/scalar/ristretto255.rs index b678d5ae..ee4a7525 100755 --- a/src/scalar/ristretto255.rs +++ b/src/scalar/ristretto255.rs @@ -454,7 +454,7 @@ impl Scalar { // // and computing their sum in the field. It remains to see that arbitrary 256-bit // numbers can be placed into Montgomery form safely using the reduction. The - // reduction works so long as the product is less than R=2^256 multipled by + // reduction works so long as the product is less than R=2^256 multiplied by // the modulus. This holds because for any `c` smaller than the modulus, we have // that (2^256 - 1)*c is an acceptable product for the reduction. Therefore, the // reduction always works so long as `c` is in the field; in this case it is either the diff --git a/src/sparse_mlpoly.rs b/src/sparse_mlpoly.rs index d7bdc9cb..02b66b6d 100644 --- a/src/sparse_mlpoly.rs +++ b/src/sparse_mlpoly.rs @@ -122,7 +122,7 @@ impl DerefsEvalProof { proof_derefs } - // evalues both polynomials at r and produces a joint proof of opening + // evaluates both polynomials at r and produces a joint proof of opening pub fn prove( derefs: &Derefs, eval_row_ops_val_vec: &[Scalar], diff --git a/src/sumcheck.rs b/src/sumcheck.rs index a077c109..ace1fefc 100644 --- a/src/sumcheck.rs +++ b/src/sumcheck.rs @@ -236,7 +236,7 @@ impl SumcheckInstanceProof { //derive the verifier's challenge for the next round let r_j = transcript.challenge_scalar(b"challenge_nextround"); r.push(r_j); - // bound all tables to the verifier's challenege + // bound all tables to the verifier's challenge poly_A.bound_poly_var_top(&r_j); poly_B.bound_poly_var_top(&r_j); poly_C.bound_poly_var_top(&r_j); @@ -375,7 +375,7 @@ impl SumcheckInstanceProof { let r_j = transcript.challenge_scalar(b"challenge_nextround"); r.push(r_j); - // bound all tables to the verifier's challenege + // bound all tables to the verifier's challenge for (poly_A, poly_B) in poly_A_vec_par.iter_mut().zip(poly_B_vec_par.iter_mut()) { poly_A.bound_poly_var_top(&r_j); poly_B.bound_poly_var_top(&r_j); @@ -481,7 +481,7 @@ impl ZKSumcheckInstanceProof { //derive the verifier's challenge for the next round let r_j = transcript.challenge_scalar(b"challenge_nextround"); - // bound all tables to the verifier's challenege + // bound all tables to the verifier's challenge poly_A.bound_poly_var_top(&r_j); poly_B.bound_poly_var_top(&r_j); @@ -669,7 +669,7 @@ impl ZKSumcheckInstanceProof { //derive the verifier's challenge for the next round let r_j = transcript.challenge_scalar(b"challenge_nextround"); - // bound all tables to the verifier's challenege + // bound all tables to the verifier's challenge poly_A.bound_poly_var_top(&r_j); poly_B.bound_poly_var_top(&r_j); poly_C.bound_poly_var_top(&r_j);