code-423n4 / 2021-11-streaming-findings

0 stars 0 forks source link

`10**6` can be changed to `1e6` and save some gas #248

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

WatchPug

Vulnerability details

https://github.com/code-423n4/2021-11-streaming/blob/56d81204a00fc949d29ddd277169690318b36821/Streaming/src/Locke.sol#L355-L363

function dilutedBalance(uint112 amount) internal view returns (uint256) {
    // duration / timeRemaining * amount
    if (block.timestamp < startTime) {
        return amount;
    } else {
        uint32 timeRemaining = endStream - uint32(block.timestamp);
        return ((uint256(streamDuration) * amount * 10**6) / timeRemaining) / 10**6;
    }
}

Recommendation

Change to:

function dilutedBalance(uint112 amount) internal view returns (uint256) {
    // duration / timeRemaining * amount
    if (block.timestamp < startTime) {
        return amount;
    } else {
        uint32 timeRemaining = endStream - uint32(block.timestamp);
        return ((uint256(streamDuration) * amount * 1e6) / timeRemaining) / 1e6;
    }
}