Platform: Code4rena
Start Date: 16/11/2021
Pot Size: $30,000 USDC
Total HM: 3
Participants: 18
Period: 3 days
Judge: leastwood
Total Solo HM: 2
Id: 56
League: ETH
Rank: 2/18
Findings: 1
Award: $7,515.15
🌟 Selected for report: 1
🚀 Solo Findings: 1
🌟 Selected for report: harleythedog
7515.1539 USDC - $7,515.15
harleythedog
Within CDP.sol (https://github.com/code-423n4/2021-11-yaxis/blob/main/contracts/v3/alchemix/libraries/alchemist/CDP.sol) there is a function called update. This function slowly decreases the debt of a position as yield is earned, until the debt is fully paid off, and the idea is then that the credit should begin incrementing as more yield is accumulated. However, the current logic to increment the totalCredit is this line of code (line 39 of CDP.sol):
_self.totalCredit = _earnedYield.sub(_currentTotalDebt);
Notice that that each time update is called, this overwrites the previous totalCredit with the incremental credit accumulated. The line should instead be:
_self.totalCredit = _self.totalCredit.add(_earnedYield.sub(_currentTotalDebt));
Indeed, look at the function getUpdatedTotalCredit
, it returns the value:
_self.totalCredit + (_unclaimedYield - _currentTotalDebt);
So it is obviously intended that the totalCredit should keep increasing over time instead of being overwritten on each update with a small value. The impact of this issue is large - the credit of every position will always be overwritten and the correct information will be lost forever. User's credit should grow over time, but instead it is overwritten with a small value every time update is called.
See line 39 in CDP.sol here: https://github.com/code-423n4/2021-11-yaxis/blob/main/contracts/v3/alchemix/libraries/alchemist/CDP.sol#:~:text=_self.totalCredit%20%3D%20_earnedYield.sub(_currentTotalDebt)%3B
Manual inspection.
Change code as described above to increment totalCredit instead of overwrite it.
#0 - Xuefeng-Zhu
2021-12-03T07:28:37Z
If there is debt, the credit should be zero
#1 - 0xleastwood
2021-12-21T07:38:13Z
It seems like if _self.totalDebt
is already zero and yield has been earned by the protocol, _self.totalCredit
will be overwritten. This doesn't seem ideal, could you clarify why the issue is incorrect?
#2 - 0xleastwood
2021-12-21T07:40:11Z
If I'm not mistaken, yield can be earned from a positive credit (net 0 debt) position.
#3 - Xuefeng-Zhu
2021-12-22T08:32:45Z
@0xleastwood totalCredit
is 0 if there is debt
#4 - 0xleastwood
2021-12-22T22:41:48Z
After chatting to @Xuefeng-Zhu in Discord, he was able to confirm the issue as valid. So keeping it as is.