Market coordinator can set proportional and adiabatic fees much higher than limited by protocol due to fixed point truncation
A market coordinator could set fee scales slightly below the allowed limit, but truncation when storing the parameters caused the actual ratio to be lower than validated, resulting in higher fees for users. This allowed charging up to 1.5 times the intended proportional or adiabatic fee.
Source: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3-judging/issues/41
Found by
panprog Summary The README states the following:
Q: 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 malicious 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
Market coordinator can set scale for takerFee or makerFee at amount significantly lower than the validated scaleLimit due to truncation when storing the parameter. This will lead to much higher proportional and adiabatic fees than max amount intended by the protocol. Example:
protocolParameter.minScale = 50%protocolParameter.minEfficiency = 100%- This means that coordinator must not set
scaleless than50%ofmakerLimit, meaning max proportional fee is 2x thetakerFee.proportionalFee - Coordinator sets risk parameter:
makerLimit = 3.9 WBTC,takerFee.scale = 1.95 WBTC, this is validated correctly (scaleis50%ofmakerLimit) - However when it's stored, both
makerLimitandtakerFee.scaleare truncated to integer numbers, storingmakerLimit = 3,takerFee.scale = 1(meaningscaleis 33% ofmakerLimit, breaking the protocol enforced ratio, and chargingx1.5higher proportional fee to takers)
Root Cause Validation before truncation: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/perennial-v2/packages/perennial/contracts/types/RiskParameter.sol#L159-L161
Truncation when storing to storage: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/perennial-v2/packages/perennial/contracts/types/RiskParameter.sol#L188
Internal pre-conditions
- Malicious market coordinator
- Market with high-price token (such as BTC),
makerLimitis not very high but still resonable (e.g.3.9 WBTCwhich is a reasonable limit of $200K+).
External pre-conditions None.
Attack Path
- Coordinator sets correct
makerLimitandscaleat the edge of allowed protocol parameter (but both slightly below integer amount) - Both
makerLimitandscalepass validation, but are truncated when stored - At this point the protocol enforced ratio is broken and actual fee charged to users is much higher (up to 1.5x) than intended by the protocol
Impact Users pay up to 1.5x higher taker/maker proportional fee or adiabatic fee
PoC Not needed.
Mitigation
Truncate both makerLimit and all scales before validating them (or do not truncate at all as more than integer precision might be required for high-price token markets)
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/equilibria-xyz/perennial-v2/pull/465
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 of fee scale against the limit is performed before truncating the values to integers for storage, so the stored ratio can be lower than the validated one.
Impact
Users could pay up to 1.5 times higher taker or maker proportional fee or adiabatic fee.
What the attacker needed
Malicious market coordinator; Market with high-price token and reasonable makerLimit
The fix
The protocol team fixed this issue in a pull request.
How it was found
- Coordinator sets makerLimit and scale at the edge of allowed protocol parameter, both slightly below integer amount.
- Both makerLimit and scale pass validation.
- Both values are truncated when stored, breaking the enforced ratio.
- The actual fee charged to users is higher than intended, up to 1.5x.
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.
A market coordinator is someone who sets fees for a trading market. The protocol checks that fees are not too high, but the check happens before the numbers are rounded down to whole numbers. So the coordinator can pick numbers that pass the check but become much smaller after rounding, making the fee ratio higher than allowed. This means users pay more fees than the protocol intends.
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.