-
Notifications
You must be signed in to change notification settings - Fork 4
EIP1967 Migrators #169
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
Draft
mkysel
wants to merge
5
commits into
main
Choose a base branch
from
mkysel/upgrades
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
EIP1967 Migrators #169
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,71 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.28; | ||
|
|
||
| import { Script, console } from "../../lib/forge-std/src/Script.sol"; | ||
|
|
||
| import { GenericEIP1967Migrator } from "../../../src/any-chain/GenericEIP1967Migrator.sol"; | ||
| import { IERC1967 } from "../../../src/abstract/interfaces/IERC1967.sol"; | ||
| import { PayerRegistry } from "../../../src/settlement-chain/PayerRegistry.sol"; | ||
|
|
||
| import { IParameterRegistry } from "../../../src/abstract/interfaces/IParameterRegistry.sol"; | ||
| import { Utils } from "../../script/utils/Utils.sol"; | ||
| import {PayerRegistryDeployer} from "../deployers/PayerRegistryDeployer.sol"; | ||
|
|
||
|
|
||
| contract PayerRegistryUpgrader is Script { | ||
| error PrivateKeyNotSet(); | ||
| error EnvironmentNotSet(); | ||
|
|
||
| string internal _environment; | ||
|
|
||
| uint256 internal _privateKey; | ||
| address internal _admin; | ||
|
|
||
| Utils.DeploymentData internal deployment; | ||
|
|
||
| function setUp() external { | ||
| _environment = vm.envString("ENVIRONMENT"); | ||
|
|
||
| if (bytes(_environment).length == 0) revert EnvironmentNotSet(); | ||
|
|
||
| console.log("Environment: %s", _environment); | ||
|
|
||
| deployment = Utils.parseDeploymentData(string.concat("config/", _environment, ".json")); | ||
|
|
||
| _privateKey = uint256(vm.envBytes32("ADMIN_PRIVATE_KEY")); | ||
|
|
||
| if (_privateKey == 0) revert PrivateKeyNotSet(); | ||
|
|
||
| _admin = vm.addr(_privateKey); | ||
|
|
||
| console.log("Admin: %s", _admin); | ||
| } | ||
|
|
||
| function UpgradePayerRegistry() external { | ||
| address factory = deployment.factory; | ||
| console.log("factory" , factory); | ||
| address paramRegistry = deployment.parameterRegistryProxy; | ||
| console.log("paramRegistry" , paramRegistry); | ||
| address feeToken = deployment.feeTokenProxy; | ||
| console.log("feeToken" , feeToken); | ||
| address proxy = deployment.payerRegistryProxy; | ||
| console.log("proxy" , proxy); | ||
|
|
||
| vm.startBroadcast(_privateKey); | ||
| (address newImpl, ) = PayerRegistryDeployer.deployImplementation( | ||
| factory, | ||
| paramRegistry, | ||
| feeToken | ||
| ); | ||
| console.log("newImpl", newImpl); | ||
|
|
||
| GenericEIP1967Migrator migrator = new GenericEIP1967Migrator(newImpl); | ||
| console.log("migrator", address(migrator)); | ||
| string memory key = PayerRegistry(proxy).migratorParameterKey(); | ||
| IParameterRegistry(paramRegistry).set(key, bytes32(uint256(uint160(address(migrator))))); | ||
|
|
||
| PayerRegistry(proxy).migrate(); | ||
|
|
||
| vm.stopBroadcast(); | ||
| } | ||
| } |
This file contains hidden or 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,74 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.28; | ||
|
|
||
| import { Script, console } from "../../lib/forge-std/src/Script.sol"; | ||
|
|
||
| import { GenericEIP1967Migrator } from "../../../src/any-chain/GenericEIP1967Migrator.sol"; | ||
| import { IERC1967 } from "../../../src/abstract/interfaces/IERC1967.sol"; | ||
|
|
||
| import { IParameterRegistry } from "../../../src/abstract/interfaces/IParameterRegistry.sol"; | ||
| import { Utils } from "../../script/utils/Utils.sol"; | ||
| import {PayerReportManager} from "../../src/settlement-chain/PayerReportManager.sol"; | ||
| import {PayerReportManagerDeployer} from "../deployers/PayerReportManagerDeployer.sol"; | ||
|
|
||
|
|
||
| contract PayerReportManagerUpgrader is Script { | ||
| error PrivateKeyNotSet(); | ||
| error EnvironmentNotSet(); | ||
|
|
||
| string internal _environment; | ||
|
|
||
| uint256 internal _privateKey; | ||
| address internal _admin; | ||
|
|
||
| Utils.DeploymentData internal deployment; | ||
|
|
||
| function setUp() external { | ||
| _environment = vm.envString("ENVIRONMENT"); | ||
|
|
||
| if (bytes(_environment).length == 0) revert EnvironmentNotSet(); | ||
|
|
||
| console.log("Environment: %s", _environment); | ||
|
|
||
| deployment = Utils.parseDeploymentData(string.concat("config/", _environment, ".json")); | ||
|
|
||
| _privateKey = uint256(vm.envBytes32("ADMIN_PRIVATE_KEY")); | ||
|
|
||
| if (_privateKey == 0) revert PrivateKeyNotSet(); | ||
|
|
||
| _admin = vm.addr(_privateKey); | ||
|
|
||
| console.log("Admin: %s", _admin); | ||
| } | ||
|
|
||
| function UpgradePayerReportManager() external { | ||
| address factory = deployment.factory; | ||
| console.log("factory" , factory); | ||
| address paramRegistry = deployment.parameterRegistryProxy; | ||
| console.log("paramRegistry" , paramRegistry); | ||
| address proxy = deployment.payerReportManagerProxy; | ||
| console.log("proxy" , proxy); | ||
| address nodeRegistry = deployment.nodeRegistryProxy; | ||
| console.log("nodeRegistry" , nodeRegistry); | ||
| address payerRegistry = deployment.payerRegistryProxy; | ||
| console.log("payerRegistry" , payerRegistry); | ||
|
|
||
| vm.startBroadcast(_privateKey); | ||
| (address newImpl, ) = PayerReportManagerDeployer.deployImplementation( | ||
| factory, | ||
| paramRegistry, | ||
| nodeRegistry, | ||
| payerRegistry | ||
| ); | ||
| console.log("newImpl", newImpl); | ||
|
|
||
| GenericEIP1967Migrator migrator = new GenericEIP1967Migrator(newImpl); | ||
| console.log("migrator", address(migrator)); | ||
| string memory key = PayerReportManager(proxy).migratorParameterKey(); | ||
| IParameterRegistry(paramRegistry).set(key, bytes32(uint256(uint160(address(migrator))))); | ||
|
|
||
| PayerReportManager(proxy).migrate(); | ||
|
|
||
| vm.stopBroadcast(); | ||
| } | ||
| } |
This file contains hidden or 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,81 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.28; | ||
|
|
||
| import { Script, console } from "../../lib/forge-std/src/Script.sol"; | ||
|
|
||
| import { GenericEIP1967Migrator } from "../../../src/any-chain/GenericEIP1967Migrator.sol"; | ||
| import { IERC1967 } from "../../../src/abstract/interfaces/IERC1967.sol"; | ||
|
|
||
| import { IParameterRegistry } from "../../../src/abstract/interfaces/IParameterRegistry.sol"; | ||
| import { SettlementChainGateway } from "../../../src/settlement-chain/SettlementChainGateway.sol"; | ||
| import { SettlementChainGatewayDeployer } from "../../../script/deployers/SettlementChainGatewayDeployer.sol"; | ||
| import { Utils } from "../../script/utils/Utils.sol"; | ||
|
|
||
| interface ISettlementChainGateway { | ||
| function parameterRegistry() external view returns (address); | ||
| function appChainGateway() external view returns (address); | ||
| function feeToken() external view returns (address); | ||
| function migrate() external; | ||
| function migratorParameterKey() external pure returns (string memory); | ||
| } | ||
|
|
||
| contract SettlementChainGatewayUpgrader is Script { | ||
| error PrivateKeyNotSet(); | ||
| error EnvironmentNotSet(); | ||
|
|
||
| string internal _environment; | ||
|
|
||
| uint256 internal _privateKey; | ||
| address internal _admin; | ||
|
|
||
| Utils.DeploymentData internal deployment; | ||
|
|
||
| function setUp() external { | ||
| _environment = vm.envString("ENVIRONMENT"); | ||
|
|
||
| if (bytes(_environment).length == 0) revert EnvironmentNotSet(); | ||
|
|
||
| console.log("Environment: %s", _environment); | ||
|
|
||
| deployment = Utils.parseDeploymentData(string.concat("config/", _environment, ".json")); | ||
|
|
||
| _privateKey = uint256(vm.envBytes32("ADMIN_PRIVATE_KEY")); | ||
|
|
||
| if (_privateKey == 0) revert PrivateKeyNotSet(); | ||
|
|
||
| _admin = vm.addr(_privateKey); | ||
|
|
||
| console.log("Admin: %s", _admin); | ||
| } | ||
|
|
||
| function UpgradeSettlementChainGateway() external { | ||
| address factory = deployment.factory; | ||
| console.log("factory" , factory); | ||
| address paramRegistry = deployment.parameterRegistryProxy; | ||
| console.log("paramRegistry" , paramRegistry); | ||
| address settlementChainGateway = deployment.gatewayProxy; | ||
| console.log("settlementChainGateway" , settlementChainGateway); | ||
| address feeToken = deployment.feeTokenProxy; | ||
| console.log("feeToken" , feeToken); | ||
| address proxy = deployment.gatewayProxy; | ||
| console.log("proxy" , proxy); | ||
|
|
||
| vm.startBroadcast(_privateKey); | ||
| (address newImpl, ) = SettlementChainGatewayDeployer.deployImplementation( | ||
| factory, | ||
| paramRegistry, | ||
| settlementChainGateway, | ||
| feeToken | ||
| ); | ||
| console.log("newImpl", newImpl); | ||
|
|
||
| GenericEIP1967Migrator migrator = new GenericEIP1967Migrator(newImpl); | ||
| console.log("migrator", address(migrator)); | ||
| string memory key = ISettlementChainGateway(proxy).migratorParameterKey(); | ||
| IParameterRegistry(paramRegistry).set(key, bytes32(uint256(uint160(address(migrator))))); | ||
|
|
||
| SettlementChainGateway(settlementChainGateway).migrate(); | ||
|
|
||
| vm.stopBroadcast(); | ||
| } | ||
| } |
63 changes: 63 additions & 0 deletions
63
script/upgrades/SettlementChainParameterRegistryUpgrader.s.sol
This file contains hidden or 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,63 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.28; | ||
|
|
||
| import { Script, console } from "../../lib/forge-std/src/Script.sol"; | ||
|
|
||
| import { GenericEIP1967Migrator } from "../../../src/any-chain/GenericEIP1967Migrator.sol"; | ||
| import { IERC1967 } from "../../../src/abstract/interfaces/IERC1967.sol"; | ||
|
|
||
| import { IParameterRegistry } from "../../../src/abstract/interfaces/IParameterRegistry.sol"; | ||
| import { Utils } from "../../script/utils/Utils.sol"; | ||
| import {SettlementChainParameterRegistryDeployer} from "../deployers/SettlementChainParameterRegistryDeployer.sol"; | ||
|
|
||
| contract SettlementChainParameterRegistryUpgrader is Script { | ||
| error PrivateKeyNotSet(); | ||
| error EnvironmentNotSet(); | ||
|
|
||
| string internal _environment; | ||
|
|
||
| uint256 internal _privateKey; | ||
| address internal _admin; | ||
|
|
||
| Utils.DeploymentData internal deployment; | ||
|
|
||
| function setUp() external { | ||
| _environment = vm.envString("ENVIRONMENT"); | ||
|
|
||
| if (bytes(_environment).length == 0) revert EnvironmentNotSet(); | ||
|
|
||
| console.log("Environment: %s", _environment); | ||
|
|
||
| deployment = Utils.parseDeploymentData(string.concat("config/", _environment, ".json")); | ||
|
|
||
| _privateKey = uint256(vm.envBytes32("ADMIN_PRIVATE_KEY")); | ||
|
|
||
| if (_privateKey == 0) revert PrivateKeyNotSet(); | ||
|
|
||
| _admin = vm.addr(_privateKey); | ||
|
|
||
| console.log("Admin: %s", _admin); | ||
| } | ||
|
|
||
| function UpgradeSettlementParameterRegistry() external { | ||
| address factory = deployment.factory; | ||
| console.log("factory" , factory); | ||
| address paramRegistry = deployment.parameterRegistryProxy; | ||
| console.log("paramRegistry" , paramRegistry); | ||
|
|
||
| vm.startBroadcast(_privateKey); | ||
| (address newImpl, ) = SettlementChainParameterRegistryDeployer.deployImplementation( | ||
| factory | ||
| ); | ||
| console.log("newImpl", newImpl); | ||
|
|
||
| GenericEIP1967Migrator migrator = new GenericEIP1967Migrator(newImpl); | ||
| console.log("migrator", address(migrator)); | ||
| string memory key = IParameterRegistry(paramRegistry).migratorParameterKey(); | ||
| IParameterRegistry(paramRegistry).set(key, bytes32(uint256(uint160(address(migrator))))); | ||
|
|
||
| IParameterRegistry(paramRegistry).migrate(); | ||
|
|
||
| vm.stopBroadcast(); | ||
| } | ||
| } |
This file contains hidden or 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,64 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.28; | ||
|
|
||
| import { IERC1967 } from "../../src/abstract/interfaces/IERC1967.sol"; | ||
|
|
||
| /** | ||
| * @title GenericEIP1967Migrator | ||
| * @notice Minimal migrator that upgrades an EIP-1967 proxy to a new implementation. | ||
| * | ||
| * @dev HOW IT WORKS | ||
| * - This contract is deployed as a *standalone* “migrator”. | ||
| * - Your proxied contract implements the XMTP `Migratable` pattern. When governance | ||
| * sets this migrator’s address in the ParameterRegistry and calls `proxy.migrate()`, | ||
| * the proxy will `delegatecall("")` into this contract (empty calldata). | ||
| * - Because it’s a `delegatecall`, *this fallback executes in the proxy’s storage | ||
| * context*, so it can write the EIP-1967 implementation slot on the proxy. | ||
| * | ||
| * WHAT IT DOES | ||
| * - Writes `NEW_IMPL` into the EIP-1967 implementation slot. | ||
| * - Emits the standard `IERC1967.Upgraded(newImpl)` event. | ||
| * | ||
| * WHAT IT DOES NOT DO | ||
| * - Does not run any initialization or data migration on the new implementation. | ||
| * If you need state transforms or an `initialize(...)` call, use a purpose-built | ||
| * migrator that (after setting the slot) `delegatecall`s the new impl with the | ||
| * desired calldata. | ||
| * | ||
| * SAFETY NOTES | ||
| * - This migrator is intentionally tiny: fewer moving parts, easier to audit. | ||
| * - Make sure `NEW_IMPL` preserves storage layout and initializer semantics. | ||
| * - Only allow `migrate()` to be reachable via your governed parameter (`migrator` key). | ||
| */ | ||
| contract GenericEIP1967Migrator { | ||
| error InvalidImplementation(); | ||
|
|
||
| /// @notice The implementation that the proxy will be upgraded to. | ||
| address public immutable NEW_IMPL; | ||
|
Check failure on line 37 in src/any-chain/GenericEIP1967Migrator.sol
|
||
|
|
||
| /// @dev bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1) | ||
| bytes32 private constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; | ||
|
|
||
| /** | ||
| * @param newImpl_ The address of the new implementation (must be non-zero). | ||
| */ | ||
| constructor(address newImpl_) { | ||
| if (newImpl_ == address(0)) revert InvalidImplementation(); | ||
| NEW_IMPL = newImpl_; | ||
| } | ||
|
|
||
| /** | ||
| * @notice Entry point when the proxy `delegatecall`s this contract with empty calldata. | ||
| * @dev Runs in the *proxy’s* context (storage is the proxy’s), so we can sstore the slot. | ||
| * Emits the standard ERC-1967 `Upgraded` event via the imported interface. | ||
| */ | ||
| fallback() external payable { | ||
| address impl = NEW_IMPL; | ||
|
|
||
| assembly { | ||
| sstore(_IMPLEMENTATION_SLOT, impl) | ||
| } | ||
|
|
||
| emit IERC1967.Upgraded(impl); | ||
| } | ||
|
Comment on lines
+55
to
+63
Check warningCode scanning / Slither Assembly usage Warning |
||
| } | ||
|
Comment on lines
+33
to
+64
Check warningCode scanning / Slither Contracts that lock Ether Medium
Contract locking ether found:
Contract GenericEIP1967Migrator has payable functions: - GenericEIP1967Migrator.fallback() But does not have a function to withdraw the ether |
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / Slither
Conformance to Solidity naming conventions Warning