Skip to content

Commit dd6cc22

Browse files
JohnGuilding0xmad
authored andcommitted
fix: maci 12 account can vote unlimited times in free for all policy
1 parent c3d2ea9 commit dd6cc22

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/contracts/contracts/extensions/freeForAll/FreeForAllPolicy.sol

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,28 @@ pragma solidity ^0.8.20;
44
import {BasePolicy} from "../../policy/BasePolicy.sol";
55

66
/// @title FreeForAllPolicy
7-
/// @notice A policy which allows anyone to sign up.
7+
/// @notice A policy which allows anyone to sign up, but only once per address.
88
contract FreeForAllPolicy is BasePolicy {
9+
/// @notice Store the addreses that have been enforced
10+
mapping(address => bool) public enforcedUsers;
11+
912
/// @notice Create a new instance of FreeForAllPolicy
1013
// solhint-disable-next-line no-empty-blocks
1114
constructor() payable {}
1215

16+
/// @notice Enforce a user so they can only be enforced once
17+
/// @param subject The user's Ethereum address.
18+
/// @param evidence The ABI-encoded evidence data.
19+
function _enforce(address subject, bytes calldata evidence) internal override {
20+
if (enforcedUsers[subject]) {
21+
revert AlreadyEnforced();
22+
}
23+
24+
enforcedUsers[subject] = true;
25+
26+
super._enforce(subject, evidence);
27+
}
28+
1329
/// @notice Get the trait of the Policy
1430
/// @return The type of the Policy
1531
function trait() public pure override returns (string memory) {

packages/contracts/test/extensions/FreeForAll.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,11 @@ describe("FreeForAll", () => {
7979

8080
expect(receipt?.status).to.eq(1)
8181
})
82+
83+
it("should prevent enforcing the same account twice", async () => {
84+
await expect(
85+
policy.connect(target).enforce(subject, AbiCoder.defaultAbiCoder().encode([], []))
86+
).to.be.revertedWithCustomError(policy, "AlreadyEnforced")
87+
})
8288
})
8389
})

0 commit comments

Comments
 (0)