Skip to content
Business logic Audit finding Intermediate

Owner of Denied Position is not able to withdraw collateral until expiry

When a position is denied, its cooldown is set to the expiry time, and the noCooldown modifier prevents the owner from withdrawing collateral until that time. This locks the owner's funds for a potentially long period.

yellowBirdy Follow with carrotsmuggler, Norah and 3 others

Originally disclosed on Code4rena

Submitted by yellowBirdy, also found by carrotsmuggler, Norah, ChrisTina, BenRai, and GreedyGoblin

Lines of code

https://github.com/code-423n4/2023-04-frankencoin/blob/1022cb106919fba963a89205d3b90bf62543f68f/contracts/Position.sol#L112 https://github.com/code-423n4/2023-04-frankencoin/blob/1022cb106919fba963a89205d3b90bf62543f68f/contracts/Position.sol#L263 https://github.com/code-423n4/2023-04-frankencoin/blob/1022cb106919fba963a89205d3b90bf62543f68f/contracts/Position.sol#L373-L376

Vulnerability details

Denying a position puts it into perma cooldown state ie. cooldown ends at expiry. It’s impossible to withdraw collateral in the cooldown state.

Impact

Locks owner funds until expiry, expiry time is not capped and can be expected to be long. There is no benefit to the owner to set it shorter and be forced to repay the position at an inconvenient time. Hence a high risk exists to lock the collateral semi permanently

Proof of Concept

Consider owner trying to call withdrawCollateral on a denied position

    function deny(address[] calldata helpers, string calldata message) public {
        if (block.timestamp >= start) revert TooLate();
        IReserve(zchf.reserve()).checkQualified(msg.sender, helpers);
        cooldown = expiration; // since expiration is immutable, we put it under cooldown until the end
        emit PositionDenied(msg.sender, message);
    }

    function withdrawCollateral(address target, uint256 amount) public onlyOwner noChallenge noCooldown {
        uint256 balance = internalWithdrawCollateral(target, amount);
        checkCollateral(balance, price);
    }

    modifier noCooldown() {
        if (block.timestamp <= cooldown) revert Hot();
        _;
    }
  1. Successful call all to deny will set cooldown = expiry
  2. Subsequent call to withdrawCollateral will be reverted by noCooldown modifier

Recommended Mitigation Steps

Return the collateral to the owner at the end of deny

    function deny(address[] calldata helpers, string calldata message) public {
        if (block.timestamp >= start) revert TooLate();
        IReserve(zchf.reserve()).checkQualified(msg.sender, helpers);
        cooldown = expiration; // since expiration is immutable, we put it under cooldown until the end
        internalWithdrawCollateral(owner, IERC20(collateral).balanceOf(address(this)));
        emit PositionDenied(msg.sender, message);
    }

0xA5DF (lookout) commented:

Might be a design choice, will leave open for sponsor to comment. Severity should be medium since funds aren’t lost but are locked for some period of time.

luziusmeisser (Frankencoin) confirmed and commented:

Excellent point! This is not intended and will be addressed. The owner of a denied position should be allowed to withdraw their collateral. Severity high is ok due to the high likelihood of this happening to innocent users, even though it is not a real loss of assets.

hansfriese (judge) decreased severity to Medium


The original report as published on Code4rena, by yellowBirdy. 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 deny function sets cooldown to expiration, and withdrawCollateral is blocked by the noCooldown modifier while block.timestamp <= cooldown.

Impact

The owner's collateral is locked until expiry, which could be a long time, though the funds are not lost.

What the attacker needed

A position that can be denied; someone calls deny on the position

The fix

The collateral should be returned to the owner at the end of the deny function.

How it was found

  1. Call deny on a position, which sets cooldown to expiration.
  2. Attempt to call withdrawCollateral, which reverts due to the noCooldown modifier.

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 this smart contract, a position owner can be denied by others, which starts a cooldown. The cooldown is set to last until the position expires, and during that time the owner cannot withdraw their collateral. So their funds are stuck until expiry.

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 from Frankencoin

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.