Underlying token percents should add up to 100% / exposure.sortVaultsByDelta
tracking does not work
#100
Labels
exposure.sortVaultsByDelta
tracking does not work
#100
Handle
cmichel
Vulnerability details
Vulnerability Details
The
Insurance.setUnderlyingTokenPercent
function sets the target allocations per vault which is used throughout the code ("delta").It does not validate that the sum of the
underlyingTokensPercents
is 100%, it could be higher or lower.If the sum is less than 100% it leads to severe issues in parts of the code, for example, it's used in
getVaultDeltaForDeposit
to get the sortedvaultIndexes
through this callexposure.sortVaultsByDelta
.However,
exposure.sortVaultsByDelta
has a bug with tracking min and max indexes if they don't add up to 100%, because theelse
branch ofminDelta
must never be taken.Example bug:
Assume:
unifiedTotalAssets = 100k
,unifiedAssets = [40k, 30k, 30k]
,targetPercents = [30%, 30%, 30%]
.Then for
i = 0
:delta = 40k - 100k * 30% = 10k > 0
=> setsmaxDelta = 10k, maxIndex = 0
Then for
i = 1
:delta = 30k - 100k * 30% = 0 > 0
is false butelse
branch with0 < 0
is false as well => nothing is setThen for
i = 2
:delta = 30k - 100k * 30% = 0 > 0
is false butelse
branch with0 < 0
is false as well => nothing is setResulting in both
maxIndex = 0
,minIndex = 0
and thusvaultIndexes = [0, 3, 0]
depositing into the first vault twice and completely skipping the others.Recommended Mitigation Steps
Validate that it adds up to 100%.
Alternatively, fix the
minDelta
andmaxDelta
starting values (0
is bad) and computation.The text was updated successfully, but these errors were encountered: