interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / hive-page / fresh-oracle.js

21 lines · 1228 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// Read-only verification oracle; no code/IR/wasm generation.
3'use strict';
4const fs = require('node:fs');
5const assert = require('node:assert/strict');
6const [wasmPath, tablePath, statusPath] = process.argv.slice(2);
7const bytes = fs.readFileSync(wasmPath);
8assert(WebAssembly.validate(bytes));
9const moduleObject = new WebAssembly.Module(bytes);
10assert.deepEqual(WebAssembly.Module.imports(moduleObject), []);
11const { fresh } = new WebAssembly.Instance(moduleObject).exports;
12const rows = fs.readFileSync(tablePath, 'utf8').split('\n')
13 .filter(line => line && !line.startsWith('#')).map(line => line.split(' '));
14const native = fs.readFileSync(statusPath, 'utf8').trim().split('\n').map(Number);
15assert.equal(native.length, rows.length);
16for (const [index, [now, generated, previous, stale, ok, expected]] of rows.entries()) {
17 const result = fresh(BigInt(now), BigInt(generated), BigInt(previous), BigInt(stale), ok === 'true' ? 1 : 0);
18 assert.equal(result, native[index], `native/wasm case ${index + 1}`);
19 assert.equal(result, Number(expected), `specified boundary case ${index + 1}`);
20}
21console.log(`PASS freshness native/wasm boundary cases=${rows.length}; all four states`);