The ThunderLoan
protocol has hard-coded the precision for fee calculations and exchange rate as 1e18
, which assumes that all tokens have 18 decimals. This is a common standard for many ERC20 tokens, but not all tokens follow this standard (USDC and ZIL for example). Tokens with a different decimal count will result in incorrect fee calculations and exchange rates when interacting with the ThunderLoan
protocol.
The fee and exchange rate calculations are exemplified in the following snippets:
The hardcoded precision can lead to significant discrepancies in value calculations for tokens with non-standard decimals. If a token has fewer than 18 decimals, the protocol may calculate fees and exchange rates that are disproportionately high, unfairly penalizing users of such tokens. Conversely, if a token has more than 18 decimals, the protocol might undercharge for its services, leading to a loss of potential revenue and unfair benefit to users of these tokens.
To resolve this issue, the protocol should dynamically adjust the precision based on the decimal count of the token in question. This can be achieved by querying the decimals()
function that many ERC20 tokens implement. Below is an example of how the getCalculatedFee
function could be adjusted to accommodate tokens with different decimals:
For the AssetToken
exchange rate updates, a similar dynamic adjustment should be made to ensure the exchange rate remains fair and accurate regardless of the token's decimals:
By making these changes, the ThunderLoan
protocol can ensure fair treatment of all tokens regardless of their decimal precision, maintain the protocol's economic balance, and prevent any potential exploits or user dissatisfaction arising from the decimal incompatibility.
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.