The getPositionFeeUsd function in the VaultReader contract does not handle the case where the positionFeeFactor is zero, which can lead to incorrect fee calculations.
The getPositionFeeUsd function calculates the position fee in USD for a given market and size delta. It retrieves the positionFeeFactor from the dataStore and uses it to calculate the fee. However, if the positionFeeFactor is zero, the calculated fee will also be zero, which may not be the intended behavior.
Root Cause:
The root cause of this issue is the lack of a check for a zero positionFeeFactor in the getPositionFeeUsd function. The function directly uses the retrieved positionFeeFactor without verifying its validity.
If the positionFeeFactor is zero, the calculated position fee will be zero, potentially leading to incorrect fee calculations and loss of revenue for the protocol. This can occur if the positionFeeFactor is set to zero during updates or if it is not properly initialized.
Manual
To mitigate this issue, add a check for a zero positionFeeFactor in the getPositionFeeUsd function. If the positionFeeFactor is zero, revert the transaction or set a default minimum fee.
Example of improved getPositionFeeUsd function:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.