Skip to content

Commit 7db1acc

Browse files
authored
feat: add contract upgrade script for fp (#450)
* feat: add contract upgrade script for fp * docs: add l1 rpc url * feat(fault-proof): support dry run
1 parent f75036e commit 7db1acc

File tree

5 files changed

+171
-3
lines changed

5 files changed

+171
-3
lines changed

book/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- [Quick Start](./fault_proofs/quick_start.md)
2727
- [Best Practices](./fault_proofs/best_practices.md)
2828
- [Deploy FP Contracts](./fault_proofs/deploy.md)
29+
- [Upgrade FP Contracts](./fault_proofs/upgrade.md)
2930
- [How to run the FP Proposer](./fault_proofs/proposer.md)
3031
- [How to run the FP Challenger](./fault_proofs/challenger.md)
3132
- [Running with Docker](./fault_proofs/docker.md)

book/fault_proofs/upgrade.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Upgrading the OPSuccinct Fault Dispute Game
2+
3+
This guide explains how to upgrade the OPSuccinct Fault Dispute Game contract.
4+
5+
## Overview
6+
7+
The upgrade script performs the following actions:
8+
1. Deploys a new implementation of the `OPSuccinctFaultDisputeGame` contract
9+
2. Sets the new implementation in the `DisputeGameFactory` for the specified game type
10+
11+
### Required Environment Variables
12+
13+
Create a `.env` file in the contracts directory with the following variables:
14+
15+
| Variable | Description | Example |
16+
|----------|-------------|---------|
17+
| `FACTORY_ADDRESS` | Address of the existing DisputeGameFactory | `0x...` |
18+
| `GAME_TYPE` | Unique identifier for the game type (uint32) | `42` |
19+
| `MAX_CHALLENGE_DURATION` | Maximum duration for challenges in seconds | `604800` for 7 days |
20+
| `MAX_PROVE_DURATION` | Maximum duration for proving in seconds | `86400` for 1 day |
21+
| `VERIFIER_ADDRESS` | Address of the SP1 verifier | `0x...` |
22+
| `ROLLUP_CONFIG_HASH` | Hash of the rollup configuration | `0x...` |
23+
| `AGGREGATION_VKEY` | Verification key for aggregation | `0x...` |
24+
| `RANGE_VKEY_COMMITMENT` | Commitment to range verification key | `0x...` |
25+
| `ANCHOR_STATE_REGISTRY` | Address of the AnchorStateRegistry | `0x...` |
26+
| `ACCESS_MANAGER` | Address of the AccessManager | `0x...` |
27+
28+
### Getting the Rollup Config Hash, Aggregation Verification Key, and Range Verification Key Commitment
29+
30+
First, create a `.env` file in the root directory with the following variables:
31+
```bash
32+
L1_RPC=<L1_RPC_URL>
33+
L1_BEACON_RPC=<L1_BEACON_RPC_URL>
34+
L2_RPC=<L2_RPC_URL>
35+
L2_NODE_RPC=<L2_NODE_RPC_URL>
36+
```
37+
38+
You can get the aggregation program verification key, range program verification key commitment, and rollup config hash by running the following command:
39+
40+
```bash
41+
cargo run --bin config --release -- --env-file <PATH_TO_ENV_FILE>
42+
```
43+
44+
### Optional Environment Variables
45+
46+
| Variable | Description | Default | Example |
47+
|----------|-------------|---------|---------|
48+
| `CHALLENGER_BOND_WEI` | Challenger bond for the game | `0.001 ether` | `1000000000000000` |
49+
50+
Use `cast --to-wei <value> eth` to convert the value to wei to avoid mistakes.
51+
52+
## Upgrade Command
53+
54+
Dry run the upgrade command in the root directory of the project:
55+
```bash
56+
DRY_RUN=true just -f fault-proof/justfile --dotenv-filename contracts/.env upgrade-fault-dispute-game
57+
```
58+
59+
Run the upgrade command in the root directory of the project:
60+
```bash
61+
DRY_RUN=false just -f fault-proof/justfile --dotenv-filename contracts/.env upgrade-fault-dispute-game
62+
```
63+
64+
## Verification
65+
66+
You can verify the upgrade by running the following command:
67+
```bash
68+
cast call <FACTORY_ADDRESS> "gameImpls(uint32)" <GAME_TYPE> --rpc-url <L1_RPC_URL>
69+
```
70+
71+
## Troubleshooting
72+
73+
Common issues and solutions:
74+
75+
1. **Compilation Errors**:
76+
- Run `cd contracts && forge clean`
77+
78+
2. **Deployment Failures**:
79+
- Check RPC connection
80+
- Verify sufficient ETH balance
81+
- Confirm environment variables are set correctly
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.15;
3+
4+
// Libraries
5+
import {Script} from "forge-std/Script.sol";
6+
import {console} from "forge-std/console.sol";
7+
import {GameType, Duration} from "src/dispute/lib/Types.sol";
8+
9+
// Interfaces
10+
import {IDisputeGame} from "interfaces/dispute/IDisputeGame.sol";
11+
import {IDisputeGameFactory} from "interfaces/dispute/IDisputeGameFactory.sol";
12+
import {ISP1Verifier} from "@sp1-contracts/src/ISP1Verifier.sol";
13+
import {IAnchorStateRegistry} from "interfaces/dispute/IAnchorStateRegistry.sol";
14+
15+
// Contracts
16+
import {OPSuccinctFaultDisputeGame} from "../../src/fp/OPSuccinctFaultDisputeGame.sol";
17+
import {DisputeGameFactory} from "src/dispute/DisputeGameFactory.sol";
18+
import {AccessManager} from "../../src/fp/AccessManager.sol";
19+
20+
contract UpgradeOPSuccinctFDG is Script {
21+
function run() public {
22+
vm.startBroadcast();
23+
24+
// Get the factory.
25+
address factoryAddress = vm.envAddress("FACTORY_ADDRESS");
26+
DisputeGameFactory factory = DisputeGameFactory(factoryAddress);
27+
28+
// Get the game type.
29+
GameType gameType = GameType.wrap(uint32(vm.envUint("GAME_TYPE")));
30+
31+
// Deploy new implementation.
32+
OPSuccinctFaultDisputeGame newImpl = new OPSuccinctFaultDisputeGame(
33+
Duration.wrap(uint64(vm.envUint("MAX_CHALLENGE_DURATION"))),
34+
Duration.wrap(uint64(vm.envUint("MAX_PROVE_DURATION"))),
35+
IDisputeGameFactory(factoryAddress),
36+
ISP1Verifier(vm.envAddress("VERIFIER_ADDRESS")),
37+
vm.envBytes32("ROLLUP_CONFIG_HASH"),
38+
vm.envBytes32("AGGREGATION_VKEY"),
39+
vm.envBytes32("RANGE_VKEY_COMMITMENT"),
40+
vm.envOr("CHALLENGER_BOND_WEI", uint256(0.001 ether)),
41+
IAnchorStateRegistry(vm.envAddress("ANCHOR_STATE_REGISTRY")),
42+
AccessManager(vm.envAddress("ACCESS_MANAGER"))
43+
);
44+
45+
console.log("New OPSuccinctFaultDisputeGame implementation deployed at: ", address(newImpl));
46+
47+
// Set the new implementation.
48+
factory.setImplementation(gameType, IDisputeGame(address(newImpl)));
49+
50+
console.log("New implementation set in factory: ", address(factory.gameImpls(gameType)));
51+
52+
vm.stopBroadcast();
53+
}
54+
}

contracts/src/fp/OPSuccinctFaultDisputeGame.sol

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,18 @@ contract OPSuccinctFaultDisputeGame is Clone, ISemver, IDisputeGame {
641641
disputeGameFactory_ = DISPUTE_GAME_FACTORY;
642642
}
643643

644+
/// @notice Returns the challenger bond amount.
645+
function challengerBond() external view returns (uint256 challengerBond_) {
646+
challengerBond_ = CHALLENGER_BOND;
647+
}
648+
644649
/// @notice Returns the anchor state registry contract.
645650
function anchorStateRegistry() external view returns (IAnchorStateRegistry registry_) {
646651
registry_ = ANCHOR_STATE_REGISTRY;
647652
}
648653

649-
/// @notice Returns the challenger bond amount.
650-
function challengerBond() external view returns (uint256 challengerBond_) {
651-
challengerBond_ = CHALLENGER_BOND;
654+
/// @notice Returns the access manager contract.
655+
function accessManager() external view returns (AccessManager accessManager_) {
656+
accessManager_ = ACCESS_MANAGER;
652657
}
653658
}

fault-proof/justfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
default:
2+
@just --list
3+
4+
# Upgrade the OPSuccinct Fault Dispute Game implementation.
5+
upgrade-fault-dispute-game:
6+
#!/usr/bin/env bash
7+
set -euo pipefail
8+
9+
# cd into contracts directory.
10+
cd ../contracts
11+
12+
# Install dependencies.
13+
forge install
14+
15+
# Run the forge upgrade script.
16+
if [ "${DRY_RUN}" = "false" ]; then
17+
forge script script/fp/UpgradeOPSuccinctFDG.s.sol:UpgradeOPSuccinctFDG \
18+
--rpc-url $L1_RPC \
19+
--private-key $PRIVATE_KEY \
20+
--etherscan-api-key $ETHERSCAN_API_KEY \
21+
--broadcast
22+
else
23+
forge script script/fp/UpgradeOPSuccinctFDG.s.sol:UpgradeOPSuccinctFDG \
24+
--rpc-url $L1_RPC \
25+
--private-key $PRIVATE_KEY \
26+
--etherscan-api-key $ETHERSCAN_API_KEY
27+
fi

0 commit comments

Comments
 (0)