-
Notifications
You must be signed in to change notification settings - Fork 18
/
Risc0Dapp.sol
51 lines (40 loc) · 1.54 KB
/
Risc0Dapp.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
interface IRisc0Receiver {
function verify(bytes calldata seal, bytes32 imageId, bytes32 journalDigest) external view;
}
contract Risc0Dapp {
bytes public proof;
bytes public proof_seal;
bytes32 public proof_journal;
uint256 public projectId;
uint256 public proverId;
string public clientId;
// risc0 verification contract
address private risc0Verifier;
mapping(uint256 => bytes32) private projectIdToImageId;
function process(uint256 _projectId, uint256 _proverId, string memory _clientId, bytes calldata _data) public {
projectId = _projectId;
proverId = _proverId;
clientId = _clientId;
proof = _data;
(bytes memory proof_snark_seal, bytes memory proof_snark_journal) = abi.decode(_data, (bytes, bytes));
proof_seal = proof_snark_seal;
proof_journal = sha256(proof_snark_journal);
// verify zk proof
IRisc0Receiver(risc0Verifier).verify(proof_seal, projectIdToImageId[projectId], proof_journal);
// TODO
}
function setProjectIdToImageId(uint256 _projectId, bytes32 _imageId) public {
projectIdToImageId[_projectId] = _imageId;
}
function getImageIdByProjectId(uint256 _projectId) public view returns (bytes32) {
return projectIdToImageId[_projectId];
}
function setReceiver(address _receiver) public {
risc0Verifier = _receiver;
}
function getReceiver() public view returns (address ){
return risc0Verifier;
}
}