Skip to content
Business logic Audit finding Intermediate

It is possible to open insolvent position in Silo connector, due to missing check in borrow function

The Silo connector's borrow function did not run the solvency check that the repay function runs, so a manager could open a Silo position that was already below the protocol's minimum health factor. Such a position breaks the protocol's health-factor invariant and is easier to liquidate.

KYP Follow with KupiaSec, Weed0607 and 6 others

Originally disclosed on Code4rena

Submitted by KYP, also found by KupiaSec, Weed0607, pkqs90, AlexCzm, ladboy233, Bigsam, BenRai (1, 2), 0xAlix2, and Tigerfrake

SiloConnector

NOYA uses Connectors to interact with different protocols - deposit, borrow, repay, withdraw. One of the protocols is Silo through the SiloConnector.

In the code snippet below the borrow and repay functions of the SiloConnector can be seen:

    function borrow(address siloToken, address bToken, uint256 amount) external onlyManager nonReentrant {
        ISilo silo = ISilo(siloRepository.getSilo(siloToken));
        silo.borrow(bToken, amount);
        emit Borrow(siloToken, bToken, amount);
    }

...

    function repay(address siloToken, address rToken, uint256 amount) external onlyManager nonReentrant {
        ISilo silo = ISilo(siloRepository.getSilo(siloToken));
        _approveOperations(rToken, address(silo), amount);
        silo.repay(rToken, amount);
        _updateTokenInRegistry(rToken);
        if (!SolvencyV2.isSolvent(silo, address(this), minimumHealthFactor)) {
            revert IConnector_LowHealthFactor(0);
        }
        emit Repay(siloToken, rToken, amount);
    }

As can be seen in the repay() function there is a solvency check that reverts the transaction if the repay amount does not make to position solvent again.

However, this check is missing in the borrow() function which allows for a position (in Silo) to be opened that is insolvent (according to the NOYA solvency check in SolvencyV2) from the start.

Root Cause

Missing Validation

Impact

Breaks protocol invariant of minimum health factor and also the position is easier to get liquidated.

Proof of Concept

Add the following test to SiloConnecctor.t.sol and run with forge test --mt test_borrowAndRepay -vv.

function test_borrowAndRepay() public {
    // Get value of 1 WETH in USDC
    uint256 wethPrice = chainlinkOracle.getValue(address(WETH), address(840), 1 ether);
    console.log("weth price :", wethPrice); // 2903,25841858

    // Deal a bit more (15%) USDC than the amount of 2 ETH. Mul by 23 and div by 10 so we deposit 115% USDC per ETH - 23/2 ETH = 1.15
    uint256 _amount = wethPrice * 23 / 100 / 10; // Divide by 100 because oracle price is 8 dec and USDC is 6.
    console.log("USDC deposited:", _amount);

    _dealWhale(baseToken, address(connector), USDC_Whale, _amount);

    vm.startPrank(address(owner));

    // siloToken, deposit token, amount, open position
    connector.deposit(USDC, USDC, _amount, true);

    // siloToken, borrow token, amount
    connector.borrow(USDC, WETH, 2e18); // borrow 2 WETH in exchange for ~7000 USDC as collateral

    // Get silo repository from connector
    ISiloRepository siloRepository1 = connector.siloRepository();

    // Get USDC silo from silo repository
    ISilo silo = ISilo(siloRepository1.getSilo(USDC));

    console.log("Is Solvent: %s ", SolvencyV2.isSolvent(silo, address(connector), connector.minimumHealthFactor()));

    // siloToken, repay token, amount
    connector.repay(USDC, WETH, 1e18);

    vm.stopPrank();
}

Recommended Mitigation Steps

Add solvency check in the borrow function.

function borrow(address siloToken, address bToken, uint256 amount) external onlyManager nonReentrant {
    ISilo silo = ISilo(siloRepository.getSilo(siloToken));
    silo.borrow(bToken, amount);
+    if (!SolvencyV2.isSolvent(silo, address(this), minimumHealthFactor)) {
+        revert IConnector_LowHealthFactor(0);
+    }
    _updateTokenInRegistry(bToken);
    emit Borrow(siloToken, bToken, amount);
}

HadiEsna (NOYA) confirmed


The original report as published on Code4rena, by KYP. 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 borrow function in the Silo connector omitted the SolvencyV2 health-factor check that the repay function performs after interacting with Silo.

Impact

The protocol's minimum health-factor invariant is broken and the position could be liquidated more easily.

What the attacker needed

Manager role on the connector

The fix

The borrow function should perform the same SolvencyV2 health-factor check as repay and revert if the position is insolvent.

How it was found

  1. Deposit USDC into the Silo connector and open a position.
  2. Call borrow on the connector to borrow WETH against that collateral.
  3. Observe that the resulting Silo position is insolvent according to SolvencyV2.
  4. Call repay and see that the solvency check there reverts or constrains the position.

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.

A connector is a piece of code that lets the main protocol deposit, borrow and repay through another lending service called Silo. The protocol wants every position to stay above a minimum safety level, called a health factor, and it checks this after repaying. The borrow function skipped that check, so a position could be opened already below the safety line, which makes it easier for someone else to liquidate it.

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 by KYP

View all

1 more disclosed report, best first.

More from NOYA

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.