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

Commit b410945

Browse files
authored
token-2022: [OS-SPL-ADV-03] Check account mint in approve (#5901)
* token-2022: [OS-SPL-ADV-03] Check account mint in approve * Address review feedback
1 parent 6ed80b3 commit b410945

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,64 @@ async fn confidential_transfer_configure_token_account() {
306306
);
307307
}
308308

309+
#[tokio::test]
310+
async fn confidential_transfer_fail_approving_account_on_wrong_mint() {
311+
let authority = Keypair::new();
312+
let auto_approve_new_accounts = false;
313+
let auditor_elgamal_keypair = ElGamalKeypair::new_rand();
314+
let auditor_elgamal_pubkey = (*auditor_elgamal_keypair.pubkey()).into();
315+
316+
let mut context_a = TestContext::new().await;
317+
context_a
318+
.init_token_with_mint(vec![
319+
ExtensionInitializationParams::ConfidentialTransferMint {
320+
authority: Some(authority.pubkey()),
321+
auto_approve_new_accounts,
322+
auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey),
323+
},
324+
])
325+
.await
326+
.unwrap();
327+
328+
let token_a_context = context_a.token_context.unwrap();
329+
330+
let mut context_b = TestContext {
331+
context: context_a.context.clone(),
332+
token_context: None,
333+
};
334+
context_b
335+
.init_token_with_mint(vec![
336+
ExtensionInitializationParams::ConfidentialTransferMint {
337+
authority: Some(authority.pubkey()),
338+
auto_approve_new_accounts,
339+
auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey),
340+
},
341+
])
342+
.await
343+
.unwrap();
344+
let TokenContext { token, alice, .. } = context_b.token_context.unwrap();
345+
let alice_meta = ConfidentialTokenAccountMeta::new(&token, &alice, None, false, false).await;
346+
347+
let err = token_a_context
348+
.token
349+
.confidential_transfer_approve_account(
350+
&alice_meta.token_account,
351+
&authority.pubkey(),
352+
&[&authority],
353+
)
354+
.await
355+
.unwrap_err();
356+
assert_eq!(
357+
err,
358+
TokenClientError::Client(Box::new(TransportError::TransactionError(
359+
TransactionError::InstructionError(
360+
0,
361+
InstructionError::Custom(TokenError::MintMismatch as u32)
362+
)
363+
)))
364+
);
365+
}
366+
309367
#[tokio::test]
310368
async fn confidential_transfer_enable_disable_confidential_credits() {
311369
let authority = Keypair::new();

token/program-2022/src/extension/confidential_transfer/processor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ fn process_approve_account(accounts: &[AccountInfo]) -> ProgramResult {
171171
let token_account_data = &mut token_account_info.data.borrow_mut();
172172
let mut token_account = StateWithExtensionsMut::<Account>::unpack(token_account_data)?;
173173

174+
if *mint_info.key != token_account.base.mint {
175+
return Err(TokenError::MintMismatch.into());
176+
}
177+
174178
check_program_account(mint_info.owner)?;
175179
let mint_data = &mint_info.data.borrow_mut();
176180
let mint = StateWithExtensions::<Mint>::unpack(mint_data)?;

0 commit comments

Comments
 (0)