From ed538c3d27a3b64f2f11b4e6411253420479ad02 Mon Sep 17 00:00:00 2001 From: moana Date: Mon, 12 Aug 2024 16:55:05 +0200 Subject: [PATCH] circuits: Add rkyv serialization for the circuit types --- .github/workflows/dusk_ci.yml | 2 +- circuits/CHANGELOG.md | 3 +++ circuits/Cargo.toml | 10 ++++++++++ circuits/src/lib.rs | 18 ++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dusk_ci.yml b/.github/workflows/dusk_ci.yml index 3b0b3b2..7d06814 100644 --- a/.github/workflows/dusk_ci.yml +++ b/.github/workflows/dusk_ci.yml @@ -40,4 +40,4 @@ jobs: name: test cirucits no-default-features uses: dusk-network/.github/.github/workflows/run-tests.yml@main with: - test_flags: -p phoenix-circuits --no-default-features + test_flags: -p phoenix-circuits --no-default-features --features=rkyv-impl,rkyv/size_16 --no-run diff --git a/circuits/CHANGELOG.md b/circuits/CHANGELOG.md index 00d7431..bdf9b64 100644 --- a/circuits/CHANGELOG.md +++ b/circuits/CHANGELOG.md @@ -37,6 +37,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `dusk-bls12_381` dependency [#235] - Add `"plonk"` feature to add the `dusk-plonk` dependency [#235] - Add `"plonk"` feature as default feature [#235] +- Add `"rkyv-impl"` feature +- Add rkyv dependencies behind `rkyv-impl` feature +- Add rkyv derives for `TxCircuit`, `InputNoteInfo` and `OutputNoteInfo` ## [0.2.1] - 2024-07-03 diff --git a/circuits/Cargo.toml b/circuits/Cargo.toml index bb491c1..0233347 100644 --- a/circuits/Cargo.toml +++ b/circuits/Cargo.toml @@ -17,6 +17,8 @@ dusk-jubjub = { version = "0.14", default-features = false } poseidon-merkle = { version = "0.6" } dusk-poseidon = { version = "0.39" } jubjub-schnorr = { version = "0.4" } +rkyv = { version = "0.7", default-features = false, optional = true } +bytecheck = { version = "0.6", default-features = false, optional = true } dusk-plonk = { version = "0.19", default-features = false, optional = true } [dev-dependencies] @@ -32,3 +34,11 @@ plonk = [ "dusk-poseidon/zk", "jubjub-schnorr/zk", ] +rkyv-impl = [ + "phoenix-core/rkyv-impl", + "dusk-jubjub/rkyv-impl", + "jubjub-schnorr/rkyv-impl", + "dusk-bls12_381/rkyv-impl", + "rkyv", + "bytecheck" +] diff --git a/circuits/src/lib.rs b/circuits/src/lib.rs index 45c32b9..a0aebad 100644 --- a/circuits/src/lib.rs +++ b/circuits/src/lib.rs @@ -27,6 +27,9 @@ use dusk_jubjub::{JubJubAffine, JubJubScalar}; use jubjub_schnorr::{Signature as SchnorrSignature, SignatureDouble}; use poseidon_merkle::{Item, Opening, Tree, ARITY}; +#[cfg(feature = "rkyv-impl")] +use rkyv::{Archive, Deserialize, Serialize}; + use phoenix_core::{Note, PublicKey, SecretKey, OUTPUT_NOTES}; extern crate alloc; @@ -34,6 +37,11 @@ use alloc::vec::Vec; /// Declaration of the transaction circuit calling the [`gadget`]. #[derive(Debug, Clone, PartialEq)] +#[cfg_attr( + feature = "rkyv-impl", + derive(Archive, Serialize, Deserialize), + archive_attr(derive(bytecheck::CheckBytes)) +)] pub struct TxCircuit { /// All information needed in relation to the transaction input-notes pub input_notes_info: [InputNoteInfo; I], @@ -201,6 +209,11 @@ impl Default for TxCircuit { /// Struct holding all information needed by the transfer circuit regarding the /// transaction input-notes. #[derive(Debug, Clone, PartialEq)] +#[cfg_attr( + feature = "rkyv-impl", + derive(Archive, Serialize, Deserialize), + archive_attr(derive(bytecheck::CheckBytes)) +)] pub struct InputNoteInfo { /// The merkle opening for the note pub merkle_opening: Opening<(), H>, @@ -291,6 +304,11 @@ impl InputNoteInfo { /// Struct holding all information needed by the transfer circuit regarding the /// transaction output-notes. #[derive(Debug, Clone, PartialEq)] +#[cfg_attr( + feature = "rkyv-impl", + derive(Archive, Serialize, Deserialize), + archive_attr(derive(bytecheck::CheckBytes)) +)] pub struct OutputNoteInfo { /// The value of the note pub value: u64,