Skip to content

Commit e9a4014

Browse files
committed
Simplify everything
1 parent ea24871 commit e9a4014

File tree

7 files changed

+94
-106
lines changed

7 files changed

+94
-106
lines changed

aggregation_mode/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ make proof_aggregator_write_program_ids
7474

7575
We are using docker to produce deterministic builds so that the program ids are the same for all systems.
7676

77-
### Updating the program id in `AlignedProofAggregationService` contract
77+
### Updating the verifier program commitment in `AlignedProofAggregationService` contract
7878

79-
If the program ids have changed, you will also need to add the updated one to the `AlignedProofAggregationService` contract. You can do this by calling the `addProgramId` method with the new image ID and the verifier type number as parameters (you can check the last parameter in the VerifierType definition at `contracts/src/core/AlignedProofAggregationService.sol`).
79+
If the verifier program commitments have changed, you will also need to add the updated one to the `AlignedProofAggregationService` contract. You can do this by calling the `allowVerifyingProgram` method with the new commitment and the proving system ID as parameters (you can check the last parameter in the ProvingSystemId definition at `contracts/src/core/IAlignedProofAggregationService.sol`).
8080

81-
You can fetch the program ID values from the following:
81+
You can fetch the verifier program commitment values from the following:
8282

8383
- Risc0: Use the value of `risc0_chunk_aggregator_image_id` from `aggregation_mode/program_ids.json`.
8484
- SP1: Use the value of `sp1_chunk_aggregator_vk_hash` from `aggregation_mode/program_ids.json`.

