Skip to content

Commit 95c296f

Browse files
committed
chore: reject gov deposit into gov
1 parent a34ff5e commit 95c296f

File tree

5 files changed

+76
-4
lines changed

5 files changed

+76
-4
lines changed

l1-contracts/src/governance/Governance.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ contract Governance is IGovernance {
233233
* @dev Modifier to ensure that the beneficiary is allowed to hold power in Governance.
234234
*/
235235
modifier isDepositAllowed(address _beneficiary) {
236+
require(msg.sender != address(this), Errors.Governance__CallerCannotBeSelf());
236237
require(
237238
depositControl.allBeneficiariesAllowed || depositControl.isAllowed[_beneficiary],
238239
Errors.Governance__DepositNotAllowed()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ library Errors {
1616
error Governance__CallerNotGovernanceProposer(address caller, address governanceProposer);
1717
error Governance__GovernanceProposerCannotBeSelf();
1818
error Governance__CallerNotSelf(address caller, address self);
19+
error Governance__CallerCannotBeSelf();
1920
error Governance__NoCheckpointsFound();
2021
error Governance__InsufficientPower(address voter, uint256 have, uint256 required);
2122
error Governance__InvalidConfiguration();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ contract GovernanceBase is TestBase {
121121
function _stateQueued(bytes32 _proposalName, address _voter, uint256 _totalPower, uint256 _votesCast, uint256 _yeas)
122122
internal
123123
{
124-
vm.assume(_voter != address(0));
124+
vm.assume(_voter != address(0) && _voter != address(governance));
125125
proposal = proposals[_proposalName];
126126
proposalId = proposalIds[_proposalName];
127127

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,28 @@ contract LimitedDepositTest is TestBase {
4040
function test_WhenNotAllowedToDeposit(address _caller, address _depositor) external {
4141
// it reverts
4242

43-
vm.assume(_caller != address(0) && _depositor != address(0));
43+
vm.assume(_caller != address(0) && _depositor != address(0) && _caller != address(governance));
4444
vm.assume(!governance.isPermittedInGovernance(_depositor));
4545

4646
vm.prank(_caller);
4747
vm.expectRevert(abi.encodeWithSelector(Errors.Governance__DepositNotAllowed.selector));
4848
governance.deposit(_depositor, 1000);
4949
}
5050

51+
function test_WhenNotAllowedToDepositSelf(address _depositor, bool _floodgatesOpen) external {
52+
if (_floodgatesOpen) {
53+
vm.prank(address(governance));
54+
governance.openFloodgates();
55+
}
56+
57+
vm.prank(address(governance));
58+
vm.expectRevert(abi.encodeWithSelector(Errors.Governance__CallerCannotBeSelf.selector));
59+
governance.deposit(_depositor, 1000);
60+
}
61+
5162
function test_WhenIsAllowedToDeposit(address _caller, address _depositor) external {
5263
// it deposits
53-
vm.assume(_caller != address(0) && _depositor != address(0));
64+
vm.assume(_caller != address(0) && _depositor != address(0) && _caller != address(governance));
5465

5566
vm.prank(address(governance));
5667
governance.addBeneficiary(_depositor);
@@ -69,7 +80,7 @@ contract LimitedDepositTest is TestBase {
6980
function test_WhenFloodgatesAreOpen(address _caller, address _depositor) external {
7081
// it deposits
7182

72-
vm.assume(_caller != address(0) && _depositor != address(0));
83+
vm.assume(_caller != address(0) && _depositor != address(0) && _caller != address(governance));
7384

7485
vm.prank(address(governance));
7586
governance.openFloodgates();
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity >=0.8.27;
3+
4+
import {TestBase} from "@test/base/Base.sol";
5+
import {TestERC20} from "@aztec/mock/TestERC20.sol";
6+
import {Governance} from "@aztec/governance/Governance.sol";
7+
import {GovernanceProposer} from "@aztec/governance/proposer/GovernanceProposer.sol";
8+
import {Registry} from "@aztec/governance/Registry.sol";
9+
import {IMintableERC20} from "@aztec/shared/interfaces/IMintableERC20.sol";
10+
import {TestGov} from "@test/governance/helpers/TestGov.sol";
11+
import {TestConstants} from "@test/harnesses/TestConstants.sol";
12+
import {IGSE} from "@aztec/governance/GSE.sol";
13+
import {Errors} from "@aztec/governance/libraries/Errors.sol";
14+
15+
contract OddERC20 is TestERC20 {
16+
constructor(string memory _name, string memory _symbol, address _owner) TestERC20(_name, _symbol, _owner) {}
17+
18+
function _spendAllowance(address owner, address spender, uint256 value) internal virtual override {
19+
if (owner == msg.sender) {
20+
return;
21+
}
22+
super._spendAllowance(owner, spender, value);
23+
}
24+
}
25+
26+
contract DepositTest is TestBase {
27+
IMintableERC20 internal token;
28+
Registry internal registry;
29+
Governance internal governance;
30+
GovernanceProposer internal governanceProposer;
31+
32+
function setUp() public {
33+
token = IMintableERC20(address(new OddERC20("test", "TEST", address(this))));
34+
35+
registry = new Registry(address(this), token);
36+
governanceProposer = new GovernanceProposer(registry, IGSE(address(0x03)), 677, 1000);
37+
38+
governance =
39+
new TestGov(token, address(governanceProposer), address(this), TestConstants.getGovernanceConfiguration());
40+
}
41+
42+
function test_when_calling_self() public {
43+
vm.prank(address(governance));
44+
governance.openFloodgates();
45+
46+
uint256 amount = 1000e18;
47+
token.mint(address(this), amount);
48+
token.approve(address(governance), amount);
49+
50+
governance.deposit(address(this), amount);
51+
assertEq(token.balanceOf(address(governance)), amount);
52+
53+
vm.prank(address(governance));
54+
vm.expectRevert(abi.encodeWithSelector(Errors.Governance__CallerCannotBeSelf.selector, address(governance)));
55+
governance.deposit(address(governance), amount);
56+
57+
assertEq(governance.powerNow(address(governance)), 0);
58+
}
59+
}

0 commit comments

Comments
 (0)