@@ -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}
0 commit comments