aggregation_mode/src/backend/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl ProofAggregator {
173173
let tx_req = match aggregated_proof {
174174
AlignedProof::SP1(proof) => self
175175
.proof_aggregation_service
176-
.verifySP1(
176+
.verifyAggregationSP1(
177177
blob_versioned_hash.into(),
178178
proof.proof_with_pub_values.public_values.to_vec().into(),
179179
proof.proof_with_pub_values.bytes().into(),
@@ -186,7 +186,7 @@ impl ProofAggregator {
186186
AggregatedProofSubmissionError::Risc0EncodingSeal(e.to_string())
187187
})?;
188188
self.proof_aggregation_service
189-
.verifyRisc0(
189+
.verifyAggregationRisc0(
190190
blob_versioned_hash.into(),
191191
encoded_seal.into(),
192192
proof.receipt.journal.bytes.into(),

contracts/script/deploy/AlignedProofAggregationServiceDeployer.s.sol

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,16 @@ contract AlignedProofAggregationServiceDeployer is Script {
2525

2626
AlignedProofAggregationService alignedProofAggregationService = new AlignedProofAggregationService();
2727

28-
bytes32[] memory programIds = new bytes32[](2);
29-
programIds[0] = risc0AggregationProgramImageId;
30-
programIds[1] = sp1AggregationProgramVKHash;
31-
32-
uint8[] memory verifierTypes = new uint8[](2);
33-
verifierTypes[0] = uint8(IAlignedProofAggregationService.VerifierType.RISC0);
34-
verifierTypes[1] = uint8(IAlignedProofAggregationService.VerifierType.SP1);
35-
3628
ERC1967Proxy proxy = new ERC1967Proxy(
3729
address(alignedProofAggregationService),
3830
abi.encodeWithSignature(
39-
"initialize(address,address,address,address,bytes32[],uint8[])",
31+
"initialize(address,address,address,address,bytes32,bytes32)",
4032
ownerAddress,
4133
alignedAggregatorAddress,
4234
sp1VerifierAddress,
4335
risc0VerifierAddress,
44-
programIds,
45-
verifierTypes
36+
risc0AggregationProgramImageId,
37+
sp1AggregationProgramVKHash
4638
)
4739
);
4840

contracts/src/core/AlignedProofAggregationService.sol

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ contract AlignedProofAggregationService is
1515
OwnableUpgradeable,
1616
UUPSUpgradeable
1717
{
18-
/// @notice Map the merkle root to a boolean to indicate it was verified
19-
mapping(bytes32 => bool) public aggregatedProofs;
18+
/// @notice true if merkle root is verified
19+
mapping(bytes32 => bool) public isMerkleRootVerified;
2020

2121
/// @notice The address of the SP1 verifier contract.
2222
/// @dev This can either be a specific SP1Verifier for a specific version, or the
@@ -37,10 +37,14 @@ contract AlignedProofAggregationService is
3737
/// if the sp1 verifier address is set to this address, then we skip verification
3838
address public constant VERIFIER_MOCK_ADDRESS = address(0xFF);
3939

40-
/// @notice A map to track aggregation program IDs (image IDs for RISC Zero or vk hashes for SP1)
41-
/// with their proving system. These program IDs are used to validate that the proofs to verify are indeed from
42-
/// a trusted aggregation program.
43-
mapping(bytes32 => uint8) public programIds;
40+
/// @notice Proving system ID for SP1
41+
uint8 public constant SP1_ID = 1;
42+
43+
/// @notice Proving system ID for RISC0
44+
uint8 public constant RISC0_ID = 2;
45+
46+
/// @notice Maps allowed verifiers commitments to their proving system. If the verifier is not a valid one, it returns 0 and is considered invalid
47+
mapping(bytes32 => uint8) public allowedVerifiersProvingSystem;
4448

4549
constructor() {
4650
_disableInitializers();
@@ -51,86 +55,85 @@ contract AlignedProofAggregationService is
5155
address _alignedAggregatorAddress,
5256
address _sp1VerifierAddress,
5357
address _risc0VerifierAddress,
54-
bytes32[] memory _programIds,
55-
uint8[] memory _verifierTypes
58+
bytes32 _risc0AggregatorProgramImageId,
59+
bytes32 _sp1AggregatorProgramVKHash
5660
) public initializer {
5761
__Ownable_init();
5862
__UUPSUpgradeable_init();
5963
_transferOwnership(newOwner);
6064
alignedAggregatorAddress = _alignedAggregatorAddress;
6165
sp1VerifierAddress = _sp1VerifierAddress;
6266
risc0VerifierAddress = _risc0VerifierAddress;
63-
for (uint256 i = 0; i < _programIds.length; i++) {
64-
programIds[_programIds[i]] = _verifierTypes[i];
65-
}
67+
allowedVerifiersProvingSystem[_risc0AggregatorProgramImageId] = RISC0_ID;
68+
allowedVerifiersProvingSystem[_sp1AggregatorProgramVKHash] = SP1_ID;
6669
}
6770

68-
function verifySP1(bytes32 blobVersionedHash, bytes calldata sp1PublicValues, bytes calldata sp1ProofBytes, bytes32 programId)
71+
function verifyAggregationSP1(bytes32 blobVersionedHash, bytes calldata sp1PublicValues, bytes calldata sp1ProofBytes, bytes32 verifierProgramCommitment)
6972
public
7073
onlyAlignedAggregator
7174
{
7275
(bytes32 merkleRoot) = abi.decode(sp1PublicValues, (bytes32));
7376

74-
if (programIds[programId] != uint8(IAlignedProofAggregationService.VerifierType.SP1)) {
75-
revert InvalidProgramId(programId, IAlignedProofAggregationService.VerifierType.SP1, programIds[programId]);
77+
if (allowedVerifiersProvingSystem[verifierProgramCommitment] != SP1_ID) {
78+
revert InvalidVerifyingProgram(verifierProgramCommitment, SP1_ID, allowedVerifiersProvingSystem[verifierProgramCommitment]);
7679
}
7780

7881
// In dev mode, proofs are mocked, so we skip the verification part
7982
if (_isSP1VerificationEnabled()) {
80-
ISP1Verifier(sp1VerifierAddress).verifyProof(programId, sp1PublicValues, sp1ProofBytes);
83+
ISP1Verifier(sp1VerifierAddress).verifyProof(verifierProgramCommitment, sp1PublicValues, sp1ProofBytes);
8184
}
8285

83-
aggregatedProofs[merkleRoot] = true;
86+
isMerkleRootVerified[merkleRoot] = true;
8487
emit AggregatedProofVerified(merkleRoot, blobVersionedHash);
8588
}
8689

87-
function verifyRisc0(bytes32 blobVersionedHash, bytes calldata risc0ReceiptSeal, bytes calldata risc0JournalBytes, bytes32 programId)
90+
function verifyAggregationRisc0(bytes32 blobVersionedHash, bytes calldata risc0ReceiptSeal, bytes calldata risc0JournalBytes, bytes32 verifierProgramCommitment)
8891
public
8992
onlyAlignedAggregator
9093
{
9194
(bytes32 merkleRoot) = abi.decode(risc0JournalBytes, (bytes32));
9295

93-
if (programIds[programId] != uint8(IAlignedProofAggregationService.VerifierType.RISC0)) {
94-
revert InvalidProgramId(programId, IAlignedProofAggregationService.VerifierType.RISC0, programIds[programId]);
96+
if (allowedVerifiersProvingSystem[verifierProgramCommitment] != RISC0_ID) {
97+
revert InvalidVerifyingProgram(verifierProgramCommitment, RISC0_ID, allowedVerifiersProvingSystem[verifierProgramCommitment]);
9598
}
9699

97100
// In dev mode, proofs are mocked, so we skip the verification part
98101
if (_isRisc0VerificationEnabled()) {
99102
bytes32 risc0JournalDigest = sha256(risc0JournalBytes);
100103
IRiscZeroVerifier(risc0VerifierAddress).verify(
101-
risc0ReceiptSeal, programId, risc0JournalDigest
104+
risc0ReceiptSeal, verifierProgramCommitment, risc0JournalDigest
102105
);
103106
}
104107

105-
aggregatedProofs[merkleRoot] = true;
108+
isMerkleRootVerified[merkleRoot] = true;
106109
emit AggregatedProofVerified(merkleRoot, blobVersionedHash);
107110
}
108111

109112
/// @notice Verifies the inclusion of proof in an aggregated proof via Merkle tree proof.
110113
///
111114
/// @dev
112-
/// - The `programId` parameter represents the unique identifier for the vm program:
115+
/// - The `programCommitment` parameter represents the unique identifier for the vm program:
113116
/// - In RISC Zero, this corresponds to the `image_id`.
114117
/// - In SP1, this corresponds to the `vk` (verification key) hash.
115-
/// - The proof commitment is derived by hashing together the `programId` and the `publicInputs`.
118+
/// - The proof commitment is derived by hashing together the `programCommitment` and the `publicInputs`.
116119
/// - The `merklePath` is then used to compute the Merkle root from this commitment.
117120
/// - The function returns `true` if this Merkle root is known to correspond to a valid aggregated proof.
118121
///
119122
/// @param merklePath The Merkle proof (sibling hashes) needed to reconstruct the Merkle root.
120123
/// @param provingSystemId The id of the proving system (1 for SP1, 2 for RISC0).
121-
/// @param programId The identifier for the ZK program (image_id in RISC0 or vk hash in SP1).
122-
/// @param publicInputs The public inputs bytes of the proof.
124+
/// @param programCommitment The commitment of the program sent to Aligned (image_id in RISC0 or vk hash in SP1).
125+
/// @param publicInputs The public inputs bytes of the proof sent to Aligned.
123126
///
124127
/// @return bool Returns true if the computed Merkle root is a recognized valid aggregated proof.
125-
function verifyProofInclusion(
128+
function isProofVerified(
126129
bytes32[] calldata merklePath,
127130
uint16 provingSystemId,
128-
bytes32 programId,
131+
bytes32 programCommitment,
129132
bytes calldata publicInputs
130133
) public view returns (bool) {
131-
bytes32 proofCommitment = keccak256(abi.encodePacked(provingSystemId, programId, publicInputs));
134+
bytes32 proofCommitment = keccak256(abi.encodePacked(provingSystemId, programCommitment, publicInputs));
132135
bytes32 merkleRoot = MerkleProof.processProofCalldata(merklePath, proofCommitment);
133-
return aggregatedProofs[merkleRoot];
136+
return isMerkleRootVerified[merkleRoot];
134137
}
135138

136139
function _isSP1VerificationEnabled() internal view returns (bool) {
@@ -154,13 +157,13 @@ contract AlignedProofAggregationService is
154157
_;
155158
}
156159

157-
/// @notice Modifier to ensure the provided verifier type is one of the valid enum values.
158-
modifier onValidVerifierType(IAlignedProofAggregationService.VerifierType verifierType) {
159-
if (verifierType != IAlignedProofAggregationService.VerifierType.SP1 &&
160-
verifierType != IAlignedProofAggregationService.VerifierType.RISC0){
161-
revert IAlignedProofAggregationService.InvalidVerifierType(uint8(verifierType));
160+
/// @notice Modifier to ensure the provided proving system ID is one of the valid values.
161+
modifier onValidProvingSystemId(uint8 provingSystemId) {
162+
if (provingSystemId != SP1_ID &&
163+
provingSystemId != RISC0_ID){
164+
revert IAlignedProofAggregationService.InvalidProvingSystemId(provingSystemId);
162165
}
163-
166+
164167
_;
165168
}
166169

@@ -178,31 +181,30 @@ contract AlignedProofAggregationService is
178181
emit SP1VerifierAddressUpdated(_sp1VerifierAddress);
179182
}
180183

181-
/// @notice Adds a new program ID to the list of valid program IDs.
182-
/// @param programId The program ID to add (image ID for RISC0 or vk hash for SP1).
183-
/// @param verifierType The type of verifier associated with the program ID.
184-
function addProgramId(bytes32 programId, IAlignedProofAggregationService.VerifierType verifierType)
184+
/// @notice Allows a new verifying program commitment to the list of valid verifying programs.
185+
/// @param verifierProgramCommitment The verifying program commitment to allow (image ID for RISC0 or vk hash for SP1).
186+
/// @param provingSystemId The proving system ID associated with the verifying program.
187+
function allowVerifyingProgram(bytes32 verifierProgramCommitment, uint8 provingSystemId)
185188
external
186189
onlyOwner
187-
onValidVerifierType(verifierType)
190+
onValidProvingSystemId(provingSystemId)
188191
{
189-
programIds[programId] = uint8(verifierType);
190-
emit ProgramIdAdded(programId, verifierType);
192+
allowedVerifiersProvingSystem[verifierProgramCommitment] = provingSystemId;
193+
emit VerifierProgramAllowed(verifierProgramCommitment, provingSystemId);
191194
}
192195

193-
/// @notice Deletes a program ID from the list of valid program IDs.
194-
/// @param programId The program ID to delete (image ID for RISC0 or vk hash for SP1).
195-
function deleteProgramId(bytes32 programId, IAlignedProofAggregationService.VerifierType verifierType) external onlyOwner onValidVerifierType(verifierType) {
196-
// Preserve the verifier type so we can emit it with the event
197-
uint8 verifierTypeRaw = programIds[programId];
198-
uint8 rawReceivedVerifierType = uint8(verifierType);
196+
/// @notice Disallows a verifying program commitment from the list of valid verifying programs.
197+
/// @param verifierProgramCommitment The verifying program commitment to disallow (image ID for RISC0 or vk hash for SP1).
198+
function disallowVerifyingProgram(bytes32 verifierProgramCommitment, uint8 provingSystemId) external onlyOwner onValidProvingSystemId(provingSystemId) {
199+
// Preserve the proving system ID so we can emit it with the event
200+
uint8 provingSystemIdRaw = allowedVerifiersProvingSystem[verifierProgramCommitment];
199201

200-
// Check if the obtained verifier type matches the one received by param
201-
if (verifierTypeRaw != rawReceivedVerifierType) {
202-
revert IAlignedProofAggregationService.VerifierTypeMismatch(verifierTypeRaw, rawReceivedVerifierType);
202+
// Check if the obtained proving system ID matches the one received by param
203+
if (provingSystemIdRaw != provingSystemId) {
204+
revert IAlignedProofAggregationService.ProvingSystemIdMismatch(provingSystemIdRaw, provingSystemId);
203205
}
204206

205-
delete programIds[programId];
206-
emit ProgramIdDeleted(programId, IAlignedProofAggregationService.VerifierType(verifierTypeRaw));
207+
delete allowedVerifiersProvingSystem[verifierProgramCommitment];
208+
emit VerifierProgramDisallowed(verifierProgramCommitment, provingSystemIdRaw);
207209
}
208210
}

contracts/src/core/IAlignedProofAggregationService.sol

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ interface IAlignedProofAggregationService {
1010
/// @notice Event emitted when the SP1 verifier address is updated
1111
event SP1VerifierAddressUpdated(address indexed newAddress);
1212

13-
/// @notice Event emitted when a new program ID is added
14-
event ProgramIdAdded(bytes32 indexed programId, VerifierType verifierType);
13+
/// @notice Event emitted when a verifier program is allowed
14+
event VerifierProgramAllowed(bytes32 indexed verifierProgramCommitment, uint8 provingSystemId);
1515

16-
/// @notice Event emitted when a program ID is deleted
17-
event ProgramIdDeleted(bytes32 indexed programId, VerifierType verifierType);
16+
/// @notice Event emitted when a verifier program is disallowed
17+
event VerifierProgramDisallowed(bytes32 indexed verifierProgramCommitment, uint8 provingSystemId);
1818

1919
/// @notice Method to verify an aggregated proof from aligned
2020
/// @dev This function is called by the aligned proof aggregator after collecting the proofs and aggregating them
2121
/// to be verified on-chain. We expect the blobTransactionHash to be called before
2222
/// @param blobVersionedHash the versioned hash of the blob transaction that contains the leaves that compose the merkle root.
2323
/// @param sp1PublicValues Values used to perform the execution
2424
/// @param sp1ProofBytes Groth16 proof
25-
/// @param programId The chunk aggregator program ID against which the proof should be verified
26-
function verifySP1(bytes32 blobVersionedHash, bytes calldata sp1PublicValues, bytes calldata sp1ProofBytes, bytes32 programId)
25+
/// @param verifierProgramCommitment The chunk aggregator verifier program commitment against which the proof should be verified
26+
function verifyAggregationSP1(bytes32 blobVersionedHash, bytes calldata sp1PublicValues, bytes calldata sp1ProofBytes, bytes32 verifierProgramCommitment)
2727
external;
2828

29-
function verifyRisc0(bytes32 blobVersionedHash, bytes calldata risc0ReceiptSeal, bytes calldata risc0JournalBytes, bytes32 programId)
29+
function verifyAggregationRisc0(bytes32 blobVersionedHash, bytes calldata risc0ReceiptSeal, bytes calldata risc0JournalBytes, bytes32 verifierProgramCommitment)
3030
external;
3131

32-
function verifyProofInclusion(
32+
function isProofVerified(
3333
bytes32[] calldata merklePath,
3434
uint16 provingSystemId,
35-
bytes32 programId,
35+
bytes32 programCommitment,
3636
bytes calldata publicInputs
3737
) external view returns (bool);
3838

@@ -44,27 +44,21 @@ interface IAlignedProofAggregationService {
4444
/// @param _sp1VerifierAddress The new address for the SP1 verifier contract
4545
function setSP1VerifierAddress(address _sp1VerifierAddress) external;
4646

47-
/// @notice Adds a new program ID with its verifier type
48-
/// @param programId The program ID to add
49-
/// @param verifierType The type of verifier (SP1 or RISC0)
50-
function addProgramId(bytes32 programId, VerifierType verifierType) external;
47+
/// @notice Allows a new verifier program commitment with its proving system ID
48+
/// @param verifierProgramCommitment The verifier program commitment to allow
49+
/// @param provingSystemId The proving system ID (1 for SP1, 2 for RISC0)
50+
function allowVerifyingProgram(bytes32 verifierProgramCommitment, uint8 provingSystemId) external;
5151

52-
/// @notice Deletes an existing program ID
53-
/// @param programId The program ID to delete
54-
/// @param verifierType The type of verifier (SP1 or RISC0)
55-
function deleteProgramId(bytes32 programId, VerifierType verifierType) external;
52+
/// @notice Disallows an existing verifier program commitment
53+
/// @param verifierProgramCommitment The verifier program commitment to disallow
54+
/// @param provingSystemId The proving system ID (1 for SP1, 2 for RISC0)
55+
function disallowVerifyingProgram(bytes32 verifierProgramCommitment, uint8 provingSystemId) external;
5656

5757
error OnlyAlignedAggregator(address sender);
5858

59-
error InvalidProgramId(bytes32 programId, VerifierType expected, uint8 actual);
59+
error InvalidVerifyingProgram(bytes32 verifierProgramCommitment, uint8 expected, uint8 actual);
6060

61-
error InvalidVerifierType(uint8 actual);
61+
error InvalidProvingSystemId(uint8 actual);
6262

63-
error VerifierTypeMismatch(uint8 expected, uint8 received);
64-
65-
enum VerifierType {
66-
INVALID, // If a given program does not exist in the `programId` map, it defaults to 0. This prevents non-existing keys to be considered valid in case SP1 or RISC0 were in this position
67-
SP1,
68-
RISC0
69-
}
63+
error ProvingSystemIdMismatch(uint8 expected, uint8 received);
7064
}

0 commit comments

Comments
 (0)