diff --git a/report.js b/report.js index 96c3b85..2e5ffa8 100644 --- a/report.js +++ b/report.js @@ -104,8 +104,8 @@ function numbersIn(s) { } function allowedSet(src, keyNums) { const set = new Set(); - const add = v => { if (!isFinite(v)) return; for (const d of [0, 1, 2, 3, 4]) set.add(Number(v.toFixed(d))); }; - for (const n of numbersIn(src)) add(n.v); + const add = v => { if (!isFinite(v)) return; for (const d of [0, 1, 2, 3, 4, 5, 6]) set.add(Number(v.toFixed(d))); }; + for (const n of numbersIn(src)) { add(n.v); if (!n.raw.includes('.') && n.raw.replace(/,/g, '').length >= 7) { add(Number(n.raw.replace(/,/g, '')) / 1e18); add(Number(n.raw.replace(/,/g, '')) / 1e6); } } const k = [...new Set(keyNums.filter(x => isFinite(x) && x !== 0))].slice(0, 350); for (let i = 0; i < k.length; i++) for (let j = 0; j < k.length; j++) { const a = k[i], b = k[j]; @@ -130,12 +130,27 @@ function factcheck(report, evidenceText, keyNums) { const [a, b] = s.split(/\u2026|\.\.\.?/); if (!new RegExp(a + '[0-9a-f]*' + b + '(?![0-9a-f])').test(src)) bad.push({ kind: 'short address', item: s }); } - const stripped = all.replace(/0x[0-9a-fA-F]+/g, ' ').replace(/\b\d{4}-\d{2}-\d{2}\b/g, ' ').replace(/\b\d{1,2}:\d{2}\b/g, ' '); + const strip = t => t.replace(/0x[0-9a-fA-F]+/g, ' ').replace(/\b\d{4}-\d{2}-\d{2}\b/g, ' ').replace(/\b\d{1,2}:\d{2}\b/g, ' '); + const stripped = strip(all); + const okNum = v => allowed.has(v) || [2, 3, 4, 5, 6].some(d => allowed.has(Number(v.toFixed(d)))); + // shown arithmetic: a number that is the sum or difference of 2 to 4 other allowed numbers written in the same sentence + const shown = (v, sentence) => { + const xs = numbersIn(sentence).map(x => x.v).filter(x => x !== v && okNum(x)).slice(0, 12); + const near = t => Math.abs(t - v) <= Math.max(0.011, Math.abs(v) * 1e-9); + const n = xs.length; + for (let a = 0; a < n; a++) for (let b = a + 1; b < n; b++) { + if (near(xs[a] + xs[b]) || near(Math.abs(xs[a] - xs[b]))) return true; + for (let c = b + 1; c < n; c++) { if (near(xs[a] + xs[b] + xs[c])) return true; for (let d = c + 1; d < n; d++) if (near(xs[a] + xs[b] + xs[c] + xs[d])) return true; } + } + return false; + }; + const sentences = texts.flatMap(t => strip(t).split(/(?<=[.;!?])\s+/)); for (const n of numbersIn(stripped)) { const v = n.v; if (!n.raw.includes('.') && !n.raw.includes(',') && v < 10) continue; // small counts and scores if (!n.raw.includes('.') && !n.raw.includes(',') && v >= 1990 && v <= 2035) continue; // years - if (allowed.has(v) || allowed.has(Number(v.toFixed(2)))) continue; + if (okNum(v)) continue; + if (sentences.some(se => se.includes(n.raw) && shown(v, se))) continue; // a rounded form of an allowed value (3,632 for 3,632.30, 29.06k style excluded) let near = false; // integers: allowed already holds every allowed value rounded to 0 decimals (3,632 for 3,632.30) if (n.raw.includes('.')) { const d = n.raw.split('.')[1].length; for (const x of [v - Math.pow(10, -d), v + Math.pow(10, -d)]) if (allowed.has(Number(x.toFixed(d)))) near = true; } @@ -185,6 +200,7 @@ function normalize(report) { async function write({ kind, pack, siteText, facts, evidence, key }) { const keyNums = []; const walk = x => { if (typeof x === 'number') keyNums.push(x); else if (Array.isArray(x)) x.forEach(walk); else if (x && typeof x === 'object') Object.values(x).forEach(walk); }; + for (const d of Object.values(evidence.decoded_events || {})) for (const x of Object.values(d.uint_field_sums_raw || {})) { const nx = Number(x); if (isFinite(nx)) { keyNums.push(nx); if (nx >= 1e6) keyNums.push(nx / 1e18, nx / 1e6); } } walk({ money: evidence.money, approvals: evidence.approvals, positions: evidence.positions, counts: evidence.counts, txs: evidence.txs, values: evidence.values, age: evidence.age_days, wallets: evidence.wallets, native: evidence.native_balance }); const site = siteText ? siteText.slice(0, kind === 'deep' ? 12000 : 6000) : ''; const evidenceText = pack + '\n' + site + '\n' + JSON.stringify(facts);