SSSwap

First Flight #41
Beginner FriendlyRust
100 EXP
View results
Submission Details
Impact: medium
Likelihood: medium
Invalid

Missing Reload of Mint Account Before Accessing Decimals in `transfer_tokens`

Description:

The transfer_tokens function uses mint.decimals as an argument for the transfer_checked CPI call. However, it does not reload the mint account before accessing its data field. This can result in the use of an uninitialized or stale decimals value, which may default to zero if the account was not properly loaded. This behavior is particularly relevant when using InterfaceAccount<'info, Mint>, where account deserialization is not guaranteed unless reload() is explicitly called.

This can lead to incorrect transfer behavior, particularly for tokens with non-zero decimal precision, resulting in under- or over-transfer of tokens.


Impact:

  • Incorrect transfer amounts for tokens with decimal precision.

  • Potential financial loss for users interacting with tokens that have decimals greater than 0.

  • Silent precision bugs that are difficult to detect during normal usage or audits, potentially undermining trust in the system.


Recommendation:

Reload the mint account before accessing decimals to ensure its value is accurate:

pub fn transfer_tokens<'info>(
from: &InterfaceAccount<'info, TokenAccount>,
to: &InterfaceAccount<'info, TokenAccount>,
amount: &u64,
mint: &InterfaceAccount<'info, Mint>,
authority: &Signer<'info>,
token_program: &Interface<'info, TokenInterface>
) -> Result<()> {
mint.reload()?; // Ensure mint account is deserialized
let decimals = mint.decimals;
let transfer_account_options = TransferChecked {
from: from.to_account_info(),
mint: mint.to_account_info(),
to: to.to_account_info(),
authority: authority.to_account_info(),
};
let cpi_context = CpiContext::new(
token_program.to_account_info(),
transfer_account_options,
);
transfer_checked(cpi_context, *amount, decimals)
}
Updates

Lead Judging Commences

0xtimefliez Lead Judge 5 days ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.