blockyard 0.0.1 → 0.0.9
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.
- package/CHANGELOG.md +679 -0
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +172 -4
- package/SECURITY.md +38 -0
- package/bin/blockyard.js +40 -0
- package/config/pool-map.json +2620 -0
- package/docs/API.md +1575 -0
- package/docs/ARCHITECTURE.md +1307 -0
- package/docs/AUTO-UPDATE.md +269 -0
- package/docs/CONFIGURATION.md +840 -0
- package/docs/DEFECTS.md +813 -0
- package/docs/EFFECTS-AGENTS.md +448 -0
- package/docs/GETTING-STARTED.md +202 -0
- package/docs/INSTALL.md +490 -0
- package/docs/MEASUREMENTS.md +1254 -0
- package/docs/PRIVATE-LEADERBOARD.md +230 -0
- package/docs/RULES.md +681 -0
- package/docs/SECURITY-AUDIT-2026-09-14.md +177 -0
- package/docs/SECURITY-AUDIT.md +258 -0
- package/docs/SECURITY.md +195 -0
- package/docs/STATE-2026-09-09.md +200 -0
- package/docs/TROUBLESHOOTING.md +298 -0
- package/docs/USER-GUIDE.md +1022 -0
- package/package.json +53 -5
- package/public/404.html +9 -0
- package/public/css/app.css +1785 -0
- package/public/index.html +893 -0
- package/public/js/about.js +112 -0
- package/public/js/agents.js +964 -0
- package/public/js/app.js +1312 -0
- package/public/js/arkanoid.js +806 -0
- package/public/js/blockanoid.js +347 -0
- package/public/js/blockout.js +347 -0
- package/public/js/blockpack.js +428 -0
- package/public/js/blockscene3d.js +2678 -0
- package/public/js/breakout.js +224 -0
- package/public/js/charts.js +635 -0
- package/public/js/depthchart.js +311 -0
- package/public/js/details3d.js +2957 -0
- package/public/js/explorer.js +405 -0
- package/public/js/feepalette.js +149 -0
- package/public/js/fmt.js +162 -0
- package/public/js/goggles.js +886 -0
- package/public/js/kiosk.js +41 -0
- package/public/js/login.js +83 -0
- package/public/js/markets.js +357 -0
- package/public/js/mining.js +1138 -0
- package/public/js/panels.js +966 -0
- package/public/js/pricechart.js +188 -0
- package/public/js/settings.js +1014 -0
- package/public/js/tetris.js +226 -0
- package/public/js/tetrust.js +356 -0
- package/public/js/tetsound.js +175 -0
- package/public/login.html +33 -0
- package/scripts/blockfile-measure.js +156 -0
- package/scripts/browser-check.mjs +286 -0
- package/scripts/check.js +173 -0
- package/scripts/decode-check.js +81 -0
- package/scripts/doc-counts.js +109 -0
- package/scripts/donate-qr.py +20 -0
- package/scripts/fake-node.js +534 -0
- package/scripts/index-bench.js +216 -0
- package/scripts/index-benchmark.js +117 -0
- package/scripts/index-build.js +40 -0
- package/scripts/live-render-check.mjs +89 -0
- package/scripts/manage-users.js +132 -0
- package/scripts/motion-check.mjs +138 -0
- package/scripts/pool-map.js +157 -0
- package/scripts/setup.js +410 -0
- package/scripts/shots.mjs +272 -0
- package/scripts/smoke.sh +327 -0
- package/scripts/ui.js +174 -0
- package/server/auth/sessions.js +221 -0
- package/server/auth/users.js +243 -0
- package/server/chain/blockfile.js +234 -0
- package/server/chain/index/build.js +193 -0
- package/server/chain/index/heights.js +36 -0
- package/server/chain/index/live.js +276 -0
- package/server/chain/index/rows.js +145 -0
- package/server/chain/index/store.js +154 -0
- package/server/chain/index/worker.js +109 -0
- package/server/chain/tx.js +310 -0
- package/server/collect/gbt.js +229 -0
- package/server/collect/logparse.js +765 -0
- package/server/collect/logtail.js +189 -0
- package/server/collect/markets.js +333 -0
- package/server/collect/mining.js +333 -0
- package/server/collect/monitor.js +2516 -0
- package/server/collect/nextblock.js +275 -0
- package/server/collect/sync.js +386 -0
- package/server/config.js +620 -0
- package/server/http/api.js +1275 -0
- package/server/http/explorer.js +418 -0
- package/server/http/server.js +412 -0
- package/server/http/sse.js +176 -0
- package/server/http/static.js +212 -0
- package/server/main.js +628 -0
- package/server/netinfo.js +253 -0
- package/server/rpc/allowlist.js +130 -0
- package/server/rpc/client.js +414 -0
- package/server/store/audit.js +148 -0
- package/server/store/history.js +220 -0
- package/server/store/ledger.js +290 -0
- package/server/store/ring.js +173 -0
- package/server/util/fmt.js +29 -0
- package/systemd/blockyard.service +100 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# Blockchain leaderboards for the Diversions — scoping report
|
|
2
|
+
|
|
3
|
+
**Private local document.** Gitignored via `docs/PRIVATE-*.md`. Not a decision, not a commitment —
|
|
4
|
+
a scoping of what this would actually take, written 2026-09-13.
|
|
5
|
+
|
|
6
|
+
> Note on the privacy guard: `test/privacy.test.js` scans `git ls-files`, so an ignored file is
|
|
7
|
+
> outside it. That is how a real LAN address reached a commit earlier today. Nothing sensitive
|
|
8
|
+
> should go in here on the assumption a test will catch it.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## The short answers
|
|
13
|
+
|
|
14
|
+
| question | answer |
|
|
15
|
+
|---|---|
|
|
16
|
+
| Do we need a Bitcoin address? | **Only if you want on-chain writes or signed identity.** A working leaderboard needs neither. |
|
|
17
|
+
| How do people submit scores? | **A replay, not a score.** The server re-plays the game and computes the score itself. |
|
|
18
|
+
| Can we do it for free? | **Yes, entirely** — if "use the blockchain" means *seed from a block hash and anchor by timestamp*. **No** if it means *one transaction per score*. |
|
|
19
|
+
| What is the hard part? | **Not the blockchain.** It is proving a score was earned rather than typed into a POST body. |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 1. The insight this whole design rests on
|
|
24
|
+
|
|
25
|
+
The three games were built with a pure-rules / screen split, and the rules are **deterministic by
|
|
26
|
+
construction**. This was done for testability, but it is exactly what a trustworthy leaderboard
|
|
27
|
+
needs.
|
|
28
|
+
|
|
29
|
+
Verified headless under Node on 2026-09-13:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
tetris.js newGame(seed) with a seeded rng(seed); newGame(12345) twice → identical queue
|
|
33
|
+
arkanoid.js hash01(key) everywhere, NO Math.random — capsules, minion lanes, drift phases
|
|
34
|
+
breakout.js launch angle is an argument, not a roll
|
|
35
|
+
all three "no DOM, no canvas, no clock"; they import and run fine in plain Node
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Entry points for a replay: `step(g, dtMs)` (breakout, arkanoid), `tick(g)` / `move` / `rotate` /
|
|
39
|
+
`hardDrop` (tetris). `tetrust.js` already drives the rules from a **fixed-step accumulator**
|
|
40
|
+
(`while (G.acc >= ms)`), so a game is already a discrete sequence of steps, not a wall-clock
|
|
41
|
+
animation.
|
|
42
|
+
|
|
43
|
+
**Therefore the server can replay a submitted game and recompute the score.** That is real
|
|
44
|
+
anti-cheat, and it does not involve Bitcoin at all.
|
|
45
|
+
|
|
46
|
+
## 2. What "use the blockchain" can usefully mean here
|
|
47
|
+
|
|
48
|
+
Four options, ranked by what they actually buy:
|
|
49
|
+
|
|
50
|
+
### (a) Block hash as the game seed — free, and the best fit
|
|
51
|
+
|
|
52
|
+
The tip hash at game start becomes the seed. This gives three properties for nothing:
|
|
53
|
+
|
|
54
|
+
- **Unpredictable** — nobody can pre-compute a favourable piece order, because nobody knows block
|
|
55
|
+
N+1's hash. (Miners have a marginal grinding advantage; irrelevant at this stake.)
|
|
56
|
+
- **A lower time bound** — a game seeded from block N provably was not played before block N. That
|
|
57
|
+
is a real timestamp, from our own node, at zero cost.
|
|
58
|
+
- **A fair shared round** — everyone playing "the block 966,781 round" gets the same piece order, so
|
|
59
|
+
scores are comparable in a way they never are with per-player seeds. This is the genuinely novel
|
|
60
|
+
bit: a *per-block tournament*.
|
|
61
|
+
|
|
62
|
+
We already have the data: `/api/blocks` returns hashes, and the monitor is watching a node anyway.
|
|
63
|
+
|
|
64
|
+
### (b) OpenTimestamps anchoring — free, proves *when*
|
|
65
|
+
|
|
66
|
+
Hash the leaderboard state periodically and submit the digest to public OTS calendar servers, which
|
|
67
|
+
aggregate thousands of digests into one transaction. Produces a Bitcoin-anchored proof that the
|
|
68
|
+
leaderboard said X at time T, and costs nothing because the calendar operator pays the fee.
|
|
69
|
+
|
|
70
|
+
Cost: one outbound HTTPS call to a third party, which conflicts with this project's "outbound
|
|
71
|
+
connections are limited and on demand" stance — it would need to be opt-in and documented in
|
|
72
|
+
`docs/SECURITY.md` alongside the exchange APIs.
|
|
73
|
+
|
|
74
|
+
### (c) OP_RETURN per score — cheap, not free, and probably wrong
|
|
75
|
+
|
|
76
|
+
Real numbers from the node right now: fee estimates ≈ **5.65e-06 BTC/kvB ≈ 0.57 sat/vB**, relay
|
|
77
|
+
floor 1 sat/vB. A minimal OP_RETURN transaction is ~200 vB → **~200 sats ≈ 15¢** at $77k.
|
|
78
|
+
|
|
79
|
+
But: needs a funded wallet, key custody, a UTXO set to manage, change handling, fee bumping when the
|
|
80
|
+
mempool moves, and it puts arcade scores in every archival node on Earth, for ever. It also requires
|
|
81
|
+
passing the node-writes gate, which currently needs four independent yeses and is off by default.
|
|
82
|
+
|
|
83
|
+
**Recommendation: no.** Use (a) for fairness and (b) for timestamping.
|
|
84
|
+
|
|
85
|
+
### (d) Signed scores for pseudonymous identity — free via RPC, but legacy addresses only
|
|
86
|
+
|
|
87
|
+
A player signs their submission with a Bitcoin key; the address is their leaderboard identity. No
|
|
88
|
+
funds, no on-chain footprint.
|
|
89
|
+
|
|
90
|
+
**Partly wrong as first written, corrected 2026-09-13 after the operator asked "why do we need
|
|
91
|
+
crypto primitives — can't we just use the bitcoind rpc?".** They were right.
|
|
92
|
+
|
|
93
|
+
*Verifying* a user's signature needs no crypto code at all: **`verifymessage` is already permitted
|
|
94
|
+
by our own allowlist** and the node does the pubkey recovery. Confirmed it genuinely evaluates
|
|
95
|
+
rather than stubbing — a malformed signature errors `-3 Malformed base64 encoding`, and a bech32
|
|
96
|
+
address errors `Address does not refer to key`.
|
|
97
|
+
|
|
98
|
+
What survives is an **asymmetry**: the node can verify, but it cannot sign *for us*. The Umbrel has
|
|
99
|
+
no wallet loaded (`listwallets` → `[]`), `signmessage` is in our own deny list as a wallet mutator,
|
|
100
|
+
and asking a user's node to hold the monitor's identity is the wrong layer anyway. So:
|
|
101
|
+
|
|
102
|
+
- **users proving they control an address** → pure RPC, no crypto, no dependency;
|
|
103
|
+
- **the monitor holding its own identity and signing attestations** → local keys, which is a
|
|
104
|
+
custody decision rather than a coding one.
|
|
105
|
+
|
|
106
|
+
Node 22 does have enough for the second if wanted: secp256k1 DER sign/verify, `ripemd160`, and
|
|
107
|
+
therefore hash160 — a P2WPKH address derives zero-dependency (verified: produced a valid bech32
|
|
108
|
+
address with a ~40-line encoder). It is *recovery* from a compact signature that Node lacks, and
|
|
109
|
+
only the monitor-side signing path would need it.
|
|
110
|
+
|
|
111
|
+
**THE REAL CONSTRAINT IS ADDRESS TYPE, NOT CRYPTO.** Measured against the node on 2026-09-13:
|
|
112
|
+
|
|
113
|
+
| address | `verifymessage` |
|
|
114
|
+
|---|---|
|
|
115
|
+
| P2PKH `1...` | **works** — returned `false` for a wrong signature, i.e. it evaluated |
|
|
116
|
+
| P2SH `3...` | error: `Address does not refer to key` |
|
|
117
|
+
| P2WPKH `bc1q...` | error: `Address does not refer to key` |
|
|
118
|
+
| P2TR `bc1p...` | error: `Address does not refer to key` |
|
|
119
|
+
|
|
120
|
+
Core's `verifymessage` implements the old "Bitcoin Signed Message" scheme, which is defined only
|
|
121
|
+
for P2PKH. **Most modern wallets — including the one on an Umbrel — hand out `bc1q` or `bc1p`
|
|
122
|
+
addresses, and those users cannot sign this way at all.** That is the main obstacle to the
|
|
123
|
+
user-identity design, and no amount of our own code fixes it, because the limitation is in the
|
|
124
|
+
signing standard rather than in us.
|
|
125
|
+
|
|
126
|
+
Options, in order of how much they cost:
|
|
127
|
+
|
|
128
|
+
1. **Accept legacy-only**, and say so in the UI: "paste a `1...` address". Many wallets can still
|
|
129
|
+
produce one; Sparrow, Electrum and Core itself can sign with a legacy key. Free, honest, and
|
|
130
|
+
excludes some users.
|
|
131
|
+
2. **BIP-322** — the modern generalised signing scheme covering segwit and taproot, and what `bc1`
|
|
132
|
+
wallets actually implement. **Checked, and the answer is no:** Core 31.1.0 (`/Satoshi:31.1.0/`)
|
|
133
|
+
exposes `verifymessage`, `signmessage`, `signmessagewithprivkey`, `signrawtransactionwithkey`,
|
|
134
|
+
`signrawtransactionwithwallet` and `enumeratesigners` — and **no BIP-322 method of any name**.
|
|
135
|
+
So the node cannot verify a segwit or taproot signature for us. Supporting `bc1` identities means
|
|
136
|
+
implementing BIP-322 verification ourselves, which needs precisely the secp256k1 primitives the
|
|
137
|
+
RPC route was chosen to avoid. That is a substantial piece of work and a dependency-rule
|
|
138
|
+
conversation, not an afternoon.
|
|
139
|
+
3. **Do not use Bitcoin signing for identity at all** — a chosen display name plus the replay proof.
|
|
140
|
+
The replay is what makes a score trustworthy; the address only says *who*. If the leaderboard is
|
|
141
|
+
local or shared-by-export, a name is sufficient and costs nothing.
|
|
142
|
+
|
|
143
|
+
## 3. Recommended design
|
|
144
|
+
|
|
145
|
+
**Decision taken 2026-09-13: identity means _users prove who they are_** — the monitor holds no
|
|
146
|
+
key, signs nothing, and custodies nothing. Everything below assumes that.
|
|
147
|
+
|
|
148
|
+
**Per-block tournaments, verified by replay, identified by address, anchored by timestamp.**
|
|
149
|
+
|
|
150
|
+
1. A round opens when a block lands. Its hash seeds every game in that round.
|
|
151
|
+
2. The player plays locally, exactly as now.
|
|
152
|
+
3. On game over, the client submits a **replay**: `{ game, seedBlock, seedHash, steps[], claimedScore }`
|
|
153
|
+
where `steps[]` is the discrete input sequence the fixed-step loop already produces.
|
|
154
|
+
4. The server imports the same pure rules module, replays the steps, and computes the score itself.
|
|
155
|
+
The claimed score is ignored except as a cross-check — a mismatch is a rejected submission.
|
|
156
|
+
5. Accepted entries join the round's board. When the round closes (next block), the board is hashed
|
|
157
|
+
and optionally OTS-anchored.
|
|
158
|
+
|
|
159
|
+
**Identity, if a player wants one** (optional — an anonymous entry is still replay-verified):
|
|
160
|
+
|
|
161
|
+
- The server issues a challenge string tied to the round (`blockyard:<round>:<nonce>`).
|
|
162
|
+
- The player signs it in their own wallet and pastes address + signature.
|
|
163
|
+
- We call `verifymessage` — already permitted by the allowlist, no crypto code, no key on our box.
|
|
164
|
+
- `validateaddress` first, so a `bc1` address is refused with *"legacy `1...` addresses only, see
|
|
165
|
+
BIP-322 note"* rather than a confusing `Address does not refer to key`.
|
|
166
|
+
|
|
167
|
+
Two allowlist additions are needed, one line each: `validateaddress` and `deriveaddresses`. Both
|
|
168
|
+
are read-only and currently denied only because nothing had asked for them.
|
|
169
|
+
|
|
170
|
+
**Testing this path needs no wallet.** `signmessagewithprivkey` takes a WIF and a message and
|
|
171
|
+
returns a signature, so a test can generate a genuine legacy-address signature as a fixture and
|
|
172
|
+
assert that our verification accepts it and rejects a tampered message — without depending on a
|
|
173
|
+
wallet existing on whatever node the suite runs against. That matters: the Umbrel has none
|
|
174
|
+
(`listwallets` → `[]`), and the fake node in `scripts/fake-node.js` would otherwise have to grow a
|
|
175
|
+
signing implementation.
|
|
176
|
+
|
|
177
|
+
Why this is worth doing: the leaderboard is **verifiable by anyone**. Given the replay, any third
|
|
178
|
+
party can recompute the score using the same public rules file. That is a much stronger claim than
|
|
179
|
+
most leaderboards can make, and it comes from the determinism that already exists.
|
|
180
|
+
|
|
181
|
+
## 4. What it actually costs to build
|
|
182
|
+
|
|
183
|
+
| piece | size | notes |
|
|
184
|
+
|---|---|---|
|
|
185
|
+
| Record inputs in the three screen modules | **M** | The fixed-step loop already exists; capture `(stepIndex, action)` pairs. Arkanoid is the fiddliest — mouse position per step needs quantising or it is unreplayable. |
|
|
186
|
+
| Headless replay harness | **S** | The rules already import under Node. Mostly a loop and a score readout. |
|
|
187
|
+
| Replay determinism tests | **M** | The real work: proving client and server agree on every float. **See §5.** |
|
|
188
|
+
| Submission API + storage | **S** | One POST, one GET, a JSON file per round. |
|
|
189
|
+
| Round lifecycle from block events | **S** | The monitor already emits new-tip events. |
|
|
190
|
+
| Leaderboard UI | **M** | A page, a per-round board, a "verify this replay yourself" button. |
|
|
191
|
+
| OTS anchoring | **S** | Optional, opt-in, one HTTPS call. |
|
|
192
|
+
| **Total** | **~2-4 days** | Assuming local/self-hosted scope. |
|
|
193
|
+
|
|
194
|
+
## 5. The risks, honestly
|
|
195
|
+
|
|
196
|
+
- **Floating-point determinism is the sharp edge.** `breakout.js` and `arkanoid.js` advance ball
|
|
197
|
+
physics with floats. Same JS engine, same order of operations, same result — but client and server
|
|
198
|
+
are *different Node/browser builds*, and any divergence makes an honest player's replay fail
|
|
199
|
+
verification. **This must be proven before building anything else**: record N real games in a
|
|
200
|
+
browser, replay them server-side, and assert bit-identical scores. If it does not hold, the fix is
|
|
201
|
+
integer or fixed-point physics, which is a rules rewrite. Tetris is much safer here — it is
|
|
202
|
+
integer grid logic.
|
|
203
|
+
- **Replay size.** A ten-minute Arkanoid game at 60 steps/second is ~36,000 steps. Compressible
|
|
204
|
+
(most steps are "no input"), but it is not a 20-byte score.
|
|
205
|
+
- **A leaderboard is inherently shared, and this app is not.** Blockyard is a single-user LAN
|
|
206
|
+
monitor that ships open-access with a `viewer` ceiling. A *global* leaderboard means **you run a
|
|
207
|
+
hosted service** — with moderation, abuse handling, data retention, and an endpoint strangers
|
|
208
|
+
POST to. That is a different product with different obligations, not a feature of this one.
|
|
209
|
+
Three honest scopes:
|
|
210
|
+
- **Local only** — verified replays, your own high scores, no server. Nearly free to build.
|
|
211
|
+
- **Shared export** — a signed/anchored replay file you can hand to someone else to verify.
|
|
212
|
+
- **Hosted leaderboard** — the real product, and the one with ongoing cost and duty of care.
|
|
213
|
+
- **Replay does not stop a bot.** It proves the score was *achievable under the rules*, not that a
|
|
214
|
+
human earned it. A perfect Tetris bot submits perfectly valid replays. Per-block rounds limit the
|
|
215
|
+
damage (everyone gets one shot at that seed) but do not eliminate it.
|
|
216
|
+
- **Scope creep into custody.** The moment there is a funded address, this stops being a monitor and
|
|
217
|
+
becomes something holding other people's money-adjacent state. Option (c) is where that starts,
|
|
218
|
+
which is the strongest argument against it.
|
|
219
|
+
|
|
220
|
+
## 6. Recommendation
|
|
221
|
+
|
|
222
|
+
1. **Spike the determinism question first** (half a day). Everything else is wasted if browser and
|
|
223
|
+
server disagree on ball physics.
|
|
224
|
+
2. Build **local-only** verified replays with block-hash seeds. Free, no address, no third party, no
|
|
225
|
+
hosted service, and it delivers the interesting half: provably fair rounds and self-verifying
|
|
226
|
+
scores.
|
|
227
|
+
3. Add **OTS anchoring** only if "provably at this time" matters to you. Opt-in, documented as an
|
|
228
|
+
outbound connection.
|
|
229
|
+
4. **Do not** put scores on-chain per-game, and **do not** introduce a funded wallet.
|
|
230
|
+
5. Treat a hosted global leaderboard as a separate product decision, not a Diversions feature.
|