Closed c4-bot-8 closed 8 months ago
gzeon-c4 marked the issue as sufficient quality report
gzeon-c4 marked the issue as primary issue
yanisepfl (sponsor) disputed
The _getPTandIBTRates
allows for rounding up or down the PT rate obtained from the IBT rate change in the situation where the IBT rate has decreased, only for respecting the 5095 invariant that previewDeposit <= deposit
. In any other usage of this method, it is best to round down the PT rate derived from the IBT rate decrease.
For instance, in the important issue mentioned by the auditor, rounding down the PT rate would indeed lead to a larger amount of shares (PTs/YTs) than if we had rounded up the PT rate. However, the auditor does not take into account the value of those PT. Indeed, having more of something that is worth less (more shares, PT rate rounded down) is not necessarily worst than having less of something that is worth more (less shares, PT rate rounded up). In particular, our protocol was designed so that the protocol is always favored.
Same principle goes for the "the less important issue" reported by the auditor.
Therefore, while the following statement:
If _ptRate rounds down, shares would round up.
is correct, the auditor did not take into account the PTs worth in assets, which matters here.
This issue is therefore incorrect and we dispute it.
JustDravee marked the issue as unsatisfactory: Invalid
Lines of code
https://github.com/code-423n4/2024-02-spectra/blob/main/src/tokens/PrincipalToken.sol#L680-L693 https://github.com/code-423n4/2024-02-spectra/blob/main/src/tokens/PrincipalToken.sol#L659-L672
Vulnerability details
Impact
The rounding of
_convertIBTsToShares()
and_convertSharesToIBTs()
function is incorrect, and does not always benefit the protocol. This could result in the minting of more shares for the user than intended, disadvantaging the protocol.Bug Description
There are two rounding issues in the code:
_convertIBTsToShares()
, the more important issue, which may lead to user minting more PT/YTs than intended._convertSharesToIBTs()
, the less important issue, does not cause any main issues at the moment, but is still coded incorrectly.1.
_convertIBTsToShares()
The
_convertIBTsToShares
function is designed to convert IBTs into PT/YT shares, the_roundUp
parameter dictates the rounding direction. In scenarios where_roundUp == false
, indicating a preference for rounding down. The current implementation incorrectly passes false to the_getPTandIBTRates
function. This results in rounding down of the_ptRate
, which, upon division to calculate the share amount, leads to rounding up the final share quantity.This means even if the function is called with
_roundUp == false
, it may still round up. This discrepancy can impact the_depositIBT
function, leading it to mint an amount of shares for the user that is slightly more than what is strictly proportional, favoring the user over the protocol. This could allow users to gain additional value, which is not the intended behavior.2.
_convertSharesToIBTs()
The root cause is the same as above: the
_getPTandIBTRates
function always passes infalse
. However, since all current calls to_convertSharesToIBTs
passes in_roundUp == false
, the impact of this error is not severe. Instead, it presents itself more as a coding oversight than a critical flaw.Proof of Concept
If
_ptRate
rounds down,shares
would round up. Following is the mathematic formula:Tools Used
Manual review.
Recommended Mitigation Steps
false
to!_roundUp
for_convertIBTsToShares()
.false
to_roundUp
for_convertSharesToIBTs()
.Assessed type
Math