@xmbl/simulator 0.1.0 → 0.1.11
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 +82 -0
- package/index.js +5 -2
- package/package.json +4 -1
- package/src/devnet.js +3 -2
- package/src/devnet.test.mjs +55 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,87 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Return every `@xmbl/*` protocol package to ONE version line (0.1.11) after a night of per-package
|
|
8
|
+
hotfix publishes (cubic-ledger reached 0.1.10 while zero-knowledge sat at 0.1.1, crates at 0.1.0).
|
|
9
|
+
|
|
10
|
+
Changes since the last unified line (0.1.0), carried as one PATCH line — 0.1.x stays the pre-mainnet line until the ⛔ AUDIT gates close:
|
|
11
|
+
|
|
12
|
+
- cubic-ledger: block ids address CONSENSUS CONTENT (`consensusBody`) instead of the whole tx envelope; an
|
|
13
|
+
anchor's `hash` must be a sha-256 digest; invalid txs are evicted for good (`evict`, `evicted:` keyspace);
|
|
14
|
+
legacy envelope-keyed rows converge to content ids on the next boot; a canonical rebuild preserves every
|
|
15
|
+
non-anchor block and reports what it wiped; `ready()` is the boot join point. `capabilities()` (hardcoded
|
|
16
|
+
flags) is gone; `census.mjs` (an operator one-off) no longer ships in the tarball. A FORGERY CAN NO LONGER
|
|
17
|
+
DELETE THE TRANSACTION IT IMPERSONATES: an invalid typed datum is evicted under a digest of its own bytes,
|
|
18
|
+
never under the xid it claims (a datum fails `validateXid` precisely when that xid is somebody else's), and
|
|
19
|
+
the anchor dedup key claimed before validation is released on every failure. Both doors are closed on BOTH
|
|
20
|
+
entry points — `addTransaction` and `addSealedBatch`, the path a finalized transaction actually takes — and
|
|
21
|
+
one invalid entry in a batch no longer discards the honest transactions behind it.
|
|
22
|
+
- consensus: a content-addressed type-6 value tx is admitted on its content address (it carries no in-body
|
|
23
|
+
signature by design); a malformed anchor is refused at the door by the ledger's own `validateTransaction`;
|
|
24
|
+
`finalizeTransaction` preserves the signed `id`.
|
|
25
|
+
- identity: one canonical `signingMessage`; `signingStatus()` / `verifySigning()`; `Identity.fromPrivateKey`
|
|
26
|
+
(a stub that only threw) is removed.
|
|
27
|
+
- state-machine: the verkle trie is rebuilt on load; diffs are keyed by content identity; `ready()`.
|
|
28
|
+
- networking: self-elected circuit-relay server; NO_FATAL transport tolerance; throttled bootstrap warnings.
|
|
29
|
+
- storage-compute: `CoordinateDelivery` (broken: `require` in ESM, keyed on the public key) is removed.
|
|
30
|
+
- core: ships the node daemon as the `xmbl-node` bin; the control socket implements the coordinator
|
|
31
|
+
contract (`xsc`, `submit_batch`, `ledger_capabilities`, `identity_status`, a signed `chain` claim, honest
|
|
32
|
+
`submit_tx` rejections) and reports the RUNNING versions; boot waits for the stores.
|
|
33
|
+
- every package exports a load-time `VERSION`.
|
|
34
|
+
- PROTOCOL (operator, 2026-09-16): every transaction is typed by its xid (tokens.json type codes; `micromineTx`/
|
|
35
|
+
`validateXid`; untyped rows deleted on boot, skipped by a canonical rebuild; an anchor's wire tx carries `prior`);
|
|
36
|
+
consensus validates in order — can it happen, is the xid correct, is the placement right (`validate.js`,
|
|
37
|
+
`verifyPlacement`); block hashes are content-only so every node seals the same cubes.
|
|
38
|
+
- ROLLOUT (operator, 2026-09-16): a node proves its version (`build` digest of the loaded code, signed into the
|
|
39
|
+
`chain` claim; `release` op), suspends itself when behind the npm `latest` of @xmbl/core (no submits, validations
|
|
40
|
+
or seals), installs the latest over the air and restarts (exit 75 under a supervisor).
|
|
41
|
+
- lng: ships its BROWSER build — `dist/lng.browser.js` (`@xmbl/lng/browser`), one dependency-free ES module
|
|
42
|
+
generated from the same `src/*.js` the node runs and byte-checked by the gate (same surface, same bytes, runs
|
|
43
|
+
with no Node globals); the sources no longer assume `process`/`Buffer`.
|
|
44
|
+
- lng: the `~bytes` BYTE-STRING TYPE reaches the WASM backend — a (pointer, length) pair on the operand
|
|
45
|
+
stack, never a 256-bit word: a literal's bytes live in a data segment with a compile-time length, a runtime
|
|
46
|
+
value (a UTXO id from `xmbl_input_id`) is host-written into fresh memory with its length in a local. A
|
|
47
|
+
`~bytes` FIELD or PARAM is now REFUSED — committed state and the call ABI are both 32-byte words with
|
|
48
|
+
nowhere to put a length, and until now both compiled SILENTLY as words. New opt-in host modes
|
|
49
|
+
`compile(src, { crypto: true })` (`xmbl.mayo.verify` / `xmbl.cubic.verify`) and `{ utxo: true }` (the
|
|
50
|
+
five-entry value ABI), so a contract written in LNG verifies a signature and spends a UTXO the caller
|
|
51
|
+
presented. The value ABI's `-1` sentinel TRAPS instead of widening to 2^256-1. The typechecker refuses
|
|
52
|
+
arithmetic/bitwise/ordering on `~bytes` and now walks `~contract` method bodies at all, which it never did.
|
|
53
|
+
A contract with no byte literals emits a byte-identical, import-free module.
|
|
54
|
+
- storage-compute: THE ERASURE CODER RETURNED CORRUPTED DATA WITHOUT SAYING SO. `StorageShard.decode`
|
|
55
|
+
recovers a lost data shard by XOR-ing its parity group, and XOR parity recovers AT MOST ONE loss per
|
|
56
|
+
group — but when two members of one group were missing it filled the hole with zeros and returned the
|
|
57
|
+
buffer as if decoding had succeeded, with no error, no flag and no short read. MEASURED on k=4, m=2:
|
|
58
|
+
losing data shards 0 and 2 handed back a buffer that differed from the original and nothing downstream
|
|
59
|
+
could tell. Two independent causes are fixed: the group is now checked for completeness before the XOR
|
|
60
|
+
is trusted, and `m` — the encoding's PARITY DEGREE — is carried on every shard as the new optional
|
|
61
|
+
`parityCount` field instead of being inferred from however many parity shards happened to survive (that
|
|
62
|
+
inference was wrong exactly when a parity shard was among the losses: given data 0,1,2 and parity 4 only,
|
|
63
|
+
the inferred m was 1, the recovery group became {0,1,2,3} instead of {0,2}, and decode returned wrong
|
|
64
|
+
bytes). An unrecoverable decode now THROWS and names every missing shard. Proven exhaustively over all
|
|
65
|
+
63 non-empty subsets of a k=4/m=2 encoding: every subset either decodes to the exact original or throws,
|
|
66
|
+
and none returns wrong bytes. COMPAT: `parityCount` is additive and optional, so a shard written by an
|
|
67
|
+
older node reads back fine — a new node treats it as legacy and REFUSES parity recovery rather than
|
|
68
|
+
guessing, which fails loudly where the old code failed silently. Shard metadata persists as JSON
|
|
69
|
+
(`meta:<id>`), so an old reader ignores the extra field.
|
|
70
|
+
- core: a boot crash. `Config._applyEnvOverrides()` assigned into `config.network` / `config.logging`
|
|
71
|
+
without creating them, so a node started with `XN_PORT` or `LOG_LEVEL` set against a config that omitted
|
|
72
|
+
those sections died on `undefined.port` before it could log why. The sections are created on demand.
|
|
73
|
+
- the protocol gate is 75 suites (was 67), and line coverage across the twelve protocol packages is 85.5%
|
|
74
|
+
(was 80.6%). `scripts/coverage-report.mjs` is the instrument: `NODE_V8_COVERAGE` + a V8-range reducer,
|
|
75
|
+
since nothing in the tree measured coverage at all. Ten protocol files that no suite had ever loaded now
|
|
76
|
+
have one; four remain, all process entry points.
|
|
77
|
+
- NODE 22 IS NOW DECLARED, because it was already REQUIRED. Every published package gains
|
|
78
|
+
`engines: { node: ">=22" }`; the workspace root's `">=20"` was simply false. `@xmbl/identity` imports
|
|
79
|
+
`node:sqlite` (Node 22.5+) for the durable nonce registry, `@xmbl/storage-compute` meters jobs with
|
|
80
|
+
`process.threadCpuUsage` (22.10+), and libp2p's own dependency chain calls `Promise.withResolvers`
|
|
81
|
+
(22.0). On Node 20 a consumer installed cleanly and crashed at import instead of being told at install
|
|
82
|
+
time. MEASURED: the protocol gate scores 54/75 on Node 20.20.2 and 75/75 on Node 22 — the twenty-one
|
|
83
|
+
failures were the runtime, not the code. CI and the release workflow now run Node 22 as well.
|
|
84
|
+
|
|
3
85
|
All notable changes to the `xsim` module will be documented in this file.
|
|
4
86
|
|
|
5
87
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
package/index.js
CHANGED
|
@@ -46,5 +46,8 @@ if (isMainModule || process.argv.includes('--run')) {
|
|
|
46
46
|
|
|
47
47
|
export { SystemSimulator, StructuredLogger, LocalDevnet, DevnetRpc };
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
// THE VERSION OF THE CODE THIS PROCESS LOADED. Read once at import time from this package's own manifest, so a
|
|
50
|
+
// running node can report what it is actually executing — an install that lands on disk after this module was
|
|
51
|
+
// loaded changes the file, not this constant. Consumed by @xmbl/core's control socket (`status`.versions).
|
|
52
|
+
import { readFileSync as __readPkg } from 'node:fs';
|
|
53
|
+
export const VERSION = JSON.parse(__readPkg(new URL('./package.json', import.meta.url), 'utf8')).version;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmbl/simulator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"description": "XMBL Simulator",
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
"chance": "^1.1.13"
|
|
15
15
|
},
|
|
16
16
|
"license": "MIT",
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=22"
|
|
19
|
+
},
|
|
17
20
|
"publishConfig": {
|
|
18
21
|
"access": "public"
|
|
19
22
|
},
|
package/src/devnet.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
// getPublicKeyByAddress); the devnet opts it in, which is why the direct path is what it drives.
|
|
25
25
|
import { EventEmitter } from 'node:events';
|
|
26
26
|
import { Identity } from '../../identity/index.js';
|
|
27
|
-
import { Ledger } from '../../cubic-ledger/index.js';
|
|
27
|
+
import { Ledger, micromineTx } from '../../cubic-ledger/index.js';
|
|
28
28
|
|
|
29
29
|
export class LocalDevnet extends EventEmitter {
|
|
30
30
|
constructor(options = {}) {
|
|
@@ -120,7 +120,8 @@ export class LocalDevnet extends EventEmitter {
|
|
|
120
120
|
amount,
|
|
121
121
|
timestamp: Date.now(),
|
|
122
122
|
};
|
|
123
|
-
const
|
|
123
|
+
const typed = micromineTx(tx); // the xmbl type: xid micromined over the body, from final
|
|
124
|
+
const signed = await from.signTransaction(typed); // adds the MAYO sig over everything incl. the xid
|
|
124
125
|
this.metrics.submitted++;
|
|
125
126
|
try {
|
|
126
127
|
const result = await this.ledger.addTransaction(signed);
|
package/src/devnet.test.mjs
CHANGED
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
// control so a regression fails loudly.
|
|
10
10
|
import assert from 'node:assert/strict';
|
|
11
11
|
import { LocalDevnet } from './devnet.js';
|
|
12
|
+
import { micromineTx } from '../../cubic-ledger/index.js';
|
|
12
13
|
import { Identity } from '../../identity/index.js';
|
|
14
|
+
import { Ledger } from '@xmbl/cubic-ledger';
|
|
13
15
|
import { ConsensusWorkflow } from '../../consensus/index.js';
|
|
14
16
|
|
|
15
17
|
let pass = 0;
|
|
@@ -47,7 +49,7 @@ const ok = (name, cond, detail = '') => {
|
|
|
47
49
|
|
|
48
50
|
// NEGATIVE CONTROL — verification is actually ON: a tx tampered after signing is rejected.
|
|
49
51
|
const from = net.identities[0];
|
|
50
|
-
const signed = await from.signTransaction({ id: 'tamper_1', type: 'utxo', from: from.address, to: net.addressOf(1), amount: 5, timestamp: Date.now() });
|
|
52
|
+
const signed = await from.signTransaction(micromineTx({ id: 'tamper_1', type: 'utxo', from: from.address, to: net.addressOf(1), amount: 5, timestamp: Date.now() }));
|
|
51
53
|
const tampered = { ...signed, amount: 9999 }; // mutate a signed field
|
|
52
54
|
let threw = '';
|
|
53
55
|
try { await net.ledger.addTransaction(tampered); } catch (e) { threw = e.message; }
|
|
@@ -60,7 +62,7 @@ const ok = (name, cond, detail = '') => {
|
|
|
60
62
|
{
|
|
61
63
|
const net = await new LocalDevnet({ identities: 2 }).start();
|
|
62
64
|
const from = net.identities[0];
|
|
63
|
-
const signed = await from.signTransaction({ id: 'seam_client_id', type: 'utxo', from: from.address, to: net.addressOf(1), amount: 7, timestamp: Date.now() });
|
|
65
|
+
const signed = await from.signTransaction(micromineTx({ id: 'seam_client_id', type: 'utxo', from: from.address, to: net.addressOf(1), amount: 7, timestamp: Date.now() }));
|
|
64
66
|
|
|
65
67
|
// FIX(a): consensus finalizeTransaction now PRESERVES the originator's signed `id`. It used to
|
|
66
68
|
// overwrite it with validatedHash (workflow.js), corrupting the signed message so the ledger's
|
|
@@ -77,18 +79,62 @@ const ok = (name, cond, detail = '') => {
|
|
|
77
79
|
ok('FIX(a): finalize PRESERVES the signed id (not validatedHash)', !!emitted && emitted.txData.id === 'seam_client_id', `id=${emitted?.txData?.id}`);
|
|
78
80
|
ok('FIX(a): the finalized tx STILL verifies against the signer key', (await Identity.verifyTransaction(emitted.txData, from.publicKey)) === true);
|
|
79
81
|
ok('FIX(a): the consensus hash is carried separately as the event txId', emitted.txId === validatedHash);
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
// so a real finalized tx does NOT re-verify against the signer key. This is why ledger-side
|
|
83
|
-
// re-verification stays OFF in production. If someone wires getPublicKeyByAddress into the
|
|
84
|
-
// Ledger without first resolving (c) (block-id-from-signed-body OR carrying validationTimestamp
|
|
85
|
-
// as a sibling), THIS assertion flips and the gate fails — which is the intended tripwire.
|
|
82
|
+
// WHY A TX MUST NOT CARRY THE CONSENSUS CLOCK: identity's signingMessage covers every field except
|
|
83
|
+
// sig/publicKey, so a `validationTimestamp` written into the body is a value the signer never saw.
|
|
86
84
|
const withVt = { ...signed, validationTimestamp: '123' };
|
|
87
|
-
ok('
|
|
85
|
+
ok('a tx carrying a validationTimestamp INSIDE the signed body does NOT re-verify (why A5 moved it out)',
|
|
88
86
|
(await Identity.verifyTransaction(withVt, from.publicKey)) === false);
|
|
89
87
|
try { await w.mempool?.db?.close?.(); } catch { /* in-memory / already closed */ }
|
|
90
88
|
}
|
|
91
89
|
|
|
90
|
+
// FIX(c) / A5 — DRIVEN AT THE REAL SITE, not asserted on a hand-built object. The previous version of this
|
|
91
|
+
// block pinned the DEFECT by checking a property of verifyTransaction itself, which no amount of fixing
|
|
92
|
+
// moveToProcessing could ever flip — a tripwire that could not trip. This runs the actual pipeline:
|
|
93
|
+
// addRawTransaction → quorum timestamps → moveToProcessing → finalizeTransaction → the ledger, with a key
|
|
94
|
+
// resolver wired exactly as the daemon wires it (B7). If consensus ever writes its clock back into the
|
|
95
|
+
// signed body, the finalized tx stops verifying and the ledger refuses it — here, in the gate.
|
|
96
|
+
{
|
|
97
|
+
const w = new ConsensusWorkflow({});
|
|
98
|
+
const rawTxId = await w.mempool.addRawTransaction('leaderA', { ...signed });
|
|
99
|
+
w.rawTxToId.set(rawTxId, 'leaderA');
|
|
100
|
+
const entry = w.mempool.rawTx.get('leaderA').get(rawTxId);
|
|
101
|
+
entry.validationTimestamps = [
|
|
102
|
+
{ nodeId: 'v1', timestamp: 1789470971116000000n },
|
|
103
|
+
{ nodeId: 'v2', timestamp: 1789470971117000000n },
|
|
104
|
+
{ nodeId: 'v3', timestamp: 1789470971118000000n },
|
|
105
|
+
];
|
|
106
|
+
await w.moveToProcessing(rawTxId);
|
|
107
|
+
const [key, processing] = [...w.mempool.processingTx.entries()][0];
|
|
108
|
+
ok('A5: the processing tx body carries NO validationTimestamp (the clock is a sibling)',
|
|
109
|
+
processing.txData.validationTimestamp === undefined, `body=${JSON.stringify(Object.keys(processing.txData))}`);
|
|
110
|
+
ok('A5: the clock travels BESIDE the tx and is non-null', processing.validationTimestamp != null);
|
|
111
|
+
ok('A5: the processing tx STILL verifies against the signer key (the whole point)',
|
|
112
|
+
(await Identity.verifyTransaction(processing.txData, from.publicKey)) === true);
|
|
113
|
+
|
|
114
|
+
let fin = null;
|
|
115
|
+
w.on('tx:finalized', (d) => { fin = d; });
|
|
116
|
+
await w.finalizeTransaction(key);
|
|
117
|
+
ok('A5: the FINALIZED tx verifies against the signer key', !!fin && (await Identity.verifyTransaction(fin.txData, from.publicKey)) === true);
|
|
118
|
+
ok('A5: the finalized event carries the clock as its own field', fin.validationTimestamp != null && fin.txData.validationTimestamp === undefined);
|
|
119
|
+
|
|
120
|
+
// B7 — the ledger, with the resolver the daemon now wires, verifies the same tx a SECOND time.
|
|
121
|
+
const led = new Ledger({});
|
|
122
|
+
led.xid = from; // enables the ledger's signature check
|
|
123
|
+
led.getPublicKeyByAddress = (addr) => (addr === from.address ? from.publicKey : null);
|
|
124
|
+
const res = await led.addTransaction(fin.txData, { validationTimestamp: fin.validationTimestamp });
|
|
125
|
+
ok('B7: a signed finalized tx is ACCEPTED at the ledger with re-verification ON', !!res && res.duplicate !== true);
|
|
126
|
+
const block = [...led._membershipPool, ...led.blocks.values()].find((b) => b.tx && b.tx.id === 'seam_client_id');
|
|
127
|
+
ok('B7: the block carries the consensus clock as its own field, and its tx does not',
|
|
128
|
+
!!block && block.validationTimestamp != null && block.tx.validationTimestamp === undefined);
|
|
129
|
+
let refused = '';
|
|
130
|
+
try { await led.addTransaction({ ...fin.txData, amount: 424242 }, { validationTimestamp: fin.validationTimestamp }); }
|
|
131
|
+
catch (e) { refused = e.message; }
|
|
132
|
+
ok('B7: a tx tampered AFTER consensus is REFUSED at the ledger (the defense-in-depth layer is live)',
|
|
133
|
+
/Invalid transaction signature|address mismatch/.test(refused), `threw="${refused}"`);
|
|
134
|
+
try { await w.mempool?.db?.close?.(); } catch { /* in-memory / already closed */ }
|
|
135
|
+
try { await led.close?.(); } catch { /* in-memory */ }
|
|
136
|
+
}
|
|
137
|
+
|
|
92
138
|
// FIX(a) negative control: mutating `id` AFTER signing (what the old overwrite effectively did)
|
|
93
139
|
// is REJECTED by the ledger — `id` is inside the signed domain, which is exactly why consensus
|
|
94
140
|
// must not overwrite it.
|