Skip to content

[SECURITY] Vulnerability Disclosure: Immunefi_Report_makerdao_dss_abaci.sol.md #386

@rbxict

Description

@rbxict

Description

The contract StairstepExponentialDecrease has a potential vulnerability in the rpow function. The function uses the shr instruction to check if the most significant bit of x is set, but it does not handle the case where x is equal to 2**128.

Attack Scenario

An attacker can exploit this vulnerability by calling the rpow function with x = 2**128 and n > 0. This will cause the shr instruction to underflow, resulting in an incorrect calculation.

Impact

The impact of this vulnerability is that an attacker can manipulate the price calculation in the StairstepExponentialDecrease contract, potentially resulting in a loss of funds.

Recommendation

To fix this vulnerability, the rpow function should be modified to correctly handle the case where x = 2**128.

function rpow(uint256 x, uint256 n, uint256 b) internal pure returns (uint256 z) {
    assembly {
        switch n case 0 { z := b }
        default {
            switch x case 0 { z := 0 }
            default {
                switch mod(n, 2) case 0 { z := b } default { z := x }
                let half := div(b, 2)  // for rounding.
                for { n := div(n, 2) } n { n := div(n,2) } {
                    let xx := mul(x, x)
                    if and(iszero(iszero(x)), gt(x, 2**128)) { revert(0,0) }
                    let xxRound := add(xx, half)
                    if lt(xxRound, xx) { revert(0,0) }
                    x := div(xxRound, b)
                    if mod(n,2) {
                        let zx := mul(z, x)
                        if and(iszero(iszero(x)), iszero(eq(div(zx, x), z))) { revert(0,0) }
                        let zxRound := add(zx, half)
                        if lt(zxRound, zx) { revert(0,0) }
                        z := div(zxRound, b)
                    }
                }
            }
        }
    }
}

However, we notice a second thing - lack of input validation. If n is large, rpow can cause an overflow. If x and b are large, the mul and div can also overflow.

Description

In the LinearDecrease contract and the StairstepExponentialDecrease contract, there is a potential for an arithmetic overflow in several places.

Attack Scenario

If an attacker calls LinearDecrease or StairstepExponentialDecrease with the right sequence of large numbers, they could overflow.

Impact

The impact of this vulnerability is DoS on parts of the protocol, specifically related to calculations done within those functions.

Recommendation

Implement proper checks to prevent these potential arithmetic overflows.

function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
    require((z = x + y) >= x, 'overflow');
}

function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
    require(y == 0 || (z = x * y) / y == x, 'overflow');
}

Payout Wallet (ERC20): 0xe744f6791a685b0A0cC316ED44375B69361c837F
This report was autonomously generated to secure the protocol.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions