incorporate aes ciphertext for zk-proof instructions
This commit is contained in:
@ -6,6 +6,7 @@ use {
|
|||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
encryption::{
|
encryption::{
|
||||||
|
aes::AESCiphertext,
|
||||||
elgamal::{ElGamalCiphertext, ElGamalPubkey, ElGamalSecretKey},
|
elgamal::{ElGamalCiphertext, ElGamalPubkey, ElGamalSecretKey},
|
||||||
pedersen::{
|
pedersen::{
|
||||||
Pedersen, PedersenBase, PedersenCommitment, PedersenDecryptHandle, PedersenOpening,
|
Pedersen, PedersenBase, PedersenCommitment, PedersenDecryptHandle, PedersenOpening,
|
||||||
@ -46,10 +47,14 @@ pub struct TransferData {
|
|||||||
|
|
||||||
/// Zero-knowledge proofs for Transfer
|
/// Zero-knowledge proofs for Transfer
|
||||||
pub proof: TransferProof,
|
pub proof: TransferProof,
|
||||||
|
|
||||||
|
/// The new decryptable balance
|
||||||
|
pub aes_ciphertext: pod::OptionAESCiphertext, // 17 bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "bpf"))]
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
impl TransferData {
|
impl TransferData {
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
transfer_amount: u64,
|
transfer_amount: u64,
|
||||||
spendable_balance: u64,
|
spendable_balance: u64,
|
||||||
@ -58,6 +63,7 @@ impl TransferData {
|
|||||||
source_sk: &ElGamalSecretKey,
|
source_sk: &ElGamalSecretKey,
|
||||||
dest_pk: ElGamalPubkey,
|
dest_pk: ElGamalPubkey,
|
||||||
auditor_pk: ElGamalPubkey,
|
auditor_pk: ElGamalPubkey,
|
||||||
|
aes_ciphertext: Option<AESCiphertext>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// split and encrypt transfer amount
|
// split and encrypt transfer amount
|
||||||
//
|
//
|
||||||
@ -136,6 +142,7 @@ impl TransferData {
|
|||||||
new_spendable_ct: new_spendable_ct.into(),
|
new_spendable_ct: new_spendable_ct.into(),
|
||||||
transfer_public_keys,
|
transfer_public_keys,
|
||||||
proof,
|
proof,
|
||||||
|
aes_ciphertext: aes_ciphertext.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,6 +500,7 @@ mod test {
|
|||||||
&source_sk,
|
&source_sk,
|
||||||
dest_pk,
|
dest_pk,
|
||||||
auditor_pk,
|
auditor_pk,
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(transfer_data.verify().is_ok());
|
assert!(transfer_data.verify().is_ok());
|
||||||
@ -527,6 +535,7 @@ mod test {
|
|||||||
&source_sk,
|
&source_sk,
|
||||||
dest_pk,
|
dest_pk,
|
||||||
auditor_pk,
|
auditor_pk,
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
let decryption_data = decode_u32_precomputation_for_G();
|
let decryption_data = decode_u32_precomputation_for_G();
|
||||||
|
@ -8,6 +8,7 @@ use {
|
|||||||
encryption::{
|
encryption::{
|
||||||
elgamal::{ElGamalCiphertext, ElGamalPubkey, ElGamalSecretKey},
|
elgamal::{ElGamalCiphertext, ElGamalPubkey, ElGamalSecretKey},
|
||||||
pedersen::{PedersenBase, PedersenOpening},
|
pedersen::{PedersenBase, PedersenOpening},
|
||||||
|
aes::AESCiphertext,
|
||||||
},
|
},
|
||||||
errors::ProofError,
|
errors::ProofError,
|
||||||
instruction::Verifiable,
|
instruction::Verifiable,
|
||||||
@ -36,6 +37,9 @@ pub struct WithdrawData {
|
|||||||
|
|
||||||
/// Proof that the account is solvent
|
/// Proof that the account is solvent
|
||||||
pub proof: WithdrawProof, // 736 bytes
|
pub proof: WithdrawProof, // 736 bytes
|
||||||
|
|
||||||
|
/// The new decryptable balance component
|
||||||
|
pub aes_ciphertext: pod::OptionAESCiphertext, // 17 bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WithdrawData {
|
impl WithdrawData {
|
||||||
@ -46,6 +50,7 @@ impl WithdrawData {
|
|||||||
source_sk: &ElGamalSecretKey,
|
source_sk: &ElGamalSecretKey,
|
||||||
current_balance: u64,
|
current_balance: u64,
|
||||||
current_balance_ct: ElGamalCiphertext,
|
current_balance_ct: ElGamalCiphertext,
|
||||||
|
aes_ciphertext: Option<AESCiphertext>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// subtract withdraw amount from current balance
|
// subtract withdraw amount from current balance
|
||||||
//
|
//
|
||||||
@ -62,6 +67,7 @@ impl WithdrawData {
|
|||||||
Self {
|
Self {
|
||||||
final_balance_ct: final_balance_ct.into(),
|
final_balance_ct: final_balance_ct.into(),
|
||||||
proof,
|
proof,
|
||||||
|
aes_ciphertext: aes_ciphertext.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,6 +198,7 @@ mod test {
|
|||||||
&secret,
|
&secret,
|
||||||
current_balance,
|
current_balance,
|
||||||
current_balance_ct,
|
current_balance_ct,
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
assert!(data.verify().is_ok());
|
assert!(data.verify().is_ok());
|
||||||
|
|
||||||
@ -203,6 +210,7 @@ mod test {
|
|||||||
&secret,
|
&secret,
|
||||||
wrong_balance,
|
wrong_balance,
|
||||||
current_balance_ct,
|
current_balance_ct,
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
assert!(data.verify().is_err());
|
assert!(data.verify().is_err());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user