-
Notifications
You must be signed in to change notification settings - Fork 9
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
fix: dust left in unallocatedOffset
despite allocating all LQTY
#112
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ba0f44c
fix: dust left in `unallocatedOffset` despite allocating all LQTY
danielattilasimon 9093f62
Merge remote-tracking branch 'origin/main' into fix-offset-dust
danielattilasimon e0b08a6
test: voting power manipulation via allocation
danielattilasimon 8173873
test: voting power manipulation via withdrawal
danielattilasimon e50789c
fix: add strong assertions on non-negative voting power allocation
danielattilasimon 3ca74e1
chore: add comment about offset allocation scheme
danielattilasimon 73fbf86
chore: add explanation to rounding error test case
danielattilasimon 5d2d605
chore: death to ugly numbers
danielattilasimon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2477,6 +2477,7 @@ abstract contract GovernanceTest is Test { | |
// By waiting `initialVotingPower` seconds while having 1 wei LQTY staked, | ||
// we accrue exactly `initialVotingPower` | ||
vm.warp(block.timestamp + initialVotingPower); | ||
|
||
governance.depositLQTY(583399417581888701); | ||
|
||
address[] memory initiativesToReset; // left empty | ||
|
@@ -2503,6 +2504,43 @@ abstract contract GovernanceTest is Test { | |
); | ||
} | ||
|
||
function test_WhenWithdrawingTinyAmounts_VotingPowerDoesNotTurnNegativeDueToRoundingError( | ||
uint256 initialVotingPower, | ||
uint256 numWithdrawals | ||
) external { | ||
initialVotingPower = bound(initialVotingPower, 1, 20); | ||
numWithdrawals = bound(numWithdrawals, 1, 20); | ||
|
||
vm.startPrank(user); | ||
{ | ||
address userProxy = governance.deriveUserProxyAddress(user); | ||
lqty.approve(userProxy, type(uint256).max); | ||
governance.depositLQTY(1); | ||
|
||
// By waiting `initialVotingPower` seconds while having 1 wei LQTY staked, | ||
// we accrue exactly `initialVotingPower` | ||
vm.warp(block.timestamp + initialVotingPower); | ||
|
||
governance.depositLQTY(583399417581888701); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here |
||
|
||
for (uint256 i = 0; i < numWithdrawals; ++i) { | ||
governance.withdrawLQTY(1); | ||
} | ||
} | ||
vm.stopPrank(); | ||
|
||
(uint256 unallocatedLQTY, uint256 unallocatedOffset,,) = governance.userStates(user); | ||
int256 votingPower = int256(unallocatedLQTY * block.timestamp) - int256(unallocatedOffset); | ||
|
||
// Even though we are withdrawing tiny amounts, each withdrawal | ||
// reduces voting power by 1 (due to rounding), but not below zero | ||
assertEq( | ||
votingPower, | ||
int256(initialVotingPower > numWithdrawals ? initialVotingPower - numWithdrawals : 0), | ||
"voting power should stay non-negative" | ||
); | ||
} | ||
|
||
function test_Vote_Stake_Unvote() external { | ||
address[] memory noInitiatives; | ||
address[] memory initiatives = new address[](1); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where dies this number come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some random prime. Actually, there's nothing special about it, any number big enough to result in rounding error would work, even round numbers.