Commit 5e7fe63
feat(prover-api): production-ready claim migration prover with security hardening (#68)
* refactor(prover-api): modularize codebase with job queue and worker pool
Split monolithic main.rs into separate modules for better maintainability:
- config.rs: Configuration loading and validation
- types.rs: Shared types (AppState, JobEntry, CachedProof, etc.)
- handlers.rs: HTTP request handlers (submit_job, job_status, health)
- prover.rs: ZK proof generation logic
- queue.rs: JobQueue and WorkerPool for concurrent proof generation
- cache.rs: Proof caching with TTL cleanup
- rate_limit.rs: Per-pubkey rate limiting
- jobs.rs: Job entry cleanup
- validation.rs: Request validation utilities
Added production features:
- Configurable worker pool size and queue capacity
- Background cleanup tasks for cache, rate limits, and stale jobs
- Max body size limiting
- Proof timeout configuration
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* feat(prover-api): add eligibility verification, signature validation, and IP rate limiting
Adds production hardening features:
- Load eligibility data from merkle-tree.json at startup with pubkey-based O(1) lookup
- Verify sr25519 signatures before proof generation using schnorrkel
- IP-based rate limiting (separate from pubkey rate limiting) to catch bots/scanners
- Add proof metrics tracking (completions, timeouts, background tasks)
- Update Dockerfile to bundle eligibility data with configurable path
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* chore(prover-api): tune default config values for production use
- Increase cache TTL from 10 minutes to 1 hour since proofs are
deterministic and expensive to compute
- Reduce queue capacity from 100 to 50 for better wait time estimation
(~1 hour max with 4 workers)
- Increase jobs TTL from 10 minutes to 1 hour to let users return
for their proof
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix(prover-api): use explicit Mainnet mode for SP1 network prover
ProverClient::from_env() defaults to Reserved mode which has an invalid
domain for the mainnet network. Explicitly use NetworkMode::Mainnet via
ProverClient::builder().network_for(NetworkMode::Mainnet) to ensure
correct mainnet RPC URL is used.
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* feat(prover-api): improve security and fix concurrency control
- Add trust_proxy_headers config for secure IP extraction behind reverse proxies
- When false (default), only socket address is used for rate limiting
- When true, respects X-Forwarded-For and X-Real-IP headers
- Strip port from socket addresses for consistent rate limiting
- Add configurable RPC timeout for on-chain verification
- timeout_seconds field in VerifyOnchainConfig
- Uses RPC_TIMEOUT_SECONDS env var (default: 10s)
- Fix unbounded concurrency when proof generation times out
- Acquire semaphore permit before spawning task, not inside
- Hold permit until blocking task actually completes (not just timeout)
- Use tokio::select! instead of tokio::time::timeout to keep handle valid
- Add decrement_timed_out_still_running metric tracking
- Fix JobQueue::from_sender to use shared queue_size counter
- Prevents queue size tracking inconsistencies
- Add error handling for misconfigured state
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* test(prover-api): add httpmock tests for on-chain verification
- Add httpmock dev dependency for mocking RPC responses
- Add tests for verify_onchain_proof success and revert cases
- Add test for check_already_claimed with claimed/unclaimed scenarios
- Minor code cleanup and formatting fixes
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix(prover-api): use consistent timestamp in rate limiter
Capture timestamp once at the start of check_and_update() to avoid
potential race condition where multiple calls to now_ts() could return
different values.
Co-Authored-By: Claude Opus 4.5 <[email protected]>
---------
Co-authored-by: Claude Opus 4.5 <[email protected]>1 parent ea1a7b4 commit 5e7fe63
File tree
18 files changed
+4483
-461
lines changed- packages/migration-claim/sp1
- prover-api
- scripts
- src
18 files changed
+4483
-461
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
19 | 26 | | |
20 | 27 | | |
| 28 | + | |
| 29 | + | |
21 | 30 | | |
22 | 31 | | |
23 | 32 | | |
| |||
Lines changed: 223 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments