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

Commit 6570d6e

Browse files
[token-2022] Remove unnecessary split proof generation logic (#7164)
1 parent 342e227 commit 6570d6e

File tree

1 file changed

+116
-64
lines changed

1 file changed

+116
-64
lines changed

token/client/src/token.rs

Lines changed: 116 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,19 +2083,26 @@ where
20832083
WithdrawAccountInfo::new(confidential_transfer_account)
20842084
};
20852085

2086-
let WithdrawProofData {
2087-
equality_proof_data,
2088-
range_proof_data,
2089-
} = account_info
2090-
.generate_proof_data(withdraw_amount, elgamal_keypair, aes_key)
2091-
.map_err(|_| TokenError::ProofGeneration)?;
2092-
2093-
// if proof accounts are none, then proof data must be included as instruction
2094-
// data
2095-
let equality_proof_data = equality_proof_account
2096-
.is_none()
2097-
.then_some(equality_proof_data);
2098-
let range_proof_data = range_proof_account.is_none().then_some(range_proof_data);
2086+
let (equality_proof_data, range_proof_data) =
2087+
if equality_proof_account.is_some() && range_proof_account.is_some() {
2088+
(None, None)
2089+
} else {
2090+
let WithdrawProofData {
2091+
equality_proof_data,
2092+
range_proof_data,
2093+
} = account_info
2094+
.generate_proof_data(withdraw_amount, elgamal_keypair, aes_key)
2095+
.map_err(|_| TokenError::ProofGeneration)?;
2096+
2097+
// if proof accounts are none, then proof data must be included as instruction
2098+
// data
2099+
let equality_proof_data = equality_proof_account
2100+
.is_none()
2101+
.then_some(equality_proof_data);
2102+
let range_proof_data = range_proof_account.is_none().then_some(range_proof_data);
2103+
2104+
(equality_proof_data, range_proof_data)
2105+
};
20992106

21002107
// cannot panic as long as either `proof_data` or `proof_account` is `Some(..)`,
21012108
// which is guaranteed by the previous check
@@ -2165,29 +2172,46 @@ where
21652172
TransferAccountInfo::new(confidential_transfer_account)
21662173
};
21672174

2168-
let TransferProofData {
2169-
equality_proof_data,
2170-
ciphertext_validity_proof_data,
2171-
range_proof_data,
2172-
} = account_info
2173-
.generate_split_transfer_proof_data(
2174-
transfer_amount,
2175-
source_elgamal_keypair,
2176-
source_aes_key,
2177-
destination_elgamal_pubkey,
2178-
auditor_elgamal_pubkey,
2175+
let (equality_proof_data, ciphertext_validity_proof_data, range_proof_data) = if [
2176+
equality_proof_account,
2177+
ciphertext_validity_proof_account,
2178+
range_proof_account,
2179+
]
2180+
.iter()
2181+
.all(|proof_account| proof_account.is_some())
2182+
{
2183+
(None, None, None)
2184+
} else {
2185+
let TransferProofData {
2186+
equality_proof_data,
2187+
ciphertext_validity_proof_data,
2188+
range_proof_data,
2189+
} = account_info
2190+
.generate_split_transfer_proof_data(
2191+
transfer_amount,
2192+
source_elgamal_keypair,
2193+
source_aes_key,
2194+
destination_elgamal_pubkey,
2195+
auditor_elgamal_pubkey,
2196+
)
2197+
.map_err(|_| TokenError::ProofGeneration)?;
2198+
2199+
// if proof accounts are none, then proof data must be included as instruction
2200+
// data
2201+
let equality_proof_data = equality_proof_account
2202+
.is_none()
2203+
.then_some(equality_proof_data);
2204+
let ciphertext_validity_proof_data = ciphertext_validity_proof_account
2205+
.is_none()
2206+
.then_some(ciphertext_validity_proof_data);
2207+
let range_proof_data = range_proof_account.is_none().then_some(range_proof_data);
2208+
2209+
(
2210+
equality_proof_data,
2211+
ciphertext_validity_proof_data,
2212+
range_proof_data,
21792213
)
2180-
.map_err(|_| TokenError::ProofGeneration)?;
2181-
2182-
// if proof accounts are none, then proof data must be included as instruction
2183-
// data
2184-
let equality_proof_data = equality_proof_account
2185-
.is_none()
2186-
.then_some(equality_proof_data);
2187-
let ciphertext_validity_proof_data = ciphertext_validity_proof_account
2188-
.is_none()
2189-
.then_some(ciphertext_validity_proof_data);
2190-
let range_proof_data = range_proof_account.is_none().then_some(range_proof_data);
2214+
};
21912215

21922216
// cannot panic as long as either `proof_data` or `proof_account` is `Some(..)`,
21932217
// which is guaranteed by the previous check
@@ -2457,7 +2481,7 @@ where
24572481
source_authority: &Pubkey,
24582482
equality_proof_account: Option<&ProofAccount>,
24592483
transfer_amount_ciphertext_validity_proof_account: Option<&ProofAccount>,
2460-
fee_sigma_proof_account: Option<&ProofAccount>,
2484+
percentage_with_cap_proof_account: Option<&ProofAccount>,
24612485
fee_ciphertext_validity_proof_account: Option<&ProofAccount>,
24622486
range_proof_account: Option<&ProofAccount>,
24632487
transfer_amount: u64,
@@ -2483,39 +2507,67 @@ where
24832507
TransferAccountInfo::new(confidential_transfer_account)
24842508
};
24852509

