Skip to content

Commit

Permalink
feat: broken key test
Browse files Browse the repository at this point in the history
  • Loading branch information
GalloDaSballo committed Oct 16, 2024
1 parent 0ae541f commit 3927a88
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 35 deletions.
8 changes: 7 additions & 1 deletion src/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ contract Governance is Multicall, UserProxyFactory, ReentrancyGuard, IGovernance
// allocate the voting and vetoing LQTY to the initiative
initiativeState.voteLQTY = add(initiativeState.voteLQTY, deltaLQTYVotes);
initiativeState.vetoLQTY = add(initiativeState.vetoLQTY, deltaLQTYVetos);
// assert(initiativeState.voteLQTY != 0); // Votes are non zero
// assert(deltaLQTYVotes != 0) // Votes are non zero

// update the initiative's state
initiativeStates[initiative] = initiativeState;
Expand Down Expand Up @@ -583,7 +585,7 @@ contract Governance is Multicall, UserProxyFactory, ReentrancyGuard, IGovernance
allocation.atEpoch = currentEpoch;
require(!(allocation.voteLQTY != 0 && allocation.vetoLQTY != 0), "Governance: vote-and-veto");
lqtyAllocatedByUserToInitiative[msg.sender][initiative] = allocation;

userState.allocatedLQTY = add(userState.allocatedLQTY, deltaLQTYVotes + deltaLQTYVetos);

emit AllocateLQTY(msg.sender, initiative, deltaLQTYVotes, deltaLQTYVetos, currentEpoch);
Expand All @@ -598,6 +600,9 @@ contract Governance is Multicall, UserProxyFactory, ReentrancyGuard, IGovernance
"Governance: insufficient-or-allocated-lqty"
);

// assert(state.countedVoteLQTY != 0);
// assert(state.countedVoteLQTYAverageTimestamp != 0);
/// Update storage
globalState = state;
userStates[msg.sender] = userState;
}
Expand Down Expand Up @@ -630,6 +635,7 @@ contract Governance is Multicall, UserProxyFactory, ReentrancyGuard, IGovernance
state.countedVoteLQTY - initiativeState.voteLQTY
);
state.countedVoteLQTY -= initiativeState.voteLQTY;

globalState = state;

/// weeks * 2^16 > u32 so the contract will stop working before this is an issue
Expand Down
62 changes: 29 additions & 33 deletions test/recon/CryticToFoundry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,46 @@ import {Test} from "forge-std/Test.sol";
import {TargetFunctions} from "./TargetFunctions.sol";
import {FoundryAsserts} from "@chimera/FoundryAsserts.sol";

import {console} from "forge-std/console.sol";


