refactor: create pod struct for ZeroBalanceProof
This commit is contained in:
parent
208621e3cf
commit
c26fa1d0e9
|
@ -11,6 +11,7 @@ use {
|
||||||
},
|
},
|
||||||
errors::ProofError,
|
errors::ProofError,
|
||||||
instruction::Verifiable,
|
instruction::Verifiable,
|
||||||
|
sigma_proofs::zero_balance_proof::ZeroBalanceProof,
|
||||||
transcript::TranscriptProtocol,
|
transcript::TranscriptProtocol,
|
||||||
},
|
},
|
||||||
curve25519_dalek::{
|
curve25519_dalek::{
|
||||||
|
@ -71,9 +72,7 @@ impl Verifiable for CloseAccountData {
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub struct CloseAccountProof {
|
pub struct CloseAccountProof {
|
||||||
pub Y_P: pod::CompressedRistretto, // 32 bytes
|
pub proof: pod::ZeroBalanceProof,
|
||||||
pub Y_D: pod::CompressedRistretto, // 32 bytes
|
|
||||||
pub z: pod::Scalar, // 32 bytes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
@ -89,6 +88,8 @@ impl CloseAccountProof {
|
||||||
// add a domain separator to record the start of the protocol
|
// add a domain separator to record the start of the protocol
|
||||||
transcript.close_account_proof_domain_sep();
|
transcript.close_account_proof_domain_sep();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// extract the relevant scalar and Ristretto points from the input
|
// extract the relevant scalar and Ristretto points from the input
|
||||||
let P = source_keypair.public.get_point();
|
let P = source_keypair.public.get_point();
|
||||||
let s = source_keypair.secret.get_scalar();
|
let s = source_keypair.secret.get_scalar();
|
||||||
|
|
|
@ -20,7 +20,7 @@ mod target_arch {
|
||||||
elgamal::{ElGamalCiphertext, ElGamalPubkey},
|
elgamal::{ElGamalCiphertext, ElGamalPubkey},
|
||||||
pedersen::{PedersenCommitment, PedersenDecryptHandle},
|
pedersen::{PedersenCommitment, PedersenDecryptHandle},
|
||||||
},
|
},
|
||||||
sigma_proofs::{equality_proof::EqualityProof, validity_proof::ValidityProof},
|
sigma_proofs::{equality_proof::EqualityProof, validity_proof::ValidityProof, zero_balance_proof::ZeroBalanceProof},
|
||||||
errors::ProofError,
|
errors::ProofError,
|
||||||
range_proof::RangeProof,
|
range_proof::RangeProof,
|
||||||
},
|
},
|
||||||
|
@ -169,6 +169,20 @@ mod target_arch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ZeroBalanceProof> for pod::ZeroBalanceProof {
|
||||||
|
fn from(proof: ZeroBalanceProof) -> Self {
|
||||||
|
Self(proof.to_bytes())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<pod::ZeroBalanceProof> for ZeroBalanceProof {
|
||||||
|
type Error = ProofError;
|
||||||
|
|
||||||
|
fn try_from(pod: pod::ZeroBalanceProof) -> Result<Self, Self::Error> {
|
||||||
|
Self::from_bytes(&pod.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<RangeProof> for pod::RangeProof64 {
|
impl TryFrom<RangeProof> for pod::RangeProof64 {
|
||||||
type Error = ProofError;
|
type Error = ProofError;
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,16 @@ pub struct ValidityProof(pub [u8; 160]);
|
||||||
unsafe impl Zeroable for ValidityProof {}
|
unsafe impl Zeroable for ValidityProof {}
|
||||||
unsafe impl Pod for ValidityProof {}
|
unsafe impl Pod for ValidityProof {}
|
||||||
|
|
||||||
|
/// Serialization of zero balance proofs
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct ZeroBalanceProof(pub [u8; 160]);
|
||||||
|
|
||||||
|
// `ZeroBalanceProof` is a Pod and Zeroable.
|
||||||
|
// Add the marker traits manually because `bytemuck` only adds them for some `u8` arrays
|
||||||
|
unsafe impl Zeroable for ZeroBalanceProof {}
|
||||||
|
unsafe impl Pod for ZeroBalanceProof {}
|
||||||
|
|
||||||
/// Serialization of range proofs for 64-bit numbers (for `Withdraw` instruction)
|
/// Serialization of range proofs for 64-bit numbers (for `Withdraw` instruction)
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
|
|
Loading…
Reference in New Issue