-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathsingle.just
183 lines (156 loc) · 7.65 KB
/
single.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
set dotenv-load
export rpcUrl := env_var('ETH_RPC_URL')
export signatures := env_var_or_default('SIGNATURES', '')
export bundleName := env_var_or_default('BUNDLE_NAME', 'input')
export taskPath := invocation_directory()
export ownerSafe := env_var('OWNER_SAFE')
PRIVATE_KEY_OWNER := "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
PRIVATE_KEY_EXECUTOR :="0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
export FAKE_SIG :="11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
approvehash_in_anvil hdPath='0':
#!/usr/bin/env bash
echo "simulating in anvil"
localrpcUrl="http://localhost:8545"
bundlePath=${taskPath}/${bundleName}.json
script=SignFromJson
if [ -f "${taskPath}/SignFromJson.s.sol" ]; then
script="${taskPath}/SignFromJson.s.sol"
fi
echo "Using script ${script} with simulate_in_anvil."
echo "Safe address: ${ownerSafe}"
echo "Getting signer address..."
if [ ! -z "$SIMULATE_WITHOUT_LEDGER" ]; then
signer=$(cast wallet address --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80) # corresponding to 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 private-key.
else
signer=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")
fi
echo "Simulating with: ${signer}"
echo ""
echo "============ OVERRIDE SAFE SETTINGS '${ownerSafe}' ============"
echo "1. Set the threshold to 1."
cast rpc anvil_setStorageAt ${ownerSafe} 0x0000000000000000000000000000000000000000000000000000000000000004 0x0000000000000000000000000000000000000000000000000000000000000001 --rpc-url ${localrpcUrl}
echo "2.set the owner count to 1."
## 2. Set the owner count to 1.
cast rpc anvil_setStorageAt ${ownerSafe} 0x0000000000000000000000000000000000000000000000000000000000000003 0x0000000000000000000000000000000000000000000000000000000000000001 --rpc-url ${localrpcUrl}
echo "3.Insert the address 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 as the sole owner of the safe."
## 3. Set the 0xf39 address to the sole signer of the safe.
# cast keccak 1 || 2 => 0xe90b7bceb6e7df5418fb78d8ee546e97c83a08bbccc01a0644d599ccd2a7c2e0 expected owner mapping: {0x1 -> 0xf39..., 0xf39 -> 0x1}
cast rpc anvil_setStorageAt ${ownerSafe} 0xe90b7bceb6e7df5418fb78d8ee546e97c83a08bbccc01a0644d599ccd2a7c2e0 0x000000000000000000000000f39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url ${localrpcUrl}
## 4. Set the owner (abi.encode(owner, uint256(2)))-> to sentinel_address (0x1).
echo "4.Close the mapping of the owners to the sentinel address."
cast rpc anvil_setStorageAt ${ownerSafe} 0xbc40fbf4394cd00f78fae9763b0c2c71b21ea442c42fdadc5b720537240ebac1 0x0000000000000000000000000000000000000000000000000000000000000001 --rpc-url ${localrpcUrl}
echo "the sole Owner of the ${ownerSafe} is: $(cast call ${ownerSafe} "getOwners()(address[])" --rpc-url http://localhost:8545)"
echo "================================================"
# sender=$(cast wallet address --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80)
forge build
signer_tenderly=$(cast call ${ownerSafe} "getOwners()(address[])" -r ${rpcUrl} | grep -oE '0x[a-fA-F0-9]{40}' | head -n1)
tenderly_link=$(forge script ${script} \
--rpc-url ${rpcUrl} \
--sender ${signer_tenderly} \
--sig "signJson(string)" \
${bundlePath})
echo "Tenderly link: $tenderly_link"
outputforge=$(forge script ${script} \
--rpc-url ${localrpcUrl} \
--sig "signJson(string)" ${bundlePath} \
--sender ${signer})
tempfile=$(mktemp)
echo "tmp file located to:" > $tempfile
echo "Outputforge: $outputforge" > $tempfile
hash=$(cat $tempfile | grep -A 1 "If submitting onchain, call Safe.approveHash on " | cut -d ':' -f 2 | tr -d '[:space:]')
# hash=$(echo $outputforge | grep -A 1 "If submitting onchain, call Safe.approveHash" "$file_path" | tail -n 1 | awk '{print $2}')
# Check if a hash was found
if [[ -z "$hash" ]]; then
echo "Hash not found in the file."
exit 1
else
echo "Extracted Hash: $hash"
fi
## 5. Approve the hash with the well-known private key that is the first owner of anvil selection.
cast send ${ownerSafe} "approveHash(bytes32)" ${hash} --rpc-url ${localrpcUrl} --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 # &> /dev/null
simulate hdPath='0':
#!/usr/bin/env bash
bundlePath=${taskPath}/${bundleName}.json
script=SignFromJson
if [ -f "${taskPath}/SignFromJson.s.sol" ]; then
script="${taskPath}/SignFromJson.s.sol"
fi
echo "Using script ${script}"
echo "Safe address: ${ownerSafe}"
echo "Getting signer address..."
if [ ! -z "$SIMULATE_WITHOUT_LEDGER" ]; then
signer=$(cast call ${ownerSafe} "getOwners()(address[])" -r ${rpcUrl} | grep -oE '0x[a-fA-F0-9]{40}' | head -n1)
else
signer=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")
fi
echo "Simulating with: ${signer}"
echo ""
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
forge build
forge script ${script} \
--rpc-url ${rpcUrl} \
--sig "signJson(string)" ${bundlePath} \
--sender ${signer}
sign hdPath='0':
#!/usr/bin/env bash
bundlePath=${taskPath}/${bundleName}.json
script=SignFromJson
if [ -f "${taskPath}/SignFromJson.s.sol" ]; then
script="${taskPath}/SignFromJson.s.sol"
fi
echo "Using script ${script}"
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)" \
${bundlePath}
execute_in_anvil hdPath='0':
#!/usr/bin/env bash
# set -x
localrpcUrl="http://localhost:8545" # Can be set as global in the future.
bundlePath=${taskPath}/${bundleName}.json
script=SignFromJson
if [ -f "${taskPath}/SignFromJson.s.sol" ]; then
script="${taskPath}/SignFromJson.s.sol"
fi
if [ ! -z "$SIMULATE_WITHOUT_LEDGER" ]; then
signer=$(cast wallet address --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80) # corresponding to 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 private-key.
else
signer=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")
fi
echo "Simulating with: ${signer}"
echo "Using script ${script}"
forge build
execution=$(forge script ${script} \
--rpc-url ${localrpcUrl} \
--sig "runJson(string,bytes)" ${bundlePath} ${FAKE_SIG} \
--broadcast --private-key {{PRIVATE_KEY_EXECUTOR}} 2>&1)
echo $execution
execute hdPath='0':
#!/usr/bin/env bash
bundlePath=${taskPath}/${bundleName}.json
script=SignFromJson
if [ -f "${taskPath}/SignFromJson.s.sol" ]; then
script="${taskPath}/SignFromJson.s.sol"
fi
echo "Using script ${script}"
sender=$(cast wallet address --ledger --mnemonic-derivation-path "m/44'/60'/{{hdPath}}'/0/0")
forge build
forge script --fork-url ${ETH_RPC_URL} ${script} \
--sig "runJson(string,bytes)" ${bundlePath} ${SIGNATURES} \
--ledger --hd-paths "m/44'/60'/{{hdPath}}'/0/0" --broadcast \
--sender ${sender}