Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(protocol): add delete-instance function (TKO16) #15629

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/protocol/contracts/L1/verifiers/SgxVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions packages/protocol/test/L1/SgxVerifier.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading