liqproof 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +536 -2
  3. package/bugs/README.md +144 -0
  4. package/bugs/coin-gecko-liquidity-report.md +283 -0
  5. package/bugs/collect-ds-aggregate.mjs +213 -0
  6. package/bugs/collect-evidence.mjs +458 -0
  7. package/bugs/collect-gt-aggregate.mjs +215 -0
  8. package/bugs/collect-raw-rpc.mjs +165 -0
  9. package/bugs/collect-sweep-context.mjs +162 -0
  10. package/bugs/dexscreener-fake-liquidity-report.md +310 -0
  11. package/bugs/evidence/aggregator-liquidity-claims.json +648 -0
  12. package/bugs/evidence/aggregator-liquidity-claims.md +103 -0
  13. package/bugs/evidence/bat-native-pool-drained.json +136 -0
  14. package/bugs/evidence/bat-native-pool-drained.md +51 -0
  15. package/bugs/evidence/chz-impersonator-pool-drained.json +136 -0
  16. package/bugs/evidence/chz-impersonator-pool-drained.md +51 -0
  17. package/bugs/evidence/gt-stale-reserve-after-drain.json +141 -0
  18. package/bugs/evidence/gt-stale-reserve-after-drain.md +31 -0
  19. package/bugs/evidence/raw-rpc-transcript.json +683 -0
  20. package/bugs/evidence/raw-rpc-transcript.md +308 -0
  21. package/bugs/evidence/sweep-context.json +325 -0
  22. package/bugs/evidence/sweep-context.md +55 -0
  23. package/bugs/evidence/verified-aggregate.json +526 -0
  24. package/bugs/evidence/verified-aggregate.md +24 -0
  25. package/bugs/evidence/verified-ds-liquidity-usd.json +1197 -0
  26. package/bugs/evidence/verified-ds-liquidity-usd.md +250 -0
  27. package/bugs/evidence/verified-gt-reserve-in-usd.json +1002 -0
  28. package/bugs/evidence/verified-gt-reserve-in-usd.md +218 -0
  29. package/bugs/fix-bundle-titles.mjs +72 -0
  30. package/bugs/geckoterminal-stale-reserve-after-drain.md +137 -0
  31. package/data/dataset-summary.md +103 -0
  32. package/data/impersonators.json +12888 -0
  33. package/data/verified-impersonators.json +725 -0
  34. package/data/wallets.json +23 -0
  35. package/dist/base58.js +70 -0
  36. package/dist/base58.js.map +1 -0
  37. package/dist/canonical.js +372 -0
  38. package/dist/canonical.js.map +1 -0
  39. package/dist/cli.js +830 -0
  40. package/dist/cli.js.map +1 -0
  41. package/dist/curve.js +255 -0
  42. package/dist/curve.js.map +1 -0
  43. package/dist/dashboard.js +485 -0
  44. package/dist/dashboard.js.map +1 -0
  45. package/dist/keccak.js +197 -0
  46. package/dist/keccak.js.map +1 -0
  47. package/dist/mcp.js +604 -0
  48. package/dist/mcp.js.map +1 -0
  49. package/dist/operator.js +180 -0
  50. package/dist/operator.js.map +1 -0
  51. package/dist/pda.js +86 -0
  52. package/dist/pda.js.map +1 -0
  53. package/dist/receipt.js +897 -0
  54. package/dist/receipt.js.map +1 -0
  55. package/dist/render.js +335 -0
  56. package/dist/render.js.map +1 -0
  57. package/dist/rpc.js +377 -0
  58. package/dist/rpc.js.map +1 -0
  59. package/dist/sources.js +599 -0
  60. package/dist/sources.js.map +1 -0
  61. package/dist/store.js +330 -0
  62. package/dist/store.js.map +1 -0
  63. package/dist/tokenmeta.js +424 -0
  64. package/dist/tokenmeta.js.map +1 -0
  65. package/dist/util.js +273 -0
  66. package/dist/util.js.map +1 -0
  67. package/dist/vaults.js +510 -0
  68. package/dist/vaults.js.map +1 -0
  69. package/dist/wallet.js +404 -0
  70. package/dist/wallet.js.map +1 -0
  71. package/dist/warnings.js +41 -0
  72. package/dist/warnings.js.map +1 -0
  73. package/dist/worker.js +857 -0
  74. package/dist/worker.js.map +1 -0
  75. package/dist/x402.js +549 -0
  76. package/dist/x402.js.map +1 -0
  77. package/docs/HACKATHON-SUBMISSION.md +264 -0
  78. package/docs/liqproof-plan.md +221 -0
  79. package/docs/llms.txt +32 -0
  80. package/docs/mcp-registry.md +165 -0
  81. package/docs/screenshots/01-dashboard.png +0 -0
  82. package/docs/screenshots/02-receipt-drained.png +0 -0
  83. package/docs/screenshots/03-receipt-impersonator.png +0 -0
  84. package/docs/screenshots/04-receipt-canonical.png +0 -0
  85. package/docs/x402-pricing.md +171 -0
  86. package/docs/zero-xyz.md +250 -0
  87. package/out/6eftxVbSAunVEoxUWdGhPdxg5UdsJ8Wkwy5w5YFuxouw.json +1171 -0
  88. package/out/6eftxVbSAunVEoxUWdGhPdxg5UdsJ8Wkwy5w5YFuxouw.md +52 -0
  89. package/out/6eftxVbSAunVEoxUWdGhPdxg5UdsJ8Wkwy5w5YFuxouw.svg +25 -0
  90. package/out/BTNiaZb6HaEFWeEtND4SXtZ7T6mgtDwSryHTAj6PuPyp.json +3975 -0
  91. package/out/BTNiaZb6HaEFWeEtND4SXtZ7T6mgtDwSryHTAj6PuPyp.md +90 -0
  92. package/out/BTNiaZb6HaEFWeEtND4SXtZ7T6mgtDwSryHTAj6PuPyp.svg +25 -0
  93. package/out/ENGkoidj2jNs73A7GZuseVmnkRg6EVF9tDtViwPz8o85.json +1446 -0
  94. package/out/ENGkoidj2jNs73A7GZuseVmnkRg6EVF9tDtViwPz8o85.md +66 -0
  95. package/out/ENGkoidj2jNs73A7GZuseVmnkRg6EVF9tDtViwPz8o85.svg +25 -0
  96. package/out/dataset.csv +67 -0
  97. package/out/impersonation-table.md +156 -0
  98. package/out/index.html +1179 -0
  99. package/package.json +78 -4
  100. package/scripts/assert-no-canonical-accusations.mjs +193 -0
  101. package/scripts/backfill.mjs +1063 -0
  102. package/scripts/bundle-evidence.mjs +237 -0
  103. package/scripts/bundle-stale-claim.mjs +417 -0
  104. package/scripts/capture-bch-evidence.mjs +58 -0
  105. package/scripts/check-orientation-fix.mjs +40 -0
  106. package/scripts/check-wallet.mjs +54 -0
  107. package/scripts/daily-refresh.mjs +451 -0
  108. package/scripts/decode-clmm-vaults.mjs +180 -0
  109. package/scripts/falsifiability.mjs +263 -0
  110. package/scripts/impersonator-mining.mjs +156 -0
  111. package/scripts/inspect-matches.mjs +73 -0
  112. package/scripts/operator-sweep.mjs +252 -0
  113. package/scripts/publish-release.mjs +248 -0
  114. package/scripts/refresh-store.mjs +78 -0
  115. package/scripts/survival-miner.mjs +951 -0
  116. package/scripts/test-keccak.mjs +103 -0
  117. package/scripts/verify-bch-1p95b.mjs +124 -0
  118. package/scripts/verify-clmm-1p95b.mjs +127 -0
  119. package/scripts/verify-clmm-control.mjs +84 -0
  120. package/scripts/verify-impersonators.mjs +138 -0
  121. package/scripts/verify-raw.mjs +110 -0
  122. package/scripts/verify-raw2.mjs +99 -0
  123. package/server.json +34 -0
  124. package/src/base58.ts +68 -0
  125. package/src/canonical.ts +447 -0
  126. package/src/cli.ts +941 -0
  127. package/src/curve.ts +349 -0
  128. package/src/dashboard.ts +504 -0
  129. package/src/keccak.ts +228 -0
  130. package/src/mcp.ts +735 -0
  131. package/src/operator.ts +219 -0
  132. package/src/receipt.ts +1219 -0
  133. package/src/render.ts +396 -0
  134. package/src/rpc.ts +435 -0
  135. package/src/sources.ts +714 -0
  136. package/src/store.ts +428 -0
  137. package/src/tokenmeta.ts +460 -0
  138. package/src/util.ts +276 -0
  139. package/src/vaults.ts +574 -0
  140. package/src/wallet.ts +459 -0
  141. package/src/warnings.ts +40 -0
  142. package/src/worker.ts +1086 -0
  143. package/src/x402.ts +717 -0
package/src/keccak.ts ADDED
@@ -0,0 +1,228 @@
1
+ /**
2
+ * keccak.ts — Keccak-256 and EIP-55 address checksums, zero dependencies.
3
+ *
4
+ * WHY THIS EXISTS
5
+ *
6
+ * A Base (or any EVM) address is 20 bytes. Written in hex it is 40
7
+ * characters. A single mistyped character produces an address that is
8
+ * perfectly well-formed — the wrong one, but well-formed. Nothing about the
9
+ * string itself tells you it is wrong.
10
+ *
11
+ * EIP-55 solves that with a checksum: the case of every letter encodes a
12
+ * hash of the address itself. If even one character is wrong, the case no
13
+ * longer matches, and the mismatch is detectable without touching a
14
+ * blockchain.
15
+ *
16
+ * That check needs Keccak-256 — the original Keccak, not NIST SHA3-256.
17
+ * They share a sponge construction but differ in the padding byte, and they
18
+ * produce completely different hashes. Node's `crypto` exposes `sha3-256`
19
+ * (NIST) and NOT `keccak-256`, so `createHash('keccak256')` throws and
20
+ * `createHash('sha3-256')` returns the wrong answer. The project has zero
21
+ * dependencies by design (`liqproof verify` asserts it), so the permutation
22
+ * is implemented here directly.
23
+ *
24
+ * The implementation is verified against published test vectors in
25
+ * `scripts/test-keccak.mjs` — the Keccak digest of the empty string and of
26
+ * "abc", plus the four canonical EIP-55 addresses from the EIP itself.
27
+ */
28
+
29
+ // ── the permutation ──────────────────────────────────────────────────────────
30
+
31
+ const MASK64 = (1n << 64n) - 1n;
32
+
33
+ function rotl(x: bigint, n: bigint): bigint {
34
+ if (n === 0n) return x;
35
+ return ((x << n) | (x >> (64n - n))) & MASK64;
36
+ }
37
+
38
+ /** Round constants of Keccak-f[1600]. */
39
+ const RC: bigint[] = [
40
+ 0x0000000000000001n, 0x0000000000008082n, 0x800000000000808an, 0x8000000080008000n,
41
+ 0x000000000000808bn, 0x0000000080000001n, 0x8000000080008081n, 0x8000000000008009n,
42
+ 0x000000000000008an, 0x0000000000000088n, 0x0000000080008009n, 0x000000008000000an,
43
+ 0x000000008000808bn, 0x800000000000008bn, 0x8000000000008089n, 0x8000000000008003n,
44
+ 0x8000000000008002n, 0x8000000000000080n, 0x000000000000800an, 0x800000008000000an,
45
+ 0x8000000080008081n, 0x8000000000008080n, 0x0000000080000001n, 0x8000000080008008n,
46
+ ];
47
+
48
+ /**
49
+ * Rotation offsets and the π permutation, as published in the Keccak
50
+ * reference implementation.
51
+ *
52
+ * These two arrays are used together in the standard "rho and pi" loop:
53
+ * the value of lane `PILN[i-1]` is rotated by `RHO[i]` and written into
54
+ * lane `PILN[i]`.
55
+ *
56
+ * The pair is transcribed verbatim rather than reconstructed from a table,
57
+ * because the two arrays only make sense together — deriving one from the
58
+ * other and transposing it is exactly the mistake this file was written to
59
+ * avoid (and exactly the mistake it initially had).
60
+ */
61
+ const RHO: bigint[] = [
62
+ 1n, 3n, 6n, 10n, 15n, 21n, 28n, 36n, 45n, 55n, 2n, 14n, 27n, 41n, 56n, 8n, 25n, 43n,
63
+ 62n, 18n, 39n, 61n, 20n, 44n,
64
+ ];
65
+
66
+ const PILN: number[] = [
67
+ 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1,
68
+ ];
69
+
70
+ /** In-place Keccak-f[1600] on a flat 25-lane state. */
71
+ function keccakF1600(st: bigint[]): void {
72
+ const bc = new Array<bigint>(5).fill(0n);
73
+
74
+ for (let round = 0; round < 24; round++) {
75
+ // θ — column parities
76
+ for (let i = 0; i < 5; i++) {
77
+ bc[i] = st[i]! ^ st[i + 5]! ^ st[i + 10]! ^ st[i + 15]! ^ st[i + 20]!;
78
+ }
79
+ for (let i = 0; i < 5; i++) {
80
+ const t = bc[(i + 4) % 5]! ^ rotl(bc[(i + 1) % 5]!, 1n);
81
+ for (let j = 0; j < 25; j += 5) st[j + i] = st[j + i]! ^ t;
82
+ }
83
+
84
+ // ρ + π — rotate each lane and move it to its π position
85
+ let t = st[1]!;
86
+ for (let i = 0; i < 24; i++) {
87
+ const j = PILN[i]!;
88
+ const tmp = st[j]!;
89
+ st[j] = rotl(t, RHO[i]!);
90
+ t = tmp;
91
+ }
92
+
93
+ // χ — non-linear step
94
+ for (let j = 0; j < 25; j += 5) {
95
+ for (let i = 0; i < 5; i++) bc[i] = st[j + i]!;
96
+ for (let i = 0; i < 5; i++) {
97
+ st[j + i] = st[j + i]! ^ ((~bc[(i + 1) % 5]!) & MASK64 & bc[(i + 2) % 5]!);
98
+ }
99
+ }
100
+
101
+ // ι — round constant
102
+ st[0] = st[0]! ^ RC[round]!;
103
+ }
104
+ }
105
+
106
+ const RATE_BYTES = 136; // 1088 bits, the rate of Keccak-256
107
+
108
+ /**
109
+ * Keccak-256 (the original Keccak padding, NOT NIST SHA3-256).
110
+ */
111
+ export function keccak256(input: Uint8Array): Uint8Array {
112
+ const blocks = Math.ceil((input.length + 1) / RATE_BYTES);
113
+ const padded = new Uint8Array(blocks * RATE_BYTES);
114
+ padded.set(input);
115
+ padded[input.length] = 0x01; // Keccak domain separator
116
+ padded[padded.length - 1] = (padded[padded.length - 1] ?? 0) | 0x80;
117
+
118
+ const state = new Array<bigint>(25).fill(0n);
119
+
120
+ for (let off = 0; off < padded.length; off += RATE_BYTES) {
121
+ for (let i = 0; i < RATE_BYTES; i++) {
122
+ const lane = i >>> 3;
123
+ const byte = padded[off + i] ?? 0;
124
+ state[lane] = state[lane]! ^ (BigInt(byte) << BigInt(8 * (i & 7)));
125
+ }
126
+ keccakF1600(state);
127
+ }
128
+
129
+ const out = new Uint8Array(32);
130
+ for (let i = 0; i < 32; i++) {
131
+ const lane = i >>> 3;
132
+ out[i] = Number((state[lane]! >> BigInt(8 * (i & 7))) & 0xffn);
133
+ }
134
+ return out;
135
+ }
136
+
137
+ export function toHex(bytes: Uint8Array): string {
138
+ let s = '';
139
+ for (const b of bytes) s += b.toString(16).padStart(2, '0');
140
+ return s;
141
+ }
142
+
143
+ /** Keccak-256 of a string, as lowercase hex. */
144
+ export function keccak256Hex(text: string): string {
145
+ return toHex(keccak256(Buffer.from(text, 'utf8')));
146
+ }
147
+
148
+ // ── EIP-55 ───────────────────────────────────────────────────────────────────
149
+
150
+ const HEX40 = /^0x[0-9a-fA-F]{40}$/;
151
+
152
+ /**
153
+ * The EIP-55 checksummed form of an address.
154
+ *
155
+ * Rules: hash the lowercase 40 hex characters (no `0x` prefix) with
156
+ * Keccak-256. Then uppercase the i-th character if the i-th nibble of the
157
+ * hash is 8 or greater.
158
+ */
159
+ export function eip55Checksum(address: string): string {
160
+ const body = address.toLowerCase().replace(/^0x/, '');
161
+ const hash = keccak256(Buffer.from(body, 'utf8'));
162
+
163
+ let out = '0x';
164
+ for (let i = 0; i < body.length; i++) {
165
+ const byte = hash[i >> 1] ?? 0;
166
+ const nibble = i % 2 === 0 ? (byte >> 4) & 0x0f : byte & 0x0f;
167
+ const ch = body[i]!;
168
+ out += nibble >= 8 ? ch.toUpperCase() : ch;
169
+ }
170
+ return out;
171
+ }
172
+
173
+ export interface EvmAddressCheck {
174
+ valid: boolean;
175
+ /** 'ok' | 'mismatch' | 'not-mixed-case' | 'malformed' */
176
+ checksum: 'ok' | 'mismatch' | 'not-mixed-case' | 'malformed';
177
+ /** The checksummed spelling of the same address. */
178
+ expected: string;
179
+ detail: string;
180
+ }
181
+
182
+ /**
183
+ * Check an EVM address, including its EIP-55 checksum.
184
+ *
185
+ * An all-lowercase address is *valid* — the checksum simply carries no
186
+ * information, because every letter is forced to lowercase. An all-uppercase
187
+ * one is the same. A MIXED-case address, however, is a checksummed spelling:
188
+ * it either matches the hash exactly, or the address was mistyped.
189
+ */
190
+ export function checkEvmAddress(address: string): EvmAddressCheck {
191
+ if (!HEX40.test(address)) {
192
+ return {
193
+ valid: false,
194
+ checksum: 'malformed',
195
+ expected: '',
196
+ detail: 'not a 20-byte hex address (expected 0x followed by 40 hex characters)',
197
+ };
198
+ }
199
+
200
+ const body = address.slice(2);
201
+ const expected = eip55Checksum(address);
202
+ const isMixed = body !== body.toLowerCase() && body !== body.toUpperCase();
203
+
204
+ if (!isMixed) {
205
+ return {
206
+ valid: true,
207
+ checksum: 'not-mixed-case',
208
+ expected,
209
+ detail: 'valid address, but written in a single case — the EIP-55 checksum carries no information',
210
+ };
211
+ }
212
+
213
+ if (address === expected) {
214
+ return {
215
+ valid: true,
216
+ checksum: 'ok',
217
+ expected,
218
+ detail: 'EIP-55 checksum matches — the address was copied correctly',
219
+ };
220
+ }
221
+
222
+ return {
223
+ valid: false,
224
+ checksum: 'mismatch',
225
+ expected,
226
+ detail: 'EIP-55 checksum does NOT match — at least one character is wrong',
227
+ };
228
+ }