-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add upgradable
Shell
contract (#1170)
* Add temporary rescue mechanism to gateway contract * Simplified the implementation * Add more comments
- Loading branch information
Showing
14 changed files
with
152 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.23; | ||
|
||
import {Upgrade} from "./Upgrade.sol"; | ||
import {IInitializable} from "./interfaces/IInitializable.sol"; | ||
import {IUpgradable} from "./interfaces/IUpgradable.sol"; | ||
import {IShell} from "./interfaces/IShell.sol"; | ||
|
||
// address recoveryOperator = vm.envOr("RECOVERY_OPERATOR", address(0)); | ||
|
||
contract Shell is IShell, IUpgradable, IInitializable { | ||
address public immutable operator; | ||
|
||
error Unauthorised(); | ||
|
||
constructor(address _operator) { | ||
operator = _operator; | ||
} | ||
|
||
function upgrade(address impl, bytes32 implCodeHash, bytes calldata initializerParams) external { | ||
if (msg.sender != operator) { | ||
revert Unauthorised(); | ||
} | ||
Upgrade.upgrade(impl, implCodeHash, initializerParams); | ||
} | ||
|
||
function initialize(bytes memory params) external {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.23; | ||
|
||
import {ERC1967} from "./utils/ERC1967.sol"; | ||
import {Call} from "./utils/Call.sol"; | ||
import {Address} from "./utils/Address.sol"; | ||
import {IInitializable} from "./interfaces/IInitializable.sol"; | ||
import {IUpgradable} from "./interfaces/IUpgradable.sol"; | ||
|
||
/// @dev Upgrades implementation contract | ||
library Upgrade { | ||
using Address for address; | ||
|
||
function upgrade(address impl, bytes32 implCodeHash, bytes memory initializerParams) internal { | ||
// Verify that the implementation is actually a contract | ||
if (!impl.isContract()) { | ||
revert IUpgradable.InvalidContract(); | ||
} | ||
|
||
// As a sanity check, ensure that the codehash of implementation contract | ||
// matches the codehash in the upgrade proposal | ||
if (impl.codehash != implCodeHash) { | ||
revert IUpgradable.InvalidCodeHash(); | ||
} | ||
|
||
// Update the proxy with the address of the new implementation | ||
ERC1967.store(impl); | ||
|
||
// Call the initializer | ||
(bool success, bytes memory returndata) = | ||
impl.delegatecall(abi.encodeCall(IInitializable.initialize, initializerParams)); | ||
Call.verifyResult(success, returndata); | ||
|
||
emit IUpgradable.Upgraded(impl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.23; | ||
|
||
interface IShell { | ||
// Upgrade gateway shell to a new implementation | ||
function upgrade(address impl, bytes32 implCodeHash, bytes calldata initializerParams) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.23; | ||
|
||
interface IUpgradable { | ||
// The new implementation address is a not a contract | ||
error InvalidContract(); | ||
// The supplied codehash does not match the new implementation codehash | ||
error InvalidCodeHash(); | ||
|
||
// The implementation contract was upgraded | ||
event Upgraded(address indexed implementation); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.