Removing markets from WildcatArchController gives lenders immunity from sanctions
Lines of code
https://github.com/code-423n4/2023-10-wildcat/blob/main/src/WildcatSanctionsSentinel.sol#L95-L102
Vulnerability details
Bug Description
In WildcatSanctionsSentinel.sol, the createEscrow() function checks that msg.sender is a registered market in the WildcatArchController contract:
WildcatSanctionsSentinel.sol#L95-L102
solidityfunction createEscrow( address borrower, address account, address asset ) public override returns (address escrowContract) { if (!IWildcatArchController(archController).isRegisteredMarket(msg.sender)) { revert NotRegisteredMarket(); }
This is meant to ensure that createEscrow() can only be called by markets deployed by the protocol, since they are registered using registerMarket().
However, such an implementation does not account for markets that are removed using the removeMarket() function.
If a market is removed, it should still be able to operate normally as a registered market would. However, due to the check shown above, any function that calls createEscrow() will always revert for removed markets, namely nukeFromOrbit() and executeWithdrawal() when they are called for sanctioned lenders.
Impact
If a market is removed, lenders that are sanctioned on Chainalysis cannot be blocked using nukeFromOrbit() since the function will always revert.
This is problematic as sanctioned addresses will still be able to interact with the market in various ways, such as transferring market tokens, making deposits or calling queueWithdrawal(), when they should not be able to.
Sanctioned lenders will also be unable to call executeWithdrawal() to withdraw their assets from the market into their own escrows.
Proof of Concept
The following test demonstrates how nukeFromOrbit() and executeWithdrawal() will revert for sanctioned lenders when a market is removed from the WildcatArchController contract:
solidity// SPDX-License-Identifier: MIT pragma solidity >=0.8.20; import 'src/WildcatSanctionsSentinel.sol'; import 'src/WildcatArchController.sol'; import 'src/WildcatMarketControllerFactory.sol'; import 'src/interfaces/IWildcatSanctionsSentinel.sol'; import 'forge-std/Test.sol'; import 'test/shared/TestConstants.sol'; import 'test/helpers/MockERC20.sol'; contract CreateEscrowTest is Test { // Wildcat contracts WildcatSanctionsSentinel sentinel; WildcatArchController archController; WildcatMarketControllerFactory controllerFactory; WildcatMarketController controller; WildcatMarket market; // Test contracts MockChainalysis chainalysis = new MockChainalysis(); MockERC20 asset = new MockERC20(); // Users address AIKEN; address DUEET; function setUp() external { // Deploy Wildcat contracts archController = new WildcatArchController(); sentinel = new WildcatSanctionsSentinel(address(archController), address(chainalysis)); MarketParameterConstraints memory constraints = MarketParameterConstraints({ minimumDelinquencyGracePeriod: MinimumDelinquencyGracePeriod, maximumDelinquencyGracePeriod: MaximumDelinquencyGracePeriod, minimumReserveRatioBips: MinimumReserveRatioBips, maximumReserveRatioBips: MaximumReserveRatioBips, minimumDelinquencyFeeBips: MinimumDelinquencyFeeBips, maximumDelinquencyFeeBips: MaximumDelinquencyFeeBips, minimumWithdrawalBatchDuration: MinimumWithdrawalBatchDuration, maximumWithdrawalBatchDuration: MaximumWithdrawalBatchDuration, minimumAnnualInterestBips: MinimumAnnualInterestBips, maximumAnnualInterestBips: MaximumAnnualInterestBips }); controllerFactory = new WildcatMarketControllerFactory( address(archController), address(sentinel), constraints ); // Register controllerFactory in archController archController.registerControllerFactory(address(controllerFactory)); // Setup Aiken and register him as borrower AIKEN = makeAddr("AIKEN"); archController.registerBorrower(AIKEN); // Setup Dueet and give him some asset token DUEET = makeAddr("DUEET"); asset.mint(DUEET, 1000e18); // Deploy controller and market for Aiken vm.prank(AIKEN); (address _controller, address _market) = controllerFactory.deployControllerAndMarket( "Market Token", "MKT", address(asset), type(uint128).max, MaximumAnnualInterestBips, MaximumDelinquencyFeeBips, MaximumWithdrawalBatchDuration, MaximumReserveRatioBips, MaximumDelinquencyGracePeriod ); controller = WildcatMarketController(_controller); market = WildcatMarket(_market); } function test_removingMarketDOSCreateEscrow() public { // Register Dueet as lender address[] memory arr = new address[](1); arr[0] = DUEET; vm.prank(AIKEN); controller.authorizeLenders(arr); // Dueet becomes a lender in the market vm.startPrank(DUEET); asset.approve(address(market), 1000e18); market.depositUpTo(1000e18); // Queue withdrawal for Dueet market.queueWithdrawal(500e18); vm.stopPrank(); // Time passes until the withdrawal expires skip(MaximumWithdrawalBatchDuration); // Dueet becomes sanctioned chainalysis.sanction(DUEET); // Market get removes from archController archController.removeMarket(address(market)); // nukeFromOrbit() reverts for Dueet vm.expectRevert(IWildcatSanctionsSentinel.NotRegisteredMarket.selector); market.nukeFromOrbit(DUEET); // executeWithdrawal() also reverts for Dueet vm.expectRevert(IWildcatSanctionsSentinel.NotRegisteredMarket.selector); market.executeWithdrawal(DUEET, uint32(block.timestamp)); } } contract MockChainalysis { mapping(address => bool) public isSanctioned; function sanction(address addr) external { isSanctioned[addr] = true; } }
Recommended Mitigation
Consider implementing a way to track removed markets in WildcatArchController. For example, a new EnumerableSet named _removedMarkets could be added.
This can be used to allow removed markets to call createEscrow() as such:
WildcatSanctionsSentinel.sol#L95-L102
difffunction createEscrow( address borrower, address account, address asset ) public override returns (address escrowContract) { - if (!IWildcatArchController(archController).isRegisteredMarket(msg.sender)) { + if (!IWildcatArchController(archController).isRegisteredMarket(msg.sender) && !IWildcatArchController(archController).isRemovedMarket(msg.sender)) { revert NotRegisteredMarket(); }
Assessed type
Invalid Validation
