Skip to content
Access control Audit finding Intermediate

Liquidators can be tricked to operate with LiquidationPairs that were deployed using the LiquidationPairFactory but they configured the LiquidationSource as a fake malicious contract

The LiquidationPairFactory allowed anyone to create a LiquidationPair with an arbitrary malicious source contract. An attacker could trick users into swapping through such a pair, causing their input tokens to be sent to the attacker instead of the legitimate vault.

0xStalin Follow with MohammedRizwan

Originally disclosed on Code4rena

Submitted by 0xStalin, also found by MohammedRizwan

Users and Bots can be tricked into operating with LiquidationPairs that were deployed using the LiquidationPairFactory but they configured the LiquidationSource as a fake malicious contract that will allow the Liquidator’s creator to steal all the POOL tokens that were meant to be used to liquidate the Vault’s Yield.

Proof of Concept

  • So, if a LiquidationPair is created by the LiquidationPairFactory may allow malicious users to trick users who want to liquidate the Vault’s Yield to operate with a LiquidationPair who’ll end up stealing their POOL tokens (tokenIn) when swapping tokens.

  • Practical Example of how the LiquidationPair would steal the user’s assets, (Keep in mind that source is not the address of a Vault, but an arbitrary contract)

    • The fake source contract would look like this:
contract FakeSource {

  function targetOf(address _token) external view returns (address) {
    return <ContractCreatorAddress>;
  }

  function liquidate(
    address _account,
    address _tokenIn,
    uint256 _amountIn,
    address _tokenOut,
    uint256 _amountOut
  ) public virtual override returns (bool) {
    return true;
  }

}
  1. Calling LiquidationPair.target() will return source.targetOf(tokenIn), and the source contract can return any address when the targetOf() is called, so, let’s say that will return the address of its creator.
  2. So, LiquidationPair.target() will return the address of its creator, instead of returning the expected address of the PrizePool contract
  3. Calling LiquidationPair::swapExactAmount() will do some computations prior to call source.liquidate(), and the source.liquidate() can just return true not to cause the tx to be reverted.
  4. So, LiquidationPair::swapExactAmount() will basically do nothing.
  5. With the above points in mind, let’s see what would be the result of swapping using the LiquidationRouter contract
function swapExactAmountOut(
  LiquidationPair _liquidationPair,
  address _receiver,
  uint256 _amountOut,
  uint256 _amountInMax
) external onlyTrustedLiquidationPair(_liquidationPair) returns (uint256) {

  //@audit-issue => The `tokenIn` will be transferred to the address of the LiquidationPair's creator instead of the PrizePool contract (Point 1) <====== Point 1 ======>
  IERC20(_liquidationPair.tokenIn()).safeTransferFrom(
    msg.sender,
    _liquidationPair.target(),
    _liquidationPair.computeExactAmountIn(_amountOut)
  );

  //@audit-issue => This call will basically do nothing, just return a true not to cause the tx to be reverted (Point 2)  <====== Point 2 ======>
  uint256 amountIn = _liquidationPair.swapExactAmountOut(_receiver, _amountOut, _amountInMax);

  emit SwappedExactAmountOut(_liquidationPair, _receiver, _amountOut, _amountInMax, amountIn);

  return amountIn;
}

Recommended Mitigation Steps

  • Use the deployedVaults mapping of the VaultFactory contract to validate if the inputted address of the _source parameter is a valid vault supported by the Protocol.

    • Additionally, it could be a good idea to set the _tokenIn and _tokenOut by pulling the values that are already set up in the vault.
function createPair(
  ILiquidationSource _source,
- address _tokenIn,
- address _tokenOut,
  uint32 _periodLength,
  uint32 _periodOffset,
  uint32 _targetFirstSaleTime,
  SD59x18 _decayConstant,
  uint112 _initialAmountIn,
  uint112 _initialAmountOut,
  uint256 _minimumAuctionAmount
) external returns (LiquidationPair) {

+ require(VaultFactory.deployedVaults(address(_source)) == true, "_source address is not a supported Vault");
+ address _prizePool = _source.prizePool();
+ address _tokenIn = _prizePool.prizeToken();
+ address _tokenOut = address(_source);

  LiquidationPair _liquidationPair = new LiquidationPair(
    _source,
    _tokenIn,
    _tokenOut,
    _periodLength,
    _periodOffset,
    _targetFirstSaleTime,
    _decayConstant,
    _initialAmountIn,
    _initialAmountOut,
    _minimumAuctionAmount
  );

  allPairs.push(_liquidationPair);
  deployedPairs[_liquidationPair] = true;

  emit PairCreated(
    _liquidationPair,
    _source,
    _tokenIn,
    _tokenOut,
    _periodLength,
    _periodOffset,
    _targetFirstSaleTime,
    _decayConstant,
    _initialAmountIn,
    _initialAmountOut,
    _minimumAuctionAmount
  );

  return _liquidationPair;
}

Assessed type

Invalid Validation

asselstine (PoolTogether) confirmed and commented:

This is an interesting report.

There are two ways we expect liquidations to occur:

  • EOAs that interact with the LiquidationRouter. (users, off-chain bots, etc)
  • Smart Contracts that interact with the LiquidationPair directly

Smart contracts that interact with the Pair can easily assert that they received the expected tokens; so a malicious LiquidationSource would not be a problem.

However, EOAs that interact with a Pair via the LiquidationRouter would be vulnerable to this kind of attack.

This makes me think that the fix is actually to alter the LiquidationRouter so that:

  1. In swapExactAmountOut the router makes itself the recipient of the tokens.
  2. The router asserts that it has received the expected amount of tokens
  3. The router transfers to the tokens to the caller.

It costs more gas, but this change ensures that anyone who calls the router would receive the expected tokens.


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

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

Impact

Users and bots that interact with the malicious pair via the LiquidationRouter could lose their input tokens to the attacker; smart contracts that check received tokens are not affected.

What the attacker needed

Attacker can deploy a malicious contract; victim uses LiquidationRouter with the malicious pair

The fix

The LiquidationRouter should be altered so that it receives the tokens itself, asserts it received the expected amount, and then forwards them to the caller; alternatively, the factory should validate the source against deployed vaults.

How it was found

  1. Attacker deploys a fake source contract that returns the attacker's address from targetOf and returns true from liquidate.
  2. Attacker calls LiquidationPairFactory.createPair with the fake source, creating a pair that is added to deployedPairs.
  3. A user or bot is tricked into calling LiquidationRouter.swapExactAmountOut with this malicious pair.
  4. The router transfers the user's tokenIn to the address returned by target(), which is the attacker.
  5. The subsequent call to swapExactAmountOut does nothing but return true, so the transaction succeeds and the user loses funds.

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 factory contract lets anyone create a trading pair for liquidating yield. The factory did not check that the source of the pair was a real vault, so an attacker could make a fake source that redirects payments to themselves. When a user swaps through this fake pair, their tokens go to the attacker instead of the real vault.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by 0xStalin

View all

20 more disclosed reports, best first.

More from PoolTogether

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.