From 7775a0feb3f8ec5e7046172c6f879c2c60307b5e Mon Sep 17 00:00:00 2001 From: dante <45801863+alexander-camuto@users.noreply.github.com> Date: Fri, 25 Aug 2023 15:58:12 +0100 Subject: [PATCH] chore: bump to stable rust (#434) --- .github/workflows/rust.yml | 40 +++++++++++++++++------------------ .github/workflows/wasm.yml | 2 +- README.md | 35 +++++++----------------------- examples/conv2d_mnist/main.rs | 17 --------------- rust-toolchain | 4 ++-- src/lib.rs | 5 ++--- src/tensor/ops.rs | 5 ++++- 7 files changed, 37 insertions(+), 71 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4dd63938c..73da6de31 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -26,7 +26,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - name: Build @@ -38,7 +38,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - name: Docs @@ -50,7 +50,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: baptiste0928/cargo-install@v1 @@ -69,7 +69,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: baptiste0928/cargo-install@v1 @@ -88,7 +88,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: jetli/wasm-pack-action@v0.4.0 @@ -100,7 +100,7 @@ jobs: - name: Install wasm runner run: cargo install wasm-server-runner - name: Add rust-src - run: rustup component add rust-src --toolchain nightly-2023-04-17-x86_64-unknown-linux-gnu + run: rustup component add rust-src --toolchain nightly-2023-08-24-x86_64-unknown-linux-gnu - name: Run wasm verifier tests run: wasm-pack test --chrome --headless -- -Z build-std="panic_abort,std" --features web @@ -111,7 +111,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: mwilliamson/setup-wasmtime-action@v2 @@ -131,7 +131,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: baptiste0928/cargo-install@v1 @@ -148,7 +148,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: baptiste0928/cargo-install@v1 @@ -199,7 +199,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: baptiste0928/cargo-install@v1 @@ -232,7 +232,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: baptiste0928/cargo-install@v1 @@ -257,7 +257,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: baptiste0928/cargo-install@v1 @@ -280,7 +280,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: baptiste0928/cargo-install@v1 @@ -297,14 +297,14 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: baptiste0928/cargo-install@v1 with: crate: cargo-nextest locked: true - - name: KZG prove and verify aggr tests + - name: KZG )tests run: cargo nextest run --release --verbose tests_aggr::kzg_aggr_prove_and_verify_ --test-threads 8 -- --include-ignored prove-and-verify-aggr-evm-tests: @@ -319,7 +319,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: baptiste0928/cargo-install@v1 @@ -342,7 +342,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: baptiste0928/cargo-install@v1 @@ -361,7 +361,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: baptiste0928/cargo-install@v1 @@ -381,7 +381,7 @@ jobs: python-version: "3.7" - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - name: Install solc @@ -424,7 +424,7 @@ jobs: python-version: "3.9" - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: baptiste0928/cargo-install@v1 diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index 6f44b9e65..278af475a 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-04-17 + toolchain: nightly-2023-08-24 override: true components: rustfmt, clippy - uses: jetli/wasm-pack-action@v0.4.0 diff --git a/README.md b/README.md index f6c715424..b89440b76 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,9 @@ In the backend we use [Halo2](https://github.com/privacy-scaling-explorations/ha The generated proofs can then be used on-chain to verify computation, only the Ethereum Virtual Machine (EVM) is supported at the moment. - - If you have any questions, we'd love for you to open up a discussion topic in [Discussions](https://github.com/zkonduit/ezkl/discussions). Alternatively, you can join the ✨[EZKL Community Telegram Group](https://t.me/+QRzaRvTPIthlYWMx)💫. +- To see what you can build with ezkl, check out [cryptoidol.tech](https://cryptoidol.tech/) where ezkl is used to create an AI that judges your singing ... forever. ---------------------- @@ -43,8 +43,8 @@ Install the python bindings by calling. ```bash pip install ezkl ``` +Google Colab Example to learn how you can train a neural net and deploy an inference verifier onchain for use in other smart contracts. [![Notebook](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/zkonduit/ezkl/blob/main/examples/notebooks/ezkl_demo.ipynb) -Google Colab Example to learn how you can train a neural net and deploy an inference verifier onchain for use in other smart contracts. [(https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/zkonduit/ezkl/blob/main/examples/notebooks/ezkl_demo.ipynb) More notebook tutorials can be found within `examples/notebooks`. @@ -64,32 +64,11 @@ Build the auto-generated rust documentation and open the docs in your browser lo ### building the project 🔨 #### Rust CLI -Note that the library requires a nightly version of the rust toolchain. You can change the default toolchain by running: - -```bash -# we set it to this version because of https://github.com/rust-lang/rust/issues/110829 -rustup override set nightly-2023-04-17 -``` - -After which you may build the library - -```bash -cargo build --release -``` -A folder `./target/release` will be generated. Add this folder to your PATH environment variable to call `ezkl` from the CLI. +You can install the library from source ```bash -# For UNIX like systems -# in .bashrc, .bash_profile, or some other path file -export PATH="/ezkl/target/release:$PATH" -``` - -Restart your shell or reload your shell settings - -```bash -# example, replace .bash_profile with the file you use to configure your shell -source ~/.bash_profile +cargo install --path . ``` You will need a functioning installation of `solc` in order to run `ezkl` properly. @@ -109,7 +88,6 @@ maturin develop --release --features python-bindings pip install torch pandas numpy seaborn jupyter onnx kaggle py-solc-x web3 librosa tensorflow keras tf2onnx ``` - ### repos The EZKL project has several libraries and repos. @@ -117,7 +95,7 @@ The EZKL project has several libraries and repos. | Repo | Description | | --- | --- | | [@zkonduit/ezkl](https://github.com/zkonduit/ezkl) | the main ezkl repo in rust with wasm and python bindings | -| [@zkonduit/pyezkl](https://github.com/zkonduit/pyezkl) | additional functionality written in python to support data science and zero knowledge applications | +| [@zkonduit/ezkljs](https://github.com/zkonduit/ezkljs) | typescript and javascript tooling to help integrate ezkl into web apps | ---------------------- @@ -143,3 +121,6 @@ Unless you explicitly state otherwise, any contribution intentionally submitted Ezkl is unaudited, beta software undergoing rapid development. There may be bugs. No guarantees of security are made and it should not be relied on in production. +> NOTE: Because operations are quantized when they are converted from an onnx file to a zk-circuit, outputs in python and ezkl may differ slightly. + + diff --git a/examples/conv2d_mnist/main.rs b/examples/conv2d_mnist/main.rs index 30acddaea..825d8dbc0 100644 --- a/examples/conv2d_mnist/main.rs +++ b/examples/conv2d_mnist/main.rs @@ -347,23 +347,6 @@ pub fn runconv() { l2_params: [l2_weights, l2_biases], }; - #[cfg(feature = "dev-graph")] - { - println!("Plotting"); - use plotters::prelude::*; - - let root = BitMapBackend::new("conv2dmnist-layout.png", (2048, 7680)).into_drawing_area(); - root.fill(&WHITE).unwrap(); - let root = root - .titled("Conv -> ReLU -> Affine -> ReLU", ("sans-serif", 60)) - .unwrap(); - - halo2_proofs::dev::CircuitLayout::default() - .render(13, &circuit, &root) - .unwrap(); - return; - } - let public_input: Tensor = vec![ -25124i32, -19304, -16668, -4399, -6209, -4548, -2317, -8349, -6117, -23461, ] diff --git a/rust-toolchain b/rust-toolchain index 014bb1ec8..9bb8264e2 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-04-16" -components = [ "rustfmt", "clippy" ] +channel = "nightly-2023-08-24" +components = ["rustfmt", "clippy"] diff --git a/src/lib.rs b/src/lib.rs index dd83687d4..a2ebd2b4a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,8 +22,6 @@ missing_debug_implementations, unsafe_code )] -#![feature(lint_reasons)] -#![feature(int_roundings)] //! A library for turning computational graphs, such as neural networks, into ZK-circuits. //! @@ -39,7 +37,8 @@ pub mod circuit; #[cfg(not(target_arch = "wasm32"))] pub mod commands; #[cfg(not(target_arch = "wasm32"))] -#[allow(missing_docs, reason = "abigen doesn't generate docs for this module")] +// abigen doesn't generate docs for this module +#[allow(missing_docs)] /// Utility functions for contracts pub mod eth; /// Command execution diff --git a/src/tensor/ops.rs b/src/tensor/ops.rs index c38e5cd4c..b3bf316d9 100644 --- a/src/tensor/ops.rs +++ b/src/tensor/ops.rs @@ -1082,7 +1082,10 @@ pub fn downsample( modulo: usize, ) -> Result, TensorError> { let mut output_shape = input.dims().to_vec(); - output_shape[dim] = (input.dims()[dim] - modulo).div_ceil(stride); + // now downsample along axis dim offset by modulo, rounding up (+1 if remaidner is non-zero) + let remainder = (input.dims()[dim] - modulo) % stride; + let div = (input.dims()[dim] - modulo) / stride; + output_shape[dim] = div + (remainder > 0) as usize; let mut output = Tensor::::new(None, &output_shape)?; assert!(modulo <= input.dims()[dim]);