2486-
let TransferWithFeeProofData {
2510+
let (
24872511
equality_proof_data,
24882512
transfer_amount_ciphertext_validity_proof_data,
24892513
percentage_with_cap_proof_data,
24902514
fee_ciphertext_validity_proof_data,
24912515
range_proof_data,
2492-
} = account_info
2493-
.generate_split_transfer_with_fee_proof_data(
2494-
transfer_amount,
2495-
source_elgamal_keypair,
2496-
source_aes_key,
2497-
destination_elgamal_pubkey,
2498-
auditor_elgamal_pubkey,
2499-
withdraw_withheld_authority_elgamal_pubkey,
2500-
fee_rate_basis_points,
2501-
maximum_fee,
2502-
)
2503-
.map_err(|_| TokenError::ProofGeneration)?;
2516+
) = if [
2517+
equality_proof_account,
2518+
transfer_amount_ciphertext_validity_proof_account,
2519+
percentage_with_cap_proof_account,
2520+
fee_ciphertext_validity_proof_account,
2521+
range_proof_account,
2522+
]
2523+
.iter()
2524+
.all(|proof_account| proof_account.is_some())
2525+
{
2526+
// is all proofs come from accounts, then skip proof generation
2527+
(None, None, None, None, None)
2528+
} else {
2529+
let TransferWithFeeProofData {
2530+
equality_proof_data,
2531+
transfer_amount_ciphertext_validity_proof_data,
2532+
percentage_with_cap_proof_data,
2533+
fee_ciphertext_validity_proof_data,
2534+
range_proof_data,
2535+
} = account_info
2536+
.generate_split_transfer_with_fee_proof_data(
2537+
transfer_amount,
2538+
source_elgamal_keypair,
2539+
source_aes_key,
2540+
destination_elgamal_pubkey,
2541+
auditor_elgamal_pubkey,
2542+
withdraw_withheld_authority_elgamal_pubkey,
2543+
fee_rate_basis_points,
2544+
maximum_fee,
2545+
)
2546+
.map_err(|_| TokenError::ProofGeneration)?;
25042547

2505-
let equality_proof_data = equality_proof_account
2506-
.is_none()
2507-
.then_some(equality_proof_data);
2508-
let transfer_amount_ciphertext_validity_proof_data =
2509-
transfer_amount_ciphertext_validity_proof_account
2548+
let equality_proof_data = equality_proof_account
2549+
.is_none()
2550+
.then_some(equality_proof_data);
2551+
let transfer_amount_ciphertext_validity_proof_data =
2552+
transfer_amount_ciphertext_validity_proof_account
2553+
.is_none()
2554+
.then_some(transfer_amount_ciphertext_validity_proof_data);
2555+
let percentage_with_cap_proof_data = percentage_with_cap_proof_account
2556+
.is_none()
2557+
.then_some(percentage_with_cap_proof_data);
2558+
let fee_ciphertext_validity_proof_data = fee_ciphertext_validity_proof_account
25102559
.is_none()
2511-
.then_some(transfer_amount_ciphertext_validity_proof_data);
2512-
let fee_sigma_proof_data = fee_sigma_proof_account
2513-
.is_none()
2514-
.then_some(percentage_with_cap_proof_data);
2515-
let fee_ciphertext_validity_proof_data = fee_ciphertext_validity_proof_account
2516-
.is_none()
2517-
.then_some(fee_ciphertext_validity_proof_data);
2518-
let range_proof_data = range_proof_account.is_none().then_some(range_proof_data);
2560+
.then_some(fee_ciphertext_validity_proof_data);
2561+
let range_proof_data = range_proof_account.is_none().then_some(range_proof_data);
2562+
2563+
(
2564+
equality_proof_data,
2565+
transfer_amount_ciphertext_validity_proof_data,
2566+
percentage_with_cap_proof_data,
2567+
fee_ciphertext_validity_proof_data,
2568+
range_proof_data,
2569+
)
2570+
};
25192571

25202572
// cannot panic as long as either `proof_data` or `proof_account` is `Some(..)`,
25212573
// which is guaranteed by the previous check
@@ -2533,8 +2585,8 @@ where
25332585
)
25342586
.unwrap();
25352587
let fee_sigma_proof_location = Self::confidential_transfer_create_proof_location(
2536-
fee_sigma_proof_data.as_ref(),
2537-
fee_sigma_proof_account,
2588+
percentage_with_cap_proof_data.as_ref(),
2589+
percentage_with_cap_proof_account,
25382590
3,
25392591
)
25402592
.unwrap();

0 commit comments

Comments
 (0)