feat(evm): retain lossless terminal CBOR metadata Refs morluto/rea#2388 Co-authored-by: Matheus Breguêz <matbrgz@gmail.com> Co-authored-by: Codex <noreply@openai.com>
618 lines
20 KiB
JavaScript
618 lines
20 KiB
JavaScript
#!/usr/bin/env node
|
|
import assert from "node:assert/strict";
|
|
import { execFile } from "node:child_process";
|
|
import { createHash } from "node:crypto";
|
|
import { access, readFile, readdir, writeFile } from "node:fs/promises";
|
|
import { constants } from "node:fs";
|
|
import { isAbsolute, join } from "node:path";
|
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
import { promisify } from "node:util";
|
|
import { Client } from "@modelcontextprotocol/client";
|
|
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
|
import { PrivateRuntimeRoot } from "../dist/process/PrivateRuntimeRoot.js";
|
|
import { parseEvidence } from "../dist/domain/evidence.js";
|
|
import { mcpTextValue } from "./lib/mcp-verifier-results.mjs";
|
|
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
|
|
|
const solcModule = process.env.REA_VERIFY_SOLC_MODULE;
|
|
const strace = process.env.REA_VERIFY_STRACE_COMMAND;
|
|
if (
|
|
process.platform !== "linux" ||
|
|
process.arch !== "x64" ||
|
|
!isAbsolute(solcModule ?? "") ||
|
|
!isAbsolute(strace ?? "")
|
|
)
|
|
throw new Error(
|
|
"verify:evm:interface requires Linux x64, caller-supplied util-linux prlimit and absolute REA_VERIFY_SOLC_MODULE pointing to unchanged solc 0.8.30 and absolute REA_VERIFY_STRACE_COMMAND. No target or chain is executed.",
|
|
);
|
|
try {
|
|
await access(
|
|
process.env.REA_EVM_PRLIMIT_COMMAND ?? "/usr/bin/prlimit",
|
|
constants.X_OK,
|
|
);
|
|
await access(solcModule, constants.R_OK);
|
|
await access(strace, constants.X_OK);
|
|
} catch (cause) {
|
|
throw new Error(
|
|
"verify:evm:interface prerequisite unavailable: selected solc module, strace or util-linux prlimit",
|
|
{ cause },
|
|
);
|
|
}
|
|
const solc = (await import(pathToFileURL(solcModule).href)).default;
|
|
assert.equal(solc.version(), "0.8.30+commit.73712a01.Emscripten.clang");
|
|
const source = await readFile(
|
|
new URL("./fixtures/evm-interface.sol", import.meta.url),
|
|
"utf8",
|
|
);
|
|
const entrypoint =
|
|
process.argv[2] ?? fileURLToPath(new URL("./rea.mjs", import.meta.url));
|
|
const execute = promisify(execFile);
|
|
const environment = Object.fromEntries(
|
|
Object.entries(process.env).filter(([, value]) => typeof value === "string"),
|
|
);
|
|
const run = createVerifierRun();
|
|
const root = await PrivateRuntimeRoot.create({ prefix: "rea-evm-verifier-" });
|
|
const client = new Client({ name: "evm-interface-verifier", version: "1" });
|
|
const transport = new StdioClientTransport({
|
|
command: process.execPath,
|
|
args: [entrypoint, "mcp"],
|
|
env: environment,
|
|
stderr: "pipe",
|
|
});
|
|
const failures = [];
|
|
let cases = 0;
|
|
try {
|
|
await client.connect(transport);
|
|
const tools = await client.listTools();
|
|
assert.ok(tools.tools.some(({ name }) => name === "inspect_evm_interface"));
|
|
const inspect = async (
|
|
mode,
|
|
path,
|
|
encoding,
|
|
expectedCategory,
|
|
scope = { command: process.execPath, prefix: [], client },
|
|
) => {
|
|
let value;
|
|
if (mode === "cli") {
|
|
let stdout;
|
|
try {
|
|
({ stdout } = await execute(
|
|
scope.command,
|
|
[
|
|
...scope.prefix,
|
|
entrypoint,
|
|
"inspect-evm-interface",
|
|
path,
|
|
encoding,
|
|
"--json",
|
|
],
|
|
{
|
|
env: scope.environment ?? environment,
|
|
timeout: 45_000,
|
|
maxBuffer: 32 * 1024 * 1024,
|
|
},
|
|
));
|
|
} catch (cause) {
|