Skip to content

Commit

Permalink
Merge pull request #239 from dusk-network/mocello/rkyv_circuits
Browse files Browse the repository at this point in the history
circuits: Add rkyv serialization for the circuit types
  • Loading branch information
moCello authored Aug 13, 2024
2 parents 620b7b6 + ed538c3 commit 5776f43
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/dusk_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions circuits/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions circuits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"
]
18 changes: 18 additions & 0 deletions circuits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ 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;
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<const H: usize, const I: usize> {
/// All information needed in relation to the transaction input-notes
pub input_notes_info: [InputNoteInfo<H>; I],
Expand Down Expand Up @@ -201,6 +209,11 @@ impl<const H: usize, const I: usize> Default for TxCircuit<H, I> {
/// 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<const H: usize> {
/// The merkle opening for the note
pub merkle_opening: Opening<(), H>,
Expand Down Expand Up @@ -291,6 +304,11 @@ impl<const H: usize> InputNoteInfo<H> {
/// 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,
Expand Down

0 comments on commit 5776f43

Please sign in to comment.