-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(merkleroot-gatekeeper): adds a gatekeeper that uses merkle tree #1821
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
contract MerkleProofGatekeeper is SignUpGatekeeper, Ownable(msg.sender) { | ||
// the merkle tree root | ||
bytes32 public root; | ||
|
||
/// @notice the reference to the MACI contract | ||
address public maci; | ||
|
||
// a mapping of addresses that have already registered | ||
mapping(address => bool) public registeredProofs; | ||
|
||
/// @notice custom errors | ||
error InvalidProof(); | ||
error AlreadyRegistered(); | ||
error OnlyMACI(); | ||
error ZeroAddress(); | ||
error InvalidRoot(); | ||
|
||
/// @notice Deploy an instance of MerkleProofGatekeeper | ||
/// @param _root The tree root | ||
constructor(bytes32 _root) payable { | ||
if (_root == bytes32(0)) revert InvalidRoot(); | ||
root = _root; | ||
} | ||
|
||
/// @notice Adds an uninitialised MACI instance to allow for token signups | ||
/// @param _maci The MACI contract interface to be stored | ||
function setMaciInstance(address _maci) public override onlyOwner { | ||
if (_maci == address(0)) revert ZeroAddress(); | ||
maci = _maci; | ||
} | ||
|
||
/// @notice Register an user based on being part of the tree | ||
/// @dev Throw if the proof is not valid or the user has already been registered | ||
/// @param _user The user's Ethereum address. | ||
/// @param _data The proof athat the user is part of the tree. | ||
function register(address _user, bytes memory _data) public override { | ||
// ensure that the caller is the MACI contract | ||
if (maci != msg.sender) revert OnlyMACI(); | ||
|
||
bytes32[] memory proof = abi.decode(_data, (bytes32[])); | ||
|
||
// ensure that the user has not been registered yet | ||
if (registeredProofs[_user]) revert AlreadyRegistered(); | ||
|
||
// register the user so it cannot be called again with the same one | ||
registeredProofs[_user] = true; | ||
|
||
// get the leaf | ||
bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(_user)))); | ||
|
||
// check the proof | ||
if (!MerkleProof.verify(proof, root, leaf)) revert InvalidProof(); | ||
} | ||
|
||
/// @notice Get the trait of the gatekeeper | ||
/// @return The type of the gatekeeper | ||
function getTrait() public pure override returns (string memory) { | ||
return "MerkleProof"; | ||
} | ||
} |
Check warning
Code scanning / Slither
Contracts that lock Ether Medium
Contract MerkleProofGatekeeper has payable functions:
- MerkleProofGatekeeper.constructor(bytes32)
But does not have a function to withdraw the ether
packages/contracts/contracts/gatekeepers/MerkleProofGatekeeper.sol
Fixed
Show resolved
Hide resolved
|
||
/// @notice Adds an uninitialised MACI instance to allow for token signups | ||
/// @param _maci The MACI contract interface to be stored | ||
function setMaciInstance(address _maci) public override onlyOwner { |
Check warning
Code scanning / Slither
Conformance to Solidity naming conventions Warning
/// @dev Throw if the proof is not valid or the user has already been registered | ||
/// @param _user The user's Ethereum address. | ||
/// @param _data The proof athat the user is part of the tree. | ||
function register(address _user, bytes memory _data) public override { |
Check warning
Code scanning / Slither
Conformance to Solidity naming conventions Warning
/// @dev Throw if the proof is not valid or the user has already been registered | ||
/// @param _user The user's Ethereum address. | ||
/// @param _data The proof athat the user is part of the tree. | ||
function register(address _user, bytes memory _data) public override { |
Check warning
Code scanning / Slither
Conformance to Solidity naming conventions Warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, left some comments
packages/contracts/contracts/gatekeepers/MerkleProofGatekeeper.sol
Fixed
Show resolved
Hide resolved
packages/contracts/contracts/gatekeepers/MerkleProofGatekeeper.sol
Outdated
Show resolved
Hide resolved
packages/contracts/contracts/gatekeepers/MerkleProofGatekeeper.sol
Outdated
Show resolved
Hide resolved
d78d663
to
5190955
Compare
5190955
to
f7fdba7
Compare
Thanks! added the fixes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Description
A gatekeeper contract which allows users to sign up to MACI only if they are part of the tree
Confirmation