Skip to content

Commit ca08984

Browse files
[program] Re-order confidential mint burn ciphertexts to dest/src, supply, then auditor (#173)
* re-order confidential mint burn ciphertexts to dest/src, supply, then auditor * add checks that the supply in the mint is updated correctly * add and subtract the correct ciphertext to the encrypted supply
1 parent d14c98b commit ca08984

File tree

9 files changed

+82
-27
lines changed

9 files changed

+82
-27
lines changed

clients/rust-legacy/tests/confidential_mint_burn.rs

+55
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ async fn confidential_mint_burn_with_option(option: ConfidentialTransferOption)
10771077
.await
10781078
.unwrap();
10791079

1080+
// check that the right amount is minted to the destination account
10801081
let state = token
10811082
.get_account_info(&alice_meta.token_account)
10821083
.await
@@ -1102,6 +1103,23 @@ async fn confidential_mint_burn_with_option(option: ConfidentialTransferOption)
11021103
0
11031104
);
11041105

1106+
// check that the supply in the mint is updated correctly
1107+
let mint = token.get_mint_info().await.unwrap();
1108+
let extension = mint.get_extension::<ConfidentialMintBurn>().unwrap();
1109+
assert_eq!(
1110+
supply_elgamal_keypair
1111+
.secret()
1112+
.decrypt_u32(&extension.confidential_supply.try_into().unwrap())
1113+
.unwrap(),
1114+
mint_amount
1115+
);
1116+
assert_eq!(
1117+
supply_aes_key
1118+
.decrypt(&extension.decryptable_supply.try_into().unwrap())
1119+
.unwrap(),
1120+
mint_amount
1121+
);
1122+
11051123
token
11061124
.confidential_transfer_apply_pending_balance(
11071125
&alice_meta.token_account,
@@ -1129,6 +1147,7 @@ async fn confidential_mint_burn_with_option(option: ConfidentialTransferOption)
11291147
.await
11301148
.unwrap();
11311149

1150+
// check that the right amount is burned in the source account
11321151
let state = token
11331152
.get_account_info(&alice_meta.token_account)
11341153
.await
@@ -1153,4 +1172,40 @@ async fn confidential_mint_burn_with_option(option: ConfidentialTransferOption)
11531172
.unwrap(),
11541173
0
11551174
);
1175+
1176+
// check that the supply in the mint is updated correctly
1177+
let mint = token.get_mint_info().await.unwrap();
1178+
let extension = mint.get_extension::<ConfidentialMintBurn>().unwrap();
1179+
assert_eq!(
1180+
supply_elgamal_keypair
1181+
.secret()
1182+
.decrypt_u32(&extension.confidential_supply.try_into().unwrap())
1183+
.unwrap(),
1184+
0
1185+
);
1186+
assert_eq!(
1187+
supply_aes_key
1188+
.decrypt(&extension.decryptable_supply.try_into().unwrap())
1189+
.unwrap(),
1190+
mint_amount,
1191+
);
1192+
1193+
let new_decryptable_supply = supply_aes_key.encrypt(0).into();
1194+
token
1195+
.confidential_transfer_update_decrypt_supply(
1196+
&mint_authority.pubkey(),
1197+
&new_decryptable_supply,
1198+
&[&mint_authority],
1199+
)
1200+
.await
1201+
.unwrap();
1202+
1203+
let mint = token.get_mint_info().await.unwrap();
1204+
let extension = mint.get_extension::<ConfidentialMintBurn>().unwrap();
1205+
assert_eq!(
1206+
supply_aes_key
1207+
.decrypt(&extension.decryptable_supply.try_into().unwrap())
1208+
.unwrap(),
1209+
0,
1210+
);
11561211
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use {
1212
/// The public keys associated with a confidential burn
1313
pub struct BurnPubkeys {
1414
pub source: PodElGamalPubkey,
15-
pub auditor: PodElGamalPubkey,
1615
pub supply: PodElGamalPubkey,
16+
pub auditor: PodElGamalPubkey,
1717
}
1818

1919
/// The proof context information needed to process a confidential burn
@@ -51,8 +51,8 @@ impl BurnProofContext {
5151
// `BurnProofContext`.
5252
let BatchedGroupedCiphertext3HandlesValidityProofContext {
5353
first_pubkey: source_elgamal_pubkey_from_validity_proof,
54-
second_pubkey: auditor_elgamal_pubkey,
55-
third_pubkey: supply_elgamal_pubkey,
54+
second_pubkey: supply_elgamal_pubkey,
55+
third_pubkey: auditor_elgamal_pubkey,
5656
grouped_ciphertext_lo: burn_amount_ciphertext_lo,
5757
grouped_ciphertext_hi: burn_amount_ciphertext_hi,
5858
} = ciphertext_validity_proof_context;
@@ -116,8 +116,8 @@ impl BurnProofContext {
116116

117117
let burn_pubkeys = BurnPubkeys {
118118
source: *source_elgamal_pubkey_from_equality_proof,
119-
auditor: *auditor_elgamal_pubkey,
120119
supply: *supply_elgamal_pubkey,
120+
auditor: *auditor_elgamal_pubkey,
121121
};
122122

123123
Ok(BurnProofContext {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use {
1212
/// The public keys associated with a confidential mint
1313
pub struct MintPubkeys {
1414
pub destination: PodElGamalPubkey,
15-
pub auditor: PodElGamalPubkey,
1615
pub supply: PodElGamalPubkey,
16+
pub auditor: PodElGamalPubkey,
1717
}
1818

1919
/// The proof context information needed to process a confidential mint
@@ -49,8 +49,8 @@ impl MintProofContext {
4949
// fields should be returned as part of `MintProofContext`.
5050
let BatchedGroupedCiphertext3HandlesValidityProofContext {
5151
first_pubkey: destination_elgamal_pubkey,
52-
second_pubkey: auditor_elgamal_pubkey,
53-
third_pubkey: supply_elgamal_pubkey_from_ciphertext_validity_proof,
52+
second_pubkey: supply_elgamal_pubkey_from_ciphertext_validity_proof,
53+
third_pubkey: auditor_elgamal_pubkey,
5454
grouped_ciphertext_lo: mint_amount_ciphertext_lo,
5555
grouped_ciphertext_hi: mint_amount_ciphertext_hi,
5656
} = ciphertext_validity_proof_context;
@@ -116,8 +116,8 @@ impl MintProofContext {
116116

117117
let mint_pubkeys = MintPubkeys {
118118
destination: *destination_elgamal_pubkey,
119-
auditor: *auditor_elgamal_pubkey,
120119
supply: *supply_elgamal_pubkey_from_equality_proof,
120+
auditor: *auditor_elgamal_pubkey,
121121
};
122122

123123
Ok(MintProofContext {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ pub fn burn_split_proof_data(
3636
burn_amount: u64,
3737
source_elgamal_keypair: &ElGamalKeypair,
3838
source_aes_key: &AeKey,
39-
auditor_elgamal_pubkey: Option<&ElGamalPubkey>,
4039
supply_elgamal_pubkey: &ElGamalPubkey,
40+
auditor_elgamal_pubkey: Option<&ElGamalPubkey>,
4141
) -> Result<BurnProofData, TokenProofGenerationError> {
4242
let default_auditor_pubkey = ElGamalPubkey::default();
4343
let auditor_elgamal_pubkey = auditor_elgamal_pubkey.unwrap_or(&default_auditor_pubkey);
@@ -50,15 +50,15 @@ pub fn burn_split_proof_data(
5050
let (burn_amount_ciphertext_lo, burn_amount_opening_lo) = BurnAmountCiphertext::new(
5151
burn_amount_lo,
5252
source_elgamal_keypair.pubkey(),
53-
auditor_elgamal_pubkey,
5453
supply_elgamal_pubkey,
54+
auditor_elgamal_pubkey,
5555
);
5656

5757
let (burn_amount_ciphertext_hi, burn_amount_opening_hi) = BurnAmountCiphertext::new(
5858
burn_amount_hi,
5959
source_elgamal_keypair.pubkey(),
60-
auditor_elgamal_pubkey,
6160
supply_elgamal_pubkey,
61+
auditor_elgamal_pubkey,
6262
);
6363

6464
// decrypt the current available balance at the source
@@ -106,8 +106,8 @@ pub fn burn_split_proof_data(
106106
// generate ciphertext validity data
107107
let ciphertext_validity_proof_data = BatchedGroupedCiphertext3HandlesValidityProofData::new(
108108
source_elgamal_keypair.pubkey(),
109-
auditor_elgamal_pubkey,
110109
supply_elgamal_pubkey,
110+
auditor_elgamal_pubkey,
111111
&burn_amount_ciphertext_lo.0,
112112
&burn_amount_ciphertext_hi.0,
113113
burn_amount_lo,

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ impl BurnAmountCiphertext {
9595
pub fn new(
9696
amount: u64,
9797
source_pubkey: &ElGamalPubkey,
98-
auditor_pubkey: &ElGamalPubkey,
9998
supply_pubkey: &ElGamalPubkey,
99+
auditor_pubkey: &ElGamalPubkey,
100100
) -> (Self, PedersenOpening) {
101101
let opening = PedersenOpening::new_rand();
102102
let grouped_ciphertext = GroupedElGamal::<3>::encrypt_with(
103-
[source_pubkey, auditor_pubkey, supply_pubkey],
103+
[source_pubkey, supply_pubkey, auditor_pubkey],
104104
amount,
105105
&opening,
106106
);
@@ -121,12 +121,12 @@ impl MintAmountCiphertext {
121121
pub fn new(
122122
amount: u64,
123123
source_pubkey: &ElGamalPubkey,
124-
auditor_pubkey: &ElGamalPubkey,
125124
supply_pubkey: &ElGamalPubkey,
125+
auditor_pubkey: &ElGamalPubkey,
126126
) -> (Self, PedersenOpening) {
127127
let opening = PedersenOpening::new_rand();
128128
let grouped_ciphertext = GroupedElGamal::<3>::encrypt_with(
129-
[source_pubkey, auditor_pubkey, supply_pubkey],
129+
[source_pubkey, supply_pubkey, auditor_pubkey],
130130
amount,
131131
&opening,
132132
);

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,25 @@ pub fn mint_split_proof_data(
4949
let (mint_amount_grouped_ciphertext_lo, mint_amount_opening_lo) = MintAmountCiphertext::new(
5050
mint_amount_lo,
5151
destination_elgamal_pubkey,
52-
auditor_elgamal_pubkey,
5352
supply_elgamal_keypair.pubkey(),
53+
auditor_elgamal_pubkey,
5454
);
5555

5656
let (mint_amount_grouped_ciphertext_hi, mint_amount_opening_hi) = MintAmountCiphertext::new(
5757
mint_amount_hi,
5858
destination_elgamal_pubkey,
59-
auditor_elgamal_pubkey,
6059
supply_elgamal_keypair.pubkey(),
60+
auditor_elgamal_pubkey,
6161
);
6262

6363
// compute the new supply ciphertext
6464
let mint_amount_ciphertext_supply_lo = mint_amount_grouped_ciphertext_lo
6565
.0
66-
.to_elgamal_ciphertext(2)
66+
.to_elgamal_ciphertext(1)
6767
.unwrap();
6868
let mint_amount_ciphertext_supply_hi = mint_amount_grouped_ciphertext_hi
6969
.0
70-
.to_elgamal_ciphertext(2)
70+
.to_elgamal_ciphertext(1)
7171
.unwrap();
7272

7373
#[allow(clippy::arithmetic_side_effects)]
@@ -99,8 +99,8 @@ pub fn mint_split_proof_data(
9999
// generate ciphertext validity proof data
100100
let ciphertext_validity_proof_data = BatchedGroupedCiphertext3HandlesValidityProofData::new(
101101
destination_elgamal_pubkey,
102-
auditor_elgamal_pubkey,
103102
supply_elgamal_keypair.pubkey(),
103+
auditor_elgamal_pubkey,
104104
&mint_amount_grouped_ciphertext_lo.0,
105105
&mint_amount_grouped_ciphertext_hi.0,
106106
mint_amount_lo,

confidential-transfer/proof-tests/tests/proof_test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ fn test_burn_validity(spendable_balance: u64, burn_amount: u64) {
288288
burn_amount,
289289
&source_keypair,
290290
&aes_key,
291-
Some(auditor_pubkey),
292291
supply_pubkey,
292+
Some(auditor_pubkey),
293293
)
294294
.unwrap();
295295

program/src/extension/confidential_mint_burn/account_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ impl BurnAccountInfo {
201201
burn_amount,
202202
source_elgamal_keypair,
203203
aes_key,
204-
auditor_elgamal_pubkey,
205204
supply_elgamal_pubkey,
205+
auditor_elgamal_pubkey,
206206
)
207207
.map_err(|e| -> TokenError { e.into() })
208208
}

program/src/extension/confidential_mint_burn/processor.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,11 @@ fn process_confidential_mint(
260260
&current_supply,
261261
&proof_context
262262
.mint_amount_ciphertext_lo
263-
.try_extract_ciphertext(2)
263+
.try_extract_ciphertext(1)
264264
.map_err(|_| ProgramError::InvalidAccountData)?,
265265
&proof_context
266266
.mint_amount_ciphertext_hi
267-
.try_extract_ciphertext(2)
267+
.try_extract_ciphertext(1)
268268
.map_err(|_| ProgramError::InvalidAccountData)?,
269269
)
270270
.ok_or(TokenError::CiphertextArithmeticFailed)?;
@@ -395,11 +395,11 @@ fn process_confidential_burn(
395395
&current_supply,
396396
&proof_context
397397
.burn_amount_ciphertext_lo
398-
.try_extract_ciphertext(2)
398+
.try_extract_ciphertext(1)
399399
.map_err(|_| ProgramError::InvalidAccountData)?,
400400
&proof_context
401401
.burn_amount_ciphertext_hi
402-
.try_extract_ciphertext(2)
402+
.try_extract_ciphertext(1)
403403
.map_err(|_| ProgramError::InvalidAccountData)?,
404404
)
405405
.ok_or(TokenError::CiphertextArithmeticFailed)?;

0 commit comments

Comments
 (0)