Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

cducrest-brainbot - Racing condition in between repaying and liquidating a debt when repay was not allowed #5

Closed
sherlock-admin opened this issue Apr 30, 2023 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Apr 30, 2023

cducrest-brainbot

medium

Racing condition in between repaying and liquidating a debt when repay was not allowed

Summary

The selected fix to sherlock-audit/2023-02-blueberry-judging#290 was to prevent liquidation when repay is not allowed. This introduces a racing condition when repay is not allowed, positions become liquidateable, and repay is again allowed. Liquidators and position owners will race to repay / liquidate the position.

Vulnerability Detail

Both liquidation and repayment are not allowed when the admin of BlueBerryBank disables repayment:

    function liquidate(
        uint256 positionId,
        address debtToken,
        uint256 amountCall
    ) external override lock poke(debtToken) {
        if (!isRepayAllowed()) revert Errors.REPAY_NOT_ALLOWED();
        ...
    }
    function repay(
        address token,
        uint256 amountCall
    ) external override inExec poke(token) onlyWhitelistedToken(token) {
        if (!isRepayAllowed()) revert Errors.REPAY_NOT_ALLOWED();
        ...
    }

There is no means to allow repayment and prevent liquidation for a time.

Impact

While repayment is not allowed, positions can become liquidateable. When admin re-enable repayments, the owner of the position risks liquidation without having a chance to repay its position if liquidator are faster to the chain than repayer. This is highly likely as liquidator are probably automated tools while repayers are human users.

Code Snippet

https://github.com/sherlock-audit/2023-04-blueberry/blob/96eb1829571dc46e1a387985bd56989702c5e1dc/blueberry-core/contracts/BlueBerryBank.sol#L487-L492

https://github.com/sherlock-audit/2023-04-blueberry/blob/96eb1829571dc46e1a387985bd56989702c5e1dc/blueberry-core/contracts/BlueBerryBank.sol#L718-L722

Tool used

Manual Review

Recommendation

Allow reactivation of repayments without activating liquidation to give time to users to repay their position and not be liquidated. Alternatively do not disable repayments.

Duplicate of #117

@github-actions github-actions bot closed this as completed May 3, 2023
@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels May 3, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label May 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

1 participant