ChainlinkFactory will pay non-requested versions keeper fees
The ChainlinkFactory contract's fee calculation ignores the number of requested versions, so it pays keeper fees for both requested and non-requested versions. An attacker could submit non-requested versions to drain the factory's fee balance, though they must include at least one requested version.
Source: https://github.com/sherlock-audit/2024-02-perennial-v2-3-judging/issues/32
Found by
bin2chen
Summary
Protocol definition: Requested versions will pay out a keeper fee, non-requested versions will not.
But ChainlinkFactory ignores numRequested, which pays for both.
Vulnerability Details
Protocol definition: Requested versions will pay out a keeper fee, non-requested versions will not.
/// @notice Commits the price to specified version
/// @dev Accepts both requested and non-requested versions.
/// Requested versions will pay out a keeper fee, non-requested versions will not.
/// Accepts any publish time in the underlying price message, as long as it is within the validity window,
/// which means its possible for publish times to be slightly out of order with respect to versions.
/// Batched updates are supported by passing in a list of price feed ids along with a valid batch update data.
/// @param ids The list of price feed ids to commit
/// @param version The oracle version to commit
/// @param data The update data to commit
function commit(bytes32[] memory ids, uint256 version, bytes calldata data) external payable {
commit()->_handleKeeperFee()->_applicableValue()
ChainlinkFactory._applicableValue () implements the following:
function _applicableValue(uint256, bytes memory data) internal view override returns (uint256) {
bytes[] memory payloads = abi.decode(data, (bytes[]));
uint256 totalFeeAmount = 0;
for (uint256 i = 0; i < payloads.length; i++) {
(, bytes memory report) = abi.decode(payloads[i], (bytes32[3], bytes));
(Asset memory fee, ,) = feeManager.getFeeAndReward(address(this), report, feeTokenAddress);
totalFeeAmount += fee.amount;
}
return totalFeeAmount;
}
The above method ignores the first parameter numRequested.
This way, whether it is Requested versions or not, you will pay keeper fees.
Violating non-requested versions will not pay
Impact
If non-requested versions will pay as well, it is easy to maliciously submit non-requested maliciously consume ChainlinkFactory fees balance
(Note that needs at least one numRequested to call _handleKeeperFee() )
Code Snippet
Tool used
Manual Review
Recommendation
It is recommended that only Requested versions keeper fees'
- function _applicableValue(uint256 , bytes memory data) internal view override returns (uint256) {
+ function _applicableValue(uint256 numRequested, bytes memory data) internal view override returns (uint256) {
bytes[] memory payloads = abi.decode(data, (bytes[]));
uint256 totalFeeAmount = 0;
for (uint256 i = 0; i < payloads.length; i++) {
(, bytes memory report) = abi.decode(payloads[i], (bytes32[3], bytes));
(Asset memory fee, ,) = feeManager.getFeeAndReward(address(this), report, feeTokenAddress);
totalFeeAmount += fee.amount;
}
- return totalFeeAmount;
+ return totalFeeAmount * numRequested / payloads.length ;
}
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
panprog commented:
valid medium, the attacker will have to commit requested along with unrequested which might not be easy to do due to competition
sherlock-admin4
The protocol team fixed this issue in the following PRs/commits: https://github.com/equilibria-xyz/perennial-v2/pull/293
sherlock-admin4
The Lead Senior Watson signed off on the fix.
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 `_applicableValue` function ignores the `numRequested` parameter and sums fees for all payloads, instead of scaling by the number of requested versions.
Impact
An attacker could drain the ChainlinkFactory's fee balance by submitting non-requested versions, but they must include at least one requested version to trigger the fee payment.
What the attacker needed
Attacker can submit price updates; must include at least one requested version
The fix
The protocol team fixed this issue by adjusting the fee calculation to only pay for requested versions.
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 smart contract is supposed to pay a small fee only when someone requests a price update. But a mistake in the code makes it pay the fee even for updates that were not requested. An attacker could abuse this to waste the contract's funds by submitting many unrequested updates.
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.