Skip to content
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

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

crisgarner
Copy link
Collaborator

Description

A gatekeeper contract which allows users to sign up to MACI only if they are part of the tree

Confirmation

Copy link

vercel bot commented Sep 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
maci-website ✅ Ready (Inspect) Visit Preview Sep 11, 2024 5:58pm

Comment on lines 12 to 71
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 locking ether found:
Contract MerkleProofGatekeeper has payable functions:
- MerkleProofGatekeeper.constructor(bytes32)
But does not have a function to withdraw the ether

/// @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

Copy link
Collaborator

@ctrlc03 ctrlc03 left a 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

@crisgarner
Copy link
Collaborator Author

Thanks, left some comments

Thanks! added the fixes.

Copy link
Collaborator

@ctrlc03 ctrlc03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@ctrlc03 ctrlc03 merged commit 1cce59a into dev Sep 11, 2024
22 checks passed
@ctrlc03 ctrlc03 deleted the feat/merkle-gatekeeper branch September 11, 2024 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants