From 96c8d54dd974322f4456a508d7d531bfbc116ec0 Mon Sep 17 00:00:00 2001 From: Joey Kraut Date: Thu, 23 Nov 2023 15:47:32 -0800 Subject: [PATCH] circuits: integration: Simplify integration tests This removes many unnecessary integration tests in light of the mocking framework for MPC gadgets -- which has allowed most tests to be moved into unit tests where they belond. Integration tests will be reserved for connecting circuits and end-to -end functionality. --- Cargo.lock | 176 +++++------ circuit-types/src/order.rs | 2 +- circuit-types/src/traits.rs | 2 +- circuits/Cargo.toml | 1 + circuits/Dockerfile | 4 +- circuits/docker-compose.yml | 4 +- circuits/integration/main.rs | 8 +- circuits/integration/mpc_circuits/match.rs | 284 ++---------------- circuits/integration/mpc_circuits/settle.rs | 22 ++ .../integration/mpc_gadgets/arithmetic.rs | 112 ------- circuits/integration/mpc_gadgets/bits.rs | 230 -------------- .../integration/mpc_gadgets/comparators.rs | 188 ------------ circuits/integration/mpc_gadgets/mod.rs | 41 --- circuits/integration/mpc_gadgets/modulo.rs | 84 ------ circuits/integration/mpc_gadgets/poseidon.rs | 95 ------ circuits/integration/types/mod.rs | 2 +- circuits/integration/types/sharing.rs | 62 ++-- circuits/integration/zk_gadgets/arithmetic.rs | 89 ------ circuits/integration/zk_gadgets/bits.rs | 55 ---- circuits/integration/zk_gadgets/mod.rs | 4 - circuits/integration/zk_gadgets/poseidon.rs | 118 -------- circuits/src/lib.rs | 8 +- .../src/zk_circuits/valid_match_settle/mod.rs | 8 - 23 files changed, 157 insertions(+), 1442 deletions(-) create mode 100644 circuits/integration/mpc_circuits/settle.rs delete mode 100644 circuits/integration/mpc_gadgets/arithmetic.rs delete mode 100644 circuits/integration/mpc_gadgets/bits.rs delete mode 100644 circuits/integration/mpc_gadgets/comparators.rs delete mode 100644 circuits/integration/mpc_gadgets/mod.rs delete mode 100644 circuits/integration/mpc_gadgets/modulo.rs delete mode 100644 circuits/integration/mpc_gadgets/poseidon.rs delete mode 100644 circuits/integration/zk_gadgets/arithmetic.rs delete mode 100644 circuits/integration/zk_gadgets/bits.rs delete mode 100644 circuits/integration/zk_gadgets/mod.rs delete mode 100644 circuits/integration/zk_gadgets/poseidon.rs diff --git a/Cargo.lock b/Cargo.lock index a7d62922f..885a38cbc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -485,7 +485,7 @@ dependencies = [ [[package]] name = "ark-mpc" version = "0.1.2" -source = "git+https://github.com/renegade-fi/ark-mpc#c0c199178b40fc8d2f4f276ff1fc40974ca2aaf2" +source = "git+https://github.com/renegade-fi/ark-mpc#5c1fb4db9acb3fffc7f7242a80f2a8f4bcb7933d" dependencies = [ "ark-ec", "ark-ff", @@ -686,31 +686,33 @@ dependencies = [ [[package]] name = "async-io" -version = "1.13.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" +checksum = "41ed9d5715c2d329bf1b4da8d60455b99b187f27ba726df2883799af9af60997" dependencies = [ "async-lock", - "autocfg", "cfg-if", "concurrent-queue", + "futures-io", "futures-lite", - "log", "parking", "polling", - "rustix 0.37.27", + "rustix", "slab", - "socket2 0.4.10", + "tracing", "waker-fn", + "windows-sys 0.48.0", ] [[package]] name = "async-lock" -version = "2.8.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" +checksum = "655b9c7fe787d3b25cc0f804a1a8401790f0c5bc395beb5a64dc77d8de079105" dependencies = [ "event-listener", + "event-listener-strategy", + "pin-project-lite", ] [[package]] @@ -2088,15 +2090,15 @@ dependencies = [ [[package]] name = "data-encoding" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" +checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" [[package]] name = "data-encoding-macro" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c904b33cc60130e1aeea4956ab803d08a3f4a0ca82d64ed757afac3891f2bb99" +checksum = "20c01c06f5f429efdf2bae21eb67c28b3df3cf85b7dd2d8ef09c0838dac5d33e" dependencies = [ "data-encoding", "data-encoding-macro-internal", @@ -2104,9 +2106,9 @@ dependencies = [ [[package]] name = "data-encoding-macro-internal" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fdf3fce3ce863539ec1d7fd1b6dcc3c645663376b43ed376bbf887733e4f772" +checksum = "0047d07f2c89b17dd631c80450d69841a6b5d7fb17278cbc43d7e4cfcf2576f3" dependencies = [ "data-encoding", "syn 1.0.109", @@ -2968,9 +2970,24 @@ dependencies = [ [[package]] name = "event-listener" -version = "2.5.3" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d93877bcde0eb80ca09131a08d23f0a5c18a620b01db137dba666d18cd9b30c2" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +checksum = "d96b852f1345da36d551b9473fa1e2b1eb5c5195585c6c018118bc92a8d91160" +dependencies = [ + "event-listener", + "pin-project-lite", +] [[package]] name = "external-api" @@ -2997,15 +3014,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "fastrand" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] - [[package]] name = "fastrand" version = "2.0.1" @@ -3116,9 +3124,9 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] @@ -3196,17 +3204,12 @@ checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" [[package]] name = "futures-lite" -version = "1.13.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +checksum = "d3831c2651acb5177cbd83943f3d9c8912c5ad03c76afcc0e9511ba568ec5ebb" dependencies = [ - "fastrand 1.9.0", "futures-core", - "futures-io", - "memchr", - "parking", "pin-project-lite", - "waker-fn", ] [[package]] @@ -3812,9 +3815,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -3822,19 +3825,19 @@ dependencies = [ [[package]] name = "if-addrs" -version = "0.7.0" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbc0fa01ffc752e9dbc72818cdb072cd028b86be5e09dd04c5a643704fe101a9" +checksum = "cabb0019d51a643781ff15c9c8a3e5dedc365c47211270f4e8f82812fedd8f0a" dependencies = [ "libc", - "winapi", + "windows-sys 0.48.0", ] [[package]] name = "if-watch" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb892e5777fe09e16f3d44de7802f4daa7267ecbe8c466f19d94e25bb0c303e" +checksum = "d6b0422c86d7ce0e97169cc42e04ae643caf278874a7a3c87b8150a220dc7e1e" dependencies = [ "async-io", "core-foundation", @@ -3975,17 +3978,6 @@ version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0508c56cfe9bfd5dfeb0c22ab9a6abfda2f27bdca422132e494266351ed8d83c" -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi 0.3.3", - "libc", - "windows-sys 0.48.0", -] - [[package]] name = "ipconfig" version = "0.3.2" @@ -4011,7 +4003,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi 0.3.3", - "rustix 0.38.25", + "rustix", "windows-sys 0.48.0", ] @@ -4702,12 +4694,6 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" -[[package]] -name = "linux-raw-sys" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" - [[package]] name = "linux-raw-sys" version = "0.4.11" @@ -5455,9 +5441,9 @@ dependencies = [ [[package]] name = "openssl" -version = "0.10.59" +version = "0.10.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a257ad03cd8fb16ad4172fedf8094451e1af1c4b70097636ef2eac9a5f0cc33" +checksum = "79a4c6c3a2b158f7f8f2a2fc5a969fa3a068df6fc9dbb4a43845436e3af7c800" dependencies = [ "bitflags 2.4.1", "cfg-if", @@ -5487,9 +5473,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.95" +version = "0.9.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40a4130519a360279579c2053038317e40eff64d13fd3f004f9e1b72b8a6aaf9" +checksum = "3812c071ba60da8b5677cc12bcb1d42989a65553772897a7e0355545a819838f" dependencies = [ "cc", "libc", @@ -5753,9 +5739,9 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "petgraph" @@ -5922,17 +5908,15 @@ dependencies = [ [[package]] name = "polling" -version = "2.8.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +checksum = "e53b6af1f60f36f8c2ac2aad5459d75a5a9b4be1e8cdd40264f315d78193e531" dependencies = [ - "autocfg", - "bitflags 1.3.2", "cfg-if", "concurrent-queue", - "libc", - "log", "pin-project-lite", + "rustix", + "tracing", "windows-sys 0.48.0", ] @@ -6179,9 +6163,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5a410fc7882af66deb8d01d01737353cf3ad6204c408177ba494291a626312" +checksum = "146c289cda302b98a28d40c8b3b90498d6e526dd24ac2ecea73e4e491685b94a" dependencies = [ "bytes", "prost-derive", @@ -6189,9 +6173,9 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fa3d084c8704911bfefb2771be2f9b6c5c0da7343a71e0021ee3c665cada738" +checksum = "c55e02e35260070b6f716a2423c2ff1c3bb1642ddca6f99e1f26d06268a0e2d2" dependencies = [ "bytes", "heck", @@ -6211,9 +6195,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065717a5dfaca4a83d2fe57db3487b311365200000551d7a364e715dbf4346bc" +checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e" dependencies = [ "anyhow", "itertools 0.11.0", @@ -6224,9 +6208,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8339f32236f590281e2f6368276441394fcd1b2133b549cc895d0ae80f2f9a52" +checksum = "193898f59edcf43c26227dcd4c8427f00d99d61e95dcde58dabd49fa291d470e" dependencies = [ "prost", ] @@ -6854,20 +6838,6 @@ dependencies = [ "nom", ] -[[package]] -name = "rustix" -version = "0.37.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys 0.3.8", - "windows-sys 0.48.0", -] - [[package]] name = "rustix" version = "0.38.25" @@ -6877,7 +6847,7 @@ dependencies = [ "bitflags 2.4.1", "errno", "libc", - "linux-raw-sys 0.4.11", + "linux-raw-sys", "windows-sys 0.48.0", ] @@ -8238,9 +8208,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" dependencies = [ "cfg-if", - "fastrand 2.0.1", + "fastrand", "redox_syscall 0.4.1", - "rustix 0.38.25", + "rustix", "windows-sys 0.48.0", ] @@ -8913,12 +8883,12 @@ dependencies = [ [[package]] name = "url" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", - "idna 0.4.0", + "idna 0.5.0", "percent-encoding", ] @@ -9206,9 +9176,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.25.2" +version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" +checksum = "1778a42e8b3b90bff8d0f5032bf22250792889a5cdc752aa0020c84abe3aaf10" [[package]] name = "webrtc" @@ -9427,7 +9397,7 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.25", + "rustix", ] [[package]] diff --git a/circuit-types/src/order.rs b/circuit-types/src/order.rs index 1fa06633b..dd2f0b14d 100644 --- a/circuit-types/src/order.rs +++ b/circuit-types/src/order.rs @@ -102,7 +102,7 @@ impl BaseType for OrderSide { fn from_scalars>(i: &mut I) -> Self { match scalar_to_u64(&i.next().unwrap()) { val @ 0..=1 => OrderSide::from(val), - _ => panic!("invalid value for OrderSide"), + x => panic!("invalid value for OrderSide({x})"), } } } diff --git a/circuit-types/src/traits.rs b/circuit-types/src/traits.rs index b1c0e8492..a72fe3fbe 100644 --- a/circuit-types/src/traits.rs +++ b/circuit-types/src/traits.rs @@ -68,7 +68,7 @@ pub trait BaseType: Clone { /// This method is added to the `BaseType` trait for maximum flexibility, so /// that types may be shared without requiring them to implement the /// full `MpcBaseType` trait - async fn share_public(&self, owning_party: PartyId, fabric: Fabric) -> Self { + async fn share_public(&self, owning_party: PartyId, fabric: &Fabric) -> Self { let self_scalars = self.to_scalars(); let res_scalars = fabric .batch_share_plaintext(self_scalars, owning_party) diff --git a/circuits/Cargo.toml b/circuits/Cargo.toml index 9f795ae5f..957dd6223 100644 --- a/circuits/Cargo.toml +++ b/circuits/Cargo.toml @@ -12,6 +12,7 @@ stats = ["ark-mpc/stats"] name = "integration" path = "integration/main.rs" harness = false +required-features = ["test_helpers"] [[bench]] name = "valid_wallet_create" diff --git a/circuits/Dockerfile b/circuits/Dockerfile index 391bfb5ea..c97ee517b 100644 --- a/circuits/Dockerfile +++ b/circuits/Dockerfile @@ -49,7 +49,7 @@ RUN sed -i 's/main.rs/dummy-main.rs/g' Cargo.toml ENV RUSTFLAGS=-Awarnings ENV RUST_BACKTRACE=1 -RUN cargo build --quiet --test integration +RUN cargo build --quiet --test integration --all-features # Edit the Cargo.toml back to the original, build the full executable RUN sed -i 's/dummy-lib.rs/lib.rs/g' Cargo.toml @@ -58,6 +58,6 @@ RUN sed -i 's/dummy-main.rs/main.rs/g' Cargo.toml COPY circuits/src ./src COPY circuits/integration ./integration -RUN cargo build --quiet --test integration +RUN cargo build --quiet --test integration --all-features CMD [ "cargo", "test" ] diff --git a/circuits/docker-compose.yml b/circuits/docker-compose.yml index e2afc5abd..2f10b8821 100644 --- a/circuits/docker-compose.yml +++ b/circuits/docker-compose.yml @@ -7,7 +7,7 @@ services: ports: - "8000:8000" command: > - cargo test --test integration -- + cargo test --test integration --all-features -- --party 0 --port1 8000 --port2 9000 @@ -22,7 +22,7 @@ services: ports: - "9000:9000" command: > - cargo test --test integration -- + cargo test --test integration --all-features -- --party 1 --port1 9000 --port2 8000 diff --git a/circuits/integration/main.rs b/circuits/integration/main.rs index 0982334b5..c9760fab4 100644 --- a/circuits/integration/main.rs +++ b/circuits/integration/main.rs @@ -6,13 +6,11 @@ #![feature(inherent_associated_types)] mod mpc_circuits; -mod mpc_gadgets; mod types; -mod zk_circuits; -mod zk_gadgets; +// mod zk_circuits; +use circuit_types::Fabric; use clap::Parser; -use mpc_stark::MpcFabric; use test_helpers::{integration_test_main, mpc_network::setup_mpc_fabric}; use util::logging::LevelFilter; @@ -44,7 +42,7 @@ struct CliArgs { #[derive(Debug, Clone)] struct IntegrationTestArgs { /// The MPC fabric to use during the course of the integration test - pub(crate) mpc_fabric: MpcFabric, + pub(crate) mpc_fabric: Fabric, } impl From for IntegrationTestArgs { diff --git a/circuits/integration/mpc_circuits/match.rs b/circuits/integration/mpc_circuits/match.rs index 2299bde9b..aa89039a6 100644 --- a/circuits/integration/mpc_circuits/match.rs +++ b/circuits/integration/mpc_circuits/match.rs @@ -1,23 +1,10 @@ //! Groups integration tests for the match circuitry -use circuit_types::{ - balance::Balance, - fixed_point::FixedPoint, - order::{Order, OrderSide}, - r#match::MatchResult, - traits::{LinkableBaseType, MpcBaseType, MpcType, MultiproverCircuitBaseType}, -}; -use circuits::{ - mpc_circuits::r#match::compute_match, - zk_circuits::valid_match_mpc::{AuthenticatedValidMatchMpcWitness, ValidMatchMpcCircuit}, -}; -use eyre::{eyre, Result}; -use merlin::HashChainTranscript as Transcript; -use mpc_bulletproof::{r1cs_mpc::MpcProver, PedersenGens}; -use mpc_stark::{PARTY0, PARTY1}; -use num_bigint::BigUint; -use rand::thread_rng; -use test_helpers::integration_test_async; +use ark_mpc::PARTY0; +use circuit_types::traits::{BaseType, MpcBaseType, MpcType}; +use circuits::{mpc_circuits::r#match::compute_match, test_helpers::random_orders_and_match}; +use eyre::Result; +use test_helpers::{assert_eq_result, integration_test_async}; use crate::IntegrationTestArgs; @@ -25,248 +12,31 @@ use crate::IntegrationTestArgs; // | Test Cases | // -------------- -/// Tests the match function with non overlapping orders for a variety of -/// failure cases -async fn test_match_no_match(test_args: IntegrationTestArgs) -> Result<()> { - // Convenience selector for brevity - let fabric = &test_args.mpc_fabric; - let mut rng = thread_rng(); - let party_id = fabric.party_id(); - - /// Convenience selector between two party's values - macro_rules! sel { - ($a:expr, $b:expr) => { - if party_id == 0 { - $a - } else { - $b - } - }; - } - - // Give a balance to each party and allocate it in the network - let my_balance = sel!( - Balance { - mint: BigUint::from(1u8), - amount: 200 - }, - Balance { - mint: BigUint::from(2u8), - amount: 200 - } - ) - .to_linkable(); - - let balance1 = my_balance.allocate(PARTY0, fabric); - let balance2 = my_balance.allocate(PARTY1, fabric); - - // Build the test cases for different invalid match pairs - let test_cases: Vec<(Order, u64)> = vec![ - // Quote mints different - ( - Order { - quote_mint: sel!(0u8, 1u8).into(), - base_mint: 2u8.into(), - side: sel!(OrderSide::Buy, OrderSide::Sell), - worst_case_price: FixedPoint::from_integer(sel!(15, 5)), - amount: sel!(20, 30), - timestamp: 0, // unused - }, - 10, // execution_price - ), - // Base mints different - ( - Order { - quote_mint: 1u8.into(), - base_mint: sel!(0u8, 1u8).into(), - side: sel!(OrderSide::Buy, OrderSide::Sell), - worst_case_price: FixedPoint::from_integer(sel!(15, 5)), - amount: sel!(20, 30), - timestamp: 0, // unused - }, - 10, // execution_price - ), - // Orders on the same side (buy side) - ( - Order { - quote_mint: 1u8.into(), - base_mint: 2u8.into(), - side: OrderSide::Buy, - worst_case_price: FixedPoint::from_integer(15), - amount: 20, - timestamp: 0, // unused - }, - 10, // execution_price - ), - // Prices differ between orders - ( - Order { - quote_mint: 1u8.into(), - base_mint: 2u8.into(), - side: sel!(OrderSide::Buy, OrderSide::Sell), - worst_case_price: FixedPoint::from_integer(sel!(15, 5)), - amount: 30, - timestamp: 0, // unused - }, - sel!(10, 11), // execution_price - ), - ]; - - for (my_order, my_price) in test_cases.into_iter() { - // Allocate the orders in the network - let order1 = my_order.to_linkable().allocate(PARTY0, fabric); - let order2 = my_order.to_linkable().allocate(PARTY1, fabric); - - // Allocate the price in the network - let price1 = FixedPoint::from_integer(my_price).allocate(PARTY0, fabric); - let price2 = FixedPoint::from_integer(my_price).allocate(PARTY1, fabric); - - // Compute matches - let res = compute_match( - &order1, - &order2, - order1.amount.value(), - order2.amount.value(), - &price1, // Use the first party's price - fabric, - ); - - // Assert that match verification fails - let pc_gens = PedersenGens::default(); - let transcript = Transcript::new(b"test"); - let mut dummy_prover = - MpcProver::new_with_fabric(test_args.mpc_fabric.clone(), transcript, pc_gens); - - let witness = AuthenticatedValidMatchMpcWitness { - order1: order1.clone(), - amount1: order1.amount.value().clone(), - price1: price1.clone(), - order2: order2.clone(), - amount2: order2.amount.value().clone(), - price2: price2.clone(), - balance1: balance1.clone(), - balance2: balance2.clone(), - match_res: res.link_commitments(fabric), - }; - let (witness_var, _) = witness.commit_shared(&mut rng, &mut dummy_prover).unwrap(); - - ValidMatchMpcCircuit::matching_engine_check( - witness_var, - test_args.mpc_fabric.clone(), - &mut dummy_prover, - ) - .unwrap(); - - if dummy_prover.constraints_satisfied().await { - return Err(eyre!("Constraints satisfied")); - } - } - - Ok(()) -} - /// Tests that a valid match is found when one exists -async fn test_match_valid_match(test_args: IntegrationTestArgs) -> Result<()> { - // Convenience selector for brevity, simpler to redefine per test than to - // pass in party_id from the environment +async fn test_match(test_args: IntegrationTestArgs) -> Result<()> { let fabric = &test_args.mpc_fabric; - let party_id = fabric.party_id(); - - /// Convenience selector for values that differ between parties - macro_rules! sel { - ($a:expr, $b:expr) => { - if party_id == 0 { - $a - } else { - $b - } - }; - } - - let test_cases: Vec<(Order, u64)> = vec![ - // Different amounts - ( - Order { - quote_mint: 1u8.into(), - base_mint: 2u8.into(), - side: sel!(OrderSide::Buy, OrderSide::Sell), - worst_case_price: FixedPoint::from_integer(sel!(15, 5)), - amount: sel!(20, 30), - timestamp: 0, // unused - }, - 10, // execution_price - ), - // Same amount - ( - Order { - quote_mint: 1u8.into(), - base_mint: 2u8.into(), - side: sel!(OrderSide::Sell, OrderSide::Buy), - worst_case_price: FixedPoint::from_integer(sel!(5, 15)), - amount: 15, - timestamp: 0, // unused - }, - 10, // execution_price - ), - ]; - // Stores the expected result for each test case as a vector - // [party1_buy_mint, party1_buy_amount, party2_buy_mint, party2_buy_amount] - let expected_results = vec![ - MatchResult { - quote_mint: BigUint::from(1u8), - base_mint: BigUint::from(2u8), - quote_amount: 200, - base_amount: 20, - direction: 0, - max_minus_min_amount: 10, - min_amount_order_index: 0, - }, - MatchResult { - quote_mint: BigUint::from(1u8), - base_mint: BigUint::from(2u8), - quote_amount: 150, - base_amount: 15, - direction: 1, - max_minus_min_amount: 0, - min_amount_order_index: 1, - }, - ]; - - for ((my_order, my_price), expected_res) in - test_cases.into_iter().zip(expected_results.into_iter()) - { - // Allocate the prices in the network - let price1 = FixedPoint::from_integer(my_price).allocate(PARTY0, fabric); - - // Allocate the orders in the network - let order1 = my_order.to_linkable().allocate(PARTY0, fabric); - let order2 = my_order.to_linkable().allocate(PARTY1, fabric); - - // Compute matches - let res = compute_match( - &order1, - &order2, - order1.amount.value(), - order2.amount.value(), - &price1, - fabric, - ) - .open_and_authenticate() - .await - .map_err(|e| eyre!("Error computing match: {e:?}"))?; - - // Assert that no match occurred - if res != expected_res.clone() { - return Err(eyre!( - "Match result {res:?} does not match expected result {expected_res:?}", - )); - } - } + // Compute a match on two random orders using the internal engine + let (o1, o2, price, expected) = random_orders_and_match(); + + // Compute a match in a circuit + let order1 = o1.allocate(PARTY0, fabric); + let order2 = o2.allocate(PARTY0, fabric); + let price_shared = price.allocate(PARTY0, fabric); + let res = compute_match( + &order1, + &order2, + &order1.amount, + &order2.amount, + &price_shared, + fabric, + ) + .open_and_authenticate() + .await?; - Ok(()) + // Party 0 shares their expected match + let expected = expected.share_public(PARTY0, fabric).await; + assert_eq_result!(res, expected) } -// Take inventory -integration_test_async!(test_match_no_match); -integration_test_async!(test_match_valid_match); +integration_test_async!(test_match); diff --git a/circuits/integration/mpc_circuits/settle.rs b/circuits/integration/mpc_circuits/settle.rs new file mode 100644 index 000000000..7c2008560 --- /dev/null +++ b/circuits/integration/mpc_circuits/settle.rs @@ -0,0 +1,22 @@ +//! Integration tests for the settlement circuit + +use circuits::{test_helpers::random_orders_and_match, mpc_circuits::r#match::compute_match}; +use eyre::Result; +use test_helpers::integration_test_async; +use util::matching_engine::match_orders; + +use crate::IntegrationTestArgs; + +/// Tests settling a match into a set of wallet shares +/// +/// Validates that the resultant shares satisfy the `VALID MATCH SETTLE` +/// circuit's constraints +async fn test_match_settle_witness_generation(test_args: IntegrationTestArgs) -> Result<()> { + // Sample random orders and a crossing price + let (o1, o2, price, match_res) = random_orders_and_match(); + let authenticated_match = compute_match(order1, order2, amount1, amount2, price, fabric) + + Ok(()) +} + +integration_test_async!(test_match_settle_witness_generation); diff --git a/circuits/integration/mpc_gadgets/arithmetic.rs b/circuits/integration/mpc_gadgets/arithmetic.rs deleted file mode 100644 index 0f294f0f3..000000000 --- a/circuits/integration/mpc_gadgets/arithmetic.rs +++ /dev/null @@ -1,112 +0,0 @@ -//! Groups integration tests for arithmetic gadgets used in the MPC circuits - -use circuits::mpc_gadgets::arithmetic::{pow, prefix_mul, product}; -use eyre::Result; -use futures::future::join_all; -use mpc_stark::{ - algebra::{authenticated_scalar::AuthenticatedScalarResult, scalar::Scalar}, - PARTY0, PARTY1, -}; -use num_bigint::BigUint; -use rand::{thread_rng, Rng, RngCore}; -use renegade_crypto::fields::{get_scalar_field_modulus, scalar_to_u64}; -use test_helpers::integration_test_async; - -use crate::IntegrationTestArgs; - -use super::{assert_scalar_batch_eq, assert_scalar_eq}; - -/// Tests the product gadget -async fn test_product(test_args: IntegrationTestArgs) -> Result<()> { - // Each party decided on `n` values - let n = 5; - let fabric = &test_args.mpc_fabric; - let mut rng = thread_rng(); - let my_values = (0..n) - .map(|_| (rng.gen_range(0..100)) as u64) - .collect::>(); - - // Share the values - let p1_values = fabric.batch_share_scalar(my_values.clone(), PARTY0); - let p2_values = fabric.batch_share_scalar(my_values, PARTY1); - - let mut all_values = Vec::new(); - all_values.append(&mut p1_values.clone()); - all_values.append(&mut p2_values.clone()); - - // Compute the product - let res = product(&all_values, fabric).open_authenticated().await?; - - // Open the shared values and compute the expected result - let p1_values_prod = join_all(AuthenticatedScalarResult::open_batch(&p1_values)) - .await - .iter() - .fold(Scalar::one(), |acc, val| acc * val); - - let p2_values_prod = join_all(AuthenticatedScalarResult::open_batch(&p2_values)) - .await - .iter() - .fold(Scalar::one(), |acc, val| acc * val); - let expected_result = p1_values_prod * p2_values_prod; - - assert_scalar_eq(&expected_result, &res) -} - -/// Tests the prefix-mul gadget -async fn test_prefix_mul(test_args: IntegrationTestArgs) -> Result<()> { - // Compute powers of 3 - let n = 25; - let fabric = &test_args.mpc_fabric; - let value = 3; - let shared_values = fabric.batch_share_scalar(vec![value; n], PARTY0); - - // Run the prefix_mul gadget - let prefixes = prefix_mul(&shared_values, fabric); - - // Open the prefixes and verify the result - let opened_prefix_products = join_all(AuthenticatedScalarResult::open_authenticated_batch( - &prefixes, - )) - .await - .into_iter() - .collect::, _>>()?; - - let mut expected_result = Vec::with_capacity(n); - let mut acc = Scalar::one(); - for _ in 0..n { - acc *= Scalar::from(value); - expected_result.push(acc); - } - - assert_scalar_batch_eq(&expected_result, &opened_prefix_products) -} - -/// Tests the exponentiation gadget -async fn test_pow(test_args: IntegrationTestArgs) -> Result<()> { - // Party 0 selects a base and party 0 selects an exponent - let fabric = &test_args.mpc_fabric; - let mut rng = thread_rng(); - - let random_base = fabric.share_scalar(rng.next_u64(), PARTY0); - let random_exp = fabric - .share_plaintext(Scalar::from(rng.next_u32()), PARTY1) - .await; - - let res = pow(&random_base, scalar_to_u64(&random_exp), fabric) - .open_authenticated() - .await?; - - // Open the random input and compute the expected result - let random_base_open = random_base.open().await; - let expected_res = random_base_open.to_biguint().modpow( - &BigUint::from(scalar_to_u64(&random_exp)), - &get_scalar_field_modulus(), - ); - - assert_scalar_eq(&Scalar::from(expected_res), &res) -} - -// Take inventory -integration_test_async!(test_product); -integration_test_async!(test_prefix_mul); -integration_test_async!(test_pow); diff --git a/circuits/integration/mpc_gadgets/bits.rs b/circuits/integration/mpc_gadgets/bits.rs deleted file mode 100644 index 2290fbc23..000000000 --- a/circuits/integration/mpc_gadgets/bits.rs +++ /dev/null @@ -1,230 +0,0 @@ -//! Groups integration tests for bitwise operating MPC gadgets - -use circuits::mpc_gadgets::bits::{bit_add, bit_lt, bit_xor, to_bits_le}; -use eyre::{eyre, Result}; -use futures::future::join_all; -use itertools::Itertools; -use mpc_stark::{ - algebra::{authenticated_scalar::AuthenticatedScalarResult, scalar::Scalar}, - PARTY0, PARTY1, -}; -use rand::{thread_rng, RngCore}; -use renegade_crypto::fields::scalar_to_u64; -use test_helpers::integration_test_async; - -use crate::IntegrationTestArgs; - -use super::{assert_scalar_batch_eq, assert_scalar_eq}; - -// ----------- -// | Helpers | -// ----------- - -/// Converts a u64 to a bit representation as a vector of u64s. -fn u64_to_bits_le(mut a: u64) -> Vec { - let mut bits = Vec::with_capacity(64); - for _ in 0..64 { - bits.push(a & 1); - a >>= 1; - } - - bits -} - -// --------- -// | Tests | -// --------- - -/// Tests the bit xor gadget -async fn test_bit_xor(test_args: IntegrationTestArgs) -> Result<()> { - // Try all combinations of zero and one - let fabric = &test_args.mpc_fabric; - let shared_zero = fabric.zero_authenticated(); - let shared_one = fabric.one_authenticated(); - - // 0 XOR 0 == 0 - let zero_xor_zero = bit_xor(&shared_zero, &shared_zero) - .open_authenticated() - .await?; - assert_scalar_eq(&zero_xor_zero, &Scalar::zero())?; - - // 1 XOR 0 == 1 - let one_xor_zero = bit_xor(&shared_one, &shared_zero) - .open_authenticated() - .await?; - assert_scalar_eq(&one_xor_zero, &Scalar::one())?; - - // 0 XOR 1 == 1 - let zero_xor_one = bit_xor(&shared_zero, &shared_one) - .open_authenticated() - .await?; - assert_scalar_eq(&zero_xor_one, &Scalar::one())?; - - // 1 XOR 1 == 0 - let one_xor_one = bit_xor(&shared_one, &shared_one) - .open_authenticated() - .await?; - assert_scalar_eq(&one_xor_one, &Scalar::zero())?; - - Ok(()) -} - -/// Tests the bit_add method -async fn test_bit_add(test_args: IntegrationTestArgs) -> Result<()> { - // Each party samples a random number, converts it to bits, then shares and adds - // it For the sake of the test (because we convert back to u64 to compare) - // make sure both numbers have log2(x) < 63 - let fabric = &test_args.mpc_fabric; - let my_random_number = thread_rng().next_u64() / 2; - let my_random_bits = u64_to_bits_le(my_random_number); - - // Share the bits, party 0 holds a, party 1 holds b - let shared_bits_a = fabric.batch_share_scalar( - my_random_bits - .iter() - .cloned() - .map(Scalar::from) - .collect::>(), - PARTY0, - ); - let shared_bits_b = fabric.batch_share_scalar( - my_random_bits - .into_iter() - .map(Scalar::from) - .collect::>(), - PARTY1, - ); - - // Add the bits and open the result - let res_bits = bit_add( - shared_bits_a.as_slice()[..64].try_into().unwrap(), - shared_bits_b.as_slice()[..64].try_into().unwrap(), - fabric, - ) - .0; - let result = join_all(AuthenticatedScalarResult::open_authenticated_batch( - &res_bits, - )) - .await - .into_iter() - .collect::, _>>()?; - - // Open the original random numbers and bitify the sum - let random_number1 = fabric - .share_plaintext(Scalar::from(my_random_number), PARTY0) - .await; - let random_number2 = fabric - .share_plaintext(Scalar::from(my_random_number), PARTY1) - .await; - - let expected_result = scalar_to_u64(&(random_number1 + random_number2)); - let expected_bits = u64_to_bits_le(expected_result) - .into_iter() - .map(Scalar::from) - .collect_vec(); - - assert_scalar_batch_eq(&expected_bits, &result) -} - -/// Tests that getting the bits of 0 returns all zeros -async fn test_bits_le_zero(test_args: IntegrationTestArgs) -> Result<()> { - let fabric = &test_args.mpc_fabric; - let shared_zero = fabric.zero_authenticated(); - - let shared_bits = to_bits_le::<250>(&shared_zero, fabric); - let shared_bits_open = join_all(AuthenticatedScalarResult::open_authenticated_batch( - &shared_bits, - )) - .await - .into_iter() - .collect::, _>>()?; - - assert_scalar_batch_eq(&shared_bits_open, &vec![Scalar::zero(); shared_bits.len()]) -} - -/// Tests the to_bits_le gadget -async fn test_to_bits_le(test_args: IntegrationTestArgs) -> Result<()> { - let fabric = &test_args.mpc_fabric; - let value = 119; - - let shared_value = fabric.share_scalar(value, PARTY0); - let shared_bits = to_bits_le::<8>(&shared_value, fabric); - - // Open the bits and compare - let opened_bits = join_all(AuthenticatedScalarResult::open_authenticated_batch( - &shared_bits, - )) - .await - .into_iter() - .collect::, _>>()?; - - if !opened_bits[..8].eq(&vec![ - Scalar::one(), - Scalar::one(), - Scalar::one(), - Scalar::zero(), - Scalar::one(), - Scalar::one(), - Scalar::one(), - Scalar::zero(), - ]) { - return Err(eyre!( - "Expected 0b11101110, Got {:?}", - opened_bits[..8] - .iter() - .map(scalar_to_u64) - .fold("0b".to_string(), |acc, val| acc + &val.to_string()) - )); - } - - Ok(()) -} - -/// Tests the bitwise less than comparator -async fn test_bit_lt(test_args: IntegrationTestArgs) -> Result<()> { - // Test equal values - let fabric = &test_args.mpc_fabric; - let value = 15; - - let equal_value1 = fabric.share_scalar(value, PARTY0); - let equal_value2 = fabric.share_scalar(value, PARTY1); - - let res = bit_lt( - &to_bits_le::<250>(&equal_value1, fabric), - &to_bits_le::<250>(&equal_value2, fabric), - fabric, - ) - .open_authenticated() - .await?; - - assert_scalar_eq(&res, &Scalar::zero())?; - - // Test unequal values - let mut rng = thread_rng(); - let my_value = rng.next_u64(); - - let shared_value1 = fabric.share_scalar(my_value, PARTY0); - let shared_value2 = fabric.share_scalar(my_value, PARTY1); - - let res = bit_lt( - &to_bits_le::<250>(&shared_value1, fabric), - &to_bits_le::<250>(&shared_value2, fabric), - fabric, - ) - .open_authenticated() - .await?; - - // Open the original values to get the expected result - let value1 = fabric.share_plaintext(Scalar::from(my_value), PARTY0).await; - let value2 = fabric.share_plaintext(Scalar::from(my_value), PARTY1).await; - let expected_res = scalar_to_u64(&value1) < scalar_to_u64(&value2); - - assert_scalar_eq(&res, &Scalar::from(expected_res)) -} - -// Take inventory -integration_test_async!(test_bit_xor); -integration_test_async!(test_bit_add); -integration_test_async!(test_bits_le_zero); -integration_test_async!(test_to_bits_le); -integration_test_async!(test_bit_lt); diff --git a/circuits/integration/mpc_gadgets/comparators.rs b/circuits/integration/mpc_gadgets/comparators.rs deleted file mode 100644 index dbe14f531..000000000 --- a/circuits/integration/mpc_gadgets/comparators.rs +++ /dev/null @@ -1,188 +0,0 @@ -//! Groups integration tests for comparators - -use circuits::mpc_gadgets::comparators::{ - cond_select, cond_select_vec, eq, eq_zero, greater_than, greater_than_equal, kary_or, - less_than, less_than_equal, -}; -use eyre::Result; -use futures::future::join_all; -use mpc_stark::{ - algebra::{authenticated_scalar::AuthenticatedScalarResult, scalar::Scalar}, - PARTY0, PARTY1, -}; -use rand::{seq::SliceRandom, thread_rng, Rng, RngCore}; -use renegade_crypto::fields::scalar_to_u64; -use test_helpers::integration_test_async; - -use crate::IntegrationTestArgs; - -use super::{assert_scalar_batch_eq, assert_scalar_eq}; - -/// Tests all the inequality comparators -async fn test_inequalities(test_args: IntegrationTestArgs) -> Result<()> { - // Do not use all bits to avoid overflow, for the sake of testing this is okay - let fabric = &test_args.mpc_fabric; - let my_random_value = (thread_rng().next_u32() / 4) as u64; - - let shared_a = fabric.share_scalar(my_random_value, PARTY0); - let shared_b = fabric.share_scalar(my_random_value, PARTY1); - - let opened_a = scalar_to_u64(&shared_a.open().await); - let opened_b = scalar_to_u64(&shared_b.open().await); - - // Test < - let lt_result = less_than::<250>(&shared_a, &shared_b, fabric) - .open_authenticated() - .await?; - let mut expected_result = opened_a < opened_b; - - assert_scalar_eq(<_result, &expected_result.into())?; - - // Test <= with equal values - let mut lte_result = less_than_equal::<250>(&shared_a, &shared_a, fabric) - .open_authenticated() - .await?; - assert_scalar_eq(<e_result, &Scalar::one())?; - - // Test <= with random values - lte_result = less_than_equal::<250>(&shared_a, &shared_b, fabric) - .open_authenticated() - .await?; - expected_result = opened_a <= opened_b; - assert_scalar_eq(<e_result, &expected_result.into())?; - - // Test > - let gt_result = greater_than::<250>(&shared_a, &shared_b, fabric) - .open_authenticated() - .await?; - expected_result = opened_a > opened_b; - assert_scalar_eq(>_result, &expected_result.into())?; - - // Test >= with random values - let gte_result = greater_than_equal::<250>(&shared_a, &shared_b, fabric) - .open_authenticated() - .await?; - expected_result = opened_a >= opened_b; - assert_scalar_eq(>e_result, &expected_result.into())?; - - Ok(()) -} - -/// Tests the equality comparators -async fn test_equalities(test_args: IntegrationTestArgs) -> Result<()> { - let fabric = &test_args.mpc_fabric; - // 0 == 0 - let shared_zero = fabric.zero_authenticated(); - let mut res = eq_zero::<250>(&shared_zero, fabric) - .open_authenticated() - .await?; - - assert_scalar_eq(&res, &Scalar::one())?; - - // random == 0 - let mut rng = thread_rng(); - let shared_random = fabric.share_scalar(rng.next_u32() as u64, PARTY0); - res = eq_zero::<250>(&shared_random, fabric) - .open_authenticated() - .await?; - - assert_scalar_eq(&res, &Scalar::zero())?; - - // random_1 == random_1 - let shared_random = fabric.share_scalar(rng.next_u32(), PARTY0); - res = eq::<250>(&shared_random, &shared_random, fabric) - .open_authenticated() - .await?; - - assert_scalar_eq(&res, &Scalar::one())?; - - // random_1 == random_2 - let shared_random1 = fabric.share_scalar(rng.next_u32(), PARTY0); - let shared_random2 = fabric.share_scalar(rng.next_u32(), PARTY1); - - res = eq::<250>(&shared_random1, &shared_random2, fabric) - .open_authenticated() - .await?; - - assert_scalar_eq(&res, &Scalar::zero()) -} - -/// Tests the k-ary or boolean operator -async fn test_kary_or(test_args: IntegrationTestArgs) -> Result<()> { - /// The circuit size - const N: usize = 10; - let fabric = &test_args.mpc_fabric; - - // All zeros - let zeros: [AuthenticatedScalarResult; N] = fabric.zeros_authenticated(N).try_into().unwrap(); - let res = kary_or::(&zeros, fabric).open_authenticated().await?; - - assert_scalar_eq(&res, &Scalar::zero())?; - - // A random amount of ones - let mut rng = thread_rng(); - let num_ones = rng.gen_range(1..N); - let mut values = [ - vec![Scalar::one(); num_ones], - vec![Scalar::zero(); N - num_ones], - ] - .concat(); - - // Randomly permute the array and share with the counterparty - values.shuffle(&mut rng); - let shared_bits: [AuthenticatedScalarResult; N] = fabric - .batch_share_scalar(values, PARTY0) - .try_into() - .unwrap(); - - let res = kary_or(&shared_bits, fabric).open_authenticated().await?; - assert_scalar_eq(&res, &Scalar::one()) -} - -/// Tests the conditional select gadget -async fn test_cond_select(test_args: IntegrationTestArgs) -> Result<()> { - let fabric = &test_args.mpc_fabric; - let value1 = fabric.share_scalar(5, PARTY0); - let value2 = fabric.share_scalar(10, PARTY1); - - // Select `value1` - let res = cond_select(&fabric.one_authenticated(), &value1, &value2) - .open_authenticated() - .await?; - assert_scalar_eq(&res, &5.into())?; - - // Select `value2` - let res = cond_select(&fabric.zero_authenticated(), &value1, &value2) - .open_authenticated() - .await?; - assert_scalar_eq(&res, &10.into()) -} - -/// Tests the conditional vector select gadget -async fn test_cond_select_vector(test_args: IntegrationTestArgs) -> Result<()> { - let fabric = &test_args.mpc_fabric; - let values1 = fabric.batch_share_scalar(vec![1, 2, 3], PARTY0); - let values2 = fabric.batch_share_scalar(vec![4, 5, 6], PARTY1); - - // Select `values1` - let res = cond_select_vec(&fabric.one_authenticated(), &values1, &values2); - let res_open = join_all(AuthenticatedScalarResult::open_authenticated_batch(&res)) - .await - .into_iter() - .collect::, _>>()?; - assert_scalar_batch_eq(&res_open, &[1.into(), 2.into(), 3.into()])?; - - // Select `values2` - let res = cond_select_vec(&fabric.zero_authenticated(), &values1, &values2); - let res_open = join_all(AuthenticatedScalarResult::open_authenticated_batch(&res)) - .await - .into_iter() - .collect::, _>>()?; - assert_scalar_batch_eq(&res_open, &[4.into(), 5.into(), 6.into()]) -} - -integration_test_async!(test_inequalities); -integration_test_async!(test_equalities); -integration_test_async!(test_kary_or); -integration_test_async!(test_cond_select); -integration_test_async!(test_cond_select_vector); diff --git a/circuits/integration/mpc_gadgets/mod.rs b/circuits/integration/mpc_gadgets/mod.rs deleted file mode 100644 index 33d23eb27..000000000 --- a/circuits/integration/mpc_gadgets/mod.rs +++ /dev/null @@ -1,41 +0,0 @@ -//! Integration tests for MPC gadgets - -use eyre::{eyre, Result}; -use mpc_stark::algebra::scalar::Scalar; - -pub mod arithmetic; -pub mod bits; -pub mod comparators; -pub mod modulo; -pub mod poseidon; - -// ----------- -// | Helpers | -// ----------- - -/// Assert two scalars are equal, returning a `String` error if they are not -pub fn assert_scalar_eq(a: &Scalar, b: &Scalar) -> Result<()> { - if a == b { - Ok(()) - } else { - Err(eyre!("Expected {a} == {b}")) - } -} - -/// Assert two batches of scalars are equal, returning a `String` error if they -/// are not -pub fn assert_scalar_batch_eq(a: &[Scalar], b: &[Scalar]) -> Result<()> { - if a.len() != b.len() { - return Err(eyre!( - "Expected batch lengths to be equal: {} != {}", - a.len(), - b.len() - )); - } - - for (a, b) in a.iter().zip(b.iter()) { - assert_scalar_eq(a, b)?; - } - - Ok(()) -} diff --git a/circuits/integration/mpc_gadgets/modulo.rs b/circuits/integration/mpc_gadgets/modulo.rs deleted file mode 100644 index 3b430c128..000000000 --- a/circuits/integration/mpc_gadgets/modulo.rs +++ /dev/null @@ -1,84 +0,0 @@ -//! Groups integration tests for modulo MPC gadgets -use circuits::mpc_gadgets::modulo::{mod_2m, shift_right, truncate}; -use eyre::Result; -use mpc_stark::{algebra::scalar::Scalar, PARTY0, PARTY1}; -use num_bigint::{BigUint, RandomBits}; -use rand::{thread_rng, Rng, RngCore}; -use renegade_crypto::fields::scalar_to_biguint; -use test_helpers::integration_test_async; - -use crate::IntegrationTestArgs; - -use super::assert_scalar_eq; - -/// Test the mod_2m method -async fn test_mod_2m(test_args: IntegrationTestArgs) -> Result<()> { - /// The modulus exponent - const M: usize = 5; - - // Clean multiple of 2^m - let fabric = &test_args.mpc_fabric; - let value: u64 = (1 << M) * thread_rng().next_u32() as u64; - let shared_value = fabric.share_scalar(value, PARTY0); - let value_mod_2m = mod_2m::(&shared_value, fabric) - .open_authenticated() - .await?; - - assert_scalar_eq(&value_mod_2m, &Scalar::zero())?; - - // Random value - let random_value: BigUint = thread_rng().sample(RandomBits::new(250)); - let shared_random_value = fabric.share_scalar(random_value, PARTY1); - let random_value_mod_2m = mod_2m::(&shared_random_value, fabric) - .open_authenticated() - .await?; - - let value_opened = shared_random_value.open_authenticated().await?; - let expected_result: BigUint = scalar_to_biguint(&value_opened) % (1u64 << M); - - assert_scalar_eq(&random_value_mod_2m, &expected_result.into()) -} - -/// Tests truncation circuit -async fn test_truncate(test_args: IntegrationTestArgs) -> Result<()> { - /// The modulus exponent - const M: usize = 190; - let fabric = &test_args.mpc_fabric; - - let mut rng = thread_rng(); - let random_value: BigUint = rng.sample(RandomBits::new(250)); - - // Party 0 chooses truncated value, party 1 chooses truncation amount - let shared_random_value = fabric.share_scalar(random_value, PARTY0); - let res = truncate::(&shared_random_value, fabric) - .open_authenticated() - .await?; - - // Open the original value and compute the expected result - let random_value = shared_random_value.open_authenticated().await?; - let expected_result = scalar_to_biguint(&random_value) >> M; - - assert_scalar_eq(&res, &expected_result.into()) -} - -/// Tests the shift right gadget -async fn test_shift_right(test_args: IntegrationTestArgs) -> Result<()> { - /// The bit-amount to shift right by - const SHIFT_AMOUNT: usize = 3; - let fabric = &test_args.mpc_fabric; - let mut rng = thread_rng(); - let random_value = fabric.share_scalar(rng.next_u32(), PARTY0); - - let res = shift_right::(&random_value, fabric) - .open_authenticated() - .await?; - - // Open the random value and compute the expected result - let random_value_open = random_value.open().await; - let expected_res = scalar_to_biguint(&random_value_open) >> SHIFT_AMOUNT; - assert_scalar_eq(&res, &expected_res.into()) -} - -integration_test_async!(test_mod_2m); -integration_test_async!(test_truncate); -integration_test_async!(test_shift_right); diff --git a/circuits/integration/mpc_gadgets/poseidon.rs b/circuits/integration/mpc_gadgets/poseidon.rs deleted file mode 100644 index 73cd7f585..000000000 --- a/circuits/integration/mpc_gadgets/poseidon.rs +++ /dev/null @@ -1,95 +0,0 @@ -//! Groups integration tests for Poseidon hashing - -use ark_crypto_primitives::sponge::{poseidon::PoseidonSponge, CryptographicSponge}; -use circuits::mpc_gadgets::poseidon::AuthenticatedPoseidonHasher; -use eyre::{eyre, Result}; -use futures::future::join_all; -use itertools::Itertools; -use mpc_stark::{ - algebra::{authenticated_scalar::AuthenticatedScalarResult, scalar::Scalar}, - PARTY0, PARTY1, -}; -use rand::{thread_rng, RngCore}; -use renegade_crypto::hash::{default_poseidon_params, PoseidonParams}; -use test_helpers::integration_test_async; - -use crate::IntegrationTestArgs; - -// ----------- -// | Helpers | -// ----------- - -/// Helper to check that a given result is the correct hash of the input -/// sequence. -/// -/// Uses the Arkworks Poseidon implementation for comparison -async fn check_against_arkworks_hash( - result: &AuthenticatedScalarResult, - input_sequence: &[AuthenticatedScalarResult], - hasher_params: &PoseidonParams, -) -> Result<()> { - // Open the input sequence and cast it to field elements - let arkworks_input = join_all(AuthenticatedScalarResult::open_batch(input_sequence)) - .await - .into_iter() - .map(|s| s.inner()) - .collect_vec(); - - // Build the arkworks hasher - let mut arkworks_poseidon = PoseidonSponge::new(hasher_params); - for input_elem in arkworks_input.iter() { - // Arkworks Fp256 does not implement From so we have to - // cast to i128 first to ensure that the value is not represented as a negative - arkworks_poseidon.absorb(input_elem); - } - - let arkworks_squeezed: Scalar::Field = - arkworks_poseidon.squeeze_field_elements(1 /* num_elements */)[0]; - let expected = Scalar::from(arkworks_squeezed); - - // Open the given result and compare to the computed result - let result_open = result.open_authenticated().await?; - if result_open != expected { - return Err(eyre!("Expected {expected:?}, got {result_open:?}",)); - } - - Ok(()) -} - -// --------- -// | Tests | -// --------- - -/// Tests that a collaboratively computed poseidon hash works properly -async fn test_hash(test_args: IntegrationTestArgs) -> Result<()> { - // Each party samples a random string of 5 values to hash and shares them - let n = 5; - let fabric = &test_args.mpc_fabric; - let mut rng = thread_rng(); - let my_values = (0..n).map(|_| rng.next_u64()).collect::>(); - - let party0_values = fabric.batch_share_scalar(my_values.clone(), PARTY0); - let party1_values = fabric.batch_share_scalar(my_values, PARTY1); - - let hasher_params = default_poseidon_params(); - let mut hasher = AuthenticatedPoseidonHasher::new(&hasher_params, test_args.mpc_fabric.clone()); - - // Interleave the party's input values - // Track the input sequence to compute the expected result afterwards - let mut input_sequence = Vec::with_capacity(2 * n); - for (p0_value, p1_value) in party0_values.into_iter().zip(party1_values.into_iter()) { - // Store the inputs for the expected result hash - input_sequence.push(p0_value.clone()); - input_sequence.push(p1_value.clone()); - - // Absorb the inputs - hasher.absorb_batch(&[p0_value, p1_value]); - } - - let res = hasher.squeeze(); - check_against_arkworks_hash(&res, &input_sequence, &hasher_params).await?; - - Ok(()) -} - -integration_test_async!(test_hash); diff --git a/circuits/integration/types/mod.rs b/circuits/integration/types/mod.rs index 322304a79..09bd2622a 100644 --- a/circuits/integration/types/mod.rs +++ b/circuits/integration/types/mod.rs @@ -6,7 +6,7 @@ use circuit_types::{ native_helpers::create_wallet_shares_with_randomness, wallet::{Wallet, WalletShare}, }; -use mpc_stark::algebra::scalar::Scalar; +use constants::Scalar; use rand::rngs::OsRng; pub mod sharing; diff --git a/circuits/integration/types/sharing.rs b/circuits/integration/types/sharing.rs index 77019540a..6bf92557d 100644 --- a/circuits/integration/types/sharing.rs +++ b/circuits/integration/types/sharing.rs @@ -1,12 +1,12 @@ //! Groups integration tests around sharing values in an MPC fabric +use ark_mpc::PARTY0; use circuit_types::{ - r#match::MatchResult, - traits::{BaseType, LinkableBaseType, LinkableType, MpcBaseType, MpcType, SecretShareType}, + traits::{BaseType, MpcBaseType, MpcType, SecretShareType}, wallet::Wallet, }; use constants::{MAX_BALANCES, MAX_FEES, MAX_ORDERS}; -use eyre::{eyre, Result}; -use test_helpers::integration_test_async; +use eyre::Result; +use test_helpers::{assert_eq_result, integration_test_async}; use crate::IntegrationTestArgs; @@ -15,52 +15,36 @@ use super::create_wallet_shares; /// A wallet with default generics type SizedWallet = Wallet; +/// Tests sharing a value then opening it +async fn test_share_then_open(test_args: IntegrationTestArgs) -> Result<()> { + let wallet = SizedWallet::default(); + let fabric = &test_args.mpc_fabric; + + let shared = wallet.allocate(PARTY0, fabric); + let opened = shared.open().await?; + + assert_eq_result!(wallet, opened) +} + /// Tests sharing values in the cleartext over an MPC fabric async fn test_share_public(test_args: IntegrationTestArgs) -> Result<()> { - // Construct a linkable wallet share type + let fabric = test_args.mpc_fabric.clone(); + + // Construct a set of wallet shares let wallet = SizedWallet::default(); let (private_shares, blinded_public_shares) = create_wallet_shares(&wallet); - let linkable_private_share = private_shares.to_linkable(); - let linkable_public_share = blinded_public_shares.to_linkable(); - // Share the public and private shares over the network - let fabric = test_args.mpc_fabric.clone(); - let private = linkable_private_share - .share_public(0 /* owning_party */, fabric.clone()) - .await - .to_base_type(); - let public_blinded = linkable_public_share - .share_public(0 /* owning_party */, fabric) - .await - .to_base_type(); + let private = private_shares.share_public(PARTY0, &fabric).await; + let public_blinded = blinded_public_shares.share_public(PARTY0, &fabric).await; // Recover the wallet let recovered_blinder = private.blinder + public_blinded.blinder; let public_shares = public_blinded.unblind_shares(recovered_blinder); - let recovered_wallet = private.add_shares(public_shares); - - if recovered_wallet != wallet { - return Err(eyre!("Wallets do not match")); - } - - Ok(()) -} - -/// Tests opening an authenticated Match result that has been proof linked -async fn test_open_linkable_match_res(test_args: IntegrationTestArgs) -> Result<()> { - let fabric = &test_args.mpc_fabric; - let match_res = MatchResult::default().allocate(0 /* owning_party */, fabric); - - let linkable_match_res = match_res.link_commitments(fabric); - let opened = linkable_match_res.open_and_authenticate().await?; - - if opened.to_base_type() != MatchResult::default() { - return Err(eyre!("Match results do not match")); - } + let recovered_wallet = private.add_shares(&public_shares); - Ok(()) + assert_eq_result!(wallet, recovered_wallet) } +integration_test_async!(test_share_then_open); integration_test_async!(test_share_public); -integration_test_async!(test_open_linkable_match_res); diff --git a/circuits/integration/zk_gadgets/arithmetic.rs b/circuits/integration/zk_gadgets/arithmetic.rs deleted file mode 100644 index 28c4459c2..000000000 --- a/circuits/integration/zk_gadgets/arithmetic.rs +++ /dev/null @@ -1,89 +0,0 @@ -//! Groups gadgets around arithmetic integration tests -use circuit_types::traits::MultiproverCircuitBaseType; -use circuits::zk_gadgets::arithmetic::MultiproverExpGadget; -use eyre::{eyre, Result}; -use merlin::HashChainTranscript as Transcript; -use mpc_bulletproof::{ - r1cs::Variable, - r1cs_mpc::{MpcConstraintSystem, MpcLinearCombination, MpcProver, MpcVariable}, - PedersenGens, -}; -use mpc_stark::{algebra::scalar::Scalar, PARTY0, PARTY1}; -use rand::{thread_rng, RngCore}; -use renegade_crypto::fields::get_scalar_field_modulus; -use test_helpers::integration_test_async; - -use crate::IntegrationTestArgs; - -/// Tests that the exponentiation gadget works properly on valid inputs -async fn test_exp_multiprover(test_args: IntegrationTestArgs) -> Result<()> { - // Party 1 chooses an exponent, party 0 chooses the base - let mut rng = thread_rng(); - let fabric = &test_args.mpc_fabric; - let shared_base = fabric.share_scalar(Scalar::random(&mut rng), PARTY0); - let shared_exp = fabric.share_scalar(rng.next_u32(), PARTY1); - - // Compute the expected result - let base_open = shared_base.open().await.to_biguint(); - let exp_open = shared_exp.open().await.to_biguint(); - - let expected_res = base_open.modpow(&exp_open, &get_scalar_field_modulus()); - let expected_scalar = expected_res.into(); - - // Prove and verify the exp statement - let pc_gens = PedersenGens::default(); - let transcript = Transcript::new(b"test"); - let mut prover = MpcProver::new_with_fabric(test_args.mpc_fabric.clone(), transcript, pc_gens); - let (shared_base_var, _) = shared_base.commit_shared(&mut rng, &mut prover).unwrap(); - let res = MultiproverExpGadget::exp( - shared_base_var, - exp_open.try_into().unwrap(), - fabric, - &mut prover, - )?; - prover.constrain( - res - MpcLinearCombination::from_scalar(expected_scalar, test_args.mpc_fabric.clone()), - ); - - if prover.constraints_satisfied().await { - Ok(()) - } else { - Err(eyre!("Constraints not satisfied")) - } -} - -/// Tests the exp gadget on an invalid witness -async fn test_exp_multiprover_invalid(test_args: IntegrationTestArgs) -> Result<()> { - let mut rng = thread_rng(); - let fabric = &test_args.mpc_fabric; - - let shared_base = fabric.share_scalar(Scalar::random(&mut rng), PARTY0); - let shared_exp = fabric.share_scalar(rng.next_u32(), PARTY1); - - // Compute the expected result - let exp_open = shared_exp.open().await.to_biguint(); - - let pc_gens = PedersenGens::default(); - let transcript = Transcript::new(b"test"); - let mut prover = MpcProver::new_with_fabric(test_args.mpc_fabric.clone(), transcript, pc_gens); - let (shared_base_var, _) = shared_base.commit_shared(&mut rng, &mut prover).unwrap(); - - let res = MultiproverExpGadget::exp( - shared_base_var, - exp_open.try_into().unwrap(), - fabric, - &mut prover, - )?; - prover - .constrain(res - MpcVariable::new_with_type(Variable::One(), test_args.mpc_fabric.clone())); - - if prover.constraints_satisfied().await { - Err(eyre!("Constraints satisfied")) - } else { - Ok(()) - } -} - -// Take inventory -integration_test_async!(test_exp_multiprover); -integration_test_async!(test_exp_multiprover_invalid); diff --git a/circuits/integration/zk_gadgets/bits.rs b/circuits/integration/zk_gadgets/bits.rs deleted file mode 100644 index f98de7abd..000000000 --- a/circuits/integration/zk_gadgets/bits.rs +++ /dev/null @@ -1,55 +0,0 @@ -//! Groups integration tests for the circuitry that converts between scalars and -//! their bit representations - -use circuit_types::traits::MultiproverCircuitBaseType; -use circuits::zk_gadgets::bits::MultiproverToBitsGadget; -use eyre::{eyre, Result}; -use merlin::HashChainTranscript as Transcript; -use mpc_bulletproof::{ - r1cs_mpc::{MpcConstraintSystem, MpcLinearCombination, MpcProver}, - PedersenGens, -}; -use mpc_stark::{algebra::scalar::Scalar, PARTY0}; -use rand::{thread_rng, RngCore}; -use renegade_crypto::fields::{bigint_to_scalar_bits, scalar_to_bigint}; -use test_helpers::integration_test_async; - -use crate::IntegrationTestArgs; - -/// Tests the to_bits gadget -async fn test_to_bits(test_args: IntegrationTestArgs) -> Result<()> { - // Generate a random scalar to bitify - let mut rng = thread_rng(); - let fabric = &test_args.mpc_fabric; - let random_scalar = Scalar::from(rng.next_u64()); - - // Party 0 shares the scalar as a private input - let shared_scalar = fabric.share_scalar(random_scalar, PARTY0); - - // Bitify the input and share the result to build a circuit statement - let bits = &bigint_to_scalar_bits::<64 /* bits */>(&scalar_to_bigint(&random_scalar))[..64]; - let expected_bits = fabric.batch_share_plaintext(bits.to_vec(), PARTY0).await; - - let pc_gens = PedersenGens::default(); - let transcript = Transcript::new(b"test"); - let mut prover = MpcProver::new_with_fabric(test_args.mpc_fabric.clone(), transcript, pc_gens); - let (shared_scalar_var, _) = shared_scalar.commit_shared(&mut rng, &mut prover).unwrap(); - let res_bits = - MultiproverToBitsGadget::<64 /* bits */>::to_bits(shared_scalar_var, fabric, &mut prover)?; - - for (expected_bit, bit) in expected_bits.iter().zip(res_bits.iter()) { - let allocated_bit = - MpcLinearCombination::from_scalar(*expected_bit, test_args.mpc_fabric.clone()); - - prover.constrain(bit.clone() - allocated_bit); - } - - if prover.constraints_satisfied().await { - Ok(()) - } else { - Err(eyre!("Constraints not satisfied")) - } -} - -// Take inventory -integration_test_async!(test_to_bits); diff --git a/circuits/integration/zk_gadgets/mod.rs b/circuits/integration/zk_gadgets/mod.rs deleted file mode 100644 index d4926a91d..000000000 --- a/circuits/integration/zk_gadgets/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -//! Groups tests for zero knowledge proof gadgets -mod arithmetic; -pub mod bits; -mod poseidon; diff --git a/circuits/integration/zk_gadgets/poseidon.rs b/circuits/integration/zk_gadgets/poseidon.rs deleted file mode 100644 index 2741a7a85..000000000 --- a/circuits/integration/zk_gadgets/poseidon.rs +++ /dev/null @@ -1,118 +0,0 @@ -//! Groups integration tests for multiprover poseidon gadget - -use circuit_types::traits::MultiproverCircuitBaseType; -use circuits::zk_gadgets::poseidon::MultiproverPoseidonHashGadget; - -use eyre::{eyre, Result}; -use futures::future::join_all; -use itertools::Itertools; -use merlin::HashChainTranscript as Transcript; -use mpc_bulletproof::{ - r1cs_mpc::{MpcLinearCombination, MpcProver}, - PedersenGens, -}; -use mpc_stark::{ - algebra::{authenticated_scalar::AuthenticatedScalarResult, scalar::Scalar}, - PARTY0, PARTY1, -}; -use rand::{thread_rng, RngCore}; -use renegade_crypto::hash::{compute_poseidon_hash, default_poseidon_params}; -use test_helpers::integration_test_async; - -use crate::IntegrationTestArgs; - -/// Tests the poseidon hash gadget -async fn test_poseidon_multiprover(test_args: IntegrationTestArgs) -> Result<()> { - // Each party samples a random set of 5 values - let n = 1; - let mut rng = thread_rng(); - let fabric = &test_args.mpc_fabric; - let my_values = (0..n).map(|_| rng.next_u64()).collect_vec(); - - // Secret share the values - let party0_values = fabric.batch_share_scalar(my_values.clone(), PARTY0); - let party1_values = fabric.batch_share_scalar(my_values, PARTY1); - - // Compute the expected result via Arkworks hash - let inputs_open = join_all(AuthenticatedScalarResult::open_batch( - &party0_values - .iter() - .cloned() - .chain(party1_values.iter().cloned()) - .collect_vec(), - )) - .await; - let expected_result = compute_poseidon_hash(&inputs_open); - - // Prove the statement - let pc_gens = PedersenGens::default(); - let transcript = Transcript::new(b"test"); - let mut prover = MpcProver::new_with_fabric(test_args.mpc_fabric.clone(), transcript, pc_gens); - let hash_input: Vec = party0_values - .into_iter() - .chain(party1_values.into_iter()) - .map(|v| v.commit_shared(&mut rng, &mut prover).unwrap()) - .map(|(var, _)| var.into()) - .collect_vec(); - - let params = default_poseidon_params(); - let mut hasher = MultiproverPoseidonHashGadget::new(params, test_args.mpc_fabric.clone()); - hasher.hash( - &hash_input, - &MpcLinearCombination::from_scalar(expected_result, test_args.mpc_fabric.clone()), - &mut prover, - )?; - - if prover.constraints_satisfied().await { - Ok(()) - } else { - Err(eyre!("Constraints not satisfied")) - } -} - -/// Tests the case in which the witness is invalid; i.e. not the correct -/// pre-image -async fn test_poseidon_multiprover_invalid(test_args: IntegrationTestArgs) -> Result<()> { - // Sample a random input - // Each party samples a random set of 5 values - let n = 1; - let mut rng = thread_rng(); - let fabric = &test_args.mpc_fabric; - let my_values = (0..n).map(|_| rng.next_u64()).collect_vec(); - - // Secret share the values - let party0_values = fabric.batch_share_scalar(my_values.clone(), PARTY0); - let party1_values = fabric.batch_share_scalar(my_values, PARTY1); - - // Prove the statement - let hasher_params = default_poseidon_params(); - let pc_gens = PedersenGens::default(); - let transcript = Transcript::new(b"test"); - let mut prover = MpcProver::new_with_fabric(test_args.mpc_fabric.clone(), transcript, pc_gens); - - let hash_input: Vec = party0_values - .iter() - .chain(party1_values.iter()) - .map(|v| v.commit_shared(&mut rng, &mut prover).unwrap()) - .map(|(var, _)| var.into()) - .collect_vec(); - - let expected_out = MpcLinearCombination::from_scalar( - Scalar::from(rng.next_u64()), - test_args.mpc_fabric.clone(), - ); - - let mut hasher = - MultiproverPoseidonHashGadget::new(hasher_params, test_args.mpc_fabric.clone()); - hasher.hash(&hash_input, &expected_out, &mut prover)?; - - if prover.constraints_satisfied().await { - Err(eyre!("Constraints satisfied")) - } else { - Ok(()) - } -} - -// Take inventory -integration_test_async!(test_poseidon_multiprover); -integration_test_async!(test_poseidon_multiprover_invalid); diff --git a/circuits/src/lib.rs b/circuits/src/lib.rs index 4c713ed74..166896185 100644 --- a/circuits/src/lib.rs +++ b/circuits/src/lib.rs @@ -126,7 +126,7 @@ pub async fn multiprover_prove_and_verify( // | Test Helpers | // ---------------- #[cfg(any(test, feature = "test_helpers"))] -pub(crate) mod test_helpers { +pub mod test_helpers { //! Helpers used in tests throughout the crate and integration tests outside //! the crate @@ -165,12 +165,6 @@ pub(crate) mod test_helpers { }; } - /// Constructor to initialize logging in tests - #[ctor::ctor] - fn setup() { - init_logger() - } - /// Initialize a logger pub fn init_logger() { let env = Env::default().filter_or("MY_CRATE_LOG", "trace"); diff --git a/circuits/src/zk_circuits/valid_match_settle/mod.rs b/circuits/src/zk_circuits/valid_match_settle/mod.rs index c1684df14..331bc48e4 100644 --- a/circuits/src/zk_circuits/valid_match_settle/mod.rs +++ b/circuits/src/zk_circuits/valid_match_settle/mod.rs @@ -460,11 +460,7 @@ mod tests { fn test_valid_match__invalid_balance_mint() { let (mut witness, statement) = dummy_witness_and_statement(); -<<<<<<< HEAD // Corrupt the mint -======= - // Switch the mint of the balance to be the wrong asset in the pair ->>>>>>> 1e36d44 (circuits: zk-circuits: valid-match-settle: Add match unit tests) rand_branch!(witness.balance1.mint += 1u8, witness.balance2.mint += 1u8); assert!(!check_constraint_satisfaction::( &witness, &statement @@ -507,11 +503,7 @@ mod tests { let mut rng = thread_rng(); let (mut witness, statement) = dummy_witness_and_statement(); -<<<<<<< HEAD // Change the max minus min amount -======= - // Add one to the max minus min amount ->>>>>>> 1e36d44 (circuits: zk-circuits: valid-match-settle: Add match unit tests) witness.match_res.max_minus_min_amount = rng.next_u64(); assert!(!check_constraint_satisfaction::( &witness, &statement