MultiInvoker doesn't pay keepers refund for l1 calldata
The MultiInvoker contract did not include the L1 calldata fee in the keeper refund because it inherited from the base Kept contract, which returns zero for calldata fee. As a result, keepers might not be sufficiently incentivised to execute orders.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-10-perennial-judging/issues/22
Found by
rvierdiiev
Summary
MultiInvoker doesn't pay keepers refund for l1 calldata, as result keepers can be not incentivized to execute orders.
Vulnerability Detail
MultiInvoker contract allows users to create orders, which then can be executed by keepers. For his job, keeper receives fee from order's creator. This fee payment is handled by _handleKeep function.
The function will call keep modifier and will craft KeepConfig which contains keepBufferCalldata, which is flat fee for l1 calldata of this call.
modifier keep(
KeepConfig memory config,
bytes calldata applicableCalldata,
uint256 applicableValue,
bytes memory data
) {
uint256 startGas = gasleft();
_;
uint256 applicableGas = startGas - gasleft();
(UFixed18 baseFee, UFixed18 calldataFee) = (
_baseFee(applicableGas, config.multiplierBase, config.bufferBase),
_calldataFee(applicableCalldata, config.multiplierCalldata, config.bufferCalldata)
);
UFixed18 keeperFee = UFixed18.wrap(applicableValue).add(baseFee).add(calldataFee).mul(_etherPrice());
_raiseKeeperFee(keeperFee, data);
keeperToken().push(msg.sender, keeperFee);
emit KeeperCall(msg.sender, applicableGas, applicableValue, baseFee, calldataFee, keeperFee);
}
This modifier should calculate amount of tokens that should be refunded to user and then raise it. We are interested not in whole modifier, but in calldata handling. To do that we call _calldataFee function. This function does nothing in the Kept contract and is overrided in the Kept_Arbitrum and Kept_Optimism.
The problem is that MultiInvoker is only one and it just extends Keept. As result his _calldataFee function will always return 0, which means that calldata fee will not be added to the refund of keeper.
Impact
Keeper will not be incentivized to execute orders.
Code Snippet
Provided above
Tool used
Manual Review
Recommendation
You need to implement 2 versions of MultiInvoker: for optimism(Kept_Optimism) and arbitrum(Kept_Arbitrum).
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
panprog commented:
invalid, I believe this is by design, the payment for order execution is fixed at the time of order placement and is paid by the user, so there is no point in calculating the calldata fee
kbrizzle
This is actually valid and something we've recently patched in our live v2.0 deployment (here).
The supplied fee in the trigger order is only a "max fee", but the paid out fee is calculated at time of execution.
panprog
Mitigation Review:
Fixed. A thing to note is that for Optimism, there should MultiInvoker_Optimism and for all the other L2 networks as well.
MLON33
Fix: https://github.com/equilibria-xyz/perennial-v2/pull/151
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
MultiInvoker inherited from the base Kept contract, whose _calldataFee function returns zero, instead of using a chain-specific version that calculates the calldata fee.
Impact
Keepers may not be incentivised to execute orders because they are not refunded for L1 calldata costs.
What the attacker needed
None
The fix
The issue was fixed by implementing chain-specific versions of MultiInvoker that correctly calculate the calldata fee.
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.
When a keeper executes an order, they get paid a fee that should cover the cost of sending the transaction, including the cost of the data (calldata) they send. In this case, the contract that calculates the fee always returned zero for the calldata part, so keepers might lose money and stop executing orders.
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.