-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathnested.just
303 lines (272 loc) · 11.5 KB
/
nested.just
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
set dotenv-load
export rpcUrl := env_var_or_default('ETH_RPC_URL', 'https://ethereum.publicnode.com')
export signatures := env_var_or_default('SIGNATURES', '')
export bundleName := env_var_or_default('BUNDLE_NAME', 'input')
export taskPath := invocation_directory()
# Accounts
export councilSafe := env_var("COUNCIL_SAFE")
export foundationSafe := env_var("FOUNDATION_SAFE")
export ownerSafe := env_var('OWNER_SAFE')
export chainGovernorSafe := env_var_or_default('CHAIN_GOVERNOR_SAFE', '')
export randomPersonEoa := "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
# These are two of the anvil default private keys, they are publicly known
export PRIVATE_KEY_OWNER := "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
export PRIVATE_KEY_EXECUTOR :="0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
export ANVIL_LOCALHOST_RPC :="http://localhost:8545"
export FAKE_SIG :="11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
simulate whichSafe hdPath='0':
#!/usr/bin/env bash
bundlePath=${taskPath}/${bundleName}.json
script=NestedSignFromJson
if [ -f "${taskPath}/NestedSignFromJson.s.sol" ]; then
script="${taskPath}/NestedSignFromJson.s.sol"
echo "Running script with assertions"
fi
echo "Using script ${script}"
echo "getting signer address for {{whichSafe}}..."
if [ "{{whichSafe}}" == "foundation" ]; then
safe="{{foundationSafe}}"
fi
if [ "{{whichSafe}}" == "council" ]; then
safe="{{councilSafe}}"
fi
if [ "{{whichSafe}}" == "chain-governor" ]; then
if [ -z "{{chainGovernorSafe}}" ]; then
echo "Error: CHAIN_GOVERNOR_SAFE is not set for chain-governor." >&2
exit 1
fi
safe="{{chainGovernorSafe}}"
fi
signer=$(cast call ${safe} "getOwners()(address[])" -r ${rpcUrl} | grep -oE '0x[a-fA-F0-9]{40}' | head -n1)
root_dir=$(git rev-parse --show-toplevel)
if [ "${FOUNDRY_PROFILE}" == "ci" ]; then
if [[ "${rpcUrl}" == *"sep"* ]]; then
ETH_RPC_URL=$(yq eval ".profile.ci.rpc_endpoints.sepolia" "${root_dir}/foundry.toml")
else
ETH_RPC_URL=$(yq eval ".profile.ci.rpc_endpoints.mainnet" "${root_dir}/foundry.toml")
fi
export ETH_RPC_URL
fi
echo "safe: $safe"
echo "Simulating call to {{whichSafe}} at ${safe}"
if [ -z "$SIMULATE_WITHOUT_LEDGER" ]; then
signer=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")
echo "Simulating with ledger account: ${signer}"
else
echo "Simulating without ledger using the first owner account: ${signer}"
fi
echo ""
forge build
forge script ${script} \
--rpc-url ${rpcUrl} \
--sender ${signer} \
--sig "signJson(string,address)" \
${bundlePath} \
"${safe}"
sign whichSafe hdPath='0':
#!/usr/bin/env bash
bundlePath=${taskPath}/${bundleName}.json
script=NestedSignFromJson
if [ -f "${taskPath}/NestedSignFromJson.s.sol" ]; then
script="${taskPath}/NestedSignFromJson.s.sol"
echo "Running script with assertions"
fi
echo "Using script ${script}"
if [ "{{whichSafe}}" == "foundation" ]; then
safe="{{foundationSafe}}"
echo "Using foundation safe at ${safe}"
fi
if [ "{{whichSafe}}" == "council" ]; then
safe="{{councilSafe}}"
echo "Using council safe at ${safe}"
fi
if [ "{{whichSafe}}" == "chain-governor" ]; then
if [ -z "{{chainGovernorSafe}}" ]; then
echo "Error: CHAIN_GOVERNOR_SAFE is not set for chain-governor." >&2
exit 1
fi
safe="{{chainGovernorSafe}}"
fi
echo "getting signer address..."
signer=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")
echo "Signing with: ${signer}"
echo ""
forge build
# Using the eip712sign within the repo folder since eip712sign was installed there in ./justfile.
$(git rev-parse --show-toplevel)/bin/eip712sign --ledger --hd-paths "m/44'/60'/{{hdPath}}'/0/0" -- \
forge script ${script} \
--rpc-url ${rpcUrl} \
--sig "signJson(string,address)" \
${bundlePath} \
"${safe}"
## approvehash_in_anvil is a function to generate the nested hash and approve the hash for the given safes (SC, or FND) for later executing during the simulation using the execute_in_anvil function.
approvehash_in_anvil whichSafe hdPath='0':
#!/usr/bin/env bash
# set -x
ANVIL_LOCALHOST_RPC="http://localhost:8545"
bundlePath=${taskPath}/${bundleName}.json
script=NestedSignFromJson
signer=""
echo "Approving hash in Anvil.."
if [ -f "${taskPath}/NestedSignFromJson.s.sol" ]; then
script="${taskPath}/NestedSignFromJson.s.sol"
echo "Running script with assertions"
fi
echo "Using script ${script}"
if [ "{{whichSafe}}" == "foundation" ]; then
safe="{{foundationSafe}}"
echo "Using foundation safe at ${safe}"
fi
if [ "{{whichSafe}}" == "council" ]; then
safe="{{councilSafe}}"
echo "Using council safe at ${safe}"
fi
if [ "{{whichSafe}}" == "chain-governor" ]; then
if [ -z "{{chainGovernorSafe}}" ]; then
echo "Error: CHAIN_GOVERNOR_SAFE is not set for chain-governor." >&2
exit 1
fi
safe="{{chainGovernorSafe}}"
fi
echo "Using script ${script} with nested approvehash_in_anvil."
echo "Safe address: ${ownerSafe}"
echo "Getting signer address..."
if [ ! -z "$SIMULATE_WITHOUT_LEDGER" ]; then
signer=$(cast wallet address --private-key ${PRIVATE_KEY_OWNER})
echo "${PRIVATE_KEY_OWNER}"
else
signer=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")
fi
echo "============ OVERRIDE SAFES SETTINGS Parent Safe:'${ownerSafe}' & Child Safe: '${safe}' ============"
echo "1. Set the threshold to 1 of the child safe."
cast rpc anvil_setStorageAt ${safe} 0x0000000000000000000000000000000000000000000000000000000000000004 0x0000000000000000000000000000000000000000000000000000000000000001 --rpc-url ${ANVIL_LOCALHOST_RPC}
echo "2. Set the owner count to 1."
cast rpc anvil_setStorageAt ${safe} 0x0000000000000000000000000000000000000000000000000000000000000003 0x0000000000000000000000000000000000000000000000000000000000000001 --rpc-url ${ANVIL_LOCALHOST_RPC}
# cast index address 0x0000000000000000000000000000000000000001 2 => 0xe90b7bceb6e7df5418fb78d8ee546e97c83a08bbccc01a0644d599ccd2a7c2e0 expected owner mapping: {0x1 -> 0xf39..., 0xf39 -> 0x1}
echo "3. Insert the address 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 as the sole owner of the safe."
cast rpc anvil_setStorageAt ${safe} 0xe90b7bceb6e7df5418fb78d8ee546e97c83a08bbccc01a0644d599ccd2a7c2e0 0x000000000000000000000000f39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url ${ANVIL_LOCALHOST_RPC}
echo "4. Close the mapping of the owners to the sentinel address."
# cast index address 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 2 => 0xbc40fbf4394cd00f78fae9763b0c2c71b21ea442c42fdadc5b720537240ebac1
cast rpc anvil_setStorageAt ${safe} 0xbc40fbf4394cd00f78fae9763b0c2c71b21ea442c42fdadc5b720537240ebac1 0x0000000000000000000000000000000000000000000000000000000000000001 --rpc-url ${ANVIL_LOCALHOST_RPC}
echo "The sole Owner of the \"${safe}\" is: $(cast call ${safe} "getOwners()(address[])" --rpc-url http://localhost:8545)"
echo "================================================"
forge build
outputforge=$(forge script ${script} \
--rpc-url ${ANVIL_LOCALHOST_RPC} \
--private-key {{PRIVATE_KEY_OWNER}} \
--sig "signJson(string,address)" \
${bundlePath} \
${safe})
tempfile=$(mktemp)
echo "tmp file located to:" > $tempfile
echo "Outputforge: $outputforge" > $tempfile
## 1. Generate hash for the SC and FND
hash=$(cat $tempfile | grep -A 1 "If submitting onchain, call Safe.approveHash on " | cut -d ':' -f 2 | tr -d '[:space:]')
if [[ -z "$hash" ]]; then
echo "Hash not found in the file."
exit 10
else
echo "Extracted Hash: $hash"
fi
## 2. Approval of this hash in the SC and FND respectively.
cast send ${safe} "approveHash(bytes32)" ${hash} --rpc-url ${ANVIL_LOCALHOST_RPC} --private-key {{PRIVATE_KEY_OWNER}} 2>&1 /dev/null
## 3. Execute the Approval from another private-key `PRIVATE_KEY_EXECUTOR` on the L1PAO.
# This will revert, if there is an error with the nonce here and throw the GS025 error on the logs.
forge script ${script} \
--rpc-url ${ANVIL_LOCALHOST_RPC} \
--broadcast \
--private-key {{PRIVATE_KEY_EXECUTOR}} \
--sig "approveJson(string,address,bytes)" \
${bundlePath} \
${safe} \
${FAKE_SIG} 2>&1 /dev/null
## execute_in_anvil is a function to execute hash in anvil dedicated for simulation.
execute_in_anvil hdPath='0':
#!/usr/bin/env bash
# set -x
bundlePath=${taskPath}/${bundleName}.json
script=NestedSignFromJson
if [ -f "${taskPath}/NestedSignFromJson.s.sol" ]; then
script="${taskPath}/NestedSignFromJson.s.sol"
echo "Running script with assertions"
fi
echo "Using script ${script}"
if [ ! -z "$SIMULATE_WITHOUT_LEDGER" ]; then
signer=$(cast wallet address --private-key ${PRIVATE_KEY_OWNER}) # corresponding to 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 private-key.
else
signer=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")
fi
## 4. Once the L1PAO has the two approvhashes, we execute the transaction permissionlessly.nested.just
forge build
execution=$(forge script ${script} \
--rpc-url ${ANVIL_LOCALHOST_RPC} \
--broadcast --private-key {{PRIVATE_KEY_EXECUTOR}} \
--sig "runJson(string)" \
${bundlePath} 2>&1)
approve whichSafe hdPath='0':
#!/usr/bin/env bash
bundlePath=${taskPath}/${bundleName}.json
script=NestedSignFromJson
if [ -f "${taskPath}/NestedSignFromJson.s.sol" ]; then
script="${taskPath}/NestedSignFromJson.s.sol"
echo "Running script with assertions"
fi
echo "Using script ${script}"
if [ "{{whichSafe}}" == "foundation" ]; then
safe="{{foundationSafe}}"
echo "Using foundation safe at ${safe}"
fi
if [ "{{whichSafe}}" == "council" ]; then
safe="{{councilSafe}}"
echo "Using council safe at ${safe}"
fi
if [ "{{whichSafe}}" == "chain-governor" ]; then
if [ -z "{{chainGovernorSafe}}" ]; then
echo "Error: CHAIN_GOVERNOR_SAFE is not set for chain-governor." >&2
exit 1
fi
safe="{{chainGovernorSafe}}"
fi
sender=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")
forge build
forge script ${script} \
--fork-url ${rpcUrl} \
--ledger --hd-paths "m/44'/60'/{{hdPath}}'/0/0" \
--broadcast \
--sender ${sender} \
--sig "approveJson(string,address,bytes)" \
${bundlePath} \
${safe} \
${signatures}
execute hdPath='0':
#!/usr/bin/env bash
bundlePath=${taskPath}/${bundleName}.json
script=NestedSignFromJson
if [ -f "${taskPath}/NestedSignFromJson.s.sol" ]; then
script="${taskPath}/NestedSignFromJson.s.sol"
echo "Running script with assertions"
fi
echo "Using script ${script}"
sender=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")
forge script ${script} \
--fork-url ${rpcUrl} \
--ledger --hd-paths "m/44'/60'/{{hdPath}}'/0/0" \
--broadcast \
--sender ${sender} \
--sig "runJson(string)" \
${bundlePath}
simulated-run hdPath='0':
#!/usr/bin/env bash
bundlePath=${taskPath}/${bundleName}.json
script=NestedSignFromJson
if [ -f "${taskPath}/NestedSignFromJson.s.sol" ]; then
script="${taskPath}/NestedSignFromJson.s.sol"
echo "Running script with assertions"
fi
echo "Using script ${script}"
forge build
forge script ${script} \
--fork-url ${rpcUrl} \
--sender ${randomPersonEoa} \
--sig "runJson(string)" \
${bundlePath}