Summary
The contract does not explicitly handle discrepancies in token decimals between asset
and underlying
tokens involved in swaps. This oversight can lead to calculation errors, incorrect slippage handling, and financial discrepancies during swaps.
Technical Details
The _swapUnderlyingToAsset
function performs a direct comparison of minOut
and _amount
:
This assumes that both tokens (asset
and underlying
) use the same decimal configuration. If they differ, the comparison becomes invalid, leading to potential precision mismatches.
Potential Attack Scenarios
Setup: The asset
token uses 6 decimals, while the underlying
token uses 18 decimals.
Execution: An attacker provides a minOut
value that appears valid due to mismatched decimal precision, bypassing the require(minOut > _amount)
check.
Impact: The swap executes at an unfavorable rate, reducing the strategy's profitability and harming users.
Setup: A swap involves tokens with differing decimal configurations.
Execution: Incorrect slippage calculations based on mismatched decimals result in swaps that fail or execute with excessive losses.
Impact: Attackers exploit this inconsistency to profit from manipulated slippage conditions.
Setup: Post-swap, the strategy allocates funds based on incorrect assumptions about token decimals.
Execution: Tokens are incorrectly distributed, causing financial discrepancies in the strategy’s accounting.
Impact: Misallocation affects user withdrawals and share calculations, reducing trust in the protocol.
Financial Risk: Precision errors can lead to financial losses through miscalculated swaps or fund mismanagement.
Operational Risk: Misallocation of funds post-swap affects the strategy’s ability to maintain accurate accounting and user balances.
Exploitation Risk: Attackers can exploit slippage or precision mismatches to profit at the expense of the protocol.
Before performing any calculations or comparisons, normalize token amounts to a common decimal standard:
Fetch token decimals dynamically using ERC20’s decimals()
function to ensure accurate calculations:
Ensure all calculations involving token amounts account for their respective decimal configurations. Use utility libraries or helpers to handle precision.
Deploy the contract with two tokens:
TokenA
(6 decimals) as asset
.
TokenB
(18 decimals) as underlying
.
Call _swapUnderlyingToAsset
with a minOut
value designed to bypass the require(minOut > _amount)
check due to mismatched precision.
Observe the swap executing at an unfavorable rate, reducing the protocol’s profitability.
Call _swapUnderlyingToAsset
with mismatched decimals.
Observe the function normalizing decimals and accurately enforcing the require(minOut > _amount)
condition.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.