Skip to content

Commit

Permalink
fix: do not fail mark bootstrap to gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 committed Sep 3, 2024
1 parent 31fc163 commit 51ad701
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/core/ClientChainGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ contract ClientChainGateway is

_whiteListFunctionSelectors[Action.REQUEST_ADD_WHITELIST_TOKENS] =
this.afterReceiveAddWhitelistTokensRequest.selector;
// overwrite the bootstrap function selector
_whiteListFunctionSelectors[Action.REQUEST_MARK_BOOTSTRAP] = this.afterReceiveMarkBootstrapRequest.selector;

bootstrapped = true;

Expand All @@ -82,8 +84,6 @@ contract ClientChainGateway is

/// @dev Clears the bootstrap data.
function _clearBootstrapData() internal {
// mandatory to clear!
delete _whiteListFunctionSelectors[Action.REQUEST_MARK_BOOTSTRAP];
// the set below is recommended to clear, so that any possibilities of upgrades
// can then be removed.
delete customProxyAdmin;
Expand Down
8 changes: 8 additions & 0 deletions src/core/ClientGatewayLzReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,12 @@ abstract contract ClientGatewayLzReceiver is PausableUpgradeable, OAppReceiverUp
}
}

/// @notice Called after a mark-bootstrap response is received.
/// @dev Since the contract is already bootstrapped (if we are here), there is nothing to do.
/// @dev Failing this, however, will cause a nonce mismatch resulting in a system halt.
/// Hence, we silently ignore this call.
function afterReceiveMarkBootstrapRequest() public onlyCalledFromThis whenNotPaused {
emit BootstrappedAlready();
}

}
17 changes: 12 additions & 5 deletions test/foundry/unit/Bootstrap.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -924,11 +924,8 @@ contract BootstrapTest is Test {
function test12_MarkBootstrapped_AlreadyBootstrapped() public {
test12_MarkBootstrapped();
vm.startPrank(address(clientChainLzEndpoint));
vm.expectRevert(
abi.encodeWithSelector(
GatewayStorage.UnsupportedRequest.selector, GatewayStorage.Action.REQUEST_MARK_BOOTSTRAP
)
);
vm.expectEmit(address(bootstrap));
emit BootstrapStorage.BootstrappedAlready();
bootstrap.lzReceive(
Origin(exocoreChainId, bytes32(bytes20(undeployedExocoreGateway)), uint64(2)),
generateUID(1),
Expand All @@ -955,6 +952,16 @@ contract BootstrapTest is Test {
_markBootstrapped(2, true);
}

function test12_MarkBootstrapped_FailThenSucceed2x() public {
vm.warp(spawnTime - 5);
_markBootstrapped(1, false);
vm.warp(spawnTime + 1);
_markBootstrapped(2, true);
// silently succeeds and does not block the system after bootstrapping
vm.warp(spawnTime + 10);
_markBootstrapped(3, true);
}

function test13_OperationAllowed() public {
vm.warp(spawnTime - offsetDuration);
vm.startPrank(addrs[0]);
Expand Down

0 comments on commit 51ad701

Please sign in to comment.