-
Notifications
You must be signed in to change notification settings - Fork 138
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 #1820
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 attestation is not valid or just complete silently | ||
/// @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
/// only if they've received an attestation of a specific schema from a trusted attester | ||
contract MerkleProofGatekeeper is SignUpGatekeeper, Ownable(msg.sender) { | ||
// the merkle tree root | ||
bytes32 public root; |
Check warning
Code scanning / Slither
State variables that could be declared immutable Warning
|
||
/// @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 attestation is not valid or just complete silently | ||
/// @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 attestation is not valid or just complete silently | ||
/// @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
Description
Adds a Merkle Proof gatekeeper to allow users that are part of the tree to signup.
Confirmation