Skip to content

Commit 932ac22

Browse files
committed
2.1.3 action + script
1 parent 6340a2c commit 932ac22

File tree

7 files changed

+257
-0
lines changed

7 files changed

+257
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity 0.8.16;
3+
4+
import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
5+
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
6+
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
7+
8+
interface IInbox {
9+
function bridge() external view returns (address);
10+
function sequencerInbox() external view returns (address);
11+
}
12+
13+
interface IERC20Bridge {
14+
function nativeToken() external view returns (address);
15+
}
16+
17+
interface IERC20Bridge_v2 {
18+
function nativeTokenDecimals() external view returns (uint8);
19+
}
20+
21+
/**
22+
* @title NitroContracts2Point1Point3UpgradeAction
23+
* @notice Upgrade the bridge to Inbox and SequencerInbox to v2.1.3
24+
* Will revert if the bridge is an ERC20Bridge below v2.x.x
25+
*/
26+
contract NitroContracts2Point1Point3UpgradeAction {
27+
address public immutable newEthInboxImpl;
28+
address public immutable newERC20InboxImpl;
29+
address public immutable newSequencerInboxImpl;
30+
31+
constructor(address _newEthInboxImpl, address _newERC20InboxImpl, address _newSequencerInboxImpl) {
32+
require(
33+
Address.isContract(_newEthInboxImpl),
34+
"NitroContracts2Point1Point3UpgradeAction: _newEthInboxImpl is not a contract"
35+
);
36+
require(
37+
Address.isContract(_newERC20InboxImpl),
38+
"NitroContracts2Point1Point3UpgradeAction: _newERC20InboxImpl is not a contract"
39+
);
40+
require(
41+
Address.isContract(_newSequencerInboxImpl),
42+
"NitroContracts2Point1Point3UpgradeAction: _newSequencerInboxImpl is not a contract"
43+
);
44+
45+
newEthInboxImpl = _newEthInboxImpl;
46+
newERC20InboxImpl = _newERC20InboxImpl;
47+
newSequencerInboxImpl = _newSequencerInboxImpl;
48+
}
49+
50+
function perform(address inbox, ProxyAdmin proxyAdmin) external {
51+
address bridge = IInbox(inbox).bridge();
52+
address sequencerInbox = IInbox(inbox).sequencerInbox();
53+
54+
bool isERC20 = false;
55+
56+
// if the bridge is an ERC20Bridge below v2.x.x, revert
57+
try IERC20Bridge(bridge).nativeToken() returns (address) {}
58+
catch {
59+
isERC20 = true;
60+
// it is an ERC20Bridge, check if it is on v2.x.x
61+
try IERC20Bridge_v2(address(bridge)).nativeTokenDecimals() returns (uint8) {}
62+
catch {
63+
// it is not on v2.x.x, revert
64+
revert("NitroContracts2Point1Point3UpgradeAction: bridge is an ERC20Bridge below v2.x.x");
65+
}
66+
}
67+
68+
// upgrade the sequencer inbox
69+
proxyAdmin.upgrade({
70+
proxy: TransparentUpgradeableProxy(payable((sequencerInbox))),
71+
implementation: newSequencerInboxImpl
72+
});
73+
74+
// upgrade the inbox
75+
proxyAdmin.upgrade({
76+
proxy: TransparentUpgradeableProxy(payable((inbox))),
77+
implementation: isERC20 ? newERC20InboxImpl : newEthInboxImpl
78+
});
79+
}
80+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@arbitrum/nitro-contracts-1.3.0": "npm:@arbitrum/[email protected]",
3030
"@arbitrum/nitro-contracts-2.1.0": "npm:@arbitrum/[email protected]",
3131
"@arbitrum/nitro-contracts-2.1.2": "npm:[email protected]",
32+
"@arbitrum/nitro-contracts-2.1.3": "npm:[email protected]",
3233
"@arbitrum/token-bridge-1.2.2": "npm:@arbitrum/[email protected]",
3334
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
3435
"@nomicfoundation/hardhat-ethers": "^3.0.0",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## These env vars are used for ExecuteNitroContracts2Point1Point2UpgradeScript
2+
3+
UPGRADE_ACTION_ADDRESS=
4+
INBOX_ADDRESS=
5+
PROXY_ADMIN_ADDRESS=
6+
PARENT_UPGRADE_EXECUTOR_ADDRESS=
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity 0.8.16;
3+
4+
import {DeploymentHelpersScript} from "../../helper/DeploymentHelpers.s.sol";
5+
import {NitroContracts2Point1Point3UpgradeAction} from
6+
"../../../../contracts/parent-chain/contract-upgrades/NitroContracts2Point1Point3UpgradeAction.sol";
7+
8+
/**
9+
* @title DeployNitroContracts2Point1Point2UpgradeActionScript
10+
* @notice This script deploys the ERC20Bridge contract and NitroContracts2Point1Point2UpgradeAction contract.
11+
*/
12+
contract DeployNitroContracts2Point1Point3UpgradeActionScript is DeploymentHelpersScript {
13+
function run() public {
14+
vm.startBroadcast();
15+
16+
// deploy new ERC20Inbox contract from v2.1.3
17+
address newEthInboxImpl = deployBytecodeFromJSON(
18+
"/node_modules/@arbitrum/nitro-contracts-2.1.3/build/contracts/src/bridge/Inbox.sol/Inbox.json"
19+
);
20+
// deploy new ERC20Inbox contract from v2.1.3
21+
address newERC20InboxImpl = deployBytecodeFromJSON(
22+
"/node_modules/@arbitrum/nitro-contracts-2.1.3/build/contracts/src/bridge/ERC20Inbox.sol/ERC20Inbox.json"
23+
);
24+
// deploy new ERC20Inbox contract from v2.1.3
25+
address newSeqInboxImpl = deployBytecodeFromJSON(
26+
"/node_modules/@arbitrum/nitro-contracts-2.1.3/build/contracts/src/bridge/SequencerInbox.sol/SequencerInbox.json"
27+
);
28+
29+
// deploy upgrade action
30+
new NitroContracts2Point1Point3UpgradeAction(newEthInboxImpl, newERC20InboxImpl, newSeqInboxImpl);
31+
32+
vm.stopBroadcast();
33+
}
34+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity 0.8.16;
3+
4+
import "forge-std/Script.sol";
5+
import {
6+
NitroContracts2Point1Point3UpgradeAction,
7+
ProxyAdmin
8+
} from "../../../../contracts/parent-chain/contract-upgrades/NitroContracts2Point1Point3UpgradeAction.sol";
9+
import {IInboxBase} from "@arbitrum/nitro-contracts-1.2.1/src/bridge/IInboxBase.sol";
10+
import {IERC20Bridge} from "@arbitrum/nitro-contracts-2.1.2/src/bridge/IERC20Bridge.sol";
11+
import {IUpgradeExecutor} from "@offchainlabs/upgrade-executor/src/IUpgradeExecutor.sol";
12+
13+
/**
14+
* @title ExecuteNitroContracts1Point2Point3UpgradeScript
15+
* @notice This script executes nitro contracts 2.1.3 upgrade through UpgradeExecutor
16+
*/
17+
contract ExecuteNitroContracts2Point1Point3UpgradeScript is Script {
18+
function run() public {
19+
NitroContracts2Point1Point3UpgradeAction upgradeAction =
20+
NitroContracts2Point1Point3UpgradeAction(vm.envAddress("UPGRADE_ACTION_ADDRESS"));
21+
22+
address inbox = (vm.envAddress("INBOX_ADDRESS"));
23+
24+
// prepare upgrade calldata
25+
ProxyAdmin proxyAdmin = ProxyAdmin(vm.envAddress("PROXY_ADMIN_ADDRESS"));
26+
bytes memory upgradeCalldata =
27+
abi.encodeCall(NitroContracts2Point1Point3UpgradeAction.perform, (inbox, proxyAdmin));
28+
29+
// execute the upgrade
30+
// action checks prerequisites, and script will fail if the action reverts
31+
IUpgradeExecutor executor = IUpgradeExecutor(vm.envAddress("PARENT_UPGRADE_EXECUTOR_ADDRESS"));
32+
vm.startBroadcast();
33+
executor.execute(address(upgradeAction), upgradeCalldata);
34+
vm.stopBroadcast();
35+
}
36+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# TODO: FIX, THIS IS COPIED FROM 2.1.2
2+
3+
# Nitro contracts 2.1.2 upgrade
4+
5+
> [!CAUTION]
6+
> This is a patch version and is only necessary for custom fee token chains with an `ERC20Bridge` contract below version `< v2.0.0`.
7+
>
8+
> If your chain uses the parent chain's native asset for fees, or your `ERC20Bridge` is already at `v2.0.0` or above, do not perform this upgrade.
9+
>
10+
> The rest of this document assumes the chain satisfies the above.
11+
12+
These scripts deploy and execute the `NitroContracts2Point1Point2UpgradeAction` contract which allows Orbit chains to upgrade to [2.1.2 release](https://github.com/OffchainLabs/nitro-contracts/releases/tag/v2.1.2). Predeployed instances of the upgrade action exist on the chains listed in the following section.
13+
14+
Upgrading to `v2.1.2` is REQUIRED before upgrading to `v3.0.0`. Upgrading to `v2.1.0` is REQUIRED before upgrading to `v2.1.2`.
15+
16+
`NitroContracts2Point1Point2UpgradeAction` will perform the following action:
17+
18+
1. Upgrade the `ERC20Bridge` contract to `v2.1.2`
19+
1. Force `nativeTokenDecimals` to 18
20+
21+
It is assumed that the native token has 18 decimals, since this was a requirement for deploying a custom fee token chain prior to `v2.0.0`.
22+
23+
## Requirements
24+
25+
This upgrade only support upgrading from the following [nitro-contract release](https://github.com/OffchainLabs/nitro-contracts/releases):
26+
27+
- Inbox: v1.1.0 - v1.3.0 inclusive
28+
- Outbox: v1.1.0 - v1.3.0 inclusive
29+
- SequencerInbox: v1.2.1 - v2.1.0 inclusive
30+
- Bridge: v1.1.0 - v1.3.0 inclusive
31+
- RollupProxy: v1.1.0 - v2.1.0 inclusive
32+
- RollupAdminLogic: v2.1.0
33+
- RollupUserLogic: v2.1.0
34+
- ChallengeManager: v2.1.0
35+
36+
Please refer to the top [README](/README.md#check-version-and-upgrade-path) `Check Version and Upgrade Path` on how to determine your current nitro contracts version.
37+
38+
## Deployed instances
39+
40+
### Mainnets
41+
- L1 Mainnet: TODO
42+
- L2 Arb1: TODO
43+
- L2 Nova: TODO
44+
- L2 Base: TODO
45+
46+
### Testnets
47+
- L1 Sepolia: TODO
48+
- L1 Holesky: TODO
49+
- L2 ArbSepolia: TODO
50+
- L2 BaseSepolia: TODO
51+
52+
## How to use it
53+
54+
1. Setup .env according to the example files, make sure you have everything correctly defined. The .env file must be in project root for recent foundry versions.
55+
56+
> [!CAUTION]
57+
> The .env file must be in project root.
58+
59+
2. (Skip this step if you can use the deployed instances of action contract)
60+
`DeployNitroContracts2Point1Point2UpgradeActionScript.s.sol` script deploys templates, and upgrade action itself. It can be executed in this directory like this:
61+
62+
```bash
63+
forge script --sender $DEPLOYER --rpc-url $PARENT_CHAIN_RPC --broadcast --slow DeployNitroContracts2Point1Point2UpgradeActionScript -vvv --verify --skip-simulation
64+
# use --account XXX / --private-key XXX / --interactive / --ledger to set the account to send the transaction from
65+
```
66+
67+
As a result, all templates and upgrade action are deployed. Note the last deployed address - that's the upgrade action.
68+
69+
3. `ExecuteNitroContracts2Point1Point2Upgrade.s.sol` script uses previously deployed upgrade action to execute the upgrade. It makes following assumptions - L1UpgradeExecutor is the rollup owner, and there is an EOA which has executor rights on the L1UpgradeExecutor. Proceed with upgrade using the owner account (the one with executor rights on L1UpgradeExecutor):
70+
71+
```bash
72+
forge script --sender $EXECUTOR --rpc-url $PARENT_CHAIN_RPC --broadcast ExecuteNitroContracts2Point1Point2UpgradeScript -vvv
73+
# use --account XXX / --private-key XXX / --interactive / --ledger to set the account to send the transaction from
74+
```
75+
76+
If you have a multisig as executor, you can still run the above command without broadcasting to get the payload for the multisig transaction.
77+
78+
4. That's it, upgrade has been performed. You can make sure it has successfully executed by checking the native token decimals.
79+
80+
```bash
81+
# should return 18
82+
cast call --rpc-url $PARENT_CHAIN_RPC $BRIDGE "nativeTokenDecimals()(uint8)"
83+
```
84+
85+
## FAQ
86+
87+
### Q: intrinsic gas too low when running foundry script
88+
89+
A: try to add -g 1000 to the command

yarn.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@
5454
patch-package "^6.4.7"
5555
solady "0.0.182"
5656

57+
"@arbitrum/nitro-contracts-2.1.3@npm:[email protected]":
58+
version "2.1.3-0"
59+
resolved "https://registry.yarnpkg.com/godzillaba-nitro-contracts/-/godzillaba-nitro-contracts-2.1.3-0.tgz#c2a0dc6e0f13bc650eede99b40863b71a6e84466"
60+
integrity sha512-SPQeF9vQupq2oNEKbXdMvAf2cp27oScOvg2xqA5WTvD1c4qPhXZgeAHtwLRuLpcUxerpodDLd2Q+UFG5li4+Mg==
61+
dependencies:
62+
"@offchainlabs/upgrade-executor" "1.1.0-beta.0"
63+
"@openzeppelin/contracts" "4.5.0"
64+
"@openzeppelin/contracts-upgradeable" "4.5.2"
65+
patch-package "^6.4.7"
66+
solady "0.0.182"
67+
5768
"@arbitrum/[email protected]":
5869
version "1.1.1"
5970
resolved "https://registry.yarnpkg.com/@arbitrum/nitro-contracts/-/nitro-contracts-1.1.1.tgz#2d8a2f9ab757bb7654562aebe435bff833c4b98d"

0 commit comments

Comments
 (0)