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

Exp removal of last counted epoch #32

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 0 additions & 10 deletions src/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,6 @@ contract Governance is Multicall, UserProxyFactory, ReentrancyGuard, IGovernance

initiativeSnapshot.forEpoch = currentEpoch - 1;

/// @audit Conditional
/// If we meet the threshold then we increase this
/// TODO: Either simplify, or use this for the state machine as well
if(
initiativeSnapshot.votes > initiativeSnapshot.vetos &&
initiativeSnapshot.votes >= votingThreshold
) {
// initiativeSnapshot.lastCountedEpoch = currentEpoch - 1; /// @audit This updating makes it so that we lose track | TODO: Find a better way
}

votesForInitiativeSnapshot[_initiative] = initiativeSnapshot;
emit SnapshotVotesForInitiative(_initiative, initiativeSnapshot.votes, initiativeSnapshot.forEpoch);
}
Expand Down
4 changes: 1 addition & 3 deletions src/interfaces/IGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ interface IGovernance {
struct InitiativeVoteSnapshot {
uint224 votes; // Votes at epoch transition
uint16 forEpoch; // Epoch for which the votes are counted
uint16 lastCountedEpoch; // Epoch at which which the votes where counted last in the global snapshot
uint224 vetos; // Vetos at epoch transition
}

Expand All @@ -103,11 +102,10 @@ interface IGovernance {
/// @param _initiative Address of the initiative
/// @return votes Number of votes
/// @return forEpoch Epoch for which the votes are counted
/// @return lastCountedEpoch Epoch at which which the votes where counted last in the global snapshot
function votesForInitiativeSnapshot(address _initiative)
external
view
returns (uint224 votes, uint16 forEpoch, uint16 lastCountedEpoch, uint224 vetos);
returns (uint224 votes, uint16 forEpoch, uint224 vetos);

struct Allocation {
uint88 voteLQTY; // LQTY allocated vouching for the initiative
Expand Down
22 changes: 8 additions & 14 deletions test/Governance.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -628,23 +628,21 @@ contract GovernanceTest is Test {
assertEq(forEpoch, governance.epoch() - 1);

IGovernance.InitiativeVoteSnapshot memory initiativeSnapshot =
IGovernance.InitiativeVoteSnapshot(0, governance.epoch() - 1, 0, 0);
IGovernance.InitiativeVoteSnapshot(0, 0, 0);
vm.store(
address(governance),
keccak256(abi.encode(baseInitiative3, uint256(3))),
bytes32(
abi.encodePacked(
uint16(initiativeSnapshot.lastCountedEpoch),
uint16(initiativeSnapshot.forEpoch),
uint224(initiativeSnapshot.votes)
)
)
);
(uint224 votes_, uint16 forEpoch_, uint16 lastCountedEpoch, ) =
(uint224 votes_, uint16 forEpoch_, ) =
governance.votesForInitiativeSnapshot(baseInitiative3);
assertEq(votes_, 0);
assertEq(forEpoch_, governance.epoch() - 1);
assertEq(lastCountedEpoch, 0);

governance.unregisterInitiative(baseInitiative3);

Expand Down Expand Up @@ -917,7 +915,7 @@ contract GovernanceTest is Test {
// should snapshot the global and initiatives votes if there hasn't been a snapshot in the current epoch yet
(, uint16 forEpoch) = governance.votesSnapshot();
assertEq(forEpoch, governance.epoch() - 1);
(, forEpoch, ,) = governance.votesForInitiativeSnapshot(baseInitiative1);
(, forEpoch, ) = governance.votesForInitiativeSnapshot(baseInitiative1);
assertEq(forEpoch, governance.epoch() - 1);

vm.stopPrank();
Expand Down Expand Up @@ -1153,7 +1151,7 @@ contract GovernanceTest is Test {
(Governance.InitiativeStatus status, , uint256 claimable) = governance.getInitiativeState(baseInitiative2);
console.log("res", uint8(status));
console.log("claimable", claimable);
(uint224 votes, , , uint224 vetos) = governance.votesForInitiativeSnapshot(baseInitiative2);
(uint224 votes, , uint224 vetos) = governance.votesForInitiativeSnapshot(baseInitiative2);
console.log("snapshot votes", votes);
console.log("snapshot vetos", vetos);

Expand Down Expand Up @@ -1338,44 +1336,40 @@ contract GovernanceTest is Test {
assertEq(forEpoch, governance.epoch() - 1);

IGovernance.InitiativeVoteSnapshot memory initiativeSnapshot =
IGovernance.InitiativeVoteSnapshot(1, governance.epoch() - 1, governance.epoch() - 1, 0);
IGovernance.InitiativeVoteSnapshot(1, governance.epoch() - 1, 0);
vm.store(
address(governance),
keccak256(abi.encode(address(mockInitiative), uint256(3))),
bytes32(
abi.encodePacked(
uint16(initiativeSnapshot.lastCountedEpoch),
uint16(initiativeSnapshot.forEpoch),
uint224(initiativeSnapshot.votes)
)
)
);
(uint224 votes_, uint16 forEpoch_, uint16 lastCountedEpoch, ) =
(uint224 votes_, uint16 forEpoch_, ) =
governance.votesForInitiativeSnapshot(address(mockInitiative));
assertEq(votes_, 1);
assertEq(forEpoch_, governance.epoch() - 1);
assertEq(lastCountedEpoch, governance.epoch() - 1);

governance.claimForInitiative(address(mockInitiative));

vm.warp(block.timestamp + governance.EPOCH_DURATION());

initiativeSnapshot = IGovernance.InitiativeVoteSnapshot(0, governance.epoch() - 1, 0, 0);
initiativeSnapshot = IGovernance.InitiativeVoteSnapshot(0, 0, 0);
vm.store(
address(governance),
keccak256(abi.encode(address(mockInitiative), uint256(3))),
bytes32(
abi.encodePacked(
uint16(initiativeSnapshot.lastCountedEpoch),
uint16(initiativeSnapshot.forEpoch),
uint224(initiativeSnapshot.votes)
)
)
);
(votes_, forEpoch_, lastCountedEpoch, ) = governance.votesForInitiativeSnapshot(address(mockInitiative));
(votes_, forEpoch_, ) = governance.votesForInitiativeSnapshot(address(mockInitiative));
assertEq(votes_, 0, "votes");
assertEq(forEpoch_, governance.epoch() - 1, "forEpoch_");
assertEq(lastCountedEpoch, 0, "lastCountedEpoch");

vm.warp(block.timestamp + governance.EPOCH_DURATION() * 4);

Expand Down
7 changes: 2 additions & 5 deletions zzz_TEMP_TO_FIX.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
[FAIL. Reason: revert: Governance: claim-not-met] test_claimForInitiative() (gas: 1198986)

Fails because of Governance: claim-not-met

TODO: Discuss if we should return 0 in those scenarios
[FAIL. Reason: assertion failed: 65536 != 1] test_nonReentrant() (gas: 829813)
[FAIL. Reason: assertion failed: 0 != 104] test_unregisterInitiative() (gas: 435924)
Loading