Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 9daa22c

Browse files
committed
update program-2022 to use zk-sdk
1 parent 92b05b7 commit 9daa22c

File tree

11 files changed

+78
-84
lines changed

11 files changed

+78
-84
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token/program-2022/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ num-traits = "0.2"
2424
num_enum = "0.7.3"
2525
solana-program = "2.0.3"
2626
solana-security-txt = "1.1.1"
27-
solana-zk-token-sdk = "2.0.3"
27+
solana-zk-sdk = "2.0.3"
2828
spl-memo = { version = "5.0", path = "../../memo/program", features = [ "no-entrypoint" ] }
2929
spl-token = { version = "6.0", path = "../program", features = ["no-entrypoint"] }
3030
spl-token-group-interface = { version = "0.3.0", path = "../../token-group/interface" }

token/program-2022/src/extension/confidential_transfer/instruction.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#[cfg(not(target_os = "solana"))]
2-
use solana_zk_token_sdk::encryption::auth_encryption::AeCiphertext;
3-
pub use solana_zk_token_sdk::{
4-
zk_token_proof_instruction::*, zk_token_proof_state::ProofContextState,
1+
pub use solana_zk_sdk::zk_elgamal_proof_program::{
2+
instruction::ProofInstruction, proof_data::*, state::ProofContextState,
53
};
4+
65
#[cfg(feature = "serde-traits")]
76
use {
87
crate::serialization::aeciphertext_fromstr,
@@ -638,7 +637,7 @@ pub fn initialize_mint(
638637
mint: &Pubkey,
639638
authority: Option<Pubkey>,
640639
auto_approve_new_accounts: bool,
641-
auditor_elgamal_pubkey: Option<ElGamalPubkey>,
640+
auditor_elgamal_pubkey: Option<PodElGamalPubkey>,
642641
) -> Result<Instruction, ProgramError> {
643642
check_program_account(token_program_id)?;
644643
let accounts = vec![AccountMeta::new(*mint, false)];
@@ -663,7 +662,7 @@ pub fn update_mint(
663662
authority: &Pubkey,
664663
multisig_signers: &[&Pubkey],
665664
auto_approve_new_accounts: bool,
666-
auditor_elgamal_pubkey: Option<ElGamalPubkey>,
665+
auditor_elgamal_pubkey: Option<PodElGamalPubkey>,
667666
) -> Result<Instruction, ProgramError> {
668667
check_program_account(token_program_id)?;
669668
let mut accounts = vec![
@@ -693,11 +692,11 @@ pub fn inner_configure_account(
693692
token_program_id: &Pubkey,
694693
token_account: &Pubkey,
695694
mint: &Pubkey,
696-
decryptable_zero_balance: AeCiphertext,
695+
decryptable_zero_balance: PodAeCiphertext,
697696
maximum_pending_balance_credit_counter: u64,
698697
authority: &Pubkey,
699698
multisig_signers: &[&Pubkey],
700-
proof_data_location: ProofLocation<PubkeyValidityData>,
699+
proof_data_location: ProofLocation<PubkeyValidityProofData>,
701700
) -> Result<Instruction, ProgramError> {
702701
check_program_account(token_program_id)?;
703702

@@ -748,11 +747,11 @@ pub fn configure_account(
748747
token_program_id: &Pubkey,
749748
token_account: &Pubkey,
750749
mint: &Pubkey,
751-
decryptable_zero_balance: AeCiphertext,
750+
decryptable_zero_balance: PodAeCiphertext,
752751
maximum_pending_balance_credit_counter: u64,
753752
authority: &Pubkey,
754753
multisig_signers: &[&Pubkey],
755-
proof_data_location: ProofLocation<PubkeyValidityData>,
754+
proof_data_location: ProofLocation<PubkeyValidityProofData>,
756755
) -> Result<Vec<Instruction>, ProgramError> {
757756
let mut instructions = vec![inner_configure_account(
758757
token_program_id,
@@ -777,9 +776,8 @@ pub fn configure_account(
777776
return Err(TokenError::InvalidProofInstructionOffset.into());
778777
}
779778
match proof_data {
780-
ProofData::InstructionData(data) => {
781-
instructions.push(verify_pubkey_validity(None, data))
782-
}
779+
ProofData::InstructionData(data) => instructions
780+
.push(ProofInstruction::VerifyPubkeyValidity.encode_verify_proof(None, data)),
783781
ProofData::RecordAccount(address, offset) => instructions.push(
784782
ProofInstruction::VerifyPubkeyValidity
785783
.encode_verify_proof_from_account(None, address, offset),
@@ -824,7 +822,7 @@ pub fn inner_empty_account(
824822
token_account: &Pubkey,
825823
authority: &Pubkey,
826824
multisig_signers: &[&Pubkey],
827-
proof_data_location: ProofLocation<ZeroBalanceProofData>,
825+
proof_data_location: ProofLocation<ZeroCiphertextProofData>,
828826
) -> Result<Instruction, ProgramError> {
829827
check_program_account(token_program_id)?;
830828
let mut accounts = vec![AccountMeta::new(*token_account, false)];
@@ -869,7 +867,7 @@ pub fn empty_account(
869867
token_account: &Pubkey,
870868
authority: &Pubkey,
871869
multisig_signers: &[&Pubkey],
872-
proof_data_location: ProofLocation<ZeroBalanceProofData>,
870+
proof_data_location: ProofLocation<ZeroCiphertextProofData>,
873871
) -> Result<Vec<Instruction>, ProgramError> {
874872
let mut instructions = vec![inner_empty_account(
875873
token_program_id,
@@ -891,9 +889,10 @@ pub fn empty_account(
891889
return Err(TokenError::InvalidProofInstructionOffset.into());
892890
}
893891
match proof_data {
894-
ProofData::InstructionData(data) => instructions.push(verify_zero_balance(None, data)),
892+
ProofData::InstructionData(data) => instructions
893+
.push(ProofInstruction::VerifyZeroCiphertext.encode_verify_proof(None, data)),
895894
ProofData::RecordAccount(address, offset) => instructions.push(
896-
ProofInstruction::VerifyZeroBalance
895+
ProofInstruction::VerifyZeroCiphertext
897896
.encode_verify_proof_from_account(None, address, offset),
898897
),
899898
};
@@ -1002,7 +1001,7 @@ pub fn withdraw(
10021001
mint: &Pubkey,
10031002
amount: u64,
10041003
decimals: u8,
1005-
new_decryptable_available_balance: AeCiphertext,
1004+
new_decryptable_available_balance: PodAeCiphertext,
10061005
authority: &Pubkey,
10071006
multisig_signers: &[&Pubkey],
10081007
proof_data_location: ProofLocation<WithdrawData>,
@@ -1261,7 +1260,7 @@ pub fn apply_pending_balance(
12611260
token_program_id: &Pubkey,
12621261
token_account: &Pubkey,
12631262
pending_balance_instructions: u64,
1264-
new_decryptable_available_balance: AeCiphertext,
1263+
new_decryptable_available_balance: PodAeCiphertext,
12651264
authority: &Pubkey,
12661265
multisig_signers: &[&Pubkey],
12671266
) -> Result<Instruction, ProgramError> {
@@ -1381,7 +1380,7 @@ pub fn inner_transfer_with_fee(
13811380
transfer_amount_ciphertext_validity_proof_data_location: ProofLocation<
13821381
BatchedGroupedCiphertext3HandlesValidityProofData,
13831382
>,
1384-
fee_sigma_proof_data_location: ProofLocation<FeeSigmaProofData>,
1383+
fee_sigma_proof_data_location: ProofLocation<PercentageWithCapProofData>,
13851384
fee_ciphertext_validity_proof_data_location: ProofLocation<
13861385
BatchedGroupedCiphertext2HandlesValidityProofData,
13871386
>,
@@ -1507,7 +1506,7 @@ pub fn transfer_with_fee(
15071506
transfer_amount_ciphertext_validity_proof_data_location: ProofLocation<
15081507
BatchedGroupedCiphertext3HandlesValidityProofData,
15091508
>,
1510-
fee_sigma_proof_data_location: ProofLocation<FeeSigmaProofData>,
1509+
fee_sigma_proof_data_location: ProofLocation<PercentageWithCapProofData>,
15111510
fee_ciphertext_validity_proof_data_location: ProofLocation<
15121511
BatchedGroupedCiphertext2HandlesValidityProofData,
15131512
>,
@@ -1574,11 +1573,10 @@ pub fn transfer_with_fee(
15741573
return Err(TokenError::InvalidProofInstructionOffset.into());
15751574
}
15761575
match proof_data {
1577-
ProofData::InstructionData(data) => {
1578-
instructions.push(ProofInstruction::VerifyFeeSigma.encode_verify_proof(None, data))
1579-
}
1576+
ProofData::InstructionData(data) => instructions
1577+
.push(ProofInstruction::VerifyPercentageWithCap.encode_verify_proof(None, data)),
15801578
ProofData::RecordAccount(address, offset) => instructions.push(
1581-
ProofInstruction::VerifyFeeSigma
1579+
ProofInstruction::VerifyPercentageWithCap
15821580
.encode_verify_proof_from_account(None, address, offset),
15831581
),
15841582
};

token/program-2022/src/extension/confidential_transfer/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use {
55
},
66
bytemuck::{Pod, Zeroable},
77
solana_program::entrypoint::ProgramResult,
8-
solana_zk_token_sdk::zk_token_elgamal::pod::{AeCiphertext, ElGamalCiphertext, ElGamalPubkey},
8+
solana_zk_sdk::encryption::pod::{
9+
auth_encryption::PodAeCiphertext,
10+
elgamal::{PodElGamalCiphertext, PodElGamalPubkey},
11+
},
912
spl_pod::{
1013
optional_keys::{OptionalNonZeroElGamalPubkey, OptionalNonZeroPubkey},
1114
primitives::{PodBool, PodU64},
@@ -48,9 +51,9 @@ pub mod account_info;
4851
pub mod ciphertext_extraction;
4952

5053
/// ElGamal ciphertext containing an account balance
51-
pub type EncryptedBalance = ElGamalCiphertext;
54+
pub type EncryptedBalance = PodElGamalCiphertext;
5255
/// Authenticated encryption containing an account balance
53-
pub type DecryptableBalance = AeCiphertext;
56+
pub type DecryptableBalance = PodAeCiphertext;
5457

5558
/// Confidential transfer mint configuration
5659
#[repr(C)]
@@ -89,7 +92,7 @@ pub struct ConfidentialTransferAccount {
8992
pub approved: PodBool,
9093

9194
/// The public key associated with ElGamal encryption
92-
pub elgamal_pubkey: ElGamalPubkey,
95+
pub elgamal_pubkey: PodElGamalPubkey,
9396

9497
/// The low 16 bits of the pending balance (encrypted by `elgamal_pubkey`)
9598
pub pending_balance_lo: EncryptedBalance,

token/program-2022/src/extension/confidential_transfer/processor.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,10 @@ fn process_configure_account(
102102
let mint_info = next_account_info(account_info_iter)?;
103103

104104
// zero-knowledge proof certifies that the supplied ElGamal public key is valid
105-
let proof_context = verify_and_extract_context::<PubkeyValidityData, PubkeyValidityProofContext>(
106-
account_info_iter,
107-
proof_instruction_offset,
108-
None,
109-
)?;
105+
let proof_context = verify_and_extract_context::<
106+
PubkeyValidityProofData,
107+
PubkeyValidityProofContext,
108+
>(account_info_iter, proof_instruction_offset, None)?;
110109

111110
let authority_info = next_account_info(account_info_iter)?;
112111
let authority_info_data_len = authority_info.data_len();
@@ -210,11 +209,10 @@ fn process_empty_account(
210209

211210
// zero-knowledge proof certifies that the available balance ciphertext holds
212211
// the balance of 0.
213-
let proof_context = verify_and_extract_context::<ZeroBalanceProofData, ZeroBalanceProofContext>(
214-
account_info_iter,
215-
proof_instruction_offset,
216-
None,
217-
)?;
212+
let proof_context = verify_and_extract_context::<
213+
ZeroCiphertextProofData,
214+
ZeroCiphertextProofContext,
215+
>(account_info_iter, proof_instruction_offset, None)?;
218216

219217
let authority_info = next_account_info(account_info_iter)?;
220218
let authority_info_data_len = authority_info.data_len();

token/program-2022/src/extension/confidential_transfer/verify_proof.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn verify_transfer_with_fee_proof(
111111
)?;
112112

113113
let fee_sigma_proof_context =
114-
verify_and_extract_context::<FeeSigmaProofData, FeeSigmaProofContext>(
114+
verify_and_extract_context::<PercentageWithCapProofData, PercentageWithCapProofContext>(
115115
account_info_iter,
116116
fee_sigma_proof_instruction_offset,
117117
sysvar_account_info,

token/program-2022/src/extension/confidential_transfer_fee/instruction.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ use {
88
check_program_account,
99
error::TokenError,
1010
extension::confidential_transfer::{
11-
instruction::{
12-
verify_ciphertext_ciphertext_equality, CiphertextCiphertextEqualityProofData,
13-
},
14-
DecryptableBalance,
11+
instruction::CiphertextCiphertextEqualityProofData, DecryptableBalance,
1512
},
1613
instruction::{encode_instruction, TokenInstruction},
1714
proof::{ProofData, ProofLocation},
18-
solana_zk_token_sdk::{
19-
zk_token_elgamal::pod::ElGamalPubkey, zk_token_proof_instruction::ProofInstruction,
15+
solana_zk_sdk::{
16+
encryption::pod::elgamal::PodElGamalPubkey,
17+
zk_elgamal_proof_program::instruction::ProofInstruction,
2018
},
2119
},
2220
bytemuck::{Pod, Zeroable},
@@ -233,7 +231,7 @@ pub struct InitializeConfidentialTransferFeeConfigData {
233231

234232
/// ElGamal public key used to encrypt withheld fees.
235233
#[cfg_attr(feature = "serde-traits", serde(with = "elgamalpubkey_fromstr"))]
236-
pub withdraw_withheld_authority_elgamal_pubkey: ElGamalPubkey,
234+
pub withdraw_withheld_authority_elgamal_pubkey: PodElGamalPubkey,
237235
}
238236

239237
/// Data expected by
@@ -277,7 +275,7 @@ pub fn initialize_confidential_transfer_fee_config(
277275
token_program_id: &Pubkey,
278276
mint: &Pubkey,
279277
authority: Option<Pubkey>,
280-
withdraw_withheld_authority_elgamal_pubkey: ElGamalPubkey,
278+
withdraw_withheld_authority_elgamal_pubkey: PodElGamalPubkey,
281279
) -> Result<Instruction, ProgramError> {
282280
check_program_account(token_program_id)?;
283281
let accounts = vec![AccountMeta::new(*mint, false)];
@@ -380,9 +378,10 @@ pub fn withdraw_withheld_tokens_from_mint(
380378
return Err(TokenError::InvalidProofInstructionOffset.into());
381379
}
382380
match proof_data {
383-
ProofData::InstructionData(data) => {
384-
instructions.push(verify_ciphertext_ciphertext_equality(None, data))
385-
}
381+
ProofData::InstructionData(data) => instructions.push(
382+
ProofInstruction::VerifyCiphertextCiphertextEquality
383+
.encode_verify_proof(None, data),
384+
),
386385
ProofData::RecordAccount(address, offset) => instructions.push(
387386
ProofInstruction::VerifyCiphertextCiphertextEquality
388387
.encode_verify_proof_from_account(None, address, offset),
@@ -491,9 +490,10 @@ pub fn withdraw_withheld_tokens_from_accounts(
491490
return Err(TokenError::InvalidProofInstructionOffset.into());
492491
}
493492
match proof_data {
494-
ProofData::InstructionData(data) => {
495-
instructions.push(verify_ciphertext_ciphertext_equality(None, data))
496-
}
493+
ProofData::InstructionData(data) => instructions.push(
494+
ProofInstruction::VerifyCiphertextCiphertextEquality
495+
.encode_verify_proof(None, data),
496+
),
497497
ProofData::RecordAccount(address, offset) => instructions.push(
498498
ProofInstruction::VerifyCiphertextCiphertextEquality
499499
.encode_verify_proof_from_account(None, address, offset),

token/program-2022/src/extension/confidential_transfer_fee/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use {
55
},
66
bytemuck::{Pod, Zeroable},
77
solana_program::entrypoint::ProgramResult,
8-
solana_zk_token_sdk::zk_token_elgamal::pod::{ElGamalCiphertext, ElGamalPubkey, FeeEncryption},
8+
solana_zk_sdk::encryption::pod::elgamal::{PodElGamalCiphertext, PodElGamalPubkey},
99
spl_pod::{optional_keys::OptionalNonZeroPubkey, primitives::PodBool},
1010
};
1111

@@ -23,7 +23,7 @@ pub mod account_info;
2323
/// ElGamal ciphertext containing a transfer fee
2424
pub type EncryptedFee = FeeEncryption;
2525
/// ElGamal ciphertext containing a withheld fee in an account
26-
pub type EncryptedWithheldAmount = ElGamalCiphertext;
26+
pub type EncryptedWithheldAmount = PodElGamalCiphertext;
2727

2828
/// Confidential transfer fee extension data for mints
2929
#[repr(C)]
@@ -38,7 +38,7 @@ pub struct ConfidentialTransferFeeConfig {
3838
/// key has the ability to decode any withheld fee amount that are
3939
/// associated with accounts. When combined with the fee parameters, the
4040
/// withheld fee amounts can reveal information about transfer amounts.
41-
pub withdraw_withheld_authority_elgamal_pubkey: ElGamalPubkey,
41+
pub withdraw_withheld_authority_elgamal_pubkey: PodElGamalPubkey,
4242

4343
/// If `false`, the harvest of withheld tokens to mint is rejected.
4444
pub harvest_to_mint_enabled: PodBool,

0 commit comments

Comments
 (0)