diff --git a/chain/chainrpc.py b/chain/chainrpc.py index 4509716..c65608a 100644 --- a/chain/chainrpc.py +++ b/chain/chainrpc.py @@ -15,7 +15,7 @@ from concurrent.futures import ThreadPoolExecutor NODEREAL = 'https://bsc-mainnet.nodereal.io/v1/64a9df0874fb4a93b9d0a3849de012d3' CHAINS = { 'bsc': {'id': 56, 'name': 'BNB Chain', 'native': 'BNB', 'explorer': 'https://bscscan.com', - 'rpcs': ['https://bsc-dataseed.bnbchain.org', 'https://bsc-rpc.publicnode.com', NODEREAL, 'https://bsc-dataseed1.defibit.io', 'https://bsc-dataseed2.ninicoin.io'], + 'rpcs': ['https://bsc-dataseed.bnbchain.org', 'https://bsc-rpc.publicnode.com', 'https://bsc-dataseed1.defibit.io', 'https://bsc-dataseed2.ninicoin.io'], 'log_providers': [(NODEREAL, 49000), ('https://bsc.rpc.blxrbdn.com', 5000)], 'archive_rpcs': [NODEREAL], 'block_secs': 0.45, 'tokens': {'USDT': '0x55d398326f99059ff775485246999027b3197955', 'USDC': '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d', 'BUSD': '0xe9e7cea3dcd96aee6a24b63ae6d6e53fba8a9b56'}}, @@ -37,6 +37,20 @@ CHAINS = { } TRANSFER = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' APPROVAL = '0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925' +# nodereal's public key allows a burst of about 20 calls, then about 1 call a second (measured 2026-11-16): pace it, never hammer it +LIMITS = {NODEREAL: (1.1, 12)} + + +class Bucket: + def __init__(self, rate, burst): self.rate, self.cap, self.tokens, self.t, self.lock = rate, burst, burst, time.time(), threading.Lock() + def take(self): + while True: + with self.lock: + now = time.time(); self.tokens = min(self.cap, self.tokens + (now - self.t) * self.rate); self.t = now + if self.tokens >= 1: self.tokens -= 1; return + wait = (1 - self.tokens) / self.rate + time.sleep(wait) +BUCKETS = {u: Bucket(*v) for u, v in LIMITS.items()} S = requests.Session() S.headers.update({'user-agent': 'webworthit-readonly-scan/1'}) @@ -47,6 +61,7 @@ class RPC: def _post(self, u, method, params, timeout=60): with self.lock: self.calls += 1 + if u in BUCKETS: BUCKETS[u].take() return S.post(u, json={'jsonrpc': '2.0', 'id': 1, 'method': method, 'params': params}, timeout=timeout).json() def call(self, method, params, tries=6, urls=None): @@ -93,7 +108,11 @@ class RPC: if time.time() > deadline: raise TimeoutError() y = min(x + span - 1, b) qq = dict(q); qq['fromBlock'] = hex(x); qq['toBlock'] = hex(y) - j = self._post(u, 'eth_getLogs', [qq], timeout=45 if pi == 0 else 20) + for _ in range(6): + j = self._post(u, 'eth_getLogs', [qq], timeout=45 if pi == 0 else 20) + if 'error' in j and isinstance(j['error'], dict) and j['error'].get('code') in (-32005, 429) and time.time() < deadline: + time.sleep(3); continue + break if 'error' in j: raise Exception(j['error']) out += j['result'] return out, True diff --git a/chain/scan.py b/chain/scan.py index d4a60cd..f8393ec 100644 --- a/chain/scan.py +++ b/chain/scan.py @@ -308,16 +308,20 @@ def main(): # ---- contract logs step('logs', blocks=latest - frm + 1) - L, gaps = r.logs(A, frm, latest, threads=2, deadline=T0 + budget * 0.32) toks = C['tokens']; tlist = list(toks.values()); E['tokens_checked'] = list(toks.keys()) qin = [[TRANSFER, APPROVAL], None, addr_topic(A)]; qout = [TRANSFER, addr_topic(A)] - inn, g1 = r.logs(tlist, frm, latest, qin, threads=2, deadline=max(time.time() + 30, T0 + budget * 0.52)) - out, g2 = r.logs(tlist, frm, latest, qout, threads=2, deadline=max(time.time() + 30, T0 + budget * 0.72)) + # the three filters run side by side and share the provider's pace, so a time cut leaves small gaps in each, not one lost filter + dl = T0 + budget * 0.8 + with ThreadPoolExecutor(3) as ex3: + fL = ex3.submit(r.logs, A, frm, latest, None, 2, dl) + fI = ex3.submit(r.logs, tlist, frm, latest, qin, 2, dl) + fO = ex3.submit(r.logs, tlist, frm, latest, qout, 2, dl) + L, gaps = fL.result(); inn, g1 = fI.result(); out, g2 = fO.result() # second pass over every range that failed (rate limits clear in seconds), with what is left of the budget passes = 0 - while (gaps or g1 or g2) and time.time() < T0 + budget * 0.88 and passes < 4: + while (gaps or g1 or g2) and time.time() < T0 + budget * 0.9 and passes < 4: passes += 1; step('retry_gaps', ranges=len(gaps) + len(g1) + len(g2)) - dl = T0 + budget * 0.88 + dl = T0 + budget * 0.9 def refill(addr, topics, gs, have): left = [] for a, b in gs: diff --git a/tools/golive/polhunter-missions.json b/tools/golive/polhunter-missions.json new file mode 100644 index 0000000..40dd689 --- /dev/null +++ b/tools/golive/polhunter-missions.json @@ -0,0 +1,12 @@ +{ + "_note": "PREPARED, NOT LIVE (2026-11-16). WebWorthIt missions in PolHunter's own shapes (lib/missions.js mission object, lib/detective-bank.json question). Go-live: POST them in polhunter.com/admin (missions) and POST /api/admin/detective/question (questions), and add the PolHunter embed to webworthit.com (assets/index.js: script https://polhunter.com/embed.js, data-slots 3, data-selector '#scoring div[style*=\"grid\"] > div'); CSP script-src + connect-src must then allow https://polhunter.com. Rewards come from PolHunter's normal draw (free tier 0.02 to 0.1 POL, Game Pass 0.05 to 1 POL, inside the 20 POL house daily cap): no new budget line. Referral bounties stay brand-new members only (fail closed).", + "missions": [ + { "id": "wwi-how", "site": "WebWorthIt", "host": "webworthit.com", "name": "How a check works", "brief": "Open WebWorthIt and read How a check works. Your find code hides in one of the three steps.", "url": "https://webworthit.com/#scoring", "dwell": 45, "reward": { "min": 0.02, "max": 0.1 }, "budget": 0, "active": false } + ], + "detective_questions": [ + { "id": "wwi-how-1", "missionId": "wwi-how", "q": "What does a WebWorthIt check never ask you to do?", "options": ["Connect a wallet", "Read the scorecard", "Paste an address", "Pick a chain"], "fact": "Read-only: a check never asks you to connect a wallet.", "active": false, "added": "2026-11-16" }, + { "id": "wwi-how-2", "missionId": "wwi-how", "q": "What does the tag VERIFIED mean on a finding?", "options": ["Seen on chain with a transaction link", "The project paid for it", "A member voted for it", "It came from the project's own website"], "fact": "VERIFIED means seen on chain with a transaction link.", "active": false, "added": "2026-11-16" }, + { "id": "wwi-how-3", "missionId": "wwi-how", "q": "How many free checks does each visitor get a day?", "options": ["3", "1", "10", "Unlimited"], "fact": "3 free checks a day.", "active": false, "added": "2026-11-16" }, + { "id": "wwi-how-4", "missionId": "wwi-how", "q": "What are the scores and the grade on a WebWorthIt check?", "options": ["Our opinion from the published rubric", "A legal finding", "A paid badge", "The project's own rating"], "fact": "Scores and grade are our opinion, based on our published rubric applied to the public facts.", "active": false, "added": "2026-11-16" } + ] +} diff --git a/website.js b/website.js index abe4ff9..809f7cd 100644 --- a/website.js +++ b/website.js @@ -15,7 +15,7 @@ const COMMON = new Set(['0x0000000000000000000000000000000000000000', '0x0000000 '0xc2132d05d31c914a87c6611c10748aeb04b58e8f', '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359', '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', '0xdac17f958d2ee523a2206206994597c13d831ec7', '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270', '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', - '0x4200000000000000000000000000000000000006', '0x10ed43c718714eb63d5aa57b78b54704e256024e', '0xca11bde05977b3631167028862be2a173976ca11']); + '0x4200000000000000000000000000000000000006', '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', '0x10ed43c718714eb63d5aa57b78b54704e256024e', '0xca11bde05977b3631167028862be2a173976ca11']); function privateIp(ip) { if (net.isIPv4(ip)) { @@ -107,7 +107,33 @@ async function scan(url, opts) { } for (const a of res.text.match(ADDR_RE) || []) bump(a, 3, 'visible text'); for (const a of html.match(ADDR_RE) || []) bump(a, 1, 'page HTML'); - for (const a of (scripts.match(ADDR_RE) || []).slice(0, 3000)) bump(a, 0.5, 'site scripts'); + // in the site's own code, the words just before an address say what it is (NEXT_PUBLIC_..._ADDRESS, contract: 0x..) or that + // it is wallet-library plumbing (paymaster, multicall, permit2, router) that is never the project contract + { const re = new RegExp(ADDR_RE.source, 'g'); let m, n = 0; + while ((m = re.exec(scripts)) && n++ < 4000) { + const ctx = scripts.slice(Math.max(0, m.index - 90), m.index); + let s = 0.5; + if (/(_ADDRESS|_ADDR|CONTRACT|contract|[Vv]ault|[Pp]roxy|[Pp]ool)[^,;]{0,40}$/.test(ctx)) s += 3; + if (/(paymaster|wallet_|multicall|[Pp]ermit2?|[Rr]outer|WETH|[Ff]actory|[Ee]ntry[Pp]oint|[Ee]ns|safe[A-Z_]|chainlink|[Oo]racle)[^,;]{0,40}$/.test(ctx)) s -= 2; + bump(m[0], s, s > 2 ? 'site code, named as the contract' : 'site scripts'); + } } + // nothing on the front page: open up to 2 of the site's own pages named like a contract / ledger / proof page (public pages only) + if (!res.explorerLinks.length && ![...score.values()].some(s => s.score >= 3)) { + const base = new URL(page.url()); const seenP = new Set([base.pathname]); + const subs = links.filter(l => { try { const x = new URL(l); return x.hostname === base.hostname && /contract|ledger|proof|verify|audit|transparen|smart/i.test(x.pathname) && !seenP.has(x.pathname) && seenP.add(x.pathname); } catch (e) { return false; } }).slice(0, 2); + for (const sl of subs) { + try { + await page.goto(sl, { waitUntil: 'domcontentloaded', timeout: 20000 }); await page.waitForLoadState('networkidle', { timeout: 6000 }).catch(() => {}); + const t2 = String(await page.evaluate(() => document.body ? document.body.innerText : '').catch(() => '')).slice(0, 8000); + const l2 = await page.evaluate(() => Array.from(document.querySelectorAll('a[href]')).map(a => a.href).slice(0, 1000)).catch(() => []); + const pth = new URL(sl).pathname; + for (const l of l2) { let lu; try { lu = new URL(l); } catch (e) { continue; } const host = lu.hostname.replace(/^www\./, ''); const ch = EXPLORERS[host]; const m = lu.pathname.match(/\/(address|token)\/(0x[a-fA-F0-9]{40})/); + if (ch && m) { res.explorerLinks.push({ chain: ch, address: m[2].toLowerCase(), url: l.slice(0, 300), page: pth }); bump(m[2], 6, 'explorer link on ' + pth); res.chainHints[ch] = (res.chainHints[ch] || 0) + 3; } } + for (const a of t2.match(ADDR_RE) || []) bump(a, 3, 'visible text on ' + pth); + res.text += '\n\n[Page ' + pth + ']\n' + t2.slice(0, 5000); res.pagesRead = (res.pagesRead || []).concat([pth]); + } catch (e) {} + } + } for (const [ch, re] of Object.entries(CHAIN_WORDS)) { const n = (res.text.match(re) || []).length; if (n) res.chainHints[ch] = (res.chainHints[ch] || 0) + n; } res.addresses = [...score.values()].sort((a, b) => b.score - a.score).slice(0, 25).map(s => ({ address: s.address, score: Math.round(s.score * 10) / 10, seen: [...s.seen] })); res.abi = parseHumanAbi(scripts + html);