From eb296b175e421e3d3c7420ea91bba38ce54c88f4 Mon Sep 17 00:00:00 2001 From: aniampio Date: Wed, 13 Dec 2023 13:33:59 +0000 Subject: [PATCH] Remove date_timestamp from the expiration date struct --- .../src/scheme/expiration_date_signatures.rs | 18 +++++------------- .../src/scheme/identify.rs | 6 +++--- .../src/scheme/mod.rs | 14 +++++++------- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/common/nym_offline_compact_ecash/src/scheme/expiration_date_signatures.rs b/common/nym_offline_compact_ecash/src/scheme/expiration_date_signatures.rs index 0b1c2ee049..b7839500ab 100644 --- a/common/nym_offline_compact_ecash/src/scheme/expiration_date_signatures.rs +++ b/common/nym_offline_compact_ecash/src/scheme/expiration_date_signatures.rs @@ -16,7 +16,6 @@ use rayon::prelude::*; /// A structure representing an expiration date signature. #[derive(Debug, PartialEq, Clone)] pub struct ExpirationDateSignature { - pub(crate) date_timestamp: Scalar, pub(crate) h: G1Projective, pub(crate) s: G1Projective, } @@ -42,7 +41,6 @@ impl ExpirationDateSignature { let s_prime = (self.s * r_prime) + (h_prime * r); ( ExpirationDateSignature { - date_timestamp: self.date_timestamp, h: h_prime, s: s_prime, }, @@ -56,8 +54,7 @@ impl ExpirationDateSignature { /// /// A vector of bytes representing the expiration date signature. pub fn to_bytes(&self) -> Vec { - let mut bytes: Vec = Vec::with_capacity(48 + 48 + 32); - bytes.extend(self.date_timestamp.to_bytes()); + let mut bytes: Vec = Vec::with_capacity(48 + 48); bytes.extend(self.h.to_affine().to_compressed()); bytes.extend(self.s.to_affine().to_compressed()); bytes @@ -68,18 +65,16 @@ impl TryFrom<&[u8]> for ExpirationDateSignature { type Error = CompactEcashError; fn try_from(bytes: &[u8]) -> Result { - if bytes.len() != 128 { + if bytes.len() != 96 { return Err(CompactEcashError::Deserialization(format!( - "ExpirationDateSignature must be exactly 128 bytes, got {}", + "ExpirationDateSignature must be exactly 96 bytes, got {}", bytes.len() ))); } - let date_timestamp_bytes: &[u8; 32] = &bytes[..32].try_into().expect("Slice size != 32"); - let h_bytes: &[u8; 48] = &bytes[32..80].try_into().expect("Slice size != 48"); - let s_bytes: &[u8; 48] = &bytes[80..].try_into().expect("Slice size != 48"); + let h_bytes: &[u8; 48] = &bytes[..48].try_into().expect("Slice size != 48"); + let s_bytes: &[u8; 48] = &bytes[48..].try_into().expect("Slice size != 48"); - let date_timestamp = Scalar::from_bytes(date_timestamp_bytes).unwrap(); let h = try_deserialize_g1_projective( h_bytes, CompactEcashError::Deserialization( @@ -95,7 +90,6 @@ impl TryFrom<&[u8]> for ExpirationDateSignature { )?; Ok(ExpirationDateSignature { - date_timestamp, h, s, }) @@ -147,7 +141,6 @@ pub fn sign_expiration_date( s_exponent += &sk_auth.ys[2] * m2; // Create the signature struct on the expiration date let exp_sign = PartialExpirationDateSignature { - date_timestamp: Scalar::from(valid_date.timestamp() as u64), h, s: h * s_exponent, }; @@ -314,7 +307,6 @@ pub fn aggregate_expiration_signatures( .map(|(coeff, sig)| sig.s * coeff) .sum(); let aggr_sig = ExpirationDateSignature { - date_timestamp: Scalar::from(valid_date.timestamp() as u64), h, s: aggr_s, }; diff --git a/common/nym_offline_compact_ecash/src/scheme/identify.rs b/common/nym_offline_compact_ecash/src/scheme/identify.rs index 8bbbc49c84..ea5bd21a17 100644 --- a/common/nym_offline_compact_ecash/src/scheme/identify.rs +++ b/common/nym_offline_compact_ecash/src/scheme/identify.rs @@ -9,7 +9,7 @@ use crate::scheme::setup::{ aggregate_indices_signatures, sign_coin_indices, CoinIndexSignature, Parameters, PartialCoinIndexSignature, }; -use crate::scheme::{compute_payinfo_hash, Payment}; +use crate::scheme::{compute_pay_info_hash, Payment}; use crate::utils::hash_to_scalar; use crate::PayInfo; use bls12_381::Scalar; @@ -47,8 +47,8 @@ pub fn identify( if pay_info1 == pay_info2 { Ok(IdentifyResult::DuplicatePayInfo(pay_info1)) } else { - let rr_k_payment1 = compute_payinfo_hash(&pay_info1, k as u64); - let rr_j_payment2 = compute_payinfo_hash(&pay_info2, j as u64); + let rr_k_payment1 = compute_pay_info_hash(&pay_info1, k as u64); + let rr_j_payment2 = compute_pay_info_hash(&pay_info2, j as u64); let rr_diff = rr_k_payment1 - rr_j_payment2; let pk = (payment2.tt[j] * rr_k_payment1 - payment1.tt[k] * rr_j_payment2) * rr_diff.invert().unwrap(); diff --git a/common/nym_offline_compact_ecash/src/scheme/mod.rs b/common/nym_offline_compact_ecash/src/scheme/mod.rs index c808dd02eb..a8cbf44b61 100644 --- a/common/nym_offline_compact_ecash/src/scheme/mod.rs +++ b/common/nym_offline_compact_ecash/src/scheme/mod.rs @@ -190,7 +190,7 @@ pub struct Wallet { /// /// A `Scalar` value representing the hash of the concatenated byte sequence. /// -pub fn compute_payinfo_hash(pay_info: &PayInfo, k: u64) -> Scalar { +pub fn compute_pay_info_hash(pay_info: &PayInfo, k: u64) -> Scalar { let mut bytes = Vec::new(); bytes.extend_from_slice(&pay_info.pay_info_bytes); bytes.extend_from_slice(&k.to_le_bytes()); @@ -329,7 +329,7 @@ impl Wallet { lk_vec.push(Scalar::from(lk)); // compute hashes R_k = H(payinfo, k) - let rr_k = compute_payinfo_hash(pay_info, k); + let rr_k = compute_pay_info_hash(pay_info, k); rr.push(rr_k); let o_a_k = grp_params.random_scalar(); @@ -777,7 +777,7 @@ impl Payment { // Verify whether the coin indices signatures and kappa_k are correct self.check_coin_index_signature(¶ms, &verification_key, k)?; // Compute hashes R_k = H(payinfo, k) - let rr_k = compute_payinfo_hash(&pay_info, k); + let rr_k = compute_pay_info_hash(&pay_info, k); rr.push(rr_k); } // verify the zk proof @@ -900,19 +900,19 @@ impl TryFrom<&[u8]> for Payment { let sig_bytes: [u8; 96] = bytes[192..288].try_into().unwrap(); let sig = Signature::try_from(sig_bytes.as_slice())?; - let sig_exp_bytes: [u8; 128] = bytes[288..416].try_into().unwrap(); + let sig_exp_bytes: [u8; 96] = bytes[288..384].try_into().unwrap(); let sig_exp = ExpirationDateSignature::try_from(sig_exp_bytes.as_slice())?; - let spend_value_bytes: [u8; 8] = bytes[416..424].try_into().unwrap(); + let spend_value_bytes: [u8; 8] = bytes[384..392].try_into().unwrap(); let spend_value = u64::from_le_bytes(spend_value_bytes); - let cc_bytes: [u8; 48] = bytes[424..472].try_into().unwrap(); + let cc_bytes: [u8; 48] = bytes[392..440].try_into().unwrap(); let cc = try_deserialize_g1_projective( &cc_bytes, CompactEcashError::Deserialization("Failed to deserialize cc".to_string()), )?; - let mut idx = 472; + let mut idx = 440; let kappa_k_len = u64::from_le_bytes(bytes[idx..idx + 8].try_into().unwrap()) as usize; idx += 8; let mut kappa_k = Vec::with_capacity(kappa_k_len);