Skip to content

Commit 5bb7011

Browse files
committed
feat: enforce image_id, vk_hash from solidity contract
1 parent 56122ad commit 5bb7011

File tree

4 files changed

+42
-32
lines changed

4 files changed

+42
-32
lines changed

aggregation_mode/abi/AlignedProofAggregationService.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

aggregation_mode/src/backend/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use config::Config;
2020
use fetcher::{ProofsFetcher, ProofsFetcherError};
2121
use merkle_tree::compute_proofs_merkle_root;
2222
use risc0_ethereum_contracts::encode_seal;
23-
use sp1_sdk::HashableKey;
2423
use std::str::FromStr;
2524
use tracing::{error, info, warn};
2625
use types::{AlignedProofAggregationService, AlignedProofAggregationServiceContract};
@@ -154,7 +153,6 @@ impl ProofAggregator {
154153
self.proof_aggregation_service
155154
.verifySP1(
156155
blob_versioned_hash.into(),
157-
proof.vk().bytes32_raw().into(),
158156
proof.proof_with_pub_values.public_values.to_vec().into(),
159157
proof.proof_with_pub_values.bytes().into(),
160158
)
@@ -170,7 +168,6 @@ impl ProofAggregator {
170168
.verifyRisc0(
171169
blob_versioned_hash.into(),
172170
encoded_seal.into(),
173-
proof.image_id.into(),
174171
proof.receipt.journal.bytes.into(),
175172
)
176173
.sidecar(blob)

contracts/src/core/AlignedProofAggregationService.sol

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ contract AlignedProofAggregationService is
3636
/// if the sp1 verifier address is set to this address, then we skip verification
3737
address public constant VERIFIER_MOCK_ADDRESS = address(0xFF);
3838

39+
/// The unique identifier (image ID) of the RISC Zero aggregator program.
40+
/// This ensures that only proofs generated by a trusted Risc0 program can be verified.
41+
bytes32 public risc0AggregatorProgramImageId;
42+
43+
/// The verification key hash for the SP1 aggregator program.
44+
/// This ensures that only proofs generated by a trusted SP1 program can be verified.
45+
bytes32 public sp1AggregatorProgramVKHash;
46+
3947
constructor() {
4048
_disableInitializers();
4149
}
@@ -44,45 +52,47 @@ contract AlignedProofAggregationService is
4452
address newOwner,
4553
address _alignedAggregatorAddress,
4654
address _sp1VerifierAddress,
47-
address _risc0VerifierAddress
55+
address _risc0VerifierAddress,
56+
bytes32 _risc0AggregatorProgramImageId,
57+
bytes32 _sp1AggregatorProgramVKHash
4858
) public initializer {
4959
__Ownable_init();
5060
__UUPSUpgradeable_init();
5161
_transferOwnership(newOwner);
5262
alignedAggregatorAddress = _alignedAggregatorAddress;
5363
sp1VerifierAddress = _sp1VerifierAddress;
5464
risc0VerifierAddress = _risc0VerifierAddress;
65+
risc0AggregatorProgramImageId = _risc0AggregatorProgramImageId;
66+
sp1AggregatorProgramVKHash = _sp1AggregatorProgramVKHash;
5567
}
5668

57-
function verifySP1(
58-
bytes32 blobVersionedHash,
59-
bytes32 sp1ProgramVKey,
60-
bytes calldata sp1PublicValues,
61-
bytes calldata sp1ProofBytes
62-
) public onlyAlignedAggregator {
69+
function verifySP1(bytes32 blobVersionedHash, bytes calldata sp1PublicValues, bytes calldata sp1ProofBytes)
70+
public
71+
onlyAlignedAggregator
72+
{
6373
(bytes32 merkleRoot) = abi.decode(sp1PublicValues, (bytes32));
6474

6575
// In dev mode, poofs are mocked, so we skip the verification part
6676
if (_isSP1VerificationEnabled()) {
67-
ISP1Verifier(sp1VerifierAddress).verifyProof(sp1ProgramVKey, sp1PublicValues, sp1ProofBytes);
77+
ISP1Verifier(sp1VerifierAddress).verifyProof(sp1AggregatorProgramVKHash, sp1PublicValues, sp1ProofBytes);
6878
}
6979

7080
aggregatedProofs[merkleRoot] = true;
7181
emit AggregatedProofVerified(merkleRoot, blobVersionedHash);
7282
}
7383

74-
function verifyRisc0(
75-
bytes32 blobVersionedHash,
76-
bytes calldata risc0ReceiptSeal,
77-
bytes32 risc0ImageId,
78-
bytes calldata risc0JournalBytes
79-
) public onlyAlignedAggregator {
84+
function verifyRisc0(bytes32 blobVersionedHash, bytes calldata risc0ReceiptSeal, bytes calldata risc0JournalBytes)
85+
public
86+
onlyAlignedAggregator
87+
{
8088
(bytes32 merkleRoot) = abi.decode(risc0JournalBytes, (bytes32));
8189

8290
// In dev mode, poofs are mocked, so we skip the verification part
8391
if (_isRisc0VerificationEnabled()) {
8492
bytes32 risc0JournalDigest = sha256(risc0JournalBytes);
85-
IRiscZeroVerifier(risc0VerifierAddress).verify(risc0ReceiptSeal, risc0ImageId, risc0JournalDigest);
93+
IRiscZeroVerifier(risc0VerifierAddress).verify(
94+
risc0ReceiptSeal, risc0AggregatorProgramImageId, risc0JournalDigest
95+
);
8696
}
8797

8898
aggregatedProofs[merkleRoot] = true;
@@ -115,4 +125,16 @@ contract AlignedProofAggregationService is
115125
function setRisc0VerifierAddress(address _risc0VerifierAddress) external onlyOwner {
116126
risc0VerifierAddress = _risc0VerifierAddress;
117127
}
128+
129+
/// @notice Sets the image id of the Risc0 program
130+
/// @param _risc0AggregatorProgramImageId The new imageid for the Risc0 aggregator program
131+
function setRisc0AggregatorProgramImageId(bytes32 _risc0AggregatorProgramImageId) external onlyOwner {
132+
risc0AggregatorProgramImageId = _risc0AggregatorProgramImageId;
133+
}
134+
135+
/// @notice Sets the vk hash of the sp1 program
136+
/// @param _sp1AggregatorProgramVKHash The new vk hash for the sp1 aggregator program
137+
function setSP1AggregatorProgramVKHash(bytes32 _sp1AggregatorProgramVKHash) external onlyOwner {
138+
sp1AggregatorProgramVKHash = _sp1AggregatorProgramVKHash;
139+
}
118140
}

contracts/src/core/IAlignedProofAggregationService.sol

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,13 @@ interface IAlignedProofAggregationService {
55
/// @dev This function is called by the aligned proof aggregator after collecting the proofs and aggregating them
66
/// to be verified on-chain. We expect the blobTransactionHash to be called before
77
/// @param blobVersionedHash the versioned hash of the blob transaction that contains the leaves that compose the merkle root.
8-
/// @param sp1ProgramVKey Public verifying key
98
/// @param sp1PublicValues Values used to perform the execution
109
/// @param sp1ProofBytes Groth16 proof
11-
function verifySP1(
12-
bytes32 blobVersionedHash,
13-
bytes32 sp1ProgramVKey,
14-
bytes calldata sp1PublicValues,
15-
bytes calldata sp1ProofBytes
16-
) external;
10+
function verifySP1(bytes32 blobVersionedHash, bytes calldata sp1PublicValues, bytes calldata sp1ProofBytes)
11+
external;
1712

18-
function verifyRisc0(
19-
bytes32 blobVersionedHash,
20-
bytes calldata risc0ReceiptSeal,
21-
bytes32 risc0ImageId,
22-
bytes calldata risc0JournalBytes
23-
) external;
13+
function verifyRisc0(bytes32 blobVersionedHash, bytes calldata risc0ReceiptSeal, bytes calldata risc0JournalBytes)
14+
external;
2415

2516
/// @notice event that gets emitted after a successful aggregated proof verification
2617
event AggregatedProofVerified(bytes32 indexed merkleRoot, bytes32 blobVersionedHash);

0 commit comments

Comments
 (0)