Closed c4-bot-3 closed 9 months ago
This is valid - potential fix in https://github.com/lindy-labs/opus_contracts/pull/531.
bytes032 marked the issue as sufficient quality report
bytes032 marked the issue as primary issue
tserg (sponsor) confirmed
Duplicate of #120.
alex-ppg marked issue #143 as primary and marked this issue as a duplicate of 143
alex-ppg marked the issue as satisfactory
Lines of code
https://github.com/code-423n4/2024-01-opus/blob/4720e9481a4fb20f4ab4140f9cc391a23ede3817/src/core/shrine.cairo#L1753
Vulnerability details
Vulnerability details
in
redistribute_helper()
Two important arrays (updated_trove_yang_balances[], new_yang_totals[]) are calculated , and then updated based on these two arrays.
updated_trove_yang_balances[]
is used to update the remaining quantity of trove.new_yang_totals[]
is used to update the total remaining quantity ofyang
.For example, Assume there are ETH, BTC and trove[1] trove[1].ETH = 0 trove[1].BTC = 200 total_yang_ETH = 1000 total_yang_BTC = 2000
Execute redistribute(trove[1]), redistribute eth = 0, redistribute btc = 20
After calculation: updated_trove_yang_balances = [0,180] new_yang_totals = [1000,1980]
Then update the corresponding values based on these two arrays. An important point is that these two arrays should be of the same length and correspond one-to-one.
The main code is as follows:
The problem is that if
trove_yang_amt.is_zero()
, it will only appendupdated_trove_yang_balances[]
and will not appendnew_yang_totals[]
.This leads to the above example becoming After calculation: updated_trove_yang_balances = [0,180] new_yang_totals = [1980] (Correct should be [1000,1980])
Updating through these two arrays of different lengths will cause some not to be updated.
Modification: trove[1].eth = 0
trove[1].btc = 200 (not change , because only loop 1 time , correct should be 180)
total_yang_BTC = 1980 total_yang_ETH = 1000 (not change, new_yang_totals only have btc ,not eth)
Impact
The total balance of trove and yang is not updated correctly.
Recommended Mitigation
Assessed type
Error