Skip to content

Commit

Permalink
test: voting power manipulation via withdrawal
Browse files Browse the repository at this point in the history
  • Loading branch information
danielattilasimon committed Jan 1, 2025
1 parent e0b08a6 commit 8173873
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/Governance.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

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);
Expand Down

0 comments on commit 8173873

Please sign in to comment.