diff --git a/packages/protocol/contracts/L1/verifiers/SgxVerifier.sol b/packages/protocol/contracts/L1/verifiers/SgxVerifier.sol index 1f1846050f..4b37005c9a 100644 --- a/packages/protocol/contracts/L1/verifiers/SgxVerifier.sol +++ b/packages/protocol/contracts/L1/verifiers/SgxVerifier.sol @@ -54,6 +54,7 @@ contract SgxVerifier is EssentialContract, IVerifier { event InstanceAdded( uint256 indexed id, address indexed instance, address replaced, uint256 timstamp ); + event InstanceDeleted(uint256 indexed id, address indexed instance); error SGX_INVALID_INSTANCE(); error SGX_INVALID_INSTANCES(); @@ -77,6 +78,22 @@ contract SgxVerifier is EssentialContract, IVerifier { ids = _addInstances(_instances); } + /// @notice Deletes SGX instances from the registry. + /// @param _ids The ids array of SGX instances. + function deleteInstances(uint256[] calldata _ids) + external + onlyFromOwnerOrNamed("rollup_watchdog") + { + if (_ids.length == 0) revert SGX_INVALID_INSTANCES(); + for (uint256 i; i < _ids.length; ++i) { + if (instances[_ids[i]].addr == address(0)) revert SGX_INVALID_INSTANCE(); + + emit InstanceDeleted(_ids[i], instances[_ids[i]].addr); + + delete instances[_ids[i]]; + } + } + /// @notice Adds SGX instances to the registry by another SGX instance. /// @param id The id of the SGX instance who is adding new members. /// @param newInstance The new address of this instance. diff --git a/packages/protocol/test/L1/SgxVerifier.t.sol b/packages/protocol/test/L1/SgxVerifier.t.sol index 5811aef097..f5e713dc70 100644 --- a/packages/protocol/test/L1/SgxVerifier.t.sol +++ b/packages/protocol/test/L1/SgxVerifier.t.sol @@ -28,6 +28,20 @@ contract TestSgxVerifier is TaikoL1TestBase { sv.addInstances(_instances); } + function test_deleteInstancesByOwner() external { + uint256[] memory _ids = new uint256[](1); + _ids[0] = 0; + + address instance; + (instance,) = sv.instances(0); + assertEq(instance, SGX_X_0); + + sv.deleteInstances(_ids); + + (instance,) = sv.instances(0); + assertEq(instance, address(0)); + } + function test_addInstancesBySgxInstance() external { address[] memory _instances = new address[](2); _instances[0] = SGX_Y;