The `RiskParameter.liquidationFee` variable is not treated and validated as a percentage value, leading to breaking protocol invariants
The liquidationFee parameter was changed from a fixed amount to a percentage but was still validated against fixed-value protocol parameters, allowing a coordinator to set a liquidation fee that exceeds the intended maximum. This could let a malicious coordinator extract excessive fees from liquidated accounts, potentially causing bad debt.
Source: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3-judging/issues/69
Found by
eeyore
Summary
In Perennial v2.2, the RiskParameter.liquidationFee variable held a fixed amount. In Perennial v2.3, it became a percentage value. However, this change is not fully reflected in the code.
In RiskParameterStorageLib, it is incorrectly validated and compared to fixed values from the ProtocolParameter struct, leading to incorrect assumptions, particularly regarding the protocol-wide maxFeeAbsolute setting, as well as per-market minMaintenance values.
Vulnerability Detail
As stated in the README in the section, "Please list any known issues and explicitly state the acceptable risks for each known issue.":
Coordinators are given broad control over the parameters of the markets they coordinate. The protocol parameter is designed to prevent situations where parameters are set to maliciously steal funds. If the coordinator can operate within the bounds of reasonable protocol parameters to negatively affect markets, we would like to know about it.
There is theoretically no limitation on the liquidationFee value. The liquidation fee that can be paid by the account can exceed the maxFeeAbsolute value, breaking assumptions and negatively affecting the markets.
For example, if the maxFeeAbsolute value is set to $50, then the liquidationFee can be up to 5000% of the settlement fee, calculated using this equation:
File: VersionLib.sol
246: function _accumulateLiquidationFee(
247: Version memory next,
248: VersionAccumulationContext memory context
249: ) private pure returns (UFixed6 liquidationFee) {
250: liquidationFee = context.toOracleVersion.valid ?
251:@> context.toOracleReceipt.settlementFee.mul(context.riskParameter.liquidationFee) :
252: UFixed6Lib.ZERO;
Here are the places where the liquidationFee percentage value is incorrectly validated against fixed values:
File: RiskParameter.sol
139: if (self.liquidationFee.gt(protocolParameter.maxFeeAbsolute)) revert RiskParameterStorageInvalidError();
File: RiskParameter.sol
155: if (self.minMaintenance.lt(self.liquidationFee)) revert RiskParameterStorageInvalidError();
Impact
- Coordinators can negatively affect markets while operating within the bounds of reasonable protocol parameters.
Code Snippet
https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/perennial-v2/packages/perennial/contracts/types/RiskParameter.sol#L32-L33
https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/perennial-v2/packages/perennial/contracts/types/RiskParameter.sol#L139
https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/perennial-v2/packages/perennial/contracts/types/RiskParameter.sol#L155
https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/perennial-v2/packages/perennial/contracts/libs/VersionLib.sol#L250-L252
Tool Used
Manual Review
Recommendation
The protocol-wide maxFeeAbsolute value needs to be enforced across the markets. The liquidationFee should be validated as a percentage value.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/equilibria-xyz/perennial-v2/pull/459
panprog
The fix has removed the requirement of minMaintenance >= liquidationFee, which opens up the following attack scenario for the Coordinator:
- set
minMaintenance = minMargin = 0 - set
liquidationFee = protocol.maxLiquidationFee, settlement - open a lot of tiny positions with collateral at almost 0 + settlement fee
- either wait or intentionally make positions liquidatable and liquidate them, getting the liquidation fee, which is higher than settlement fee used to open it, so it's profitable
- all tiny position accounts are in bad debt due to liquidation fee being higher than their remaining collateral.
Recommendation: add the requirement for minMaintenance. Not sure if the settlement fee is available at that point (in risk parameter validation), if not, then introduce a minMaintenance and/or minMargin protocol parameter.
arjun-io
Thanks for outlining this attack vector @panprog - we're going to skip the fix for this malicious coordinator case for this audit but we'll circle back on it for future updates.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, the validation logic was not updated when liquidationFee changed from a fixed amount to a percentage, so it was incorrectly compared to fixed-value protocol parameters.
Impact
A coordinator could set a liquidation fee that exceeds the protocol's intended maximum, potentially extracting excessive fees and causing accounts to go into bad debt.
What the attacker needed
Coordinator role
The fix
The issue was fixed by enforcing the protocol-wide maxFeeAbsolute across markets and validating liquidationFee as a percentage, though a follow-up discussion noted a remaining attack vector that was not addressed in this audit.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In this protocol, a 'liquidation fee' is a penalty paid when a risky position is closed by someone else. The code was updated so this fee is a percentage, but the safety checks still compared it to a fixed dollar limit. That mismatch meant a market coordinator could set a very high percentage fee, potentially taking more money from users than intended.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.