Skip to content

Commit ba099a5

Browse files
Add a modifier to ensure the provided verifier type is one of the valid enum values
1 parent d4fe4be commit ba099a5

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

contracts/src/core/AlignedProofAggregationService.sol

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ contract AlignedProofAggregationService is
152152
_;
153153
}
154154

155+
/// @notice Modifier to ensure the provided verifier type is one of the valid enum values.
156+
modifier validVerifierType(IAlignedProofAggregationService.VerifierType verifierType) {
157+
uint8 v = uint8(verifierType);
158+
if (v == uint8(IAlignedProofAggregationService.VerifierType.SP1) ||
159+
v == uint8(IAlignedProofAggregationService.VerifierType.RISC0)){
160+
revert IAlignedProofAggregationService.InvalidVerifierType(v);
161+
}
162+
163+
_;
164+
}
165+
155166
/// @notice Sets the address of the Risc0 verifier contract
156167
/// @param _risc0VerifierAddress The new address for the Risc0 verifier contract
157168
function setRisc0VerifierAddress(address _risc0VerifierAddress) external onlyOwner {
@@ -169,16 +180,23 @@ contract AlignedProofAggregationService is
169180
/// @notice Adds a new program ID to the list of valid program IDs.
170181
/// @param programId The program ID to add (image ID for RISC0 or vk hash for SP1).
171182
/// @param verifierType The type of verifier associated with the program ID.
172-
function addProgramId(bytes32 programId, IAlignedProofAggregationService.VerifierType verifierType) external onlyOwner {
183+
function addProgramId(bytes32 programId, IAlignedProofAggregationService.VerifierType verifierType)
184+
external
185+
onlyOwner
186+
validVerifierType(verifierType)
187+
{
173188
programIds[programId] = uint8(verifierType);
174189
emit ProgramIdAdded(programId, verifierType);
175190
}
176191

177192
/// @notice Deletes a program ID from the list of valid program IDs.
178193
/// @param programId The program ID to delete (image ID for RISC0 or vk hash for SP1).
179-
function deleteProgramId(bytes32 programId) external onlyOwner {
194+
function deleteProgramId(bytes32 programId, IAlignedProofAggregationService.VerifierType verifierType) external onlyOwner validVerifierType(verifierType) {
180195
// Preserve the verifier type so we can emit it with the event
181196
uint8 verifierTypeRaw = programIds[programId];
197+
198+
// TODO: Check if the verifier type matches the one received by param
199+
182200
delete programIds[programId];
183201
emit ProgramIdDeleted(programId, IAlignedProofAggregationService.VerifierType(verifierTypeRaw));
184202
}

contracts/src/core/IAlignedProofAggregationService.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,15 @@ interface IAlignedProofAggregationService {
5050

5151
/// @notice Deletes an existing program ID
5252
/// @param programId The program ID to delete
53-
function deleteProgramId(bytes32 programId) external;
53+
/// @param verifierType The type of verifier (SP1 or RISC0)
54+
function deleteProgramId(bytes32 programId, VerifierType verifierType) external;
5455

5556
error OnlyAlignedAggregator(address sender);
5657

5758
error InvalidProgramId(bytes32 programId, VerifierType expected, uint8 actual);
5859

60+
error InvalidVerifierType(uint8 actual);
61+
5962
enum VerifierType {
6063
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
6164
SP1,

0 commit comments

Comments
 (0)