Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive rkyv for Encryption #16

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added Rkyv derivation for Encryption struct

## [0.4.0] - 2025-03-12

### Added
Expand Down
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ exclude = [".github/workflows/dusk-ci.yml", ".gitignore"]
[dependencies]
dusk-jubjub = { version = "0.15", default-features = false, features = ["zeroize"] }
dusk-plonk = { version = "0.21", default-features = false, features = ["alloc"], optional = true }
rkyv = { version = "0.7", optional = true, default-features = false }
bytecheck = { version = "0.6", optional = true, default-features = false }
dusk-bytes = "0.1"

[dev-dependencies]
Expand All @@ -18,3 +20,8 @@ rand = { version = "0.8", default-features = false, features = ["std_rng"] }

[features]
zk = ["dusk-plonk"]
rkyv-impl = [
"dusk-jubjub/rkyv-impl",
"rkyv",
"bytecheck",
]
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use dusk_jubjub::{
JubJubAffine, JubJubExtended, JubJubScalar, GENERATOR_EXTENDED,
};

#[cfg(feature = "rkyv-impl")]
use rkyv::{Archive, Deserialize, Serialize};

/// This module implements the equivalent plonk-gadgets for encrypting and
/// decrypting. These gadgets can be used as part of a larger circuit.
#[cfg(feature = "zk")]
Expand All @@ -29,6 +32,11 @@ pub enum DecryptFrom {

/// `ElGamal` encryption of a [`JubJubExtended`] plaintext
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(
feature = "rkyv-impl",
derive(Archive, Deserialize, Serialize),
archive_attr(derive(bytecheck::CheckBytes))
)]
pub struct Encryption {
ciphertext_1: JubJubExtended,
ciphertext_2: JubJubExtended,
Expand Down
5 changes: 5 additions & 0 deletions src/zk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ pub enum DecryptFrom {
/// `ElGamal` encryption of a [`JubJubExtended`] plaintext
/// in a Witness form, meant to be used in-circuit
#[derive(Debug)]
#[cfg_attr(
feature = "rkyv-impl",
derive(Archive, Deserialize, Serialize),
archive_attr(derive(bytecheck::CheckBytes))
)]
pub struct Encryption {
pub(crate) ciphertext_1: WitnessPoint,
pub(crate) ciphertext_2: WitnessPoint,
Expand Down