Skip to content
Access control Audit finding Intermediate

drawManager can be set to a malicious address

The PrizePool contract's setDrawManager function lacks access control, allowing anyone to set the drawManager address if it is not already set. An attacker could front-run the legitimate assignment to set a malicious drawManager, gaining control over functions like withdrawReserve and closeDraw.

Udsen Follow with catellatech, Inspecktor and 10 others

Originally disclosed on Code4rena

Submitted by Udsen, also found by catellatech, Inspecktor, squeaky_cactus, 0xPsuedoPandit, 0x11singh99, Tripathi, Nyx, Daniel526 (1, 2), namx05, Jorgect, Praise (1, 2), xuwinnie, YY, and Darwin

In the PrizePool.constructor the drawManager state variable is set as follows:

drawManager = params.drawManager;

But it accepts, even if the params.drawManager == address(0). There is no input validation for the address(0) as well.

The PrizePool.setDrawManager function is used to set the drawManager if not already set. But the problem here, is that there is no access control for this function and anyone can call this. A malicious user can front-run the valid drawManager assignment transaction and set a malicious address as the drawManager. The other issue, is once the drawManager is set, it can not be updated due to the following conditional check. Hence, the contract will have to redeployed.

if (drawManager != address(0)) { //@audit-issue - can be front run by a malicious user
  revert DrawManagerAlreadySet();
}

The following two functions controlled by the onlyDrawManager modifier will be vulnerable to attacks, since the drawManager is a malicious address now.

  1. PrizePool.withdrawReserve can withdraw tokens from the reserve to any address given in the _to parameter. Hence, this function will be vulnerable.
  2. The PrizePool.closeDraw() function can close the current open draw. This function is only callable by the drawManager function. A malicious user can get control of this function, thus making it vulnerable.

Proof of Concept

    drawManager = params.drawManager;
    if (params.drawManager != address(0)) {
      emit DrawManagerSet(params.drawManager);
    }

https://github.com/GenerationSoftware/pt-v5-prize-pool/blob/4bc8a12b857856828c018510b5500d722b79ca3a/src/PrizePool.sol#L278-L281

  function setDrawManager(address _drawManager) external {
    if (drawManager != address(0)) {
      revert DrawManagerAlreadySet();
    }
    drawManager = _drawManager;

    emit DrawManagerSet(_drawManager);
  }

https://github.com/GenerationSoftware/pt-v5-prize-pool/blob/4bc8a12b857856828c018510b5500d722b79ca3a/src/PrizePool.sol#L299-L306

  function closeDraw(uint256 winningRandomNumber_) external onlyDrawManager returns (uint16) {

https://github.com/GenerationSoftware/pt-v5-prize-pool/blob/4bc8a12b857856828c018510b5500d722b79ca3a/src/PrizePool.sol#L348

  function withdrawReserve(address _to, uint104 _amount) external onlyDrawManager {
    if (_amount > _reserve) {
      revert InsufficientReserve(_amount, _reserve);
    }
    _reserve -= _amount;
    _transfer(_to, _amount);
    emit WithdrawReserve(_to, _amount);
  }

https://github.com/GenerationSoftware/pt-v5-prize-pool/blob/4bc8a12b857856828c018510b5500d722b79ca3a/src/PrizePool.sol#L335-L342

Tools Used

VSCode

Recommended Mitigation Steps

It is recommended to check for address(0) in the constructor when drawManager is set; or to implement access control in the PrizePool.setDrawManager function, so that only the admin of the contract can call this function to set the drawManager, if it is not set already.

Assessed type

Invalid Validation

PoolTogether confirmed via discord communication

PoolTogether mitigated:

Record deployer and permission draw manager. PR: https://github.com/GenerationSoftware/pt-v5-prize-pool/pull/31

Status: Mitigation confirmed. Full details in reports from rvierdiiev, dirk_y and 0xStalin.


The original report as published on Code4rena, by Udsen. 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

Root cause

The setDrawManager function lacks access control, allowing any caller to set the drawManager if it is not already set.

Impact

The attacker could control the withdrawReserve and closeDraw functions, potentially withdrawing reserve tokens to any address and closing draws.

What the attacker needed

DrawManager not yet set; attacker can front-run transaction

The fix

The constructor should check for address(0) when setting drawManager, or setDrawManager should have access control so only an admin can call it.

How it was found

  1. The legitimate user submits a transaction to set the drawManager.
  2. An attacker sees this transaction and front-runs it by calling setDrawManager with a malicious address.
  3. The attacker's transaction is mined first, setting the drawManager to the malicious address.
  4. The legitimate transaction then reverts because drawManager is already set.

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.

In a smart contract, certain functions should only be callable by trusted addresses. Here, a function that sets an important manager address can be called by anyone, so an attacker could quickly call it first and become the manager. That would let them control actions like withdrawing funds or closing draws.

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 Udsen

View all

6 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.