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

Commit a502871

Browse files
committed
update token-cli
1 parent 3d61b57 commit a502871

File tree

7 files changed

+141
-62
lines changed

7 files changed

+141
-62
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: 76 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,35 +1589,41 @@ 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,
1612+
true,
16091613
&range_proof_context_state_account,
16101614
),
1611-
token.create_equality_proof_context_state_for_transfer(
1615+
token.confidential_transfer_create_context_state_account(
16121616
&equality_proof_pubkey,
16131617
&context_state_authority_pubkey,
16141618
&equality_proof_data,
1619+
false,
16151620
&equality_proof_context_state_account,
16161621
),
1617-
token.create_ciphertext_validity_proof_context_state_for_transfer(
1622+
token.confidential_transfer_create_context_state_account(
16181623
&ciphertext_validity_proof_pubkey,
16191624
&context_state_authority_pubkey,
16201625
&ciphertext_validity_proof_data,
1626+
false,
16211627
&ciphertext_validity_proof_context_state_account,
16221628
)
16231629
)?;
@@ -2944,7 +2950,7 @@ async fn command_update_confidential_transfer_settings(
29442950
let new_auditor_pubkey = if let Some(auditor_pubkey) = auditor_pubkey {
29452951
auditor_pubkey.into()
29462952
} else {
2947-
Option::<ElGamalPubkey>::from(confidential_transfer_mint.auditor_elgamal_pubkey)
2953+
Option::<PodElGamalPubkey>::from(confidential_transfer_mint.auditor_elgamal_pubkey)
29482954
};
29492955

29502956
(new_auto_approve, new_auditor_pubkey)
@@ -3335,28 +3341,47 @@ async fn command_deposit_withdraw_confidential_tokens(
33353341
let withdraw_account_info = WithdrawAccountInfo::new(extension_state);
33363342

33373343
let context_state_authority = config.fee_payer()?;
3338-
let context_state_keypair = Keypair::new();
3339-
let context_state_pubkey = context_state_keypair.pubkey();
3344+
let equality_proof_context_state_keypair = Keypair::new();
3345+
let equality_proof_context_state_pubkey = equality_proof_context_state_keypair.pubkey();
3346+
let range_proof_context_state_keypair = Keypair::new();
3347+
let range_proof_context_state_pubkey = range_proof_context_state_keypair.pubkey();
33403348

3341-
let withdraw_proof_data =
3342-
withdraw_account_info.generate_proof_data(amount, elgamal_keypair, aes_key)?;
3349+
let WithdrawProofData {
3350+
equality_proof_data,
3351+
range_proof_data,
3352+
} = withdraw_account_info.generate_proof_data(amount, elgamal_keypair, aes_key)?;
33433353

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,
3354+
// set up context state accounts
3355+
let context_state_authority_pubkey = context_state_authority.pubkey();
3356+
3357+
let _ = try_join!(
3358+
token.confidential_transfer_create_context_state_account(
3359+
&equality_proof_context_state_pubkey,
3360+
&context_state_authority_pubkey,
3361+
&equality_proof_data,
3362+
false,
3363+
&equality_proof_context_state_keypair,
3364+
),
3365+
token.confidential_transfer_create_context_state_account(
3366+
&range_proof_context_state_pubkey,
3367+
&context_state_authority_pubkey,
3368+
&range_proof_data,
3369+
true,
3370+
&range_proof_context_state_keypair,
33513371
)
3352-
.await?;
3372+
)?;
33533373

33543374
// do the withdrawal
3355-
token
3375+
let withdraw_result = token
33563376
.confidential_transfer_withdraw(
33573377
&token_account_address,
33583378
&owner,
3359-
Some(&ProofAccount::ContextAccount(context_state_pubkey)),
3379+
Some(&ProofAccount::ContextAccount(
3380+
equality_proof_context_state_pubkey,
3381+
)),
3382+
Some(&ProofAccount::ContextAccount(
3383+
range_proof_context_state_pubkey,
3384+
)),
33603385
amount,
33613386
decimals,
33623387
Some(withdraw_account_info),
@@ -3367,15 +3392,22 @@ async fn command_deposit_withdraw_confidential_tokens(
33673392
.await?;
33683393

33693394
// 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,
3395+
let _ = try_join!(
3396+
token.confidential_transfer_close_context_state(
3397+
&equality_proof_context_state_pubkey,
3398+
&token_account_address,
3399+
&context_state_authority_pubkey,
3400+
&context_state_authority,
3401+
),
3402+
token.confidential_transfer_close_context_state(
3403+
&range_proof_context_state_pubkey,
33743404
&token_account_address,
33753405
&context_state_authority_pubkey,
33763406
&context_state_authority,
33773407
)
3378-
.await?
3408+
)?;
3409+
3410+
withdraw_result
33793411
}
33803412
};
33813413

@@ -3447,8 +3479,8 @@ async fn command_apply_pending_balance(
34473479
struct ConfidentialTransferArgs {
34483480
sender_elgamal_keypair: ElGamalKeypair,
34493481
sender_aes_key: AeKey,
3450-
recipient_elgamal_pubkey: Option<ElGamalPubkey>,
3451-
auditor_elgamal_pubkey: Option<ElGamalPubkey>,
3482+
recipient_elgamal_pubkey: Option<PodElGamalPubkey>,
3483+
auditor_elgamal_pubkey: Option<PodElGamalPubkey>,
34523484
}
34533485

34543486
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: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,6 +2358,7 @@ where
23582358
context_state_account: &Pubkey,
23592359
context_state_authority: &Pubkey,
23602360
proof_data: &ZK,
2361+
split_instruction: bool,
23612362
signer: &S,
23622363
) -> TokenResult<T::Output> {
23632364
let instruction_type = zk_proof_type_to_instruction(ZK::PROOF_TYPE)?;
@@ -2373,20 +2374,54 @@ where
23732374
context_state_authority,
23742375
};
23752376

2376-
self.process_ixs(
2377-
&[
2378-
system_instruction::create_account(
2377+
// Some proof instructions are right at the transaction size limit, but in the
2378+
// future it might be able to support the transfer too
2379+
if split_instruction {
2380+
self.process_ixs(
2381+
&[system_instruction::create_account(
23792382
&self.payer.pubkey(),
23802383
context_state_account,
23812384
rent,
23822385
space as u64,
23832386
&zk_elgamal_proof_program::id(),
2384-
),
2385-
instruction_type.encode_verify_proof(Some(context_state_info), proof_data),
2386-
],
2387-
&[signer],
2388-
)
2389-
.await
2387+
)],
2388+
&[signer],
2389+
)
2390+
.await?;
2391+
2392+
let blockhash = self
2393+
.client
2394+
.get_latest_blockhash()
2395+
.await
2396+
.map_err(TokenError::Client)?;
2397+
2398+
let transaction = Transaction::new_signed_with_payer(
2399+
&[instruction_type.encode_verify_proof(Some(context_state_info), proof_data)],
2400+
Some(&self.payer.pubkey()),
2401+
&[self.payer.as_ref()],
2402+
blockhash,
2403+
);
2404+
2405+
self.client
2406+
.send_transaction(&transaction)
2407+
.await
2408+
.map_err(TokenError::Client)
2409+
} else {
2410+
self.process_ixs(
2411+
&[
2412+
system_instruction::create_account(
2413+
&self.payer.pubkey(),
2414+
context_state_account,
2415+
rent,
2416+
space as u64,
2417+
&zk_elgamal_proof_program::id(),
2418+
),
2419+
instruction_type.encode_verify_proof(Some(context_state_info), proof_data),
2420+
],
2421+
&[signer],
2422+
)
2423+
.await
2424+
}
23902425
}
23912426

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

0 commit comments

Comments
 (0)