ClearingHouse May Whitelist Duplicate AMMs #50
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
disagree with severity
Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments)
resolved
Finding has been patched by sponsor (sponsor pls link to PR containing fix)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/ClearingHouse.sol#L339-L342
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/ClearingHouse.sol#L269-L282
Vulnerability details
Impact
ClearingHouse.sol
allows the Governance protocol to whitelistAMM.sol
contracts. These contracts allow users to earn profits based on the price of a base asset against a quote asset.It is possible to add the same
AMM
twice in the functionwhitelistAmm()
. The impact is that unrealized profits will be counted multiple times. As a result the liquidation calculations will be incorrect, potentially allowing users to trade while insolvent or incorrectly liquidating solvent users.Note
whitelistAmm()
may only be called by Governance.Proof of Concept
The function
getTotalNotionalPositionAndUnrealizedPnl()
will iterate over allamms
summing theunrealizedPnl
andnotinoalPosition
, thus if anamm
is repeated theunrealizedPnl
andnotionalPosition
of that asset will be counted multiple times.This is used in
_calcMarginFraction()
which calculates a users margin as a fraction of the total position. The margin fraction is used to determine if a user is liquitable or is allowed to open new positions.Recommended Mitigation Steps
Consider ensuring the
AMM
does not already exist in the list when adding a newAMM
.The text was updated successfully, but these errors were encountered: