@gmitch215/folio 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +398 -28
- package/dist/affine-state.d.ts +171 -0
- package/dist/affine-state.js +763 -0
- package/dist/affine.d.ts +160 -0
- package/dist/affine.js +571 -0
- package/dist/boundaries.d.ts +59 -0
- package/dist/boundaries.js +127 -0
- package/dist/certified.d.ts +66 -0
- package/dist/certified.js +192 -0
- package/dist/certify.d.ts +98 -0
- package/dist/certify.js +2628 -0
- package/dist/context.d.ts +16 -2
- package/dist/context.js +60 -14
- package/dist/coordinator.js +50 -3
- package/dist/extract.d.ts +19 -0
- package/dist/extract.js +133 -5
- package/dist/fold.d.ts +32 -0
- package/dist/fold.js +105 -0
- package/dist/frames.d.ts +5 -1
- package/dist/frames.js +156 -9
- package/dist/inline.d.ts +114 -0
- package/dist/inline.js +276 -13
- package/dist/iteration-admission.d.ts +116 -7
- package/dist/iteration-admission.js +137 -8
- package/dist/iteration-layout.d.ts +60 -0
- package/dist/iteration-layout.js +54 -3
- package/dist/iteration-owner.d.ts +14 -1
- package/dist/iteration-owner.js +2 -2
- package/dist/iteration-worker.js +124 -58
- package/dist/iteration.d.ts +179 -13
- package/dist/iteration.js +845 -70
- package/dist/lease.d.ts +45 -0
- package/dist/lease.js +274 -0
- package/dist/managed.d.ts +72 -0
- package/dist/managed.js +425 -27
- package/dist/memo.d.ts +99 -0
- package/dist/memo.js +250 -0
- package/dist/node.d.ts +43 -1
- package/dist/node.js +87 -11
- package/dist/ownership-redirect.d.ts +30 -0
- package/dist/ownership-redirect.js +179 -0
- package/dist/ownership-slices.d.ts +44 -0
- package/dist/ownership-slices.js +72 -0
- package/dist/ownership.d.ts +161 -0
- package/dist/ownership.js +6568 -0
- package/dist/ranges.d.ts +78 -0
- package/dist/ranges.js +263 -0
- package/dist/read-scan.d.ts +18 -0
- package/dist/read-scan.js +94 -0
- package/dist/read-windows.d.ts +103 -0
- package/dist/read-windows.js +244 -0
- package/dist/router-worker.d.ts +1 -0
- package/dist/router-worker.js +4 -0
- package/dist/router.d.ts +203 -0
- package/dist/router.js +667 -0
- package/dist/runs.d.ts +44 -0
- package/dist/runs.js +182 -0
- package/dist/slices-worker.d.ts +1 -0
- package/dist/slices-worker.js +38 -0
- package/dist/slices.d.ts +126 -0
- package/dist/slices.js +441 -0
- package/dist/tasks.d.ts +14 -4
- package/dist/tasks.js +12 -11
- package/dist/transaction.d.ts +10 -0
- package/package.json +40 -4
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { type AffineCheck, type AffineRing } from './affine.ts';
|
|
2
|
+
import { type FoldChunk } from './fold.ts';
|
|
3
|
+
import { type TaskLink, type TaskPool } from './tasks.ts';
|
|
4
|
+
/** Where the probe puts the context and the data in the kernel's linear memory. */
|
|
5
|
+
export declare const CONTEXT_ADDRESS: number;
|
|
6
|
+
export declare const DATA_ADDRESS: number;
|
|
7
|
+
/** Where the context pointer, the data pointer and the length sit in the entry's parameters. */
|
|
8
|
+
export interface ContextLayout {
|
|
9
|
+
entry: string;
|
|
10
|
+
ctx: number;
|
|
11
|
+
ptr: number;
|
|
12
|
+
len: number;
|
|
13
|
+
/** Bytes of the context the probe examines and every task copies. At most 256. */
|
|
14
|
+
window: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* What a worker needs to run a context kernel: the module, the parameter layout, the context image
|
|
18
|
+
* the caller initialised, and which bytes of it are state. Every other byte of the image is held at
|
|
19
|
+
* its value in `context`.
|
|
20
|
+
*/
|
|
21
|
+
export interface ContextSubject {
|
|
22
|
+
module: WebAssembly.Module | Uint8Array;
|
|
23
|
+
layout: ContextLayout;
|
|
24
|
+
context: Uint8Array;
|
|
25
|
+
state: number[];
|
|
26
|
+
}
|
|
27
|
+
/** One independent part of the state vector, with the ring it is affine over. */
|
|
28
|
+
export interface StateFactor {
|
|
29
|
+
ring: AffineRing;
|
|
30
|
+
/** Context offsets of the bytes of this factor, ascending. */
|
|
31
|
+
offsets: number[];
|
|
32
|
+
/** Positions of those bytes in the state vector of the model. */
|
|
33
|
+
slots: number[];
|
|
34
|
+
wordBytes: number;
|
|
35
|
+
endian: 'le' | 'be';
|
|
36
|
+
words: number;
|
|
37
|
+
/** Bits per word. For `gf2` it is the width of the whole factor. */
|
|
38
|
+
bits: number;
|
|
39
|
+
/** `gf2`: the columns of the one-unit bit matrix. `z2w`: the words x words matrix over Z/2^bits. */
|
|
40
|
+
operator: bigint[] | bigint[][];
|
|
41
|
+
}
|
|
42
|
+
export interface StateCheck extends AffineCheck {
|
|
43
|
+
/** Index of the factor, or -1 for a check on the whole context. */
|
|
44
|
+
factor: number;
|
|
45
|
+
shape: string;
|
|
46
|
+
}
|
|
47
|
+
/** The recovered model of a state vector that lives in the context. */
|
|
48
|
+
export interface StateModel {
|
|
49
|
+
kind: 'state';
|
|
50
|
+
layout: ContextLayout;
|
|
51
|
+
/** The context image the probe ran from. Bytes that are not state stay at these values. */
|
|
52
|
+
context: Uint8Array;
|
|
53
|
+
/** Context offsets of the state: bytes that a call both reads and writes. */
|
|
54
|
+
state: number[];
|
|
55
|
+
/** Bytes a call reads and never writes, and that change the result. Held at `context`. */
|
|
56
|
+
params: number[];
|
|
57
|
+
/** Bytes a call writes and never reads. They are not state and are not carried. */
|
|
58
|
+
scratch: number[];
|
|
59
|
+
factors: StateFactor[];
|
|
60
|
+
align: number;
|
|
61
|
+
checks: StateCheck[];
|
|
62
|
+
calls: number;
|
|
63
|
+
}
|
|
64
|
+
export interface StateRefusal {
|
|
65
|
+
kind: 'refusal';
|
|
66
|
+
reason: string;
|
|
67
|
+
checks: StateCheck[];
|
|
68
|
+
calls: number;
|
|
69
|
+
}
|
|
70
|
+
export interface StateProbeOptions {
|
|
71
|
+
/** Seed of the PRNG. The default is fixed. */
|
|
72
|
+
seed?: number;
|
|
73
|
+
/** Trials per check. The default is 32. */
|
|
74
|
+
trials?: number;
|
|
75
|
+
/** Every probed data length is a multiple of this. */
|
|
76
|
+
align?: number;
|
|
77
|
+
/** The context image as the caller's init function left it. The default is zeros. */
|
|
78
|
+
context?: Uint8Array;
|
|
79
|
+
/** Bytes of the context to examine, at most 256. The default is 256. */
|
|
80
|
+
window?: number;
|
|
81
|
+
}
|
|
82
|
+
export interface StateFoldOptions {
|
|
83
|
+
/** The state vector before the first byte. The default is the state bytes of `model.context`. */
|
|
84
|
+
initial?: Uint8Array;
|
|
85
|
+
chunks?: FoldChunk[];
|
|
86
|
+
}
|
|
87
|
+
export interface StateFoldResult {
|
|
88
|
+
state: Uint8Array;
|
|
89
|
+
chunks: number;
|
|
90
|
+
tasks: number;
|
|
91
|
+
validated: number;
|
|
92
|
+
mismatchAt: number;
|
|
93
|
+
fallbackBytes: number;
|
|
94
|
+
}
|
|
95
|
+
/** One private instance of a context kernel: put and get bytes, call it, count the calls. */
|
|
96
|
+
export declare class ContextKernel {
|
|
97
|
+
#private;
|
|
98
|
+
readonly arity: number;
|
|
99
|
+
readonly entry: string;
|
|
100
|
+
calls: number;
|
|
101
|
+
constructor(module: WebAssembly.Module | Uint8Array, entry: string);
|
|
102
|
+
/** Puts the memory back to what it was after instantiation. */
|
|
103
|
+
restore(): void;
|
|
104
|
+
put(at: number, bytes: Uint8Array): void;
|
|
105
|
+
get(at: number, length: number): Uint8Array;
|
|
106
|
+
raw(args: (number | bigint)[]): number | bigint;
|
|
107
|
+
/** Copies of every byte of memory outside the given ranges, for the hidden state check. */
|
|
108
|
+
outside(ranges: [number, number][]): Uint8Array;
|
|
109
|
+
/**
|
|
110
|
+
* One call: the context image at the context address, the data at the data address. Returns the
|
|
111
|
+
* context window afterwards, or undefined when the kernel traps.
|
|
112
|
+
*/
|
|
113
|
+
run(layout: ContextLayout, image: Uint8Array, data: Uint8Array): Uint8Array | undefined;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The context image after one call of an init function, for a subject whose state starts from
|
|
117
|
+
* something other than zeros. `args` gets the context address; `inputs` is placed at the data
|
|
118
|
+
* address first, for init functions that take a key or an IV.
|
|
119
|
+
*/
|
|
120
|
+
export declare function initialContext(module: WebAssembly.Module | Uint8Array, entry: string, args: (ctx: number, data: number) => (number | bigint)[], inputs?: Uint8Array, window?: number): Uint8Array;
|
|
121
|
+
/** A subject whose state is the whole window, for chains with no model. */
|
|
122
|
+
export declare function contextSubject(module: WebAssembly.Module | Uint8Array, entry: string, context: Uint8Array, layout?: Partial<ContextLayout>): ContextSubject;
|
|
123
|
+
/** The subject a model describes, for `serveContext`. */
|
|
124
|
+
export declare function modelSubject(module: WebAssembly.Module | Uint8Array, model: StateModel): ContextSubject;
|
|
125
|
+
export declare const pick: (image: Uint8Array, offsets: number[]) => Uint8Array;
|
|
126
|
+
export declare function toHex(bytes: Uint8Array): string;
|
|
127
|
+
export declare function fromHex(hex: string): Uint8Array;
|
|
128
|
+
export declare const bytesEqual: (a: Uint8Array, b: Uint8Array) => boolean;
|
|
129
|
+
/**
|
|
130
|
+
* The state vector after a chunk of `length` bytes from `start`, given `offset`, the state vector
|
|
131
|
+
* after the same chunk from zero: A(length) start + offset, factor by factor. `length` must be a
|
|
132
|
+
* multiple of `model.align`.
|
|
133
|
+
*/
|
|
134
|
+
export declare function predictState(model: Pick<StateModel, 'factors' | 'align' | 'state'>, start: Uint8Array, length: number, offset: Uint8Array): Uint8Array;
|
|
135
|
+
/**
|
|
136
|
+
* Probes `entry`, a function (context pointer, data pointer, length) that updates a context struct
|
|
137
|
+
* in place, and decides by trial what its state is and whether the state transition is affine.
|
|
138
|
+
*
|
|
139
|
+
* It finds the parameter order under which the call composes over a split, then, from contexts the
|
|
140
|
+
* function itself produced, flips each of the first `window` context bytes and records which bytes
|
|
141
|
+
* the result depends on. State is the set of bytes a call both reads and writes. A byte that is read
|
|
142
|
+
* and never written is a parameter and stays at its value in `options.context`. State bytes that
|
|
143
|
+
* do not depend on each other form independent factors. Each factor is tested over GF(2) and over
|
|
144
|
+
* Z/2^bits (as one little or big endian integer, or as 32-bit words coupled by a matrix) with the
|
|
145
|
+
* five checks of `probeAffine`, with the other factors set to random bytes in every call, which
|
|
146
|
+
* tests that they do not interact. A factor that is affine in no ring refuses the whole context.
|
|
147
|
+
*
|
|
148
|
+
* A pass is evidence on the sampled inputs only. It cannot see state outside the window, a byte
|
|
149
|
+
* that is read only on rare inputs, or behaviour above the probed lengths. `foldState` in exact
|
|
150
|
+
* mode does not trust the model, but its guarantee needs the state to be complete.
|
|
151
|
+
*/
|
|
152
|
+
export declare function probeState(module: WebAssembly.Module | Uint8Array, entry: string, options?: StateProbeOptions): StateModel | StateRefusal;
|
|
153
|
+
/**
|
|
154
|
+
* Runs on the worker side. Answers `ctx:<hex state>` with the end state bytes, and
|
|
155
|
+
* `ctxrec:<hex state>:<step>` with the state after every `step` bytes, concatenated, the last one
|
|
156
|
+
* being the end state. The context image is rebuilt from `subject.context` for every task.
|
|
157
|
+
*/
|
|
158
|
+
export declare function serveContext(link: TaskLink, subject: ContextSubject): void;
|
|
159
|
+
/** The serial reference: one call over all the bytes on a private instance. */
|
|
160
|
+
export declare function stateSerial(subject: ContextSubject): (input: Uint8Array, state?: Uint8Array) => Uint8Array;
|
|
161
|
+
/**
|
|
162
|
+
* `foldAffine` exact mode for a state vector in the context: pass 1 runs every chunk but the last
|
|
163
|
+
* from the zero state, the model turns the offsets into predicted start vectors, pass 2 runs
|
|
164
|
+
* chunks 1 to n-1 from them in workers started with `serveContext`, and each end vector is compared
|
|
165
|
+
* with the next predicted start. All equal: the last end vector is the serial state, by induction,
|
|
166
|
+
* whatever the model got wrong. The first difference hands the rest to one serial task.
|
|
167
|
+
*
|
|
168
|
+
* The result is the state bytes only. Bytes a call writes and does not read (`model.scratch`, and
|
|
169
|
+
* the data a call changes in place) are not returned.
|
|
170
|
+
*/
|
|
171
|
+
export declare function foldState(pool: TaskPool, input: Uint8Array, model: StateModel, options?: StateFoldOptions): StateFoldResult;
|