-
Notifications
You must be signed in to change notification settings - Fork 7
206 lines (183 loc) · 7.86 KB
/
process-claim.yml
File metadata and controls
206 lines (183 loc) · 7.86 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
# Faucet Claim Relayer
#
# Triggered when someone opens an issue with [CLAIM] in the title.
# Parses proof data from issue body, submits tx, comments result.
#
# REQUIREMENTS:
# - RELAYER_PRIVATE_KEY secret: funded wallet for gas
# - Faucet contract must be deployed on Base Sepolia
name: Process Faucet Claim
on:
issues:
types: [opened]
permissions:
issues: write
jobs:
process-claim:
if: contains(github.event.issue.title, '[CLAIM]')
runs-on: ubuntu-latest
steps:
- name: Parse claim data
id: parse
uses: actions/github-script@v7
with:
script: |
const body = context.payload.issue.body || '';
// Extract JSON from code block
const jsonMatch = body.match(/```json\s*([\s\S]*?)\s*```/);
if (!jsonMatch) {
core.setFailed('No JSON code block found in issue body');
return;
}
let claim;
try {
claim = JSON.parse(jsonMatch[1]);
} catch (e) {
core.setFailed(`Invalid JSON: ${e.message}`);
return;
}
const required = ['proof', 'inputs', 'certificateHex', 'username', 'recipient'];
for (const field of required) {
if (!claim[field]) {
core.setFailed(`Missing required field: ${field}`);
return;
}
}
if (!/^0x[a-fA-F0-9]{40}$/.test(claim.recipient)) {
core.setFailed('Invalid recipient address format');
return;
}
if (!/^0x[a-fA-F0-9]+$/.test(claim.proof)) {
core.setFailed('Invalid proof format (must be hex)');
return;
}
if (!Array.isArray(claim.inputs)) {
core.setFailed('inputs must be an array');
return;
}
core.setOutput('proof', claim.proof);
core.setOutput('inputs', JSON.stringify(claim.inputs));
core.setOutput('certificate', claim.certificateHex);
core.setOutput('username', claim.username);
core.setOutput('recipient', claim.recipient);
core.setOutput('faucet', claim.faucet || '0x72cd70d28284dD215257f73e1C5aD8e28847215B');
console.log(`Claim: ${claim.username} -> ${claim.recipient} (${claim.inputs.length} inputs, ${claim.certificateHex.length} cert hex chars)`);
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Submit claim transaction
id: submit
env:
RELAYER_KEY: ${{ secrets.RELAYER_PRIVATE_KEY }}
run: |
# Format inputs as Solidity array
INPUTS='${{ steps.parse.outputs.inputs }}'
INPUTS_FORMATTED=$(echo "$INPUTS" | jq -r 'join(",")')
echo "Submitting claim to faucet..."
echo "Username: ${{ steps.parse.outputs.username }}"
# Decode a 4-byte error selector into a human-readable message
decode_error() {
local selector="$1"
case "$selector" in
832f97cb) echo "WrongCommit: proof was generated from the wrong git ref. Run the workflow from the required tag (see VERSIONS.json)." ;;
09bde339) echo "InvalidProof: ZK proof failed on-chain verification." ;;
ddf32b51) echo "CertificateMismatch: sha256(certificate) doesn't match the attested artifact hash." ;;
4dca8d92) echo "UsernameMismatch: username arg doesn't match what's in the certificate." ;;
c0ee95bb) echo "RecipientMismatch: recipient address doesn't match what's in the certificate." ;;
39b1a59e) echo "AlreadyClaimedToday: 24h cooldown not met. Try again tomorrow." ;;
c1336f85) echo "FaucetEmpty: no ETH left in faucet." ;;
*) echo "" ;;
esac
}
set +e
OUTPUT=$(cast send \
${{ steps.parse.outputs.faucet }} \
"claim(bytes,bytes32[],bytes,string,address)" \
"${{ steps.parse.outputs.proof }}" \
"[$INPUTS_FORMATTED]" \
"${{ steps.parse.outputs.certificate }}" \
"${{ steps.parse.outputs.username }}" \
"${{ steps.parse.outputs.recipient }}" \
--private-key "$RELAYER_KEY" \
--rpc-url https://sepolia.base.org \
--gas-limit 3500000 \
--json 2>&1)
EXIT_CODE=$?
set -e
if [ $EXIT_CODE -ne 0 ]; then
echo "Cast output:"
echo "$OUTPUT"
# Try custom error selector first, then string error, then raw output
SELECTOR=$(echo "$OUTPUT" | grep -oP 'custom error 0x\K[a-f0-9]{8}' | head -1)
REASON=$(decode_error "$SELECTOR")
if [ -z "$REASON" ]; then
SELECTOR=$(echo "$OUTPUT" | grep -oP '0x\K[a-f0-9]{8}' | head -1)
REASON=$(decode_error "$SELECTOR")
fi
if [ -z "$REASON" ]; then
REASON=$(echo "$OUTPUT" | grep -oP 'Error\("\K[^"]+' || echo "$OUTPUT" | head -1)
fi
echo "error_reason=$REASON" >> $GITHUB_OUTPUT
echo "Transaction failed: $REASON"
exit 1
fi
TX_HASH=$(echo "$OUTPUT" | jq -r '.transactionHash')
STATUS=$(echo "$OUTPUT" | jq -r '.status')
echo "tx_hash=$TX_HASH" >> $GITHUB_OUTPUT
if [ "$STATUS" = "0x0" ]; then
# Transaction reverted on-chain — trace to get error selector
REVERT_OUTPUT=$(cast run "$TX_HASH" --rpc-url https://sepolia.base.org 2>&1 || true)
SELECTOR=$(echo "$REVERT_OUTPUT" | grep -oP 'custom error 0x\K[a-f0-9]{8}' | head -1)
REASON=$(decode_error "$SELECTOR")
if [ -z "$REASON" ]; then
REASON="Transaction reverted on-chain (tx: $TX_HASH)"
else
REASON="$REASON (tx: $TX_HASH)"
fi
echo "error_reason=$REASON" >> $GITHUB_OUTPUT
echo "Transaction reverted: $REASON"
exit 1
fi
echo "Transaction succeeded: $TX_HASH"
- name: Comment success
if: success()
uses: actions/github-script@v7
with:
script: |
const txHash = '${{ steps.submit.outputs.tx_hash }}';
const recipient = '${{ steps.parse.outputs.recipient }}';
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## ✅ Claim Successful!\n\n` +
`**Recipient:** \`${recipient}\`\n` +
`**Transaction:** [${txHash}](https://sepolia.basescan.org/tx/${txHash})\n\n` +
`Funds should arrive shortly.`
});
await github.rest.issues.update({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
labels: ['claimed']
});
- name: Comment failure
if: failure()
uses: actions/github-script@v7
with:
script: |
const errorReason = '${{ steps.submit.outputs.error_reason }}' || 'Unknown';
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## ❌ Claim Failed\n\n` +
`**Reason:** ${errorReason}\n\n` +
`[View logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})`
});
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['failed']
});