check expected new source ciphertext in processing confidential transfer (#3867)

This commit is contained in:
samkim-crypto 2022-12-03 14:46:02 +09:00 committed by GitHub
parent 6a8cf4f938
commit c7fbd4b69b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -585,6 +585,7 @@ fn process_transfer(
&proof_data.transfer_with_fee_pubkeys.source_pubkey,
&source_ciphertext_lo,
&source_ciphertext_hi,
&proof_data.new_source_ciphertext,
new_source_decryptable_available_balance,
)?;
@ -643,6 +644,7 @@ fn process_transfer(
&proof_data.transfer_pubkeys.source_pubkey,
&source_ciphertext_lo,
&source_ciphertext_hi,
&proof_data.new_source_ciphertext,
new_source_decryptable_available_balance,
)?;
@ -679,6 +681,7 @@ fn process_source_for_transfer(
source_encryption_pubkey: &EncryptionPubkey,
source_ciphertext_lo: &EncryptedBalance,
source_ciphertext_hi: &EncryptedBalance,
expected_new_source_available_balance: &EncryptedBalance,
new_source_decryptable_available_balance: DecryptableBalance,
) -> ProgramResult {
check_program_account(token_account_info.owner)?;
@ -719,6 +722,10 @@ fn process_source_for_transfer(
.ok_or(ProgramError::InvalidInstructionData)?
};
if new_source_available_balance != *expected_new_source_available_balance {
return Err(TokenError::ConfidentialTransferBalanceMismatch.into());
}
confidential_transfer_account.available_balance = new_source_available_balance;
confidential_transfer_account.decryptable_available_balance =
new_source_decryptable_available_balance;