From 16efe9fd76eab9de15eb80ca4acd208654acd7da Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Wed, 29 Jan 2025 11:00:47 -0800 Subject: [PATCH 01/10] introduce spell check in CI --- .github/workflows/rust.yml | 112 +++++++++++++++++++++++++------------ 1 file changed, 76 insertions(+), 36 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e694aaae..bcf3d920 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,48 +1,88 @@ name: Build and Test Spartan +permissions: + contents: read + pull-requests: write + on: push: - branches: [ master ] + branches: [ main ] pull_request: - branches: [ master ] + branches: [ main ] 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: + - 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-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 + + 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 + + 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: - - 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 + - name: Checkout Actions Repository + uses: actions/checkout@v3 + - name: Spell Check Repo + uses: crate-ci/typos@685eb3d55be2f85191e8c84acb9f44d7756f84ab From 3d61e6868625d5cf82739f39d257c9957706092e Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Wed, 29 Jan 2025 11:02:58 -0800 Subject: [PATCH 02/10] fix typos automatically --- Cargo.toml | 1 + src/product_tree.rs | 2 +- src/r1csproof.rs | 12 ++++++------ src/scalar/ristretto255.rs | 2 +- src/sparse_mlpoly.rs | 2 +- src/sumcheck.rs | 8 ++++---- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e2dabb33..7f7b3372 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ subtle = { version = "2.4", features = ["i128"], default-features = false } itertools = { version = "0.10.0", default-features = false } colored = { version = "2.0.0", default-features = false, optional = true } flate2 = { version = "1.0.14" } +typos = "0.10.33" [dev-dependencies] criterion = "0.3.1" 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); From 2b7447c04556c1362cfbd91a31c201e37b88f0f9 Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Wed, 29 Jan 2025 11:04:08 -0800 Subject: [PATCH 03/10] rename --- .github/workflows/rust.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index bcf3d920..35bd3f79 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -6,9 +6,9 @@ permissions: on: push: - branches: [ main ] + branches: [ master ] pull_request: - branches: [ main ] + branches: [ master ] jobs: build: From 9a979173aa2561308008493cf4c7e9945a171846 Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Wed, 29 Jan 2025 11:04:40 -0800 Subject: [PATCH 04/10] rename --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7f7b3372..5c04b781 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,10 +29,10 @@ subtle = { version = "2.4", features = ["i128"], default-features = false } itertools = { version = "0.10.0", default-features = false } colored = { version = "2.0.0", default-features = false, optional = true } flate2 = { version = "1.0.14" } -typos = "0.10.33" [dev-dependencies] criterion = "0.3.1" +typos = "0.10.33" [lib] name = "libspartan" From ebe5bfa33c6b70122e6f9a6fa5d4e384d96591bf Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Wed, 29 Jan 2025 11:13:33 -0800 Subject: [PATCH 05/10] small fixes --- .github/workflows/rust.yml | 27 ++++++++++++++++----------- Cargo.toml | 7 +++++-- src/lib.rs | 1 - 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 35bd3f79..2af78cdb 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -24,19 +24,24 @@ jobs: command: build args: --examples --benches --verbose - build-wasm: + 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 + - 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 test: runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index 5c04b781..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,6 +30,9 @@ 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" 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")] From d69b3396553644689bf80673bce0c02728fe7b3e Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Wed, 29 Jan 2025 11:15:22 -0800 Subject: [PATCH 06/10] small fixes --- .github/workflows/rust.yml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2af78cdb..cf504c1e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -27,21 +27,21 @@ jobs: 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: 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 test: runs-on: ubuntu-latest From 0b7ea9d37bc73d913119cb5cc3d30a24318655b1 Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Wed, 29 Jan 2025 11:49:58 -0800 Subject: [PATCH 07/10] fix CI --- .github/workflows/rust.yml | 65 +++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index cf504c1e..39612090 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -23,25 +23,47 @@ jobs: 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_wasm: + build-wasi: 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 + - name: Wasi build + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: wasm32-wasi + - uses: actions-rs/cargo@v1 + with: + command: build + args: --no-default-features --target wasm32-wasi test: runs-on: ubuntu-latest @@ -55,6 +77,19 @@ jobs: 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 From d07c756b1e0615d5786fdc063e1febbcd0947211 Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Wed, 29 Jan 2025 11:54:32 -0800 Subject: [PATCH 08/10] fix CI --- .github/workflows/rust.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 39612090..762a21d3 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -60,6 +60,8 @@ jobs: with: toolchain: stable target: wasm32-wasi + - name: Install wasm32-wasi target + run: rustup target add wasm32-wasi - uses: actions-rs/cargo@v1 with: command: build From 28e78cb588a34bc51fb515077b7c85592cc976d1 Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Wed, 29 Jan 2025 11:56:05 -0800 Subject: [PATCH 09/10] fix CI --- .github/workflows/rust.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 762a21d3..23c1c7a1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -55,11 +55,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Wasi build - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - target: wasm32-wasi - name: Install wasm32-wasi target run: rustup target add wasm32-wasi - uses: actions-rs/cargo@v1 From 7db344b954b76ba9c61d1258a8744e5cb14147af Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Wed, 29 Jan 2025 13:24:57 -0800 Subject: [PATCH 10/10] fix CI --- .github/workflows/rust.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 23c1c7a1..230795ee 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -55,12 +55,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Install wasm32-wasi target - run: rustup target add wasm32-wasi + - 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-wasi + args: --no-default-features --target wasm32-wasip1 test: runs-on: ubuntu-latest