diff --git a/contracts/src/Gateway.sol b/contracts/src/Gateway.sol index c057db4734..6bafe27fb0 100644 --- a/contracts/src/Gateway.sol +++ b/contracts/src/Gateway.sol @@ -373,8 +373,8 @@ contract Gateway is IGateway, IInitializable { revert InvalidCodeHash(); } - // Verify that the code in the implementation contract was not changed - // after the upgrade initiated on BridgeHub parachain. + // As a sanity check, ensure that the codehash of implementation contract + // matches the codehash in the upgrade proposal if (params.impl.codehash != params.implCodeHash) { revert InvalidCodeHash(); } @@ -384,11 +384,9 @@ contract Gateway is IGateway, IInitializable { // Apply the initialization function of the implementation only if params were provided if (params.initParams.length > 0) { - (bool success,) = - params.impl.delegatecall(abi.encodeWithSelector(this.initialize.selector, params.initParams)); - if (!success) { - revert InitializationFailed(); - } + (bool success, bytes memory returndata) = + params.impl.delegatecall(abi.encodeCall(IInitializable.initialize, params.initParams)); + Call.verifyResult(success, returndata); } emit Upgraded(params.impl); diff --git a/contracts/src/GatewayProxy.sol b/contracts/src/GatewayProxy.sol index ca728c3268..c9f329c453 100644 --- a/contracts/src/GatewayProxy.sol +++ b/contracts/src/GatewayProxy.sol @@ -3,6 +3,7 @@ pragma solidity 0.8.22; import {ERC1967} from "./utils/ERC1967.sol"; +import {Call} from "./utils/Call.sol"; import {IInitializable} from "./interfaces/IInitializable.sol"; contract GatewayProxy is IInitializable { @@ -14,13 +15,12 @@ contract GatewayProxy is IInitializable { ERC1967.store(implementation); // Initialize storage by calling the implementation's `initialize(bytes)` function // using `delegatecall`. - (bool success,) = implementation.delegatecall(abi.encodeCall(IInitializable.initialize, params)); - if (!success) { - revert InitializationFailed(); - } + (bool success, bytes memory returndata) = + implementation.delegatecall(abi.encodeCall(IInitializable.initialize, params)); + Call.verifyResult(success, returndata); } - // Prevent fallback() from calling `initialize(bytes)` on the implementation contract + // Prevent fallback() from calling `IInitializable.initialize(bytes)` on the implementation contract function initialize(bytes calldata) external pure { revert Unauthorized(); } diff --git a/contracts/src/interfaces/IInitializable.sol b/contracts/src/interfaces/IInitializable.sol index 2421d63b47..4cabab96b4 100644 --- a/contracts/src/interfaces/IInitializable.sol +++ b/contracts/src/interfaces/IInitializable.sol @@ -3,10 +3,8 @@ pragma solidity 0.8.22; /** - * @title Initialization of gateway contracts + * @title Initialization of gateway logic contracts */ interface IInitializable { - error InitializationFailed(); - function initialize(bytes calldata data) external; } diff --git a/contracts/test/Gateway.t.sol b/contracts/test/Gateway.t.sol index f214242074..8edf215a5a 100644 --- a/contracts/test/Gateway.t.sol +++ b/contracts/test/Gateway.t.sol @@ -486,7 +486,7 @@ contract GatewayTest is Test { initParams: abi.encode(666) }); - vm.expectRevert(IInitializable.InitializationFailed.selector); + vm.expectRevert("initialize failed"); GatewayMock(address(gateway)).upgradePublic(abi.encode(params)); }