Skip to content
Business logic Audit finding Intermediate

settle() asyncFee is left in the KeepFactory and is not transfer to the keeper

The settle() function in KeeperFactory transfers asyncFee from KeeperOracle to the factory contract but does not forward it to the keeper who called the function. As a result, the fee remains locked in the factory contract with no way to withdraw it.

bin2chen Follow with volodya

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3-judging/issues/34

Found by

bin2chen, volodya

Summary

After KeeperFactory.settle() executes successfully, asyncFee goes to the factory, not to keeper.

Root Cause

in KeeperFactory.sol:168 After keeper executes the settle() method, the asyncFee is transferred from KeeperOracle to KeeperFactory. But in the current code, KeeperFactory doesn't transfer this fee to msg.sender but leaves it in the contract and doesn't provide any method to do the transfer out

Solidity
abstract contract KeeperFactory is IKeeperFactory, Factory {
    function settle(bytes32[] memory oracleIds, uint256[] memory versions, uint256[] memory maxCounts) external {
...
        for (uint256 i; i < oracleIds.length; i++)
@>          IKeeperOracle(address(oracles[oracleIds[i]])).settle(versions[i], maxCounts[i]);
    }
Solidity
contract KeeperOracle is IKeeperOracle, Instance {

    function settle(uint256 version, uint256 maxCount) external onlyFactory {
        for (uint256 i; i < maxCount && callbacks.length() > 0; i++) {
            address account = callbacks.at(0);
            market.settle(account);
            callbacks.remove(account);
            emit CallbackFulfilled(SettlementCallback(market, account, version));

            // full settlement fee already cleamed in commit
            PriceResponse memory priceResponse = _responses[version].read();
@>          market.token().push(msg.sender, UFixed18Lib.from(priceResponse.asyncFee));
        }
    }

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

  1. Keeper call KeeperFactory.settle()
  • token transfer from : keeperOracle.sol -> KeeperFactory.sol
  1. token stay KeeperFactory.sol

Impact

asyncFee is locked in the contract.

PoC

No response

Mitigation

Diff
    function settle(bytes32[] memory oracleIds, uint256[] memory versions, uint256[] memory maxCounts) external {
        if (oracleIds.length == 0 || oracleIds.length != versions.length || oracleIds.length != maxCounts.length)
            revert KeeperFactoryInvalidSettleError();

        for (uint256 i; i < oracleIds.length; i++) 
+       {
+           Token18 rewardToken = IKeeperOracle(address(oracles[oracleIds[i]])).oracle().market().token();
+           UFixed18 balanceBefore = rewardToken.balanceOf();
            IKeeperOracle(address(oracles[oracleIds[i]])).settle(versions[i], maxCounts[i]);
+           rewardToken.push(msg.sender,rewardToken.balanceOf() - balanceBefore);
+      }
    }

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/equilibria-xyz/perennial-v2/pull/456

The original report as published on Sherlock, by bin2chen. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

The KeeperFactory.settle() function calls KeeperOracle.settle(), which sends the asyncFee to the factory contract, but the factory does not forward that fee to the caller (the keeper) and has no withdrawal function.

Impact

The asyncFee is locked in the KeeperFactory contract and cannot be recovered by the keeper.

What the attacker needed

Keeper calls settle()

The fix

The protocol team fixed this issue in a pull request.

How it was found

  1. Keeper calls KeeperFactory.settle().
  2. Tokens are transferred from KeeperOracle to KeeperFactory.
  3. Tokens remain in KeeperFactory.

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 (a bot that maintains the system) calls settle(), a fee is supposed to be paid to them for their work. Instead, the fee gets stuck in the factory contract and the keeper never receives it, so the money is effectively lost.

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.

More by bin2chen

View all

139 more disclosed reports, best first.

More from Perennial V2 Update #3

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.