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 setting end time in the past #396

Merged
merged 9 commits into from
Apr 4, 2023
Merged

Prevent setting end time in the past #396

merged 9 commits into from
Apr 4, 2023

Conversation

andreivladbrg
Copy link
Member

Copy link
Member

@PaulRBerg PaulRBerg left a comment

Choose a reason for hiding this comment

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

Feedback below.

src/libraries/Errors.sol Outdated Show resolved Hide resolved
src/libraries/Errors.sol Outdated Show resolved Hide resolved
src/libraries/Helpers.sol Outdated Show resolved Hide resolved
src/libraries/Helpers.sol Outdated Show resolved Hide resolved
test/fork/lockup/linear/Linear.t.sol Outdated Show resolved Hide resolved
test/shared/Fuzzers.t.sol Outdated Show resolved Hide resolved
@andreivladbrg

This comment was marked as resolved.

@andreivladbrg andreivladbrg force-pushed the fix/past-endTime branch 2 times, most recently from c92a945 to 82e0095 Compare March 30, 2023 21:09
@andreivladbrg
Copy link
Member Author

I have improved the wording in my last commit. Can you please confirm that everything is good now?

Copy link
Member

@PaulRBerg PaulRBerg left a comment

Choose a reason for hiding this comment

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

I approved the changes because I have already resolved the comments with my latest commits.

But please have a look at all comments, @andreivladbrg.

the warp cheatcode doesn't work for the invariant tests

You are right. What we had to was to bound the start time and the cliff time like this:

uint40 currentTime = getBlockTimestamp();
params.broker.fee = bound(params.broker.fee, 0, DEFAULT_MAX_FEE);
params.range.start = boundUint40(params.range.start, 0, currentTime);
params.range.cliff = boundUint40(params.range.cliff, currentTime, currentTime + 52 weeks);
params.range.end = boundUint40(params.range.end, params.range.cliff + 1, MAX_UNIX_TIMESTAMP);

Another pre-requisite to make this work was to increase the default block.timestamp used in our tests. I ended up setting it to March 1, 2023:

DEFAULT_START_TIME = uint40(1_677_632_400);
vm.warp({ timestamp: DEFAULT_START_TIME });

This proved to be a very good decision, since it has led me to identify several minor issues in the tests (e.g. using DEFAULT_CLIFF_TIME instead of DEFAULT_CLIFF_DURATION in the bounding of timeWarp).

In addition, setting the block timestamp to a value in the present creates a more realistic testing environment (as I have argued here).

src/libraries/Errors.sol Outdated Show resolved Hide resolved
src/libraries/Helpers.sol Outdated Show resolved Hide resolved
src/libraries/Helpers.sol Outdated Show resolved Hide resolved
src/libraries/Helpers.sol Outdated Show resolved Hide resolved
test/shared/Fuzzers.t.sol Outdated Show resolved Hide resolved
@andreivladbrg
Copy link
Member Author

DEFAULT_CLIFF_TIME instead of DEFAULT_CLIFF_DURATION

Good catch

setting the block timestamp to a value in the present creates a more realistic testing environment

TBH, I don't have an opinion here . Feel free to proceed as you see want.

andreivladbrg and others added 8 commits April 3, 2023 12:35
docs: specify that the end time can't be in the past
test: when the current time is not less than end time
test: ensure the last milestone is greater than the current time in fuzzSegments
test: bound end time between current time + 1 and MAX_UNIX_TIMESTAMP
chore: improve wording in explanatory comments
test: improve naming for tests
test: remove unnecessary casting
chore: fix explanations in comments
test: use named arguments for "vm.warp"
test: add "MAX_SEGMENT_DURATION"
test: delete stale comments about fuzzing scenarios
test: improve "fuzzSegmentMilestones"
test: fix "min" for cliff duration bounds
test: simplify bounding for end time
@PaulRBerg
Copy link
Member

PaulRBerg commented Apr 3, 2023

There is an invariant test run that failed, but it is unrelated to this PR (see my explanation here).

@PaulRBerg PaulRBerg merged commit 6f2698a into main Apr 4, 2023
@PaulRBerg PaulRBerg deleted the fix/past-endTime branch April 4, 2023 07:34
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.

2 participants