Skip to content

Commit

Permalink
Disable confidential transfer tests (solana-labs#3786)
Browse files Browse the repository at this point in the history
* disable confidential transfer tests

* featurize additional parts of the code
  • Loading branch information
samkim-crypto authored and HaoranYi committed Jul 19, 2023
1 parent d8f2d2f commit f70eea2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions token/program-2022-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ version = "0.0.1"

[features]
test-sbf = []
zk-ops = []

[build-dependencies]
walkdir = "2"
Expand Down
26 changes: 23 additions & 3 deletions token/program-2022-test/tests/confidential_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use {
program_test::{TestContext, TokenContext},
solana_program_test::tokio,
solana_sdk::{
epoch_info::EpochInfo, instruction::InstructionError, pubkey::Pubkey, signature::Signer,
signer::keypair::Keypair, transaction::TransactionError, transport::TransportError,
instruction::InstructionError, pubkey::Pubkey, signature::Signer, signer::keypair::Keypair,
transaction::TransactionError, transport::TransportError,
},
spl_token_2022::{
error::TokenError,
Expand All @@ -19,7 +19,7 @@ use {
},
solana_zk_token_sdk::{
encryption::{auth_encryption::*, elgamal::*},
zk_token_elgamal::{self, pod::Zeroable},
zk_token_elgamal::pod::Zeroable,
},
},
spl_token_client::{
Expand All @@ -29,10 +29,16 @@ use {
std::convert::TryInto,
};

#[cfg(feature = "zk-ops")]
use {solana_sdk::epoch_info::EpochInfo, spl_token_2022::solana_zk_token_sdk::zk_token_elgamal};

#[cfg(feature = "zk-ops")]
const TEST_MAXIMUM_FEE: u64 = 100;
#[cfg(feature = "zk-ops")]
const TEST_FEE_BASIS_POINTS: u16 = 250;
const TEST_MAXIMUM_PENDING_BALANCE_CREDIT_COUNTER: u64 = 2;

#[cfg(feature = "zk-ops")]
fn test_epoch_info() -> EpochInfo {
EpochInfo {
epoch: 0,
Expand All @@ -49,6 +55,7 @@ struct ConfidentialTransferMintWithKeypairs {
ct_mint_authority: Keypair,
#[allow(dead_code)]
ct_mint_transfer_auditor_encryption_keypair: ElGamalKeypair,
#[allow(dead_code)]
ct_mint_withdraw_withheld_authority_encryption_keypair: ElGamalKeypair,
}

Expand Down Expand Up @@ -123,6 +130,7 @@ impl ConfidentialTokenAccountMeta {
}
}

#[cfg(feature = "zk-ops")]
async fn new_with_required_memo_transfers<T>(token: &Token<T>, owner: &Keypair) -> Self
where
T: SendTransaction,
Expand Down Expand Up @@ -165,6 +173,7 @@ impl ConfidentialTokenAccountMeta {
}
}

#[cfg(feature = "zk-ops")]
async fn with_tokens<T>(
token: &Token<T>,
owner: &Keypair,
Expand Down Expand Up @@ -199,6 +208,7 @@ impl ConfidentialTokenAccountMeta {
meta
}

#[cfg(feature = "zk-ops")]
async fn check_balances<T>(&self, token: &Token<T>, expected: ConfidentialTokenAccountBalances)
where
T: SendTransaction,
Expand Down Expand Up @@ -238,13 +248,15 @@ impl ConfidentialTokenAccountMeta {
}
}

#[cfg(feature = "zk-ops")]
struct ConfidentialTokenAccountBalances {
pending_balance_lo: u64,
pending_balance_hi: u64,
available_balance: u64,
decryptable_available_balance: u64,
}

#[cfg(feature = "zk-ops")]
async fn check_withheld_amount_in_mint<T>(
token: &Token<T>,
withdraw_withheld_authority_encryption_keypair: &ElGamalKeypair,
Expand Down Expand Up @@ -468,6 +480,7 @@ async fn ct_new_account_is_empty() {
.unwrap();
}

#[cfg(feature = "zk-ops")]
#[tokio::test]
async fn ct_deposit() {
let ConfidentialTransferMintWithKeypairs { ct_mint, .. } =
Expand Down Expand Up @@ -591,6 +604,7 @@ async fn ct_deposit() {
assert_eq!(extension.actual_pending_balance_credit_counter, 2.into());
}

#[cfg(feature = "zk-ops")]
#[tokio::test]
async fn ct_withdraw() {
let ConfidentialTransferMintWithKeypairs { ct_mint, .. } =
Expand Down Expand Up @@ -693,6 +707,7 @@ async fn ct_withdraw() {
.unwrap();
}

#[cfg(feature = "zk-ops")]
#[tokio::test]
async fn ct_transfer() {
let ConfidentialTransferMintWithKeypairs { ct_mint, .. } =
Expand Down Expand Up @@ -920,6 +935,7 @@ async fn ct_transfer() {
.await;
}

#[cfg(feature = "zk-ops")]
#[tokio::test]
async fn ct_transfer_with_fee() {
let ConfidentialTransferMintWithKeypairs { ct_mint, .. } =
Expand Down Expand Up @@ -1123,6 +1139,7 @@ async fn ct_transfer_with_fee() {
.await;
}

#[cfg(feature = "zk-ops")]
#[tokio::test]
async fn ct_withdraw_withheld_tokens_from_mint() {
let ConfidentialTransferMintWithKeypairs {
Expand Down Expand Up @@ -1277,6 +1294,7 @@ async fn ct_withdraw_withheld_tokens_from_mint() {
.await;
}

#[cfg(feature = "zk-ops")]
#[tokio::test]
async fn ct_withdraw_withheld_tokens_from_accounts() {
let ConfidentialTransferMintWithKeypairs {
Expand Down Expand Up @@ -1396,6 +1414,7 @@ async fn ct_withdraw_withheld_tokens_from_accounts() {
.await;
}

#[cfg(feature = "zk-ops")]
#[tokio::test]
async fn ct_transfer_memo() {
let ConfidentialTransferMintWithKeypairs { ct_mint, .. } =
Expand Down Expand Up @@ -1496,6 +1515,7 @@ async fn ct_transfer_memo() {
.await;
}

#[cfg(feature = "zk-ops")]
#[tokio::test]
async fn ct_transfer_with_fee_memo() {
let ConfidentialTransferMintWithKeypairs { ct_mint, .. } =
Expand Down
2 changes: 1 addition & 1 deletion token/program-2022/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ no-entrypoint = []
test-sbf = []
serde-traits = ["serde", "serde_with"]
# Remove these features once the underlying syscalls are released on all networks
default = ["zk-ops"]
default = []
zk-ops = []

[dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use {
error::TokenError,
extension::{
confidential_transfer::{instruction::*, *},
memo_transfer::{check_previous_sibling_instruction_is_memo, memo_required},
non_transferable::NonTransferable,
StateWithExtensions, StateWithExtensionsMut,
},
instruction::{decode_instruction_data, decode_instruction_type},
Expand All @@ -26,7 +24,11 @@ use {
// Remove feature once zk ops syscalls are enabled on all networks
#[cfg(feature = "zk-ops")]
use {
crate::extension::transfer_fee::TransferFeeConfig,
crate::extension::{
memo_transfer::{check_previous_sibling_instruction_is_memo, memo_required},
non_transferable::NonTransferable,
transfer_fee::TransferFeeConfig,
},
solana_program::{clock::Clock, sysvar::Sysvar},
solana_zk_token_sdk::zk_token_elgamal::ops,
};
Expand All @@ -46,13 +48,15 @@ fn decode_proof_instruction<T: Pod>(
}

/// Checks if a confidential extension is configured to send funds
#[cfg(feature = "zk-ops")]
fn check_source_confidential_account(
source_confidential_transfer_account: &ConfidentialTransferAccount,
) -> ProgramResult {
source_confidential_transfer_account.approved()
}

/// Checks if a confidential extension is configured to receive funds
#[cfg(feature = "zk-ops")]
fn check_destination_confidential_account(
destination_confidential_transfer_account: &ConfidentialTransferAccount,
) -> ProgramResult {
Expand Down

0 comments on commit f70eea2

Please sign in to comment.