Closed code423n4 closed 3 years ago
low risk: Insurance.setUnderlyingTokenPercent is set by governance and will be behind a timelock similar issue in #11, which is set to low risk, which I agree with
This requires human error to be an issue. While I agree that best practices recommend data validation, I'd imagine that governance TX would be checked 10 times before sending. I'm agreeing with sponsor, this is low risk.
Duplicate of #11
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 theunderlyingTokensPercents
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 fori = 1
:delta = 30k - 100k * 30% = 0 > 0
is false butelse
branch with0 < 0
is false as well => nothing is set Then fori = 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.