-
Notifications
You must be signed in to change notification settings - Fork 33
/
justfile
217 lines (185 loc) · 7.96 KB
/
justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
default:
@just --list
# Runs the op-succinct program for a single block.
run-single l2_block_num use-cache="false" prove="false":
#!/usr/bin/env bash
CACHE_FLAG=""
if [ "{{use-cache}}" = "true" ]; then
CACHE_FLAG="--use-cache"
fi
PROVE_FLAG=""
if [ "{{prove}}" = "true" ]; then
PROVE_FLAG="--prove"
fi
cargo run --bin single --release -- --l2-block {{l2_block_num}} $CACHE_FLAG $PROVE_FLAG
# Runs the op-succinct program for multiple blocks.
run-multi start end use-cache="false" prove="false":
#!/usr/bin/env bash
CACHE_FLAG=""
if [ "{{use-cache}}" = "true" ]; then
CACHE_FLAG="--use-cache"
fi
PROVE_FLAG=""
if [ "{{prove}}" = "true" ]; then
PROVE_FLAG="--prove"
fi
cargo run --bin multi --release -- --start {{start}} --end {{end}} $CACHE_FLAG $PROVE_FLAG
# Runs the cost estimator for a given block range.
cost-estimator start end:
#!/usr/bin/env bash
cargo run --bin cost-estimator --release -- --start {{start}} --end {{end}}
# Runs the client program in native execution mode. Modified version of Kona Native Client execution:
# https://github.com/ethereum-optimism/kona/blob/ae71b9df103c941c06b0dc5400223c4f13fe5717/bin/client/justfile#L65-L108
run-client-native l2_block_num l1_rpc='${L1_RPC}' l1_beacon_rpc='${L1_BEACON_RPC}' l2_rpc='${L2_RPC}' verbosity="-vvvv":
#!/usr/bin/env bash
L1_NODE_ADDRESS="{{l1_rpc}}"
L1_BEACON_ADDRESS="{{l1_beacon_rpc}}"
L2_NODE_ADDRESS="{{l2_rpc}}"
echo "L1 Node Address: $L1_NODE_ADDRESS"
echo "L1 Beacon Address: $L1_BEACON_ADDRESS"
echo "L2 Node Address: $L2_NODE_ADDRESS"
HOST_BIN_PATH="./kona-host"
CLIENT_BIN_PATH="$(pwd)/target/release-client-lto/fault-proof"
L2_BLOCK_NUMBER="{{l2_block_num}}"
L2_BLOCK_SAFE_HEAD=$((L2_BLOCK_NUMBER - 1))
L2_OUTPUT_STATE_ROOT=$(cast block --rpc-url $L2_NODE_ADDRESS --field stateRoot $L2_BLOCK_SAFE_HEAD)
L2_HEAD=$(cast block --rpc-url $L2_NODE_ADDRESS --field hash $L2_BLOCK_SAFE_HEAD)
L2_OUTPUT_STORAGE_HASH=$(cast proof --rpc-url $L2_NODE_ADDRESS --block $L2_BLOCK_SAFE_HEAD 0x4200000000000000000000000000000000000016 | jq -r '.storageHash')
L2_OUTPUT_ENCODED=$(cast abi-encode "x(uint256,bytes32,bytes32,bytes32)" 0 $L2_OUTPUT_STATE_ROOT $L2_OUTPUT_STORAGE_HASH $L2_HEAD)
L2_OUTPUT_ROOT=$(cast keccak $L2_OUTPUT_ENCODED)
echo "L2 Safe Head: $L2_BLOCK_SAFE_HEAD"
echo "Safe Head Output Root: $L2_OUTPUT_ROOT"
L2_CLAIM_STATE_ROOT=$(cast block --rpc-url $L2_NODE_ADDRESS --field stateRoot $L2_BLOCK_NUMBER)
L2_CLAIM_HASH=$(cast block --rpc-url $L2_NODE_ADDRESS --field hash $L2_BLOCK_NUMBER)
L2_CLAIM_STORAGE_HASH=$(cast proof --rpc-url $L2_NODE_ADDRESS --block $L2_BLOCK_NUMBER 0x4200000000000000000000000000000000000016 | jq -r '.storageHash')
L2_CLAIM_ENCODED=$(cast abi-encode "x(uint256,bytes32,bytes32,bytes32)" 0 $L2_CLAIM_STATE_ROOT $L2_CLAIM_STORAGE_HASH $L2_CLAIM_HASH)
L2_CLAIM=$(cast keccak $L2_CLAIM_ENCODED)
echo "L2 Block Number: $L2_BLOCK_NUMBER"
echo "L2 Claim Root: $L2_CLAIM"
L2_BLOCK_TIMESTAMP=$(cast block --rpc-url $L2_NODE_ADDRESS $L2_BLOCK_NUMBER -j | jq -r .timestamp)
L1_HEAD=$(cast block --rpc-url $L1_NODE_ADDRESS $(cast find-block --rpc-url $L1_NODE_ADDRESS $(($(cast 2d $L2_BLOCK_TIMESTAMP) + 300))) -j | jq -r .hash)
echo "L1 Head: $L1_HEAD"
L2_CHAIN_ID=10
DATA_DIRECTORY="./data/$L2_BLOCK_NUMBER"
echo "Saving Data to $DATA_DIRECTORY"
echo "Building client program..."
cargo build --bin fault-proof --profile release-client-lto
echo "Running host program with native client program..."
cargo run --bin op-succinct-witnessgen --release -- \
--l1-head $L1_HEAD \
--l2-head $L2_HEAD \
--l2-claim $L2_CLAIM \
--l2-output-root $L2_OUTPUT_ROOT \
--l2-block-number $L2_BLOCK_NUMBER \
--l2-chain-id $L2_CHAIN_ID \
--l1-node-address $L1_NODE_ADDRESS \
--l1-beacon-address $L1_BEACON_ADDRESS \
--l2-node-address $L2_NODE_ADDRESS \
--exec $CLIENT_BIN_PATH \
--data-dir $DATA_DIRECTORY \
{{verbosity}}
# Output the data required for the ZKVM execution.
echo "$L1_HEAD $L2_OUTPUT_ROOT $L2_CLAIM $L2_BLOCK_NUMBER $L2_CHAIN_ID"
upgrade-l2oo l1_rpc admin_pk etherscan_api_key="":
#!/usr/bin/env bash
CHAIN_ID=$(jq -r '.chainId' contracts/opsuccinctl2ooconfig.json)
if [ "$CHAIN_ID" = "0" ] || [ -z "$CHAIN_ID" ]; then
echo "Are you sure you've filled out your opsuccinctl2ooconfig.json? Your chain ID is currently set to 0."
exit 1
fi
VERIFY=""
ETHERSCAN_API_KEY="{{etherscan_api_key}}"
if [ $ETHERSCAN_API_KEY != "" ]; then
VERIFY="--verify --verifier etherscan --etherscan-api-key $ETHERSCAN_API_KEY"
fi
L1_RPC="{{l1_rpc}}"
ADMIN_PK="{{admin_pk}}"
cd contracts && forge script script/OPSuccinctUpgrader.s.sol:OPSuccinctUpgrader --rpc-url $L1_RPC --private-key $ADMIN_PK $VERIFY --broadcast --slow
# Deploy mock verifier
deploy-mock-verifier env_file=".env":
#!/usr/bin/env bash
set -a
source {{env_file}}
set +a
if [ -z "$L1_RPC" ]; then
echo "L1_RPC not set in {{env_file}}"
exit 1
fi
if [ -z "$PRIVATE_KEY" ]; then
echo "PRIVATE_KEY not set in {{env_file}}"
exit 1
fi
VERIFY_FLAGS=""
if [ ! -z "$ETHERSCAN_API_KEY" ]; then
VERIFY_FLAGS="--verify --verifier etherscan --etherscan-api-key $ETHERSCAN_API_KEY"
fi
cd contracts
forge script script/DeployMockVerifier.s.sol:DeployMockVerifier \
--rpc-url $L1_RPC \
--private-key $PRIVATE_KEY \
--broadcast \
$VERIFY_FLAGS
# Deploy the OPSuccinct L2 Output Oracle
deploy-oracle env_file=".env":
#!/usr/bin/env bash
set -euo pipefail
# First fetch rollup config using the env file
RUST_LOG=info cargo run --bin fetch-rollup-config --release -- --env-file {{env_file}}
# Load environment variables
source {{env_file}}
# cd into contracts directory
cd contracts
# Run the forge deployment script
forge script script/OPSuccinctDeployer.s.sol:OPSuccinctDeployer \
--rpc-url $L1_RPC \
--private-key $PRIVATE_KEY \
--broadcast \
--verify \
--verifier etherscan \
--etherscan-api-key $ETHERSCAN_API_KEY
# Upgrade the OPSuccinct L2 Output Oracle
upgrade-oracle env_file=".env":
#!/usr/bin/env bash
set -euo pipefail
# First fetch rollup config using the env file
RUST_LOG=info cargo run --bin fetch-rollup-config --release -- --env-file {{env_file}}
# Load environment variables
source {{env_file}}
# cd into contracts directory
cd contracts
# Run the forge upgrade script
if [ "${EXECUTE_UPGRADE_CALL:-true}" = "false" ]; then
L2OO_ADDRESS=$L2OO_ADDRESS forge script script/OPSuccinctUpgrader.s.sol:OPSuccinctUpgrader \
--rpc-url $L1_RPC \
--private-key $PRIVATE_KEY \
--etherscan-api-key $ETHERSCAN_API_KEY
else
L2OO_ADDRESS=$L2OO_ADDRESS forge script script/OPSuccinctUpgrader.s.sol:OPSuccinctUpgrader \
--rpc-url $L1_RPC \
--private-key $PRIVATE_KEY \
--verify \
--verifier etherscan \
--etherscan-api-key $ETHERSCAN_API_KEY \
--broadcast
fi
# Update the parameters of the OPSuccinct L2 Output Oracle
update-parameters env_file=".env":
#!/usr/bin/env bash
set -euo pipefail
# First fetch rollup config using the env file
RUST_LOG=info cargo run --bin fetch-rollup-config --release -- --env-file {{env_file}}
# Load environment variables
source {{env_file}}
# cd into contracts directory
cd contracts
# Run the forge upgrade script
if [ "${EXECUTE_UPGRADE_CALL:-true}" = "false" ]; then
L2OO_ADDRESS=$L2OO_ADDRESS forge script script/OPSuccinctParameterUpdater.s.sol:OPSuccinctParameterUpdater \
--rpc-url $L1_RPC \
--private-key $PRIVATE_KEY
else
L2OO_ADDRESS=$L2OO_ADDRESS forge script script/OPSuccinctParameterUpdater.s.sol:OPSuccinctParameterUpdater \
--rpc-url $L1_RPC \
--private-key $PRIVATE_KEY \
--broadcast
fi