From 72fc388353680d37ba9c37d182d8d6d89c6cd126 Mon Sep 17 00:00:00 2001 From: Conghao Shen Date: Wed, 8 Jun 2022 13:41:05 -0700 Subject: [PATCH 01/12] feat: add binary compatibility test --- manta-pay/Cargo.toml | 2 + manta-pay/src/test/compat.rs | 307 +++++++++++++++++++++++++++++++++++ manta-pay/src/test/mod.rs | 2 + 3 files changed, 311 insertions(+) create mode 100644 manta-pay/src/test/compat.rs diff --git a/manta-pay/Cargo.toml b/manta-pay/Cargo.toml index 09f794e75..3336f6fdf 100644 --- a/manta-pay/Cargo.toml +++ b/manta-pay/Cargo.toml @@ -140,4 +140,6 @@ ws_stream_wasm = { version = "0.7.3", optional = true, default-features = false [dev-dependencies] manta-crypto = { path = "../manta-crypto", default-features = false, features = ["getrandom"] } manta-pay = { path = ".", default-features = false, features = ["groth16", "scale", "scale-std", "std", "test"] } +manta-sdk = { git = "https://github.com/manta-network/sdk.git", default-features = false, features = ["download"]} +anyhow = "1.0.55" tempfile = { version = "3.3.0", default-features = false } diff --git a/manta-pay/src/test/compat.rs b/manta-pay/src/test/compat.rs new file mode 100644 index 000000000..6e1329d58 --- /dev/null +++ b/manta-pay/src/test/compat.rs @@ -0,0 +1,307 @@ +// Copyright 2019-2022 Manta Network. +// This file is part of manta-rs. +// +// manta-rs is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// manta-rs is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with manta-rs. If not, see . + +//! ## Manta Pay UTXO Binary Compatibility +//! This test checks if current implementation is compatible with precomputed transactions in Manta SDK. + +// This test is adapted from https://github.com/Manta-Network/Manta/blob/1c5c4b8750d06cb028fb555813414a5802554817/pallets/manta-pay/src/bin/precompute_coins.rs + +use crate::config::{ + self, FullParameters, MerkleTreeConfiguration, Mint, MultiProvingContext, + MultiVerifyingContext, NoteEncryptionScheme, Parameters, PrivateTransfer, ProofSystem, + ProvingContext, Reclaim, TransferPost, UtxoAccumulatorModel, UtxoCommitmentScheme, + VerifyingContext, VoidNumberCommitmentScheme, +}; +use anyhow::Result; +use ark_std::rand::thread_rng; +use manta_accounting::{ + asset::{Asset, AssetId}, + transfer::{self, SpendingKey}, +}; +use manta_crypto::{ + accumulator::Accumulator, + constraint::ProofSystem as _, + merkle_tree::{forest::TreeArrayMerkleForest, full::Full}, + rand::{CryptoRng, Rand, RngCore, Sample}, +}; +use manta_util::codec::{Decode, IoReader}; +use std::{fs::File, path::Path}; + +/// UTXO Accumulator for Building Circuits +type UtxoAccumulator = + TreeArrayMerkleForest, 256>; + +/// Loads parameters from the SDK, using `directory` as a temporary directory to store files. +#[inline] +fn load_parameters( + directory: &Path, +) -> Result<( + MultiProvingContext, + MultiVerifyingContext, + Parameters, + UtxoAccumulatorModel, +)> { + println!("Loading parameters..."); + let mint_path = directory.join("mint.dat"); + manta_sdk::pay::testnet::proving::Mint::download(&mint_path)?; + let private_transfer_path = directory.join("private-transfer.dat"); + manta_sdk::pay::testnet::proving::PrivateTransfer::download(&private_transfer_path)?; + let reclaim_path = directory.join("reclaim.dat"); + manta_sdk::pay::testnet::proving::Reclaim::download(&reclaim_path)?; + let proving_context = MultiProvingContext { + mint: ProvingContext::decode(IoReader(File::open(mint_path)?)) + .expect("Unable to decode MINT proving context."), + private_transfer: ProvingContext::decode(IoReader(File::open(private_transfer_path)?)) + .expect("Unable to decode PRIVATE_TRANSFER proving context."), + reclaim: ProvingContext::decode(IoReader(File::open(reclaim_path)?)) + .expect("Unable to decode RECLAIM proving context."), + }; + let verifying_context = MultiVerifyingContext { + mint: VerifyingContext::decode( + manta_sdk::pay::testnet::verifying::Mint::get().expect("Checksum did not match."), + ) + .expect("Unable to decode MINT verifying context."), + private_transfer: VerifyingContext::decode( + manta_sdk::pay::testnet::verifying::PrivateTransfer::get() + .expect("Checksum did not match."), + ) + .expect("Unable to decode PRIVATE_TRANSFER verifying context."), + reclaim: VerifyingContext::decode( + manta_sdk::pay::testnet::verifying::Reclaim::get().expect("Checksum did not match."), + ) + .expect("Unable to decode RECLAIM verifying context."), + }; + let parameters = Parameters { + note_encryption_scheme: NoteEncryptionScheme::decode( + manta_sdk::pay::testnet::parameters::NoteEncryptionScheme::get() + .expect("Checksum did not match."), + ) + .expect("Unable to decode NOTE_ENCRYPTION_SCHEME parameters."), + utxo_commitment: UtxoCommitmentScheme::decode( + manta_sdk::pay::testnet::parameters::UtxoCommitmentScheme::get() + .expect("Checksum did not match."), + ) + .expect("Unable to decode UTXO_COMMITMENT_SCHEME parameters."), + void_number_commitment: VoidNumberCommitmentScheme::decode( + manta_sdk::pay::testnet::parameters::VoidNumberCommitmentScheme::get() + .expect("Checksum did not match."), + ) + .expect("Unable to decode VOID_NUMBER_COMMITMENT_SCHEME parameters."), + }; + println!("Loading parameters Done."); + Ok(( + proving_context, + verifying_context, + parameters, + UtxoAccumulatorModel::decode( + manta_sdk::pay::testnet::parameters::UtxoAccumulatorModel::get() + .expect("Checksum did not match."), + ) + .expect("Unable to decode UTXO_ACCUMULATOR_MODEL."), + )) +} + +/// Asserts that `post` represents a valid `Transfer` verifying against `verifying_context`. +#[inline] +fn assert_valid_proof(verifying_context: &VerifyingContext, post: &config::TransferPost) { + assert!( + ProofSystem::verify( + verifying_context, + &post.generate_proof_input(), + &post.validity_proof, + ) + .expect("Unable to verify proof."), + "Invalid proof: {:?}.", + post + ); +} + +/// Samples a [`Mint`] transaction. +#[inline] +fn sample_mint( + proving_context: &ProvingContext, + verifying_context: &VerifyingContext, + parameters: &Parameters, + utxo_accumulator_model: &UtxoAccumulatorModel, + asset: Asset, + rng: &mut R, +) -> TransferPost +where + R: CryptoRng + RngCore + ?Sized, +{ + let mint = Mint::from_spending_key(parameters, &SpendingKey::gen(rng), asset, rng) + .into_post( + FullParameters::new(parameters, utxo_accumulator_model), + proving_context, + rng, + ) + .expect("Unable to build MINT proof."); + assert_valid_proof(verifying_context, &mint); + mint.into() +} + +/// Samples a [`PrivateTransfer`] transaction under two [`Mint`]s. +#[inline] +fn sample_private_transfer( + proving_context: &MultiProvingContext, + verifying_context: &MultiVerifyingContext, + parameters: &Parameters, + utxo_accumulator_model: &UtxoAccumulatorModel, + asset_0: Asset, + asset_1: Asset, + rng: &mut R, +) -> ([TransferPost; 2], TransferPost) +where + R: CryptoRng + RngCore + ?Sized, +{ + let mut utxo_accumulator = UtxoAccumulator::new(utxo_accumulator_model.clone()); + let spending_key_0 = SpendingKey::new(rng.gen(), rng.gen()); + let (mint_0, pre_sender_0) = transfer::test::sample_mint( + &proving_context.mint, + FullParameters::new(parameters, utxo_accumulator.model()), + &spending_key_0, + asset_0, + rng, + ) + .expect("Unable to build MINT proof."); + assert_valid_proof(&verifying_context.mint, &mint_0); + let sender_0 = pre_sender_0 + .insert_and_upgrade(&mut utxo_accumulator) + .expect("Just inserted so this should not fail."); + let spending_key_1 = SpendingKey::new(rng.gen(), rng.gen()); + let (mint_1, pre_sender_1) = transfer::test::sample_mint( + &proving_context.mint, + FullParameters::new(parameters, utxo_accumulator.model()), + &spending_key_1, + asset_1, + rng, + ) + .expect("Unable to build MINT proof."); + assert_valid_proof(&verifying_context.mint, &mint_1); + let sender_1 = pre_sender_1 + .insert_and_upgrade(&mut utxo_accumulator) + .expect("Just inserted so this should not fail."); + let private_transfer = PrivateTransfer::build( + [sender_0, sender_1], + [ + spending_key_0.receiver(parameters, rng.gen(), asset_1), + spending_key_1.receiver(parameters, rng.gen(), asset_0), + ], + ) + .into_post( + FullParameters::new(parameters, utxo_accumulator.model()), + &proving_context.private_transfer, + rng, + ) + .expect("Unable to build PRIVATE_TRANSFER proof."); + assert_valid_proof(&verifying_context.private_transfer, &private_transfer); + ([mint_0.into(), mint_1.into()], private_transfer.into()) +} + +/// Samples a [`Reclaim`] transaction under two [`Mint`]s. +#[inline] +fn sample_reclaim( + proving_context: &MultiProvingContext, + verifying_context: &MultiVerifyingContext, + parameters: &Parameters, + utxo_accumulator_model: &UtxoAccumulatorModel, + asset_0: Asset, + asset_1: Asset, + rng: &mut R, +) -> ([TransferPost; 2], TransferPost) +where + R: CryptoRng + RngCore + ?Sized, +{ + let mut utxo_accumulator = UtxoAccumulator::new(utxo_accumulator_model.clone()); + let spending_key_0 = SpendingKey::new(rng.gen(), rng.gen()); + let (mint_0, pre_sender_0) = transfer::test::sample_mint( + &proving_context.mint, + FullParameters::new(parameters, utxo_accumulator.model()), + &spending_key_0, + asset_0, + rng, + ) + .expect("Unable to build MINT proof."); + assert_valid_proof(&verifying_context.mint, &mint_0); + let sender_0 = pre_sender_0 + .insert_and_upgrade(&mut utxo_accumulator) + .expect("Just inserted so this should not fail."); + let spending_key_1 = SpendingKey::new(rng.gen(), rng.gen()); + let (mint_1, pre_sender_1) = transfer::test::sample_mint( + &proving_context.mint, + FullParameters::new(parameters, utxo_accumulator.model()), + &spending_key_1, + asset_1, + rng, + ) + .expect("Unable to build MINT proof."); + assert_valid_proof(&verifying_context.mint, &mint_1); + let sender_1 = pre_sender_1 + .insert_and_upgrade(&mut utxo_accumulator) + .expect("Just inserted so this should not fail."); + let reclaim = Reclaim::build( + [sender_0, sender_1], + [spending_key_0.receiver(parameters, rng.gen(), asset_1)], + asset_0, + ) + .into_post( + FullParameters::new(parameters, utxo_accumulator.model()), + &proving_context.reclaim, + rng, + ) + .expect("Unable to build RECLAIM proof."); + assert_valid_proof(&verifying_context.reclaim, &reclaim); + ([mint_0.into(), mint_1.into()], reclaim.into()) +} + +/// Test validity on sampled transactions. +#[test] +fn compatibility() { + let directory = tempfile::tempdir().expect("Unable to generate temporary test directory."); + println!("[INFO] Temporary Directory: {:?}", directory); + + let mut rng = thread_rng(); + let (proving_context, verifying_context, parameters, utxo_accumulator_model) = + load_parameters(directory.path()).expect("failed to load parameters"); + let asset_id: u32 = 8; + + let _ = sample_mint( + &proving_context.mint, + &verifying_context.mint, + ¶meters, + &utxo_accumulator_model, + AssetId(asset_id).value(100_000), + &mut rng, + ); + let _ = sample_private_transfer( + &proving_context, + &verifying_context, + ¶meters, + &utxo_accumulator_model, + AssetId(asset_id).value(10_000), + AssetId(asset_id).value(20_000), + &mut rng, + ); + let _ = sample_reclaim( + &proving_context, + &verifying_context, + ¶meters, + &utxo_accumulator_model, + AssetId(asset_id).value(10_000), + AssetId(asset_id).value(20_000), + &mut rng, + ); +} diff --git a/manta-pay/src/test/mod.rs b/manta-pay/src/test/mod.rs index 625bef8d6..00c86e7c2 100644 --- a/manta-pay/src/test/mod.rs +++ b/manta-pay/src/test/mod.rs @@ -24,3 +24,5 @@ // pub mod simulation; pub mod transfer; + +pub mod compat; From 3ffd47f80a874c3d3016b703f0b1d1a41b9dd283 Mon Sep 17 00:00:00 2001 From: Conghao Shen Date: Wed, 8 Jun 2022 17:25:03 -0700 Subject: [PATCH 02/12] chore: nit --- manta-pay/src/test/compat.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manta-pay/src/test/compat.rs b/manta-pay/src/test/compat.rs index 6e1329d58..5aa2cce9a 100644 --- a/manta-pay/src/test/compat.rs +++ b/manta-pay/src/test/compat.rs @@ -150,7 +150,7 @@ where ) .expect("Unable to build MINT proof."); assert_valid_proof(verifying_context, &mint); - mint.into() + mint } /// Samples a [`PrivateTransfer`] transaction under two [`Mint`]s. @@ -208,7 +208,7 @@ where ) .expect("Unable to build PRIVATE_TRANSFER proof."); assert_valid_proof(&verifying_context.private_transfer, &private_transfer); - ([mint_0.into(), mint_1.into()], private_transfer.into()) + ([mint_0, mint_1], private_transfer) } /// Samples a [`Reclaim`] transaction under two [`Mint`]s. @@ -264,7 +264,7 @@ where ) .expect("Unable to build RECLAIM proof."); assert_valid_proof(&verifying_context.reclaim, &reclaim); - ([mint_0.into(), mint_1.into()], reclaim.into()) + ([mint_0, mint_1], reclaim) } /// Test validity on sampled transactions. From b7f5a80bc71304b5a4614e20fb1ff05c367c1537 Mon Sep 17 00:00:00 2001 From: "Brandon H. Gomes" Date: Thu, 9 Jun 2022 03:15:45 -0400 Subject: [PATCH 03/12] feat: add documentation and CI for contributing (#93) * feat: add documentation for contributing * fix: update logo spacing and correct formatting for bullets * feat: update CHANGELOG to include current changes * fix: use full paths for CHANGELOG and CONTRIBUTING links * fix: correct Github -> GitHub typo * feat: add automatic tag-and-release pipeline * feat: add label descriptions in CONTRIBUTING.md * fix: update PULL_REQUEST_TEMPLATE links Signed-off-by: Brandon H. Gomes --- .github/PULL_REQUEST_TEMPLATE.md | 10 +++++++ .github/release.yml | 26 ++++++++++++++++++ .github/workflows/release.yml | 17 ++++++++++++ CHANGELOG.md | 46 ++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 44 +++++++++++++++++++++++++----- Cargo.toml | 1 - README.md | 20 ++++++++++++++ logo.svg | 10 +++++++ manta-benchmark/Cargo.toml | 16 +++++------ manta-crypto/Cargo.toml | 1 - 10 files changed, 174 insertions(+), 17 deletions(-) create mode 100644 .github/release.yml create mode 100644 .github/workflows/release.yml create mode 100644 CHANGELOG.md create mode 100644 logo.svg diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index e69de29bb..73edb9fc0 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,10 @@ + + +--- + +Before we can merge this PR, please make sure that all the following items have been checked off: + +- [ ] Linked to an issue with discussion and accepted design OR have an explanation in the PR that describes this work. +- [ ] Added **one** line describing your change in [`CHANGELOG.md`](https://github.com/manta-network/manta-rs/blob/main/CHANGELOG.md) and added the appropriate `changelog` label to the PR. +- [ ] Re-reviewed `Files changed` in the GitHub PR explorer. +- [ ] Checked that changes and commits conform to the standards outlined in [`CONTRIBUTING.md`](https://github.com/manta-network/manta-rs/blob/main/CONTRIBUTING.md). diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 000000000..48d0a7e76 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,26 @@ +changelog: + exclude: + labels: + - changelog:skip + categories: + - title: Added + labels: + - changelog:added + - title: Changed + labels: + - changelog:changed + - title: Deprecated + labels: + - changelog:deprecated + - title: Removed + labels: + - changelog:removed + - title: Fixed + labels: + - changelog:fixed + - title: Security + labels: + - changelog:security + - title: Other Unsorted Updates + labels: + - "*" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..3cfdd6667 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,17 @@ +name: Release +on: + push: + branches: + - 'main' +jobs: + release-on-push: + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: rymndhng/release-on-push-action@0.23.1 + with: + bump_version_scheme: norelease + tag_prefix: v + use_github_release_notes: true + max_commits: 128 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..8314bc3f4 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,46 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] +### Added +- [\#93](https://github.com/Manta-Network/manta-rs/pull/93) Add Changelog and Update Contributing Guidelines + +### Changed + +### Deprecated + +### Removed + +### Fixed + +### Security + +## [0.4.0] - 2022-06-08 +### Added +- [\#68](https://github.com/Manta-Network/manta-rs/pull/68) Increase Likelihood of Low Probability Events in the Simulation +- [\#66](https://github.com/Manta-Network/manta-rs/pull/66) Add WASM Prover Benchmark +- [\#62](https://github.com/Manta-Network/manta-rs/pull/62) Add Recovery to the Simulation +- [\#57](https://github.com/Manta-Network/manta-rs/pull/57) Add Parameter Generation for Poseidon +- [\#53](https://github.com/Manta-Network/manta-rs/pull/53) Add `serde` implementaion to HD-KDF +- [\#48](https://github.com/Manta-Network/manta-rs/pull/48) Add Contribution Guidelines and Issue/PR Templates +- [\#34](https://github.com/Manta-Network/manta-rs/pull/34) Support Scalar Multiplication from Precomputed Table +- [\#3](https://github.com/Manta-Network/manta-rs/pull/3) Setup Initial Rust CI Pipeline + +### Changed +- [\#64](https://github.com/Manta-Network/manta-rs/pull/64) Improve Synchronization Infrastructure +- [\#59](https://github.com/Manta-Network/manta-rs/pull/59) Improve Ledger API Flexibility and Encoding +- [\#58](https://github.com/Manta-Network/manta-rs/pull/58) Upgrade Simulation to an optional CLI +- [\#42](https://github.com/Manta-Network/manta-rs/pull/42) Convert back to `async` Wallet Interface for WASM + +### Fixed +- [\#88](https://github.com/Manta-Network/manta-rs/pull/88) Downgrade Poseidon to fix Binary Incompatibility +- [\#38](https://github.com/Manta-Network/manta-rs/pull/38) Use Correct `AssetList` as `BalanceState` Implementation +- [\#33](https://github.com/Manta-Network/manta-rs/pull/33) Fix Receiving Key Encoding and Generalize Wallets + +### Security +- [\#50](https://github.com/Manta-Network/manta-rs/pull/50) Remove Trapdoor from Circuit + +[Unreleased]: https://github.com/Manta-Network/manta-rs/compare/v0.4.0...HEAD +[0.4.0]: https://github.com/Manta-Network/manta-rs/releases/tag/v0.4.0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index caf877d6c..894de5d90 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,21 +4,51 @@ Thank you for contributing to the `manta-rs` codebase! Here are some guidelines ## Use Conventional Commits -Please use conventional commits at least for the major changes introduced by your PR. We use the following types: +Please use conventional commits. We use at least the following types: - `feat`: adding a new feature, new functionality to the codebase - `fix`: fixing old code -- `wip`: marked whenever a commit should be considered part of a set of commits that together implement a feature or fix - `chore`: small changes/commits that are left over from other commits +- `wip`: marked whenever a commit should be considered part of a set of commits that together implement a feature or fix + +See the [conventional commits specification](https://www.conventionalcommits.org) for more details on how to write and use conventional commits. We use squashing for our PRs so we can add types to commits and reformat them according to the spec if you forget to include them. PR titles should also follow conventional commits with the major category that the PR belongs to (except for `wip` which should only be for commits). + +## Changelog + +We use the [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) specification for [`CHANGELOG.md`](./CHANGELOG.md). Whenever we add a new PR we want to make sure to add **one** line to the changelog with the following format: + +```text +- [\#3](https://github.com/Manta-Network/manta-rs/pull/3) Setup Initial Rust CI Pipeline +``` -See the [conventional commits specification](https://www.conventionalcommits.org) for more details on how to write and use conventional commits. We use squash and rebase merge for our PRs so we can add types to commits and reformat them according to the spec if you forget to include them. +in any of the relevant categories outlined in the changelog spec: + +- `Added` for new features. +- `Changed` for changes in existing functionality. +- `Deprecated` for soon-to-be removed features. +- `Removed` for now removed features. +- `Fixed` for any bug fixes. +- `Security` in case of vulnerabilities. + +Like the rest of the specification entails, all changes should be presented in reverse-chronological order. To label a PR as belonging to any one of these categories for inclusion in the GitHub auto-generated release notes, use the following labels: + +- `changelog:added` +- `changelog:changed` +- `changelog:deprecated` +- `changelog:removed` +- `changelog:fixed` +- `changelog:security` + +to place each PR in its respective category or use `changelog:skip` if it should not be included in the GitHub auto-generated release notes. + +## Pull Requests + +See the [`PULL_REQUEST_TEMPLATE.md`](./.github/PULL_REQUEST_TEMPLATE.md) for more details on how to build a good PR. ## Style Guide To keep code and documentation style consistent across all the code in the repository, we are adopting the following style guide. We begin with the formatting style enforced by the Nightly version of `rustfmt` with configuration specified in the [`.rustfmt.toml`](./.rustfmt.toml) file. Beyond what `rustfmt` currently enforces we have specified other rules below. -### General Gramatical Structures - ### The `Cargo.toml` File The `Cargo.toml` file should ahere to the following template: @@ -72,7 +102,7 @@ maintenance = { status = "actively-developed" } Specifically, we have: 1. Use double quotes instead of single quotes. -2. Use the standard ordering of the `[package]` map. +2. Use the above as the standard ordering of the `[package]` map. 3. `[[bin]]` before `[features]` before `[dependencies]` before `[dev-dependencies]` before `[build-dependencies]` before `[profile]` settings. 4. Order features and dependencies alphabetically. 5. When selecting features for a `[features]` entry or when selecting the features on a dependency, order the features alphabetically. @@ -80,7 +110,7 @@ Specifically, we have: ```toml crate-name = { version = "...", optional = true, default-features = false, features = ["..."] } ``` - If the crate is a `path` or `git` dependency, replace those keys with the `version` key. + If the crate is a `path` or `git` dependency, replace those keys with the `version` key and add a `tag`, `branch`, or `rev` as needed following the `git` key. 7. When adding a feature, add a doc string in title case and a newline between each feature. ### Feature Selection diff --git a/Cargo.toml b/Cargo.toml index 3fe38ff37..e4d637955 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,3 @@ members = [ "manta-pay", "manta-util", ] - diff --git a/README.md b/README.md index e955c4878..d29685a6e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ + + github-banner + + # manta-rs [![Workflow Status](https://flat.badgen.net/github/checks/Manta-Network/manta-rs?label=workflow)](https://github.com/Manta-Network/manta-rs/actions) @@ -5,3 +9,19 @@ _Rust Crates for the Manta Network Ecosystem_ +
+ +## About + +The `manta-rs` libraries represent the core logic of the Manta Network protocols shared across all of its products. This project is built as a monorepo for the foundational Rust codebase of Manta. See the following repositories for projects by Manta Network that build off of `manta-rs`: + +- [`Manta`](https://github.com/manta-network/Manta): Core blockchain node implementations built on [`substrate`](https://github.com/paritytech/substrate) +- [`manta-signer`](https://github.com/manta-network/manta-signer): Desktop ZKP prover and wallet implementation +- [`manta-front-end`](https://github.com/manta-network/manta-front-end): Web dApp for interacting with Manta networks +- [`sdk`](https://github.com/manta-network/sdk): Software Development Kit for building wallets and dApps on top of Manta + +The protocols implemented in `manta-rs` are described by the [Manta Specifications](https://github.com/manta-network/spec). See those documents for more information. + +## Contributing + +To contribute to `manta-rs` please read the [`CONTRIBUTING.md`](./CONTRIBUTING.md) file for more details. diff --git a/logo.svg b/logo.svg new file mode 100644 index 000000000..7fe38f8e1 --- /dev/null +++ b/logo.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/manta-benchmark/Cargo.toml b/manta-benchmark/Cargo.toml index e6f1f2fba..305d3deb9 100644 --- a/manta-benchmark/Cargo.toml +++ b/manta-benchmark/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = 'manta-benchmark' -version = '0.4.0' +name = "manta-benchmark" +version = "0.4.0" edition = "2021" authors = ["Manta Network "] -readme = 'README.md' +readme = "README.md" license-file = "LICENSE" repository = "https://github.com/Manta-Network/manta-rs" homepage = "https://github.com/Manta-Network" @@ -35,14 +35,14 @@ name = "reclaim" harness = false [dependencies] -getrandom = { version = "0.2", features = ["js"]} -instant = { version = "0.1", features = [ "wasm-bindgen" ] } +getrandom = { version = "0.2.6", features = ["js"]} +instant = { version = "0.1.12", features = [ "wasm-bindgen" ] } manta-accounting = { path = "../manta-accounting", default-features = false, features = ["test"] } manta-crypto = { path = "../manta-crypto", default-features = false, features = ["getrandom", "test"] } manta-pay = { path = "../manta-pay", default-features = false, features = ["groth16", "test"] } -wasm-bindgen = "0.2" -wasm-bindgen-test = { version = "0.3"} -web-sys = { version = "0.3", features = ["console"]} +wasm-bindgen = { version = "0.2.28", default-features = false } +wasm-bindgen-test = { version = "0.3.30", default-features = false } +web-sys = { version = "0.3.57", default-features = false, features = ["console"] } [dev-dependencies] criterion = { version = "0.3.4", default-features = false } diff --git a/manta-crypto/Cargo.toml b/manta-crypto/Cargo.toml index a91780a12..ee53c46d1 100644 --- a/manta-crypto/Cargo.toml +++ b/manta-crypto/Cargo.toml @@ -45,4 +45,3 @@ rand_core = { version = "0.6.3", default-features = false } [dev-dependencies] rand = "0.8.4" - From b729f00fe7dbbf1b24f27eb6afe4e573b4bbeae2 Mon Sep 17 00:00:00 2001 From: Conghao Shen Date: Thu, 9 Jun 2022 13:08:48 -0700 Subject: [PATCH 04/12] chore: update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8314bc3f4..37abee16a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] ### Added - [\#93](https://github.com/Manta-Network/manta-rs/pull/93) Add Changelog and Update Contributing Guidelines +- [\#90](https://github.com/Manta-Network/manta-rs/pull/90) Add Binary Compatibility Test for `manta-pay` ### Changed From 4a4862ad05137a0f64494765af43109e484a9361 Mon Sep 17 00:00:00 2001 From: Boyuan Feng Date: Tue, 14 Jun 2022 16:10:50 -0400 Subject: [PATCH 05/12] fix: refactor shared prove&verify code --- manta-benchmark/benches/mint.rs | 3 +- manta-benchmark/benches/private_transfer.rs | 5 +- manta-benchmark/benches/reclaim.rs | 5 +- manta-benchmark/src/lib.rs | 11 +- manta-pay/src/lib.rs | 1 + {manta-benchmark => manta-pay}/src/payment.rs | 5 +- manta-pay/src/test/compat.rs | 232 +++--------------- 7 files changed, 45 insertions(+), 217 deletions(-) rename {manta-benchmark => manta-pay}/src/payment.rs (98%) diff --git a/manta-benchmark/benches/mint.rs b/manta-benchmark/benches/mint.rs index b6a44ec08..9d570d0ae 100644 --- a/manta-benchmark/benches/mint.rs +++ b/manta-benchmark/benches/mint.rs @@ -15,9 +15,8 @@ // along with manta-rs. If not, see . use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use manta_benchmark::payment; use manta_crypto::rand::{OsRng, Rand}; -use manta_pay::parameters; +use manta_pay::{parameters, payment}; fn prove(c: &mut Criterion) { let mut group = c.benchmark_group("bench"); diff --git a/manta-benchmark/benches/private_transfer.rs b/manta-benchmark/benches/private_transfer.rs index 68a6451fa..203c38ae0 100644 --- a/manta-benchmark/benches/private_transfer.rs +++ b/manta-benchmark/benches/private_transfer.rs @@ -15,9 +15,8 @@ // along with manta-rs. If not, see . use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use manta_benchmark::payment::{self, assert_valid_proof}; use manta_crypto::rand::OsRng; -use manta_pay::parameters; +use manta_pay::{parameters, payment}; fn prove(c: &mut Criterion) { let mut group = c.benchmark_group("bench"); @@ -48,7 +47,7 @@ fn verify(c: &mut Criterion) { )); group.bench_function("private transfer verify", |b| { b.iter(|| { - assert_valid_proof(&verifying_context.private_transfer, &private_transfer); + payment::assert_valid_proof(&verifying_context.private_transfer, &private_transfer); }) }); } diff --git a/manta-benchmark/benches/reclaim.rs b/manta-benchmark/benches/reclaim.rs index ba0547b93..10ae4d815 100644 --- a/manta-benchmark/benches/reclaim.rs +++ b/manta-benchmark/benches/reclaim.rs @@ -15,9 +15,8 @@ // along with manta-rs. If not, see . use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use manta_benchmark::payment::{self, assert_valid_proof}; use manta_crypto::rand::OsRng; -use manta_pay::parameters; +use manta_pay::{parameters, payment}; fn prove(c: &mut Criterion) { let mut group = c.benchmark_group("bench"); @@ -48,7 +47,7 @@ fn verify(c: &mut Criterion) { )); group.bench_function("reclaim verify", |b| { b.iter(|| { - assert_valid_proof(&verifying_context.reclaim, &reclaim); + payment::assert_valid_proof(&verifying_context.reclaim, &reclaim); }) }); } diff --git a/manta-benchmark/src/lib.rs b/manta-benchmark/src/lib.rs index 95b54b4d9..9b0f76818 100644 --- a/manta-benchmark/src/lib.rs +++ b/manta-benchmark/src/lib.rs @@ -14,18 +14,15 @@ // You should have received a copy of the GNU General Public License // along with manta-rs. If not, see . -use crate::payment::assert_valid_proof; use manta_crypto::rand::{OsRng, Rand}; use manta_pay::{ config::{ MultiProvingContext, MultiVerifyingContext, Parameters, TransferPost, UtxoAccumulatorModel, }, - parameters, + parameters, payment, }; use wasm_bindgen::prelude::wasm_bindgen; -pub mod payment; - #[wasm_bindgen] #[derive(Clone, Debug)] pub struct Context { @@ -95,15 +92,15 @@ pub fn prove_reclaim(context: &Context) -> Proof { #[wasm_bindgen] pub fn verify_mint(context: &Context, proof: &Proof) { - assert_valid_proof(&context.verifying_context.mint, &proof.0); + payment::assert_valid_proof(&context.verifying_context.mint, &proof.0); } #[wasm_bindgen] pub fn verify_private_transfer(context: &Context, proof: &Proof) { - assert_valid_proof(&context.verifying_context.private_transfer, &proof.0); + payment::assert_valid_proof(&context.verifying_context.private_transfer, &proof.0); } #[wasm_bindgen] pub fn verify_reclaim(context: &Context, proof: &Proof) { - assert_valid_proof(&context.verifying_context.reclaim, &proof.0); + payment::assert_valid_proof(&context.verifying_context.reclaim, &proof.0); } diff --git a/manta-pay/src/lib.rs b/manta-pay/src/lib.rs index 43582d0f0..8d7958d30 100644 --- a/manta-pay/src/lib.rs +++ b/manta-pay/src/lib.rs @@ -27,6 +27,7 @@ extern crate alloc; mod test; pub mod crypto; +pub mod payment; pub mod util; #[cfg(feature = "groth16")] diff --git a/manta-benchmark/src/payment.rs b/manta-pay/src/payment.rs similarity index 98% rename from manta-benchmark/src/payment.rs rename to manta-pay/src/payment.rs index 342a3b1f7..631b76159 100644 --- a/manta-benchmark/src/payment.rs +++ b/manta-pay/src/payment.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with manta-rs. If not, see . -//! prove and verify functions for benchmark +//! Prove and Verify Functions for Benchmark and Test Purposes use manta_accounting::{ asset::{Asset, AssetId}, @@ -26,7 +26,7 @@ use manta_crypto::{ merkle_tree::{forest::TreeArrayMerkleForest, full::Full}, rand::{CryptoRng, Rand, RngCore, Sample}, }; -use manta_pay::config::{ +use crate::config::{ self, FullParameters, MerkleTreeConfiguration, Mint, MultiProvingContext, Parameters, PrivateTransfer, ProofSystem, ProvingContext, Reclaim, UtxoAccumulatorModel, VerifyingContext, }; @@ -111,7 +111,6 @@ where let asset_id = AssetId(rng.gen()); let asset_0 = asset_id.value(10_000); let asset_1 = asset_id.value(20_000); - let mut utxo_accumulator = UtxoAccumulator::new(utxo_accumulator_model.clone()); let (spending_key_0, sender_0) = sample_mint_context(parameters, &mut utxo_accumulator, asset_0, rng); diff --git a/manta-pay/src/test/compat.rs b/manta-pay/src/test/compat.rs index 5aa2cce9a..3da1e9106 100644 --- a/manta-pay/src/test/compat.rs +++ b/manta-pay/src/test/compat.rs @@ -19,31 +19,20 @@ // This test is adapted from https://github.com/Manta-Network/Manta/blob/1c5c4b8750d06cb028fb555813414a5802554817/pallets/manta-pay/src/bin/precompute_coins.rs -use crate::config::{ - self, FullParameters, MerkleTreeConfiguration, Mint, MultiProvingContext, - MultiVerifyingContext, NoteEncryptionScheme, Parameters, PrivateTransfer, ProofSystem, - ProvingContext, Reclaim, TransferPost, UtxoAccumulatorModel, UtxoCommitmentScheme, - VerifyingContext, VoidNumberCommitmentScheme, +use crate::{ + config::{ + MultiProvingContext, MultiVerifyingContext, NoteEncryptionScheme, Parameters, + ProvingContext, UtxoAccumulatorModel, UtxoCommitmentScheme, VerifyingContext, + VoidNumberCommitmentScheme, + }, + payment::{assert_valid_proof, prove_mint, prove_private_transfer, prove_reclaim}, }; use anyhow::Result; use ark_std::rand::thread_rng; -use manta_accounting::{ - asset::{Asset, AssetId}, - transfer::{self, SpendingKey}, -}; -use manta_crypto::{ - accumulator::Accumulator, - constraint::ProofSystem as _, - merkle_tree::{forest::TreeArrayMerkleForest, full::Full}, - rand::{CryptoRng, Rand, RngCore, Sample}, -}; +use manta_crypto::rand::Rand; use manta_util::codec::{Decode, IoReader}; use std::{fs::File, path::Path}; -/// UTXO Accumulator for Building Circuits -type UtxoAccumulator = - TreeArrayMerkleForest, 256>; - /// Loads parameters from the SDK, using `directory` as a temporary directory to store files. #[inline] fn load_parameters( @@ -114,194 +103,39 @@ fn load_parameters( )) } -/// Asserts that `post` represents a valid `Transfer` verifying against `verifying_context`. -#[inline] -fn assert_valid_proof(verifying_context: &VerifyingContext, post: &config::TransferPost) { - assert!( - ProofSystem::verify( - verifying_context, - &post.generate_proof_input(), - &post.validity_proof, - ) - .expect("Unable to verify proof."), - "Invalid proof: {:?}.", - post - ); -} - -/// Samples a [`Mint`] transaction. -#[inline] -fn sample_mint( - proving_context: &ProvingContext, - verifying_context: &VerifyingContext, - parameters: &Parameters, - utxo_accumulator_model: &UtxoAccumulatorModel, - asset: Asset, - rng: &mut R, -) -> TransferPost -where - R: CryptoRng + RngCore + ?Sized, -{ - let mint = Mint::from_spending_key(parameters, &SpendingKey::gen(rng), asset, rng) - .into_post( - FullParameters::new(parameters, utxo_accumulator_model), - proving_context, - rng, - ) - .expect("Unable to build MINT proof."); - assert_valid_proof(verifying_context, &mint); - mint -} - -/// Samples a [`PrivateTransfer`] transaction under two [`Mint`]s. -#[inline] -fn sample_private_transfer( - proving_context: &MultiProvingContext, - verifying_context: &MultiVerifyingContext, - parameters: &Parameters, - utxo_accumulator_model: &UtxoAccumulatorModel, - asset_0: Asset, - asset_1: Asset, - rng: &mut R, -) -> ([TransferPost; 2], TransferPost) -where - R: CryptoRng + RngCore + ?Sized, -{ - let mut utxo_accumulator = UtxoAccumulator::new(utxo_accumulator_model.clone()); - let spending_key_0 = SpendingKey::new(rng.gen(), rng.gen()); - let (mint_0, pre_sender_0) = transfer::test::sample_mint( - &proving_context.mint, - FullParameters::new(parameters, utxo_accumulator.model()), - &spending_key_0, - asset_0, - rng, - ) - .expect("Unable to build MINT proof."); - assert_valid_proof(&verifying_context.mint, &mint_0); - let sender_0 = pre_sender_0 - .insert_and_upgrade(&mut utxo_accumulator) - .expect("Just inserted so this should not fail."); - let spending_key_1 = SpendingKey::new(rng.gen(), rng.gen()); - let (mint_1, pre_sender_1) = transfer::test::sample_mint( - &proving_context.mint, - FullParameters::new(parameters, utxo_accumulator.model()), - &spending_key_1, - asset_1, - rng, - ) - .expect("Unable to build MINT proof."); - assert_valid_proof(&verifying_context.mint, &mint_1); - let sender_1 = pre_sender_1 - .insert_and_upgrade(&mut utxo_accumulator) - .expect("Just inserted so this should not fail."); - let private_transfer = PrivateTransfer::build( - [sender_0, sender_1], - [ - spending_key_0.receiver(parameters, rng.gen(), asset_1), - spending_key_1.receiver(parameters, rng.gen(), asset_0), - ], - ) - .into_post( - FullParameters::new(parameters, utxo_accumulator.model()), - &proving_context.private_transfer, - rng, - ) - .expect("Unable to build PRIVATE_TRANSFER proof."); - assert_valid_proof(&verifying_context.private_transfer, &private_transfer); - ([mint_0, mint_1], private_transfer) -} - -/// Samples a [`Reclaim`] transaction under two [`Mint`]s. -#[inline] -fn sample_reclaim( - proving_context: &MultiProvingContext, - verifying_context: &MultiVerifyingContext, - parameters: &Parameters, - utxo_accumulator_model: &UtxoAccumulatorModel, - asset_0: Asset, - asset_1: Asset, - rng: &mut R, -) -> ([TransferPost; 2], TransferPost) -where - R: CryptoRng + RngCore + ?Sized, -{ - let mut utxo_accumulator = UtxoAccumulator::new(utxo_accumulator_model.clone()); - let spending_key_0 = SpendingKey::new(rng.gen(), rng.gen()); - let (mint_0, pre_sender_0) = transfer::test::sample_mint( - &proving_context.mint, - FullParameters::new(parameters, utxo_accumulator.model()), - &spending_key_0, - asset_0, - rng, - ) - .expect("Unable to build MINT proof."); - assert_valid_proof(&verifying_context.mint, &mint_0); - let sender_0 = pre_sender_0 - .insert_and_upgrade(&mut utxo_accumulator) - .expect("Just inserted so this should not fail."); - let spending_key_1 = SpendingKey::new(rng.gen(), rng.gen()); - let (mint_1, pre_sender_1) = transfer::test::sample_mint( - &proving_context.mint, - FullParameters::new(parameters, utxo_accumulator.model()), - &spending_key_1, - asset_1, - rng, - ) - .expect("Unable to build MINT proof."); - assert_valid_proof(&verifying_context.mint, &mint_1); - let sender_1 = pre_sender_1 - .insert_and_upgrade(&mut utxo_accumulator) - .expect("Just inserted so this should not fail."); - let reclaim = Reclaim::build( - [sender_0, sender_1], - [spending_key_0.receiver(parameters, rng.gen(), asset_1)], - asset_0, - ) - .into_post( - FullParameters::new(parameters, utxo_accumulator.model()), - &proving_context.reclaim, - rng, - ) - .expect("Unable to build RECLAIM proof."); - assert_valid_proof(&verifying_context.reclaim, &reclaim); - ([mint_0, mint_1], reclaim) -} - /// Test validity on sampled transactions. #[test] fn compatibility() { let directory = tempfile::tempdir().expect("Unable to generate temporary test directory."); - println!("[INFO] Temporary Directory: {:?}", directory); - let mut rng = thread_rng(); let (proving_context, verifying_context, parameters, utxo_accumulator_model) = - load_parameters(directory.path()).expect("failed to load parameters"); - let asset_id: u32 = 8; - - let _ = sample_mint( - &proving_context.mint, + load_parameters(directory.path()).expect("Failed to load parameters"); + assert_valid_proof( &verifying_context.mint, - ¶meters, - &utxo_accumulator_model, - AssetId(asset_id).value(100_000), - &mut rng, + &prove_mint( + &proving_context.mint, + ¶meters, + &utxo_accumulator_model, + rng.gen(), + &mut rng, + ), ); - let _ = sample_private_transfer( - &proving_context, - &verifying_context, - ¶meters, - &utxo_accumulator_model, - AssetId(asset_id).value(10_000), - AssetId(asset_id).value(20_000), - &mut rng, + assert_valid_proof( + &verifying_context.private_transfer, + &prove_private_transfer( + &proving_context, + ¶meters, + &utxo_accumulator_model, + &mut rng, + ), ); - let _ = sample_reclaim( - &proving_context, - &verifying_context, - ¶meters, - &utxo_accumulator_model, - AssetId(asset_id).value(10_000), - AssetId(asset_id).value(20_000), - &mut rng, + assert_valid_proof( + &verifying_context.reclaim, + &prove_reclaim( + &proving_context, + ¶meters, + &utxo_accumulator_model, + &mut rng, + ), ); } From 2929ce210b692400de955f3989688dae7ddccaf2 Mon Sep 17 00:00:00 2001 From: Boyuan Feng Date: Tue, 14 Jun 2022 16:37:33 -0400 Subject: [PATCH 06/12] fix: update formats, cfg, and dependency versions --- manta-benchmark/Cargo.toml | 5 ++--- manta-pay/Cargo.toml | 4 ++-- manta-pay/src/lib.rs | 5 ++++- manta-pay/src/payment.rs | 8 ++++---- manta-pay/src/test/compat.rs | 6 ++---- manta-pay/src/test/mod.rs | 3 +-- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/manta-benchmark/Cargo.toml b/manta-benchmark/Cargo.toml index 30f7aed19..04010321d 100644 --- a/manta-benchmark/Cargo.toml +++ b/manta-benchmark/Cargo.toml @@ -37,12 +37,11 @@ harness = false [dependencies] getrandom = { version = "0.2.6", features = ["js"]} instant = { version = "0.1.12", features = [ "wasm-bindgen" ] } -manta-accounting = { path = "../manta-accounting", default-features = false, features = ["test"] } manta-crypto = { path = "../manta-crypto", default-features = false, features = ["getrandom", "test"] } manta-pay = { path = "../manta-pay", default-features = false, features = ["groth16", "test"] } -wasm-bindgen = { version = "0.2.28", default-features = false } +wasm-bindgen = { version = "0.2.81", default-features = false } wasm-bindgen-test = { version = "0.3.30", default-features = false } -web-sys = { version = "0.3.57", default-features = false, features = ["console"] } +web-sys = { version = "0.3.58", default-features = false, features = ["console"] } [dev-dependencies] criterion = { version = "0.3.4", default-features = false } diff --git a/manta-pay/Cargo.toml b/manta-pay/Cargo.toml index 8fdba2f68..b18e531a0 100644 --- a/manta-pay/Cargo.toml +++ b/manta-pay/Cargo.toml @@ -117,7 +117,7 @@ ark-std = { version = "0.3.0", optional = true, default-features = false } bip32 = { version = "0.3.0", optional = true, default-features = false, features = ["bip39", "secp256k1"] } blake2 = { version = "0.10.4", default-features = false } bs58 = { version = "0.4.0", optional = true, default-features = false, features = ["alloc"] } -clap = { version = "3.1.18", optional = true, default-features = false, features = ["color", "derive", "std", "suggestions", "unicode", "wrap_help"] } +clap = { version = "3.2.1", optional = true, default-features = false, features = ["color", "derive", "std", "suggestions", "unicode", "wrap_help"] } derivative = { version = "2.2.0", default-features = false, features = ["use_core"] } futures = { version = "0.3.21", optional = true, default-features = false } indexmap = { version = "1.8.2", optional = true, default-features = false } @@ -141,5 +141,5 @@ ws_stream_wasm = { version = "0.7.3", optional = true, default-features = false manta-crypto = { path = "../manta-crypto", default-features = false, features = ["getrandom"] } manta-pay = { path = ".", default-features = false, features = ["groth16", "scale", "scale-std", "std", "test"] } manta-sdk = { git = "https://github.com/manta-network/sdk.git", default-features = false, features = ["download"]} -anyhow = "1.0.55" +anyhow = "1.0.56" tempfile = { version = "3.3.0", default-features = false } diff --git a/manta-pay/src/lib.rs b/manta-pay/src/lib.rs index 8d7958d30..4bb344617 100644 --- a/manta-pay/src/lib.rs +++ b/manta-pay/src/lib.rs @@ -27,7 +27,6 @@ extern crate alloc; mod test; pub mod crypto; -pub mod payment; pub mod util; #[cfg(feature = "groth16")] @@ -42,6 +41,10 @@ pub mod key; #[cfg_attr(doc_cfg, doc(cfg(all(feature = "groth16", feature = "test"))))] pub mod parameters; +#[cfg(all(feature = "groth16", feature = "test"))] +#[cfg_attr(doc_cfg, doc(cfg(all(feature = "groth16", feature = "test"))))] +pub mod payment; + #[cfg(feature = "groth16")] #[cfg_attr(doc_cfg, doc(cfg(feature = "groth16")))] pub mod signer; diff --git a/manta-pay/src/payment.rs b/manta-pay/src/payment.rs index 631b76159..9fd610ce8 100644 --- a/manta-pay/src/payment.rs +++ b/manta-pay/src/payment.rs @@ -16,6 +16,10 @@ //! Prove and Verify Functions for Benchmark and Test Purposes +use crate::config::{ + self, FullParameters, MerkleTreeConfiguration, Mint, MultiProvingContext, Parameters, + PrivateTransfer, ProofSystem, ProvingContext, Reclaim, UtxoAccumulatorModel, VerifyingContext, +}; use manta_accounting::{ asset::{Asset, AssetId}, transfer::SpendingKey, @@ -26,10 +30,6 @@ use manta_crypto::{ merkle_tree::{forest::TreeArrayMerkleForest, full::Full}, rand::{CryptoRng, Rand, RngCore, Sample}, }; -use crate::config::{ - self, FullParameters, MerkleTreeConfiguration, Mint, MultiProvingContext, Parameters, - PrivateTransfer, ProofSystem, ProvingContext, Reclaim, UtxoAccumulatorModel, VerifyingContext, -}; /// UTXO Accumulator for Building Circuits type UtxoAccumulator = diff --git a/manta-pay/src/test/compat.rs b/manta-pay/src/test/compat.rs index 3da1e9106..f20024a03 100644 --- a/manta-pay/src/test/compat.rs +++ b/manta-pay/src/test/compat.rs @@ -14,10 +14,8 @@ // You should have received a copy of the GNU General Public License // along with manta-rs. If not, see . -//! ## Manta Pay UTXO Binary Compatibility -//! This test checks if current implementation is compatible with precomputed transactions in Manta SDK. - -// This test is adapted from https://github.com/Manta-Network/Manta/blob/1c5c4b8750d06cb028fb555813414a5802554817/pallets/manta-pay/src/bin/precompute_coins.rs +//! Manta Pay UTXO Binary Compatibility +//! Checks if the current circuit implementation is compatible with precomputed parameters. use crate::{ config::{ diff --git a/manta-pay/src/test/mod.rs b/manta-pay/src/test/mod.rs index 00c86e7c2..f18e69415 100644 --- a/manta-pay/src/test/mod.rs +++ b/manta-pay/src/test/mod.rs @@ -23,6 +23,5 @@ // #[cfg_attr(doc_cfg, doc(cfg(feature = "simulation")))] // pub mod simulation; -pub mod transfer; - pub mod compat; +pub mod transfer; From 4b7a414ff8fe2b613c269eeedab20f446b350e40 Mon Sep 17 00:00:00 2001 From: Boyuan Feng Date: Tue, 14 Jun 2022 18:48:54 -0400 Subject: [PATCH 07/12] fix: change `sdk` to `manta-parameters` --- manta-pay/Cargo.toml | 4 ++-- manta-pay/src/test/compat.rs | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/manta-pay/Cargo.toml b/manta-pay/Cargo.toml index b39675df2..79c596b0a 100644 --- a/manta-pay/Cargo.toml +++ b/manta-pay/Cargo.toml @@ -140,6 +140,6 @@ ws_stream_wasm = { version = "0.7.3", optional = true, default-features = false [dev-dependencies] manta-crypto = { path = "../manta-crypto", default-features = false, features = ["getrandom"] } manta-pay = { path = ".", default-features = false, features = ["groth16", "scale", "scale-std", "std", "test"] } -manta-sdk = { git = "https://github.com/manta-network/sdk.git", default-features = false, features = ["download"]} -anyhow = "1.0.56" +manta-parameters = { path = "../manta-parameters", default-features = false, features = ["download"]} +anyhow = "1.0.57" tempfile = { version = "3.3.0", default-features = false } diff --git a/manta-pay/src/test/compat.rs b/manta-pay/src/test/compat.rs index f20024a03..96bb2566b 100644 --- a/manta-pay/src/test/compat.rs +++ b/manta-pay/src/test/compat.rs @@ -43,11 +43,11 @@ fn load_parameters( )> { println!("Loading parameters..."); let mint_path = directory.join("mint.dat"); - manta_sdk::pay::testnet::proving::Mint::download(&mint_path)?; + manta_parameters::pay::testnet::proving::Mint::download(&mint_path)?; let private_transfer_path = directory.join("private-transfer.dat"); - manta_sdk::pay::testnet::proving::PrivateTransfer::download(&private_transfer_path)?; + manta_parameters::pay::testnet::proving::PrivateTransfer::download(&private_transfer_path)?; let reclaim_path = directory.join("reclaim.dat"); - manta_sdk::pay::testnet::proving::Reclaim::download(&reclaim_path)?; + manta_parameters::pay::testnet::proving::Reclaim::download(&reclaim_path)?; let proving_context = MultiProvingContext { mint: ProvingContext::decode(IoReader(File::open(mint_path)?)) .expect("Unable to decode MINT proving context."), @@ -58,32 +58,32 @@ fn load_parameters( }; let verifying_context = MultiVerifyingContext { mint: VerifyingContext::decode( - manta_sdk::pay::testnet::verifying::Mint::get().expect("Checksum did not match."), + manta_parameters::pay::testnet::verifying::Mint::get().expect("Checksum did not match."), ) .expect("Unable to decode MINT verifying context."), private_transfer: VerifyingContext::decode( - manta_sdk::pay::testnet::verifying::PrivateTransfer::get() + manta_parameters::pay::testnet::verifying::PrivateTransfer::get() .expect("Checksum did not match."), ) .expect("Unable to decode PRIVATE_TRANSFER verifying context."), reclaim: VerifyingContext::decode( - manta_sdk::pay::testnet::verifying::Reclaim::get().expect("Checksum did not match."), + manta_parameters::pay::testnet::verifying::Reclaim::get().expect("Checksum did not match."), ) .expect("Unable to decode RECLAIM verifying context."), }; let parameters = Parameters { note_encryption_scheme: NoteEncryptionScheme::decode( - manta_sdk::pay::testnet::parameters::NoteEncryptionScheme::get() + manta_parameters::pay::testnet::parameters::NoteEncryptionScheme::get() .expect("Checksum did not match."), ) .expect("Unable to decode NOTE_ENCRYPTION_SCHEME parameters."), utxo_commitment: UtxoCommitmentScheme::decode( - manta_sdk::pay::testnet::parameters::UtxoCommitmentScheme::get() + manta_parameters::pay::testnet::parameters::UtxoCommitmentScheme::get() .expect("Checksum did not match."), ) .expect("Unable to decode UTXO_COMMITMENT_SCHEME parameters."), void_number_commitment: VoidNumberCommitmentScheme::decode( - manta_sdk::pay::testnet::parameters::VoidNumberCommitmentScheme::get() + manta_parameters::pay::testnet::parameters::VoidNumberCommitmentScheme::get() .expect("Checksum did not match."), ) .expect("Unable to decode VOID_NUMBER_COMMITMENT_SCHEME parameters."), @@ -94,7 +94,7 @@ fn load_parameters( verifying_context, parameters, UtxoAccumulatorModel::decode( - manta_sdk::pay::testnet::parameters::UtxoAccumulatorModel::get() + manta_parameters::pay::testnet::parameters::UtxoAccumulatorModel::get() .expect("Checksum did not match."), ) .expect("Unable to decode UTXO_ACCUMULATOR_MODEL."), From 94293fcf08a4c9aadae765cdce457bbc84c3338b Mon Sep 17 00:00:00 2001 From: Boyuan Feng Date: Tue, 14 Jun 2022 18:49:57 -0400 Subject: [PATCH 08/12] fix: format --- manta-pay/Cargo.toml | 148 +++++++++++++++++------------------ manta-pay/src/test/compat.rs | 6 +- 2 files changed, 78 insertions(+), 76 deletions(-) diff --git a/manta-pay/Cargo.toml b/manta-pay/Cargo.toml index 79c596b0a..e4febc01e 100644 --- a/manta-pay/Cargo.toml +++ b/manta-pay/Cargo.toml @@ -1,17 +1,17 @@ [package] -name = "manta-pay" -version = "0.5.0" -edition = "2021" authors = ["Manta Network "] -readme = "README.md" -license-file = "LICENSE" -repository = "https://github.com/Manta-Network/manta-rs" -homepage = "https://github.com/Manta-Network" -documentation = "https://github.com/Manta-Network/manta-rs" categories = [""] -keywords = [""] description = "The Manta-Pay protocol and implementaion." +documentation = "https://github.com/Manta-Network/manta-rs" +edition = "2021" +homepage = "https://github.com/Manta-Network" +keywords = [""] +license-file = "LICENSE" +name = "manta-pay" publish = false +readme = "README.md" +repository = "https://github.com/Manta-Network/manta-rs" +version = "0.5.0" [package.metadata.docs.rs] # To build locally: @@ -20,9 +20,9 @@ all-features = true rustdoc-args = ["--cfg", "doc_cfg"] [badges] -is-it-maintained-issue-resolution = { repository = "Manta-Network/manta-rs" } -is-it-maintained-open-issues = { repository = "Manta-Network/manta-rs" } -maintenance = { status = "actively-developed" } +is-it-maintained-issue-resolution = {repository = "Manta-Network/manta-rs"} +is-it-maintained-open-issues = {repository = "Manta-Network/manta-rs"} +maintenance = {status = "actively-developed"} [[bin]] name = "generate_parameters" @@ -39,14 +39,14 @@ required-features = ["clap", "groth16", "simulation"] [features] # Enable Arkworks Backend arkworks = [ - "ark-bls12-381", - "ark-ec", - "ark-ed-on-bls12-381", - "ark-ff", - "ark-r1cs-std", - "ark-relations", - "ark-serialize", - "ark-std", + "ark-bls12-381", + "ark-ec", + "ark-ed-on-bls12-381", + "ark-ff", + "ark-r1cs-std", + "ark-relations", + "ark-serialize", + "ark-std", ] # Enable Groth16 ZKP System @@ -69,17 +69,17 @@ serde = ["manta-accounting/serde", "manta-crypto/serde"] # Simulation Framework simulation = [ - "indexmap", - "parking_lot", - "rayon", - "test", - "tide", - "tokio/io-std", - "tokio/io-util", - "tokio/macros", - "tokio/rt-multi-thread", - "tokio/sync", - "wallet", + "indexmap", + "parking_lot", + "rayon", + "test", + "tide", + "tokio/io-std", + "tokio/io-util", + "tokio/macros", + "tokio/rt-multi-thread", + "tokio/sync", + "wallet", ] # Standard Library @@ -93,53 +93,53 @@ wallet = ["bip32", "manta-crypto/getrandom", "std"] # Enable WebSocket Signer Client websocket = [ - "futures", - "serde", - "serde_json", - "std", - "tokio", - "tokio-tungstenite/connect", - "ws_stream_wasm", + "futures", + "serde", + "serde_json", + "std", + "tokio", + "tokio-tungstenite/connect", + "ws_stream_wasm", ] [dependencies] -aes-gcm = { version = "0.9.4", default-features = false, features = ["aes", "alloc"] } -ark-bls12-381 = { version = "0.3.0", optional = true, default-features = false, features = ["curve"] } -ark-ec = { version = "0.3.0", optional = true, default-features = false } -ark-ed-on-bls12-381 = { version = "0.3.0", optional = true, default-features = false, features = ["r1cs"] } -ark-ff = { version = "0.3.0", optional = true, default-features = false } -ark-groth16 = { version = "0.3.0", optional = true, default-features = false } -ark-r1cs-std = { version = "0.3.1", optional = true, default-features = false } -ark-relations = { version = "0.3.0", optional = true, default-features = false } -ark-serialize = { version = "0.3.0", optional = true, default-features = false, features = ["derive"] } -ark-snark = { version = "0.3.0", optional = true, default-features = false } -ark-std = { version = "0.3.0", optional = true, default-features = false } -bip32 = { version = "0.3.0", optional = true, default-features = false, features = ["bip39", "secp256k1"] } -blake2 = { version = "0.10.4", default-features = false } -bs58 = { version = "0.4.0", optional = true, default-features = false, features = ["alloc"] } -clap = { version = "3.2.4", optional = true, default-features = false, features = ["color", "derive", "std", "suggestions", "unicode", "wrap_help"] } -derivative = { version = "2.2.0", default-features = false, features = ["use_core"] } -futures = { version = "0.3.21", optional = true, default-features = false } -indexmap = { version = "1.8.2", optional = true, default-features = false } -manta-accounting = { path = "../manta-accounting", default-features = false } -manta-crypto = { path = "../manta-crypto", default-features = false } -manta-util = { path = "../manta-util", default-features = false } -parking_lot = { version = "0.12.1", optional = true, default-features = false } -rand_chacha = { version = "0.3.1", default-features = false } -rayon = { version = "1.5.1", optional = true, default-features = false } -reqwest = { version = "0.11.9", optional = true, default-features = false, features = ["json"] } -scale-codec = { package = "parity-scale-codec", version = "3.1.2", optional = true, default-features = false, features = ["derive", "max-encoded-len"] } -scale-info = { version = "2.1.2", optional = true, default-features = false, features = ["derive"] } -serde_json = { version = "1.0.79", optional = true, default-features = false, features = ["alloc"] } -tide = { version = "0.16.0", optional = true, default-features = false, features = ["h1-server"] } -tokio = { version = "1.18.2", optional = true, default-features = false } -tokio-tungstenite = { version = "0.17.1", optional = true, default-features = false, features = ["native-tls"] } -ws_stream_wasm = { version = "0.7.3", optional = true, default-features = false } +aes-gcm = {version = "0.9.4", default-features = false, features = ["aes", "alloc"]} +ark-bls12-381 = {version = "0.3.0", optional = true, default-features = false, features = ["curve"]} +ark-ec = {version = "0.3.0", optional = true, default-features = false} +ark-ed-on-bls12-381 = {version = "0.3.0", optional = true, default-features = false, features = ["r1cs"]} +ark-ff = {version = "0.3.0", optional = true, default-features = false} +ark-groth16 = {version = "0.3.0", optional = true, default-features = false} +ark-r1cs-std = {version = "0.3.1", optional = true, default-features = false} +ark-relations = {version = "0.3.0", optional = true, default-features = false} +ark-serialize = {version = "0.3.0", optional = true, default-features = false, features = ["derive"]} +ark-snark = {version = "0.3.0", optional = true, default-features = false} +ark-std = {version = "0.3.0", optional = true, default-features = false} +bip32 = {version = "0.3.0", optional = true, default-features = false, features = ["bip39", "secp256k1"]} +blake2 = {version = "0.10.4", default-features = false} +bs58 = {version = "0.4.0", optional = true, default-features = false, features = ["alloc"]} +clap = {version = "3.2.4", optional = true, default-features = false, features = ["color", "derive", "std", "suggestions", "unicode", "wrap_help"]} +derivative = {version = "2.2.0", default-features = false, features = ["use_core"]} +futures = {version = "0.3.21", optional = true, default-features = false} +indexmap = {version = "1.8.2", optional = true, default-features = false} +manta-accounting = {path = "../manta-accounting", default-features = false} +manta-crypto = {path = "../manta-crypto", default-features = false} +manta-util = {path = "../manta-util", default-features = false} +parking_lot = {version = "0.12.1", optional = true, default-features = false} +rand_chacha = {version = "0.3.1", default-features = false} +rayon = {version = "1.5.1", optional = true, default-features = false} +reqwest = {version = "0.11.9", optional = true, default-features = false, features = ["json"]} +scale-codec = {package = "parity-scale-codec", version = "3.1.2", optional = true, default-features = false, features = ["derive", "max-encoded-len"]} +scale-info = {version = "2.1.2", optional = true, default-features = false, features = ["derive"]} +serde_json = {version = "1.0.79", optional = true, default-features = false, features = ["alloc"]} +tide = {version = "0.16.0", optional = true, default-features = false, features = ["h1-server"]} +tokio = {version = "1.18.2", optional = true, default-features = false} +tokio-tungstenite = {version = "0.17.1", optional = true, default-features = false, features = ["native-tls"]} +ws_stream_wasm = {version = "0.7.3", optional = true, default-features = false} # TODO: zk-garage-plonk = { package = "plonk", git = "https://github.com/zk-garage/plonk", optional = true, default-features = false } [dev-dependencies] -manta-crypto = { path = "../manta-crypto", default-features = false, features = ["getrandom"] } -manta-pay = { path = ".", default-features = false, features = ["groth16", "scale", "scale-std", "std", "test"] } -manta-parameters = { path = "../manta-parameters", default-features = false, features = ["download"]} anyhow = "1.0.57" -tempfile = { version = "3.3.0", default-features = false } +manta-crypto = {path = "../manta-crypto", default-features = false, features = ["getrandom"]} +manta-parameters = {path = "../manta-parameters", default-features = false, features = ["download"]} +manta-pay = {path = ".", default-features = false, features = ["groth16", "scale", "scale-std", "std", "test"]} +tempfile = {version = "3.3.0", default-features = false} diff --git a/manta-pay/src/test/compat.rs b/manta-pay/src/test/compat.rs index 96bb2566b..fd5abcc19 100644 --- a/manta-pay/src/test/compat.rs +++ b/manta-pay/src/test/compat.rs @@ -58,7 +58,8 @@ fn load_parameters( }; let verifying_context = MultiVerifyingContext { mint: VerifyingContext::decode( - manta_parameters::pay::testnet::verifying::Mint::get().expect("Checksum did not match."), + manta_parameters::pay::testnet::verifying::Mint::get() + .expect("Checksum did not match."), ) .expect("Unable to decode MINT verifying context."), private_transfer: VerifyingContext::decode( @@ -67,7 +68,8 @@ fn load_parameters( ) .expect("Unable to decode PRIVATE_TRANSFER verifying context."), reclaim: VerifyingContext::decode( - manta_parameters::pay::testnet::verifying::Reclaim::get().expect("Checksum did not match."), + manta_parameters::pay::testnet::verifying::Reclaim::get() + .expect("Checksum did not match."), ) .expect("Unable to decode RECLAIM verifying context."), }; From e3e5141519a52c7a89fce61391caf4701cd8d1eb Mon Sep 17 00:00:00 2001 From: Boyuan Feng Date: Wed, 15 Jun 2022 12:38:36 -0400 Subject: [PATCH 09/12] fix: file names --- manta-benchmark/benches/mint.rs | 8 ++++---- manta-benchmark/benches/private_transfer.rs | 8 ++++---- manta-benchmark/benches/reclaim.rs | 8 ++++---- manta-benchmark/src/lib.rs | 14 +++++++------- manta-pay/src/lib.rs | 2 +- manta-pay/src/{payment.rs => sample_payment.rs} | 0 manta-pay/src/test/{compat.rs => compatibility.rs} | 5 +++-- manta-pay/src/test/mod.rs | 2 +- 8 files changed, 24 insertions(+), 23 deletions(-) rename manta-pay/src/{payment.rs => sample_payment.rs} (100%) rename manta-pay/src/test/{compat.rs => compatibility.rs} (95%) diff --git a/manta-benchmark/benches/mint.rs b/manta-benchmark/benches/mint.rs index 9d570d0ae..5e48ed7f6 100644 --- a/manta-benchmark/benches/mint.rs +++ b/manta-benchmark/benches/mint.rs @@ -16,7 +16,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; use manta_crypto::rand::{OsRng, Rand}; -use manta_pay::{parameters, payment}; +use manta_pay::{parameters, sample_payment}; fn prove(c: &mut Criterion) { let mut group = c.benchmark_group("bench"); @@ -26,7 +26,7 @@ fn prove(c: &mut Criterion) { group.bench_function("mint prove", |b| { let asset = black_box(rng.gen()); b.iter(|| { - payment::prove_mint( + sample_payment::prove_mint( &proving_context.mint, ¶meters, &utxo_accumulator_model, @@ -42,7 +42,7 @@ fn verify(c: &mut Criterion) { let (proving_context, verifying_context, parameters, utxo_accumulator_model) = parameters::generate().unwrap(); let mut rng = OsRng; - let mint = black_box(payment::prove_mint( + let mint = black_box(sample_payment::prove_mint( &proving_context.mint, ¶meters, &utxo_accumulator_model, @@ -51,7 +51,7 @@ fn verify(c: &mut Criterion) { )); group.bench_function("mint verify", |b| { b.iter(|| { - payment::assert_valid_proof(&verifying_context.mint, &mint); + sample_payment::assert_valid_proof(&verifying_context.mint, &mint); }) }); } diff --git a/manta-benchmark/benches/private_transfer.rs b/manta-benchmark/benches/private_transfer.rs index 203c38ae0..eae3ca2a4 100644 --- a/manta-benchmark/benches/private_transfer.rs +++ b/manta-benchmark/benches/private_transfer.rs @@ -16,7 +16,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; use manta_crypto::rand::OsRng; -use manta_pay::{parameters, payment}; +use manta_pay::{parameters, sample_payment}; fn prove(c: &mut Criterion) { let mut group = c.benchmark_group("bench"); @@ -24,7 +24,7 @@ fn prove(c: &mut Criterion) { let (proving_context, _, parameters, utxo_accumulator_model) = parameters::generate().unwrap(); group.bench_function("private transfer prove", |b| { b.iter(|| { - let _ = payment::prove_private_transfer( + let _ = sample_payment::prove_private_transfer( &proving_context, ¶meters, &utxo_accumulator_model, @@ -39,7 +39,7 @@ fn verify(c: &mut Criterion) { let mut rng = OsRng; let (proving_context, verifying_context, parameters, utxo_accumulator_model) = parameters::generate().unwrap(); - let private_transfer = black_box(payment::prove_private_transfer( + let private_transfer = black_box(sample_payment::prove_private_transfer( &proving_context, ¶meters, &utxo_accumulator_model, @@ -47,7 +47,7 @@ fn verify(c: &mut Criterion) { )); group.bench_function("private transfer verify", |b| { b.iter(|| { - payment::assert_valid_proof(&verifying_context.private_transfer, &private_transfer); + sample_payment::assert_valid_proof(&verifying_context.private_transfer, &private_transfer); }) }); } diff --git a/manta-benchmark/benches/reclaim.rs b/manta-benchmark/benches/reclaim.rs index 10ae4d815..66f7e4354 100644 --- a/manta-benchmark/benches/reclaim.rs +++ b/manta-benchmark/benches/reclaim.rs @@ -16,7 +16,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; use manta_crypto::rand::OsRng; -use manta_pay::{parameters, payment}; +use manta_pay::{parameters, sample_payment}; fn prove(c: &mut Criterion) { let mut group = c.benchmark_group("bench"); @@ -24,7 +24,7 @@ fn prove(c: &mut Criterion) { let (proving_context, _, parameters, utxo_accumulator_model) = parameters::generate().unwrap(); group.bench_function("reclaim prove", |b| { b.iter(|| { - let _ = payment::prove_reclaim( + let _ = sample_payment::prove_reclaim( &proving_context, ¶meters, &utxo_accumulator_model, @@ -39,7 +39,7 @@ fn verify(c: &mut Criterion) { let mut rng = OsRng; let (proving_context, verifying_context, parameters, utxo_accumulator_model) = parameters::generate().unwrap(); - let reclaim = black_box(payment::prove_reclaim( + let reclaim = black_box(sample_payment::prove_reclaim( &proving_context, ¶meters, &utxo_accumulator_model, @@ -47,7 +47,7 @@ fn verify(c: &mut Criterion) { )); group.bench_function("reclaim verify", |b| { b.iter(|| { - payment::assert_valid_proof(&verifying_context.reclaim, &reclaim); + sample_payment::assert_valid_proof(&verifying_context.reclaim, &reclaim); }) }); } diff --git a/manta-benchmark/src/lib.rs b/manta-benchmark/src/lib.rs index 9b0f76818..ec84518d9 100644 --- a/manta-benchmark/src/lib.rs +++ b/manta-benchmark/src/lib.rs @@ -19,7 +19,7 @@ use manta_pay::{ config::{ MultiProvingContext, MultiVerifyingContext, Parameters, TransferPost, UtxoAccumulatorModel, }, - parameters, payment, + parameters, sample_payment, }; use wasm_bindgen::prelude::wasm_bindgen; @@ -59,7 +59,7 @@ pub struct Proof(TransferPost); #[wasm_bindgen] pub fn prove_mint(context: &Context) -> Proof { let mut rng = OsRng; - Proof(payment::prove_mint( + Proof(sample_payment::prove_mint( &context.proving_context.mint, &context.parameters, &context.utxo_accumulator_model, @@ -71,7 +71,7 @@ pub fn prove_mint(context: &Context) -> Proof { #[wasm_bindgen] pub fn prove_private_transfer(context: &Context) -> Proof { let mut rng = OsRng; - Proof(payment::prove_private_transfer( + Proof(sample_payment::prove_private_transfer( &context.proving_context, &context.parameters, &context.utxo_accumulator_model, @@ -82,7 +82,7 @@ pub fn prove_private_transfer(context: &Context) -> Proof { #[wasm_bindgen] pub fn prove_reclaim(context: &Context) -> Proof { let mut rng = OsRng; - Proof(payment::prove_reclaim( + Proof(sample_payment::prove_reclaim( &context.proving_context, &context.parameters, &context.utxo_accumulator_model, @@ -92,15 +92,15 @@ pub fn prove_reclaim(context: &Context) -> Proof { #[wasm_bindgen] pub fn verify_mint(context: &Context, proof: &Proof) { - payment::assert_valid_proof(&context.verifying_context.mint, &proof.0); + sample_payment::assert_valid_proof(&context.verifying_context.mint, &proof.0); } #[wasm_bindgen] pub fn verify_private_transfer(context: &Context, proof: &Proof) { - payment::assert_valid_proof(&context.verifying_context.private_transfer, &proof.0); + sample_payment::assert_valid_proof(&context.verifying_context.private_transfer, &proof.0); } #[wasm_bindgen] pub fn verify_reclaim(context: &Context, proof: &Proof) { - payment::assert_valid_proof(&context.verifying_context.reclaim, &proof.0); + sample_payment::assert_valid_proof(&context.verifying_context.reclaim, &proof.0); } diff --git a/manta-pay/src/lib.rs b/manta-pay/src/lib.rs index 4bb344617..8a3b25fcd 100644 --- a/manta-pay/src/lib.rs +++ b/manta-pay/src/lib.rs @@ -43,7 +43,7 @@ pub mod parameters; #[cfg(all(feature = "groth16", feature = "test"))] #[cfg_attr(doc_cfg, doc(cfg(all(feature = "groth16", feature = "test"))))] -pub mod payment; +pub mod sample_payment; #[cfg(feature = "groth16")] #[cfg_attr(doc_cfg, doc(cfg(feature = "groth16")))] diff --git a/manta-pay/src/payment.rs b/manta-pay/src/sample_payment.rs similarity index 100% rename from manta-pay/src/payment.rs rename to manta-pay/src/sample_payment.rs diff --git a/manta-pay/src/test/compat.rs b/manta-pay/src/test/compatibility.rs similarity index 95% rename from manta-pay/src/test/compat.rs rename to manta-pay/src/test/compatibility.rs index fd5abcc19..c52bc11f5 100644 --- a/manta-pay/src/test/compat.rs +++ b/manta-pay/src/test/compatibility.rs @@ -23,7 +23,7 @@ use crate::{ ProvingContext, UtxoAccumulatorModel, UtxoCommitmentScheme, VerifyingContext, VoidNumberCommitmentScheme, }, - payment::{assert_valid_proof, prove_mint, prove_private_transfer, prove_reclaim}, + sample_payment::{assert_valid_proof, prove_mint, prove_private_transfer, prove_reclaim}, }; use anyhow::Result; use ark_std::rand::thread_rng; @@ -31,7 +31,7 @@ use manta_crypto::rand::Rand; use manta_util::codec::{Decode, IoReader}; use std::{fs::File, path::Path}; -/// Loads parameters from the SDK, using `directory` as a temporary directory to store files. +/// Loads parameters from the `manta-parameters`, using `directory` as a temporary directory to store files. #[inline] fn load_parameters( directory: &Path, @@ -48,6 +48,7 @@ fn load_parameters( manta_parameters::pay::testnet::proving::PrivateTransfer::download(&private_transfer_path)?; let reclaim_path = directory.join("reclaim.dat"); manta_parameters::pay::testnet::proving::Reclaim::download(&reclaim_path)?; + println!("mint_path: {:?}", mint_path); let proving_context = MultiProvingContext { mint: ProvingContext::decode(IoReader(File::open(mint_path)?)) .expect("Unable to decode MINT proving context."), diff --git a/manta-pay/src/test/mod.rs b/manta-pay/src/test/mod.rs index f18e69415..ac3ca9b14 100644 --- a/manta-pay/src/test/mod.rs +++ b/manta-pay/src/test/mod.rs @@ -23,5 +23,5 @@ // #[cfg_attr(doc_cfg, doc(cfg(feature = "simulation")))] // pub mod simulation; -pub mod compat; +pub mod compatibility; pub mod transfer; From 2fe6195e54de7822ed6b418d87f8c19258c541a3 Mon Sep 17 00:00:00 2001 From: Boyuan Feng Date: Wed, 15 Jun 2022 17:11:17 -0400 Subject: [PATCH 10/12] fix: refactor payment.rs --- manta-accounting/src/transfer/test.rs | 18 ++++++++++++++++++ manta-benchmark/Cargo.toml | 1 + manta-benchmark/benches/mint.rs | 9 +++++---- manta-benchmark/benches/private_transfer.rs | 9 +++++---- manta-benchmark/benches/reclaim.rs | 9 +++++---- manta-benchmark/src/lib.rs | 16 +++++++++------- manta-pay/Cargo.toml | 8 ++++---- manta-pay/src/lib.rs | 9 +++------ manta-pay/src/test/compatibility.rs | 3 ++- manta-pay/src/test/mod.rs | 5 +++++ .../src/{sample_payment.rs => test/payment.rs} | 18 +----------------- 11 files changed, 58 insertions(+), 47 deletions(-) rename manta-pay/src/{sample_payment.rs => test/payment.rs} (89%) diff --git a/manta-accounting/src/transfer/test.rs b/manta-accounting/src/transfer/test.rs index e7ba25a90..902450a39 100644 --- a/manta-accounting/src/transfer/test.rs +++ b/manta-accounting/src/transfer/test.rs @@ -400,3 +400,21 @@ where pre_sender, )) } + +/// Asserts that `post` represents a valid `Transfer` verifying against `verifying_context`. +#[inline] +pub fn assert_valid_proof(verifying_context: &VerifyingContext, post: &TransferPost) +where + C: Configuration, + ::Error: Debug, +{ + assert!( + C::ProofSystem::verify( + verifying_context, + &post.generate_proof_input(), + &post.validity_proof, + ) + .expect("Unable to verify proof."), + "Invalid proof.", + ); +} diff --git a/manta-benchmark/Cargo.toml b/manta-benchmark/Cargo.toml index 04010321d..38d603795 100644 --- a/manta-benchmark/Cargo.toml +++ b/manta-benchmark/Cargo.toml @@ -37,6 +37,7 @@ harness = false [dependencies] getrandom = { version = "0.2.6", features = ["js"]} instant = { version = "0.1.12", features = [ "wasm-bindgen" ] } +manta-accounting = { path = "../manta-accounting", default-features = false, features = ["test"] } manta-crypto = { path = "../manta-crypto", default-features = false, features = ["getrandom", "test"] } manta-pay = { path = "../manta-pay", default-features = false, features = ["groth16", "test"] } wasm-bindgen = { version = "0.2.81", default-features = false } diff --git a/manta-benchmark/benches/mint.rs b/manta-benchmark/benches/mint.rs index 5e48ed7f6..0b1637cd4 100644 --- a/manta-benchmark/benches/mint.rs +++ b/manta-benchmark/benches/mint.rs @@ -15,8 +15,9 @@ // along with manta-rs. If not, see . use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use manta_accounting::transfer::test::assert_valid_proof; use manta_crypto::rand::{OsRng, Rand}; -use manta_pay::{parameters, sample_payment}; +use manta_pay::{parameters, test::payment::prove_mint}; fn prove(c: &mut Criterion) { let mut group = c.benchmark_group("bench"); @@ -26,7 +27,7 @@ fn prove(c: &mut Criterion) { group.bench_function("mint prove", |b| { let asset = black_box(rng.gen()); b.iter(|| { - sample_payment::prove_mint( + prove_mint( &proving_context.mint, ¶meters, &utxo_accumulator_model, @@ -42,7 +43,7 @@ fn verify(c: &mut Criterion) { let (proving_context, verifying_context, parameters, utxo_accumulator_model) = parameters::generate().unwrap(); let mut rng = OsRng; - let mint = black_box(sample_payment::prove_mint( + let mint = black_box(prove_mint( &proving_context.mint, ¶meters, &utxo_accumulator_model, @@ -51,7 +52,7 @@ fn verify(c: &mut Criterion) { )); group.bench_function("mint verify", |b| { b.iter(|| { - sample_payment::assert_valid_proof(&verifying_context.mint, &mint); + assert_valid_proof(&verifying_context.mint, &mint); }) }); } diff --git a/manta-benchmark/benches/private_transfer.rs b/manta-benchmark/benches/private_transfer.rs index eae3ca2a4..6de80dbdd 100644 --- a/manta-benchmark/benches/private_transfer.rs +++ b/manta-benchmark/benches/private_transfer.rs @@ -15,8 +15,9 @@ // along with manta-rs. If not, see . use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use manta_accounting::transfer::test::assert_valid_proof; use manta_crypto::rand::OsRng; -use manta_pay::{parameters, sample_payment}; +use manta_pay::{parameters, test::payment::prove_private_transfer}; fn prove(c: &mut Criterion) { let mut group = c.benchmark_group("bench"); @@ -24,7 +25,7 @@ fn prove(c: &mut Criterion) { let (proving_context, _, parameters, utxo_accumulator_model) = parameters::generate().unwrap(); group.bench_function("private transfer prove", |b| { b.iter(|| { - let _ = sample_payment::prove_private_transfer( + let _ = prove_private_transfer( &proving_context, ¶meters, &utxo_accumulator_model, @@ -39,7 +40,7 @@ fn verify(c: &mut Criterion) { let mut rng = OsRng; let (proving_context, verifying_context, parameters, utxo_accumulator_model) = parameters::generate().unwrap(); - let private_transfer = black_box(sample_payment::prove_private_transfer( + let private_transfer = black_box(prove_private_transfer( &proving_context, ¶meters, &utxo_accumulator_model, @@ -47,7 +48,7 @@ fn verify(c: &mut Criterion) { )); group.bench_function("private transfer verify", |b| { b.iter(|| { - sample_payment::assert_valid_proof(&verifying_context.private_transfer, &private_transfer); + assert_valid_proof(&verifying_context.private_transfer, &private_transfer); }) }); } diff --git a/manta-benchmark/benches/reclaim.rs b/manta-benchmark/benches/reclaim.rs index 66f7e4354..9c83aff11 100644 --- a/manta-benchmark/benches/reclaim.rs +++ b/manta-benchmark/benches/reclaim.rs @@ -15,8 +15,9 @@ // along with manta-rs. If not, see . use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use manta_accounting::transfer::test::assert_valid_proof; use manta_crypto::rand::OsRng; -use manta_pay::{parameters, sample_payment}; +use manta_pay::{parameters, test::payment::prove_reclaim}; fn prove(c: &mut Criterion) { let mut group = c.benchmark_group("bench"); @@ -24,7 +25,7 @@ fn prove(c: &mut Criterion) { let (proving_context, _, parameters, utxo_accumulator_model) = parameters::generate().unwrap(); group.bench_function("reclaim prove", |b| { b.iter(|| { - let _ = sample_payment::prove_reclaim( + let _ = prove_reclaim( &proving_context, ¶meters, &utxo_accumulator_model, @@ -39,7 +40,7 @@ fn verify(c: &mut Criterion) { let mut rng = OsRng; let (proving_context, verifying_context, parameters, utxo_accumulator_model) = parameters::generate().unwrap(); - let reclaim = black_box(sample_payment::prove_reclaim( + let reclaim = black_box(prove_reclaim( &proving_context, ¶meters, &utxo_accumulator_model, @@ -47,7 +48,7 @@ fn verify(c: &mut Criterion) { )); group.bench_function("reclaim verify", |b| { b.iter(|| { - sample_payment::assert_valid_proof(&verifying_context.reclaim, &reclaim); + assert_valid_proof(&verifying_context.reclaim, &reclaim); }) }); } diff --git a/manta-benchmark/src/lib.rs b/manta-benchmark/src/lib.rs index ec84518d9..db17f290c 100644 --- a/manta-benchmark/src/lib.rs +++ b/manta-benchmark/src/lib.rs @@ -14,12 +14,14 @@ // You should have received a copy of the GNU General Public License // along with manta-rs. If not, see . +use manta_accounting::transfer::test::assert_valid_proof; use manta_crypto::rand::{OsRng, Rand}; use manta_pay::{ config::{ MultiProvingContext, MultiVerifyingContext, Parameters, TransferPost, UtxoAccumulatorModel, }, - parameters, sample_payment, + parameters, + test::payment, }; use wasm_bindgen::prelude::wasm_bindgen; @@ -59,7 +61,7 @@ pub struct Proof(TransferPost); #[wasm_bindgen] pub fn prove_mint(context: &Context) -> Proof { let mut rng = OsRng; - Proof(sample_payment::prove_mint( + Proof(payment::prove_mint( &context.proving_context.mint, &context.parameters, &context.utxo_accumulator_model, @@ -71,7 +73,7 @@ pub fn prove_mint(context: &Context) -> Proof { #[wasm_bindgen] pub fn prove_private_transfer(context: &Context) -> Proof { let mut rng = OsRng; - Proof(sample_payment::prove_private_transfer( + Proof(payment::prove_private_transfer( &context.proving_context, &context.parameters, &context.utxo_accumulator_model, @@ -82,7 +84,7 @@ pub fn prove_private_transfer(context: &Context) -> Proof { #[wasm_bindgen] pub fn prove_reclaim(context: &Context) -> Proof { let mut rng = OsRng; - Proof(sample_payment::prove_reclaim( + Proof(payment::prove_reclaim( &context.proving_context, &context.parameters, &context.utxo_accumulator_model, @@ -92,15 +94,15 @@ pub fn prove_reclaim(context: &Context) -> Proof { #[wasm_bindgen] pub fn verify_mint(context: &Context, proof: &Proof) { - sample_payment::assert_valid_proof(&context.verifying_context.mint, &proof.0); + assert_valid_proof(&context.verifying_context.mint, &proof.0); } #[wasm_bindgen] pub fn verify_private_transfer(context: &Context, proof: &Proof) { - sample_payment::assert_valid_proof(&context.verifying_context.private_transfer, &proof.0); + assert_valid_proof(&context.verifying_context.private_transfer, &proof.0); } #[wasm_bindgen] pub fn verify_reclaim(context: &Context, proof: &Proof) { - sample_payment::assert_valid_proof(&context.verifying_context.reclaim, &proof.0); + assert_valid_proof(&context.verifying_context.reclaim, &proof.0); } diff --git a/manta-pay/Cargo.toml b/manta-pay/Cargo.toml index e4febc01e..c7301b7cf 100644 --- a/manta-pay/Cargo.toml +++ b/manta-pay/Cargo.toml @@ -86,7 +86,7 @@ simulation = [ std = ["manta-accounting/std", "manta-util/std"] # Testing Frameworks -test = ["manta-accounting/test", "manta-crypto/test"] +test = ["anyhow", "manta-accounting/test", "manta-crypto/test", "manta-parameters/download", "tempfile"] # Wallet wallet = ["bip32", "manta-crypto/getrandom", "std"] @@ -104,6 +104,7 @@ websocket = [ [dependencies] aes-gcm = {version = "0.9.4", default-features = false, features = ["aes", "alloc"]} +anyhow = {version = "1.0.57", optional = true, default-features = false} ark-bls12-381 = {version = "0.3.0", optional = true, default-features = false, features = ["curve"]} ark-ec = {version = "0.3.0", optional = true, default-features = false} ark-ed-on-bls12-381 = {version = "0.3.0", optional = true, default-features = false, features = ["r1cs"]} @@ -123,6 +124,7 @@ futures = {version = "0.3.21", optional = true, default-features = false} indexmap = {version = "1.8.2", optional = true, default-features = false} manta-accounting = {path = "../manta-accounting", default-features = false} manta-crypto = {path = "../manta-crypto", default-features = false} +manta-parameters = {path = "../manta-parameters", optional = true, default-features = false} manta-util = {path = "../manta-util", default-features = false} parking_lot = {version = "0.12.1", optional = true, default-features = false} rand_chacha = {version = "0.3.1", default-features = false} @@ -131,6 +133,7 @@ reqwest = {version = "0.11.9", optional = true, default-features = false, featur scale-codec = {package = "parity-scale-codec", version = "3.1.2", optional = true, default-features = false, features = ["derive", "max-encoded-len"]} scale-info = {version = "2.1.2", optional = true, default-features = false, features = ["derive"]} serde_json = {version = "1.0.79", optional = true, default-features = false, features = ["alloc"]} +tempfile = {version = "3.3.0", optional = true, default-features = false} tide = {version = "0.16.0", optional = true, default-features = false, features = ["h1-server"]} tokio = {version = "1.18.2", optional = true, default-features = false} tokio-tungstenite = {version = "0.17.1", optional = true, default-features = false, features = ["native-tls"]} @@ -138,8 +141,5 @@ ws_stream_wasm = {version = "0.7.3", optional = true, default-features = false} # TODO: zk-garage-plonk = { package = "plonk", git = "https://github.com/zk-garage/plonk", optional = true, default-features = false } [dev-dependencies] -anyhow = "1.0.57" manta-crypto = {path = "../manta-crypto", default-features = false, features = ["getrandom"]} -manta-parameters = {path = "../manta-parameters", default-features = false, features = ["download"]} manta-pay = {path = ".", default-features = false, features = ["groth16", "scale", "scale-std", "std", "test"]} -tempfile = {version = "3.3.0", default-features = false} diff --git a/manta-pay/src/lib.rs b/manta-pay/src/lib.rs index 8a3b25fcd..ab3d493fa 100644 --- a/manta-pay/src/lib.rs +++ b/manta-pay/src/lib.rs @@ -23,8 +23,9 @@ extern crate alloc; -#[cfg(test)] -mod test; +#[cfg(feature = "test")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "test")))] +pub mod test; pub mod crypto; pub mod util; @@ -41,10 +42,6 @@ pub mod key; #[cfg_attr(doc_cfg, doc(cfg(all(feature = "groth16", feature = "test"))))] pub mod parameters; -#[cfg(all(feature = "groth16", feature = "test"))] -#[cfg_attr(doc_cfg, doc(cfg(all(feature = "groth16", feature = "test"))))] -pub mod sample_payment; - #[cfg(feature = "groth16")] #[cfg_attr(doc_cfg, doc(cfg(feature = "groth16")))] pub mod signer; diff --git a/manta-pay/src/test/compatibility.rs b/manta-pay/src/test/compatibility.rs index c52bc11f5..e009dd0cf 100644 --- a/manta-pay/src/test/compatibility.rs +++ b/manta-pay/src/test/compatibility.rs @@ -23,10 +23,11 @@ use crate::{ ProvingContext, UtxoAccumulatorModel, UtxoCommitmentScheme, VerifyingContext, VoidNumberCommitmentScheme, }, - sample_payment::{assert_valid_proof, prove_mint, prove_private_transfer, prove_reclaim}, + test::payment::{prove_mint, prove_private_transfer, prove_reclaim}, }; use anyhow::Result; use ark_std::rand::thread_rng; +use manta_accounting::transfer::test::assert_valid_proof; use manta_crypto::rand::Rand; use manta_util::codec::{Decode, IoReader}; use std::{fs::File, path::Path}; diff --git a/manta-pay/src/test/mod.rs b/manta-pay/src/test/mod.rs index ac3ca9b14..20f316055 100644 --- a/manta-pay/src/test/mod.rs +++ b/manta-pay/src/test/mod.rs @@ -23,5 +23,10 @@ // #[cfg_attr(doc_cfg, doc(cfg(feature = "simulation")))] // pub mod simulation; +#[cfg(test)] pub mod compatibility; + +#[cfg(test)] pub mod transfer; + +pub mod payment; diff --git a/manta-pay/src/sample_payment.rs b/manta-pay/src/test/payment.rs similarity index 89% rename from manta-pay/src/sample_payment.rs rename to manta-pay/src/test/payment.rs index 9fd610ce8..13dc63823 100644 --- a/manta-pay/src/sample_payment.rs +++ b/manta-pay/src/test/payment.rs @@ -18,7 +18,7 @@ use crate::config::{ self, FullParameters, MerkleTreeConfiguration, Mint, MultiProvingContext, Parameters, - PrivateTransfer, ProofSystem, ProvingContext, Reclaim, UtxoAccumulatorModel, VerifyingContext, + PrivateTransfer, ProvingContext, Reclaim, UtxoAccumulatorModel, }; use manta_accounting::{ asset::{Asset, AssetId}, @@ -26,7 +26,6 @@ use manta_accounting::{ }; use manta_crypto::{ accumulator::Accumulator, - constraint::ProofSystem as _, merkle_tree::{forest::TreeArrayMerkleForest, full::Full}, rand::{CryptoRng, Rand, RngCore, Sample}, }; @@ -35,21 +34,6 @@ use manta_crypto::{ type UtxoAccumulator = TreeArrayMerkleForest, 256>; -/// Asserts that `post` represents a valid `Transfer` verifying against `verifying_context`. -#[inline] -pub fn assert_valid_proof(verifying_context: &VerifyingContext, post: &config::TransferPost) { - assert!( - ProofSystem::verify( - verifying_context, - &post.generate_proof_input(), - &post.validity_proof, - ) - .expect("Unable to verify proof."), - "Invalid proof: {:?}.", - post - ); -} - /// Generates a proof for a [`Mint`] transaction. #[inline] pub fn prove_mint( From efeec4723bcd6396cc804b7585afdea9b7080d67 Mon Sep 17 00:00:00 2001 From: Boyuan Feng Date: Wed, 15 Jun 2022 17:37:32 -0400 Subject: [PATCH 11/12] fix: require "groth16" feature for `payment` --- manta-pay/src/test/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/manta-pay/src/test/mod.rs b/manta-pay/src/test/mod.rs index 20f316055..054fecde5 100644 --- a/manta-pay/src/test/mod.rs +++ b/manta-pay/src/test/mod.rs @@ -29,4 +29,6 @@ pub mod compatibility; #[cfg(test)] pub mod transfer; +#[cfg(feature = "groth16")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "groth16")))] pub mod payment; From 5562fbca63e9057f1d98bf8551c6759233c7f9e3 Mon Sep 17 00:00:00 2001 From: Boyuan Feng Date: Thu, 16 Jun 2022 15:48:56 -0400 Subject: [PATCH 12/12] feat: Fix lint and library issues --- manta-benchmark/benches/private_transfer.rs | 2 +- manta-benchmark/benches/reclaim.rs | 2 +- manta-pay/Cargo.toml | 150 ++++++++++---------- manta-pay/src/lib.rs | 8 +- manta-pay/src/test/compatibility.rs | 7 +- 5 files changed, 84 insertions(+), 85 deletions(-) diff --git a/manta-benchmark/benches/private_transfer.rs b/manta-benchmark/benches/private_transfer.rs index 6de80dbdd..2491f516e 100644 --- a/manta-benchmark/benches/private_transfer.rs +++ b/manta-benchmark/benches/private_transfer.rs @@ -25,7 +25,7 @@ fn prove(c: &mut Criterion) { let (proving_context, _, parameters, utxo_accumulator_model) = parameters::generate().unwrap(); group.bench_function("private transfer prove", |b| { b.iter(|| { - let _ = prove_private_transfer( + prove_private_transfer( &proving_context, ¶meters, &utxo_accumulator_model, diff --git a/manta-benchmark/benches/reclaim.rs b/manta-benchmark/benches/reclaim.rs index 9c83aff11..5c187bf39 100644 --- a/manta-benchmark/benches/reclaim.rs +++ b/manta-benchmark/benches/reclaim.rs @@ -25,7 +25,7 @@ fn prove(c: &mut Criterion) { let (proving_context, _, parameters, utxo_accumulator_model) = parameters::generate().unwrap(); group.bench_function("reclaim prove", |b| { b.iter(|| { - let _ = prove_reclaim( + prove_reclaim( &proving_context, ¶meters, &utxo_accumulator_model, diff --git a/manta-pay/Cargo.toml b/manta-pay/Cargo.toml index c7301b7cf..b244128ed 100644 --- a/manta-pay/Cargo.toml +++ b/manta-pay/Cargo.toml @@ -1,17 +1,17 @@ [package] -authors = ["Manta Network "] -categories = [""] -description = "The Manta-Pay protocol and implementaion." -documentation = "https://github.com/Manta-Network/manta-rs" +name = "manta-pay" +version = "0.5.0" edition = "2021" +authors = ["Manta Network "] +readme = "README.md" +license-file = "LICENSE" +repository = "https://github.com/Manta-Network/manta-rs" homepage = "https://github.com/Manta-Network" +documentation = "https://github.com/Manta-Network/manta-rs" +categories = [""] keywords = [""] -license-file = "LICENSE" -name = "manta-pay" +description = "The Manta-Pay protocol and implementaion." publish = false -readme = "README.md" -repository = "https://github.com/Manta-Network/manta-rs" -version = "0.5.0" [package.metadata.docs.rs] # To build locally: @@ -20,9 +20,9 @@ all-features = true rustdoc-args = ["--cfg", "doc_cfg"] [badges] -is-it-maintained-issue-resolution = {repository = "Manta-Network/manta-rs"} -is-it-maintained-open-issues = {repository = "Manta-Network/manta-rs"} -maintenance = {status = "actively-developed"} +is-it-maintained-issue-resolution = { repository = "Manta-Network/manta-rs" } +is-it-maintained-open-issues = { repository = "Manta-Network/manta-rs" } +maintenance = { status = "actively-developed" } [[bin]] name = "generate_parameters" @@ -39,14 +39,14 @@ required-features = ["clap", "groth16", "simulation"] [features] # Enable Arkworks Backend arkworks = [ - "ark-bls12-381", - "ark-ec", - "ark-ed-on-bls12-381", - "ark-ff", - "ark-r1cs-std", - "ark-relations", - "ark-serialize", - "ark-std", + "ark-bls12-381", + "ark-ec", + "ark-ed-on-bls12-381", + "ark-ff", + "ark-r1cs-std", + "ark-relations", + "ark-serialize", + "ark-std", ] # Enable Groth16 ZKP System @@ -69,17 +69,17 @@ serde = ["manta-accounting/serde", "manta-crypto/serde"] # Simulation Framework simulation = [ - "indexmap", - "parking_lot", - "rayon", - "test", - "tide", - "tokio/io-std", - "tokio/io-util", - "tokio/macros", - "tokio/rt-multi-thread", - "tokio/sync", - "wallet", + "indexmap", + "parking_lot", + "rayon", + "test", + "tide", + "tokio/io-std", + "tokio/io-util", + "tokio/macros", + "tokio/rt-multi-thread", + "tokio/sync", + "wallet", ] # Standard Library @@ -93,53 +93,53 @@ wallet = ["bip32", "manta-crypto/getrandom", "std"] # Enable WebSocket Signer Client websocket = [ - "futures", - "serde", - "serde_json", - "std", - "tokio", - "tokio-tungstenite/connect", - "ws_stream_wasm", + "futures", + "serde", + "serde_json", + "std", + "tokio", + "tokio-tungstenite/connect", + "ws_stream_wasm", ] [dependencies] -aes-gcm = {version = "0.9.4", default-features = false, features = ["aes", "alloc"]} -anyhow = {version = "1.0.57", optional = true, default-features = false} -ark-bls12-381 = {version = "0.3.0", optional = true, default-features = false, features = ["curve"]} -ark-ec = {version = "0.3.0", optional = true, default-features = false} -ark-ed-on-bls12-381 = {version = "0.3.0", optional = true, default-features = false, features = ["r1cs"]} -ark-ff = {version = "0.3.0", optional = true, default-features = false} -ark-groth16 = {version = "0.3.0", optional = true, default-features = false} -ark-r1cs-std = {version = "0.3.1", optional = true, default-features = false} -ark-relations = {version = "0.3.0", optional = true, default-features = false} -ark-serialize = {version = "0.3.0", optional = true, default-features = false, features = ["derive"]} -ark-snark = {version = "0.3.0", optional = true, default-features = false} -ark-std = {version = "0.3.0", optional = true, default-features = false} -bip32 = {version = "0.3.0", optional = true, default-features = false, features = ["bip39", "secp256k1"]} -blake2 = {version = "0.10.4", default-features = false} -bs58 = {version = "0.4.0", optional = true, default-features = false, features = ["alloc"]} -clap = {version = "3.2.4", optional = true, default-features = false, features = ["color", "derive", "std", "suggestions", "unicode", "wrap_help"]} -derivative = {version = "2.2.0", default-features = false, features = ["use_core"]} -futures = {version = "0.3.21", optional = true, default-features = false} -indexmap = {version = "1.8.2", optional = true, default-features = false} -manta-accounting = {path = "../manta-accounting", default-features = false} -manta-crypto = {path = "../manta-crypto", default-features = false} -manta-parameters = {path = "../manta-parameters", optional = true, default-features = false} -manta-util = {path = "../manta-util", default-features = false} -parking_lot = {version = "0.12.1", optional = true, default-features = false} -rand_chacha = {version = "0.3.1", default-features = false} -rayon = {version = "1.5.1", optional = true, default-features = false} -reqwest = {version = "0.11.9", optional = true, default-features = false, features = ["json"]} -scale-codec = {package = "parity-scale-codec", version = "3.1.2", optional = true, default-features = false, features = ["derive", "max-encoded-len"]} -scale-info = {version = "2.1.2", optional = true, default-features = false, features = ["derive"]} -serde_json = {version = "1.0.79", optional = true, default-features = false, features = ["alloc"]} -tempfile = {version = "3.3.0", optional = true, default-features = false} -tide = {version = "0.16.0", optional = true, default-features = false, features = ["h1-server"]} -tokio = {version = "1.18.2", optional = true, default-features = false} -tokio-tungstenite = {version = "0.17.1", optional = true, default-features = false, features = ["native-tls"]} -ws_stream_wasm = {version = "0.7.3", optional = true, default-features = false} +aes-gcm = { version = "0.9.4", default-features = false, features = ["aes", "alloc"] } +anyhow = { version = "1.0.57", optional = true, default-features = false } +ark-bls12-381 = { version = "0.3.0", optional = true, default-features = false, features = ["curve"] } +ark-ec = { version = "0.3.0", optional = true, default-features = false } +ark-ed-on-bls12-381 = { version = "0.3.0", optional = true, default-features = false, features = ["r1cs"] } +ark-ff = { version = "0.3.0", optional = true, default-features = false } +ark-groth16 = { version = "0.3.0", optional = true, default-features = false } +ark-r1cs-std = { version = "0.3.1", optional = true, default-features = false } +ark-relations = { version = "0.3.0", optional = true, default-features = false } +ark-serialize = { version = "0.3.0", optional = true, default-features = false, features = ["derive"] } +ark-snark = { version = "0.3.0", optional = true, default-features = false } +ark-std = { version = "0.3.0", optional = true, default-features = false } +bip32 = { version = "0.3.0", optional = true, default-features = false, features = ["bip39", "secp256k1"] } +blake2 = { version = "0.10.4", default-features = false } +bs58 = { version = "0.4.0", optional = true, default-features = false, features = ["alloc"] } +clap = { version = "3.2.4", optional = true, default-features = false, features = ["color", "derive", "std", "suggestions", "unicode", "wrap_help"] } +derivative = { version = "2.2.0", default-features = false, features = ["use_core"] } +futures = { version = "0.3.21", optional = true, default-features = false } +indexmap = { version = "1.8.2", optional = true, default-features = false } +manta-accounting = { path = "../manta-accounting", default-features = false } +manta-crypto = { path = "../manta-crypto", default-features = false } +manta-parameters = { path = "../manta-parameters", optional = true, default-features = false } +manta-util = { path = "../manta-util", default-features = false } +parking_lot = { version = "0.12.1", optional = true, default-features = false } +rand_chacha = { version = "0.3.1", default-features = false } +rayon = { version = "1.5.1", optional = true, default-features = false } +reqwest = { version = "0.11.9", optional = true, default-features = false, features = ["json"] } +scale-codec = { package = "parity-scale-codec", version = "3.1.2", optional = true, default-features = false, features = ["derive", "max-encoded-len"] } +scale-info = { version = "2.1.2", optional = true, default-features = false, features = ["derive"] } +serde_json = { version = "1.0.79", optional = true, default-features = false, features = ["alloc"] } +tempfile = { version = "3.3.0", optional = true, default-features = false } +tide = { version = "0.16.0", optional = true, default-features = false, features = ["h1-server"] } +tokio = { version = "1.18.2", optional = true, default-features = false } +tokio-tungstenite = { version = "0.17.1", optional = true, default-features = false, features = ["native-tls"] } +ws_stream_wasm = { version = "0.7.3", optional = true, default-features = false } # TODO: zk-garage-plonk = { package = "plonk", git = "https://github.com/zk-garage/plonk", optional = true, default-features = false } [dev-dependencies] -manta-crypto = {path = "../manta-crypto", default-features = false, features = ["getrandom"]} -manta-pay = {path = ".", default-features = false, features = ["groth16", "scale", "scale-std", "std", "test"]} +manta-crypto = { path = "../manta-crypto", default-features = false, features = ["getrandom"] } +manta-pay = { path = ".", default-features = false, features = ["groth16", "scale", "scale-std", "std", "test"] } diff --git a/manta-pay/src/lib.rs b/manta-pay/src/lib.rs index ab3d493fa..273691e3e 100644 --- a/manta-pay/src/lib.rs +++ b/manta-pay/src/lib.rs @@ -23,10 +23,6 @@ extern crate alloc; -#[cfg(feature = "test")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "test")))] -pub mod test; - pub mod crypto; pub mod util; @@ -49,3 +45,7 @@ pub mod signer; #[cfg(all(feature = "groth16", feature = "simulation"))] #[cfg_attr(doc_cfg, doc(cfg(all(feature = "groth16", feature = "simulation"))))] pub mod simulation; + +#[cfg(any(test, feature = "test"))] +#[cfg_attr(doc_cfg, doc(cfg(feature = "test")))] +pub mod test; diff --git a/manta-pay/src/test/compatibility.rs b/manta-pay/src/test/compatibility.rs index e009dd0cf..d36ebdea4 100644 --- a/manta-pay/src/test/compatibility.rs +++ b/manta-pay/src/test/compatibility.rs @@ -26,9 +26,8 @@ use crate::{ test::payment::{prove_mint, prove_private_transfer, prove_reclaim}, }; use anyhow::Result; -use ark_std::rand::thread_rng; use manta_accounting::transfer::test::assert_valid_proof; -use manta_crypto::rand::Rand; +use manta_crypto::rand::{OsRng, Rand}; use manta_util::codec::{Decode, IoReader}; use std::{fs::File, path::Path}; @@ -105,11 +104,11 @@ fn load_parameters( )) } -/// Test validity on sampled transactions. +/// Tests that the circuit is compatible with the current known parameters in `manta-parameters`. #[test] fn compatibility() { let directory = tempfile::tempdir().expect("Unable to generate temporary test directory."); - let mut rng = thread_rng(); + let mut rng = OsRng; let (proving_context, verifying_context, parameters, utxo_accumulator_model) = load_parameters(directory.path()).expect("Failed to load parameters"); assert_valid_proof(