aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / om / hive-page / fresh-oracle.js
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Read-only verification oracle; no code/IR/wasm generation. |
| 3 | 'use strict'; |
| 4 | const fs = require('node:fs'); |
| 5 | const assert = require('node:assert/strict'); |
| 6 | const [wasmPath, tablePath, statusPath] = process.argv.slice(2); |
| 7 | const bytes = fs.readFileSync(wasmPath); |
| 8 | assert(WebAssembly.validate(bytes)); |
| 9 | const moduleObject = new WebAssembly.Module(bytes); |
| 10 | assert.deepEqual(WebAssembly.Module.imports(moduleObject), []); |
| 11 | const { fresh } = new WebAssembly.Instance(moduleObject).exports; |
| 12 | const rows = fs.readFileSync(tablePath, 'utf8').split('\n') |
| 13 | .filter(line => line && !line.startsWith('#')).map(line => line.split(' ')); |
| 14 | const native = fs.readFileSync(statusPath, 'utf8').trim().split('\n').map(Number); |
| 15 | assert.equal(native.length, rows.length); |
| 16 | for (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 | } |
| 21 | console.log(`PASS freshness native/wasm boundary cases=${rows.length}; all four states`); |