@midnightntwrk/testkit-js 0.0.0-stage → 5.0.1
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/README.md +409 -2
- package/dist/fixtures/hf/README.md +781 -0
- package/dist/fixtures/hf/coin-receiver-016/coin-receiver.compact +24 -0
- package/dist/fixtures/hf/coin-receiver-016/compiled/compiler/contract-info.json +104 -0
- package/dist/fixtures/hf/coin-receiver-016/compiled/contract/index.d.ts +47 -0
- package/dist/fixtures/hf/coin-receiver-016/compiled/contract/index.js +412 -0
- package/dist/fixtures/hf/coin-receiver-016/receive-coin-transcript.recording.json +668 -0
- package/dist/fixtures/hf/coin-receiver-016/state-v6-envelope.hex +1 -0
- package/dist/fixtures/hf/coin-receiver-016/state-v9.hex +1 -0
- package/dist/fixtures/hf/counter-016/compiled/compiler/contract-info.json +31 -0
- package/dist/fixtures/hf/counter-016/compiled/contract/index.d.ts +39 -0
- package/dist/fixtures/hf/counter-016/compiled/contract/index.js +189 -0
- package/dist/fixtures/hf/counter-016/compiled/keys/increment.prover +0 -0
- package/dist/fixtures/hf/counter-016/compiled/keys/increment.verifier +0 -0
- package/dist/fixtures/hf/counter-016/compiled/zkir/increment.bzkir +0 -0
- package/dist/fixtures/hf/counter-016/compiled/zkir/increment.zkir +22 -0
- package/dist/fixtures/hf/counter-016/increment-transcript.golden.json +23 -0
- package/dist/fixtures/hf/fixtures.json +69 -0
- package/dist/fixtures/hf/pre-fork-private-state-store/.gitattributes +8 -0
- package/dist/fixtures/hf/pre-fork-private-state-store/ENVELOPE.md +70 -0
- package/dist/fixtures/hf/pre-fork-private-state-store/store/000005.ldb +0 -0
- package/dist/fixtures/hf/pre-fork-private-state-store/store/000006.log +0 -0
- package/dist/fixtures/hf/pre-fork-private-state-store/store/CURRENT +1 -0
- package/dist/fixtures/hf/pre-fork-private-state-store/store/MANIFEST-000004 +0 -0
- package/dist/fixtures/hf/private-counter-016/README.md +13 -0
- package/dist/fixtures/hf/private-counter-016/compiled/compiler/contract-info.json +40 -0
- package/dist/fixtures/hf/private-counter-016/compiled/contract/index.d.ts +40 -0
- package/dist/fixtures/hf/private-counter-016/compiled/contract/index.js +211 -0
- package/dist/fixtures/hf/private-counter-twin/compiled/compiler/contract-info.json +41 -0
- package/dist/fixtures/hf/private-counter-twin/compiled/contract/index.js +271 -0
- package/dist/fixtures/hf/private-counter-twin/private-counter.compact +27 -0
- package/dist/fixtures/hf/state-both-keys.hex +1 -0
- package/dist/fixtures/hf/state-co-v2-only-foreign.hex +1 -0
- package/dist/fixtures/hf/state-migrated-v9-merkle.hex +1 -0
- package/dist/fixtures/hf/state-migrated-v9.hex +1 -0
- package/dist/fixtures/hf/state-tampered-bytes.hex +1 -0
- package/dist/fixtures/hf/state-tampered-keyset-v8to9.hex +1 -0
- package/dist/fixtures/hf/state-tampered-keyset-v9to8.hex +1 -0
- package/dist/fixtures/hf/state-v8-v6-envelope.hex +1 -0
- package/dist/fixtures/hf/state-v8.hex +1 -0
- package/dist/fixtures/hf/twin-contract/compiled/compiler/contract-info.json +31 -0
- package/dist/fixtures/hf/twin-contract/compiled/compiler/contract-manifest.json +58 -0
- package/dist/fixtures/hf/twin-contract/compiled/contract/index.d.ts +40 -0
- package/dist/fixtures/hf/twin-contract/compiled/contract/index.js +196 -0
- package/dist/fixtures/hf/twin-contract/compiled/keys/increment.prover +0 -0
- package/dist/fixtures/hf/twin-contract/compiled/keys/increment.verifier +0 -0
- package/dist/fixtures/hf/twin-contract/compiled/zkir/increment.bzkir +0 -0
- package/dist/fixtures/hf/twin-contract/compiled/zkir/increment.zkir +22 -0
- package/dist/fixtures/hf/twin-contract/counter.compact +15 -0
- package/dist/fixtures-hf.d.ts +70 -0
- package/dist/fixtures-hf.js +161 -0
- package/dist/fixtures-hf.js.map +1 -0
- package/dist/index.d.ts +1067 -0
- package/dist/index.js +3459 -0
- package/dist/index.js.map +1 -0
- package/package.json +82 -3
|
@@ -0,0 +1,781 @@
|
|
|
1
|
+
# Hard-fork fixtures
|
|
2
|
+
|
|
3
|
+
Fixtures for the ledger v8/v9 hard-fork migration work. Every fixture is a
|
|
4
|
+
well-formed `ContractState`-shaped byte blob, committed as lower-case hex
|
|
5
|
+
text, for the **`counter` contract** — the smallest contract in the
|
|
6
|
+
upstream hard-fork prototype (a single `round: Counter` ledger cell, one
|
|
7
|
+
nullary circuit `increment()`), chosen for minimal size (repo precedent:
|
|
8
|
+
WASM-fixture coverage timeouts on large fixtures). Every fixture deserializes
|
|
9
|
+
as a `ContractState` on at least one ledger version — none of them fail at
|
|
10
|
+
the envelope-tag check by design; where a fixture exists to probe a failure,
|
|
11
|
+
that failure is pushed as deep as the fixture's construction allows (a
|
|
12
|
+
version-tag mismatch, a corrupted payload, or — for the mis-dispatch
|
|
13
|
+
negative — a foreign key inside an otherwise-valid operation slot, deferring
|
|
14
|
+
the failure to execution).
|
|
15
|
+
|
|
16
|
+
Source of truth for every claim below is `generators/*.mjs` (mint scripts,
|
|
17
|
+
runnable) plus throwaway, not-committed `generators/.probe*.mjs` scripts used
|
|
18
|
+
while authoring this fixture set to verify every deserialize outcome quoted
|
|
19
|
+
here against the real `@midnightntwrk/ledger-v8@8.1.2` /
|
|
20
|
+
`@midnightntwrk/ledger-v9@1.0.0-rc.3` packages — nothing below is guessed.
|
|
21
|
+
|
|
22
|
+
> **On provenance paths.** Where a fixture is described as ported from
|
|
23
|
+
> `spike-dapp-hf/…`, that is an internal hard-fork prototype repository, not a
|
|
24
|
+
> public one: the paths record *where the bytes came from* so the port can be
|
|
25
|
+
> audited internally, and are not resolvable from outside the project. Every
|
|
26
|
+
> behavioural claim in this file is reproducible from the committed bytes and
|
|
27
|
+
> the two ledger packages named above, without access to that repository.
|
|
28
|
+
|
|
29
|
+
## Consuming these fixtures
|
|
30
|
+
|
|
31
|
+
The whole tree below `src/fixtures/hf/` is **published** with
|
|
32
|
+
`@midnightntwrk/testkit-js`. The build copies it verbatim into
|
|
33
|
+
`dist/fixtures/hf/`, and `src/fixtures-hf.ts` resolves it relative to its own
|
|
34
|
+
module URL, so the same accessors work from source inside this repo and from
|
|
35
|
+
the installed package outside it:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import {
|
|
39
|
+
HF_FIXTURE_NAMES,
|
|
40
|
+
hfFixturePath,
|
|
41
|
+
hfFixturesManifest,
|
|
42
|
+
readHfFixture
|
|
43
|
+
} from '@midnightntwrk/testkit-js/fixtures-hf';
|
|
44
|
+
|
|
45
|
+
const bytes = readHfFixture('state-v8.hex'); // Uint8Array
|
|
46
|
+
const era = hfFixturesManifest['state-v8.hex'].protocolVersion; // 1000000
|
|
47
|
+
const source = hfFixturePath('twin-contract/counter.compact'); // absolute path
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`readHfFixture` covers the nine `.hex` states. Everything else in this tree —
|
|
51
|
+
every compiled contract and its source, the transcripts, the frozen
|
|
52
|
+
private-state store, `fixtures.json`, this README — is reached by path through
|
|
53
|
+
`hfFixturePath`. The sections below are the enumeration; this sentence is
|
|
54
|
+
deliberately not a second one. Both accessors throw rather than
|
|
55
|
+
returning a placeholder: an unknown fixture name, a path that climbs out of the
|
|
56
|
+
fixture directory, a missing file and a hex file that is not whole hex are all
|
|
57
|
+
errors. `hfFixturesManifest` is validated against `HF_FIXTURE_NAMES` at import,
|
|
58
|
+
so a manifest that has drifted fails immediately instead of at first lookup.
|
|
59
|
+
|
|
60
|
+
Two things to know about what ships:
|
|
61
|
+
|
|
62
|
+
- **`generators/` is deliberately excluded.** The mint scripts import the
|
|
63
|
+
`ledger-v8`/`ledger-v9` devDependencies, which a consumer of the published
|
|
64
|
+
package does not get. They stay a repo-only tool; see
|
|
65
|
+
[Regenerating](#regenerating).
|
|
66
|
+
- **The compiled contract `index.js` files are data, not modules.** In
|
|
67
|
+
particular `counter-016/compiled/contract/index.js` expects
|
|
68
|
+
`@midnight-ntwrk/compact-runtime@0.16`, which nothing in this repo installs
|
|
69
|
+
under that name
|
|
70
|
+
(see [Version pin note](#version-pin-note-deviation-from-the-brief-with-evidence)).
|
|
71
|
+
Read these files, do not `import` them.
|
|
72
|
+
- **Their `index.d.ts` siblings are imported, but only in-repo.** They name
|
|
73
|
+
`compact-runtime-ledger8`, an alias that exists in THIS workspace and not in
|
|
74
|
+
an installed consumer's, so they will not resolve for you — the same caveat as
|
|
75
|
+
the `index.js` above, one level up. `packages/contracts` imports them
|
|
76
|
+
type-only to type its retained-era fixtures; see [`counter-016/`](#counter-016).
|
|
77
|
+
|
|
78
|
+
## Fixtures
|
|
79
|
+
|
|
80
|
+
| File | protocolVersion | Mint path | What it is |
|
|
81
|
+
|---|---|---|---|
|
|
82
|
+
| `state-v8.hex` | 1000000 | mint (npm, cheap) | `state-v8-v6-envelope.hex` bridged through `ledger-v8`'s `ContractState` (`Ledger8ContractState.deserialize(bytes).serialize()`), the same bridge `assemble.ts:59-60` uses. **Finding:** byte-identical to its input — ledger-v8's codec accepts the v6-tagged envelope unchanged. |
|
|
83
|
+
| `state-v8-v6-envelope.hex` | 1000000 | golden (ported) | Raw `compact-runtime-0.16` `ContractState.serialize()` output. Tag `contract-state[v6]`. Ported verbatim from `spike-dapp-hf/island-3/driver/tests/builder/fixtures/downcast-v8.hex` (byte-identical across islands 1/2/3 and `ts-downcast/`). |
|
|
84
|
+
| `state-migrated-v9.hex` | 2000000 | golden (ported) | A real ledger-8→9 migrated contract state. Tag `contract-state[v8]`. Ported verbatim from `spike-dapp-hf/island-3/driver/tests/builder/fixtures/migrated-v9.hex`. Produced upstream by the prototype's Rust simulator's `migrate-8-to-9` state translation. |
|
|
85
|
+
| `state-migrated-v9-merkle.hex` | 2000000 | mint (npm, cheap) | Synthetic (not a real migration): a hand-built, rehashed `StateBoundedMerkleTree` wrapped in a `ContractState`, built only from `@midnightntwrk/ledger-v9`'s public API. Deserializes cleanly with `ledger-v9`. |
|
|
86
|
+
| `state-tampered-keyset-v8to9.hex` | 2000000 (claimed) / 1000000 (actual payload) | derive | `state-v8-v6-envelope.hex` with only the tag's version digit flipped `'6'→'8'`. |
|
|
87
|
+
| `state-tampered-keyset-v9to8.hex` | 1000000 (claimed) / 2000000 (actual payload) | derive | `state-migrated-v9.hex` with only the tag's version digit flipped `'8'→'6'`. |
|
|
88
|
+
| `state-tampered-bytes.hex` | 2000000 | derive | `state-migrated-v9.hex` with one payload byte bit-flipped past the header. |
|
|
89
|
+
| `state-both-keys.hex` | null (ambiguous by design) | derive | `state-v8-v6-envelope.hex` ++ `state-migrated-v9.hex` concatenated — both envelope tags in one blob. |
|
|
90
|
+
| `state-co-v2-only-foreign.hex` | 2000000 | mint (npm, cheap) | Mis-dispatch negative: a full, well-formed `ContractState` (deserializes cleanly on `ledger-v9`) whose `increment` operation slot carries a FOREIGN verifier key — borrowed from the golden `state-migrated-v9.hex`'s real `post` operation (a different, real migrated circuit, not built from the retained counter artifacts). Fails later, at execution, not at decode. |
|
|
91
|
+
|
|
92
|
+
`fixtures.json` repeats this table machine-readably, plus the exact envelope
|
|
93
|
+
tag / claimed-vs-actual era for each, plus `status` (`ok` / `synthetic` /
|
|
94
|
+
`tampered`).
|
|
95
|
+
|
|
96
|
+
### protocolVersion scheme
|
|
97
|
+
|
|
98
|
+
Scheme: `node-major * 1_000_000 + node-minor * 1_000`. v8-era fixtures use
|
|
99
|
+
`1_000_000` (node 1.x, pre-fork); v9-era fixtures use `2_000_000` (node 2.x,
|
|
100
|
+
post-fork). `state-both-keys.hex` has no single valid value by construction
|
|
101
|
+
(it wears both tags) and is recorded as `null`.
|
|
102
|
+
|
|
103
|
+
## Verified decode matrix
|
|
104
|
+
|
|
105
|
+
Every fixture was actually fed to both `@midnightntwrk/ledger-v8`'s and
|
|
106
|
+
`@midnightntwrk/ledger-v9`'s `ContractState.deserialize` while authoring this
|
|
107
|
+
set. All nine outcomes:
|
|
108
|
+
|
|
109
|
+
| Fixture | `ledger-v8.ContractState.deserialize` | `ledger-v9.ContractState.deserialize` |
|
|
110
|
+
|---|---|---|
|
|
111
|
+
| `state-v8.hex` | ACCEPT | THROW (tag `v6` != `v8`) |
|
|
112
|
+
| `state-v8-v6-envelope.hex` | ACCEPT | THROW (tag `v6` != `v8`) |
|
|
113
|
+
| `state-migrated-v9.hex` | THROW (tag `v8` != `v6`) | ACCEPT |
|
|
114
|
+
| `state-migrated-v9-merkle.hex` | THROW (tag `v8` != `v6`) | ACCEPT |
|
|
115
|
+
| `state-tampered-keyset-v8to9.hex` | THROW (tag `v8` != `v6`) | THROW ("failed to fill whole buffer" — the v6 payload is not a valid v8 payload) |
|
|
116
|
+
| `state-tampered-keyset-v9to8.hex` | THROW ("deserialized storage graph not in normal form") | THROW (tag `v6` != `v8`) |
|
|
117
|
+
| `state-tampered-bytes.hex` | THROW (tag `v8` != `v6`) | THROW ("out of range for u64") |
|
|
118
|
+
| `state-both-keys.hex` | THROW ("Not all bytes read...4692 bytes remaining") | THROW (tag mismatch at offset 0) |
|
|
119
|
+
| `state-co-v2-only-foreign.hex` | THROW (tag `v8` != `v6` — this fixture is v9-era only) | **ACCEPT** (shape-positive — see "The mis-dispatch fixture" below) |
|
|
120
|
+
|
|
121
|
+
**Every fixture that is meant to fail at decode does fail closed, on both
|
|
122
|
+
decoders — no silent-accept was found among them.** `state-both-keys.hex` in
|
|
123
|
+
particular shows `ledger-v8`'s deserializer validates full-buffer consumption
|
|
124
|
+
(it does not silently stop after the first complete message and ignore
|
|
125
|
+
trailing bytes). `state-co-v2-only-foreign.hex` is the one fixture in this
|
|
126
|
+
table that is SUPPOSED to accept on `ledger-v9` — see below for why, and
|
|
127
|
+
where its failure actually lives. This is the strongest empirical
|
|
128
|
+
evidence this fixture set provides about how the two deserializers behave
|
|
129
|
+
across the fork boundary.
|
|
130
|
+
|
|
131
|
+
### The mis-dispatch fixture (`state-co-v2-only-foreign.hex`)
|
|
132
|
+
|
|
133
|
+
Minted (`generators/mint-co-v2-foreign.mjs`) as: a fresh, blank
|
|
134
|
+
`ContractState` (`StateValue.newNull()` data — the ledger payload doesn't
|
|
135
|
+
matter for this fixture's purpose) with one operation registered under the
|
|
136
|
+
counter's own circuit name, `increment` — but the `ContractOperation`
|
|
137
|
+
object registered there is not built from anything in `twin-contract/`. It
|
|
138
|
+
is the REAL `post` operation `ContractState.deserialize('state-migrated-v9.hex').operation('post')`
|
|
139
|
+
returns: bboard's own, genuinely migrated, pre-fork-compiled verifier key
|
|
140
|
+
(the single-slot `op.v2` shape, migrated via
|
|
141
|
+
`source.v2 -> op.v2`; `ContractOperation`'s plain `verifierKey` getter is
|
|
142
|
+
documented as exposing "only the latest available version"). Verified
|
|
143
|
+
(`generators/mint-co-v2-foreign.mjs`'s own self-check, run at mint time, plus
|
|
144
|
+
the smoke test): the result deserializes cleanly with `ledger-v9`
|
|
145
|
+
(`operations()` returns `['increment']`), and its `verifierKey` bytes are
|
|
146
|
+
confirmed to differ from `twin-contract/compiled/keys/increment.verifier` —
|
|
147
|
+
genuinely foreign, not just relabeled.
|
|
148
|
+
|
|
149
|
+
This is deliberate: `downcastV9StateForExecution` (`downcast.ts`) reads
|
|
150
|
+
*only* `.data` (the `StateValue`), never `.operations()` — so this fixture
|
|
151
|
+
cannot and does not fail at down-convert. Nor does the mere presence check
|
|
152
|
+
`assemble.ts` uses (`state.operation(circuitId) === undefined ? throw :
|
|
153
|
+
...`) catch it — the slot IS populated. The mismatch is only observable at
|
|
154
|
+
the next step: attempting to actually prove/verify a real `increment` call
|
|
155
|
+
against this state's `increment` slot, which is keyed for a completely
|
|
156
|
+
different circuit. That later, deterministic, typed failure (a verifier-key
|
|
157
|
+
mismatch at proof-verification time) is the engine-level test this fixture
|
|
158
|
+
feeds; minting it is out of scope here (it needs a real proof-server round
|
|
159
|
+
trip), so this fixture supplies only the well-formed-but-booby-trapped STATE
|
|
160
|
+
input for that test to consume.
|
|
161
|
+
|
|
162
|
+
## Tampered fixtures
|
|
163
|
+
|
|
164
|
+
The byte-level offsets `generators/mint-tampered-and-derived.mjs` uses,
|
|
165
|
+
spelled out (all four are reproducible, documented byte surgery on a real
|
|
166
|
+
golden — see the file itself for the exact code):
|
|
167
|
+
|
|
168
|
+
- **`state-tampered-keyset-v8to9.hex`**: `state-v8-v6-envelope.hex` with only
|
|
169
|
+
the tag's single ASCII version digit flipped, `'6' -> '8'`, at the offset
|
|
170
|
+
found by `indexOf('[v') + 2` (offset 25 for this golden). Everything else
|
|
171
|
+
is untouched.
|
|
172
|
+
- **`state-tampered-keyset-v9to8.hex`**: `state-migrated-v9.hex`, same
|
|
173
|
+
technique, digit flipped `'8' -> '6'` (offset 25).
|
|
174
|
+
- **`state-tampered-bytes.hex`**: `state-migrated-v9.hex` with one payload
|
|
175
|
+
byte XORed with `0xff` at `headerLen + 32` (offset 57), tag left intact.
|
|
176
|
+
- **`state-both-keys.hex`**: `state-v8-v6-envelope.hex` bytes followed
|
|
177
|
+
immediately by `state-migrated-v9.hex` bytes, concatenated — no offset
|
|
178
|
+
math, just `Buffer.concat`.
|
|
179
|
+
|
|
180
|
+
None of these four are states a real chain could ever produce; each probes
|
|
181
|
+
exactly one failure mode (schema-tag lie, payload corruption, or envelope
|
|
182
|
+
over-read). See "Verified decode matrix" above for what actually happens
|
|
183
|
+
when each is fed to both ledgers' `ContractState.deserialize`.
|
|
184
|
+
|
|
185
|
+
## Mint-path decisions (per the brief's (a)/(b)/(c) order)
|
|
186
|
+
|
|
187
|
+
For the two "hard" fixtures (`state-migrated-v9.hex`,
|
|
188
|
+
`state-migrated-v9-merkle.hex`), the brief mandated checking, in order:
|
|
189
|
+
|
|
190
|
+
- **(a) Does `ledger-v9` expose a migration entry point?** Checked
|
|
191
|
+
`node_modules/@midnightntwrk/ledger-v9/ledger-v9.d.ts` for
|
|
192
|
+
`migrate`/`from_v8`/`upgrade`. Only hit: `upgradeFromTransient(transient:
|
|
193
|
+
Value): Value` — an unrelated Zswap-value helper, not a state migration.
|
|
194
|
+
**(a) FAILED** for both fixtures.
|
|
195
|
+
- **(b) Does the spike already have committed golden migrated-state hex?**
|
|
196
|
+
`find . -iname '*.hex'` across `spike-dapp-hf` found exactly two hex
|
|
197
|
+
fixtures, present identically in all of islands 1/2/3 and `ts-downcast/`:
|
|
198
|
+
`downcast-v8.hex` (tag `v6`) and `migrated-v9.hex` (tag `v8`) — see
|
|
199
|
+
`island-3/driver/tests/builder/downcast.test.ts`, which uses them exactly as
|
|
200
|
+
this task needs (a real migrated state, and a v6-envelope negative).
|
|
201
|
+
**(b) SUCCEEDED for `state-migrated-v9.hex`** (and, as a bonus, for
|
|
202
|
+
`state-v8-v6-envelope.hex`, which the brief also needed). **(b) FAILED for
|
|
203
|
+
`state-migrated-v9-merkle.hex`** — no small tree-bearing golden exists (only
|
|
204
|
+
the large `bboard`/`shielded-hf` fixtures carry a Merkle tree, and copying
|
|
205
|
+
one would violate the minimal-size mandate).
|
|
206
|
+
- **(c) Build the spike's Rust simulator.** Not attempted: (b) already
|
|
207
|
+
supplied `state-migrated-v9.hex`, and `state-migrated-v9-merkle.hex`'s actual
|
|
208
|
+
requirement — a `ContractState` whose `StateValue` contains a
|
|
209
|
+
`BoundedMerkleTree` that deserializes cleanly with `ledger-v9` — turned out
|
|
210
|
+
to be mintable directly from `ledger-v9`'s public `StateBoundedMerkleTree`/
|
|
211
|
+
`StateValue` API (see `generators/mint-migrated-v9-merkle.mjs`), with no
|
|
212
|
+
dependency on any specific contract's compiled ledger schema (the
|
|
213
|
+
down-convert's rehash step is contract-agnostic — it recurses the generic
|
|
214
|
+
`StateValue` algebra). (c) was therefore never time-boxed or attempted.
|
|
215
|
+
|
|
216
|
+
## `twin-contract/`
|
|
217
|
+
|
|
218
|
+
`twin-contract/counter.compact` is the spike's counter contract, copied
|
|
219
|
+
verbatim from
|
|
220
|
+
`spike-dapp-hf/island-3/tests/tester/fixtures/counter/counter.compact`.
|
|
221
|
+
|
|
222
|
+
`twin-contract/compiled/` is that same source **recompiled with a v9-era
|
|
223
|
+
toolchain** — a one-off snapshot taken with `compactc 0.33.0-rc.2` (fetched via
|
|
224
|
+
`yarn fetch-compactc` per `packages/compact`), reporting
|
|
225
|
+
`compiler-version: 0.33.0`, `language-version: 0.25.0`,
|
|
226
|
+
`runtime-version: 0.18.0-rc.1`, `ledger-version: ledger-9.1.0.0-rc.3`. It is
|
|
227
|
+
not regenerated by `yarn turbo compact`, so it stays pinned to those versions
|
|
228
|
+
while the repo's own toolchain moves on (`.envrc` now pins
|
|
229
|
+
`COMPACTC_VERSION=0.36.1`, and root `resolutions` pins
|
|
230
|
+
`@midnight-ntwrk/compact-runtime` to `0.21.0` — see "Version pin note"
|
|
231
|
+
below). Its `checkRuntimeVersion('0.18.0-rc.1')` guard therefore rejects the
|
|
232
|
+
repo's current runtime: tests read only its paths and `keys/`, never the module
|
|
233
|
+
itself. Contrast the spike's own artifacts (compiler `0.31.1`, runtime
|
|
234
|
+
`0.16.0`, pre-fork).
|
|
235
|
+
|
|
236
|
+
**PS-schema identity confirmed**: `twin-contract/compiled/compiler/
|
|
237
|
+
contract-info.json`'s `ledger`/`circuits` sections are structurally identical
|
|
238
|
+
to the spike's own compiled counter (`island-3/tests/tester/fixtures/counter/
|
|
239
|
+
out/compiler/contract-info.json`) — same single ledger field
|
|
240
|
+
(`round`, index `0`, exported, storage `Counter`), same single circuit
|
|
241
|
+
(`increment`, impure, proof, no arguments, empty tuple result). Only the
|
|
242
|
+
compiler/language/runtime version numbers differ, as expected for a "compiled
|
|
243
|
+
under the current toolchain" twin.
|
|
244
|
+
|
|
245
|
+
> **That identity does NOT extend to private state, because there is none.**
|
|
246
|
+
> Both sides declare `"witnesses": []`, and witnesses are the only members that
|
|
247
|
+
> read or write private state — so this pair pins the *public* schema and says
|
|
248
|
+
> nothing about a private one. It also cannot execute under this repo's runtime
|
|
249
|
+
> (see the version pin note below). Anything needing real private state, or a
|
|
250
|
+
> current-toolchain build that actually runs, wants
|
|
251
|
+
> [`private-counter-016/` and `private-counter-twin/`](#private-counter-016-and-private-counter-twin)
|
|
252
|
+
> instead.
|
|
253
|
+
|
|
254
|
+
`twin-contract/compiled/keys/increment.verifier` is used as the KNOWN-GOOD
|
|
255
|
+
key in the smoke test, to confirm `state-co-v2-only-foreign.hex`'s embedded
|
|
256
|
+
key is genuinely foreign (see "The mis-dispatch fixture" above) — that
|
|
257
|
+
fixture is NOT keyed with it.
|
|
258
|
+
|
|
259
|
+
## `counter-016/`
|
|
260
|
+
|
|
261
|
+
`counter-016/compiled/contract/index.js` is the spike's own `counter.compact` recompiled
|
|
262
|
+
with the spike's **original, pre-fork toolchain** (`compiler-version: 0.31.1`,
|
|
263
|
+
`language-version: 0.23.0`, `runtime-version: 0.16.0` — from the spike's own
|
|
264
|
+
`island-3/tests/tester/fixtures/counter/out/compiler/contract-info.json`), as
|
|
265
|
+
opposed to `twin-contract/compiled/`, which is the SAME source recompiled with
|
|
266
|
+
a v9-era toolchain (`compactc 0.33.0-rc.2`, `runtime-version:
|
|
267
|
+
0.18.0-rc.1`). The two are not interchangeable: `twin-contract/compiled/` emits
|
|
268
|
+
0.18-era (async) codegen and cannot run against a `compact-runtime@0.16`
|
|
269
|
+
instance; `counter-016/` emits the sync codegen the retained pre-fork engine
|
|
270
|
+
(`packages/protocol/src/lib/v8/executable.ts`) actually exercises, and is the
|
|
271
|
+
fixture `v8-executable.test.ts` runs `increment` against.
|
|
272
|
+
|
|
273
|
+
Ported verbatim (byte-for-byte, only source-map generation trimmed — same
|
|
274
|
+
"drop the map, keep the module minimal" precedent as `twin-contract/`) from
|
|
275
|
+
`spike-dapp-hf/island-3/tests/tester/fixtures/counter/out/contract/index.js`
|
|
276
|
+
(git blob `405a68179e4cfb3fb6307486461df7879ab508f3`). The contract source
|
|
277
|
+
itself is unchanged from `../twin-contract/counter.compact` — a single
|
|
278
|
+
`round: Counter` ledger cell with one nullary circuit `increment()` — so it is
|
|
279
|
+
not duplicated here.
|
|
280
|
+
|
|
281
|
+
Originally only the compiled contract module was ported. The rest of the
|
|
282
|
+
artifact set — `contract/index.d.ts`, `compiler/contract-info.json`, `keys/`
|
|
283
|
+
and `zkir/` — is now generated here rather than ported, because nothing can be
|
|
284
|
+
proved or deployed on a pre-fork chain without the keys, which left the FR8
|
|
285
|
+
end-to-end positive and the AC0 scenario gated at unit tier.
|
|
286
|
+
|
|
287
|
+
**The declaration file IS committed, with one line changed.** `compactc 0.31.1`
|
|
288
|
+
emits `contract/index.d.ts` beside the module; it was left uncommitted until
|
|
289
|
+
#1312, which is the defect that decided the question. `contracts`'s retained-era
|
|
290
|
+
type family is hand-written, and its compile-time tests used a hand-written
|
|
291
|
+
stand-in for this artifact -- a stand-in written in terms of the family, so it
|
|
292
|
+
agreed with the family whatever the family said and could not fail when the two
|
|
293
|
+
drifted. They drifted: `Ledger8CircuitContext` was missing `costModel`, a
|
|
294
|
+
required member of `compact-runtime@0.16`'s `CircuitContext`, and no real
|
|
295
|
+
artifact satisfied `Ledger8Contract` at all. `packages/contracts/src/test/ledger8-fixture-types.ts`
|
|
296
|
+
now imports these declarations instead. The same applies to
|
|
297
|
+
`private-counter-016/`, the only fixture that declares a witness, for the same
|
|
298
|
+
reason one member over.
|
|
299
|
+
|
|
300
|
+
The one change is the import specifier: `@midnight-ntwrk/compact-runtime` ->
|
|
301
|
+
`compact-runtime-ledger8`. It is not cosmetic and it is not optional. The root
|
|
302
|
+
`resolutions` pin the bare name to the CURRENT era (`0.20.0`), so left as
|
|
303
|
+
emitted the declarations would resolve to the wrong runtime's `CircuitContext`.
|
|
304
|
+
That is loud rather than silent -- the conformance assertions in
|
|
305
|
+
`packages/contracts/src/test/typecheck/overloads.test-d.ts` go red -- but it
|
|
306
|
+
fails somewhere that says nothing about a specifier, which is why the rewrite is
|
|
307
|
+
pinned directly. The alias is this
|
|
308
|
+
repo's own install of the same retained `@midnight-ntwrk/compact-runtime@0.16.0`
|
|
309
|
+
(see `packages/protocol/package.json`), which is the only way to name 0.16 here.
|
|
310
|
+
`ledger8-contract.test.ts` asserts both halves of that rewrite on the committed
|
|
311
|
+
bytes.
|
|
312
|
+
|
|
313
|
+
Regenerate with the same toolchain that produced the ported module:
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
cd testkit-js/testkit-js-e2e
|
|
317
|
+
COMPACT_TAG_PREFIX=compactc-v COMPACT_ASSET_PREFIX=compactc_v \
|
|
318
|
+
COMPACT_REPO=LFDT-Minokawa/compact yarn fetch-compactc --version=0.31.1
|
|
319
|
+
COMPACTC_VERSION=0.31.1 yarn run-compactc \
|
|
320
|
+
../../testkit-js/testkit-js/src/fixtures/hf/twin-contract/counter.compact <out>
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
**Provenance is corroborated, not asserted.** The `contract/index.js` that
|
|
324
|
+
command emits is byte-identical to the module ported from the spike (the only
|
|
325
|
+
difference is the trailing `//# sourceMappingURL` comment, which the port
|
|
326
|
+
retains and a fresh compile without map generation does not). So the committed
|
|
327
|
+
artifacts demonstrably belong to the committed module.
|
|
328
|
+
|
|
329
|
+
The keys are 20 KB and the zkir 8 KB, within the minimal-size mandate.
|
|
330
|
+
`coin-receiver-016/` is deliberately left without keys: its ZKIR-v2 prover key
|
|
331
|
+
is **5 MB**, nothing needs it yet, and committing it would blow that mandate for
|
|
332
|
+
no current caller. Regenerate it on demand with the same command against
|
|
333
|
+
`coin-receiver-016/coin-receiver.compact`.
|
|
334
|
+
|
|
335
|
+
**A finding worth carrying (verified 2026-09-07).** Every `compactc` this repo
|
|
336
|
+
can fetch — 0.31.1, 0.33.0 and 0.34.0-rc.0 — emits a **byte-identical** prover
|
|
337
|
+
key, verifier key and zkir for `increment()`: all ZKIR `"version": {"major": 2}`
|
|
338
|
+
under a `midnight:verifier-key[v6]:` envelope. Two consequences. Keep-state is
|
|
339
|
+
helped: key material does not change across the toolchains, so a pre-fork
|
|
340
|
+
contract's preserved key is what a current build would produce anyway. AC3's
|
|
341
|
+
negative is blocked: "a V3 proof fails against a preserved `co.v2` key" cannot
|
|
342
|
+
be built from `twin-contract/` as committed, because its keys are v2 as well.
|
|
343
|
+
Producing a genuine V3 key means running the bundled `zkir-v3 compile` against
|
|
344
|
+
the emitted zkir deliberately; `compactc` alone will not do it.
|
|
345
|
+
`counter-016-artifacts.ut.test.ts` carries this as a canary that goes red if a
|
|
346
|
+
toolchain ever starts emitting V3 by default.
|
|
347
|
+
|
|
348
|
+
None of the generated files are read at import time; the module's only own-time dependency is a bare
|
|
349
|
+
`@midnight-ntwrk/compact-runtime` import, satisfied in tests by redirecting
|
|
350
|
+
that specifier (module-registry-scoped to the one test file that imports this
|
|
351
|
+
fixture) to this repo's own `compact-runtime-ledger8` — the same retained
|
|
352
|
+
`@midnight-ntwrk/compact-runtime@0.16.0`, installed under an alias so it can
|
|
353
|
+
coexist with the root's `0.20.0` pin (see
|
|
354
|
+
`packages/protocol/package.json`).
|
|
355
|
+
|
|
356
|
+
The `compiled/` path segment (mirroring `twin-contract/compiled/`) is not
|
|
357
|
+
cosmetic: `.licenserc.yaml`'s `paths-ignore` excludes `**/compiled/**` from
|
|
358
|
+
the Apache-2.0 license-header check, which this ported-verbatim upstream
|
|
359
|
+
artifact — same as `twin-contract/compiled/contract/index.js` — must not
|
|
360
|
+
carry.
|
|
361
|
+
|
|
362
|
+
`counter-016/increment-transcript.golden.json` is a golden regression
|
|
363
|
+
reference for the transcript `executeCircuit` (`lib/v8/executable.ts`) produces
|
|
364
|
+
when running `increment()` against this contract's freshly-constructed
|
|
365
|
+
initial state (`round: 0`). The spike carries no recorded transcript fixture
|
|
366
|
+
of its own to port, so this one was minted once, directly from
|
|
367
|
+
the retired `v8-execute.test.ts`'s own real execution against this ported artifact
|
|
368
|
+
(no proving involved — circuit execution through `compact-runtime@0.16` is
|
|
369
|
+
fully deterministic), and is committed as JSON with bigints written as
|
|
370
|
+
`` `${n}n` ``-suffixed strings and byte arrays as lower-case hex (the two
|
|
371
|
+
value kinds an `AlignedValue`/`Op` tree carries that JSON has no native
|
|
372
|
+
encoding for). `preContractState`/`postContractState`/`privateStateAfter` are
|
|
373
|
+
excluded from the golden — they carry live `ChargedState` WASM objects, not
|
|
374
|
+
plain data — the transcript's post-state is instead asserted directly in the
|
|
375
|
+
same test via the contract's own `ledger()` projector (`round` goes `0n` →
|
|
376
|
+
`1n`).
|
|
377
|
+
|
|
378
|
+
## `private-counter-016/` and `private-counter-twin/`
|
|
379
|
+
|
|
380
|
+
The **witness-bearing** pair, and the only fixtures here that carry genuine
|
|
381
|
+
private state. `twin-contract/counter.compact` declares **no witness at all**
|
|
382
|
+
(`contract-info.json`'s `witnesses` is `[]`, and so is
|
|
383
|
+
`coin-receiver-016`'s) — witnesses are the only members of a compiled Compact
|
|
384
|
+
contract that read or write private state, so a dApp built on either of them
|
|
385
|
+
holds nothing a private-state continuity test could carry. A round trip driven
|
|
386
|
+
off that pair would be `{}` in, `{}` out.
|
|
387
|
+
|
|
388
|
+
`private-counter-twin/private-counter.compact` is `twin-contract/counter.compact`
|
|
389
|
+
plus one witness:
|
|
390
|
+
|
|
391
|
+
```compact
|
|
392
|
+
export ledger round: Counter;
|
|
393
|
+
|
|
394
|
+
witness localIncrement(): Uint<16>;
|
|
395
|
+
|
|
396
|
+
export circuit increment(): [] {
|
|
397
|
+
round.increment(disclose(localIncrement()));
|
|
398
|
+
}
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
`localIncrement()` reads the step out of the dApp's own private state, so
|
|
402
|
+
executing `increment()` calls the witness, threads the private state through the
|
|
403
|
+
runtime, and lets the witness hand a **new** private state back — which is what
|
|
404
|
+
makes the state a test persists something the retained toolchain really
|
|
405
|
+
produced, rather than the caller's own object passed through by reference (which
|
|
406
|
+
is all `counter-016` can offer, since nothing there ever touches private state).
|
|
407
|
+
|
|
408
|
+
**One source, two builds — this is the point of the pair.** Both were compiled
|
|
409
|
+
from the single committed `.compact` file, with `--skip-zk` (nothing here proves;
|
|
410
|
+
see below):
|
|
411
|
+
|
|
412
|
+
| Directory | Compiler | Language | Runtime | Codegen |
|
|
413
|
+
|---|---|---|---|---|
|
|
414
|
+
| `private-counter-016/compiled/` | 0.31.1 | 0.23.0 | **0.16.0** | sync (retained, pre-fork) |
|
|
415
|
+
| `private-counter-twin/compiled/` | 0.36.1 | 0.28.0 | **0.21.0** | async (current) |
|
|
416
|
+
|
|
417
|
+
The two `contract-info.json` files are **identical apart from those three
|
|
418
|
+
version fields** (plus `compiler-commit`, which compilers from 0.35.0 on add) — same single circuit, same single ledger cell, same single
|
|
419
|
+
witness — which is the machine-checkable form of the "PS-schema-identical twin"
|
|
420
|
+
claim, and is asserted rather than assumed (see below).
|
|
421
|
+
|
|
422
|
+
**Both builds EXECUTE**, and that is the difference from `twin-contract/`. The
|
|
423
|
+
retained build runs against the retained engine
|
|
424
|
+
(`packages/protocol/src/lib/v8/executable.ts`, reached through `loadLedger8Engine()`),
|
|
425
|
+
exactly as `counter-016` does. The twin's declared runtime is **the one this
|
|
426
|
+
repo resolves** (root `resolutions` pins `@midnight-ntwrk/compact-runtime` to
|
|
427
|
+
`0.21.0`), so unlike `twin-contract/` — pinned to `0.18.0-rc.1` and
|
|
428
|
+
therefore refused by its own `checkRuntimeVersion` guard — this twin's module
|
|
429
|
+
can be imported and driven. A cross-window test can consequently hand the
|
|
430
|
+
post-fork build the very private state the pre-fork build wrote and watch it
|
|
431
|
+
read the same meaning out of it.
|
|
432
|
+
|
|
433
|
+
That coupling is committed **as a gate, not as decoration**: the consuming test
|
|
434
|
+
asserts `private-counter-twin`'s declared `runtime-version` equals the runtime
|
|
435
|
+
the repo actually resolves, so bumping `compact-runtime` without recompiling
|
|
436
|
+
this fixture fails with a named assertion instead of a version-mismatch throw
|
|
437
|
+
from deep inside the twin's own module body. The retained side is pinned to the
|
|
438
|
+
literal `0.16.0` for the same reason.
|
|
439
|
+
|
|
440
|
+
Consumed by `testkit-js/testkit-js/test/cross-window.ut.test.ts`, which drives
|
|
441
|
+
one `increment()` on each side of the fork and carries the private state between
|
|
442
|
+
them through a real `LevelPrivateStateProvider`. It lives here rather than beside
|
|
443
|
+
that provider because it needs both compact runtimes in hand at once, and
|
|
444
|
+
`eslint.config.mjs`'s version-identity gate exempts testkit-js for exactly that
|
|
445
|
+
reason while `packages/**` — test files included — is gated.
|
|
446
|
+
|
|
447
|
+
**Deliberately NOT a regeneration of `twin-contract/`.** That fixture's
|
|
448
|
+
`increment.verifier` bytes and its `contract/index.js` / `index.d.ts` are
|
|
449
|
+
consumed as typecheck and known-good-key fixtures across `packages/contracts`
|
|
450
|
+
and `packages/protocol` — `grep -rl twin-contract packages/` answers *how many*
|
|
451
|
+
at the time of asking, and the answer has only ever grown. None of them executes it,
|
|
452
|
+
so its inability to run under 0.20 costs them nothing, while recompiling it
|
|
453
|
+
would change the key bytes and the codegen shape underneath all of them. It is
|
|
454
|
+
left exactly as it is.
|
|
455
|
+
|
|
456
|
+
**What is committed, and what is not.** `contract/index.js` and
|
|
457
|
+
`compiler/contract-info.json` on both sides, plus `contract/index.d.ts` on the
|
|
458
|
+
RETAINED side only — the same set `counter-016/` and `coin-receiver-016/` carry,
|
|
459
|
+
and for the same reason: `packages/contracts` types its retained-era fixtures
|
|
460
|
+
from it, and this is the only fixture that declares a WITNESS. It carries the
|
|
461
|
+
same one-line specifier rewrite as the other two. The current-toolchain side
|
|
462
|
+
needs none, since nothing types a fixture from it. No `keys/`, no `zkir/`, no
|
|
463
|
+
`contract-manifest.json`: nothing here
|
|
464
|
+
proves, so proving keys would be dead weight, and only the newer compiler emits
|
|
465
|
+
a manifest, so committing one would break the pair's symmetry for a file nothing
|
|
466
|
+
reads.
|
|
467
|
+
|
|
468
|
+
`index.js` is committed verbatim **except for its trailing
|
|
469
|
+
`//# sourceMappingURL=index.js.map` line, which is deleted** — the one departure
|
|
470
|
+
from the older fixtures, and a deliberate one. Those keep the line with no
|
|
471
|
+
`.js.map` beside it, which makes Vitest print a red `ENOENT ... index.js.map`
|
|
472
|
+
block on every run that imports them; two more of those, in a suite whose output
|
|
473
|
+
is otherwise clean, reads like a failure in a CI log. Deleting exactly that one
|
|
474
|
+
line is the same trim `twin-contract/`'s recipe already applies to the `.js.map`
|
|
475
|
+
file itself, and it costs nothing: a recompile still diffs against the committed
|
|
476
|
+
artifact with that single line as the only difference, which is the property the
|
|
477
|
+
"byte-verbatim" rule was protecting.
|
|
478
|
+
|
|
479
|
+
**A consumer who wants to RUN these needs the runtime.** The fixture tree ships
|
|
480
|
+
with `@midnightntwrk/testkit-js`, but `@midnight-ntwrk/compact-runtime` is a
|
|
481
|
+
devDependency of that package, not a dependency — so importing either
|
|
482
|
+
`contract/index.js` from an installed copy fails to resolve its own
|
|
483
|
+
`@midnight-ntwrk/compact-runtime` import unless the consumer has one in their own
|
|
484
|
+
tree. That is true of every compiled contract here; it matters for this pair
|
|
485
|
+
first, because it is the only one a consumer would plausibly want to execute
|
|
486
|
+
rather than read. The retained side additionally needs a real 0.16 instance,
|
|
487
|
+
which no consumer resolves from that specifier by default — see the redirect the
|
|
488
|
+
consuming test uses.
|
|
489
|
+
|
|
490
|
+
The `compiled/` path segment matters for the same reason it does elsewhere:
|
|
491
|
+
`.licenserc.yaml`'s `paths-ignore` excludes `**/compiled/**` from the Apache-2.0
|
|
492
|
+
header check, which generated code must not carry. The `.compact` source carries
|
|
493
|
+
no header either — `.licenserc.yaml`'s `paths` does not list `**/*.compact`, and
|
|
494
|
+
neither `counter.compact` nor `coin-receiver.compact` carries one.
|
|
495
|
+
|
|
496
|
+
**Not in `fixtures.json`, on purpose.** The manifest covers the nine `.hex`
|
|
497
|
+
state fixtures and nothing else, and `fixtures-hf.ts` validates its key set
|
|
498
|
+
against `HF_FIXTURE_NAMES` at import — so adding a contract directory to it
|
|
499
|
+
would fail every consumer at load. Compiled contract fixtures are documented
|
|
500
|
+
here and reached by path through `hfFixturePath`, exactly as `counter-016/`,
|
|
501
|
+
`twin-contract/` and `coin-receiver-016/` are.
|
|
502
|
+
|
|
503
|
+
**Keep the source file's name.** The generated code bakes `private-counter.compact`
|
|
504
|
+
into the witness's own type-error messages, with line numbers; renaming or
|
|
505
|
+
reflowing the source without recompiling both builds would leave those messages
|
|
506
|
+
pointing at the wrong place. The consuming test pins the source's SHA-256, so
|
|
507
|
+
editing it without recompiling fails there with the regeneration recipe named in
|
|
508
|
+
the failure message — the version gates only compare the two builds to each
|
|
509
|
+
other and cannot see a source that has moved out from under both of them.
|
|
510
|
+
|
|
511
|
+
`private-counter-016/` carries a short `README.md` of its own pointing back at
|
|
512
|
+
that shared source, since nothing else in that directory says where its contents
|
|
513
|
+
came from.
|
|
514
|
+
|
|
515
|
+
## `pre-fork-private-state-store/`
|
|
516
|
+
|
|
517
|
+
A small LevelDB database written by this repo's own private-state provider and
|
|
518
|
+
then **frozen** — the one fixture here that is not about the ledger's schema at
|
|
519
|
+
all, but about the envelope private state is stored IN.
|
|
520
|
+
|
|
521
|
+
Why it exists: every other private-state round trip in this repo writes and
|
|
522
|
+
reads with the same build, in the same process. A change to the persistence
|
|
523
|
+
envelope — superjson's encoding, the AES framing, the PBKDF2 parameters, the
|
|
524
|
+
salt record — moves both halves of such a round trip together, so the suite
|
|
525
|
+
stays green while every store an earlier release wrote becomes unreadable. This
|
|
526
|
+
is measured, not asserted: with the KDF iteration count changed by one, the
|
|
527
|
+
provider's own unit suite passes clean and only the test that reads these
|
|
528
|
+
frozen bytes fails.
|
|
529
|
+
|
|
530
|
+
| File | What it is |
|
|
531
|
+
|---|---|
|
|
532
|
+
| `store/` | The database. As committed: `CURRENT`, `MANIFEST-000004`, `000005.ldb`, `000006.log`, about 1.3 KB — but LevelDB picks its own file names and count, so a re-mint will differ. `LOCK`/`LOG`/`LOG.old` are runtime files, are `.gitignore`d, and are not committed. |
|
|
533
|
+
| `ENVELOPE.md` | The generation log, and the rules for changing it. Read it before touching anything here. |
|
|
534
|
+
|
|
535
|
+
One private state, under one contract address and state id, holding a bigint, a
|
|
536
|
+
`Uint8Array` and a `Map` — the three kinds JSON cannot carry, which is what makes
|
|
537
|
+
a decode regression visible. Nothing more: this is a fixture, not a corpus.
|
|
538
|
+
|
|
539
|
+
**Everything in it is synthetic and it is safe to publish.** The password is the
|
|
540
|
+
consuming suite's own fixed test constant, committed in plain sight next to the
|
|
541
|
+
ciphertext; `secretKey` is the bytes `0x00..0x1f` in order; the nullifiers are
|
|
542
|
+
two made-up strings; the salt was minted for this fixture alone. There is no key
|
|
543
|
+
material here that means anything outside this suite. It is not a captured
|
|
544
|
+
artifact from any wallet, and its password must not be copied anywhere.
|
|
545
|
+
|
|
546
|
+
**Regenerating it is how you ACCEPT a break, not how you fix a red test.** If
|
|
547
|
+
the consuming test fails against these bytes, the finding is that this checkout
|
|
548
|
+
can no longer read private state an earlier release wrote — a dApp user's own
|
|
549
|
+
state, unreadable after an upgrade. Re-minting makes the failure disappear along
|
|
550
|
+
with the evidence. `ENVELOPE.md` sets out what accepting the break requires, and
|
|
551
|
+
the suite enforces the part that can be enforced: it compares the digest recorded
|
|
552
|
+
in that note with the bytes on disk, so a regeneration that does not record a new
|
|
553
|
+
generation fails. `generators/mint-pre-fork-store.mjs` is deliberately **not**
|
|
554
|
+
wired into `generate-all.mjs`, so nothing re-mints it as a side effect of
|
|
555
|
+
regenerating something else.
|
|
556
|
+
|
|
557
|
+
Read by `testkit-js/testkit-js/test/cross-window.ut.test.ts`, which copies
|
|
558
|
+
`store/` to a temporary directory first — LevelDB writes `LOCK` and `LOG` into
|
|
559
|
+
any directory it opens, and the fixture has to stay untouched.
|
|
560
|
+
|
|
561
|
+
## `coin-receiver-016/`
|
|
562
|
+
|
|
563
|
+
The one thing `counter-016/` cannot exercise: a circuit that **receives a
|
|
564
|
+
shielded coin in-contract**. Twelve lines of Compact
|
|
565
|
+
(`coin-receiver.compact`) — `receiveShielded(coin)` followed by
|
|
566
|
+
`pot.writeCoin(coin, kernel.self())` into a `QualifiedShieldedCoinInfo` cell.
|
|
567
|
+
|
|
568
|
+
That shape is the point, not the contract. Receiving registers the coin's
|
|
569
|
+
commitment with the runtime; writing it back has to *qualify* the coin, which
|
|
570
|
+
needs the INDEX that commitment was recorded at. So a transcript from this
|
|
571
|
+
circuit **cannot be partitioned** unless the commitment indices the runtime
|
|
572
|
+
recorded travel with the call — which is what
|
|
573
|
+
`packages/protocol/src/test/era-partition-received-coin.test.ts` asserts, in
|
|
574
|
+
both directions, on both eras. `counter-016` moves no coins and reaches none
|
|
575
|
+
of it.
|
|
576
|
+
|
|
577
|
+
Deliberately NOT the spike's `micro-dao` (`island-3/driver/src/contracts/micro-dao/`),
|
|
578
|
+
which has the same receive path inside a 239 KB, 11-circuit artifact with
|
|
579
|
+
witnesses, a Merkle tree, minting and voting phases — none of which this
|
|
580
|
+
tests. This fixture is 26 KB and its source is readable in one screen.
|
|
581
|
+
|
|
582
|
+
**Compiled in this repo, not ported** — the one provenance difference from
|
|
583
|
+
`counter-016/`. The `compact` toolchain manager offers the same compiler the
|
|
584
|
+
spike used, so there was nothing to port:
|
|
585
|
+
|
|
586
|
+
```
|
|
587
|
+
compact compile --skip-zk \
|
|
588
|
+
testkit-js/testkit-js/src/fixtures/hf/coin-receiver-016/coin-receiver.compact \
|
|
589
|
+
<tmpdir>
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
with `compact` on version **0.31.1**, which reports `language-version 0.23.0`
|
|
593
|
+
and `runtime-version 0.16.0` — the same toolchain triple as `counter-016/`
|
|
594
|
+
(and as the spike's own DAO artifact). `contract/index.js`,
|
|
595
|
+
`contract/index.d.ts` and `compiler/contract-info.json` are committed: no
|
|
596
|
+
`keys/`, no `zkir/` (nothing here proves, and the call's key location hashes
|
|
597
|
+
whichever registered key the test supplies — `twin-contract`'s
|
|
598
|
+
`increment.verifier`). The declaration carries the same one-line specifier
|
|
599
|
+
rewrite as `counter-016/`'s, for the same reason.
|
|
600
|
+
|
|
601
|
+
`compiler/contract-info.json` is committed **as a gate, not as decoration**:
|
|
602
|
+
the test asserts `runtime-version: 0.16.0` and `compiler-version: 0.31.1` on
|
|
603
|
+
it, so a recompile with the repo's own pinned `compactc` (0.35.x → runtime
|
|
604
|
+
0.20, async codegen) fails loudly instead of silently producing an artifact
|
|
605
|
+
that never reaches the code under test.
|
|
606
|
+
|
|
607
|
+
The artifact is committed byte-verbatim, including its trailing
|
|
608
|
+
`//# sourceMappingURL=index.js.map` line with no `.js.map` beside it — same as
|
|
609
|
+
`counter-016/`, so a recompile can be diffed against it directly. That line
|
|
610
|
+
makes Vitest print a "could not read map file" block on any run that imports the
|
|
611
|
+
artifact; nothing imports it in this package's own unit suite, so testkit's
|
|
612
|
+
output is clean, and it shows up wherever the artifact is actually driven. No
|
|
613
|
+
list of those places is given here on purpose — the claim this paragraph
|
|
614
|
+
replaced named a count, went stale, and its replacement named one package and
|
|
615
|
+
went stale again. `grep -rl 'counter-016' packages/` answers it at the time of
|
|
616
|
+
asking. The `private-counter` pair deletes that line instead — see its section
|
|
617
|
+
above for why the two differ.
|
|
618
|
+
|
|
619
|
+
The `compiled/` path segment matters for the same reason it does under
|
|
620
|
+
`counter-016/`: `.licenserc.yaml`'s `paths-ignore` excludes `**/compiled/**`
|
|
621
|
+
from the Apache-2.0 header check, which generated code must not carry.
|
|
622
|
+
|
|
623
|
+
### The three recorded `coin-receiver-016` fixtures
|
|
624
|
+
|
|
625
|
+
Three fixtures were added beside the compiled artifact so that a **coin-moving
|
|
626
|
+
call can be driven without a retained runtime**. They are minted, and on every
|
|
627
|
+
run re-verified against a live execution, by
|
|
628
|
+
`packages/protocol/src/test/era-record-coin-receiver.test.ts` — the same
|
|
629
|
+
provenance pattern as `counter-016/increment-transcript.golden.json`, which was
|
|
630
|
+
itself minted from the retired `v8-execute.test.ts`'s own real execution.
|
|
631
|
+
|
|
632
|
+
| File | What it is |
|
|
633
|
+
|---|---|
|
|
634
|
+
| `coin-receiver-016/receive-coin-transcript.recording.json` | The `TranscriptPojo` the real `compact-runtime@0.16` runtime produces for `receive_coin`, with the state it ran against. Values are TAGGED — `{"__bigint"}`, `{"__bytes"}` (lower-case hex), `{"__map"}` — because unlike the counter golden this recording is *decoded* and fed back to a real ledger, and `partitionContext.block.parentBlockHash` is a genuine hex string sitting beside genuine byte arrays. |
|
|
635
|
+
| `coin-receiver-016/state-v6-envelope.hex` | A real retained-era `ContractState` (`contract-state[v6]`) whose `.data` is the state that same constructor built, with `receive_coin` registered. The state a pre-fork call is dispatched against. |
|
|
636
|
+
| `coin-receiver-016/state-v9.hex` | The same primary state as a current-era `ContractState` (`contract-state[v8]`), with `receive_coin` registered. The state a post-fork keep-state call is dispatched against. |
|
|
637
|
+
|
|
638
|
+
Neither `.hex` is reachable through `readHfFixture` — that accessor covers the
|
|
639
|
+
nine top-level state fixtures. Reach these by path, through `hfFixturePath`.
|
|
640
|
+
|
|
641
|
+
> **The recording substitutes NO members.** It used to freeze
|
|
642
|
+
> `partitionContext.block.secondsSinceEpoch` and `.lastBlockTime`, because the
|
|
643
|
+
> glue stamped the wall clock when a circuit context was built and the engine
|
|
644
|
+
> took no clock — so a recording that kept them would have been a different file
|
|
645
|
+
> on every run. `executeCircuit` now takes the execution clock as an input
|
|
646
|
+
> (`Ledger8CircuitOptions.nowSeconds`), so the recording is the runtime's own
|
|
647
|
+
> output end to end. The minting suite asserts that it matches a live execution,
|
|
648
|
+
> and that it still composes on **both** eras.
|
|
649
|
+
|
|
650
|
+
> **THE VERIFIER KEY IN BOTH ENVELOPES IS A STAND-IN, AND IT IS NOT THE COIN
|
|
651
|
+
> RECEIVER'S KEY.** `coin-receiver-016` ships no `keys/` — nothing in this repo
|
|
652
|
+
> proves against it — so both envelopes register
|
|
653
|
+
> `twin-contract/compiled/keys/increment.verifier` under `receive_coin`. That
|
|
654
|
+
> key belongs to a **different circuit**. It is used only because a
|
|
655
|
+
> `ContractOperation`'s setter validates a real, tagged verifier-key blob and
|
|
656
|
+
> rejects arbitrary bytes, so the slot cannot be filled with a placeholder. Any
|
|
657
|
+
> pre-proving key check driven off these fixtures therefore passes **only
|
|
658
|
+
> because both sides of the comparison use the same stand-in**: it exercises the
|
|
659
|
+
> check as wiring and says nothing about this circuit's real key. Do not read
|
|
660
|
+
> these envelopes as carrying a genuine `receive_coin` key, and do not use them
|
|
661
|
+
> to argue anything about key provenance. Contrast
|
|
662
|
+
> `state-co-v2-only-foreign.hex`, which wears a foreign key deliberately in
|
|
663
|
+
> order to FAIL.
|
|
664
|
+
|
|
665
|
+
## Regenerating
|
|
666
|
+
|
|
667
|
+
```
|
|
668
|
+
node testkit-js/testkit-js/src/fixtures/hf/generators/generate-all.mjs
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
To regenerate the three recorded `coin-receiver-016` fixtures (they are minted
|
|
672
|
+
from a real execution inside a test, not by a generator script — see their
|
|
673
|
+
section above):
|
|
674
|
+
|
|
675
|
+
```
|
|
676
|
+
MINT_HF_FIXTURES=1 yarn --cwd packages/protocol vitest run src/test/era-record-coin-receiver.test.ts
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
runs every mint/derive script and overwrites the seven non-golden `.hex`
|
|
680
|
+
files in place. `state-v8-v6-envelope.hex` and `state-migrated-v9.hex` have no
|
|
681
|
+
generator (there is nothing to regenerate — they are golden ports); to update
|
|
682
|
+
them, re-copy from a newer spike checkout and re-run
|
|
683
|
+
`generate-all.mjs` (the tamper/derive scripts read the goldens back in, so
|
|
684
|
+
they stay consistent automatically).
|
|
685
|
+
|
|
686
|
+
To recompile `coin-receiver-016/` (needs the retained-era compiler — see its
|
|
687
|
+
section above for why the version is not negotiable):
|
|
688
|
+
|
|
689
|
+
```
|
|
690
|
+
compact list # 0.31.1 must be installed
|
|
691
|
+
compact compile --skip-zk testkit-js/testkit-js/src/fixtures/hf/coin-receiver-016/coin-receiver.compact /tmp/coin-receiver-out
|
|
692
|
+
cp /tmp/coin-receiver-out/contract/index.js testkit-js/testkit-js/src/fixtures/hf/coin-receiver-016/compiled/contract/
|
|
693
|
+
cp /tmp/coin-receiver-out/compiler/contract-info.json testkit-js/testkit-js/src/fixtures/hf/coin-receiver-016/compiled/compiler/
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
To recompile `twin-contract/`:
|
|
697
|
+
|
|
698
|
+
```
|
|
699
|
+
yarn fetch-compactc # from packages/contracts/, once, if packages/compact isn't built yet — run `yarn turbo run build --filter=@midnightntwrk/midnight-js-compact` first
|
|
700
|
+
node packages/compact/dist/run-compactc.cjs testkit-js/testkit-js/src/fixtures/hf/twin-contract/counter.compact testkit-js/testkit-js/src/fixtures/hf/twin-contract/compiled
|
|
701
|
+
rm testkit-js/testkit-js/src/fixtures/hf/twin-contract/compiled/contract/index.js.map # trim: not needed, keeps the fixture minimal
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
To recompile the `private-counter` pair — **both sides, from the one source,
|
|
705
|
+
always together**, or the pair stops being a pair:
|
|
706
|
+
|
|
707
|
+
```
|
|
708
|
+
compact list # 0.31.1 must be installed, for the retained side
|
|
709
|
+
# The retained side comes from a `compact`-installed toolchain; the current side
|
|
710
|
+
# comes from the one THIS REPO pins (`.envrc`'s COMPACTC_VERSION), because that
|
|
711
|
+
# is the version whose `runtime-version` the consuming test gates on. Fetch it
|
|
712
|
+
# once, from packages/contracts/, if packages/compact/managed/ has no such
|
|
713
|
+
# directory yet:
|
|
714
|
+
# yarn fetch-compactc
|
|
715
|
+
# The `*` is the platform triple `compact` installs under.
|
|
716
|
+
SRC=testkit-js/testkit-js/src/fixtures/hf/private-counter-twin/private-counter.compact
|
|
717
|
+
DST=testkit-js/testkit-js/src/fixtures/hf
|
|
718
|
+
~/.compact/versions/0.31.1/*/compactc --skip-zk $SRC /tmp/private-counter-016
|
|
719
|
+
packages/compact/managed/0.36.1/compactc --skip-zk $SRC /tmp/private-counter-cur
|
|
720
|
+
cp /tmp/private-counter-016/contract/index.js $DST/private-counter-016/compiled/contract/
|
|
721
|
+
cp /tmp/private-counter-016/compiler/contract-info.json $DST/private-counter-016/compiled/compiler/
|
|
722
|
+
cp /tmp/private-counter-cur/contract/index.js $DST/private-counter-twin/compiled/contract/
|
|
723
|
+
cp /tmp/private-counter-cur/compiler/contract-info.json $DST/private-counter-twin/compiled/compiler/
|
|
724
|
+
# Drop the trailing map comment from both -- see "What is committed" above.
|
|
725
|
+
perl -0pi -e 's{\n?//\# sourceMappingURL=index\.js\.map\n?\z}{\n}' \
|
|
726
|
+
$DST/private-counter-016/compiled/contract/index.js \
|
|
727
|
+
$DST/private-counter-twin/compiled/contract/index.js
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
The current-side compiler is whichever one emits the `runtime-version` the repo
|
|
731
|
+
resolves; the repo-pinned `0.36.1` is the one that emits `0.21.0` today, and the
|
|
732
|
+
consuming test asserts that coupling, so a mismatch is caught rather than
|
|
733
|
+
discovered at import. Beware the near-miss: `compact`'s own `0.34.0` install
|
|
734
|
+
directory carries an `-rc.0` suffix and emits `0.19.0-rc.0`, which the gate
|
|
735
|
+
rejects -- take the current side from `packages/compact/managed/` rather than
|
|
736
|
+
from `~/.compact/versions/`. Do not copy `index.js.map` or `zkir/` across: neither
|
|
737
|
+
is committed.
|
|
738
|
+
|
|
739
|
+
To re-mint `pre-fork-private-state-store/` — **read
|
|
740
|
+
`pre-fork-private-state-store/ENVELOPE.md` first.** Doing this is a decision to
|
|
741
|
+
let private state written by earlier releases stop being readable, not a way to
|
|
742
|
+
clear a red test, which is why it is not part of `generate-all.mjs`:
|
|
743
|
+
|
|
744
|
+
```
|
|
745
|
+
cd testkit-js/testkit-js
|
|
746
|
+
# Without the flag the script refuses and changes nothing. It verifies it can
|
|
747
|
+
# read the state back before the bytes become a fixture, removes LevelDB's
|
|
748
|
+
# runtime files (LOCK/LOG/LOG.old -- but NOT the numbered NNNNNN.log, which is
|
|
749
|
+
# the write-ahead log and holds the state), and prints the digest to record.
|
|
750
|
+
node src/fixtures/hf/generators/mint-pre-fork-store.mjs --accept-envelope-break
|
|
751
|
+
# then add a generation section to ENVELOPE.md -- at the TOP, above the existing
|
|
752
|
+
# ones -- recording that digest and what the break means for a user holding an
|
|
753
|
+
# older store. The suite reads the FIRST recorded digest and compares it with
|
|
754
|
+
# the bytes, so this step cannot be skipped and the section cannot go at the end.
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
## Version pin note (deviation from the brief, with evidence)
|
|
758
|
+
|
|
759
|
+
The brief asked for `@midnightntwrk/ledger-v8` **and**
|
|
760
|
+
`@midnight-ntwrk/onchain-runtime-v3`/`compact-runtime@0.16.0` as
|
|
761
|
+
`testkit-js/testkit-js` devDependencies, to mint the v6/v8-envelope fixtures
|
|
762
|
+
directly on the 0.16 stack. This repo's root `package.json` `resolutions`
|
|
763
|
+
already pins `@midnight-ntwrk/compact-runtime` to `0.21.0` repo-wide —
|
|
764
|
+
installing `0.16.0` alongside it would be silently overridden by Yarn's
|
|
765
|
+
resolution, not actually give a 0.16 runtime. Since mint-path (b) already
|
|
766
|
+
supplied both fixtures that would have needed the 0.16 stack (as goldens),
|
|
767
|
+
`compact-runtime@0.16.0` / `onchain-runtime-v3` were never added as
|
|
768
|
+
dependencies here — only `@midnightntwrk/ledger-v8@8.1.2` and
|
|
769
|
+
`@midnightntwrk/ledger-v9@1.0.0-rc.3` (the latter already pinned by the root
|
|
770
|
+
`resolutions`) were added, and both are the only packages any generator here
|
|
771
|
+
actually imports.
|
|
772
|
+
|
|
773
|
+
## npm/registry note
|
|
774
|
+
|
|
775
|
+
The user's global `~/.npmrc` routes `@midnight-ntwrk` and `@midnightntwrk` to
|
|
776
|
+
GitHub Packages with tokens that may not resolve public npm packages. This
|
|
777
|
+
repo uses **Yarn Berry** (`nodeLinker: node-modules`), which ignores
|
|
778
|
+
`~/.npmrc` entirely and uses `.yarnrc.yml` instead. `.yarnrc.yml` declares
|
|
779
|
+
no scope registry, so both `@midnight-ntwrk/*` and `@midnightntwrk/*`
|
|
780
|
+
packages resolve from the default public registry (npmjs) without any
|
|
781
|
+
`.npmrc`/`.yarnrc.yml` change.
|