-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathhandler.verify-governance-action.yml
More file actions
307 lines (263 loc) · 12.1 KB
/
handler.verify-governance-action.yml
File metadata and controls
307 lines (263 loc) · 12.1 KB
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
304
305
306
307
name: Verify Governance Action
on:
workflow_dispatch:
inputs:
release_version:
description: 'Protocol release version (v1.x.x format)'
required: true
default: 'v1'
addresses_url:
description: 'URL to addresses file or directory (expects <network> files in directory)'
required: false
default: ''
verify_safe_pending:
description: 'Fetch and verify pending Safe governance transaction'
required: false
type: boolean
default: false
verify_etherscan:
description: 'Run Etherscan verification after bytecode verification'
required: false
type: boolean
default: false
only_network:
description: 'Only verify a specific network (leave empty for all)'
required: false
default: ''
jobs:
verify-governance-action:
name: Verify ${{ matrix.network }}
runs-on: ubuntu-22.04
env:
RELEASE_VERSION: ${{ github.event.inputs.release_version }}
ADDRESSES_URL: ${{ github.event.inputs.addresses_url }}
strategy:
fail-fast: false
matrix:
network: [eth-mainnet, polygon-mainnet, xdai-mainnet, optimism-mainnet, arbitrum-one, avalanche-c, bsc-mainnet, celo-mainnet, base-mainnet, scroll-mainnet]
defaults:
run:
shell: nix develop .#ci-default -c bash -xe {0}
steps:
- name: Check only_network filter
if: ${{ github.event.inputs.only_network != '' && github.event.inputs.only_network != matrix.network }}
run: echo "DO_SKIP=1" >> "$GITHUB_ENV"
shell: bash
- uses: actions/checkout@v4
if: env.DO_SKIP != 1
with:
ref: ${{ github.event.inputs.release_version }}
- uses: cachix/install-nix-action@v27
if: env.DO_SKIP != 1
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Build contracts
if: env.DO_SKIP != 1
run: |
yarn install --frozen-lockfile
yarn build-for-contracts-dev
- name: Fetch addresses from URL
if: env.DO_SKIP != 1 && github.event.inputs.addresses_url != ''
run: |
cd packages/ethereum-contracts
ADDRESSES_URL="${{ github.event.inputs.addresses_url }}"
NETWORK="${{ matrix.network }}"
# Check if URL is a directory (ends with /) or a file
if [[ "$ADDRESSES_URL" == */ ]]; then
# Directory URL - append network name
FETCH_URL="${ADDRESSES_URL}${NETWORK}"
else
# File URL - use as-is
FETCH_URL="$ADDRESSES_URL"
fi
echo "Fetching addresses from: $FETCH_URL"
curl -fsSL "$FETCH_URL" -o addresses-from-url.vars || {
echo "::warning::Failed to fetch addresses from URL, will fetch from chain"
touch addresses-from-url.vars
}
if [ -s addresses-from-url.vars ]; then
echo "ADDRESSES_FILE=$(pwd)/addresses-from-url.vars" >> "$GITHUB_ENV"
echo "Addresses file contents:"
cat addresses-from-url.vars
fi
- name: Fetch addresses from chain
if: env.DO_SKIP != 1 && env.ADDRESSES_FILE == ''
run: |
cd packages/ethereum-contracts
npx truffle exec --network ${{ matrix.network }} ops-scripts/info-print-contract-addresses.js : addresses.vars
echo "ADDRESSES_FILE=$(pwd)/addresses.vars" >> "$GITHUB_ENV"
env:
PROVIDER_URL: ${{ secrets.PROVIDER_URL_TEMPLATE }}
- name: Fetch pending Safe transaction
if: env.DO_SKIP != 1 && github.event.inputs.verify_safe_pending == 'true'
id: safe_tx
run: |
cd packages/ethereum-contracts
echo "Fetching pending Safe governance transaction..."
# Run the Hardhat script with PROVIDER_URL
OUTPUT_FILE=safe-pending-tx.json \
npx hardhat run scripts/fetch-safe-pending-tx.ts > safe-output.log 2>&1 || {
echo "::warning::Failed to fetch Safe pending transaction"
cat safe-output.log || true
echo "SAFE_TX_FOUND=false" >> "$GITHUB_ENV"
exit 0
}
if [ -f safe-pending-tx.json ] && [ -s safe-pending-tx.json ]; then
echo "SAFE_TX_FOUND=true" >> "$GITHUB_ENV"
echo "Safe pending transaction:"
cat safe-pending-tx.json
# Extract addresses from Safe tx and append to addresses file
EXTRACTED=$(jq -r '.extractedAddresses | to_entries | .[] | "\(.key)=\(.value)"' safe-pending-tx.json 2>/dev/null || true)
if [ -n "$EXTRACTED" ]; then
echo "" >> "${{ env.ADDRESSES_FILE }}"
echo "# Addresses from pending Safe transaction" >> "${{ env.ADDRESSES_FILE }}"
echo "$EXTRACTED" >> "${{ env.ADDRESSES_FILE }}"
echo "Appended extracted addresses to ${{ env.ADDRESSES_FILE }}"
fi
else
echo "SAFE_TX_FOUND=false" >> "$GITHUB_ENV"
fi
env:
PROVIDER_URL: ${{ secrets.PROVIDER_URL_TEMPLATE }}
- name: Verify bytecode
if: env.DO_SKIP != 1
id: bytecode_verify
run: |
cd packages/ethereum-contracts
echo "=== Bytecode Verification ==="
echo "Addresses file: ${{ env.ADDRESSES_FILE }}"
# Run the Hardhat verification script with PROVIDER_URL
ADDRESSES_FILE="${{ env.ADDRESSES_FILE }}" JSON_OUTPUT=true \
npx hardhat run scripts/verify-bytecode.ts > bytecode-report.json 2>&1 || true
# Parse and display results
if [ -f bytecode-report.json ] && [ -s bytecode-report.json ]; then
echo "Bytecode verification results:"
cat bytecode-report.json | jq '.'
# Extract summary
VERIFIED=$(jq -r '.summary.verified // 0' bytecode-report.json)
MISMATCH=$(jq -r '.summary.mismatch // 0' bytecode-report.json)
ERRORS=$(jq -r '.summary.errors // 0' bytecode-report.json)
echo "BYTECODE_VERIFIED=$VERIFIED" >> "$GITHUB_ENV"
echo "BYTECODE_MISMATCH=$MISMATCH" >> "$GITHUB_ENV"
echo "BYTECODE_ERRORS=$ERRORS" >> "$GITHUB_ENV"
if [ "$MISMATCH" -gt 0 ] || [ "$ERRORS" -gt 0 ]; then
echo "::error::Bytecode verification failed: $MISMATCH mismatches, $ERRORS errors"
else
echo "::notice::Bytecode verification passed: $VERIFIED contracts verified"
fi
else
echo "::error::Failed to generate bytecode report"
cat bytecode-report.json || true
echo "BYTECODE_VERIFIED=0" >> "$GITHUB_ENV"
echo "BYTECODE_MISMATCH=0" >> "$GITHUB_ENV"
echo "BYTECODE_ERRORS=1" >> "$GITHUB_ENV"
fi
env:
PROVIDER_URL: ${{ secrets.PROVIDER_URL_TEMPLATE }}
- name: Verify on Etherscan
if: env.DO_SKIP != 1 && github.event.inputs.verify_etherscan == 'true'
run: |
cd packages/ethereum-contracts
tasks/etherscan-verify-framework.sh ${{ matrix.network }} "${{ env.ADDRESSES_FILE }}"
env:
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
POLYGONSCAN_API_KEY: ${{ secrets.POLYGONSCAN_API_KEY }}
SNOWTRACE_API_KEY: ${{ secrets.SNOWTRACE_API_KEY }}
OPTIMISTIC_API_KEY: ${{ secrets.OPTIMISTIC_API_KEY }}
ARBISCAN_API_KEY: ${{ secrets.ARBISCAN_API_KEY }}
BSCSCAN_API_KEY: ${{ secrets.BSCSCAN_API_KEY }}
CELOSCAN_API_KEY: ${{ secrets.CELOSCAN_API_KEY }}
- name: Upload verification artifacts
if: env.DO_SKIP != 1 && always()
uses: actions/upload-artifact@v4
with:
name: verification-${{ matrix.network }}
path: |
packages/ethereum-contracts/bytecode-report.json
packages/ethereum-contracts/safe-pending-tx.json
packages/ethereum-contracts/${{ env.ADDRESSES_FILE }}
retention-days: 30
if-no-files-found: ignore
- name: Generate summary
if: env.DO_SKIP != 1 && always()
run: |
echo "## Verification Results for ${{ matrix.network }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Bytecode Verification" >> $GITHUB_STEP_SUMMARY
echo "- Verified: ${{ env.BYTECODE_VERIFIED || 'N/A' }}" >> $GITHUB_STEP_SUMMARY
echo "- Mismatch: ${{ env.BYTECODE_MISMATCH || 'N/A' }}" >> $GITHUB_STEP_SUMMARY
echo "- Errors: ${{ env.BYTECODE_ERRORS || 'N/A' }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ github.event.inputs.verify_safe_pending }}" == "true" ]; then
echo "### Safe Pending Transaction" >> $GITHUB_STEP_SUMMARY
if [ "${{ env.SAFE_TX_FOUND }}" == "true" ]; then
echo "Pending governance transaction found and analyzed." >> $GITHUB_STEP_SUMMARY
else
echo "No pending governance transaction found." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ github.event.inputs.verify_etherscan }}" == "true" ]; then
echo "### Etherscan Verification" >> $GITHUB_STEP_SUMMARY
echo "Etherscan verification was executed. Check logs for details." >> $GITHUB_STEP_SUMMARY
fi
generate-report:
name: Generate Final Report
needs: verify-governance-action
runs-on: ubuntu-22.04
if: always()
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
continue-on-error: true
- name: Generate consolidated report
run: |
echo "# Governance Action Verification Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Release Version:** ${{ github.event.inputs.release_version }}" >> $GITHUB_STEP_SUMMARY
echo "**Addresses URL:** ${{ github.event.inputs.addresses_url || 'N/A (fetched from chain)' }}" >> $GITHUB_STEP_SUMMARY
echo "**Safe Verification:** ${{ github.event.inputs.verify_safe_pending }}" >> $GITHUB_STEP_SUMMARY
echo "**Etherscan Verification:** ${{ github.event.inputs.verify_etherscan }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Network Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Network | Verified | Mismatch | Errors | Status |" >> $GITHUB_STEP_SUMMARY
echo "|---------|----------|----------|--------|--------|" >> $GITHUB_STEP_SUMMARY
if [ -d "artifacts" ]; then
for dir in artifacts/verification-*/; do
if [ -d "$dir" ]; then
NETWORK=$(basename "$dir" | sed 's/verification-//')
if [ -f "$dir/bytecode-report.json" ]; then
VERIFIED=$(jq -r '.summary.verified // 0' "$dir/bytecode-report.json" 2>/dev/null || echo "0")
MISMATCH=$(jq -r '.summary.mismatch // 0' "$dir/bytecode-report.json" 2>/dev/null || echo "0")
ERRORS=$(jq -r '.summary.errors // 0' "$dir/bytecode-report.json" 2>/dev/null || echo "0")
if [ "$MISMATCH" -gt 0 ] || [ "$ERRORS" -gt 0 ]; then
STATUS="Failed"
else
STATUS="Passed"
fi
else
VERIFIED="N/A"
MISMATCH="N/A"
ERRORS="N/A"
STATUS="No report"
fi
echo "| $NETWORK | $VERIFIED | $MISMATCH | $ERRORS | $STATUS |" >> $GITHUB_STEP_SUMMARY
fi
done
else
echo "| (no artifacts found) | - | - | - | - |" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "*Generated at $(date -u)*" >> $GITHUB_STEP_SUMMARY
- name: Upload consolidated report
if: always()
uses: actions/upload-artifact@v4
with:
name: verification-report
path: artifacts/
retention-days: 90
if-no-files-found: ignore