Skip to content

Commit 3450f17

Browse files
committed
Fix transfer bug
1 parent 38243dd commit 3450f17

File tree

2 files changed

+23
-47
lines changed

2 files changed

+23
-47
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ pub fn inner_empty_account(
574574
) -> Result<Instruction, ProgramError> {
575575
check_program_account(token_program_id)?;
576576
let mut accounts = vec![
577-
AccountMeta::new_readonly(*token_account, false),
577+
AccountMeta::new(*token_account, false),
578578
AccountMeta::new_readonly(sysvar::instructions::id(), false),
579579
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
580580
];

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

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,11 @@ fn process_transfer(
520520
return Err(TokenError::FeeParametersMismatch.into());
521521
}
522522

523-
// Process source account
524-
let ciphertext_lo_source = EncryptedBalance::from((
523+
let ciphertext_lo= EncryptedBalance::from((
525524
proof_data.ciphertext_lo.commitment,
526525
proof_data.ciphertext_lo.handle_source,
527526
));
528-
let ciphertext_hi_source = EncryptedBalance::from((
527+
let ciphertext_hi= EncryptedBalance::from((
529528
proof_data.ciphertext_hi.commitment,
530529
proof_data.ciphertext_hi.handle_source,
531530
));
@@ -537,27 +536,16 @@ fn process_transfer(
537536
authority_info,
538537
account_info_iter.as_slice(),
539538
&proof_data.transfer_with_fee_pubkeys.pubkey_source,
540-
ciphertext_lo_source,
541-
ciphertext_hi_source,
539+
&ciphertext_lo,
540+
&ciphertext_hi,
542541
new_source_decryptable_available_balance,
543542
)?;
544-
545-
// Process destination account (with fee)
546-
let ciphertext_lo_dest = EncryptedBalance::from((
547-
proof_data.ciphertext_lo.commitment,
548-
proof_data.ciphertext_lo.handle_source,
549-
));
550-
let ciphertext_hi_dest = EncryptedBalance::from((
551-
proof_data.ciphertext_hi.commitment,
552-
proof_data.ciphertext_hi.handle_source,
553-
));
554-
555543
process_dest_for_transfer(
556544
dest_token_account_info,
557545
mint_info,
558546
&proof_data.transfer_with_fee_pubkeys.pubkey_dest,
559-
ciphertext_lo_dest,
560-
ciphertext_hi_dest,
547+
&ciphertext_lo,
548+
&ciphertext_hi,
561549
Some(proof_data.ciphertext_fee),
562550
)?;
563551
} else {
@@ -571,44 +559,32 @@ fn process_transfer(
571559
return Err(TokenError::ConfidentialTransferElGamalPubkeyMismatch.into());
572560
}
573561

574-
// Process source account
575-
let ciphertext_lo_source = EncryptedBalance::from((
562+
let ciphertext_lo= EncryptedBalance::from((
576563
proof_data.ciphertext_lo.commitment,
577564
proof_data.ciphertext_lo.handle_source,
578565
));
579-
let ciphertext_hi_source = EncryptedBalance::from((
566+
let ciphertext_hi= EncryptedBalance::from((
580567
proof_data.ciphertext_hi.commitment,
581568
proof_data.ciphertext_hi.handle_source,
582569
));
583-
584570
process_source_for_transfer(
585571
program_id,
586572
token_account_info,
587573
mint_info,
588574
authority_info,
589575
account_info_iter.as_slice(),
590576
&proof_data.transfer_pubkeys.pubkey_source,
591-
ciphertext_lo_source,
592-
ciphertext_hi_source,
577+
&ciphertext_lo,
578+
&ciphertext_hi,
593579
new_source_decryptable_available_balance,
594580
)?;
595581

596-
// Process destination account (without fee)
597-
let ciphertext_lo_dest = EncryptedBalance::from((
598-
proof_data.ciphertext_lo.commitment,
599-
proof_data.ciphertext_lo.handle_source,
600-
));
601-
let ciphertext_hi_dest = EncryptedBalance::from((
602-
proof_data.ciphertext_hi.commitment,
603-
proof_data.ciphertext_hi.handle_source,
604-
));
605-
606582
process_dest_for_transfer(
607583
dest_token_account_info,
608584
mint_info,
609585
&proof_data.transfer_pubkeys.pubkey_dest,
610-
ciphertext_lo_dest,
611-
ciphertext_hi_dest,
586+
&ciphertext_lo,
587+
&ciphertext_hi,
612588
None,
613589
)?;
614590
}
@@ -624,14 +600,14 @@ fn process_source_for_transfer(
624600
authority_info: &AccountInfo,
625601
signers: &[AccountInfo],
626602
elgamal_pubkey_source: &EncryptionPubkey,
627-
ciphertext_lo_source: EncryptedBalance,
628-
ciphertext_hi_source: EncryptedBalance,
603+
ciphertext_lo_source: &EncryptedBalance,
604+
ciphertext_hi_source: &EncryptedBalance,
629605
new_source_decryptable_available_balance: DecryptableBalance,
630606
) -> ProgramResult {
631607
check_program_account(token_account_info.owner)?;
608+
let authority_info_data_len = authority_info.data_len();
632609
let token_account_data = &mut token_account_info.data.borrow_mut();
633610
let mut token_account = StateWithExtensionsMut::<Account>::unpack(token_account_data)?;
634-
let authority_info_data_len = authority_info.data_len();
635611

636612
Processor::validate_owner(
637613
program_id,
@@ -659,8 +635,8 @@ fn process_source_for_transfer(
659635
let new_source_available_balance = {
660636
ops::subtract_with_lo_hi(
661637
&confidential_transfer_account.available_balance,
662-
&ciphertext_lo_source,
663-
&ciphertext_hi_source,
638+
ciphertext_lo_source,
639+
ciphertext_hi_source,
664640
)
665641
.ok_or(ProgramError::InvalidInstructionData)?
666642
};
@@ -676,8 +652,8 @@ fn process_dest_for_transfer(
676652
dest_token_account_info: &AccountInfo,
677653
mint_info: &AccountInfo,
678654
elgamal_pubkey_dest: &EncryptionPubkey,
679-
ciphertext_lo_dest: EncryptedBalance,
680-
ciphertext_hi_dest: EncryptedBalance,
655+
ciphertext_lo_dest: &EncryptedBalance,
656+
ciphertext_hi_dest: &EncryptedBalance,
681657
encrypted_fee: Option<EncryptedFee>,
682658
) -> ProgramResult {
683659
check_program_account(dest_token_account_info.owner)?;
@@ -705,10 +681,10 @@ fn process_dest_for_transfer(
705681
return Err(TokenError::ConfidentialTransferElGamalPubkeyMismatch.into());
706682
}
707683

708-
let new_dest_pending_balance = ops::subtract_with_lo_hi(
684+
let new_dest_pending_balance = ops::add_with_lo_hi(
709685
&dest_confidential_transfer_account.pending_balance,
710-
&ciphertext_lo_dest,
711-
&ciphertext_hi_dest,
686+
ciphertext_lo_dest,
687+
ciphertext_hi_dest,
712688
)
713689
.ok_or(ProgramError::InvalidInstructionData)?;
714690

0 commit comments

Comments
 (0)