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

Change enc_X fields to JubJubAffine in RecipientParameters #213

Merged
merged 1 commit into from
Jun 14, 2024
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
1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Change `RecipientParams::enc_X` fields to contains `JubJubAffine` instead of `JubJubExtended`
- Include `recipient_params` field in `TxSkeleton`
- Move `OUTPUT_NOTES` to crate root
- Change `owns` and `owns_unchecked` to take `&Note` [#208]
Expand Down
56 changes: 23 additions & 33 deletions core/src/recipient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use dusk_bls12_381::BlsScalar;
use dusk_bytes::{DeserializableSlice, Serializable};
use dusk_jubjub::{JubJubAffine, JubJubExtended, JubJubScalar};
use dusk_jubjub::{JubJubAffine, JubJubScalar};
use ff::Field;
use jubjub_schnorr::{SecretKey as SchnorrSecretKey, Signature};
use rand::{CryptoRng, RngCore};
Expand All @@ -33,9 +33,9 @@ pub struct RecipientParameters {
/// Signatures of 'payload_hash' verifiable using 'pk_A' and 'pk_B'
pub sig: [Signature; OUTPUT_NOTES],
/// Asymmetric encryption of 'pk_A' using both recipients 'npk'
pub enc_A: [(JubJubExtended, JubJubExtended); OUTPUT_NOTES],
pub enc_A: [(JubJubAffine, JubJubAffine); OUTPUT_NOTES],
/// Asymmetric encryption of 'pk_B' using both recipients 'npk'
pub enc_B: [(JubJubExtended, JubJubExtended); OUTPUT_NOTES],
pub enc_B: [(JubJubAffine, JubJubAffine); OUTPUT_NOTES],
/// Randomness needed to encrypt/decrypt 'pk_A'
pub r_A: [JubJubScalar; OUTPUT_NOTES],
/// Randomness needed to encrypt/decrypt 'pk_B'
Expand All @@ -52,9 +52,9 @@ impl Default for RecipientParameters {
sender_pk,
output_npk: [JubJubAffine::default(), JubJubAffine::default()],
sig: [Signature::default(), Signature::default()],
enc_A: [(JubJubExtended::default(), JubJubExtended::default());
enc_A: [(JubJubAffine::default(), JubJubAffine::default());
OUTPUT_NOTES],
enc_B: [(JubJubExtended::default(), JubJubExtended::default());
enc_B: [(JubJubAffine::default(), JubJubAffine::default());
OUTPUT_NOTES],
r_A: [JubJubScalar::default(); OUTPUT_NOTES],
r_B: [JubJubScalar::default(); OUTPUT_NOTES],
Expand Down Expand Up @@ -107,14 +107,8 @@ impl Serializable<PARAMS_SIZE> for RecipientParameters {
sender_pk,
output_npk: [output_npk_0, output_npk_1],
sig: [sig_0, sig_1],
enc_A: [
(enc_A_0_0.into(), enc_A_1_0.into()),
(enc_A_0_1.into(), enc_A_1_1.into()),
],
enc_B: [
(enc_B_0_0.into(), enc_B_1_0.into()),
(enc_B_0_1.into(), enc_B_1_1.into()),
],
enc_A: [(enc_A_0_0, enc_A_1_0), (enc_A_0_1, enc_A_1_1)],
enc_B: [(enc_B_0_0, enc_B_1_0), (enc_B_0_1, enc_B_1_1)],
r_A: [r_A_0, r_A_1],
r_B: [r_B_0, r_B_1],
})
Expand All @@ -131,25 +125,15 @@ impl Serializable<PARAMS_SIZE> for RecipientParameters {
bytes[128..192].copy_from_slice(&self.sig[0].to_bytes());
bytes[192..256].copy_from_slice(&self.sig[1].to_bytes());

let enc_A_0_0 = JubJubAffine::from(self.enc_A[0].0);
let enc_A_1_0 = JubJubAffine::from(self.enc_A[0].1);
let enc_A_0_1 = JubJubAffine::from(self.enc_A[1].0);
let enc_A_1_1 = JubJubAffine::from(self.enc_A[1].1);
bytes[256..288].copy_from_slice(&self.enc_A[0].0.to_bytes());
bytes[288..320].copy_from_slice(&self.enc_A[0].1.to_bytes());
bytes[320..352].copy_from_slice(&self.enc_A[1].0.to_bytes());
bytes[352..384].copy_from_slice(&self.enc_A[1].1.to_bytes());

bytes[256..288].copy_from_slice(&enc_A_0_0.to_bytes());
bytes[288..320].copy_from_slice(&enc_A_1_0.to_bytes());
bytes[320..352].copy_from_slice(&enc_A_0_1.to_bytes());
bytes[352..384].copy_from_slice(&enc_A_1_1.to_bytes());

let enc_B_0_0 = JubJubAffine::from(self.enc_B[0].0);
let enc_B_1_0 = JubJubAffine::from(self.enc_B[0].1);
let enc_B_0_1 = JubJubAffine::from(self.enc_B[1].0);
let enc_B_1_1 = JubJubAffine::from(self.enc_B[1].1);

bytes[384..416].copy_from_slice(&enc_B_0_0.to_bytes());
bytes[416..448].copy_from_slice(&enc_B_1_0.to_bytes());
bytes[448..480].copy_from_slice(&enc_B_0_1.to_bytes());
bytes[480..512].copy_from_slice(&enc_B_1_1.to_bytes());
bytes[384..416].copy_from_slice(&self.enc_B[0].0.to_bytes());
bytes[416..448].copy_from_slice(&self.enc_B[0].1.to_bytes());
bytes[448..480].copy_from_slice(&self.enc_B[1].0.to_bytes());
bytes[480..512].copy_from_slice(&self.enc_B[1].1.to_bytes());

bytes[512..544].copy_from_slice(&self.r_A[0].to_bytes());
bytes[544..576].copy_from_slice(&self.r_A[1].to_bytes());
Expand Down Expand Up @@ -205,8 +189,14 @@ impl RecipientParameters {
&r_B[1],
);

let enc_A = [(A_enc_1_c1, A_enc_1_c2), (A_enc_2_c1, A_enc_2_c2)];
let enc_B = [(B_enc_1_c1, B_enc_1_c2), (B_enc_2_c1, B_enc_2_c2)];
let enc_A = [
(A_enc_1_c1.into(), A_enc_1_c2.into()),
(A_enc_2_c1.into(), A_enc_2_c2.into()),
];
let enc_B = [
(B_enc_1_c1.into(), B_enc_1_c2.into()),
(B_enc_2_c1.into(), B_enc_2_c2.into()),
];

// Sign the payload hash using both 'a' and 'b'
let schnorr_sk_a = SchnorrSecretKey::from(sender_sk.a());
Expand Down