[zk-token-sdk] Use `TryFrom<&[T]>` for `&[T]` instead of `arrayref` (#31959)
* remove `arrayref` from `auth_encryption` * remove `arrayref` from `sigma_proofs` * refactor `canonical_scalar_from_slice` * remove `arrayref` from `Cargo.toml` * cargo lock
This commit is contained in:
parent
91ec92cd76
commit
1bc101252c
|
@ -7250,7 +7250,6 @@ name = "solana-zk-token-sdk"
|
|||
version = "1.17.0"
|
||||
dependencies = [
|
||||
"aes-gcm-siv",
|
||||
"arrayref",
|
||||
"base64 0.21.2",
|
||||
"bincode",
|
||||
"bytemuck",
|
||||
|
|
|
@ -6264,7 +6264,6 @@ name = "solana-zk-token-sdk"
|
|||
version = "1.17.0"
|
||||
dependencies = [
|
||||
"aes-gcm-siv",
|
||||
"arrayref",
|
||||
"base64 0.21.2",
|
||||
"bincode",
|
||||
"bytemuck",
|
||||
|
|
|
@ -21,7 +21,6 @@ tiny-bip39 = { workspace = true }
|
|||
|
||||
[target.'cfg(not(target_os = "solana"))'.dependencies]
|
||||
aes-gcm-siv = { workspace = true }
|
||||
arrayref = { workspace = true }
|
||||
bincode = { workspace = true }
|
||||
byteorder = { workspace = true }
|
||||
curve25519-dalek = { workspace = true, features = ["serde"] }
|
||||
|
|
|
@ -12,7 +12,6 @@ use {
|
|||
thiserror::Error,
|
||||
};
|
||||
use {
|
||||
arrayref::{array_ref, array_refs},
|
||||
base64::{prelude::BASE64_STANDARD, Engine},
|
||||
sha3::{Digest, Sha3_512},
|
||||
solana_sdk::{
|
||||
|
@ -218,13 +217,10 @@ impl AeCiphertext {
|
|||
return None;
|
||||
}
|
||||
|
||||
let bytes = array_ref![bytes, 0, 36];
|
||||
let (nonce, ciphertext) = array_refs![bytes, 12, 24];
|
||||
let nonce = bytes[..32].try_into().ok()?;
|
||||
let ciphertext = bytes[32..].try_into().ok()?;
|
||||
|
||||
Some(AeCiphertext {
|
||||
nonce: *nonce,
|
||||
ciphertext: *ciphertext,
|
||||
})
|
||||
Some(AeCiphertext { nonce, ciphertext })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use {
|
|||
pedersen::{PedersenOpening, G, H},
|
||||
},
|
||||
errors::ProofVerificationError,
|
||||
sigma_proofs::canonical_scalar_from_slice,
|
||||
},
|
||||
curve25519_dalek::traits::MultiscalarMul,
|
||||
rand::rngs::OsRng,
|
||||
|
@ -18,7 +19,6 @@ use {
|
|||
};
|
||||
use {
|
||||
crate::{sigma_proofs::errors::EqualityProofError, transcript::TranscriptProtocol},
|
||||
arrayref::{array_ref, array_refs},
|
||||
curve25519_dalek::{
|
||||
ristretto::{CompressedRistretto, RistrettoPoint},
|
||||
scalar::Scalar,
|
||||
|
@ -239,20 +239,13 @@ impl CiphertextCiphertextEqualityProof {
|
|||
return Err(ProofVerificationError::Deserialization.into());
|
||||
}
|
||||
|
||||
let bytes = array_ref![bytes, 0, 224];
|
||||
let (Y_0, Y_1, Y_2, Y_3, z_s, z_x, z_r) = array_refs![bytes, 32, 32, 32, 32, 32, 32, 32];
|
||||
|
||||
let Y_0 = CompressedRistretto::from_slice(Y_0);
|
||||
let Y_1 = CompressedRistretto::from_slice(Y_1);
|
||||
let Y_2 = CompressedRistretto::from_slice(Y_2);
|
||||
let Y_3 = CompressedRistretto::from_slice(Y_3);
|
||||
|
||||
let z_s =
|
||||
Scalar::from_canonical_bytes(*z_s).ok_or(ProofVerificationError::Deserialization)?;
|
||||
let z_x =
|
||||
Scalar::from_canonical_bytes(*z_x).ok_or(ProofVerificationError::Deserialization)?;
|
||||
let z_r =
|
||||
Scalar::from_canonical_bytes(*z_r).ok_or(ProofVerificationError::Deserialization)?;
|
||||
let Y_0 = CompressedRistretto::from_slice(&bytes[..32]);
|
||||
let Y_1 = CompressedRistretto::from_slice(&bytes[32..64]);
|
||||
let Y_2 = CompressedRistretto::from_slice(&bytes[64..96]);
|
||||
let Y_3 = CompressedRistretto::from_slice(&bytes[96..128]);
|
||||
let z_s = canonical_scalar_from_slice(&bytes[128..160])?;
|
||||
let z_x = canonical_scalar_from_slice(&bytes[160..192])?;
|
||||
let z_r = canonical_scalar_from_slice(&bytes[192..224])?;
|
||||
|
||||
Ok(CiphertextCiphertextEqualityProof {
|
||||
Y_0,
|
||||
|
|
|
@ -16,6 +16,7 @@ use {
|
|||
pedersen::{PedersenCommitment, PedersenOpening, G, H},
|
||||
},
|
||||
errors::ProofVerificationError,
|
||||
sigma_proofs::canonical_scalar_from_slice,
|
||||
},
|
||||
curve25519_dalek::traits::MultiscalarMul,
|
||||
rand::rngs::OsRng,
|
||||
|
@ -23,7 +24,6 @@ use {
|
|||
};
|
||||
use {
|
||||
crate::{sigma_proofs::errors::EqualityProofError, transcript::TranscriptProtocol},
|
||||
arrayref::{array_ref, array_refs},
|
||||
curve25519_dalek::{
|
||||
ristretto::{CompressedRistretto, RistrettoPoint},
|
||||
scalar::Scalar,
|
||||
|
@ -219,19 +219,12 @@ impl CiphertextCommitmentEqualityProof {
|
|||
return Err(ProofVerificationError::Deserialization.into());
|
||||
}
|
||||
|
||||
let bytes = array_ref![bytes, 0, 192];
|
||||
let (Y_0, Y_1, Y_2, z_s, z_x, z_r) = array_refs![bytes, 32, 32, 32, 32, 32, 32];
|
||||
|
||||
let Y_0 = CompressedRistretto::from_slice(Y_0);
|
||||
let Y_1 = CompressedRistretto::from_slice(Y_1);
|
||||
let Y_2 = CompressedRistretto::from_slice(Y_2);
|
||||
|
||||
let z_s =
|
||||
Scalar::from_canonical_bytes(*z_s).ok_or(ProofVerificationError::Deserialization)?;
|
||||
let z_x =
|
||||
Scalar::from_canonical_bytes(*z_x).ok_or(ProofVerificationError::Deserialization)?;
|
||||
let z_r =
|
||||
Scalar::from_canonical_bytes(*z_r).ok_or(ProofVerificationError::Deserialization)?;
|
||||
let Y_0 = CompressedRistretto::from_slice(&bytes[..32]);
|
||||
let Y_1 = CompressedRistretto::from_slice(&bytes[32..64]);
|
||||
let Y_2 = CompressedRistretto::from_slice(&bytes[64..96]);
|
||||
let z_s = canonical_scalar_from_slice(&bytes[96..128])?;
|
||||
let z_x = canonical_scalar_from_slice(&bytes[128..160])?;
|
||||
let z_r = canonical_scalar_from_slice(&bytes[160..192])?;
|
||||
|
||||
Ok(CiphertextCommitmentEqualityProof {
|
||||
Y_0,
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
|
||||
#[cfg(not(target_os = "solana"))]
|
||||
use {
|
||||
crate::encryption::pedersen::{PedersenCommitment, PedersenOpening, G, H},
|
||||
crate::{
|
||||
encryption::pedersen::{PedersenCommitment, PedersenOpening, G, H},
|
||||
sigma_proofs::canonical_scalar_from_slice,
|
||||
},
|
||||
rand::rngs::OsRng,
|
||||
};
|
||||
use {
|
||||
|
@ -12,7 +15,6 @@ use {
|
|||
errors::ProofVerificationError, sigma_proofs::errors::FeeSigmaProofError,
|
||||
transcript::TranscriptProtocol,
|
||||
},
|
||||
arrayref::{array_ref, array_refs},
|
||||
curve25519_dalek::{
|
||||
ristretto::{CompressedRistretto, RistrettoPoint},
|
||||
scalar::Scalar,
|
||||
|
@ -367,24 +369,15 @@ impl FeeSigmaProof {
|
|||
return Err(ProofVerificationError::Deserialization.into());
|
||||
}
|
||||
|
||||
let bytes = array_ref![bytes, 0, 256];
|
||||
let (Y_max_proof, z_max_proof, c_max_proof, Y_delta, Y_claimed, z_x, z_delta, z_claimed) =
|
||||
array_refs![bytes, 32, 32, 32, 32, 32, 32, 32, 32];
|
||||
let Y_max_proof = CompressedRistretto::from_slice(&bytes[..32]);
|
||||
let z_max_proof = canonical_scalar_from_slice(&bytes[32..64])?;
|
||||
let c_max_proof = canonical_scalar_from_slice(&bytes[64..96])?;
|
||||
|
||||
let Y_max_proof = CompressedRistretto::from_slice(Y_max_proof);
|
||||
let z_max_proof = Scalar::from_canonical_bytes(*z_max_proof)
|
||||
.ok_or(ProofVerificationError::Deserialization)?;
|
||||
let c_max_proof = Scalar::from_canonical_bytes(*c_max_proof)
|
||||
.ok_or(ProofVerificationError::Deserialization)?;
|
||||
|
||||
let Y_delta = CompressedRistretto::from_slice(Y_delta);
|
||||
let Y_claimed = CompressedRistretto::from_slice(Y_claimed);
|
||||
let z_x =
|
||||
Scalar::from_canonical_bytes(*z_x).ok_or(ProofVerificationError::Deserialization)?;
|
||||
let z_delta = Scalar::from_canonical_bytes(*z_delta)
|
||||
.ok_or(ProofVerificationError::Deserialization)?;
|
||||
let z_claimed = Scalar::from_canonical_bytes(*z_claimed)
|
||||
.ok_or(ProofVerificationError::Deserialization)?;
|
||||
let Y_delta = CompressedRistretto::from_slice(&bytes[96..128]);
|
||||
let Y_claimed = CompressedRistretto::from_slice(&bytes[128..160]);
|
||||
let z_x = canonical_scalar_from_slice(&bytes[160..192])?;
|
||||
let z_delta = canonical_scalar_from_slice(&bytes[192..224])?;
|
||||
let z_claimed = canonical_scalar_from_slice(&bytes[224..256])?;
|
||||
|
||||
Ok(Self {
|
||||
fee_max_proof: FeeMaxProof {
|
||||
|
|
|
@ -16,6 +16,7 @@ use {
|
|||
pedersen::{PedersenCommitment, PedersenOpening, G, H},
|
||||
},
|
||||
errors::ProofVerificationError,
|
||||
sigma_proofs::canonical_scalar_from_slice,
|
||||
},
|
||||
curve25519_dalek::traits::MultiscalarMul,
|
||||
rand::rngs::OsRng,
|
||||
|
@ -23,7 +24,6 @@ use {
|
|||
};
|
||||
use {
|
||||
crate::{sigma_proofs::errors::ValidityProofError, transcript::TranscriptProtocol},
|
||||
arrayref::{array_ref, array_refs},
|
||||
curve25519_dalek::{
|
||||
ristretto::{CompressedRistretto, RistrettoPoint},
|
||||
scalar::Scalar,
|
||||
|
@ -209,17 +209,11 @@ impl GroupedCiphertext2HandlesValidityProof {
|
|||
return Err(ProofVerificationError::Deserialization.into());
|
||||
}
|
||||
|
||||
let bytes = array_ref![bytes, 0, 160];
|
||||
let (Y_0, Y_1, Y_2, z_r, z_x) = array_refs![bytes, 32, 32, 32, 32, 32];
|
||||
|
||||
let Y_0 = CompressedRistretto::from_slice(Y_0);
|
||||
let Y_1 = CompressedRistretto::from_slice(Y_1);
|
||||
let Y_2 = CompressedRistretto::from_slice(Y_2);
|
||||
|
||||
let z_r =
|
||||
Scalar::from_canonical_bytes(*z_r).ok_or(ProofVerificationError::Deserialization)?;
|
||||
let z_x =
|
||||
Scalar::from_canonical_bytes(*z_x).ok_or(ProofVerificationError::Deserialization)?;
|
||||
let Y_0 = CompressedRistretto::from_slice(&bytes[..32]);
|
||||
let Y_1 = CompressedRistretto::from_slice(&bytes[32..64]);
|
||||
let Y_2 = CompressedRistretto::from_slice(&bytes[64..96]);
|
||||
let z_r = canonical_scalar_from_slice(&bytes[96..128])?;
|
||||
let z_x = canonical_scalar_from_slice(&bytes[128..160])?;
|
||||
|
||||
Ok(GroupedCiphertext2HandlesValidityProof {
|
||||
Y_0,
|
||||
|
|
|
@ -23,3 +23,21 @@ pub mod fee_proof;
|
|||
pub mod grouped_ciphertext_validity_proof;
|
||||
pub mod pubkey_proof;
|
||||
pub mod zero_balance_proof;
|
||||
|
||||
#[cfg(not(target_os = "solana"))]
|
||||
use {crate::errors::ProofVerificationError, curve25519_dalek::scalar::Scalar};
|
||||
|
||||
#[cfg(not(target_os = "solana"))]
|
||||
fn canonical_scalar_from_slice(bytes: &[u8]) -> Result<Scalar, ProofVerificationError> {
|
||||
if bytes.len() != 32 {
|
||||
return Err(ProofVerificationError::Deserialization);
|
||||
}
|
||||
|
||||
let scalar_bytes = bytes[..32]
|
||||
.try_into()
|
||||
.map_err(|_| ProofVerificationError::Deserialization)?;
|
||||
|
||||
let scalar = Scalar::from_canonical_bytes(scalar_bytes)
|
||||
.ok_or(ProofVerificationError::Deserialization)?;
|
||||
Ok(scalar)
|
||||
}
|
||||
|
|
|
@ -5,9 +5,12 @@
|
|||
|
||||
#[cfg(not(target_os = "solana"))]
|
||||
use {
|
||||
crate::encryption::{
|
||||
elgamal::{ElGamalKeypair, ElGamalPubkey},
|
||||
pedersen::H,
|
||||
crate::{
|
||||
encryption::{
|
||||
elgamal::{ElGamalKeypair, ElGamalPubkey},
|
||||
pedersen::H,
|
||||
},
|
||||
sigma_proofs::canonical_scalar_from_slice,
|
||||
},
|
||||
rand::rngs::OsRng,
|
||||
zeroize::Zeroize,
|
||||
|
@ -17,7 +20,6 @@ use {
|
|||
errors::ProofVerificationError, sigma_proofs::errors::PubkeyValidityProofError,
|
||||
transcript::TranscriptProtocol,
|
||||
},
|
||||
arrayref::{array_ref, array_refs},
|
||||
curve25519_dalek::{
|
||||
ristretto::{CompressedRistretto, RistrettoPoint},
|
||||
scalar::Scalar,
|
||||
|
@ -126,11 +128,8 @@ impl PubkeyValidityProof {
|
|||
return Err(ProofVerificationError::Deserialization.into());
|
||||
}
|
||||
|
||||
let bytes = array_ref![bytes, 0, 64];
|
||||
let (Y, z) = array_refs![bytes, 32, 32];
|
||||
|
||||
let Y = CompressedRistretto::from_slice(Y);
|
||||
let z = Scalar::from_canonical_bytes(*z).ok_or(ProofVerificationError::Deserialization)?;
|
||||
let Y = CompressedRistretto::from_slice(&bytes[..32]);
|
||||
let z = canonical_scalar_from_slice(&bytes[32..64])?;
|
||||
|
||||
Ok(PubkeyValidityProof { Y, z })
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use {
|
|||
pedersen::H,
|
||||
},
|
||||
errors::ProofVerificationError,
|
||||
sigma_proofs::canonical_scalar_from_slice,
|
||||
},
|
||||
curve25519_dalek::traits::MultiscalarMul,
|
||||
rand::rngs::OsRng,
|
||||
|
@ -18,7 +19,6 @@ use {
|
|||
};
|
||||
use {
|
||||
crate::{sigma_proofs::errors::ZeroBalanceProofError, transcript::TranscriptProtocol},
|
||||
arrayref::{array_ref, array_refs},
|
||||
curve25519_dalek::{
|
||||
ristretto::{CompressedRistretto, RistrettoPoint},
|
||||
scalar::Scalar,
|
||||
|
@ -165,13 +165,9 @@ impl ZeroBalanceProof {
|
|||
return Err(ProofVerificationError::Deserialization.into());
|
||||
}
|
||||
|
||||
let bytes = array_ref![bytes, 0, 96];
|
||||
let (Y_P, Y_D, z) = array_refs![bytes, 32, 32, 32];
|
||||
|
||||
let Y_P = CompressedRistretto::from_slice(Y_P);
|
||||
let Y_D = CompressedRistretto::from_slice(Y_D);
|
||||
|
||||
let z = Scalar::from_canonical_bytes(*z).ok_or(ProofVerificationError::Deserialization)?;
|
||||
let Y_P = CompressedRistretto::from_slice(&bytes[..32]);
|
||||
let Y_D = CompressedRistretto::from_slice(&bytes[32..64]);
|
||||
let z = canonical_scalar_from_slice(&bytes[64..96])?;
|
||||
|
||||
Ok(ZeroBalanceProof { Y_P, Y_D, z })
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue