Skip to content
DoS Audit finding Intermediate

Edge-case USG prices will force reverts for functions relying on IRCalculator

The integer division in computing quotientFixedPoint inside _computeIR() truncates to zero for USG prices extremely close to pMax, causing _pow() to call log_2(0) and revert. This blocks functions that rely on interest rate calculation, such as withdraw, borrow, repay, liquidate, and migrate.

0xDelvine Follow with 0xShoonya and coin2own

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-08-usg-tangent-judging/issues/727

Found by

0xDelvine, 0xShoonya, coin2own

Summary

The integer division in computing quotientFixedPoint inside _computeIR() will cause it to become zero for edge-case USG prices as _pow will call log_2(0) and revert.

Root Cause

In IRCalculator.sol:249 the calculation of quotientFixedPoint performs integer division before converting into 64.64 fixed-point, which truncates fractional values below 1 to 0. This 0 then propagates into _pow()IRCalculator.sol:295, where log_2(0)IRCalculator.sol:296 is called, causing a revert due to the require(x > 0) check in ABDKMath64x64.log_2.

Internal Pre-conditions

  1. The contract fetches a usgPrice value.
  2. USGPrice needs to be less than pMax * E12.
  3. The difference (pMax * E12 - USGPrice) must be smaller than (pMax - pMin)

External Pre-conditions

The oracle needs to return a USGPrice value extremely close to, but not more than pMax * E12

Attack Path

  1. A user calls a function that calls _computeIR() to trigger the interest rate calculation.
  2. The protocol fetches USGPrice from the oracle to use as an input in _computeIR() .
  3. Inside _computeIR(), the calculation of quotientFixedPoint begins:
    Solidity
    int128 quotientFixedPoint = ABDKMath64x64.divu(
        ((uint256(irParam.pMax) * E12) - USGPrice) / (irParam.pMax - irParam.pMin),
        E12
    );
    
    • Here, the inner division ((pMax * E12) - USGPrice) / (pMax - pMin) truncates to 0 when USGPrice is very close to (pMax × E12).
    • This 0 is then passed as the numerator into ABDKMath64x64.divu(0, E12).
  4. Inside divu, the library tries to left-shift the numerator (0 << 64) to scale it into 64.64 fixed-point format. Since the numerator is already 0, the result of the shift remains 0. No meaningful fixed-point value can be produced.
  5. As a result, quotientFixedPoint = 0.
  6. _computeIR() passes quotientFixedPoint = 0 into _pow().
  7. _pow() calls ABDKMath64x64.log_2(0), which reverts due to the require(x > 0) check inside log_2.

Impact

  • The protocol cannot compute the interest rate whenever usgPrice approaches (pMax × 1e12).
  • This causes _computeIR() to revert, which blocks dependent functions from executing.
  • As a result, users are unable to perform actions that require interest rate calculation i.e withdraw, borrow, repay, liquidate, migrateFrom, migrateTo.

PoC

Proof of Concept

  1. Paste the following solidity test into tangent-contracts/test/unit/IRCalculator
Solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "forge-std/Test.sol";
import "forge-std/console.sol";
import {ABDKMath64x64} from "../../../src/libs/ABDKMath64x64.sol";

contract IRBugTest is Test {
    uint256 constant E12 = 1e12;
    uint256 constant E13 = 1e13;
    uint256 constant ONE_ETHER = 1e18;

    uint256 usgPrice = 999_999_999_999_980_001; // the edge case

    struct IRParams {
        uint32 pMin;
        uint32 pMax;
        uint32 pInf;
        uint32 rMin;
        uint32 rMax;
        uint32 a1;
        uint32 a2;
        uint32 k;
        bool isHEC;
    }

    function _computeIR(uint256 USGPrice, IRParams memory irParam) public pure returns (uint216) {
        if (USGPrice <= uint256(irParam.pMin) * E12) {
            return uint216(irParam.rMax * E13);
        }
        if (USGPrice >= uint256(irParam.pMax) * E12) {
            if (irParam.isHEC) return 0;
            return uint216(irParam.rMin * E13);
        }

        int128 sigmaX = -ABDKMath64x64.mul(
            ABDKMath64x64.fromUInt(irParam.k),
            ABDKMath64x64.divi(
                int256(USGPrice) - int256(int32(irParam.pInf)) * int256(E12),
                int256(ONE_ETHER)
            )
        );
        int128 one = ABDKMath64x64.fromUInt(1);
        int128 sigma = ABDKMath64x64.div(one, one + ABDKMath64x64.exp(sigmaX));
        int128 alpha1 = ABDKMath64x64.divu(irParam.a1, 1000);
        int128 alpha = ABDKMath64x64.add(
            alpha1,
            ABDKMath64x64.mul(
                ABDKMath64x64.sub(ABDKMath64x64.divu(irParam.a2, 1000), alpha1),
                sigma
            )
        );

        int128 quotientFixedPoint = ABDKMath64x64.divu(
            ((uint256(irParam.pMax) * E12) - USGPrice) / (irParam.pMax - irParam.pMin),
            E12
        );

        uint256 irIncrement = ABDKMath64x64.mulu(
            ABDKMath64x64.mul(
                ABDKMath64x64.fromUInt(irParam.rMax - irParam.rMin),
                _pow(quotientFixedPoint, alpha)
            ),
            E13
        );

        return uint216(uint256(irParam.rMin) * E13 + irIncrement);
    }

    function _pow(int128 a, int128 b) private pure returns (int128) {
        return ABDKMath64x64.exp_2(ABDKMath64x64.mul(ABDKMath64x64.log_2(a), b));
    }

    // external wrappers so we can catch reverts in try/catch
    function callLog2(int128 x) external pure {
        ABDKMath64x64.log_2(x);
    }

    function callCompute(uint256 price, IRParams memory params) external pure {
        _computeIR(price, params);
    }

    function test_RevertWhen_QuotientIsZero() public {
        IRParams memory params = IRParams({
            pMin: 980_000,
            pMax: 1_000_000,
            pInf: 990_000,
            rMin: 1,
            rMax: 5,
            a1: 500,
            a2: 1500,
            k: 1,
            isHEC: false
        });

        // Prove integer division collapse
        uint256 rawNumerator = (uint256(params.pMax) * E12) - usgPrice;
        uint256 rawDenom = params.pMax - params.pMin;
        uint256 afterIntDiv = rawNumerator / rawDenom;
        int128 quotientFixedPoint = ABDKMath64x64.divu(afterIntDiv, E12);

        console.log("rawNumerator:", rawNumerator);
        console.log("rawDenom:", rawDenom);
        console.log("afterIntDiv:", afterIntDiv);
        console.log("quotientFixedPoint:", int256(quotientFixedPoint));

        assertEq(afterIntDiv, 0, "Expected afterIntDiv == 0");
        assertEq(quotientFixedPoint, 0, "Expected quotientFixedPoint == 0");

        // Catch revert in log_2
        try this.callLog2(quotientFixedPoint) {
            fail("Expected log_2(0) to revert, but it did not");
        } catch (bytes memory revertData) {
            console.log("Caught revert in log_2, data length:", revertData.length);
            assertEq(revertData.length, 0, "Revert data should be empty (require log_2 check : x > 0 failed)");
        }

        // Catch revert in _computeIR
        try this.callCompute(usgPrice, params) {
            fail("Expected _computeIR to revert, but it did not");
        } catch (bytes memory revertData) {
            console.log("Caught revert in _computeIR, data length:", revertData.length);
            assertEq(revertData.length, 0, "Revert data should be empty (require log_2 check: x > 0 failed)");
        }
    }
}
  1. Run the following command:
Bash
forge test --match-path test/unit/IRCalculator/bugProof.t.sol -vvv
Solidity
forge test --match-path test/unit/IRCalculator/bugProof.t.sol -vvv
[⠘] Compiling...
No files changed, compilation skipped
forge test --match-path test/unit/IRCalculator/bugProof.t.sol -vvv
[⠰] Compiling...
No files changed, compilation skipped

Ran 1 test for test/unit/IRCalculator/bugProof.t.sol:IRBugTest
[PASS] test_RevertWhen_QuotientIsZero() (gas: 26384)
Logs:
  rawNumerator: 19999
  rawDenom: 20000
  afterIntDiv: 0
  quotientFixedPoint: 0
  Caught revert in log_2, data length: 0
  Caught revert in _computeIR, data length: 0

Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.33ms (646.97µs CPU time)

Ran 1 test suite in 51.24ms (1.33ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)

Mitigation

Add an explicit check before performing the division in _computeIR to ensure that the numerator is greater than or equal to the denominator. If the numerator is smaller, the function should handle this case gracefully to avoid unintended reverts.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/Tangent-labs/tangent-contracts/pull/119

The original report as published on Sherlock, by 0xDelvine. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

Likely the integer division in the calculation of quotientFixedPoint truncates fractional values below 1 to 0, which then causes log_2(0) to revert.

Impact

The protocol cannot compute the interest rate when USGPrice approaches pMax × 1e12, causing _computeIR() to revert and blocking dependent functions like withdraw, borrow, repay, liquidate, and migrate.

What the attacker needed

USGPrice from oracle is extremely close to pMax*E12; USGPrice is less than pMax*E12; Difference (pMax*E12 - USGPrice) < (pMax - pMin)

The fix

The protocol team fixed this issue in a pull request.

How it was found

  1. A user calls a function that calls _computeIR() to trigger the interest rate calculation.
  2. The protocol fetches USGPrice from the oracle to use as an input in _computeIR().
  3. Inside _computeIR(), the calculation of quotientFixedPoint begins and the inner division truncates to 0 when USGPrice is very close to (pMax × E12).
  4. This 0 is then passed as the numerator into ABDKMath64x64.divu(0, E12).
  5. As a result, quotientFixedPoint = 0.
  6. _computeIR() passes quotientFixedPoint = 0 into _pow(), which calls ABDKMath64x64.log_2(0) and reverts due to the require(x > 0) check.

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 smart contract calculates an interest rate using a formula that includes a division. When the price is very close to a maximum value, the division result becomes zero because the code drops fractions. Later, the code tries to take the logarithm of zero, which is mathematically impossible, so the whole transaction fails. This means users cannot perform actions that need the interest rate.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More from USG - Tangent

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.