From 6b25ac17557e90acc3992078714287618c0b8016 Mon Sep 17 00:00:00 2001 From: redshiftzero Date: Thu, 4 Apr 2024 15:20:37 -0400 Subject: [PATCH] test: migrate tests to dedicated crate --- Cargo.toml | 1 + README.md | 1 + poseidon-parameters/Cargo.toml | 5 ---- poseidon-parameters/src/lib.rs | 3 -- poseidon-tests/Cargo.toml | 30 +++++++++++++++++++ .../tests/parameters.rs | 10 +++---- .../tests/poseidon377_r1cs.rs | 0 poseidon377/Cargo.toml | 14 --------- 8 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 poseidon-tests/Cargo.toml rename poseidon-parameters/src/tests.rs => poseidon-tests/tests/parameters.rs (97%) rename poseidon377/tests/r1cs.rs => poseidon-tests/tests/poseidon377_r1cs.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index acf5ebc..d3a0085 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ members = [ "poseidon-permutation", # "poseidon-consistency", # Temporarily excluded until paramgen is refactored "poseidon-parameters", + "poseidon-tests", ] [profile.release] diff --git a/README.md b/README.md index 3632c82..6e6dc7d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ This repository contains: parameters * [`poseidon-permutation`](../main/poseidon-permutation): an independent implementation of the Poseidon permutation * [`poseidon-consistency`](../main/poseidon-consistency): property-based tests for consistency between Poseidon implementations +* [`poseidon-tests`](../main/poseidon-tests): test vectors for `poseidon-parameters` and `poseidon377` ## Audits diff --git a/poseidon-parameters/Cargo.toml b/poseidon-parameters/Cargo.toml index dd32115..5039c78 100644 --- a/poseidon-parameters/Cargo.toml +++ b/poseidon-parameters/Cargo.toml @@ -11,11 +11,6 @@ repository = "https://github.com/penumbra-zone/poseidon377" [dependencies] decaf377 = { version="0.9", default-features = false } -[dev-dependencies] -ark-ff = { version = "^0.4.0", default-features = false } -ark-ed-on-bls12-377 = "0.4" -proptest = "1" - [features] default = ["std"] alloc = [ diff --git a/poseidon-parameters/src/lib.rs b/poseidon-parameters/src/lib.rs index a0916c1..aed3da7 100644 --- a/poseidon-parameters/src/lib.rs +++ b/poseidon-parameters/src/lib.rs @@ -13,9 +13,6 @@ mod matrix_ops; mod mds_matrix; mod round_numbers; -#[cfg(test)] -mod tests; - /// Structures related to Poseidon version 1 parameters. pub mod v1; diff --git a/poseidon-tests/Cargo.toml b/poseidon-tests/Cargo.toml new file mode 100644 index 0000000..044cefb --- /dev/null +++ b/poseidon-tests/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "poseidon-tests" +version = "0.3.0" +edition = "2018" +authors = ["Penumbra ", "redshiftzero "] +description = "Common tests for penumbra's poseidon implementation" +license = "MIT OR Apache-2.0" +repository = "https://github.com/penumbra-zone/poseidon377" + +[dependencies] +poseidon-parameters = { path = "../poseidon-parameters", default-features = false } +#poseidon-paramgen = { path = "../poseidon-paramgen", default-features = false } +poseidon-permutation = { path="../poseidon-permutation", default-features = false } +decaf377 = { version="0.9", default-features = false } +poseidon377 = { path="../poseidon377", features = ["r1cs"] } + +[dev-dependencies] +ark-ff = { version = "^0.4.0", default-features = false } +ark-ed-on-bls12-377 = { version="0.4", default-features = false } +proptest = "1" +ark-ed-on-bls12-381 = "0.4" +rand_core = { version = "0.6.3", default-features=false } +rand_chacha = "0.3" +ark-groth16 = { version = "0.4", default-features = false } +ark-r1cs-std = {version = "0.4", default-features = false } +ark-relations = { version="0.4", default-features = false } +ark-snark = { version = "0.4", default-features = false } +ark-ec = { version = "0.4", default_features = false } +ark-std = { version = "0.4", default-features = false } +ark-serialize = { version = "0.4", default_features = false } \ No newline at end of file diff --git a/poseidon-parameters/src/tests.rs b/poseidon-tests/tests/parameters.rs similarity index 97% rename from poseidon-parameters/src/tests.rs rename to poseidon-tests/tests/parameters.rs index b339e6c..4c8539f 100644 --- a/poseidon-parameters/src/tests.rs +++ b/poseidon-tests/tests/parameters.rs @@ -1,11 +1,9 @@ use decaf377::Fq; use proptest::prelude::*; -use super::*; - -use crate::matrix::{mat_mul, square_mat_mul}; -use crate::{matrix::Matrix, matrix_ops::MatrixOperations}; -use crate::{matrix::SquareMatrix, matrix_ops::SquareMatrixOperations}; +use poseidon_parameters::v1::{mat_mul, square_mat_mul}; +use poseidon_parameters::v1::{Matrix, MatrixOperations}; +use poseidon_parameters::v1::{SquareMatrix, SquareMatrixOperations}; #[test] fn identity_matrix() { @@ -48,7 +46,7 @@ fn nonsquare_matmul_happy() { let matrix_2x3 = Matrix::<3, 2, 6>::new(test_elements); let matrix_3x2 = matrix_2x3.transpose(); - let res: matrix::Matrix<3, 3, 9> = mat_mul(&matrix_2x3, &matrix_3x2); + let res: Matrix<3, 3, 9> = mat_mul(&matrix_2x3, &matrix_3x2); assert_eq!(res.get_element(0, 0), Fq::from(5u64)); assert_eq!(res.get_element(0, 1), Fq::from(11u64)); assert_eq!(res.get_element(0, 2), Fq::from(17u64)); diff --git a/poseidon377/tests/r1cs.rs b/poseidon-tests/tests/poseidon377_r1cs.rs similarity index 100% rename from poseidon377/tests/r1cs.rs rename to poseidon-tests/tests/poseidon377_r1cs.rs diff --git a/poseidon377/Cargo.toml b/poseidon377/Cargo.toml index f2d251d..37a5173 100644 --- a/poseidon377/Cargo.toml +++ b/poseidon377/Cargo.toml @@ -21,16 +21,6 @@ ark-ec = { version = "0.4", default_features = false, optional=true } ark-std = { version = "0.4", default-features = false, optional=true } ark-serialize = { version = "0.4", default_features = false, optional=true } -[dev-dependencies] -ark-ed-on-bls12-381 = "0.4" -proptest = "1" -rand_core = { version = "0.6.3", default-features=false } -rand_chacha = "0.3" -ark-ff = "0.4" - -# Dependencies added for ark-sponge tests -ark-test-curves = { version = "0.4", features = ["bls12_381_curve", "mnt4_753_curve"]} - [features] default = ["arkworks"] alloc = ["decaf377/alloc"] @@ -66,7 +56,3 @@ parallel = [ "ark-std/parallel", "ark-ec/parallel", ] - -[[test]] -name = "r1cs" -required-features = ["r1cs"]