Skip to content

Commit 24aa353

Browse files
committed
fix: support builds targetting wasm32
- Introduced conditional compilation for WASM target architecture in burn.rs, mint.rs, transfer.rs, and transfer_with_fee.rs. Fixes solana-program#293
1 parent 700cc3c commit 24aa353

File tree

5 files changed

+120
-16
lines changed

5 files changed

+120
-16
lines changed

confidential-transfer/proof-generation/src/burn.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(target_arch = "wasm32")]
2+
use solana_zk_sdk::encryption::grouped_elgamal::GroupedElGamalCiphertext3Handles;
13
use {
24
crate::{
35
encryption::BurnAmountCiphertext, errors::TokenProofGenerationError,
@@ -53,14 +55,33 @@ pub fn burn_split_proof_data(
5355
supply_elgamal_pubkey,
5456
auditor_elgamal_pubkey,
5557
);
58+
#[cfg(not(target_arch = "wasm32"))]
59+
let grouped_ciphertext_lo = burn_amount_ciphertext_lo.0;
60+
#[cfg(target_arch = "wasm32")]
61+
let grouped_ciphertext_lo = GroupedElGamalCiphertext3Handles::encryption_with_u64(
62+
source_elgamal_keypair.pubkey(),
63+
supply_elgamal_pubkey,
64+
auditor_elgamal_pubkey,
65+
burn_amount_lo,
66+
&burn_amount_opening_lo,
67+
);
5668

5769
let (burn_amount_ciphertext_hi, burn_amount_opening_hi) = BurnAmountCiphertext::new(
5870
burn_amount_hi,
5971
source_elgamal_keypair.pubkey(),
6072
supply_elgamal_pubkey,
6173
auditor_elgamal_pubkey,
6274
);
63-
75+
#[cfg(not(target_arch = "wasm32"))]
76+
let grouped_ciphertext_hi = burn_amount_ciphertext_hi.0;
77+
#[cfg(target_arch = "wasm32")]
78+
let grouped_ciphertext_hi = GroupedElGamalCiphertext3Handles::encryption_with_u64(
79+
source_elgamal_keypair.pubkey(),
80+
supply_elgamal_pubkey,
81+
auditor_elgamal_pubkey,
82+
burn_amount_hi,
83+
&burn_amount_opening_hi,
84+
);
6485
// decrypt the current available balance at the source
6586
let current_decrypted_available_balance = current_decryptable_available_balance
6687
.decrypt(source_aes_key)
@@ -108,8 +129,8 @@ pub fn burn_split_proof_data(
108129
source_elgamal_keypair.pubkey(),
109130
supply_elgamal_pubkey,
110131
auditor_elgamal_pubkey,
111-
&burn_amount_ciphertext_lo.0,
112-
&burn_amount_ciphertext_hi.0,
132+
&grouped_ciphertext_lo,
133+
&grouped_ciphertext_hi,
113134
burn_amount_lo,
114135
burn_amount_hi,
115136
&burn_amount_opening_lo,

confidential-transfer/proof-generation/src/mint.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(target_arch = "wasm32")]
2+
use solana_zk_sdk::encryption::grouped_elgamal::GroupedElGamalCiphertext3Handles;
13
use {
24
crate::{
35
encryption::MintAmountCiphertext, errors::TokenProofGenerationError,
@@ -52,13 +54,33 @@ pub fn mint_split_proof_data(
5254
supply_elgamal_keypair.pubkey(),
5355
auditor_elgamal_pubkey,
5456
);
57+
#[cfg(not(target_arch = "wasm32"))]
58+
let grouped_ciphertext_lo = mint_amount_grouped_ciphertext_lo.0;
59+
#[cfg(target_arch = "wasm32")]
60+
let grouped_ciphertext_lo = GroupedElGamalCiphertext3Handles::encryption_with_u64(
61+
destination_elgamal_pubkey,
62+
supply_elgamal_keypair.pubkey(),
63+
auditor_elgamal_pubkey,
64+
mint_amount_lo,
65+
&mint_amount_opening_lo,
66+
);
5567

5668
let (mint_amount_grouped_ciphertext_hi, mint_amount_opening_hi) = MintAmountCiphertext::new(
5769
mint_amount_hi,
5870
destination_elgamal_pubkey,
5971
supply_elgamal_keypair.pubkey(),
6072
auditor_elgamal_pubkey,
6173
);
74+
#[cfg(not(target_arch = "wasm32"))]
75+
let grouped_ciphertext_hi = mint_amount_grouped_ciphertext_hi.0;
76+
#[cfg(target_arch = "wasm32")]
77+
let grouped_ciphertext_hi = GroupedElGamalCiphertext3Handles::encryption_with_u64(
78+
destination_elgamal_pubkey,
79+
supply_elgamal_keypair.pubkey(),
80+
auditor_elgamal_pubkey,
81+
mint_amount_hi,
82+
&mint_amount_opening_hi,
83+
);
6284

6385
// compute the new supply ciphertext
6486
let mint_amount_ciphertext_supply_lo = mint_amount_grouped_ciphertext_lo
@@ -101,8 +123,8 @@ pub fn mint_split_proof_data(
101123
destination_elgamal_pubkey,
102124
supply_elgamal_keypair.pubkey(),
103125
auditor_elgamal_pubkey,
104-
&mint_amount_grouped_ciphertext_lo.0,
105-
&mint_amount_grouped_ciphertext_hi.0,
126+
&grouped_ciphertext_lo,
127+
&grouped_ciphertext_hi,
106128
mint_amount_lo,
107129
mint_amount_hi,
108130
&mint_amount_opening_lo,

confidential-transfer/proof-generation/src/transfer.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(target_arch = "wasm32")]
2+
use solana_zk_sdk::encryption::grouped_elgamal::GroupedElGamalCiphertext3Handles;
13
use {
24
crate::{
35
encryption::TransferAmountCiphertext, errors::TokenProofGenerationError,
@@ -55,6 +57,16 @@ pub fn transfer_split_proof_data(
5557
destination_elgamal_pubkey,
5658
auditor_elgamal_pubkey,
5759
);
60+
#[cfg(not(target_arch = "wasm32"))]
61+
let grouped_ciphertext_lo = transfer_amount_grouped_ciphertext_lo.0;
62+
#[cfg(target_arch = "wasm32")]
63+
let grouped_ciphertext_lo = GroupedElGamalCiphertext3Handles::encryption_with_u64(
64+
source_elgamal_keypair.pubkey(),
65+
destination_elgamal_pubkey,
66+
auditor_elgamal_pubkey,
67+
transfer_amount_lo,
68+
&transfer_amount_opening_lo,
69+
);
5870

5971
let (transfer_amount_grouped_ciphertext_hi, transfer_amount_opening_hi) =
6072
TransferAmountCiphertext::new(
@@ -63,6 +75,16 @@ pub fn transfer_split_proof_data(
6375
destination_elgamal_pubkey,
6476
auditor_elgamal_pubkey,
6577
);
78+
#[cfg(not(target_arch = "wasm32"))]
79+
let grouped_ciphertext_hi = transfer_amount_grouped_ciphertext_hi.0;
80+
#[cfg(target_arch = "wasm32")]
81+
let grouped_ciphertext_hi = GroupedElGamalCiphertext3Handles::encryption_with_u64(
82+
source_elgamal_keypair.pubkey(),
83+
destination_elgamal_pubkey,
84+
auditor_elgamal_pubkey,
85+
transfer_amount_hi,
86+
&transfer_amount_opening_hi,
87+
);
6688

6789
// Decrypt the current available balance at the source
6890
let current_decrypted_available_balance = current_decryptable_available_balance
@@ -112,8 +134,8 @@ pub fn transfer_split_proof_data(
112134
source_elgamal_keypair.pubkey(),
113135
destination_elgamal_pubkey,
114136
auditor_elgamal_pubkey,
115-
&transfer_amount_grouped_ciphertext_lo.0,
116-
&transfer_amount_grouped_ciphertext_hi.0,
137+
&grouped_ciphertext_lo,
138+
&grouped_ciphertext_hi,
117139
transfer_amount_lo,
118140
transfer_amount_hi,
119141
&transfer_amount_opening_lo,

confidential-transfer/proof-generation/src/transfer_with_fee.rs

+45-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#[cfg(target_arch = "wasm32")]
2+
use solana_zk_sdk::encryption::grouped_elgamal::{GroupedElGamalCiphertext2Handles, GroupedElGamalCiphertext3Handles};
3+
#[cfg(not(target_arch = "wasm32"))]
4+
use solana_zk_sdk::encryption::grouped_elgamal::GroupedElGamal;
15
use {
26
crate::{
37
encryption::{FeeCiphertext, TransferAmountCiphertext},
@@ -9,10 +13,7 @@ use {
913
curve25519_dalek::scalar::Scalar,
1014
solana_zk_sdk::{
1115
encryption::{
12-
auth_encryption::{AeCiphertext, AeKey},
13-
elgamal::{ElGamalCiphertext, ElGamalKeypair, ElGamalPubkey},
14-
grouped_elgamal::GroupedElGamal,
15-
pedersen::{Pedersen, PedersenCommitment, PedersenOpening},
16+
auth_encryption::{AeCiphertext, AeKey}, elgamal::{ElGamalCiphertext, ElGamalKeypair, ElGamalPubkey}, pedersen::{Pedersen, PedersenCommitment, PedersenOpening}
1617
},
1718
zk_elgamal_proof_program::proof_data::{
1819
BatchedGroupedCiphertext2HandlesValidityProofData,
@@ -71,6 +72,16 @@ pub fn transfer_with_fee_split_proof_data(
7172
destination_elgamal_pubkey,
7273
auditor_elgamal_pubkey,
7374
);
75+
#[cfg(not(target_arch = "wasm32"))]
76+
let grouped_ciphertext_lo = transfer_amount_grouped_ciphertext_lo.0;
77+
#[cfg(target_arch = "wasm32")]
78+
let grouped_ciphertext_lo = GroupedElGamalCiphertext3Handles::encryption_with_u64(
79+
source_elgamal_keypair.pubkey(),
80+
destination_elgamal_pubkey,
81+
auditor_elgamal_pubkey,
82+
transfer_amount_lo,
83+
&transfer_amount_opening_lo,
84+
);
7485

7586
let (transfer_amount_grouped_ciphertext_hi, transfer_amount_opening_hi) =
7687
TransferAmountCiphertext::new(
@@ -79,6 +90,16 @@ pub fn transfer_with_fee_split_proof_data(
7990
destination_elgamal_pubkey,
8091
auditor_elgamal_pubkey,
8192
);
93+
#[cfg(not(target_arch = "wasm32"))]
94+
let grouped_ciphertext_hi = transfer_amount_grouped_ciphertext_hi.0;
95+
#[cfg(target_arch = "wasm32")]
96+
let grouped_ciphertext_hi = GroupedElGamalCiphertext3Handles::encryption_with_u64(
97+
source_elgamal_keypair.pubkey(),
98+
destination_elgamal_pubkey,
99+
auditor_elgamal_pubkey,
100+
transfer_amount_hi,
101+
&transfer_amount_opening_hi,
102+
);
82103

83104
// Decrypt the current available balance at the source
84105
let current_decrypted_available_balance = current_decryptable_available_balance
@@ -130,8 +151,8 @@ pub fn transfer_with_fee_split_proof_data(
130151
source_elgamal_keypair.pubkey(),
131152
destination_elgamal_pubkey,
132153
auditor_elgamal_pubkey,
133-
&transfer_amount_grouped_ciphertext_lo.0,
134-
&transfer_amount_grouped_ciphertext_hi.0,
154+
&grouped_ciphertext_lo,
155+
&grouped_ciphertext_hi,
135156
transfer_amount_lo,
136157
transfer_amount_hi,
137158
&transfer_amount_opening_lo,
@@ -233,6 +254,7 @@ pub fn transfer_with_fee_split_proof_data(
233254

234255
// encrypt the fee amount under the destination and withdraw withheld authority
235256
// ElGamal public key
257+
#[cfg(not(target_arch = "wasm32"))]
236258
let fee_destination_withdraw_withheld_authority_ciphertext_lo = GroupedElGamal::encrypt_with(
237259
[
238260
destination_elgamal_pubkey,
@@ -241,14 +263,29 @@ pub fn transfer_with_fee_split_proof_data(
241263
fee_amount_lo,
242264
&fee_opening_lo,
243265
);
244-
let fee_destination_withdraw_withheld_authority_ciphertext_hi = GroupedElGamal::encrypt_with(
245-
[
266+
#[cfg(target_arch = "wasm32")]
267+
let fee_destination_withdraw_withheld_authority_ciphertext_lo = GroupedElGamalCiphertext2Handles::encryption_with_u64(
268+
destination_elgamal_pubkey,
269+
withdraw_withheld_authority_elgamal_pubkey,
270+
fee_amount_lo,
271+
&fee_opening_lo
272+
);
273+
274+
#[cfg(not(target_arch = "wasm32"))]
275+
let fee_destination_withdraw_withheld_authority_ciphertext_hi = GroupedElGamal::encrypt_with([
246276
destination_elgamal_pubkey,
247277
withdraw_withheld_authority_elgamal_pubkey,
248278
],
249279
fee_amount_hi,
250280
&fee_opening_hi,
251281
);
282+
#[cfg(target_arch = "wasm32")]
283+
let fee_destination_withdraw_withheld_authority_ciphertext_hi = GroupedElGamalCiphertext2Handles::encryption_with_u64(
284+
destination_elgamal_pubkey,
285+
withdraw_withheld_authority_elgamal_pubkey,
286+
fee_amount_hi,
287+
&fee_opening_hi,
288+
);
252289

253290
// generate fee ciphertext validity data
254291
let fee_ciphertext_validity_proof_data =

program/src/extension/confidential_transfer_fee/processor.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use {
2929
processor::Processor,
3030
solana_zk_sdk::encryption::pod::elgamal::PodElGamalPubkey,
3131
},
32-
bytemuck::Zeroable,
3332
solana_account_info::{next_account_info, AccountInfo},
3433
solana_msg::msg,
3534
solana_program_error::{ProgramError, ProgramResult},
@@ -38,6 +37,9 @@ use {
3837
spl_token_confidential_transfer_proof_extraction::instruction::verify_and_extract_context,
3938
};
4039

40+
#[cfg(not(target_arch = "wasm32"))]
41+
use bytemuck::Zeroable;
42+
4143
/// Processes an [`InitializeConfidentialTransferFeeConfig`] instruction.
4244
fn process_initialize_confidential_transfer_fee_config(
4345
accounts: &[AccountInfo],

0 commit comments

Comments
 (0)