contract CryticToFoundry is Test, TargetFunctions, FoundryAsserts {
function setUp() public {
setup();
}

// forge test --match-test test_property_GV01_0 -vv
// forge test --match-test test_property_sum_of_lqty_global_user_matches_0 -vv

function test_property_GV01_0() public {

vm.roll(block.number + 4921);
vm.warp(block.timestamp + 277805);
vm.prank(0x0000000000000000000000000000000000020000);
helper_deployInitiative();

vm.roll(block.number + 17731);
vm.warp(block.timestamp + 661456);
vm.prank(0x0000000000000000000000000000000000010000);
helper_deployInitiative();

vm.roll(block.number + 41536);
vm.warp(block.timestamp + 1020941);
vm.prank(0x0000000000000000000000000000000000010000);
helper_deployInitiative();

vm.roll(block.number + 41536);
vm.warp(block.timestamp + 1020941);
function test_property_sum_of_lqty_global_user_matches_0() public {
vm.roll(block.number + 54184);
vm.warp(block.timestamp + 65199);
vm.prank(0x0000000000000000000000000000000000010000);
helper_deployInitiative();
governance_depositLQTY(10618051687797035123500145);

vm.roll(block.number + 41536);
vm.warp(block.timestamp + 1020941);
vm.prank(0x0000000000000000000000000000000000020000);
helper_deployInitiative();
vm.roll(block.number + 103930);
vm.warp(block.timestamp + 635494);
vm.prank(0x0000000000000000000000000000000000030000);
governance_allocateLQTY_clamped_single_initiative(0, 0, 1231231);

(uint88 user_allocatedLQTY, ) = governance.userStates(user);

assertTrue(user_allocatedLQTY > 0, "Something is allocated");

// Allocates `10597250933489619569146227`
(
uint88 countedVoteLQTY, uint32 countedVoteLQTYAverageTimestamp
// uint32 after_user_countedVoteLQTYAverageTimestamp // TODO: How do we do this?
) = governance.globalState();
console.log("countedVoteLQTYAverageTimestamp", countedVoteLQTYAverageTimestamp);
assertTrue(countedVoteLQTY > 0, "Something is counted");


vm.roll(block.number + 61507);
vm.warp(block.timestamp + 1049774);
vm.roll(block.number + 130098);
vm.warp(block.timestamp + 1006552);
vm.prank(0x0000000000000000000000000000000000020000);
governance_registerInitiative(22);

vm.roll(block.number + 61507);
vm.warp(block.timestamp + 1049774);
vm.prank(0x0000000000000000000000000000000000030000);
property_GV01();
property_sum_of_lqty_global_user_matches();
}



}
4 changes: 3 additions & 1 deletion test/recon/Properties.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ import {BeforeAfter} from "./BeforeAfter.sol";
import {GovernanceProperties} from "./properties/GovernanceProperties.sol";
import {BribeInitiativeProperties} from "./properties/BribeInitiativeProperties.sol";

abstract contract Properties is GovernanceProperties, BribeInitiativeProperties {

abstract contract Properties is GovernanceProperties {
/// @audit TODO: Add `BribeInitiativeProperties`
}
77 changes: 77 additions & 0 deletions test/recon/properties/GovernanceProperties.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,83 @@ abstract contract GovernanceProperties is BeforeAfter {
}

// Function sound total math

/// The Sum of LQTY allocated by Users matches the global state
function property_sum_of_lqty_global_user_matches() public {
// Get state
// Get all users
// Sum up all voted users
// Total must match
(
uint88 totalCountedLQTY,
// uint32 after_user_countedVoteLQTYAverageTimestamp // TODO: How do we do this?
) = governance.globalState();

uint256 totalUserCountedLQTY;
for(uint256 i; i < users.length; i++) {
(uint88 user_allocatedLQTY, ) = governance.userStates(users[i]);
totalUserCountedLQTY += user_allocatedLQTY;
}

eq(totalCountedLQTY, totalUserCountedLQTY, "Global vs SUM(Users_lqty) must match");
}

/// The Sum of LQTY allocated to Initiatives matches the Sum of LQTY allocated by users
function property_sum_of_lqty_initiative_user_matches() public {
// Get Initiatives
// Get all users
// Sum up all voted users & initiatives
// Total must match
uint256 totalInitiativesCountedLQTY;
for(uint256 i; i < deployedInitiatives.length; i++) {
(
uint88 after_user_voteLQTY,
,
,
,

) = governance.initiativeStates(deployedInitiatives[i]);
totalInitiativesCountedLQTY += after_user_voteLQTY;
}


uint256 totalUserCountedLQTY;
for(uint256 i; i < users.length; i++) {
(uint88 user_allocatedLQTY, ) = governance.userStates(users[i]);
totalUserCountedLQTY += user_allocatedLQTY;
}

eq(totalInitiativesCountedLQTY, totalUserCountedLQTY, "SUM(Initiatives_lqty) vs SUM(Users_lqty) must match");
}

/// The Sum of LQTY allocated to Initiatives matches the global state
function property_sum_of_lqty_global_initiatives_matches() public {
// Get Initiatives
// Get State
// Sum up all initiatives
// Total must match
(
uint88 totalCountedLQTY,
// uint32 after_user_countedVoteLQTYAverageTimestamp // TODO: How do we do this?
) = governance.globalState();

uint256 totalInitiativesCountedLQTY;
for(uint256 i; i < deployedInitiatives.length; i++) {
(
uint88 after_user_voteLQTY,
,
,
,

) = governance.initiativeStates(deployedInitiatives[i]);
totalInitiativesCountedLQTY += after_user_voteLQTY;
}

eq(totalCountedLQTY, totalInitiativesCountedLQTY, "Global vs SUM(Initiatives_lqty) must match");

}

// TODO: also `lqtyAllocatedByUserToInitiative`



Expand Down

0 comments on commit 3927a88

Please sign in to comment.