Skip to content

Commit ffbf480

Browse files
Merge pull request #121 from liquity/stale-check
refactor: remove stale and redundant check
2 parents b5ade69 + 7cf3b1f commit ffbf480

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/Governance.sol

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,10 @@ contract Governance is MultiDelegateCall, UserProxyFactory, ReentrancyGuard, Own
587587
int256[] calldata _absoluteLQTYVotes,
588588
int256[] calldata _absoluteLQTYVetos
589589
) external nonReentrant {
590-
require(_initiatives.length == _absoluteLQTYVotes.length, "Length");
591-
require(_absoluteLQTYVetos.length == _absoluteLQTYVotes.length, "Length");
590+
require(
591+
_initiatives.length == _absoluteLQTYVotes.length && _absoluteLQTYVotes.length == _absoluteLQTYVetos.length,
592+
"Governance: array-length-mismatch"
593+
);
592594

593595
// To ensure the change is safe, enforce uniqueness
594596
_requireNoDuplicates(_initiativesToReset);
@@ -669,20 +671,16 @@ contract Governance is MultiDelegateCall, UserProxyFactory, ReentrancyGuard, Own
669671
}
670672

671673
/// @dev For each given initiative applies relative changes to the allocation
672-
/// NOTE: Given the current usage the function either: Resets the value to 0, or sets the value to a new value
673-
/// Review the flows as the function could be used in many ways, but it ends up being used in just those 2 ways
674+
/// @dev Assumes that all the input arrays are of equal length
675+
/// @dev NOTE: Given the current usage the function either: Resets the value to 0, or sets the value to a new value
676+
/// Review the flows as the function could be used in many ways, but it ends up being used in just those 2 ways
674677
function _allocateLQTY(
675678
address[] memory _initiatives,
676679
int256[] memory _deltaLQTYVotes,
677680
int256[] memory _deltaLQTYVetos,
678681
int256[] memory _deltaOffsetVotes,
679682
int256[] memory _deltaOffsetVetos
680683
) internal {
681-
require(
682-
_initiatives.length == _deltaLQTYVotes.length && _initiatives.length == _deltaLQTYVetos.length,
683-
"Governance: array-length-mismatch"
684-
);
685-
686684
AllocateLQTYMemory memory vars;
687685
(vars.votesSnapshot_, vars.state) = _snapshotVotes();
688686
vars.currentEpoch = epoch();

test/Governance.t.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,24 @@ abstract contract GovernanceTest is Test {
971971
/// Ensure that at the end you remove 100%
972972
function test_fuzz_canRemoveExtact() public {}
973973

974+
function test_allocateLQTY_revertsWhenInputArraysAreOfDifferentLengths() external {
975+
address[] memory initiativesToReset = new address[](0);
976+
address[][2] memory initiatives = [new address[](2), new address[](3)];
977+
int256[][2] memory votes = [new int256[](2), new int256[](3)];
978+
int256[][2] memory vetos = [new int256[](2), new int256[](3)];
979+
980+
for (uint256 i = 0; i < 2; ++i) {
981+
for (uint256 j = 0; j < 2; ++j) {
982+
for (uint256 k = 0; k < 2; ++k) {
983+
if (i == j && j == k) continue;
984+
985+
vm.expectRevert("Governance: array-length-mismatch");
986+
governance.allocateLQTY(initiativesToReset, initiatives[i], votes[j], vetos[k]);
987+
}
988+
}
989+
}
990+
}
991+
974992
function test_allocateLQTY_single() public {
975993
vm.startPrank(user);
976994

0 commit comments

Comments
 (0)