Skip to content

Commit 62bfb60

Browse files
committed
feat: ProofAggregationService risc0 verification
1 parent 2f54502 commit 62bfb60

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@
3434
[submodule "contracts/lib/sp1-contracts"]
3535
path = contracts/lib/sp1-contracts
3636
url = https://github.com/succinctlabs/sp1-contracts
37+
[submodule "contracts/lib/risc0-ethereum"]
38+
path = contracts/lib/risc0-ethereum
39+
url = https://github.com/risc0/risc0-ethereum

contracts/lib/risc0-ethereum

Submodule risc0-ethereum added at 728ec4b

contracts/remappings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ forge-std/=lib/forge-std/src/
66
@openzeppelin/contracts/=lib/eigenlayer-middleware/lib/openzeppelin-contracts/contracts/
77
@openzeppelin-upgrades/contracts/=lib/eigenlayer-middleware/lib/openzeppelin-contracts-upgradeable/contracts/
88
@sp1-contracts/=lib/sp1-contracts/contracts/src/
9+
@risc0-contracts/=lib/risc0-ethereum/contracts/src/

contracts/src/core/AlignedProofAggregationService.sol

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import {OwnableUpgradeable} from "@openzeppelin-upgrades/contracts/access/Ownabl
66
import {UUPSUpgradeable} from "@openzeppelin-upgrades/contracts/proxy/utils/UUPSUpgradeable.sol";
77
import {IAlignedProofAggregationService} from "./IAlignedProofAggregationService.sol";
88
import {ISP1Verifier} from "@sp1-contracts/ISP1Verifier.sol";
9+
import {IRiscZeroVerifier} from "@risc0-contracts/IRiscZeroVerifier.sol";
910

1011
contract AlignedProofAggregationService is
1112
IAlignedProofAggregationService,
1213
Initializable,
1314
OwnableUpgradeable,
1415
UUPSUpgradeable
1516
{
16-
1717
/// @notice Map the merkle root to a boolean to indicate it was verified
1818
mapping(bytes32 => bool) public aggregatedProofs;
1919

@@ -24,6 +24,8 @@ contract AlignedProofAggregationService is
2424
/// https://docs.succinct.xyz/onchain-verification/contract-addresses
2525
address public sp1VerifierAddress;
2626

27+
address public risc0VerifierAddress;
28+
2729
/// @notice The address of the Wallet that is allowed to call the verify function.
2830
address public alignedAggregatorAddress;
2931

@@ -46,7 +48,7 @@ contract AlignedProofAggregationService is
4648
sp1VerifierAddress = _sp1VerifierAddress;
4749
}
4850

49-
function verify(
51+
function verifySP1(
5052
bytes32 blobVersionedHash,
5153
bytes32 sp1ProgramVKey,
5254
bytes calldata sp1PublicValues,
@@ -55,18 +57,40 @@ contract AlignedProofAggregationService is
5557
(bytes32 merkleRoot) = abi.decode(sp1PublicValues, (bytes32));
5658

5759
// In dev mode, poofs are mocked, so we skip the verification part
58-
if (_isVerificationEnabled()) {
60+
if (_isSP1VerificationEnabled()) {
5961
ISP1Verifier(sp1VerifierAddress).verifyProof(sp1ProgramVKey, sp1PublicValues, sp1ProofBytes);
6062
}
6163

6264
aggregatedProofs[merkleRoot] = true;
6365
emit AggregatedProofVerified(merkleRoot, blobVersionedHash);
6466
}
6567

66-
function _isVerificationEnabled() internal view returns (bool) {
68+
function verifyRisc0(
69+
bytes32 blobVersionedHash,
70+
bytes calldata risc0ReceiptSeal,
71+
bytes32 risc0ImageId,
72+
bytes calldata risc0JournalBytes
73+
) public onlyAlignedAggregator {
74+
(bytes32 merkleRoot) = abi.decode(risc0JournalBytes, (bytes32));
75+
76+
// In dev mode, poofs are mocked, so we skip the verification part
77+
if (_isRisc0VerificationEnabled()) {
78+
bytes32 risc0JournalDigest = sha256(risc0JournalBytes);
79+
IRiscZeroVerifier(risc0VerifierAddress).verify(risc0ReceiptSeal, risc0ImageId, risc0JournalDigest);
80+
}
81+
82+
aggregatedProofs[merkleRoot] = true;
83+
emit AggregatedProofVerified(merkleRoot, blobVersionedHash);
84+
}
85+
86+
function _isSP1VerificationEnabled() internal view returns (bool) {
6787
return sp1VerifierAddress != VERIFIER_MOCK_ADDRESS;
6888
}
6989

90+
function _isRisc0VerificationEnabled() internal view returns (bool) {
91+
return risc0VerifierAddress != VERIFIER_MOCK_ADDRESS;
92+
}
93+
7094
function _authorizeUpgrade(address newImplementation)
7195
internal
7296
override
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
pragma solidity ^0.8.12;
22

33
interface IAlignedProofAggregationService {
4-
54
/// @notice Method to verify an aggregated proof from aligned
65
/// @dev This function is called by the aligned proof aggregator after collecting the proofs and aggregating them
76
/// to be verified on-chain. We expect the blobTransactionHash to be called before
87
/// @param blobVersionedHash the versioned hash of the blob transaction that contains the leaves that compose the merkle root.
98
/// @param sp1ProgramVKey Public verifying key
109
/// @param sp1PublicValues Values used to perform the execution
1110
/// @param sp1ProofBytes Groth16 proof
12-
function verify(
11+
function verifySP1(
1312
bytes32 blobVersionedHash,
1413
bytes32 sp1ProgramVKey,
1514
bytes calldata sp1PublicValues,
1615
bytes calldata sp1ProofBytes
1716
) external;
1817

18+
function verifyRisc0(
19+
bytes32 blobVersionedHash,
20+
bytes calldata risc0ReceiptSeal,
21+
bytes32 risc0ImageId,
22+
bytes calldata risc0JournalBytes
23+
) external;
24+
1925
/// @notice event that gets emitted after a successful aggregated proof verification
20-
event AggregatedProofVerified(
21-
bytes32 indexed merkleRoot, bytes32 blobVersionedHash
22-
);
26+
event AggregatedProofVerified(bytes32 indexed merkleRoot, bytes32 blobVersionedHash);
2327

2428
error OnlyAlignedAggregator(address sender);
2529
}

0 commit comments

Comments
 (0)