Skip to content

Commit eb8ca7a

Browse files
committed
fix: address tmnt 148
1 parent 262591f commit eb8ca7a

4 files changed

Lines changed: 16 additions & 1 deletion

File tree

l1-contracts/src/governance/Governance.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ contract Governance is IGovernance {
352352
*/
353353
function finaliseWithdraw(uint256 _withdrawalId) external override(IGovernance) {
354354
Withdrawal storage withdrawal = withdrawals[_withdrawalId];
355+
// This is a sanity check, the `recipient` will only be zero for a non-existent withdrawal, so this avoids
356+
// `finalise`ing non-existent withdrawals. Note, that `_initiateWithdraw` will fail if `_to` is `address(0)`
357+
require(withdrawal.recipient != address(0), Errors.Governance__WithdrawalNotInitiated());
355358
require(!withdrawal.claimed, Errors.Governance__WithdrawalAlreadyClaimed());
356359
require(
357360
Timestamp.wrap(block.timestamp) >= withdrawal.unlocksAt,
@@ -692,6 +695,7 @@ contract Governance is IGovernance {
692695
* @return The id of the withdrawal.
693696
*/
694697
function _initiateWithdraw(address _from, address _to, uint256 _amount, Timestamp _delay) internal returns (uint256) {
698+
require(_to != address(0), Errors.Governance__CannotWithdrawToAddressZero());
695699
users[_from].sub(_amount);
696700
total.sub(_amount);
697701

l1-contracts/src/governance/libraries/Errors.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ library Errors {
1919
error Governance__NoCheckpointsFound();
2020
error Governance__InsufficientPower(address voter, uint256 have, uint256 required);
2121
error Governance__InvalidConfiguration();
22+
error Governance__CannotWithdrawToAddressZero();
23+
error Governance__WithdrawalNotInitiated();
2224
error Governance__WithdrawalAlreadyClaimed();
2325
error Governance__WithdrawalNotUnlockedYet(Timestamp currentTime, Timestamp unlocksAt);
2426
error Governance__ProposalNotActive();

l1-contracts/test/governance/governance/finaliseWithdraw.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ contract FinaliseWithdrawTest is GovernanceBase {
1818

1919
function test_WhenIdMatchNoPendingWithdrawal(uint256 _id) external {
2020
// it revert
21-
vm.expectRevert(abi.encodeWithSelector(IERC20Errors.ERC20InvalidReceiver.selector, address(0)));
21+
vm.expectRevert(abi.encodeWithSelector(Errors.Governance__WithdrawalNotInitiated.selector));
2222
governance.finaliseWithdraw(_id);
2323
}
2424

l1-contracts/test/governance/governance/initiateWithdraw.t.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ contract InitiateWithdrawTest is GovernanceBase {
1717
_;
1818
}
1919

20+
function test_WhenToIsAddressZero() external {
21+
vm.expectRevert(abi.encodeWithSelector(Errors.Governance__CannotWithdrawToAddressZero.selector));
22+
governance.initiateWithdraw(address(0), 1);
23+
}
24+
2025
function test_GivenNoCheckpoints(uint256 _amount) external whenCallerHaveInsufficientDeposits {
2126
// it revert
2227
uint256 amount = bound(_amount, 1, type(uint224).max);
@@ -62,6 +67,10 @@ contract InitiateWithdrawTest is GovernanceBase {
6267
// it creates a pending withdrawal with time of unlock
6368
// it emits {WithdrawalInitiated} event
6469

70+
for (uint256 i = 0; i < WITHDRAWAL_COUNT; i++) {
71+
vm.assume(_recipient[i] != address(0));
72+
}
73+
6574
uint256 deposit = bound(_activationThreshold, 1, type(uint224).max);
6675
uint256 sum = deposit;
6776
uint256 withdrawalId = 0;

0 commit comments

Comments
 (0)