diff --git a/.github/workflows/dusk_ci.yml b/.github/workflows/dusk_ci.yml index 37fdc9f..a6a4336 100644 --- a/.github/workflows/dusk_ci.yml +++ b/.github/workflows/dusk_ci.yml @@ -18,14 +18,20 @@ jobs: name: Dusk Analyzer uses: dusk-network/.github/.github/workflows/dusk-analysis.yml@main - test_std: - name: tests std + test_core_std: + name: test core std uses: dusk-network/.github/.github/workflows/run-tests.yml@main with: - test_flags: --features alloc + test_flags: -p phoenix-core --features alloc - test_rkyv: - name: tests rkyv + test_core_rkyv: + name: test core rkyv uses: dusk-network/.github/.github/workflows/run-tests.yml@main with: - test_flags: --features rkyv-impl + test_flags: -p phoenix-core --features rkyv-impl + + test_circuits: + name: test cirucits + uses: dusk-network/.github/.github/workflows/run-tests.yml@main + with: + test_flags: -p phoenix-circuits diff --git a/.gitignore b/.gitignore index 4cbb223..58f4d26 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ -/target -**/*.rs.bk -/src/main.rs +**/target Cargo.lock diff --git a/Cargo.toml b/Cargo.toml index 5cf6568..8679fc3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,51 +1,6 @@ -[package] -name = "phoenix-core" -version = "0.27.0" -authors = ["zer0 ", "Victor Lopez +[#171]: https://github.com/dusk-network/phoenix/issues/171 + + +[Unreleased]: https://github.com/dusk-network/phoenix/compare/v0.27.0...HEAD diff --git a/circuits/Cargo.toml b/circuits/Cargo.toml new file mode 100644 index 0000000..33e216b --- /dev/null +++ b/circuits/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "phoenix-circuits" +version = "0.1.0" +edition = "2021" +repository = "https://github.com/dusk-network/phoenix/circuits" +description = "Circuit definitions for Phoenix, an privacy-preserving ZKP-based transaction model" +license = "MPL-2.0" +exclude = [".github/workflows/dusk-ci.yml", ".gitignore"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +phoenix-core = { path = "../core" } +dusk-plonk = { version = "0.19", default-features = false } +dusk-jubjub = { version = "0.14", default-features = false } + +[dev-dependencies] +ff = { version = "0.13", default-features = false } +rand_core = { version = "0.6", default-features = false } diff --git a/circuits/README.md b/circuits/README.md new file mode 100644 index 0000000..091fb29 --- /dev/null +++ b/circuits/README.md @@ -0,0 +1,11 @@ +# Phoenix Circuits + +Phoenix is the transaction model used by Dusk, an open-source public blockchain with a UTXO-based architecture that allows for the execution of obfuscated transactions and confidential smart contracts. + +This library contains the implementation of the Phoenix-circuits, to prove, in zero-knowledge, that the following conditions hold true: + +1. Membership: every note that is about to be spent is included in the Merkle tree of notes. +2. Ownership: the sender holds the note secret key for every note that is about to be spent. +3. Nullification: the nullifier is calculated correctly. +4. Minting: the value commitment for the newly minted notes are computed correctly. +5. Balance integrity: the sum of the value of all spent notes is equal to the value of the sum of all minted notes + the gas fee + a crossover, where a crossover refers to funds being transfered to a contract. diff --git a/src/encryption/elgamal.rs b/circuits/src/encryption/elgamal.rs similarity index 89% rename from src/encryption/elgamal.rs rename to circuits/src/encryption/elgamal.rs index 7a53f27..60e9840 100644 --- a/src/encryption/elgamal.rs +++ b/circuits/src/encryption/elgamal.rs @@ -10,8 +10,6 @@ //! Reference: https://link.springer.com/chapter/10.1007/3-540-39568-7_2 use dusk_jubjub::{JubJubExtended, JubJubScalar, GENERATOR}; - -#[cfg(feature = "zk")] use dusk_plonk::prelude::*; /// Encrypts a JubJubExtended plaintext given a public key and a fresh random @@ -27,8 +25,10 @@ pub fn encrypt( (ciphertext_1, ciphertext_2) } -/// Decrypts a ciphertext given a secret key, -/// returning a JubJubExtended plaintext +/// Decrypts a ciphertext given a secret key. +/// +/// ## Return +/// Returns a JubJubExtended plaintext. pub fn decrypt( secret_key: &JubJubScalar, ciphertext_1: &JubJubExtended, @@ -38,9 +38,8 @@ pub fn decrypt( ciphertext_2 - ciphertext_1 * secret_key } -/// Encrypt in-circuit a plaintext WitnessPoint, returning -/// a ciphertext (WitnessPoint, WitnessPoint) -#[cfg(feature = "zk")] +/// Encrypt in-circuit a plaintext WitnessPoint, returning a ciphertext +/// (WitnessPoint, WitnessPoint) pub fn encrypt_gadget( composer: &mut Composer, public_key: WitnessPoint, @@ -56,7 +55,6 @@ pub fn encrypt_gadget( /// Decrypt in-circuit a ciphertext (WitnessPoint, WitnessPoint), /// returning a plaintext WitnessPoint -#[cfg(feature = "zk")] pub fn decrypt_gadget( composer: &mut Composer, secret_key: Witness, diff --git a/src/encryption/mod.rs b/circuits/src/encryption/mod.rs similarity index 88% rename from src/encryption/mod.rs rename to circuits/src/encryption/mod.rs index 8c4fd2e..300d79f 100644 --- a/src/encryption/mod.rs +++ b/circuits/src/encryption/mod.rs @@ -4,8 +4,5 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -/// AES symmetric cipher -pub mod aes; - /// ElGamal asymmetric cipher pub mod elgamal; diff --git a/circuits/src/lib.rs b/circuits/src/lib.rs new file mode 100644 index 0000000..9c0f7bc --- /dev/null +++ b/circuits/src/lib.rs @@ -0,0 +1,17 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// +// Copyright (c) DUSK NETWORK. All rights reserved. + +//! Phoenix's circuits and gadgets. + +#![allow(non_snake_case)] +#![deny(missing_docs)] +#![no_std] + +/// Encryption algorithm +mod encryption; + +/// ElGamal asymmetric cipher +pub use encryption::elgamal; diff --git a/tests/gadgets.rs b/circuits/tests/elgamal.rs similarity index 81% rename from tests/gadgets.rs rename to circuits/tests/elgamal.rs index d302bf0..83e6ed8 100644 --- a/tests/gadgets.rs +++ b/circuits/tests/elgamal.rs @@ -5,12 +5,31 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_jubjub::{JubJubAffine, JubJubScalar, GENERATOR_EXTENDED}; +use dusk_plonk::prelude::*; use ff::Field; +use phoenix_circuits::elgamal; +use phoenix_core::{PublicKey, SecretKey}; use rand_core::OsRng; -use phoenix_core::{elgamal, PublicKey, SecretKey}; +#[test] +fn test_elgamal_encrypt_and_decrypt() { + let sk = SecretKey::random(&mut OsRng); + let pk = PublicKey::from(&sk); -use dusk_plonk::prelude::*; + let message = GENERATOR_EXTENDED * JubJubScalar::from(1234u64); + + // Encrypt using a fresh random value 'r' + let r = JubJubScalar::random(&mut OsRng); + let (c1, c2) = elgamal::encrypt(pk.A(), &message, &r); + + // Assert decryption + let dec_message = elgamal::decrypt(sk.a(), &c1, &c2); + assert_eq!(message, dec_message); + + // Assert decryption using an incorrect key + let dec_message_wrong = elgamal::decrypt(sk.b(), &c1, &c2); + assert_ne!(message, dec_message_wrong); +} static LABEL: &[u8; 12] = b"dusk-network"; const CAPACITY: usize = 13; // capacity required for the setup diff --git a/CHANGELOG.md b/core/CHANGELOG.md similarity index 61% rename from CHANGELOG.md rename to core/CHANGELOG.md index 0468a65..6ea78db 100644 --- a/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -16,6 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Restructure `Encryption` module. +- Move phoenix-core into a phoenix workspace [#171] + +### Removed + +- Remove 'encryption::elgamal' module as it has been added to the 'phoenix-circuits' lib in the same workspace [#171] ## [0.27.0] - 2024-04-24 @@ -294,61 +299,62 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Canonical implementation shielded by feature. -[#162]: https://github.com/dusk-network/phoenix-core/issues/162 -[#166]: https://github.com/dusk-network/phoenix-core/issues/166 -[#165]: https://github.com/dusk-network/phoenix-core/issues/165 -[#156]: https://github.com/dusk-network/phoenix-core/issues/156 -[#155]: https://github.com/dusk-network/phoenix-core/issues/155 -[#152]: https://github.com/dusk-network/phoenix-core/issues/152 -[#136]: https://github.com/dusk-network/phoenix-core/issues/136 -[#126]: https://github.com/dusk-network/phoenix-core/issues/126 -[#119]: https://github.com/dusk-network/phoenix-core/issues/119 -[#116]: https://github.com/dusk-network/phoenix-core/issues/116 -[#114]: https://github.com/dusk-network/phoenix-core/issues/114 -[#107]: https://github.com/dusk-network/phoenix-core/issues/107 -[#96]: https://github.com/dusk-network/phoenix-core/issues/96 -[#94]: https://github.com/dusk-network/phoenix-core/issues/94 -[#92]: https://github.com/dusk-network/phoenix-core/issues/92 -[#88]: https://github.com/dusk-network/phoenix-core/issues/88 -[#86]: https://github.com/dusk-network/phoenix-core/issues/86 -[#85]: https://github.com/dusk-network/phoenix-core/issues/85 -[#84]: https://github.com/dusk-network/phoenix-core/issues/84 -[#80]: https://github.com/dusk-network/phoenix-core/issues/80 -[#76]: https://github.com/dusk-network/phoenix-core/issues/76 -[#72]: https://github.com/dusk-network/phoenix-core/issues/72 -[#69]: https://github.com/dusk-network/phoenix-core/issues/69 -[#67]: https://github.com/dusk-network/phoenix-core/issues/67 -[#61]: https://github.com/dusk-network/phoenix-core/issues/61 +[#171]: https://github.com/dusk-network/phoenix/issues/171 +[#166]: https://github.com/dusk-network/phoenix/issues/166 +[#165]: https://github.com/dusk-network/phoenix/issues/165 +[#162]: https://github.com/dusk-network/phoenix/issues/162 +[#156]: https://github.com/dusk-network/phoenix/issues/156 +[#155]: https://github.com/dusk-network/phoenix/issues/155 +[#152]: https://github.com/dusk-network/phoenix/issues/152 +[#136]: https://github.com/dusk-network/phoenix/issues/136 +[#126]: https://github.com/dusk-network/phoenix/issues/126 +[#119]: https://github.com/dusk-network/phoenix/issues/119 +[#116]: https://github.com/dusk-network/phoenix/issues/116 +[#114]: https://github.com/dusk-network/phoenix/issues/114 +[#107]: https://github.com/dusk-network/phoenix/issues/107 +[#96]: https://github.com/dusk-network/phoenix/issues/96 +[#94]: https://github.com/dusk-network/phoenix/issues/94 +[#92]: https://github.com/dusk-network/phoenix/issues/92 +[#88]: https://github.com/dusk-network/phoenix/issues/88 +[#86]: https://github.com/dusk-network/phoenix/issues/86 +[#85]: https://github.com/dusk-network/phoenix/issues/85 +[#84]: https://github.com/dusk-network/phoenix/issues/84 +[#80]: https://github.com/dusk-network/phoenix/issues/80 +[#76]: https://github.com/dusk-network/phoenix/issues/76 +[#72]: https://github.com/dusk-network/phoenix/issues/72 +[#69]: https://github.com/dusk-network/phoenix/issues/69 +[#67]: https://github.com/dusk-network/phoenix/issues/67 +[#61]: https://github.com/dusk-network/phoenix/issues/61 -[Unreleased]: https://github.com/dusk-network/phoenix-core/compare/v0.27.0...HEAD -[0.27.0]: https://github.com/dusk-network/phoenix-core/compare/v0.26.0...v0.27.0 -[0.26.0]: https://github.com/dusk-network/phoenix-core/compare/v0.25.0...v0.26.0 -[0.25.0]: https://github.com/dusk-network/phoenix-core/compare/v0.24.0...v0.25.0 -[0.24.0]: https://github.com/dusk-network/phoenix-core/compare/v0.23.0...v0.24.0 -[0.23.0]: https://github.com/dusk-network/phoenix-core/compare/v0.22.0...v0.23.0 -[0.22.0]: https://github.com/dusk-network/phoenix-core/compare/v0.21.0...v0.22.0 -[0.21.0]: https://github.com/dusk-network/phoenix-core/compare/v0.19.0...v0.21.0 -[0.19.0]: https://github.com/dusk-network/phoenix-core/compare/v0.18.1...v0.19.0 -[0.18.1]: https://github.com/dusk-network/phoenix-core/compare/v0.18.0...v0.18.1 -[0.18.0]: https://github.com/dusk-network/phoenix-core/compare/v0.17.1...v0.18.0 -[0.17.1]: https://github.com/dusk-network/phoenix-core/compare/v0.17.0...v0.17.1 -[0.17.0]: https://github.com/dusk-network/phoenix-core/compare/v0.12.0...v0.17.0 -[0.12.0]: https://github.com/dusk-network/phoenix-core/compare/v0.11.0...v0.12.0 -[0.11.0]: https://github.com/dusk-network/phoenix-core/compare/v0.10.0...v0.11.0 -[0.10.0]: https://github.com/dusk-network/phoenix-core/compare/v0.9.1...v0.10.0 -[0.9.1]: https://github.com/dusk-network/phoenix-core/compare/v0.9.0...v0.9.1 -[0.9.0]: https://github.com/dusk-network/phoenix-core/compare/v0.8.0...v0.9.0 -[0.8.0]: https://github.com/dusk-network/phoenix-core/compare/v0.7.4...v0.8.0 -[0.7.4]: https://github.com/dusk-network/phoenix-core/compare/v0.7.3...v0.7.4 -[0.7.3]: https://github.com/dusk-network/phoenix-core/compare/v0.7.2...v0.7.3 -[0.7.2]: https://github.com/dusk-network/phoenix-core/compare/v0.7.1...v0.7.2 -[0.7.1]: https://github.com/dusk-network/phoenix-core/compare/v0.7.0...v0.7.1 -[0.7.0]: https://github.com/dusk-network/phoenix-core/compare/v0.6.0...v0.7.0 -[0.6.0]: https://github.com/dusk-network/phoenix-core/compare/v0.5.1...v0.6.0 -[0.5.1]: https://github.com/dusk-network/phoenix-core/compare/v0.5.0...v0.5.1 -[0.5.0]: https://github.com/dusk-network/phoenix-core/compare/v0.3.1...v0.5.0 -[0.3.1]: https://github.com/dusk-network/phoenix-core/compare/v0.3.0...v0.3.1 -[0.3.0]: https://github.com/dusk-network/phoenix-core/compare/v0.2.0...v0.3.0 -[0.2.0]: https://github.com/dusk-network/phoenix-core/compare/v0.1.0...v0.2.0 -[0.1.0]: https://github.com/dusk-network/phoenix-core/releases/tag/v0.1.0 +[Unreleased]: https://github.com/dusk-network/phoenix/compare/v0.27.0...HEAD +[0.27.0]: https://github.com/dusk-network/phoenix/compare/v0.26.0...v0.27.0 +[0.26.0]: https://github.com/dusk-network/phoenix/compare/v0.25.0...v0.26.0 +[0.25.0]: https://github.com/dusk-network/phoenix/compare/v0.24.0...v0.25.0 +[0.24.0]: https://github.com/dusk-network/phoenix/compare/v0.23.0...v0.24.0 +[0.23.0]: https://github.com/dusk-network/phoenix/compare/v0.22.0...v0.23.0 +[0.22.0]: https://github.com/dusk-network/phoenix/compare/v0.21.0...v0.22.0 +[0.21.0]: https://github.com/dusk-network/phoenix/compare/v0.19.0...v0.21.0 +[0.19.0]: https://github.com/dusk-network/phoenix/compare/v0.18.1...v0.19.0 +[0.18.1]: https://github.com/dusk-network/phoenix/compare/v0.18.0...v0.18.1 +[0.18.0]: https://github.com/dusk-network/phoenix/compare/v0.17.1...v0.18.0 +[0.17.1]: https://github.com/dusk-network/phoenix/compare/v0.17.0...v0.17.1 +[0.17.0]: https://github.com/dusk-network/phoenix/compare/v0.12.0...v0.17.0 +[0.12.0]: https://github.com/dusk-network/phoenix/compare/v0.11.0...v0.12.0 +[0.11.0]: https://github.com/dusk-network/phoenix/compare/v0.10.0...v0.11.0 +[0.10.0]: https://github.com/dusk-network/phoenix/compare/v0.9.1...v0.10.0 +[0.9.1]: https://github.com/dusk-network/phoenix/compare/v0.9.0...v0.9.1 +[0.9.0]: https://github.com/dusk-network/phoenix/compare/v0.8.0...v0.9.0 +[0.8.0]: https://github.com/dusk-network/phoenix/compare/v0.7.4...v0.8.0 +[0.7.4]: https://github.com/dusk-network/phoenix/compare/v0.7.3...v0.7.4 +[0.7.3]: https://github.com/dusk-network/phoenix/compare/v0.7.2...v0.7.3 +[0.7.2]: https://github.com/dusk-network/phoenix/compare/v0.7.1...v0.7.2 +[0.7.1]: https://github.com/dusk-network/phoenix/compare/v0.7.0...v0.7.1 +[0.7.0]: https://github.com/dusk-network/phoenix/compare/v0.6.0...v0.7.0 +[0.6.0]: https://github.com/dusk-network/phoenix/compare/v0.5.1...v0.6.0 +[0.5.1]: https://github.com/dusk-network/phoenix/compare/v0.5.0...v0.5.1 +[0.5.0]: https://github.com/dusk-network/phoenix/compare/v0.3.1...v0.5.0 +[0.3.1]: https://github.com/dusk-network/phoenix/compare/v0.3.0...v0.3.1 +[0.3.0]: https://github.com/dusk-network/phoenix/compare/v0.2.0...v0.3.0 +[0.2.0]: https://github.com/dusk-network/phoenix/compare/v0.1.0...v0.2.0 +[0.1.0]: https://github.com/dusk-network/phoenix/releases/tag/v0.1.0 diff --git a/core/Cargo.toml b/core/Cargo.toml new file mode 100644 index 0000000..4948acb --- /dev/null +++ b/core/Cargo.toml @@ -0,0 +1,41 @@ +[package] +name = "phoenix-core" +version = "0.27.0" +edition = "2021" +repository = "https://github.com/dusk-network/phoenix/core" +description = "Core types and functionalities for Phoenix, an privacy-preserving ZKP-based transaction model" +license = "MPL-2.0" +exclude = [".github/workflows/dusk-ci.yml", ".gitignore"] + +[dependencies] +rand_core = { version = "0.6", default-features = false } +dusk-bytes = "0.1" +dusk-bls12_381 = { version = "0.13", default-features = false } +bls12_381-bls = { version = "0.3", default-features = false } +dusk-jubjub = { version = "0.14", default-features = false, features = ["zeroize"] } +dusk-poseidon = { version = "0.33", default-features = false } +jubjub-schnorr = { version = "0.3", default-features = false } +subtle = { version = "^2.2.1", default-features = false } +ff = { version = "0.13", default-features = false } +aes-gcm = "0.10" +zeroize = { version = "1", default-features = false, features = ["derive"] } +rkyv = { version = "0.7", optional = true, default-features = false } +bytecheck = { version = "0.6", optional = true, default-features = false } + +[dev-dependencies] +assert_matches = "1.3" +rand = "0.8" +rkyv = { version = "0.7", default-features = false, features = ["size_32"] } + +[features] +default = [] # "alloc" is suggested as default feature but would be breaking change +alloc = [] +rkyv-impl = [ + "dusk-poseidon/rkyv-impl", + "dusk-jubjub/rkyv-impl", + "jubjub-schnorr/rkyv-impl", + "dusk-bls12_381/rkyv-impl", + "bls12_381-bls/rkyv-impl", + "rkyv", + "bytecheck" +] diff --git a/core/README.md b/core/README.md new file mode 100644 index 0000000..2f83fff --- /dev/null +++ b/core/README.md @@ -0,0 +1,5 @@ +# Phoenix Core + +Phoenix is the transaction model used by Dusk, an open-source public blockchain with a UTXO-based architecture that allows for the execution of obfuscated transactions and confidential smart contracts. + +This library contains the cryptographic primitives, types and functionalities used in phoenix, except for the zero-knowledge circuits. diff --git a/src/convert.rs b/core/src/convert.rs similarity index 100% rename from src/convert.rs rename to core/src/convert.rs diff --git a/src/crossover.rs b/core/src/crossover.rs similarity index 100% rename from src/crossover.rs rename to core/src/crossover.rs diff --git a/src/encryption/aes.rs b/core/src/encryption/aes.rs similarity index 100% rename from src/encryption/aes.rs rename to core/src/encryption/aes.rs diff --git a/core/src/encryption/mod.rs b/core/src/encryption/mod.rs new file mode 100644 index 0000000..f0fa278 --- /dev/null +++ b/core/src/encryption/mod.rs @@ -0,0 +1,8 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// +// Copyright (c) DUSK NETWORK. All rights reserved. + +/// AES symmetric cipher +pub mod aes; diff --git a/src/error.rs b/core/src/error.rs similarity index 100% rename from src/error.rs rename to core/src/error.rs diff --git a/src/fee.rs b/core/src/fee.rs similarity index 100% rename from src/fee.rs rename to core/src/fee.rs diff --git a/src/fee/remainder.rs b/core/src/fee/remainder.rs similarity index 100% rename from src/fee/remainder.rs rename to core/src/fee/remainder.rs diff --git a/src/keys.rs b/core/src/keys.rs similarity index 100% rename from src/keys.rs rename to core/src/keys.rs diff --git a/src/keys/public.rs b/core/src/keys/public.rs similarity index 100% rename from src/keys/public.rs rename to core/src/keys/public.rs diff --git a/src/keys/secret.rs b/core/src/keys/secret.rs similarity index 100% rename from src/keys/secret.rs rename to core/src/keys/secret.rs diff --git a/src/keys/stealth.rs b/core/src/keys/stealth.rs similarity index 100% rename from src/keys/stealth.rs rename to core/src/keys/stealth.rs diff --git a/src/keys/view.rs b/core/src/keys/view.rs similarity index 100% rename from src/keys/view.rs rename to core/src/keys/view.rs diff --git a/src/lib.rs b/core/src/lib.rs similarity index 95% rename from src/lib.rs rename to core/src/lib.rs index 396d484..56dcc42 100644 --- a/src/lib.rs +++ b/core/src/lib.rs @@ -32,8 +32,6 @@ mod encryption; /// AES symmetric cipher pub use encryption::aes; -/// ElGamal asymmetric cipher -pub use encryption::elgamal; /// Hash function pub use keys::hash; /// Public (Spend) Key diff --git a/src/note.rs b/core/src/note.rs similarity index 100% rename from src/note.rs rename to core/src/note.rs diff --git a/src/transaction.rs b/core/src/transaction.rs similarity index 100% rename from src/transaction.rs rename to core/src/transaction.rs diff --git a/src/transaction/stake.rs b/core/src/transaction/stake.rs similarity index 100% rename from src/transaction/stake.rs rename to core/src/transaction/stake.rs diff --git a/src/transaction/transfer.rs b/core/src/transaction/transfer.rs similarity index 100% rename from src/transaction/transfer.rs rename to core/src/transaction/transfer.rs diff --git a/tests/crossover.rs b/core/tests/crossover.rs similarity index 100% rename from tests/crossover.rs rename to core/tests/crossover.rs diff --git a/tests/encryption.rs b/core/tests/encryption.rs similarity index 53% rename from tests/encryption.rs rename to core/tests/encryption.rs index 9d346b5..7a6252e 100644 --- a/tests/encryption.rs +++ b/core/tests/encryption.rs @@ -4,12 +4,10 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use dusk_jubjub::{JubJubAffine, JubJubScalar, GENERATOR, GENERATOR_EXTENDED}; -use ff::Field; +use dusk_jubjub::{JubJubAffine, JubJubScalar, GENERATOR}; +use phoenix_core::aes; use rand_core::OsRng; -use phoenix_core::{aes, elgamal, PublicKey, SecretKey}; - #[test] fn test_aes_encrypt_and_decrypt() { const PLAINTEXT_SIZE: usize = 20; @@ -27,23 +25,3 @@ fn test_aes_encrypt_and_decrypt() { assert_eq!(&dec_plaintext, plaintext); } - -#[test] -fn test_elgamal_encrypt_and_decrypt() { - let sk = SecretKey::random(&mut OsRng); - let pk = PublicKey::from(&sk); - - let message = GENERATOR_EXTENDED * JubJubScalar::from(1234u64); - - // Encrypt using a fresh random value 'r' - let r = JubJubScalar::random(&mut OsRng); - let (c1, c2) = elgamal::encrypt(pk.A(), &message, &r); - - // Assert decryption - let dec_message = elgamal::decrypt(sk.a(), &c1, &c2); - assert_eq!(message, dec_message); - - // Assert decryption using an incorrect key - let dec_message_wrong = elgamal::decrypt(sk.b(), &c1, &c2); - assert_ne!(message, dec_message_wrong); -} diff --git a/tests/keys.rs b/core/tests/keys.rs similarity index 100% rename from tests/keys.rs rename to core/tests/keys.rs diff --git a/tests/note_test.rs b/core/tests/note_test.rs similarity index 100% rename from tests/note_test.rs rename to core/tests/note_test.rs diff --git a/tests/transaction.rs b/core/tests/transaction.rs similarity index 100% rename from tests/transaction.rs rename to core/tests/transaction.rs