Zk instructions pass (#22851)
* zk-token-sdk: re-organize transcript * zk-token-sdk: add pod ElGamal group encryption * zk-token-sdk: add transcript domain separators for sigma proofs * zk-token-sdk: clean up transfer tx decryption * zk-token-sdk: resolve encoding issues for transfer * zk-token-sdk: fix transfer test * zk-token-sdk: clean up transcript for close account and withdraw instructions * zk-token-sdk: add transfer with fee instruction * zk-token-sdk: add transfer with fee instruction * zk-token-sdk: add pod for cryptographic structs needed for fee * zk-token-sdk: add pod for fee sigma proof * zk-token-sdk: fix test for transfer with fee instruction * zk-token-sdk: add range proof verification for transfer with fee * zk-token-sdk: add transfer amount decryption for transfer-with-fee * zk-token-sdk: add proof generation error for instruction * zk-token-sdk: cargo fmt and clippy * zk-token-sdk: fix bpf build
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use {
|
||||
crate::errors::TranscriptError,
|
||||
crate::{errors::TranscriptError, zk_token_elgamal::pod},
|
||||
curve25519_dalek::{ristretto::CompressedRistretto, scalar::Scalar, traits::IsIdentity},
|
||||
merlin::Transcript,
|
||||
};
|
||||
@@ -19,9 +19,6 @@ pub trait TranscriptProtocol {
|
||||
/// Append a domain separator for close account proof.
|
||||
fn close_account_proof_domain_sep(&mut self);
|
||||
|
||||
/// Append a domain separator for update account public key proof.
|
||||
fn update_account_public_key_proof_domain_sep(&mut self);
|
||||
|
||||
/// Append a domain separator for withdraw proof.
|
||||
fn withdraw_proof_domain_sep(&mut self);
|
||||
|
||||
@@ -34,6 +31,33 @@ pub trait TranscriptProtocol {
|
||||
/// Append a `point` with the given `label`.
|
||||
fn append_point(&mut self, label: &'static [u8], point: &CompressedRistretto);
|
||||
|
||||
/// Append an ElGamal pubkey with the given `label`.
|
||||
fn append_pubkey(&mut self, label: &'static [u8], point: &pod::ElGamalPubkey);
|
||||
|
||||
/// Append an ElGamal ciphertext with the given `label`.
|
||||
fn append_ciphertext(&mut self, label: &'static [u8], point: &pod::ElGamalCiphertext);
|
||||
|
||||
/// Append a Pedersen commitment with the given `label`.
|
||||
fn append_commitment(&mut self, label: &'static [u8], point: &pod::PedersenCommitment);
|
||||
|
||||
/// Append an ElGamal decryption handle with the given `label`.
|
||||
fn append_handle(&mut self, label: &'static [u8], point: &pod::DecryptHandle);
|
||||
|
||||
/// Append a domain separator for equality proof.
|
||||
fn equality_proof_domain_sep(&mut self);
|
||||
|
||||
/// Append a domain separator for zero-balance proof.
|
||||
fn zero_balance_proof_domain_sep(&mut self);
|
||||
|
||||
/// Append a domain separator for validity proof.
|
||||
fn validity_proof_domain_sep(&mut self);
|
||||
|
||||
/// Append a domain separator for aggregated validity proof.
|
||||
fn aggregated_validity_proof_domain_sep(&mut self);
|
||||
|
||||
/// Append a domain separator for fee sigma proof.
|
||||
fn fee_sigma_proof_domain_sep(&mut self);
|
||||
|
||||
/// Check that a point is not the identity, then append it to the
|
||||
/// transcript. Otherwise, return an error.
|
||||
fn validate_and_append_point(
|
||||
@@ -66,10 +90,6 @@ impl TranscriptProtocol for Transcript {
|
||||
self.append_message(b"dom-sep", b"CloseAccountProof");
|
||||
}
|
||||
|
||||
fn update_account_public_key_proof_domain_sep(&mut self) {
|
||||
self.append_message(b"dom-sep", b"UpdateAccountPublicKeyProof");
|
||||
}
|
||||
|
||||
fn withdraw_proof_domain_sep(&mut self) {
|
||||
self.append_message(b"dom-sep", b"WithdrawProof");
|
||||
}
|
||||
@@ -105,4 +125,40 @@ impl TranscriptProtocol for Transcript {
|
||||
|
||||
Scalar::from_bytes_mod_order_wide(&buf)
|
||||
}
|
||||
|
||||
fn append_pubkey(&mut self, label: &'static [u8], pubkey: &pod::ElGamalPubkey) {
|
||||
self.append_message(label, &pubkey.0);
|
||||
}
|
||||
|
||||
fn append_ciphertext(&mut self, label: &'static [u8], ciphertext: &pod::ElGamalCiphertext) {
|
||||
self.append_message(label, &ciphertext.0);
|
||||
}
|
||||
|
||||
fn append_commitment(&mut self, label: &'static [u8], commitment: &pod::PedersenCommitment) {
|
||||
self.append_message(label, &commitment.0);
|
||||
}
|
||||
|
||||
fn append_handle(&mut self, label: &'static [u8], handle: &pod::DecryptHandle) {
|
||||
self.append_message(label, &handle.0);
|
||||
}
|
||||
|
||||
fn equality_proof_domain_sep(&mut self) {
|
||||
self.append_message(b"dom-sep", b"equality-proof")
|
||||
}
|
||||
|
||||
fn zero_balance_proof_domain_sep(&mut self) {
|
||||
self.append_message(b"dom-sep", b"zero-balance-proof")
|
||||
}
|
||||
|
||||
fn validity_proof_domain_sep(&mut self) {
|
||||
self.append_message(b"dom-sep", b"validity-proof")
|
||||
}
|
||||
|
||||
fn aggregated_validity_proof_domain_sep(&mut self) {
|
||||
self.append_message(b"dom-sep", b"aggregated-validity-proof")
|
||||
}
|
||||
|
||||
fn fee_sigma_proof_domain_sep(&mut self) {
|
||||
self.append_message(b"dom-sep", b"fee-sigma-proof")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user