Closed sherlock-admin2 closed 10 months ago
Invalid, I is the price set by trusted admin used to convert base token balance to amount of equivalent quote balance and vice versa. It is presumed that the appropriate I
variable will be set to scale quote balance and base balance appropriately. You can see from this test here where DAI with 18 decimals is the base token and USDC with 6 decimals is the quote token
Additionally, since the only tokens expected to be used is stable coins, the maximum difference in decimals is 18 - 2 = 10. Since stable coins are priced almost identical to each other, I think I
being max 36e18 is more than suffiicient to prevent rounding errors and scale decimals appropriately
shealtielanz
high
All contracts using
DecimalMath.sol
for calculations will be broken for stableTokens likeUSDC
that have only6
Decimals.Summary
In the
Read.me
on the contest page for this contest it is stated that:However, the
DecimalMath
Library assumes that all tokens(Base and Quote Tokens
) will be18
decimals thereby causing massive rounding UP/DOWN issues in the amounts, reserves, and shares for Tokens likeUSDC
(which have 6 Token Decimals) when buying and selling.Vulnerability Detail
https://github.com/sherlock-audit/2023-12-dodo-gsp/blob/main/dodo-gassaving-pool/contracts/lib/DecimalMath.sol#L7C1-L12C4
The snippet above shows it works mainly for fixed point with 18 decimals. Using the
GSPFunding::buyShares()
as an instance, during the calculation of theshares
, it callsDecimalMath.divFloor()
, &DecimalMath.mulFloor()
, for calculations.It assumes that all tokens will be
18
Decimals Fixed however that is not true and will lead to incorrect calculations.https://github.com/sherlock-audit/2023-12-dodo-gsp/blob/main/dodo-gassaving-pool/contracts/GasSavingPool/impl/GSPFunding.sol#L56C7-L76C10
When calling
DecimalMath.mulFloor()
with tokens with 6 Decimals.Here the value will be under inflated(
rounded down far lower than the expected amount
). When callingDecimalMath.divFloor()
with tokens with 6 Decimals.Here the value is Over Inflated(
the value is far bigger than the expected amount
).Impact
This will lead to Incorrect shares minted to users and accounting issues in the contracts for the base and quote tokens..
Code Snippet
Tool used
Manual Review
Recommendation
use the
Tokens decimals
for the calculation rather than1e18
fixed inDecimalmath.sol
library.