refactor: create pod struct for ZeroBalanceProof

This commit is contained in:
Sam Kim 2021-12-16 09:15:29 -05:00 committed by Michael Vines
parent 208621e3cf
commit c26fa1d0e9
3 changed files with 29 additions and 4 deletions

View File

@ -11,6 +11,7 @@ use {
},
errors::ProofError,
instruction::Verifiable,
sigma_proofs::zero_balance_proof::ZeroBalanceProof,
transcript::TranscriptProtocol,
},
curve25519_dalek::{
@ -71,9 +72,7 @@ impl Verifiable for CloseAccountData {
#[repr(C)]
#[allow(non_snake_case)]
pub struct CloseAccountProof {
pub Y_P: pod::CompressedRistretto, // 32 bytes
pub Y_D: pod::CompressedRistretto, // 32 bytes
pub z: pod::Scalar, // 32 bytes
pub proof: pod::ZeroBalanceProof,
}
#[allow(non_snake_case)]
@ -89,6 +88,8 @@ impl CloseAccountProof {
// add a domain separator to record the start of the protocol
transcript.close_account_proof_domain_sep();
// extract the relevant scalar and Ristretto points from the input
let P = source_keypair.public.get_point();
let s = source_keypair.secret.get_scalar();

View File

@ -20,7 +20,7 @@ mod target_arch {
elgamal::{ElGamalCiphertext, ElGamalPubkey},
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,
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 {
type Error = ProofError;

View File

@ -69,6 +69,16 @@ pub struct ValidityProof(pub [u8; 160]);
unsafe impl Zeroable 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)
#[derive(Clone, Copy)]
#[repr(transparent)]