Repository navigation
Description
Affected layers
- Frontend (
src/): affected.normalizeMetricKeyinsrc/hooks/usePersistentDashboardMetrics.tsreplaces every key longer than 256 characters withh:followed by a 32-bit FNV-1a hash, and the three persisted metrics, blocks found, best difficulty and share stats, store their entries under the result. Each key ends with the channel'suser_identity, which the downstream peer picks when it opens the channel. The field is taken from sv2-apps, which reports the string the peer sent; the SV2 open-channel messages allow up to 255 bytes, and the dashboard's own prefix adds about 30 characters, so identities above roughly 225 characters are hashed. When two keys hash alike, the merges treat them as one entry and keep the larger value for each counter. - Backend (
server/): not affected. It stores no metrics. shared/: not affected. The generated types carryuser_identityas a plain string; the length bound comes from the protocol, not from the schema.
Problem
A party that can open two monitored channels can choose two long identities whose full keys collide. The Loupe PoC uses two 272-character keys for channel IDs 1 and 2 that both normalize to h:0264e956. Blocks found of 5 and 7 are stored as 7 instead of 12; the acknowledged, submitted and rejected counters of the two channels collapse the same way, and their rejection reason maps are merged. The hash is 32 bits wide and has no secret, so colliding identities can be computed offline instead of waiting for an accident. The merged entry is persisted, so the under-count survives reloads.
Impact
The operator sees fewer blocks found and fewer shares than the channels reported, for as long as the two channels are tracked, and the persisted totals stay wrong afterwards. It needs a downstream peer able to open two channels with chosen identities long enough to be hashed. Honest setups rarely use identities that long, and an accidental collision between two of them is unlikely, so ordinary deployments are not affected by chance. The best difficulty tile is not affected, since it shows a maximum anyway. Severity low.
Expected outcome
- Two channels whose keys differ never share a persisted entry, whatever the length or content of their identities. Each one's blocks found, share counters and rejection reasons are kept and summed on their own.
- Changing the key scheme does not lower totals that are already persisted.
- A regression test with two long identities that collide under the current scheme, built from a representative
/server/channelspayload asdocs/monitoring-api-compatibility.mdasks.
Possible approach (non-binding)
Raise the key length bound past what the protocol can produce, so that no key needs hashing, or hash with a digest wide enough that a collision cannot be found offline, for example 128 bits or more. The merge runs synchronously inside a state updater, so crypto.subtle does not fit there; a small synchronous digest, or a prefix of the original key kept next to a wider hash, would. The normalizeMetricKey test in src/hooks/usePersistentDashboardMetrics.test.ts is the place for the regression test, and the Loupe PoC provides the colliding pair.
Loupe findings
- project-loupe/audit-sv2-ui#54: keys over 256 characters are replaced by a 32-bit hash with no collision handling (reported as dashboard: two channels with different identities never share a persisted entry #337)
Related issues and PRs
- dashboard: persisted share stats always fit the budget they are read back under #339 depends on the same key and label length bounds for its storage budget.
- Tracker: [Tracker] Dashboard metrics #373.
Loupe export for #337 (finding #54)
Finding
- repo:
stratum-mining/sv2-ui(https://github.com/stratum-mining/sv2-ui.git) - reviewed revision:
b610455ac2d1e017c1df5db8787c0b2e505eabdc - title: Use collision-resistant keys for long channel identities
- severity:
low - location:
src/hooks/usePersistentDashboardMetrics.ts:75-87 - cwe: CWE-328
- scanner:
llm-code-review - fingerprint:
1aa141d7f515d978a2b00b27bda990cf0fb3a1fcfe74a7a4e43e9b0d78388d4a
Description
Every telemetry key longer than 256 characters is replaced by only a 32-bit FNV-1a value, with no collision detection. Channel keys include miner-controlled user_identity, so a party able to open two monitored channels can deliberately choose long identities whose complete, differently prefixed channel keys collide. The PoC supplies two 272-character keys for channel IDs 1 and 2 that both normalize to h:0264e956. mergeMetricEntries then treats them as one channel and retains only the maximum value (7) instead of the correct block-count sum (12). The same normalization is used by share statistics, where acknowledged/submitted/rejected counters and reason maps from distinct channels are similarly coalesced. This permits targeted under-reporting and persistent corruption of operator-visible mining telemetry. Because the namespace is just 32 bits and the function is predictable, collisions can be generated offline rather than occurring only by accident. A caller-side restriction on identity length could affect reachability, but no such restriction is present in the repository's API types or this hook. The prior search for normalizeMetricKey collision and hashString FNV collision telemetry returned no match.
Proof of Concept
diff --git a/src/hooks/usePersistentDashboardMetrics.hash-collision.test.ts b/src/hooks/usePersistentDashboardMetrics.hash-collision.test.ts
new file mode 100644
--- /dev/null
+++ b/src/hooks/usePersistentDashboardMetrics.hash-collision.test.ts
@@ -0,0 +1,22 @@
+import assert from 'node:assert/strict';
+import test from 'node:test';
+
+import { mergeMetricEntries, normalizeMetricKey } from './usePersistentDashboardMetrics.js';
+
+test('distinct long channel identities cannot overwrite through a hash collision', () => {
+ const first = `translator:server:extended:1:${'x'.repeat(230)}123atojcgrg4m`;
+ const second = `translator:server:extended:2:${'y'.repeat(230)}6g09no1dk83sx`;
+
+ assert.notEqual(first, second);
+ assert.notEqual(
+ normalizeMetricKey(first),
+ normalizeMetricKey(second),
+ 'distinct attacker-controlled identities must remain distinct persistence keys',
+ );
+
+ const { next } = mergeMetricEntries({}, [
+ { key: first, value: 5 },
+ { key: second, value: 7 },
+ ]);
+ assert.equal(Object.values(next).reduce((sum, value) => sum + value, 0), 12);
+});
This finding was discovered by Project Loupe.
Activity
[-]Use collision-resistant keys for long channel identities[/-][+]dashboard: two channels with different identities never share a persisted entry[/+]