all files / contracts/interfaces/ IUnirep.sol

100% Statements 0/0
100% Branches 0/0
100% Functions 0/0
100% Lines 0/0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132                                                                                                                                                                                                                                                                       
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
 
import {IncrementalBinaryTree, IncrementalTreeData} from '@zk-kit/incremental-merkle-tree.sol/IncrementalBinaryTree.sol';
import {ReusableMerkleTree, ReusableTreeData} from '../libraries/ReusableMerkleTree.sol';
import {LazyMerkleTree, LazyTreeData} from '../libraries/LazyMerkleTree.sol';
 
/// @title IUnirep
/// @dev https://developer.unirep.io/docs/contracts-api/iunirep-sol
interface IUnirep {
    event AttesterSignedUp(
        uint160 indexed attesterId,
        uint48 epochLength,
        uint48 timestamp
    );
 
    event UserSignedUp(
        uint48 indexed epoch,
        uint256 indexed identityCommitment,
        uint160 indexed attesterId,
        uint256 leafIndex
    );
 
    event UserStateTransitioned(
        uint48 indexed epoch,
        uint160 indexed attesterId,
        uint256 indexed leafIndex,
        uint256 hashedLeaf,
        uint256 nullifier
    );
 
    event Attestation(
        uint48 indexed epoch,
        uint256 indexed epochKey,
        uint160 indexed attesterId,
        uint256 fieldIndex,
        uint256 change
    );
 
    event StateTreeLeaf(
        uint48 indexed epoch,
        uint160 indexed attesterId,
        uint256 indexed index,
        uint256 leaf
    );
 
    event EpochTreeLeaf(
        uint48 indexed epoch,
        uint160 indexed attesterId,
        uint256 indexed index,
        uint256 leaf
    );
 
    event HistoryTreeLeaf(uint160 indexed attesterId, uint256 leaf);
 
    event EpochEnded(uint48 indexed epoch, uint160 indexed attesterId);
 
    // error
    error UserAlreadySignedUp(uint256 identityCommitment);
    error AttesterAlreadySignUp(uint160 attester);
    error AttesterNotSignUp(uint160 attester);
    error AttesterInvalid();
    error NullifierAlreadyUsed(uint256 nullilier);
    error AttesterIdNotMatch(uint160 attesterId);
    error OutOfRange();
    error InvalidField();
    error EpochKeyNotProcessed();
 
    error InvalidSignature();
    error InvalidEpochKey();
    error EpochNotMatch();
    error InvalidEpoch(uint256 epoch);
    error ChainIdNotMatch(uint48 chainId);
 
    error InvalidProof();
    error InvalidHistoryTreeRoot(uint256 historyTreeRoot);
 
    struct SignupSignals {
        uint48 epoch;
        uint48 chainId;
        uint160 attesterId;
        uint256 stateTreeLeaf;
        uint256 identityCommitment;
    }
 
    struct UserStateTransitionSignals {
        uint256 historyTreeRoot;
        uint256 stateTreeLeaf;
        uint48 toEpoch;
        uint160 attesterId;
        uint256[] epochKeys;
    }
 
    struct EpochKeyData {
        uint40 leafIndex;
        uint48 epoch;
        uint256 leaf;
        // use a constant because compile time variables are not supported
        uint256[128] data;
    }
 
    struct AttesterData {
        uint48 startTimestamp;
        uint48 currentEpoch;
        uint48 epochLength;
        // epoch keyed to root keyed to whether it's valid
        mapping(uint256 => mapping(uint256 => bool)) stateTreeRoots;
        mapping(uint256 => bool) historyTreeRoots;
        // epoch keyed to root
        mapping(uint256 => uint256) epochTreeRoots;
        mapping(uint256 => bool) identityCommitments;
        IncrementalTreeData semaphoreGroup;
        // epoch key management
        mapping(uint256 => EpochKeyData) epkData;
        IncrementalTreeData historyTree;
        ReusableTreeData stateTree;
        LazyTreeData epochTree;
    }
 
    struct Config {
        // circuit config
        uint8 stateTreeDepth;
        uint8 epochTreeDepth;
        uint8 historyTreeDepth;
        uint8 fieldCount;
        uint8 sumFieldCount;
        uint8 numEpochKeyNoncePerEpoch;
        uint8 replNonceBits;
        uint8 replFieldBits;
    }
}