Skip to content
Access control Audit finding Intermediate

Lenders can escape the blacklisting of their accounts because they can move their MarketTokens to different accounts and gain the WithdrawOnly Role on any account they want

A lender whose account is sanctioned can transfer their MarketTokens to other accounts and then call a function to grant those accounts the WithdrawOnly role, allowing them to withdraw funds despite the sanction. This lets them escape the blacklisting.

0xStalin Follow with elprofesor, Infect3d and 23 others

Originally disclosed on Code4rena

Submitted by 0xStalin, also found by elprofesor, Infect3d, serial-coder, xeros, radev_sw, jasonxiale, ast3ros, QiuhaoLi, Fulum, TrungOre (1, 2), SandNallani (1, 2), SovaSlava, kodyvim, 0xbepresent, Eigenvectors, 3docSec, marqymarq10, ayden, HChang26, cu5t0mpeo (1, 2), 0xCiphky (1, 2), rvierdiiev (1, 2), nobody2018, YusSecurity, gizzy, nisedo, bdmcbri, ZdravkoHr, 0xComfyCat, and max10afternoon

Lenders can escape the sanctioning of their account in any market.

Proof of Concept

Before diving into the details of how the lenders can escape the sanctioning of their account, first, let’s analyze how a lender can be excised from a Market:

  • When someone calls nukeFromOrbit within that market while flagged as sanctioned by the Chainanalysis oracle.
  • When the lender invokes executeWithdrawal while flagged as sanctioned by the Chainalysis oracle

In either of the two options, the execution flow calls the Sentinel::isSanctioned() function to verify if the account(lender) is sanctioned by the borrower of the market

  • By analyzing the Sentinel::isSanctioned() function, it can be noted that the lender’s account must have been sanctioned in the Oracle first before the account is finally sanction in a Market.

WildcatSanctionsSentinel.sol

  function isSanctioned(address borrower, address account) public view override returns (bool) {
    //@audit-info => sanctionOverrides[borrower][account] must be false <==> sanction must not be overridden for this function to return true!
    //@audit-info => If sanctionOverrides[borrower][account] is set to true, this function will return false, as if the account would not be sanctioned

    //@audit-info => For this function to return true, the account's sanction should have not been overridden (it's set to false), and the account must have been sanctioned in the ChainalysisSanctionsList Oracle.
    return
      !sanctionOverrides[borrower][account] &&
      IChainalysisSanctionsList(chainalysisSanctionsList).isSanctioned(account);
  }

Now, based on the previous explanation, we know that the lender’s account needs to be sanctioned in the Chainalysis Oracle before the Sentinel::isSanctioned() function is called.

This opens up the doors for lenders who realize that their account has been sanctioned in the Chainalysis Oracle to move their MarketTokens to different accounts before the lender’s account is fully blocked in the Market. You may be wondering what’s the point of transferring tokens to accounts that have not been granted any role in the Market, I’ll explain more about this shortly.

The lender transfers their MarketTokens to different accounts using the WildcatMarketToken::transfer() function. As a result, the lender’s account that is sanctioned in the Chainalysis Oracle has no MarketTokens anymore; all those tokens have been moved to other accounts.

Now, at this point, anybody could call the nukeFromOrbit() function to fully sanction the lender’s account in a specific Market. Ether way, the Lender has already moved their tokens to other accounts.

At this point, the lender’s MarketTokens were distributed among different accounts of their own. Such accounts have never interacted with the Market, so their current role is the Null Role.

Everything might look fine because the accounts where the tokens were sent have no permissions to interact with the Market, but there is a bug that allows lenders to gain the WithdrawOnly Role on any account they want, without having the consent of the borrower.

This problem is located in the WildcatMarketController::updateLenderAuthorization() function. The reason of this problem will be explained in the below code walkthrough:

In short, the Lender will be able to set the WithdrawOnly Role to any account they wish. The reason is that any account that is not registered in the _authorizedLenders variable of the Controller will forward the value of _isAuthorized as false. In the WildMarketConfig::updateAccountAuthorization() function, because the value of _isAuthorized is false, it will end up granting the WithdrawOnly Role. This effectively allows any Lender to grant the WithdrawOnly Role to any account they want to.

