Skip to content

Commit

Permalink
Merge branch 'feature/multisig-improvements' into feat/add-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
novaknole committed Sep 23, 2024
2 parents 6f84d88 + 6b6fa6f commit 33910d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
40 changes: 22 additions & 18 deletions packages/contracts/src/Multisig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {IMultisig} from "./IMultisig.sol";
/// @title Multisig
/// @author Aragon X - 2022-2023
/// @notice The on-chain multisig governance plugin in which a proposal passes if X out of Y approvals are met.
/// @dev v1.3 (Release 1, Build 3)
/// @dev v1.3 (Release 1, Build 3). For each upgrade, if the reinitialization step is required, increment the version numbers in the modifier for both the initialize and initializeFrom functions.

Check failure on line 22 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / checks

Line length must be no more than 120 but current length is 195

Check failure on line 22 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 195

Check failure on line 22 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 195
/// @custom:security-contact [email protected]
contract Multisig is
IMultisig,
Expand All @@ -46,8 +46,7 @@ contract Multisig is
mapping(address => bool) approvers;
IDAO.Action[] actions;
uint256 allowFailureMap;
address target; // added in v1.3.0
Operation operation; // added in v1.3.0
TargetConfig targetConfig; // added in build 3.
}

/// @notice A container for the proposal parameters.
Expand Down Expand Up @@ -103,6 +102,9 @@ contract Multisig is
/// @param sender The sender address.
error ProposalCreationForbidden(address sender);

/// @notice Thrown when initialize is called after it has already been executed.
error AlreadyInitialized();

/// @notice Thrown if an approver is not allowed to cast an approve. This can be because the proposal
/// - is not open,
/// - was executed, or
Expand Down Expand Up @@ -145,6 +147,15 @@ contract Multisig is
/// @param minApprovals The minimum amount of approvals needed to pass a proposal.
event MultisigSettingsUpdated(bool onlyListed, uint16 indexed minApprovals);

/// @notice This ensures that the initialize function cannot be called during the upgrade process.
modifier onlyCallAtInitialization() {
if (_getInitializedVersion() != 0) {
revert AlreadyInitialized();
}

_;
}

/// @notice Initializes Release 1, Build 2.
/// @dev This method is required to support [ERC-1822](https://eips.ethereum.org/EIPS/eip-1822).
/// @param _dao The IDAO interface of the associated DAO.
Expand All @@ -155,7 +166,7 @@ contract Multisig is
address[] calldata _members,
MultisigSettings calldata _multisigSettings,
TargetConfig calldata _targetConfig
) external reinitializer(2) {
) external onlyCallAtInitialization reinitializer(2) {
__PluginUUPSUpgradeable_init(_dao);

if (_members.length > type(uint16).max) {
Expand All @@ -170,7 +181,8 @@ contract Multisig is
_setTargetConfig(_targetConfig);
}

/// @notice Reinitializes the TokenVoting after an upgrade from a previous protocol version.
/// @notice Reinitializes the TokenVoting after an upgrade from a previous protocol version. For each reinitialization step, use the `_fromBuild` version to decide which internal functions to call for reinitialization.

Check failure on line 184 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / checks

Line length must be no more than 120 but current length is 222

Check failure on line 184 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 222

Check failure on line 184 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 222
/// @dev WARNING: The contract should only be upgradeable through PSP to ensure that _fromBuild is not incorrectly passed, and that the appropriate permissions for the upgrade are properly configured.

Check failure on line 185 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / checks

Line length must be no more than 120 but current length is 204

Check failure on line 185 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 204

Check failure on line 185 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 204
/// @param _fromBuild The build version number of the previous implementation contract this upgrade is transitioning from.

Check failure on line 186 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / checks

Line length must be no more than 120 but current length is 126

Check failure on line 186 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 126

Check failure on line 186 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 126
/// @param _initData The initialization data to be passed to via `upgradeToAndCall` (see [ERC-1967](https://docs.openzeppelin.com/contracts/4.x/api/proxy#ERC1967Upgrade)).

Check failure on line 187 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / checks

Line length must be no more than 120 but current length is 175

Check failure on line 187 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 175

Check failure on line 187 in packages/contracts/src/Multisig.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 175
function initializeFrom(uint16 _fromBuild, bytes calldata _initData) external reinitializer(2) {
Expand Down Expand Up @@ -302,15 +314,7 @@ contract Multisig is
proposal_.parameters.endDate = _endDate;
proposal_.parameters.minApprovals = multisigSettings.minApprovals;

TargetConfig memory currentTarget = getTargetConfig();

if (currentTarget.target == address(0)) {
proposal_.target = address(dao());
proposal_.operation = Operation.Call;
} else {
proposal_.target = currentTarget.target;
proposal_.operation = currentTarget.operation;
}
proposal_.targetConfig = getTargetConfig();

// Reduce costs
if (_allowFailureMap != 0) {
Expand Down Expand Up @@ -462,11 +466,11 @@ contract Multisig is
proposal_.executed = true;

_execute(
proposal_.target,
proposal_.targetConfig.target,
bytes32(_proposalId),
proposals[_proposalId].actions,
proposals[_proposalId].allowFailureMap,
proposal_.operation
proposal_.actions,
proposal_.allowFailureMap,
proposal_.targetConfig.operation
);

emit ProposalExecuted(_proposalId);
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/test/10_unit-testing/11_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('Multisig', function () {
defaultInitData.settings,
defaultInitData.targetConfig
)
).to.be.revertedWith('Initializable: contract is already initialized');
).to.be.revertedWithCustomError(initializedPlugin, 'AlreadyInitialized');
});

it('adds the initial addresses to the address list', async () => {
Expand Down

0 comments on commit 33910d9

Please sign in to comment.