-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathHalo2Dapp.sol
47 lines (36 loc) · 1.53 KB
/
Halo2Dapp.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
contract Halo2Dapp {
uint256 constant bn254Prime = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
// halo2 verification contract
address private halo2Verifier;
uint256 public projectId;
uint256 public proverId;
string public clientId;
bytes public data;
function setReceiver(address _receiver) public {
halo2Verifier = _receiver;
}
function getReceiver() public view returns (address ){
return halo2Verifier;
}
// verifier is the verify contract, it was generated by circuit.
function process(uint256 _projectId, uint256 _proverId, string memory _clientId, bytes calldata _data) public {
require(halo2Verifier != address(0), "verifier address not set");
projectId = _projectId;
proverId = _proverId;
clientId = _clientId;
data = _data;
(uint256 publicInput, uint256 taskID, bytes memory _proof) = abi.decode(_data, (uint256, uint256, bytes));
bytes32 _publicInput = uint256ToFr(publicInput);
bytes32 _taskID = uint256ToFr(taskID);
bytes32 _projectID = uint256ToFr(projectId);
bytes memory callData = abi.encodePacked(_publicInput, _projectID, _taskID, _proof);
(bool success,) = halo2Verifier.staticcall(callData);
require(success, "Failed to verify proof");
// TODO
}
function uint256ToFr(uint256 _value) public pure returns (bytes32) {
return bytes32(_value % bn254Prime);
}
}