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

Commit cba5b8b

Browse files
committed
update token-cli
1 parent a0d12ea commit cba5b8b

File tree

6 files changed

+111
-64
lines changed

6 files changed

+111
-64
lines changed

Cargo.lock

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

token/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ spl-token-2022 = { version = "4.0.0", path = "../program-2022", features = [
3535
"no-entrypoint",
3636
] }
3737
spl-token-client = { version = "0.11.0", path = "../client" }
38+
spl-token-confidential-transfer-proof-generation = { version = "0.1.0", path = "../confidential-transfer/proof-generation" }
3839
spl-token-metadata-interface = { version = "0.4.0", path = "../../token-metadata/interface" }
3940
spl-token-group-interface = { version = "0.3.0", path = "../../token-group/interface" }
4041
spl-associated-token-account = { version = "4.0.0", path = "../../associated-token-account/program", features = [

token/cli/src/command.rs

Lines changed: 71 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ use {
5757
transfer_hook::TransferHook,
5858
BaseStateWithExtensions, ExtensionType, StateWithExtensionsOwned,
5959
},
60-
solana_zk_token_sdk::{
61-
encryption::{
62-
auth_encryption::AeKey,
63-
elgamal::{self, ElGamalKeypair},
64-
},
65-
zk_token_elgamal::pod::ElGamalPubkey,
60+
solana_zk_sdk::encryption::{
61+
auth_encryption::AeKey,
62+
elgamal::{self, ElGamalKeypair},
63+
pod::elgamal::PodElGamalPubkey,
6664
},
6765
state::{Account, AccountState, Mint},
6866
},
6967
spl_token_client::{
7068
client::{ProgramRpcClientSendTransaction, RpcClientResponse},
71-
proof_generation::ProofAccount,
72-
token::{ComputeUnitLimit, ExtensionInitializationParams, Token},
69+
token::{ComputeUnitLimit, ExtensionInitializationParams, ProofAccount, Token},
70+
},
71+
spl_token_confidential_transfer_proof_generation::{
72+
transfer::TransferProofData, withdraw::WithdrawProofData,
7373
},
7474
spl_token_group_interface::state::TokenGroup,
7575
spl_token_metadata_interface::state::{Field, TokenMetadata},
@@ -1479,7 +1479,7 @@ async fn command_transfer(
14791479
let auditor_elgamal_pubkey = if let Ok(confidential_transfer_mint) =
14801480
mint_state.get_extension::<ConfidentialTransferMint>()
14811481
{
1482-
let expected_auditor_elgamal_pubkey = Option::<ElGamalPubkey>::from(
1482+
let expected_auditor_elgamal_pubkey = Option::<PodElGamalPubkey>::from(
14831483
confidential_transfer_mint.auditor_elgamal_pubkey,
14841484
);
14851485

@@ -1589,32 +1589,35 @@ async fn command_transfer(
15891589
.unwrap();
15901590
let transfer_account_info = TransferAccountInfo::new(extension);
15911591

1592-
let (equality_proof_data, ciphertext_validity_proof_data, range_proof_data) =
1593-
transfer_account_info
1594-
.generate_split_transfer_proof_data(
1595-
transfer_balance,
1596-
&args.sender_elgamal_keypair,
1597-
&args.sender_aes_key,
1598-
&recipient_elgamal_pubkey,
1599-
auditor_elgamal_pubkey.as_ref(),
1600-
)
1601-
.unwrap();
1592+
let TransferProofData {
1593+
equality_proof_data,
1594+
ciphertext_validity_proof_data,
1595+
range_proof_data,
1596+
} = transfer_account_info
1597+
.generate_split_transfer_proof_data(
1598+
transfer_balance,
1599+
&args.sender_elgamal_keypair,
1600+
&args.sender_aes_key,
1601+
&recipient_elgamal_pubkey,
1602+
auditor_elgamal_pubkey.as_ref(),
1603+
)
1604+
.unwrap();
16021605

16031606
// setup proofs
16041607
let _ = try_join!(
1605-
token.create_range_proof_context_state_for_transfer(
1608+
token.confidential_transfer_create_context_state_account(
16061609
&range_proof_pubkey,
16071610
&context_state_authority_pubkey,
16081611
&range_proof_data,
16091612
&range_proof_context_state_account,
16101613
),
1611-
token.create_equality_proof_context_state_for_transfer(
1614+
token.confidential_transfer_create_context_state_account(
16121615
&equality_proof_pubkey,
16131616
&context_state_authority_pubkey,
16141617
&equality_proof_data,
16151618
&equality_proof_context_state_account,
16161619
),
1617-
token.create_ciphertext_validity_proof_context_state_for_transfer(
1620+
token.confidential_transfer_create_context_state_account(
16181621
&ciphertext_validity_proof_pubkey,
16191622
&context_state_authority_pubkey,
16201623
&ciphertext_validity_proof_data,
@@ -2944,7 +2947,7 @@ async fn command_update_confidential_transfer_settings(
29442947
let new_auditor_pubkey = if let Some(auditor_pubkey) = auditor_pubkey {
29452948
auditor_pubkey.into()
29462949
} else {
2947-
Option::<ElGamalPubkey>::from(confidential_transfer_mint.auditor_elgamal_pubkey)
2950+
Option::<PodElGamalPubkey>::from(confidential_transfer_mint.auditor_elgamal_pubkey)
29482951
};
29492952

29502953
(new_auto_approve, new_auditor_pubkey)
@@ -3335,28 +3338,45 @@ async fn command_deposit_withdraw_confidential_tokens(
33353338
let withdraw_account_info = WithdrawAccountInfo::new(extension_state);
33363339

33373340
let context_state_authority = config.fee_payer()?;
3338-
let context_state_keypair = Keypair::new();
3339-
let context_state_pubkey = context_state_keypair.pubkey();
3341+
let equality_proof_context_state_keypair = Keypair::new();
3342+
let equality_proof_context_state_pubkey = equality_proof_context_state_keypair.pubkey();
3343+
let range_proof_context_state_keypair = Keypair::new();
3344+
let range_proof_context_state_pubkey = range_proof_context_state_keypair.pubkey();
33403345

3341-
let withdraw_proof_data =
3342-
withdraw_account_info.generate_proof_data(amount, elgamal_keypair, aes_key)?;
3346+
let WithdrawProofData {
3347+
equality_proof_data,
3348+
range_proof_data,
3349+
} = withdraw_account_info.generate_proof_data(amount, elgamal_keypair, aes_key)?;
33433350

3344-
// setup proof
3345-
token
3346-
.create_withdraw_proof_context_state(
3347-
&context_state_pubkey,
3348-
&context_state_authority.pubkey(),
3349-
&withdraw_proof_data,
3350-
&context_state_keypair,
3351+
// set up context state accounts
3352+
let context_state_authority_pubkey = context_state_authority.pubkey();
3353+
3354+
let _ = try_join!(
3355+
token.confidential_transfer_create_context_state_account(
3356+
&equality_proof_context_state_pubkey,
3357+
&context_state_authority_pubkey,
3358+
&equality_proof_data,
3359+
&equality_proof_context_state_keypair,
3360+
),
3361+
token.confidential_transfer_create_context_state_account(
3362+
&range_proof_context_state_pubkey,
3363+
&context_state_authority_pubkey,
3364+
&range_proof_data,
3365+
&range_proof_context_state_keypair,
33513366
)
3352-
.await?;
3367+
)?;
33533368

33543369
// do the withdrawal
3355-
token
3370+
let withdraw_result = token
33563371
.confidential_transfer_withdraw(
33573372
&token_account_address,
33583373
&owner,
3359-
Some(&ProofAccount::ContextAccount(context_state_pubkey)),
3374+
Some(&ProofAccount::ContextAccount(
3375+
equality_proof_context_state_pubkey,
3376+
)),
3377+
Some(&ProofAccount::ContextAccount(
3378+
range_proof_context_state_pubkey,
3379+
)),
33603380
amount,
33613381
decimals,
33623382
Some(withdraw_account_info),
@@ -3367,15 +3387,22 @@ async fn command_deposit_withdraw_confidential_tokens(
33673387
.await?;
33683388

33693389
// close context state account
3370-
let context_state_authority_pubkey = context_state_authority.pubkey();
3371-
token
3372-
.confidential_transfer_close_context_state(
3373-
&context_state_pubkey,
3390+
let _ = try_join!(
3391+
token.confidential_transfer_close_context_state(
3392+
&equality_proof_context_state_pubkey,
3393+
&token_account_address,
3394+
&context_state_authority_pubkey,
3395+
&context_state_authority,
3396+
),
3397+
token.confidential_transfer_close_context_state(
3398+
&range_proof_context_state_pubkey,
33743399
&token_account_address,
33753400
&context_state_authority_pubkey,
33763401
&context_state_authority,
33773402
)
3378-
.await?
3403+
)?;
3404+
3405+
withdraw_result
33793406
}
33803407
};
33813408

@@ -3447,8 +3474,8 @@ async fn command_apply_pending_balance(
34473474
struct ConfidentialTransferArgs {
34483475
sender_elgamal_keypair: ElGamalKeypair,
34493476
sender_aes_key: AeKey,
3450-
recipient_elgamal_pubkey: Option<ElGamalPubkey>,
3451-
auditor_elgamal_pubkey: Option<ElGamalPubkey>,
3477+
recipient_elgamal_pubkey: Option<PodElGamalPubkey>,
3478+
auditor_elgamal_pubkey: Option<PodElGamalPubkey>,
34523479
}
34533480

34543481
pub async fn process_command<'a>(

token/cli/src/encryption_keypair.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use {
66
base64::{prelude::BASE64_STANDARD, Engine},
77
clap::ArgMatches,
8-
spl_token_2022::solana_zk_token_sdk::{
9-
encryption::elgamal::{ElGamalKeypair, ElGamalPubkey},
10-
zk_token_elgamal::pod::ElGamalPubkey as PodElGamalPubkey,
8+
spl_token_2022::solana_zk_sdk::encryption::{
9+
elgamal::{ElGamalKeypair, ElGamalPubkey},
10+
pod::elgamal::PodElGamalPubkey,
1111
},
1212
};
1313

token/cli/tests/command.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use {
3232
BaseStateWithExtensions, StateWithExtensionsOwned,
3333
},
3434
instruction::create_native_mint,
35-
solana_zk_token_sdk::zk_token_elgamal::pod::ElGamalPubkey,
35+
solana_zk_sdk::encryption::pod::elgamal::PodElGamalPubkey,
3636
state::{Account, AccountState, Mint, Multisig},
3737
},
3838
spl_token_cli::{
@@ -2609,7 +2609,7 @@ async fn transfer_fee_basis_point(test_validator: &TestValidator, payer: &Keypai
26092609
}
26102610

26112611
async fn confidential_transfer(test_validator: &TestValidator, payer: &Keypair) {
2612-
use spl_token_2022::solana_zk_token_sdk::encryption::elgamal::ElGamalKeypair;
2612+
use spl_token_2022::solana_zk_sdk::encryption::elgamal::ElGamalKeypair;
26132613

26142614
let config = test_config_with_default_signer(test_validator, payer, &spl_token_2022::id());
26152615

@@ -2650,13 +2650,13 @@ async fn confidential_transfer(test_validator: &TestValidator, payer: &Keypair)
26502650
auto_approve,
26512651
);
26522652
assert_eq!(
2653-
Option::<ElGamalPubkey>::from(extension.auditor_elgamal_pubkey),
2653+
Option::<PodElGamalPubkey>::from(extension.auditor_elgamal_pubkey),
26542654
None,
26552655
);
26562656

26572657
// update confidential transfer mint settings
26582658
let auditor_keypair = ElGamalKeypair::new_rand();
2659-
let auditor_pubkey: ElGamalPubkey = (*auditor_keypair.pubkey()).into();
2659+
let auditor_pubkey: PodElGamalPubkey = (*auditor_keypair.pubkey()).into();
26602660
let new_auto_approve = true;
26612661

26622662
process_test_command(
@@ -2686,7 +2686,7 @@ async fn confidential_transfer(test_validator: &TestValidator, payer: &Keypair)
26862686
new_auto_approve,
26872687
);
26882688
assert_eq!(
2689-
Option::<ElGamalPubkey>::from(extension.auditor_elgamal_pubkey),
2689+
Option::<PodElGamalPubkey>::from(extension.auditor_elgamal_pubkey),
26902690
Some(auditor_pubkey),
26912691
);
26922692

@@ -2946,7 +2946,7 @@ async fn confidential_transfer_with_fee(test_validator: &TestValidator, payer: &
29462946
auto_approve,
29472947
);
29482948
assert_eq!(
2949-
Option::<ElGamalPubkey>::from(extension.auditor_elgamal_pubkey),
2949+
Option::<PodElGamalPubkey>::from(extension.auditor_elgamal_pubkey),
29502950
None,
29512951
);
29522952

token/client/src/token.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,19 +2374,37 @@ where
23742374
};
23752375

23762376
self.process_ixs(
2377-
&[
2378-
system_instruction::create_account(
2379-
&self.payer.pubkey(),
2380-
context_state_account,
2381-
rent,
2382-
space as u64,
2383-
&zk_elgamal_proof_program::id(),
2384-
),
2385-
instruction_type.encode_verify_proof(Some(context_state_info), proof_data),
2386-
],
2377+
&[system_instruction::create_account(
2378+
&self.payer.pubkey(),
2379+
context_state_account,
2380+
rent,
2381+
space as u64,
2382+
&zk_elgamal_proof_program::id(),
2383+
)],
23872384
&[signer],
23882385
)
2389-
.await
2386+
.await?;
2387+
2388+
// Some proof instructions are right at the transaction size limit, but in the
2389+
// future it might be able to support the transfer too
2390+
let blockhash = self
2391+
.client
2392+
.get_latest_blockhash()
2393+
.await
2394+
.map_err(TokenError::Client)?;
2395+
2396+
let transaction = Transaction::new_signed_with_payer(
2397+
&[instruction_type
2398+
.encode_verify_proof(Some(context_state_info), proof_data)],
2399+
Some(&self.payer.pubkey()),
2400+
&[self.payer.as_ref()],
2401+
blockhash,
2402+
);
2403+
2404+
self.client
2405+
.send_transaction(&transaction)
2406+
.await
2407+
.map_err(TokenError::Client)
23902408
}
23912409

23922410
/// Close a ZK Token proof program context state

0 commit comments

Comments
 (0)