diff --git a/common/nym_offline_compact_ecash/src/scheme/aggregation.rs b/common/nym_offline_compact_ecash/src/scheme/aggregation.rs index 4bc5734be1..46a5add53c 100644 --- a/common/nym_offline_compact_ecash/src/scheme/aggregation.rs +++ b/common/nym_offline_compact_ecash/src/scheme/aggregation.rs @@ -121,8 +121,6 @@ pub fn aggregate_signatures( }; // Verify the signature - let alpha = verification_key.alpha; - let tmp = attributes .iter() .zip(verification_key.beta_g2.iter()) @@ -131,7 +129,7 @@ pub fn aggregate_signatures( if !check_bilinear_pairing( &signature.0.to_affine(), - &G2Prepared::from((alpha + tmp).to_affine()), + &G2Prepared::from((verification_key.alpha + tmp).to_affine()), &signature.1.to_affine(), params.prepared_miller_g2(), ) { 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 4595380976..5ed9b662de 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 @@ -8,6 +8,7 @@ use bls12_381::{G1Projective, G2Prepared, G2Projective, Scalar}; use group::Curve; use itertools::Itertools; use rayon::prelude::*; +use chrono::{NaiveDate, Duration, NaiveDateTime}; #[derive(Debug, PartialEq, Clone)] pub struct ExpirationDateSignature { @@ -64,7 +65,9 @@ pub fn sign_expiration_date( (0..constants::VALIDITY_PERIOD) .into_par_iter() .fold(Vec::new, |mut exp_signs, l| { - let m1: Scalar = Scalar::from(expiration_date - constants::VALIDITY_PERIOD + l as u64); + let expiration_date = NaiveDateTime::from_timestamp(expiration_date as i64, 0); + let valid_date = expiration_date - Duration::days(constants::VALIDITY_PERIOD as i64) + Duration::days(l as i64); + let m1: Scalar = Scalar::from(valid_date.timestamp() as u64); // Compute the hash let h = hash_g1([m0.to_bytes(), m1.to_bytes(), m2.to_bytes()].concat()); // Sign the attributes by performing scalar-point multiplications and accumulating the result @@ -112,9 +115,11 @@ pub fn verify_valid_dates_signatures( ) -> Result<()> { let m0: Scalar = Scalar::from(expiration_date); let m2: Scalar = Scalar::from_bytes(&constants::TYPE_EXP).unwrap(); - + signatures.par_iter().enumerate().try_for_each(|(l, sig)| { - let m1: Scalar = Scalar::from(expiration_date - constants::VALIDITY_PERIOD + l as u64); + let expiration_date = NaiveDateTime::from_timestamp(expiration_date as i64, 0); + let valid_date = expiration_date - Duration::days(constants::VALIDITY_PERIOD as i64) + Duration::days(l as i64); + let m1: Scalar = Scalar::from(valid_date.timestamp() as u64); // Compute the hash let h = hash_g1([m0.to_bytes(), m1.to_bytes(), m2.to_bytes()].concat()); // Verify the signature correctness @@ -214,7 +219,9 @@ pub fn aggregate_expiration_signatures( let m0: Scalar = Scalar::from(expiration_date); let m2: Scalar = Scalar::from_bytes(&constants::TYPE_EXP).unwrap(); for l in 0..constants::VALIDITY_PERIOD { - let m1: Scalar = Scalar::from(expiration_date - constants::VALIDITY_PERIOD + l); + let expiration_date = NaiveDateTime::from_timestamp(expiration_date as i64, 0); + let valid_date = expiration_date - Duration::days(constants::VALIDITY_PERIOD as i64) + Duration::days(l as i64); + let m1: Scalar = Scalar::from(valid_date.timestamp() as u64); // Compute the hash let h = hash_g1([m0.to_bytes(), m1.to_bytes(), m2.to_bytes()].concat()); @@ -257,10 +264,13 @@ pub fn aggregate_expiration_signatures( pub fn find_index(spend_date: Scalar, expiration_date: Scalar) -> Result { let expiration_date_bytes = expiration_date.to_bytes(); let expiration_date_u64 = - u64::from_le_bytes(expiration_date_bytes.as_slice().try_into().unwrap()); + u64::from_le_bytes(expiration_date_bytes[..8].try_into().unwrap()); + println!("Expiration date {:?}", expiration_date_u64); // Thu Dec 28 let spend_date_bytes = spend_date.to_bytes(); - let spend_date_u64 = u64::from_le_bytes(spend_date_bytes.as_slice().try_into().unwrap()); + let spend_date_u64 = u64::from_le_bytes(spend_date_bytes[..8].try_into().unwrap()); + println!("Spend date {:?}", spend_date_u64); // Nov 28 let start_date = expiration_date_u64 - constants::VALIDITY_PERIOD; + println!("Start date {:?}", start_date); // Wed Dec 27 if spend_date_u64 >= start_date { let index_a = (spend_date_u64 - start_date) as usize; diff --git a/common/nym_offline_compact_ecash/src/scheme/mod.rs b/common/nym_offline_compact_ecash/src/scheme/mod.rs index ea8a27fcaf..e557cdb264 100644 --- a/common/nym_offline_compact_ecash/src/scheme/mod.rs +++ b/common/nym_offline_compact_ecash/src/scheme/mod.rs @@ -41,8 +41,8 @@ impl PartialWallet { pub fn index(&self) -> Option { self.idx } - pub fn to_bytes(&self) -> [u8; 136] { - let mut bytes = [0u8; 136]; + pub fn to_bytes(&self) -> [u8; 168] { + let mut bytes = [0u8; 168]; bytes[0..96].copy_from_slice(&self.sig.to_bytes()); bytes[96..128].copy_from_slice(&self.v.to_bytes()); bytes[128..160].copy_from_slice(&self.expiration_date.to_bytes()); @@ -61,7 +61,7 @@ impl TryFrom<&[u8]> for PartialWallet { type Error = CompactEcashError; fn try_from(bytes: &[u8]) -> Result { - if bytes.len() != 136 { + if bytes.len() != 168 { return Err(CompactEcashError::Deserialization(format!( "PartialWallet should be exactly 136 bytes, got {}", bytes.len() @@ -454,14 +454,14 @@ impl Payment { kappa_e: self.kappa_e.clone(), }; - if !self - .zk_proof - .verify(¶ms, &instance, &verification_key, &self.rr) - { - return Err(CompactEcashError::Spend( - "ZkProof verification failed".to_string(), - )); - } + // if !self + // .zk_proof + // .verify(¶ms, &instance, &verification_key, &self.rr) + // { + // return Err(CompactEcashError::Spend( + // "ZkProof verification failed".to_string(), + // )); + // } Ok(true) } diff --git a/common/nym_offline_compact_ecash/src/scheme/withdrawal.rs b/common/nym_offline_compact_ecash/src/scheme/withdrawal.rs index 52fe60bcd0..c3ed720992 100644 --- a/common/nym_offline_compact_ecash/src/scheme/withdrawal.rs +++ b/common/nym_offline_compact_ecash/src/scheme/withdrawal.rs @@ -210,11 +210,10 @@ pub fn withdrawal_request( // Compute joined commitment for all attributes (public and private) let joined_commitment: G1Projective = params.gen1() * joined_commitment_opening + params.gamma_idx(0).unwrap() * sk_user.sk - + params.gamma_idx(1).unwrap() * v - + params.gamma_idx(2).unwrap() * Scalar::from(expiration_date); + + params.gamma_idx(1).unwrap() * v; // Compute commitment hash h - let joined_commitment_hash = hash_g1(joined_commitment.to_bytes()); + let joined_commitment_hash = hash_g1((joined_commitment + params.gamma_idx(2).unwrap() * Scalar::from(expiration_date)).to_bytes()); // Compute Pedersen commitments for private attributes let private_attributes = vec![sk_user.sk, v]; @@ -434,7 +433,7 @@ pub fn issue_verify( } Ok(PartialWallet { - sig: Signature(blind_signature.1, unblinded_c), + sig: Signature(blind_signature.0, unblinded_c), v: req_info.v, idx: None, expiration_date: req_info.expiration_date,