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

fix: Move lqty allocation checks #77

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/BribeInitiative.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ contract BribeInitiative is IInitiative, IBribeInitiative {
lqtyAllocationByUserAtEpoch[_user].getItem(_prevLQTYAllocationEpoch);

require(
lqtyAllocation.value != 0 && _prevLQTYAllocationEpoch <= _epoch
&& (lqtyAllocation.next > _epoch || lqtyAllocation.next == 0),
_prevLQTYAllocationEpoch <= _epoch && (lqtyAllocation.next > _epoch || lqtyAllocation.next == 0),
"BribeInitiative: invalid-prev-lqty-allocation-epoch"
);
DoubleLinkedList.Item memory totalLQTYAllocation =
totalLQTYAllocationByEpoch.getItem(_prevTotalLQTYAllocationEpoch);
require(
totalLQTYAllocation.value != 0 && _prevTotalLQTYAllocationEpoch <= _epoch
_prevTotalLQTYAllocationEpoch <= _epoch
&& (totalLQTYAllocation.next > _epoch || totalLQTYAllocation.next == 0),
"BribeInitiative: invalid-prev-total-lqty-allocation-epoch"
);

(uint88 totalLQTY, uint120 totalAverageTimestamp) = _decodeLQTYAllocation(totalLQTYAllocation.value);
require(totalLQTY > 0, "BribeInitiative: invalid-prev-total-lqty");
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rephrase the error message. The variable being checked stands for the total LQTY allocated to the initiative in the epoch from which the bribes are being claimed from. Thus, I guess a better message would be: invalid-total-lqty-allocation or total-lqty-allocation-zero.


// NOTE: SCALING!!! | The timestamp will work until type(uint32).max | After which the math will eventually overflow
uint120 scaledEpochEnd = (
Expand All @@ -113,6 +113,7 @@ contract BribeInitiative is IInitiative, IBribeInitiative {
uint240 totalVotes = governance.lqtyToVotes(totalLQTY, scaledEpochEnd, totalAverageTimestamp);
if (totalVotes != 0) {
(uint88 lqty, uint120 averageTimestamp) = _decodeLQTYAllocation(lqtyAllocation.value);
require(lqty > 0, "BribeInitiative: invalid-prev-lqty");
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.


/// @audit Governance Invariant
assert(averageTimestamp <= scaledEpochEnd);
Expand Down
4 changes: 2 additions & 2 deletions test/BribeInitiative.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ contract BribeInitiativeTest is Test {
// user2 should receive no bribes if they try to claim
claimEpoch = governance.epoch() - 1; // claim for epoch 3
prevAllocationEpoch = governance.epoch() - 1; // epoch 3
(boldAmount, bribeTokenAmount) = _claimBribe(user2, claimEpoch, prevAllocationEpoch, prevAllocationEpoch);
(boldAmount, bribeTokenAmount) = _claimBribe(user2, claimEpoch, prevAllocationEpoch, prevAllocationEpoch, true);
assertEq(boldAmount, 0, "vetoer receives bold bribe amount");
assertEq(bribeTokenAmount, 0, "vetoer receives bribe amount");
}
Expand Down Expand Up @@ -857,7 +857,7 @@ contract BribeInitiativeTest is Test {
epochs[0].epoch = governance.epoch() - 1;
epochs[0].prevLQTYAllocationEpoch = governance.epoch() - 2;
epochs[0].prevTotalLQTYAllocationEpoch = governance.epoch() - 2;
vm.expectRevert("BribeInitiative: invalid-prev-total-lqty-allocation-epoch");
vm.expectRevert("BribeInitiative: invalid-prev-total-lqty");
(uint256 boldAmount, uint256 bribeTokenAmount) = bribeInitiative.claimBribes(epochs);
vm.stopPrank();

Expand Down
2 changes: 2 additions & 0 deletions test/BribeInitiativeAllocate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ contract BribeInitiativeAllocateTest is Test {
claimData[0].epoch = 2;
claimData[0].prevLQTYAllocationEpoch = 2;
claimData[0].prevTotalLQTYAllocationEpoch = 2;
vm.expectRevert("BribeInitiative: invalid-prev-total-lqty");
(uint256 boldAmount, uint256 bribeTokenAmount) = bribeInitiative.claimBribes(claimData);
assertEq(boldAmount, 0, "boldAmount nonzero");
assertEq(bribeTokenAmount, 0, "bribeTokenAmount nonzero");
Expand Down Expand Up @@ -707,6 +708,7 @@ contract BribeInitiativeAllocateTest is Test {
claimData[0].epoch = 1;
claimData[0].prevLQTYAllocationEpoch = 1;
claimData[0].prevTotalLQTYAllocationEpoch = 1;
vm.expectRevert("BribeInitiative: invalid-prev-lqty");
(uint256 boldAmount, uint256 bribeTokenAmount) = bribeInitiative.claimBribes(claimData);
assertEq(boldAmount, 0);
assertEq(bribeTokenAmount, 0);
Expand Down
Loading