diff --git a/.github/workflows/build-circuits.yml b/.github/workflows/build-circuits.yml index ef5c4d4..921b496 100644 --- a/.github/workflows/build-circuits.yml +++ b/.github/workflows/build-circuits.yml @@ -82,11 +82,14 @@ jobs: PTAU_URL: "https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_17.ptau" PTAU_FILE: "powersOfTau28_hez_final_17.ptau" steps: + - name: Checkout + uses: actions/checkout@8edcb1bdb4e267140fa742c62e395cd74f332709 + + - name: Initialise Submodules + run: git submodule update --init --recursive + - name: Install Rust Toolchain - uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 - with: - toolchain: stable - cache: false + uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746 # Version 1.0.6 - name: Install Circom run: | @@ -96,12 +99,6 @@ jobs: RUSTFLAGS="-A dead_code" cargo install --path circom circom --version - - name: Checkout - uses: actions/checkout@8edcb1bdb4e267140fa742c62e395cd74f332709 - - - name: Initialise Submodules - run: git submodule update --init --recursive - - name: Setup Node.js uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b with: @@ -153,11 +150,14 @@ jobs: OS: linux ARCH: x86_64 steps: + - name: Checkout + uses: actions/checkout@8edcb1bdb4e267140fa742c62e395cd74f332709 + + - name: Initialise Submodules + run: git submodule update --init --recursive + - name: Install Rust Toolchain - uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 - with: - toolchain: stable - cache: false + uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746 # Version 1.0.6 - name: Install Circom run: | @@ -167,12 +167,6 @@ jobs: RUSTFLAGS="-A dead_code" cargo install --path circom circom --version - - name: Checkout - uses: actions/checkout@8edcb1bdb4e267140fa742c62e395cd74f332709 - - - name: Initialise Submodules - run: git submodule update --init --recursive - - name: Setup Dependencies working-directory: rapidsnark run: sudo apt update -y @@ -389,11 +383,14 @@ jobs: OS: linux ARCH: aarch64 steps: + - name: Checkout + uses: actions/checkout@8edcb1bdb4e267140fa742c62e395cd74f332709 + + - name: Initialise Submodules + run: git submodule update --init --recursive + - name: Install Rust Toolchain - uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 - with: - toolchain: stable - cache: false + uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746 # Version 1.0.6 - name: Install Circom run: | @@ -403,12 +400,6 @@ jobs: RUSTFLAGS="-A dead_code" cargo install --path circom circom --version - - name: Checkout - uses: actions/checkout@8edcb1bdb4e267140fa742c62e395cd74f332709 - - - name: Initialise Submodules - run: git submodule update --init --recursive - - name: Setup Dependencies working-directory: rapidsnark run: sudo apt update -y @@ -637,11 +628,14 @@ jobs: make git + - name: Checkout + uses: actions/checkout@8edcb1bdb4e267140fa742c62e395cd74f332709 + + - name: Initialise Submodules + run: git submodule update --init --recursive + - name: Install Rust Toolchain - uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 - with: - toolchain: stable - cache: false + uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746 # Version 1.0.6 - name: Install Circom run: | @@ -651,12 +645,6 @@ jobs: $env:RUSTFLAGS="-A dead_code"; cargo install --path circom circom --version - - name: Checkout - uses: actions/checkout@8edcb1bdb4e267140fa742c62e395cd74f332709 - - - name: Initialise Submodules - run: git submodule update --init --recursive - - name: Install Dependencies [Witness Generator] shell: msys2 {0} run: | @@ -902,11 +890,14 @@ jobs: ARCH: aarch64 OS: macos steps: + - name: Checkout + uses: actions/checkout@8edcb1bdb4e267140fa742c62e395cd74f332709 + + - name: Initialise Submodules + run: git submodule update --init --recursive + - name: Install Rust Toolchain - uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 - with: - toolchain: stable - cache: false + uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746 # Version 1.0.6 - name: Install Circom run: | @@ -916,12 +907,6 @@ jobs: RUSTFLAGS="-A dead_code" cargo install --path circom circom --version - - name: Checkout - uses: actions/checkout@8edcb1bdb4e267140fa742c62e395cd74f332709 - - - name: Initialise Submodules - run: git submodule update --init --recursive - - name: Setup Dependencies run: mkdir include diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..fbafc0b --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,105 @@ +name: Lint + +on: + push: + branches: + - main + pull_request: + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2 # Version 4.2.2 + + # Stable toolchain for building and clippy, version and components from rust-toolchain.toml. + - name: Install Rust Toolchain + uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746 # Version 1.0.6 + + # Nightly toolchain for rustfmt only — nightly is required for formatting features not yet stable. + - name: Install Nightly Toolchain (fmt) + uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746 # Version 1.0.6 + with: + toolchain: nightly-2026-02-28 + profile: minimal + components: rustfmt + + - name: Cache Cargo artifacts + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # Version 4.2.3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + rust/target + key: ${{ runner.os }}-cargo-${{ hashFiles('rust/Cargo.lock', 'rust/Cargo.toml') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: Install taplo + run: cargo install taplo-cli --version 0.9.3 --locked + + - name: Install cargo-deny + run: cargo install cargo-deny --version 0.19.0 --locked + + - name: Install cargo-machete + run: cargo install cargo-machete --version 0.19.1 --locked + + - name: Check Rust formatting + id: fmt + continue-on-error: true + run: cargo +nightly-2026-02-28 fmt --manifest-path rust/Cargo.toml --all -- --check + + - name: Lint (clippy) + id: clippy + continue-on-error: true + run: > + cargo clippy + --manifest-path rust/Cargo.toml + --all + --all-targets + --all-features + -- + -D warnings + + - name: Audit dependencies + id: deny + continue-on-error: true + run: > + cargo deny + --manifest-path rust/Cargo.toml + --locked + --all-features + check + --hide-inclusion-graph + -c .cargo-deny.toml + --show-stats + -D warnings + + - name: Check TOML formatting + id: taplo-fmt + continue-on-error: true + run: taplo fmt --check + + - name: Lint TOML + id: taplo-lint + continue-on-error: true + run: taplo lint + + - name: Check unused dependencies + id: machete + continue-on-error: true + run: cargo machete rust/ + + - name: Report + if: always() + run: | + failed=false + [ "${{ steps.fmt.outcome }}" != "success" ] && failed=true + [ "${{ steps.clippy.outcome }}" != "success" ] && failed=true + [ "${{ steps.deny.outcome }}" != "success" ] && failed=true + [ "${{ steps.taplo-fmt.outcome }}" != "success" ] && failed=true + [ "${{ steps.taplo-lint.outcome }}" != "success" ] && failed=true + [ "${{ steps.machete.outcome }}" != "success" ] && failed=true + $failed && exit 1 || true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..fcb6b0b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +name: Test + +on: + push: + branches: + - main + pull_request: + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2 # Version 4.2.2 + + - name: Install Rust Toolchain + uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746 # Version 1.0.6 + + - name: Cache Cargo artifacts + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # Version 4.2.3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + rust/target + key: ${{ runner.os }}-cargo-${{ hashFiles('rust/Cargo.lock', 'rust/Cargo.toml') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: Test + run: > + cargo test + --manifest-path rust/Cargo.toml + --all + --all-features diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a4136a7..631d99b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,42 @@ # Contributor's Guide +## Development Setup + +### Prerequisites + +- [Rust](https://rustup.rs/) — the pinned toolchain version is in `rust-toolchain.toml` and will be installed automatically by `rustup`. +- [pre-commit](https://pre-commit.com/) — used to run formatting, linting, and audit checks before each commit. + +### Installing the Pre-Commit Hooks + +```bash +pre-commit install +``` + +This only needs to be done once after cloning the repo. Hooks will then run automatically on `git commit`. + +### Running Checks Manually + +To run all hooks manually against all files: + +```bash +pre-commit run --all-files +``` + +### Maintenance + +#### Rust Toolchain + +When bumping the stable toolchain, update `channel` in `rust-toolchain.toml`. The comment there lists every other place that must be updated in sync (nightly version, CI workflows, pre-commit hooks). + +#### Tool Versions + +`taplo`, `cargo-deny`, and `cargo-machete` are pinned in two places that must stay in sync: +- `.pre-commit-config.yaml` (hook `rev`) +- `.github/workflows/lint.yml` (`cargo install --version`) + +--- + ## Triggering a New Release for Logos Blockchain Circuits To trigger a release build: @@ -8,7 +45,8 @@ To trigger a release build: 2. This will automatically trigger the `.github/workflows/build_circuits.yml` workflow. 3. Once the workflow finishes, the generated artifacts will be attached to a new release. -> Currently, releases published this way are marked as **Draft** and **Pre-Release** to ensure that the changelog and pre-release steps are manually reviewed first. +> Currently, releases published this way are marked as **Draft** and **Pre-Release** to ensure that the changelog and +> pre-release steps are manually reviewed first. ### Generated Artifacts @@ -30,34 +68,41 @@ logos-blockchain-circuits-{version}-{os}-{arch}/ ├── prover[.exe] ├── verifier[.exe] ├── pol/ -│ ├── witness_generator[.exe] +│ ├── libpol.a │ ├── witness_generator.dat +│ ├── include/ │ ├── proving_key.zkey │ └── verification_key.json ├── poq/ -│ ├── witness_generator[.exe] +│ ├── libpoq.a │ ├── witness_generator.dat +│ ├── include/ │ ├── proving_key.zkey │ └── verification_key.json ├── zksign/ -│ ├── witness_generator[.exe] +│ ├── libsignature.a │ ├── witness_generator.dat +│ ├── include/ │ ├── proving_key.zkey │ └── verification_key.json └── poc/ - ├── witness_generator[.exe] + ├── libpoc.a ├── witness_generator.dat + ├── include/ ├── proving_key.zkey └── verification_key.json ``` +> On Windows, static libraries use the `.lib` extension instead of `.a` (e.g. `pol.lib`). + At the root level: - **prover**: Rapidsnark prover binary for generating zk-SNARK proofs - **verifier**: Rapidsnark verifier binary for verifying proofs Each circuit directory contains: -- **witness_generator**: Compiled C++ binary for generating witnesses from inputs +- **lib{circuit}.a / {circuit}.lib**: Static library for generating witnesses from inputs - **witness_generator.dat**: Required data file for the witness generator +- **include/**: C headers for linking against the witness generator library - **proving_key.zkey**: Groth16 proving key for generating zk-SNARK proofs - **verification_key.json**: Verification key for verifying proofs diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..3f5228f --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,7 @@ +[toolchain] +# Also, update the version of the nightly toolchain to the latest nightly of the new version specified in the following places: +# * .github/workflows/lint.yml (fmt step) +# * .pre-commit-config.yaml (fmt hook) +channel = "1.95.0" +# Even if clippy should be included in the default profile, in some cases it is not installed. So we force it with an explicit declaration. +components = ["clippy"]