Skip to content

Commit

Permalink
fix clippy; serde logic
Browse files Browse the repository at this point in the history
  • Loading branch information
abcalphabet committed Oct 2, 2024
1 parent e010003 commit 42e0193
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
1 change: 1 addition & 0 deletions token/confidential-transfer/proof-generation/src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub fn mint_split_proof_data(
let decryptable_supply_ciphertext = supply_elgamal_keypair
.pubkey()
.encrypt(current_decyptable_supply);
#[allow(clippy::arithmetic_side_effects)]
let ct_decryptable_to_current_diff = decryptable_supply_ciphertext - current_supply_ciphertext;
let decryptable_to_current_diff = supply_elgamal_keypair
.secret()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ fn test_mint_validity(mint_amount: u64, supply: u64) {
equality_proof_data,
ciphertext_validity_proof_data,
range_proof_data,
new_decryptable_supply: _,
} = mint_split_proof_data(
&supply_ciphertext,
&decryptable_supply,
Expand Down
26 changes: 9 additions & 17 deletions token/program-2022/src/serialization.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
//! serialization module - contains helpers for serde types from other crates,
//! deserialization visitors
use {
base64::{prelude::BASE64_STANDARD, Engine},
serde::de::Error,
};

/// helper function to ser/deser COption wrapped values
pub mod coption_fromstr {
use {
Expand Down Expand Up @@ -135,24 +130,22 @@ pub mod elgamalciphertext_fromstr {
de::{Error, Visitor},
Deserializer, Serializer,
},
solana_zk_token_sdk::zk_token_elgamal::pod::ElGamalCiphertext,
std::fmt,
solana_zk_sdk::encryption::pod::elgamal::PodElGamalCiphertext,
std::{fmt, str::FromStr},
};

const AE_CIPHERTEXT_LEN: usize = 64;

/// serialize AeCiphertext values supporting Display trait
pub fn serialize<S>(x: &ElGamalCiphertext, s: S) -> Result<S::Ok, S::Error>
pub fn serialie<S>(x: &PodElGamalCiphertext, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
s.serialize_str(&x.to_string())
}

struct AeCiphertextVisitor;
struct ElGamalCiphertextVisitor;

impl<'de> Visitor<'de> for AeCiphertextVisitor {
type Value = ElGamalCiphertext;
impl<'de> Visitor<'de> for ElGamalCiphertextVisitor {
type Value = PodElGamalCiphertext;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a FromStr type")
Expand All @@ -162,17 +155,16 @@ pub mod elgamalciphertext_fromstr {
where
E: Error,
{
let array = super::base64_to_bytes::<AE_CIPHERTEXT_LEN, E>(v)?;
Ok(ElGamalCiphertext(array))
FromStr::from_str(v).map_err(Error::custom)
}
}

/// deserialize AeCiphertext values from str
pub fn deserialize<'de, D>(d: D) -> Result<ElGamalCiphertext, D::Error>
pub fn deserialize<'de, D>(d: D) -> Result<PodElGamalCiphertext, D::Error>
where
D: Deserializer<'de>,
{
d.deserialize_str(AeCiphertextVisitor)
d.deserialize_str(ElGamalCiphertextVisitor)
}
}

Expand Down
8 changes: 1 addition & 7 deletions token/program-2022/tests/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ use {
solana_program::program_option::COption,
solana_sdk::pubkey::Pubkey,
spl_pod::optional_keys::{OptionalNonZeroElGamalPubkey, OptionalNonZeroPubkey},
spl_token_2022::{
extension::confidential_transfer,
instruction,
solana_zk_sdk::encryption::pod::{
auth_encryption::PodAeCiphertext, elgamal::PodElGamalPubkey,
},
},
spl_token_2022::{extension::confidential_transfer, instruction},
std::str::FromStr,
};

Expand Down

0 comments on commit 42e0193

Please sign in to comment.