Skip to content
Lattice

ISemaphore

Git Source

Title: ISemaphore

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Semaphore (https://github.com/semaphore-protocol/semaphore)

External interface for the Semaphore anonymous-membership / signaling module. Members join a group (a Poseidon incremental Merkle tree of identity commitments) and later prove membership in zero knowledge while broadcasting a message under a scope — without revealing which member they are. A per-(group) nullifier prevents the same identity from signaling twice in a scope.

Wraps the audited Semaphore v4 Groth16 verifier (called via setVerifier). Group membership uses the shared incremental Merkle tree (Poseidon LeanIMT) with a recent-root history, so a proof built against a slightly stale root still validates.

Functions

createGroup

Creates a new group administered by the caller.

function createGroup() external returns (uint256 groupId);

Returns

NameTypeDescription
groupIduint256The new group id.

createGroup

Creates a new group administered by admin.

function createGroup(address admin) external returns (uint256 groupId);

Parameters

NameTypeDescription
adminaddressThe group admin (may add members).

Returns

NameTypeDescription
groupIduint256The new group id.

addMember

Adds a member (identity commitment) to a group. Only the group admin.

function addMember(uint256 groupId, uint256 identityCommitment) external;

Parameters

NameTypeDescription
groupIduint256The group id.
identityCommitmentuint256The member's identity commitment.

addMembers

Adds many members to a group. Only the group admin.

function addMembers(uint256 groupId, uint256[] calldata identityCommitments) external;

Parameters

NameTypeDescription
groupIduint256The group id.
identityCommitmentsuint256[]The members' identity commitments, in order.

validateProof

Validates a proof against a group and consumes its nullifier (state-changing).

Reverts if the group/depth/root/nullifier checks fail or the proof is invalid.

function validateProof(uint256 groupId, SemaphoreProof calldata proof) external;

Parameters

NameTypeDescription
groupIduint256The group id.
proofSemaphoreProofThe Semaphore proof.

verifyProof

Verifies a proof against a group WITHOUT consuming the nullifier.

function verifyProof(uint256 groupId, SemaphoreProof calldata proof) external view returns (bool);

Parameters

NameTypeDescription
groupIduint256The group id.
proofSemaphoreProofThe Semaphore proof.

Returns

NameTypeDescription
<none>boolTrue iff the proof is valid for the group.

setVerifier

Sets the Semaphore verifier contract. Gated on the default admin role.

function setVerifier(address verifier) external;

Parameters

NameTypeDescription
verifieraddressThe ISemaphoreVerifier address.

groupCount

Returns the number of groups created.

function groupCount() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256

groupAdmin

Returns the admin of groupId.

function groupAdmin(uint256 groupId) external view returns (address);

Parameters

NameTypeDescription
groupIduint256

Returns

NameTypeDescription
<none>address

getMerkleTreeRoot

Returns the current Merkle root of groupId.

function getMerkleTreeRoot(uint256 groupId) external view returns (uint256);

Parameters

NameTypeDescription
groupIduint256

Returns

NameTypeDescription
<none>uint256

getMerkleTreeSize

Returns the number of members in groupId.

function getMerkleTreeSize(uint256 groupId) external view returns (uint256);

Parameters

NameTypeDescription
groupIduint256

Returns

NameTypeDescription
<none>uint256

hasMember

Returns whether identityCommitment is a member of groupId.

function hasMember(uint256 groupId, uint256 identityCommitment) external view returns (bool);

Parameters

NameTypeDescription
groupIduint256
identityCommitmentuint256

Returns

NameTypeDescription
<none>bool

verifier

Returns the configured Semaphore verifier address.

function verifier() external view returns (address);

Returns

NameTypeDescription
<none>address

Events

GroupCreated

Emitted when a group is created.

event GroupCreated(uint256 indexed groupId, address indexed admin);

Parameters

NameTypeDescription
groupIduint256
adminaddress

MemberAdded

Emitted when a member is added to a group.

event MemberAdded(uint256 indexed groupId, uint256 index, uint256 identityCommitment, uint256 merkleTreeRoot);

Parameters

NameTypeDescription
groupIduint256
indexuint256
identityCommitmentuint256
merkleTreeRootuint256

ProofValidated

Emitted when a proof is validated against a group.

event ProofValidated(
        uint256 indexed groupId,
        uint256 merkleTreeDepth,
        uint256 indexed merkleTreeRoot,
        uint256 nullifier,
        uint256 message,
        uint256 indexed scope,
        uint256[8] points
    );

Parameters

NameTypeDescription
groupIduint256
merkleTreeDepthuint256
merkleTreeRootuint256
nullifieruint256
messageuint256
scopeuint256
pointsuint256[8]

VerifierUpdated

Emitted when the Semaphore verifier address is set.

event VerifierUpdated(address verifier);

Parameters

NameTypeDescription
verifieraddress

Errors

SemaphoreGroupDoesNotExist

Thrown when operating on a group that does not exist.

error SemaphoreGroupDoesNotExist();

SemaphoreCallerIsNotGroupAdmin

Thrown when the caller is not the group admin.

error SemaphoreCallerIsNotGroupAdmin();

SemaphoreGroupHasNoMembers

Thrown when validating a proof against a group with no members.

error SemaphoreGroupHasNoMembers();

SemaphoreMerkleTreeDepthUnsupported

Thrown when the proof's Merkle tree depth is outside the supported range (1..32).

error SemaphoreMerkleTreeDepthUnsupported();

SemaphoreMerkleTreeRootNotInGroup

Thrown when the proof's Merkle root is not a current or recent root of the group.

error SemaphoreMerkleTreeRootNotInGroup();

SemaphoreNullifierAlreadyUsed

Thrown when the proof's nullifier was already used in the group.

error SemaphoreNullifierAlreadyUsed();

SemaphoreInvalidProof

Thrown when proof verification fails.

error SemaphoreInvalidProof();

SemaphoreVerifierNotSet

Thrown when the verifier address has not been set.

error SemaphoreVerifierNotSet();

SemaphoreVerifierIsZero

Thrown when setting the verifier to the zero address.

error SemaphoreVerifierIsZero();

Structs

SemaphoreProof

A Semaphore proof.

struct SemaphoreProof {
        uint256 merkleTreeDepth;
        uint256 merkleTreeRoot;
        uint256 nullifier;
        uint256 message;
        uint256 scope;
        uint256[8] points;
    }

Properties

NameTypeDescription
merkleTreeDepthuint256The depth of the tree the proof was generated against (1..32).
merkleTreeRootuint256The group Merkle root the proof was generated against.
nullifieruint256The scope nullifier (prevents double-signaling within a scope).
messageuint256The signaled message.
scopeuint256The scope the proof is bound to.
pointsuint256[8]The Groth16 proof points (pA, pB, pC flattened to 8 words).