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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Added overflow handling for TWAB timestamp #204

Merged
merged 2 commits into from
Oct 6, 2021

Conversation

asselstine
Copy link
Contributor

No description provided.

@linear
Copy link

linear bot commented Oct 6, 2021

POOL-1408 Ticket contract should handle overflow cleanly

Two items can overflow:

  • timestamps
  • twab amounts

The key is to let them overflow, but ensure you can detect when they overflow.

A branch with partial implementation is here, although it will be out of date: https://github.com/pooltogether/pooltogether-contract-tsunami/tree/pool-1408-ticket-contract-should-handle-overflow

I believe the branch solved the timestamp overflow, but not the amount.

@PierrickGT PierrickGT self-assigned this Oct 6, 2021
Comment on lines 248 to 253
_timestampsWithStartCutoffTimes[i] = (
_draws[i].timestamp - _prizeDistributions[i].startTimestampOffset
);
_timestampsWithEndCutoffTimes[i] = uint32(
_timestampsWithEndCutoffTimes[i] = (
_draws[i].timestamp - _prizeDistributions[i].endTimestampOffset
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we don't need these parentheses anymore right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't

@@ -261,8 +261,8 @@ contract Ticket is ControlledToken, ITicket {
averageBalances[i] = TwabLib.getAverageBalanceBetween(
_account.twabs,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be stored in a variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which? The _account.twabs ? it's a pointer- wouldn't make a difference

@@ -2,6 +2,8 @@

pragma solidity 0.8.6;

import "hardhat/console.sol";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run yarn remove-logs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yessir

test/Ticket.test.ts Show resolved Hide resolved
@@ -41,14 +41,6 @@ describe('TwabLib', () => {
.withArgs([200, 1, 1], [0, timestamp], false);
});

it('should require the timestamp to always increase', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this test been removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because if the passed timestamp is less than the previous timestamp it assumes that the timestamp has overflowed. That means this test is no longer relevant (I think)

@asselstine asselstine force-pushed the pool-1408-ticket-contract-should-handle-overflow branch from 2fe1bc4 to 2a9d203 Compare October 6, 2021 21:59
@@ -191,7 +191,7 @@ contract DrawBeacon is IDrawBeacon, Ownable {
}

/// @inheritdoc IDrawBeacon
function calculateNextBeaconPeriodStartTime(uint256 _currentTime)
function calculateNextBeaconPeriodStartTime(uint256 __currentTime)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to avoid shadowing? I've renamed to _time:

function calculateNextBeaconPeriodStartTime(uint256 _time)

So you probably need to rebase master.

@asselstine asselstine force-pushed the pool-1408-ticket-contract-should-handle-overflow branch from ff7e8b8 to 0832802 Compare October 6, 2021 23:35
@asselstine asselstine force-pushed the pool-1408-ticket-contract-should-handle-overflow branch from 0832802 to 688d7ad Compare October 6, 2021 23:36
@asselstine asselstine merged commit cff8933 into master Oct 6, 2021
@asselstine asselstine deleted the pool-1408-ticket-contract-should-handle-overflow branch October 6, 2021 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants