Skip to content
Smart contracts Audit finding Intermediate

pow() is missing check on input parameters with 0 value

The pow() function in LogExpMath.sol lacks checks for zero inputs, unlike the Balancer original. This omission might lead to unexpected results, though no specific attack is described.

gpersoon Follow

Originally disclosed on Code4rena

Submitted by gpersoon

Impact

The contract LogExpMath.sol seems to be a fork of the balancer LogExpMath.sol contract. It is mostly similar, except for checks for x and y being 0 in the beginning of the function pow(), see below.

This omission might lead to unexpected results.

Proof of Concept

https://github.com/code-423n4/2021-11-overlay/blob/914bed22f190ebe7088194453bab08c424c3f70c/contracts/libraries/LogExpMath.sol#L93-L110

 function pow(uint256 x, uint256 y) internal pure returns (uint256) {
        unchecked {
        _require(x < 2**255, Errors.X_OUT_OF_BOUNDS);

https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/solidity-utils/contracts/math/LogExpMath.sol#L93-L109

function pow(uint256 x, uint256 y) internal pure returns (uint256) {
    if (y == 0) {
        // We solve the 0^0 indetermination by making it equal one.
        return uint256(ONE_18);
    }

    if (x == 0) {
        return 0;
    }
    _require(x < 2**255, Errors.X_OUT_OF_BOUNDS);

Recommended Mitigation Steps

Check if the extra code of the balance contract is useful and if so add it.

realisation (Overlay) disputed:

Out of scope

dmvt (judge) commented:

I disagree with sponsor regarding scope. The Contracts section of the Contest Scope lists several contracts which rely on contracts/libraries/FixedPoint.sol. This contract uses the pow function containing the issue described. The warden has not described an exact attack but has show a math issue, which can certainly lead to a hypothetical loss of funds. Medium severity is appropriate and sponsor should definitely fix this.

The original report as published on Code4rena, by gpersoon. 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

Likely the developers removed the zero-input checks when forking the Balancer contract, assuming they were unnecessary.

Impact

The missing checks could lead to unexpected mathematical results, which might hypothetically cause loss of funds, but no concrete attack is demonstrated.

What the attacker needed

None

The fix

The extra zero-input checks from the Balancer contract should be added if they are useful.

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.

This is about a maths function in a smart contract that calculates powers. The original version from another project had special handling for when the base or exponent is zero, but this copy left that out. That could cause wrong calculations, but the report does not show how an attacker would exploit it.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by gpersoon

View all

47 more disclosed reports, best first.

More from Overlay Protocol contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.