@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.
Files changed (65) hide show
  1. package/README.md +398 -28
  2. package/dist/affine-state.d.ts +171 -0
  3. package/dist/affine-state.js +763 -0
  4. package/dist/affine.d.ts +160 -0
  5. package/dist/affine.js +571 -0
  6. package/dist/boundaries.d.ts +59 -0
  7. package/dist/boundaries.js +127 -0
  8. package/dist/certified.d.ts +66 -0
  9. package/dist/certified.js +192 -0
  10. package/dist/certify.d.ts +98 -0
  11. package/dist/certify.js +2628 -0
  12. package/dist/context.d.ts +16 -2
  13. package/dist/context.js +60 -14
  14. package/dist/coordinator.js +50 -3
  15. package/dist/extract.d.ts +19 -0
  16. package/dist/extract.js +133 -5
  17. package/dist/fold.d.ts +32 -0
  18. package/dist/fold.js +105 -0
  19. package/dist/frames.d.ts +5 -1
  20. package/dist/frames.js +156 -9
  21. package/dist/inline.d.ts +114 -0
  22. package/dist/inline.js +276 -13
  23. package/dist/iteration-admission.d.ts +116 -7
  24. package/dist/iteration-admission.js +137 -8
  25. package/dist/iteration-layout.d.ts +60 -0
  26. package/dist/iteration-layout.js +54 -3
  27. package/dist/iteration-owner.d.ts +14 -1
  28. package/dist/iteration-owner.js +2 -2
  29. package/dist/iteration-worker.js +124 -58
  30. package/dist/iteration.d.ts +179 -13
  31. package/dist/iteration.js +845 -70
  32. package/dist/lease.d.ts +45 -0
  33. package/dist/lease.js +274 -0
  34. package/dist/managed.d.ts +72 -0
  35. package/dist/managed.js +425 -27
  36. package/dist/memo.d.ts +99 -0
  37. package/dist/memo.js +250 -0
  38. package/dist/node.d.ts +43 -1
  39. package/dist/node.js +87 -11
  40. package/dist/ownership-redirect.d.ts +30 -0
  41. package/dist/ownership-redirect.js +179 -0
  42. package/dist/ownership-slices.d.ts +44 -0
  43. package/dist/ownership-slices.js +72 -0
  44. package/dist/ownership.d.ts +161 -0
  45. package/dist/ownership.js +6568 -0
  46. package/dist/ranges.d.ts +78 -0
  47. package/dist/ranges.js +263 -0
  48. package/dist/read-scan.d.ts +18 -0
  49. package/dist/read-scan.js +94 -0
  50. package/dist/read-windows.d.ts +103 -0
  51. package/dist/read-windows.js +244 -0
  52. package/dist/router-worker.d.ts +1 -0
  53. package/dist/router-worker.js +4 -0
  54. package/dist/router.d.ts +203 -0
  55. package/dist/router.js +667 -0
  56. package/dist/runs.d.ts +44 -0
  57. package/dist/runs.js +182 -0
  58. package/dist/slices-worker.d.ts +1 -0
  59. package/dist/slices-worker.js +38 -0
  60. package/dist/slices.d.ts +126 -0
  61. package/dist/slices.js +441 -0
  62. package/dist/tasks.d.ts +14 -4
  63. package/dist/tasks.js +12 -11
  64. package/dist/transaction.d.ts +10 -0
  65. package/package.json +40 -4
@@ -0,0 +1,179 @@
1
+ import binaryen from 'binaryen';
2
+ import { createHash } from 'node:crypto';
3
+ import { iterationRoute, redirectDelta, stackRoute } from "./extract.js";
4
+ import { memoryAccesses, verifyOwnership } from "./ownership.js";
5
+ export class OwnershipRedirectError extends Error {
6
+ code;
7
+ constructor(code, detail) {
8
+ super(detail);
9
+ this.name = 'OwnershipRedirectError';
10
+ this.code = code;
11
+ }
12
+ }
13
+ const i32 = binaryen.i32;
14
+ const api = binaryen;
15
+ const sha = (bytes) => createHash('sha256').update(bytes).digest('hex');
16
+ /**
17
+ * Rewrites the closure of a certified module so each window access adds a per-worker delta. The
18
+ * delta globals start at 0, so the module still runs in place. Throws `OwnershipRedirectError`
19
+ * when the certificate does not bind to the bytes or the module cannot be rewritten.
20
+ */
21
+ export function redirectOwnership(bytes, certificate) {
22
+ if (certificate.kind !== 'certificate' || certificate.moduleSha256 !== sha(bytes))
23
+ throw new OwnershipRedirectError('unbound', 'the certificate is for another module');
24
+ if (!verifyOwnership(bytes, certificate))
25
+ throw new OwnershipRedirectError('stale', 'the certificate does not re-derive');
26
+ const m = binaryen.readBinary(Uint8Array.from(bytes));
27
+ const debug = api.getDebugInfo?.() ?? false;
28
+ try {
29
+ const compact = binaryen.Features.CompactImports;
30
+ m.setFeatures(binaryen.Features.All & ~compact);
31
+ const windows = certificate.windows.map((w, i) => ({
32
+ low: w.low,
33
+ end: w.end,
34
+ delta: `${redirectDelta}${i}`
35
+ }));
36
+ for (const w of windows)
37
+ if (m.getGlobal(w.delta) || m.getExport(w.delta))
38
+ throw new OwnershipRedirectError('unsupported', `${w.delta} is already defined`);
39
+ for (const w of windows) {
40
+ m.addGlobal(w.delta, i32, true, m.i32.const(0));
41
+ m.addGlobalExport(w.delta, w.delta);
42
+ }
43
+ const c = (v) => m.i32.const(v | 0);
44
+ const get = (index) => m.local.get(index, i32);
45
+ const stats = {
46
+ redirected: 0,
47
+ skipped: 0,
48
+ bulk: 0,
49
+ straddle: 0,
50
+ functions: 0
51
+ };
52
+ const lowest = Math.min(...windows.map((w) => w.low));
53
+ // the byte at `a + k` lies wholly in window w when the offset from low is below `limit`
54
+ const inside = (a, k, w, width) => m.i32.lt_u(m.i32.sub(k ? m.i32.add(get(a), c(k)) : get(a), c(w.low)), c(w.end - w.low - width + 1));
55
+ const overlaps = (a, k, w, width) => m.i32.lt_u(m.i32.sub(k ? m.i32.add(get(a), c(k)) : get(a), c(w.low - width + 1)), c(w.end - w.low + width - 1));
56
+ const partial = (a, k, w, width) => m.i32.and(overlaps(a, k, w, width), m.i32.eqz(inside(a, k, w, width)));
57
+ const chain = (test) => windows.reduceRight((rest, w) => m.select(test(w), m.global.get(w.delta, i32), rest), c(0));
58
+ const any = (test) => windows.map(test).reduce((left, right) => m.i32.or(left, right));
59
+ for (const name of certificate.functions) {
60
+ const ref = m.getFunction(name);
61
+ if (!ref)
62
+ throw new OwnershipRedirectError('stale', `no function ${name}`);
63
+ const body = binaryen.getFunctionInfo(ref).body;
64
+ const sites = memoryAccesses(body);
65
+ const modes = certificate.accesses[name] ?? '';
66
+ if (modes.length !== sites.length)
67
+ throw new OwnershipRedirectError('stale', `the accesses of ${name} changed`);
68
+ const infos = sites.map((e) => ({ e, v: binaryen.getExpressionInfo(e) }));
69
+ let t = -1;
70
+ let bulk = [];
71
+ stats.functions++;
72
+ infos.forEach(({ e, v }, at) => {
73
+ const mode = modes[at];
74
+ if (mode === 'o') {
75
+ stats.skipped++;
76
+ return;
77
+ }
78
+ const id = binaryen.getExpressionId(e);
79
+ if (id === binaryen.LoadId || id === binaryen.StoreId) {
80
+ const k = Number(BigInt.asUintN(32, BigInt(v.offset)));
81
+ // a constant base plus the offset cannot wrap, so only a dynamic base needs the bound
82
+ const fixed = binaryen.getExpressionId(v.ptr) === binaryen.ConstId &&
83
+ (binaryen.getExpressionInfo(v.ptr).value >>> 0) + k <= 0xffffffff;
84
+ if (k > lowest && !fixed)
85
+ throw new OwnershipRedirectError('unsupported', 'an access offset passes a window');
86
+ if (t < 0)
87
+ t = api._BinaryenFunctionAddVar(ref, i32);
88
+ const width = v.bytes;
89
+ let delta = chain((w) => inside(t, k, w, width));
90
+ if (width > 1 && mode !== 'x' && mode !== 'b') {
91
+ delta = m.if(any((w) => partial(t, k, w, width)), m.unreachable(), delta);
92
+ stats.straddle++;
93
+ }
94
+ const ptr = m.i32.add(m.local.tee(t, v.ptr, i32), delta);
95
+ if (id === binaryen.LoadId)
96
+ api._BinaryenLoadSetPtr(e, ptr);
97
+ else
98
+ api._BinaryenStoreSetPtr(e, ptr);
99
+ stats.redirected++;
100
+ return;
101
+ }
102
+ if (bulk.length === 0) {
103
+ bulk = [0, 1, 2, 3].map(() => api._BinaryenFunctionAddVar(ref, i32));
104
+ }
105
+ const [td, ts, tn, tv] = bulk;
106
+ void tv;
107
+ const isCopy = id === binaryen.MemoryCopyId;
108
+ const dest = v.dest;
109
+ const second = isCopy
110
+ ? v.source
111
+ : id === binaryen.MemoryFillId
112
+ ? v.value
113
+ : v.offset;
114
+ const size = v.size;
115
+ const room = (a) => {
116
+ const n = (w) => w.end - w.low;
117
+ const inn = (w) => m.i32.and(m.i32.le_u(get(tn), c(n(w))), m.i32.le_u(m.i32.sub(get(a), c(w.low)), m.i32.sub(c(n(w)), get(tn))));
118
+ const part = (w) => m.i32.and(m.i32.and(m.i32.lt_u(get(a), c(w.end)), m.i32.gt_u(m.i32.add(get(a), get(tn)), c(w.low))), m.i32.eqz(inn(w)));
119
+ const pick = windows.reduceRight((rest, w) => m.select(inn(w), m.global.get(w.delta, i32), rest), c(0));
120
+ return m.if(any(part), m.unreachable(), pick);
121
+ };
122
+ const first = m.block(null, [
123
+ m.local.set(td, dest),
124
+ m.local.set(ts, second),
125
+ m.local.set(tn, size),
126
+ m.i32.add(get(td), room(td))
127
+ ], i32);
128
+ const next = isCopy ? m.i32.add(get(ts), room(ts)) : get(ts);
129
+ if (isCopy) {
130
+ api._BinaryenMemoryCopySetDest(e, first);
131
+ api._BinaryenMemoryCopySetSource(e, next);
132
+ api._BinaryenMemoryCopySetSize(e, get(tn));
133
+ }
134
+ else if (id === binaryen.MemoryFillId) {
135
+ api._BinaryenMemoryFillSetDest(e, first);
136
+ api._BinaryenMemoryFillSetValue(e, next);
137
+ api._BinaryenMemoryFillSetSize(e, get(tn));
138
+ }
139
+ else {
140
+ api._BinaryenMemoryInitSetDest(e, first);
141
+ api._BinaryenMemoryInitSetOffset(e, next);
142
+ api._BinaryenMemoryInitSetSize(e, get(tn));
143
+ }
144
+ stats.bulk++;
145
+ stats.straddle++;
146
+ });
147
+ }
148
+ if (!m.validate())
149
+ throw new OwnershipRedirectError('invalid', 'the redirected module is invalid');
150
+ api.setDebugInfo?.(true);
151
+ const out = Uint8Array.from(m.emitBinary());
152
+ try {
153
+ new WebAssembly.Module(out);
154
+ }
155
+ catch (error) {
156
+ throw new OwnershipRedirectError('invalid', `the redirected module does not compile: ${error}`);
157
+ }
158
+ return {
159
+ module: out,
160
+ plan: {
161
+ windows: windows.map((w) => ({ low: w.low, end: w.end, delta: w.delta })),
162
+ copyOut: certificate.copyOut.map(([a, b]) => [a, b])
163
+ },
164
+ stats
165
+ };
166
+ }
167
+ finally {
168
+ api.setDebugInfo?.(debug);
169
+ m.dispose();
170
+ }
171
+ }
172
+ /** The iteration route of the redirected module, with the plan the executor needs. */
173
+ export function ownershipRoute(bytes, certificate) {
174
+ const redirect = redirectOwnership(bytes, certificate);
175
+ const route = iterationRoute(redirect.module, stackRoute(redirect.module));
176
+ if (route.eligible)
177
+ route.ownership = redirect.plan;
178
+ return { route, redirect };
179
+ }
@@ -0,0 +1,44 @@
1
+ import { type OwnershipRedirect } from './ownership-redirect.ts';
2
+ import { type OwnershipCertificate } from './ownership.ts';
3
+ import { type SlicePoolOptions, type SliceReport, type SliceRunOptions } from './slices.ts';
4
+ /**
5
+ * `layout`: a record region overlaps a certified window, so the certificate does not apply.
6
+ * `wild-store`: the module stores to an address outside every window that no record owns, and
7
+ * nothing here tracks it.
8
+ * `config`: the memory or a table word differs from the config the certificate was made for.
9
+ */
10
+ export declare class OwnershipSlicesError extends Error {
11
+ readonly code: 'layout' | 'wild-store' | 'config';
12
+ constructor(code: 'layout' | 'wild-store' | 'config', detail: string);
13
+ }
14
+ export interface OwnershipSliceRunOptions extends Omit<SliceRunOptions, 'writes'> {
15
+ /** Every region the records touch: the table, inputs, aux data, outputs and arena slices. */
16
+ regions: [number, number][];
17
+ /**
18
+ * The regions the records write outside the windows. They are restored when a slice traps. The
19
+ * list must name every range the records write: a range left out keeps the writes of the records
20
+ * after the trap, and the serial replay does not undo them.
21
+ */
22
+ writes: [number, number][];
23
+ }
24
+ /**
25
+ * The slice pool over a certified module whose windows are redirected to private copies. A trap in
26
+ * any slice puts `writes` back and runs the calls serially in place, so the serial run decides the
27
+ * memory and the trap.
28
+ * @since 1.1.0
29
+ */
30
+ export declare class OwnershipSlices {
31
+ #private;
32
+ readonly redirect: OwnershipRedirect;
33
+ private constructor();
34
+ /** Redirects the module and opens the pool. Throws `OwnershipRedirectError` on a stale certificate. */
35
+ static open(bytes: Uint8Array, certificate: OwnershipCertificate, options: Omit<SlicePoolOptions, 'ownership'>): Promise<OwnershipSlices>;
36
+ get memory(): WebAssembly.Memory;
37
+ get size(): number;
38
+ /** First byte of the private regions; the memory below it is the program's. */
39
+ get privateBase(): number | undefined;
40
+ /** Calls the certified entry for `[0, count)`. Refuses with `OwnershipSlicesError` on a layout overlap. */
41
+ run(count: number, args: (from: number, to: number) => (number | bigint)[], options: OwnershipSliceRunOptions): Promise<SliceReport>;
42
+ close(): Promise<void>;
43
+ }
44
+ export declare const ownershipSlices: typeof OwnershipSlices.open;
@@ -0,0 +1,72 @@
1
+ import { redirectOwnership } from "./ownership-redirect.js";
2
+ import { checkConfig, guardRecords } from "./ownership.js";
3
+ import { SlicePool } from "./slices.js";
4
+ /**
5
+ * `layout`: a record region overlaps a certified window, so the certificate does not apply.
6
+ * `wild-store`: the module stores to an address outside every window that no record owns, and
7
+ * nothing here tracks it.
8
+ * `config`: the memory or a table word differs from the config the certificate was made for.
9
+ */
10
+ export class OwnershipSlicesError extends Error {
11
+ code;
12
+ constructor(code, detail) {
13
+ super(detail);
14
+ this.name = 'OwnershipSlicesError';
15
+ this.code = code;
16
+ }
17
+ }
18
+ /**
19
+ * The slice pool over a certified module whose windows are redirected to private copies. A trap in
20
+ * any slice puts `writes` back and runs the calls serially in place, so the serial run decides the
21
+ * memory and the trap.
22
+ * @since 1.1.0
23
+ */
24
+ export class OwnershipSlices {
25
+ #pool;
26
+ #certificate;
27
+ redirect;
28
+ constructor(pool, certificate, redirect) {
29
+ this.#pool = pool;
30
+ this.#certificate = certificate;
31
+ this.redirect = redirect;
32
+ }
33
+ /** Redirects the module and opens the pool. Throws `OwnershipRedirectError` on a stale certificate. */
34
+ static async open(bytes, certificate, options) {
35
+ if (certificate.wildStores)
36
+ throw new OwnershipSlicesError('wild-store', `${certificate.wildStores} store sites write an address no record owns`);
37
+ const redirect = redirectOwnership(bytes, certificate);
38
+ const pool = await SlicePool.open(redirect.module, {
39
+ ...options,
40
+ ownership: redirect.plan
41
+ });
42
+ return new OwnershipSlices(pool, certificate, redirect);
43
+ }
44
+ get memory() {
45
+ return this.#pool.memory;
46
+ }
47
+ get size() {
48
+ return this.#pool.size;
49
+ }
50
+ /** First byte of the private regions; the memory below it is the program's. */
51
+ get privateBase() {
52
+ return this.#pool.privateBase;
53
+ }
54
+ /** Calls the certified entry for `[0, count)`. Refuses with `OwnershipSlicesError` on a layout overlap. */
55
+ async run(count, args, options) {
56
+ const { regions, ...rest } = options;
57
+ if (!guardRecords(this.#certificate, [...regions, ...options.writes]))
58
+ throw new OwnershipSlicesError('layout', 'a record region overlaps a certified window');
59
+ const table = args(0, count)[0];
60
+ if (this.#certificate.config &&
61
+ !checkConfig(this.#certificate, new Uint8Array(this.memory.buffer), {
62
+ at: Number(table),
63
+ count
64
+ }))
65
+ throw new OwnershipSlicesError('config', 'the config words differ from the certificate');
66
+ return this.#pool.run(this.#certificate.entry, count, args, rest);
67
+ }
68
+ close() {
69
+ return this.#pool.close();
70
+ }
71
+ }
72
+ export const ownershipSlices = OwnershipSlices.open;
@@ -0,0 +1,161 @@
1
+ export type Obligation = 'state-isolation' | 'read-before-write' | 'aliasing' | 'final-state' | 'escaping-addresses' | 'failure' | 'provenance' | 'scope';
2
+ export type OwnershipReason = 'isolation' | 'read-before-write' | 'aliasing' | 'final-state' | 'escape' | 'failure' | 'allocator' | 'ptr-store' | 'ptr-return' | 'ptr-import' | 'ptr-compare' | 'ptr-control' | 'ptr-deref' | 'prefix-store' | 'prefix-cover' | 'config-store' | 'no-window' | 'unsupported' | 'budget' | 'invalid';
3
+ export declare const OWNERSHIP_REASONS: readonly OwnershipReason[];
4
+ export interface OwnershipConvention {
5
+ /** Parameter positions of the record table, the record count and the output pointer. Default 0, 1, 2. */
6
+ table: number;
7
+ count: number;
8
+ out: number;
9
+ /** Byte offsets in a table record that hold pointers. Default 0, 8, 12. */
10
+ pointers: number[];
11
+ /** Bytes of one table record. Default 16. */
12
+ recordBytes: number;
13
+ }
14
+ export interface OwnershipOptions {
15
+ /** Exported function that runs the records loop. Default `bulk`. */
16
+ entry?: string;
17
+ convention?: Partial<OwnershipConvention>;
18
+ /** Windows proposed by a probe; they only add bytes to the windows the checker derives. */
19
+ proposed?: {
20
+ low: number;
21
+ end: number;
22
+ }[];
23
+ /** Step limit of one analysis pass. Default 4,000,000. */
24
+ maxSteps?: number;
25
+ /**
26
+ * The allocator mode: the record's arena pointer may be stored in a window and used to allocate.
27
+ * `arenaBytes` is the size of the arena slice. `assumeInArena` counts the dereferences it cannot
28
+ * bound instead of refusing; the result is then never a certificate, only the next refusal.
29
+ */
30
+ allocator?: {
31
+ arenaBytes: number;
32
+ arenaWord?: number;
33
+ assumeInArena?: boolean;
34
+ };
35
+ /**
36
+ * The prefix-written domain: a buffer filled up to a cursor cell. `true` finds the cell and the buffer
37
+ * base from the module; an object names them (a hint, the checker proves every claim itself).
38
+ */
39
+ prefix?: true | {
40
+ cell: number;
41
+ base: number;
42
+ };
43
+ /**
44
+ * A configuration every record shares and none writes: the table word at byte offset `word` of every
45
+ * record equals `at`, and the bytes `[at, at + bytes.length)` hold `bytes` when the run starts. The
46
+ * checker reads them as constants. `extent` is the size of the whole configuration region from `at`; a
47
+ * record-derived pointer is never equal to an address in it. The router checks all of this before it runs.
48
+ */
49
+ config?: {
50
+ word: number;
51
+ at: number;
52
+ bytes: Uint8Array;
53
+ extent: number;
54
+ };
55
+ /** The deepest nesting of one function in the call stack the checker follows; without it recursion is refused. */
56
+ recursion?: number;
57
+ }
58
+ export interface ConfigEvidence {
59
+ word: number;
60
+ at: number;
61
+ /** The frozen bytes as lowercase hex. */
62
+ bytes: string;
63
+ extent: number;
64
+ rules: string[];
65
+ }
66
+ export interface PrefixEvidence {
67
+ /** Address of the 4-byte cursor cell. */
68
+ cell: number;
69
+ /** Address of buffer byte 0; the bytes `[base, base + cursor)` are written by the record. */
70
+ base: number;
71
+ /** Cursor stores the checker discharged against the written prefix. */
72
+ cursorStores: number;
73
+ /** Calls analysed once per exact cursor value. */
74
+ splits: number;
75
+ rules: string[];
76
+ }
77
+ export type ProvenanceRule = 'store' | 'return' | 'import' | 'compare' | 'control' | 'deref';
78
+ export interface AllocatorEvidence {
79
+ arenaBytes: number;
80
+ arenaWord: number;
81
+ /** Window ranges that may hold an arena-derived pointer; the last record supplies their serial values. */
82
+ pointerCells: [number, number][];
83
+ /** Arena offsets where an arena-derived value may have been stored; the bytes there may differ between bases. */
84
+ arenaTaint: [number, number][];
85
+ /** Heap dereferences the interval domain put inside the arena. */
86
+ derefsProved: number;
87
+ rules: Record<ProvenanceRule, string>;
88
+ /** What a router that moves the arena must do. */
89
+ shiftRule: string;
90
+ assumptions: string[];
91
+ }
92
+ export interface OwnershipWindow {
93
+ low: number;
94
+ end: number;
95
+ }
96
+ export interface SiteCounts {
97
+ exact: number;
98
+ bounded: number;
99
+ dynamic: number;
100
+ outside: number;
101
+ bulk: number;
102
+ }
103
+ export interface OwnershipCertificate {
104
+ kind: 'certificate';
105
+ schema: 'folio.ownership.v1';
106
+ checker: string;
107
+ moduleSha256: string;
108
+ entry: string;
109
+ convention: OwnershipConvention;
110
+ proposed: OwnershipWindow[];
111
+ windows: OwnershipWindow[];
112
+ /** Byte ranges the last record's copy supplies; the last record wrote every one of them. */
113
+ copyOut: [number, number][];
114
+ written: [number, number][];
115
+ covered: [number, number][];
116
+ sites: Record<string, SiteCounts>;
117
+ /** Stores whose address is neither record-derived nor inside a window; the in-place slice route refuses them. */
118
+ wildStores: number;
119
+ accesses: Record<string, string>;
120
+ functions: string[];
121
+ evidence: Record<Exclude<Obligation, 'scope' | 'provenance'>, string>;
122
+ /** Present only for a certificate made in allocator mode. */
123
+ allocator?: AllocatorEvidence;
124
+ /** Present only for a certificate made with the prefix option when a cursor cell was found. */
125
+ prefix?: PrefixEvidence;
126
+ /** Present only for a certificate made with the config option; the router checks these premises at admission. */
127
+ config?: ConfigEvidence;
128
+ /** Present only when the analysis followed recursion: the cap it was given and the deepest nesting it reached. */
129
+ recursion?: {
130
+ cap: number;
131
+ depth: number;
132
+ };
133
+ assumptions: string[];
134
+ stats: {
135
+ steps: number;
136
+ calls: number;
137
+ loops: number;
138
+ passes: number;
139
+ };
140
+ }
141
+ export interface OwnershipRefusal {
142
+ kind: 'refusal';
143
+ reason: OwnershipReason;
144
+ obligation: Obligation;
145
+ detail: string;
146
+ address?: number;
147
+ }
148
+ export declare const OWNERSHIP_CHECKER = "folio-ownership-2";
149
+ /** The loads, stores and bulk operations of a function body, in a fixed pre-order walk. */
150
+ export declare function memoryAccesses(body: number): number[];
151
+ export declare function certifyOwnership(bytes: Uint8Array, options?: OwnershipOptions): OwnershipCertificate | OwnershipRefusal;
152
+ /** Re-derives the certificate from the module and compares everything except the work counters. */
153
+ export declare function verifyOwnership(bytes: Uint8Array, certificate: OwnershipCertificate): boolean;
154
+ /** Whether no region of the records overlaps a window or, with the config option, the config region. */
155
+ export declare function guardRecords(certificate: OwnershipCertificate, regions: [number, number][]): boolean;
156
+ /** Whether a record table and a memory image satisfy the premises of a config certificate. */
157
+ export declare function checkConfig(certificate: OwnershipCertificate, memory: Uint8Array, table: {
158
+ at: number;
159
+ count: number;
160
+ recordBytes?: number;
161
+ }): boolean;