-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathUnirepApp.sol
74 lines (63 loc) · 1.81 KB
/
UnirepApp.sol
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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import { Unirep } from "@unirep/contracts/Unirep.sol";
// Uncomment this line to use console.log
// import "hardhat/console.sol";
interface IVerifier {
function verifyProof(
uint256[5] calldata publicSignals,
uint256[8] calldata proof
) external view returns (bool);
}
contract UnirepApp {
Unirep public unirep;
IVerifier internal dataVerifier;
constructor(Unirep _unirep, IVerifier _dataVerifier, uint48 _epochLength) {
// set unirep address
unirep = _unirep;
// set verifier address
dataVerifier = _dataVerifier;
// sign up as an attester
unirep.attesterSignUp(_epochLength);
}
// sign up users in this app
function userSignUp(
uint256[] memory publicSignals,
uint256[8] memory proof
) public {
unirep.userSignUp(publicSignals, proof);
}
function submitManyAttestations(
uint256 epochKey,
uint48 targetEpoch,
uint[] calldata fieldIndices,
uint[] calldata vals
) public {
require(fieldIndices.length == vals.length, 'arrmismatch');
for (uint8 x = 0; x < fieldIndices.length; x++) {
unirep.attest(epochKey, targetEpoch, fieldIndices[x], vals[x]);
}
}
function submitAttestation(
uint256 epochKey,
uint48 targetEpoch,
uint256 fieldIndex,
uint256 val
) public {
unirep.attest(
epochKey,
targetEpoch,
fieldIndex,
val
);
}
function verifyDataProof(
uint256[5] calldata publicSignals,
uint256[8] calldata proof
) public view returns(bool) {
return dataVerifier.verifyProof(
publicSignals,
proof
);
}
}