diff --git a/src/Governance.sol b/src/Governance.sol index 40fc10f..21a2ae1 100644 --- a/src/Governance.sol +++ b/src/Governance.sol @@ -587,8 +587,10 @@ contract Governance is MultiDelegateCall, UserProxyFactory, ReentrancyGuard, Own int256[] calldata _absoluteLQTYVotes, int256[] calldata _absoluteLQTYVetos ) external nonReentrant { - require(_initiatives.length == _absoluteLQTYVotes.length, "Length"); - require(_absoluteLQTYVetos.length == _absoluteLQTYVotes.length, "Length"); + require( + _initiatives.length == _absoluteLQTYVotes.length && _absoluteLQTYVotes.length == _absoluteLQTYVetos.length, + "Governance: array-length-mismatch" + ); // To ensure the change is safe, enforce uniqueness _requireNoDuplicates(_initiativesToReset); @@ -669,8 +671,9 @@ contract Governance is MultiDelegateCall, UserProxyFactory, ReentrancyGuard, Own } /// @dev For each given initiative applies relative changes to the allocation - /// NOTE: Given the current usage the function either: Resets the value to 0, or sets the value to a new value - /// Review the flows as the function could be used in many ways, but it ends up being used in just those 2 ways + /// @dev Assumes that all the input arrays are of equal length + /// @dev NOTE: Given the current usage the function either: Resets the value to 0, or sets the value to a new value + /// Review the flows as the function could be used in many ways, but it ends up being used in just those 2 ways function _allocateLQTY( address[] memory _initiatives, int256[] memory _deltaLQTYVotes, @@ -678,11 +681,6 @@ contract Governance is MultiDelegateCall, UserProxyFactory, ReentrancyGuard, Own int256[] memory _deltaOffsetVotes, int256[] memory _deltaOffsetVetos ) internal { - require( - _initiatives.length == _deltaLQTYVotes.length && _initiatives.length == _deltaLQTYVetos.length, - "Governance: array-length-mismatch" - ); - AllocateLQTYMemory memory vars; (vars.votesSnapshot_, vars.state) = _snapshotVotes(); vars.currentEpoch = epoch(); diff --git a/test/Governance.t.sol b/test/Governance.t.sol index 5033aba..7d3766e 100644 --- a/test/Governance.t.sol +++ b/test/Governance.t.sol @@ -971,6 +971,24 @@ abstract contract GovernanceTest is Test { /// Ensure that at the end you remove 100% function test_fuzz_canRemoveExtact() public {} + function test_allocateLQTY_revertsWhenInputArraysAreOfDifferentLengths() external { + address[] memory initiativesToReset = new address[](0); + address[][2] memory initiatives = [new address[](2), new address[](3)]; + int256[][2] memory votes = [new int256[](2), new int256[](3)]; + int256[][2] memory vetos = [new int256[](2), new int256[](3)]; + + for (uint256 i = 0; i < 2; ++i) { + for (uint256 j = 0; j < 2; ++j) { + for (uint256 k = 0; k < 2; ++k) { + if (i == j && j == k) continue; + + vm.expectRevert("Governance: array-length-mismatch"); + governance.allocateLQTY(initiativesToReset, initiatives[i], votes[j], vetos[k]); + } + } + } + } + function test_allocateLQTY_single() public { vm.startPrank(user);