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

Commit 95a079a

Browse files
[token-2022] Create proof-program feature (#4040)
1 parent ecd5c45 commit 95a079a

File tree

7 files changed

+108
-42
lines changed

7 files changed

+108
-42
lines changed

token/client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ thiserror = "1.0"
2424
[features]
2525
default = ["display"]
2626
display = ["dep:solana-cli-output"]
27+
proof-program = []

token/client/src/token.rs

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use {
33
solana_program_test::tokio::time,
44
solana_sdk::{
55
account::Account as BaseAccount,
6-
epoch_info::EpochInfo,
76
hash::Hash,
87
instruction::Instruction,
98
message::Message,
@@ -26,21 +25,25 @@ use {
2625
},
2726
instruction,
2827
pod::EncryptionPubkey,
29-
solana_zk_token_sdk::{
30-
encryption::{auth_encryption::*, elgamal::*},
31-
errors::ProofError,
32-
instruction::transfer_with_fee::FeeParameters,
33-
},
28+
solana_zk_token_sdk::errors::ProofError,
3429
state::{Account, AccountState, Mint, Multisig},
3530
},
3631
std::{
37-
convert::TryInto,
3832
fmt, io,
3933
sync::{Arc, RwLock},
4034
time::{Duration, Instant},
4135
},
4236
thiserror::Error,
4337
};
38+
#[cfg(feature = "proof-program")]
39+
use {
40+
solana_sdk::epoch_info::EpochInfo,
41+
spl_token_2022::solana_zk_token_sdk::{
42+
encryption::{auth_encryption::*, elgamal::*},
43+
instruction::transfer_with_fee::FeeParameters,
44+
},
45+
std::convert::TryInto,
46+
};
4447

4548
#[derive(Error, Debug)]
4649
pub enum TokenError {
@@ -1516,6 +1519,7 @@ where
15161519
}
15171520

15181521
/// Configures confidential transfers for a token account
1522+
#[cfg(feature = "proof-program")]
15191523
pub async fn confidential_transfer_configure_token_account<S: Signer>(
15201524
&self,
15211525
token_account: &Pubkey,
@@ -1532,6 +1536,7 @@ where
15321536
.await
15331537
}
15341538

1539+
#[cfg(feature = "proof-program")]
15351540
pub async fn confidential_transfer_configure_token_account_with_pending_counter<S: Signer>(
15361541
&self,
15371542
token_account: &Pubkey,
@@ -1554,6 +1559,7 @@ where
15541559
.await
15551560
}
15561561

1562+
#[cfg(feature = "proof-program")]
15571563
pub async fn confidential_transfer_configure_token_account_with_pending_counter_and_keypair<
15581564
S: Signer,
15591565
>(
@@ -1585,6 +1591,7 @@ where
15851591
}
15861592

15871593
/// Approves a token account for confidential transfers
1594+
#[cfg(feature = "proof-program")]
15881595
pub async fn confidential_transfer_approve_account<S: Signer>(
15891596
&self,
15901597
token_account: &Pubkey,
@@ -1603,6 +1610,7 @@ where
16031610
}
16041611

16051612
/// Prepare a token account with the confidential transfer extension for closing
1613+
#[cfg(feature = "proof-program")]
16061614
pub async fn confidential_transfer_empty_account<S: Signer>(
16071615
&self,
16081616
token_account: &Pubkey,
@@ -1618,6 +1626,7 @@ where
16181626
.await
16191627
}
16201628

1629+
#[cfg(feature = "proof-program")]
16211630
pub async fn confidential_transfer_empty_account_with_keypair<S: Signer>(
16221631
&self,
16231632
token_account: &Pubkey,
@@ -1649,6 +1658,7 @@ where
16491658

16501659
/// Fetch and decrypt the available balance of a confidential token account using the uniquely
16511660
/// derived decryption key from a signer
1661+
#[cfg(feature = "proof-program")]
16521662
pub async fn confidential_transfer_get_available_balance<S: Signer>(
16531663
&self,
16541664
token_account: &Pubkey,
@@ -1666,6 +1676,7 @@ where
16661676

16671677
/// Fetch and decrypt the available balance of a confidential token account using a custom
16681678
/// decryption key
1679+
#[cfg(feature = "proof-program")]
16691680
pub async fn confidential_transfer_get_available_balance_with_key(
16701681
&self,
16711682
token_account: &Pubkey,
@@ -1688,6 +1699,7 @@ where
16881699

16891700
/// Fetch and decrypt the pending balance of a confidential token account using the uniquely
16901701
/// derived decryption key from a signer
1702+
#[cfg(feature = "proof-program")]
16911703
pub async fn confidential_transfer_get_pending_balance<S: Signer>(
16921704
&self,
16931705
token_account: &Pubkey,
@@ -1702,6 +1714,7 @@ where
17021714

17031715
/// Fetch and decrypt the pending balance of a confidential token account using a custom
17041716
/// decryption key
1717+
#[cfg(feature = "proof-program")]
17051718
pub async fn confidential_transfer_get_pending_balance_with_key(
17061719
&self,
17071720
token_account: &Pubkey,
@@ -1728,6 +1741,7 @@ where
17281741
Ok(pending_balance)
17291742
}
17301743

1744+
#[cfg(feature = "proof-program")]
17311745
pub async fn confidential_transfer_get_withheld_amount<S: Signer>(
17321746
&self,
17331747
withdraw_withheld_authority: &S,
@@ -1744,6 +1758,7 @@ where
17441758
.await
17451759
}
17461760

1761+
#[cfg(feature = "proof-program")]
17471762
pub async fn confidential_transfer_get_withheld_amount_with_key(
17481763
&self,
17491764
withdraw_withheld_authority_elgamal_keypair: &ElGamalKeypair,
@@ -1770,6 +1785,7 @@ where
17701785
}
17711786

17721787
/// Fetch the ElGamal public key associated with a confidential token account
1788+
#[cfg(feature = "proof-program")]
17731789
pub async fn confidential_transfer_get_encryption_pubkey<S: Signer>(
17741790
&self,
17751791
token_account: &Pubkey,
@@ -1786,6 +1802,7 @@ where
17861802
}
17871803

17881804
/// Fetch the ElGamal pubkey key of the auditor associated with a confidential token mint
1805+
#[cfg(feature = "proof-program")]
17891806
pub async fn confidential_transfer_get_auditor_encryption_pubkey<S: Signer>(
17901807
&self,
17911808
) -> TokenResult<Option<ElGamalPubkey>> {
@@ -1806,6 +1823,7 @@ where
18061823

18071824
/// Fetch the ElGamal pubkey key of the withdraw withheld authority associated with a
18081825
/// confidential token mint
1826+
#[cfg(feature = "proof-program")]
18091827
pub async fn confidential_transfer_get_withdraw_withheld_authority_encryption_pubkey<
18101828
S: Signer,
18111829
>(
@@ -1827,6 +1845,7 @@ where
18271845
}
18281846

18291847
/// Deposit SPL Tokens into the pending balance of a confidential token account
1848+
#[cfg(feature = "proof-program")]
18301849
pub async fn confidential_transfer_deposit<S: Signer>(
18311850
&self,
18321851
token_account: &Pubkey,
@@ -1856,6 +1875,7 @@ where
18561875
/// Withdraw SPL Tokens from the available balance of a confidential token account using the
18571876
/// uniquely derived decryption key from a signer
18581877
#[allow(clippy::too_many_arguments)]
1878+
#[cfg(feature = "proof-program")]
18591879
pub async fn confidential_transfer_withdraw<S: Signer>(
18601880
&self,
18611881
token_account: &Pubkey,
@@ -1886,6 +1906,7 @@ where
18861906
/// Withdraw SPL Tokens from the available balance of a confidential token account using custom
18871907
/// keys
18881908
#[allow(clippy::too_many_arguments)]
1909+
#[cfg(feature = "proof-program")]
18891910
pub async fn confidential_transfer_withdraw_with_key<S: Signer>(
18901911
&self,
18911912
token_account: &Pubkey,
@@ -1930,6 +1951,7 @@ where
19301951

19311952
/// Transfer tokens confidentially using the uniquely derived decryption keys from a signer
19321953
#[allow(clippy::too_many_arguments)]
1954+
#[cfg(feature = "proof-program")]
19331955
pub async fn confidential_transfer_transfer<S: Signer>(
19341956
&self,
19351957
source_token_account: &Pubkey,
@@ -1964,6 +1986,7 @@ where
19641986

19651987
/// Transfer tokens confidentially using custom decryption keys
19661988
#[allow(clippy::too_many_arguments)]
1989+
#[cfg(feature = "proof-program")]
19671990
pub async fn confidential_transfer_transfer_with_key<S: Signer>(
19681991
&self,
19691992
source_token_account: &Pubkey,
@@ -2019,6 +2042,7 @@ where
20192042
/// Transfer tokens confidentially with fee using the uniquely derived decryption keys from a
20202043
/// signer
20212044
#[allow(clippy::too_many_arguments)]
2045+
#[cfg(feature = "proof-program")]
20222046
pub async fn confidential_transfer_transfer_with_fee<S: Signer>(
20232047
&self,
20242048
source_token_account: &Pubkey,
@@ -2057,6 +2081,7 @@ where
20572081

20582082
/// Transfer tokens confidential with fee using custom decryption keys
20592083
#[allow(clippy::too_many_arguments)]
2084+
#[cfg(feature = "proof-program")]
20602085
pub async fn confidential_transfer_transfer_with_fee_with_key<S: Signer>(
20612086
&self,
20622087
source_token_account: &Pubkey,
@@ -2124,6 +2149,7 @@ where
21242149

21252150
/// Applies the confidential transfer pending balance to the available balance using the
21262151
/// uniquely derived decryption key
2152+
#[cfg(feature = "proof-program")]
21272153
pub async fn confidential_transfer_apply_pending_balance<S: Signer>(
21282154
&self,
21292155
token_account: &Pubkey,
@@ -2148,6 +2174,7 @@ where
21482174

21492175
/// Applies the confidential transfer pending balance to the available balance using a custom
21502176
/// decryption key
2177+
#[cfg(feature = "proof-program")]
21512178
pub async fn confidential_transfer_apply_pending_balance_with_key<S: Signer>(
21522179
&self,
21532180
token_account: &Pubkey,
@@ -2176,6 +2203,7 @@ where
21762203
}
21772204

21782205
/// Enable confidential transfer `Deposit` and `Transfer` instructions for a token account
2206+
#[cfg(feature = "proof-program")]
21792207
pub async fn confidential_transfer_enable_confidential_credits<S: Signer>(
21802208
&self,
21812209
token_account: &Pubkey,
@@ -2196,6 +2224,7 @@ where
21962224
}
21972225

21982226
/// Disable confidential transfer `Deposit` and `Transfer` instructions for a token account
2227+
#[cfg(feature = "proof-program")]
21992228
pub async fn confidential_transfer_disable_confidential_credits<S: Signer>(
22002229
&self,
22012230
token_account: &Pubkey,
@@ -2216,6 +2245,7 @@ where
22162245
}
22172246

22182247
/// Enable a confidential extension token account to receive non-confidential payments
2248+
#[cfg(feature = "proof-program")]
22192249
pub async fn confidential_transfer_enable_non_confidential_credits<S: Signer>(
22202250
&self,
22212251
token_account: &Pubkey,
@@ -2236,6 +2266,7 @@ where
22362266
}
22372267

22382268
/// Disable non-confidential payments for a confidential extension token account
2269+
#[cfg(feature = "proof-program")]
22392270
pub async fn confidential_transfer_disable_non_confidential_credits<S: Signer>(
22402271
&self,
22412272
token_account: &Pubkey,
@@ -2256,6 +2287,7 @@ where
22562287
}
22572288

22582289
/// Withdraw withheld confidential tokens from mint using the uniquely derived decryption key
2290+
#[cfg(feature = "proof-program")]
22592291
pub async fn confidential_transfer_withdraw_withheld_tokens_from_mint<S: Signer>(
22602292
&self,
22612293
withdraw_withheld_authority: &S,
@@ -2281,6 +2313,7 @@ where
22812313
}
22822314

22832315
/// Withdraw withheld confidential tokens from mint using a custom decryption key
2316+
#[cfg(feature = "proof-program")]
22842317
pub async fn confidential_transfer_withdraw_withheld_tokens_from_mint_with_key<S: Signer>(
22852318
&self,
22862319
withdraw_withheld_authority: &S,
@@ -2314,6 +2347,7 @@ where
23142347

23152348
/// Withdraw withheld confidential tokens from accounts using the uniquely derived decryption
23162349
/// key
2350+
#[cfg(feature = "proof-program")]
23172351
pub async fn confidential_transfer_withdraw_withheld_tokens_from_accounts<S: Signer>(
23182352
&self,
23192353
withdraw_withheld_authority: &S,
@@ -2341,6 +2375,7 @@ where
23412375

23422376
/// Withdraw withheld confidential tokens from accounts using a custom decryption key
23432377
#[allow(clippy::too_many_arguments)]
2378+
#[cfg(feature = "proof-program")]
23442379
pub async fn confidential_transfer_withdraw_withheld_tokens_from_accounts_with_key<
23452380
S: Signer,
23462381
>(
@@ -2377,6 +2412,7 @@ where
23772412
}
23782413

23792414
/// Harvest withheld confidential tokens to mint
2415+
#[cfg(feature = "proof-program")]
23802416
pub async fn confidential_transfer_harvest_withheld_tokens_to_mint(
23812417
&self,
23822418
sources: &[&Pubkey],

token/program-2022-test/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ repository = "https://github.com/solana-labs/solana-program-library"
88
version = "0.0.1"
99

1010
[features]
11-
test-sbf = []
11+
test-sbf = ["zk-ops"]
1212
default = ["zk-ops"]
1313
zk-ops = []
14+
proof-program = []
1415

1516
[build-dependencies]
1617
walkdir = "2"

token/program-2022-test/tests/confidential_transfer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg(feature = "test-sbf")]
1+
#![cfg(all(feature = "test-sbf", feature = "proof-program"))]
22
#![cfg(twoxtx)]
33

44
mod program_test;

token/program-2022/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ serde-traits = ["serde", "serde_with"]
1515
# Remove these features once the underlying syscalls are released on all networks
1616
default = ["zk-ops"]
1717
zk-ops = []
18+
proof-program = []
1819

1920
[dependencies]
2021
arrayref = "0.3.6"

0 commit comments

Comments
 (0)