Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent rounding error #124

Open
code423n4 opened this issue Dec 5, 2021 · 0 comments
Open

prevent rounding error #124

code423n4 opened this issue Dec 5, 2021 · 0 comments
Labels
1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working

Comments

@code423n4
Copy link
Contributor

Handle

gpersoon

Vulnerability details

Impact

On several locations in the code a multiplication by 106 and then a division by 106 is used to prevent rounding errors, see examples below.

However in a similar situation in updateStreamInternal(), when calculating ts.tokens, this construction is not used. This might lead to some (probably minor) rounding errors.

Proof of Concept

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

function updateStreamInternal(address who) internal {
      ...
                ts.tokens -= uint112(acctTimeDelta * ts.tokens / (endStream - ts.lastUpdate));
        ...
                uint256 globalStreamingSpeedPerSecond = (uint256(unstreamed) * 10**6)/ (endStream - lastUpdate);
                unstreamed -= uint112((uint256(tdelta) * globalStreamingSpeedPerSecond) / 10**6);

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

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

Tools Used

Recommended Mitigation Steps

Change the code to

 ts.tokens -= uint112(acctTimeDelta * ts.tokens * 10**6 / (endStream - ts.lastUpdate) / 10**6 );
@code423n4 code423n4 added 1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working labels Dec 5, 2021
code423n4 added a commit that referenced this issue Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant