44 error:: TokenError ,
55 extension:: {
66 confidential_transfer:: { instruction:: * , * } ,
7- transfer_fee:: TransferFeeConfig ,
87 StateWithExtensions , StateWithExtensionsMut ,
98 } ,
109 processor:: Processor ,
1110 state:: { Account , Mint } ,
1211 } ,
1312 solana_program:: {
1413 account_info:: { next_account_info, AccountInfo } ,
15- clock:: Clock ,
1614 entrypoint:: ProgramResult ,
1715 instruction:: Instruction ,
1816 msg,
1917 program_error:: ProgramError ,
2018 pubkey:: Pubkey ,
21- sysvar:: { instructions:: get_instruction_relative, Sysvar } ,
19+ sysvar:: instructions:: get_instruction_relative,
2220 } ,
23- solana_zk_token_sdk:: { zk_token_elgamal:: ops, zk_token_proof_program} ,
21+ solana_zk_token_sdk:: zk_token_proof_program,
22+ } ;
23+ // Remove feature once zk ops syscalls are enabled on all networks
24+ #[ cfg( feature = "zk-ops" ) ]
25+ use {
26+ crate :: extension:: transfer_fee:: TransferFeeConfig ,
27+ solana_program:: { clock:: Clock , sysvar:: Sysvar } ,
28+ solana_zk_token_sdk:: zk_token_elgamal:: ops,
2429} ;
2530
2631fn decode_proof_instruction < T : Pod > (
@@ -246,6 +251,7 @@ fn process_empty_account(
246251}
247252
248253/// Processes a [Deposit] instruction.
254+ #[ cfg( feature = "zk-ops" ) ]
249255fn process_deposit (
250256 program_id : & Pubkey ,
251257 accounts : & [ AccountInfo ] ,
@@ -345,6 +351,7 @@ fn process_deposit(
345351}
346352
347353/// Processes a [Withdraw] instruction.
354+ #[ cfg( feature = "zk-ops" ) ]
348355fn process_withdraw (
349356 program_id : & Pubkey ,
350357 accounts : & [ AccountInfo ] ,
@@ -449,6 +456,7 @@ fn process_withdraw(
449456}
450457
451458/// Processes an [Transfer] instruction.
459+ #[ cfg( feature = "zk-ops" ) ]
452460fn process_transfer (
453461 program_id : & Pubkey ,
454462 accounts : & [ AccountInfo ] ,
@@ -595,6 +603,7 @@ fn process_transfer(
595603}
596604
597605#[ allow( clippy:: too_many_arguments) ]
606+ #[ cfg( feature = "zk-ops" ) ]
598607fn process_source_for_transfer (
599608 program_id : & Pubkey ,
600609 token_account_info : & AccountInfo ,
@@ -650,6 +659,7 @@ fn process_source_for_transfer(
650659 Ok ( ( ) )
651660}
652661
662+ #[ cfg( feature = "zk-ops" ) ]
653663fn process_destination_for_transfer (
654664 destination_token_account_info : & AccountInfo ,
655665 mint_info : & AccountInfo ,
@@ -730,6 +740,7 @@ fn process_destination_for_transfer(
730740}
731741
732742/// Processes an [ApplyPendingBalance] instruction.
743+ #[ cfg( feature = "zk-ops" ) ]
733744fn process_apply_pending_balance (
734745 program_id : & Pubkey ,
735746 accounts : & [ AccountInfo ] ,
@@ -806,6 +817,7 @@ fn process_allow_balance_credits(
806817}
807818
808819/// Processes an [WithdrawWithheldTokensFromMint] instruction.
820+ #[ cfg( feature = "zk-ops" ) ]
809821fn process_withdraw_withheld_tokens_from_mint (
810822 program_id : & Pubkey ,
811823 accounts : & [ AccountInfo ] ,
@@ -894,6 +906,7 @@ fn process_withdraw_withheld_tokens_from_mint(
894906 Ok ( ( ) )
895907}
896908
909+ #[ cfg( feature = "zk-ops" ) ]
897910fn process_withdraw_withheld_tokens_from_accounts (
898911 program_id : & Pubkey ,
899912 accounts : & [ AccountInfo ] ,
@@ -1009,6 +1022,7 @@ fn process_withdraw_withheld_tokens_from_accounts(
10091022 Ok ( ( ) )
10101023}
10111024
1025+ #[ cfg( feature = "zk-ops" ) ]
10121026fn harvest_from_account < ' a , ' b > (
10131027 mint_key : & ' b Pubkey ,
10141028 token_account_info : & ' b AccountInfo < ' a > ,
@@ -1032,6 +1046,7 @@ fn harvest_from_account<'a, 'b>(
10321046}
10331047
10341048/// Processes an [HarvestWithheldTokensToMint] instruction.
1049+ #[ cfg( feature = "zk-ops" ) ]
10351050fn process_harvest_withheld_tokens_to_mint ( accounts : & [ AccountInfo ] ) -> ProgramResult {
10361051 let account_info_iter = & mut accounts. iter ( ) ;
10371052 let mint_account_info = next_account_info ( account_info_iter) ?;
@@ -1061,6 +1076,7 @@ fn process_harvest_withheld_tokens_to_mint(accounts: &[AccountInfo]) -> ProgramR
10611076 Ok ( ( ) )
10621077}
10631078
1079+ #[ allow( dead_code) ]
10641080pub ( crate ) fn process_instruction (
10651081 program_id : & Pubkey ,
10661082 accounts : & [ AccountInfo ] ,
@@ -1102,38 +1118,60 @@ pub(crate) fn process_instruction(
11021118 }
11031119 ConfidentialTransferInstruction :: Deposit => {
11041120 msg ! ( "ConfidentialTransferInstruction::Deposit" ) ;
1105- let data = decode_instruction_data :: < DepositInstructionData > ( input) ?;
1106- process_deposit ( program_id, accounts, data. amount . into ( ) , data. decimals )
1121+ #[ cfg( feature = "zk-ops" ) ]
1122+ {
1123+ let data = decode_instruction_data :: < DepositInstructionData > ( input) ?;
1124+ process_deposit ( program_id, accounts, data. amount . into ( ) , data. decimals )
1125+ }
1126+ #[ cfg( not( feature = "zk-ops" ) ) ]
1127+ Err ( ProgramError :: InvalidInstructionData )
11071128 }
11081129 ConfidentialTransferInstruction :: Withdraw => {
11091130 msg ! ( "ConfidentialTransferInstruction::Withdraw" ) ;
1110- let data = decode_instruction_data :: < WithdrawInstructionData > ( input) ?;
1111- process_withdraw (
1112- program_id,
1113- accounts,
1114- data. amount . into ( ) ,
1115- data. decimals ,
1116- data. new_decryptable_available_balance ,
1117- data. proof_instruction_offset as i64 ,
1118- )
1131+ #[ cfg( feature = "zk-ops" ) ]
1132+ {
1133+ let data = decode_instruction_data :: < WithdrawInstructionData > ( input) ?;
1134+ process_withdraw (
1135+ program_id,
1136+ accounts,
1137+ data. amount . into ( ) ,
1138+ data. decimals ,
1139+ data. new_decryptable_available_balance ,
1140+ data. proof_instruction_offset as i64 ,
1141+ )
1142+ }
1143+ #[ cfg( not( feature = "zk-ops" ) ) ]
1144+ Err ( ProgramError :: InvalidInstructionData )
11191145 }
11201146 ConfidentialTransferInstruction :: Transfer => {
11211147 msg ! ( "ConfidentialTransferInstruction::Transfer" ) ;
1122- let data = decode_instruction_data :: < TransferInstructionData > ( input) ?;
1123- process_transfer (
1124- program_id,
1125- accounts,
1126- data. new_source_decryptable_available_balance ,
1127- data. proof_instruction_offset as i64 ,
1128- )
1148+ #[ cfg( feature = "zk-ops" ) ]
1149+ {
1150+ let data = decode_instruction_data :: < TransferInstructionData > ( input) ?;
1151+ process_transfer (
1152+ program_id,
1153+ accounts,
1154+ data. new_source_decryptable_available_balance ,
1155+ data. proof_instruction_offset as i64 ,
1156+ )
1157+ }
1158+ #[ cfg( not( feature = "zk-ops" ) ) ]
1159+ Err ( ProgramError :: InvalidInstructionData )
11291160 }
11301161 ConfidentialTransferInstruction :: ApplyPendingBalance => {
11311162 msg ! ( "ConfidentialTransferInstruction::ApplyPendingBalance" ) ;
1132- process_apply_pending_balance (
1133- program_id,
1134- accounts,
1135- decode_instruction_data :: < ApplyPendingBalanceData > ( input) ?,
1136- )
1163+ #[ cfg( feature = "zk-ops" ) ]
1164+ {
1165+ process_apply_pending_balance (
1166+ program_id,
1167+ accounts,
1168+ decode_instruction_data :: < ApplyPendingBalanceData > ( input) ?,
1169+ )
1170+ }
1171+ #[ cfg( not( feature = "zk-ops" ) ) ]
1172+ {
1173+ Err ( ProgramError :: InvalidInstructionData )
1174+ }
11371175 }
11381176 ConfidentialTransferInstruction :: DisableBalanceCredits => {
11391177 msg ! ( "ConfidentialTransferInstruction::DisableBalanceCredits" ) ;
@@ -1145,26 +1183,44 @@ pub(crate) fn process_instruction(
11451183 }
11461184 ConfidentialTransferInstruction :: WithdrawWithheldTokensFromMint => {
11471185 msg ! ( "ConfidentialTransferInstruction::WithdrawWithheldTokensFromMint" ) ;
1148- let data = decode_instruction_data :: < WithdrawWithheldTokensFromMintData > ( input) ?;
1149- process_withdraw_withheld_tokens_from_mint (
1150- program_id,
1151- accounts,
1152- data. proof_instruction_offset as i64 ,
1153- )
1186+ #[ cfg( feature = "zk-ops" ) ]
1187+ {
1188+ let data = decode_instruction_data :: < WithdrawWithheldTokensFromMintData > ( input) ?;
1189+ process_withdraw_withheld_tokens_from_mint (
1190+ program_id,
1191+ accounts,
1192+ data. proof_instruction_offset as i64 ,
1193+ )
1194+ }
1195+ #[ cfg( not( feature = "zk-ops" ) ) ]
1196+ Err ( ProgramError :: InvalidInstructionData )
11541197 }
11551198 ConfidentialTransferInstruction :: WithdrawWithheldTokensFromAccounts => {
11561199 msg ! ( "ConfidentialTransferInstruction::WithdrawWithheldTokensFromAccounts" ) ;
1157- let data = decode_instruction_data :: < WithdrawWithheldTokensFromAccountsData > ( input) ?;
1158- process_withdraw_withheld_tokens_from_accounts (
1159- program_id,
1160- accounts,
1161- data. num_token_accounts ,
1162- data. proof_instruction_offset as i64 ,
1163- )
1200+ #[ cfg( feature = "zk-ops" ) ]
1201+ {
1202+ let data =
1203+ decode_instruction_data :: < WithdrawWithheldTokensFromAccountsData > ( input) ?;
1204+ process_withdraw_withheld_tokens_from_accounts (
1205+ program_id,
1206+ accounts,
1207+ data. num_token_accounts ,
1208+ data. proof_instruction_offset as i64 ,
1209+ )
1210+ }
1211+ #[ cfg( not( feature = "zk-ops" ) ) ]
1212+ Err ( ProgramError :: InvalidInstructionData )
11641213 }
11651214 ConfidentialTransferInstruction :: HarvestWithheldTokensToMint => {
11661215 msg ! ( "ConfidentialTransferInstruction::HarvestWithheldTokensToMint" ) ;
1167- process_harvest_withheld_tokens_to_mint ( accounts)
1216+ #[ cfg( feature = "zk-ops" ) ]
1217+ {
1218+ process_harvest_withheld_tokens_to_mint ( accounts)
1219+ }
1220+ #[ cfg( not( feature = "zk-ops" ) ) ]
1221+ {
1222+ Err ( ProgramError :: InvalidInstructionData )
1223+ }
11681224 }
11691225 }
11701226}
0 commit comments