WildcatMarketController.sol

  //@audit-info => Anybody can call this function and pass a lender and an array of markets where the changes will be applied!
  function updateLenderAuthorization(address lender, address[] memory markets) external {
    for (uint256 i; i < markets.length; i++) {
      address market = markets[i];
      if (!_controlledMarkets.contains(market)) {
        revert NotControlledMarket();
      }
      //@audit-info => Forwards the value of the `lender` argument, and depending on the `lender` address is found in the _authorizedLenders EnumerableSet.AddressSet, will be forwarded a true or false accordingly
        //@audit => If the lender address is not found in the _authorizedLenders variable, it will forward a false to the Market::updateAccountAuthorization() function
      WildcatMarket(market).updateAccountAuthorization(lender, _authorizedLenders.contains(lender));
    }
  }

EnumerableSet.sol

function contains(AddressSet storage set, address value) internal view returns (bool) {
    //@audit-info => Calls the internal _contains()
    //@audit-info => If the given value is found it will return true, otherwise it will return false!
    return _contains(set._inner, bytes32(uint256(uint160(value))));
}

//@audit-info => The internal function will just return a true or false if the given value is in the set or not, but the tx won't be reverted!
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
    return set._indexes[value] != 0;
}

WildcatMarketConfig.sol

  function updateAccountAuthorization(
    address _account,
    //@audit-info => For any account that is not registered in the `_authorizedLenders` of the Controller, this flag was set as false!
    bool _isAuthorized
  ) external onlyController nonReentrant {
    MarketState memory state = _getUpdatedState();
    //@audit-info => If the accountAddress is not registered in the storage, the approval role is set to Null
    //@audit-info => If the account has been blacklisted, tx will revert!
    Account memory account = _getAccount(_account);
    if (_isAuthorized) {
      account.approval = AuthRole.DepositAndWithdraw;

    //@audit => Any account not registered in the Controller will be assigned the WithdrawOnly role.
    } else {
      account.approval = AuthRole.WithdrawOnly;
    }
    _accounts[_account] = account;
    _writeState(state);
    emit AuthorizationStatusUpdated(_account, account.approval);
  }

At this point, the Lender has been able to move their MarketTokens to different accounts and to grant the WithdrawOnly Role to all of the accounts they wish to.

Now, they can decide to exit the Market by queuing and executing some withdrawal requests from the different accounts where the MarketTokens were moved. Any of those accounts have now the WithdrawOnly Role and have a balance of MarketTokens, so the Lender will be able to exit the market from any of those accounts.

Recommended Mitigation Steps

The mitigation for this problem is very straight-forward, by limiting the access to which entities can call the WildcatMarketController::updateLenderAuthorization() function; either only allow the Borrower to call it, or create a type of whitelist of valid actors who are capable of updating the lender’s authorization on the Markets. In this way, the Lenders won’t be capable of granting the WithdrawOnly Role to any account they want to; thus, they won’t be able even to attempt to escape the sanctions.

WildcatMarketController.sol

- function updateLenderAuthorization(address lender, address[] memory markets) external {
+ function updateLenderAuthorization(address lender, address[] memory markets) external onlyAuthorizedEntities(){
    for (uint256 i; i < markets.length; i++) {
      address market = markets[i];
      if (!_controlledMarkets.contains(market)) {
        revert NotControlledMarket();
      }
      WildcatMarket(market).updateAccountAuthorization(lender, _authorizedLenders.contains(lender));
    }
  }

modifier onlyAuthorizedEntities() {
    require(msg.sender == <authorizedEntities>, "you are not allowed sir");
    _;
}

Assessed type

Context

0xTheC0der (judge) increased severity to High

laurenceday (Wildcat) commented:

Mitigated here.

laurenceday (Wildcat) confirmed


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

Root cause

The function updateLenderAuthorization is callable by anyone and sets the WithdrawOnly role for any account not in the authorized lenders set, without checking if the caller is allowed.

Impact

A sanctioned lender could withdraw their funds from the market, defeating the purpose of the sanction.

What the attacker needed

Lender's account is sanctioned; lender has MarketTokens; lender can call updateLenderAuthorization

How it was found

  1. The lender's account is sanctioned in the Chainalysis oracle.
  2. The lender transfers their MarketTokens to other accounts using the transfer function.
  3. Anyone calls nukeFromOrbit to sanction the lender's original account, but the tokens are already moved.
  4. The lender calls updateLenderAuthorization for each new account, which grants them the WithdrawOnly role.
  5. The lender queues and executes withdrawals from those accounts to exit the market.

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 lending system, if an account is sanctioned (blocked), it should not be able to withdraw its tokens. However, the code lets anyone mark any account as 'WithdrawOnly', which means that account can withdraw. So a sanctioned lender can move tokens to fresh accounts and then mark those accounts as WithdrawOnly, bypassing the block.

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 The Wildcat Protocol

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.