Closed code423n4 closed 1 year ago
GalloDaSballo marked the issue as primary issue
Most in depth
TriHaz marked the issue as sponsor confirmed
The warden has shown that a setter lacks a check and that can cause issues, ultimately because of the context of it being a admin function, I think QA - Low is more appropriate
L
Lines of code
https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/PairsContract.sol#L48-L65
Vulnerability details
Impact
When the function
addAsset
from thePairsContract
contract is called by the owner it adds a new allowed asset, but when saving asset details into storage the function doesn't check that the value of_baseFundingRate
set is less thanmaxBaseFundingRate
.So the owner can by accident (or intentionally) set a value bigger than the maximum, this will affect all the positions created in the
Trading
contract as the_updateFunding
function uses the value ofpairsContract.idToAsset(_asset).baseFundingRate
which has the same value as the_baseFundingRate
set previously.All the functions below call the
_updateFunding
function and will be affected by this issue :Proof of Concept
The issue occurs in the
addAsset
function :File: contracts/PairsContract.sol Line 48-65
As you can see from the code above there is no check on the value of
_baseFundingRate
and it's set directly.The
_updateFunding
function will fetchs the value ofbaseFundingRate
from thePairsContract
contract and sent it to thePostion
contract :File: contracts/Trading.sol Line L817-826
And in the
Postion
contract the value ofbaseFundingRate
is used to update the variablefundingDeltaPerSec
of the given asset :File: contracts/Position.sol Line 120
So because the
_updateFunding
function is called in the following functions :initiateMarketOrder
,addToPosition
,executeLimitOrder
,liquidatePosition
,_closePosition
this error will affect almost all the positions and the trading protocol in general.Tools Used
Manual review
Recommended Mitigation Steps
To avoid this issue the function
addAsset
must contain a check on the value of_baseFundingRate
, theaddAsset
function should be modified as follow :