From c2df9fae24671ac93f5231d0fc4f8e1f266f04a2 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Fri, 14 Jun 2024 20:59:29 -0700 Subject: [PATCH] fix: endow with original unstructured assert --- packages/SwingSet/src/controller/controller.js | 5 ++++- packages/SwingSet/src/kernel/kernel.js | 9 ++++++++- .../SwingSet/src/kernel/vat-loader/manager-local.js | 5 ++++- .../subprocess-node/supervisor-subprocess-node.js | 5 ++++- packages/SwingSet/test/zcf-ish-upgrade/pseudo-zcf.js | 12 +++++++++--- packages/cosmic-swingset/scripts/clean-core-eval.js | 5 ++++- packages/spawner/src/vat-spawned.js | 5 ++++- .../lib/supervisor-subprocess-xsnap.js | 5 ++++- packages/vats/src/core/chain-behaviors.js | 5 ++++- packages/vats/src/repl.js | 5 ++++- packages/xsnap/src/avaAssertXS.js | 2 +- packages/zoe/src/contractFacet/evalContractCode.js | 6 ++++-- 12 files changed, 54 insertions(+), 15 deletions(-) diff --git a/packages/SwingSet/src/controller/controller.js b/packages/SwingSet/src/controller/controller.js index 404619164f2f..4ab129942a86 100644 --- a/packages/SwingSet/src/controller/controller.js +++ b/packages/SwingSet/src/controller/controller.js @@ -211,7 +211,10 @@ export async function makeSwingsetController( filePrefix: 'kernel/...', endowments: { console: makeConsole(`${debugPrefix}SwingSet:kernel`), - assert, + // This is the underlying unstructured assert that @endo/errors + // uses to build the structured assert that it exports. So we + // cannot use the assert imported from @endo/errors here. + assert: globalThis.assert, require: kernelRequire, URL: globalThis.Base64, // Unavailable only on XSnap Base64: globalThis.Base64, // Available only on XSnap diff --git a/packages/SwingSet/src/kernel/kernel.js b/packages/SwingSet/src/kernel/kernel.js index ae24c76fb0be..c49b293e1070 100644 --- a/packages/SwingSet/src/kernel/kernel.js +++ b/packages/SwingSet/src/kernel/kernel.js @@ -1644,7 +1644,14 @@ export default function buildKernel( assert(bundle); const NS = await importBundle(bundle, { filePrefix: `dev-${name}/...`, - endowments: harden({ ...vatEndowments, console: devConsole, assert }), + endowments: harden({ + ...vatEndowments, + console: devConsole, + // This is the underlying unstructured assert that @endo/errors + // uses to build the structured assert that it exports. So we + // cannot use the assert imported from @endo/errors here. + assert: globalThis.assert, + }), }); if (deviceEndowments[name] || unendowed) { diff --git a/packages/SwingSet/src/kernel/vat-loader/manager-local.js b/packages/SwingSet/src/kernel/vat-loader/manager-local.js index ca94d76c7a92..65aef5d5a841 100644 --- a/packages/SwingSet/src/kernel/vat-loader/manager-local.js +++ b/packages/SwingSet/src/kernel/vat-loader/manager-local.js @@ -74,7 +74,10 @@ export function makeLocalVatManagerFactory({ const workerEndowments = harden({ ...vatEndowments, console: makeVatConsole(makeLogMaker('vat')), - assert, + // This is the underlying unstructured assert that @endo/errors + // uses to build the structured assert that it exports. So we + // cannot use the assert imported from @endo/errors here. + assert: globalThis.assert, TextEncoder, TextDecoder, Base64: globalThis.Base64, // Available only on XSnap diff --git a/packages/SwingSet/src/supervisors/subprocess-node/supervisor-subprocess-node.js b/packages/SwingSet/src/supervisors/subprocess-node/supervisor-subprocess-node.js index 20e7ff4db232..b781a0b5a025 100644 --- a/packages/SwingSet/src/supervisors/subprocess-node/supervisor-subprocess-node.js +++ b/packages/SwingSet/src/supervisors/subprocess-node/supervisor-subprocess-node.js @@ -139,7 +139,10 @@ function handleSetBundle(margs) { // Enable or disable the console accordingly. const workerEndowments = { console: makeVatConsole(makeLogMaker(`SwingSet:vat:${vatID}`)), - assert, + // This is the underlying unstructured assert that @endo/errors + // uses to build the structured assert that it exports. So we + // cannot use the assert imported from @endo/errors here. + assert: globalThis.assert, }; async function buildVatNamespace(lsEndowments, inescapableGlobalProperties) { diff --git a/packages/SwingSet/test/zcf-ish-upgrade/pseudo-zcf.js b/packages/SwingSet/test/zcf-ish-upgrade/pseudo-zcf.js index b2aac7332111..c4614ed7a2cd 100644 --- a/packages/SwingSet/test/zcf-ish-upgrade/pseudo-zcf.js +++ b/packages/SwingSet/test/zcf-ish-upgrade/pseudo-zcf.js @@ -1,11 +1,10 @@ // @ts-nocheck -/* global VatData */ +/* global globalThis, VatData */ /* eslint-disable no-unused-vars */ import { Far } from '@endo/far'; import { importBundle } from '@endo/import-bundle'; import { defineDurableKind } from '@agoric/vat-data'; -import { assert } from '@agoric/assert'; import { provideHandle, provideBaggageSubset as provideBaggageSubTree, @@ -24,7 +23,14 @@ export const buildRootObject = async (vatPowers, vatParameters, baggage) => { const { D } = vatPowers; const { contractBundleCap } = vatParameters; const contractBundle = D(contractBundleCap).getBundle(); - const endowments = { console, assert, VatData }; + const endowments = { + console, + // This is the underlying unstructured assert that @endo/errors + // uses to build the structured assert that it exports. So we + // cannot use the assert imported from @endo/errors here. + assert: globalThis.assert, + VatData, + }; const contractNS = await importBundle(contractBundle, { endowments }); const { setupInstallation, setup: _ } = contractNS; if (!setupInstallation) { diff --git a/packages/cosmic-swingset/scripts/clean-core-eval.js b/packages/cosmic-swingset/scripts/clean-core-eval.js index 58ad55094e08..54467e5e7bd2 100755 --- a/packages/cosmic-swingset/scripts/clean-core-eval.js +++ b/packages/cosmic-swingset/scripts/clean-core-eval.js @@ -12,7 +12,10 @@ export const compartmentEvaluate = code => { const globals = harden({ ...modules, ...farExports, - assert, + // This is the underlying unstructured assert that @endo/errors + // uses to build the structured assert that it exports. So we + // cannot use the assert imported from @endo/errors here. + assert: globalThis.assert, console: { // Ensure we don't pollute stdout. debug: console.warn, diff --git a/packages/spawner/src/vat-spawned.js b/packages/spawner/src/vat-spawned.js index fa33bfa3e478..31b151db6a79 100644 --- a/packages/spawner/src/vat-spawned.js +++ b/packages/spawner/src/vat-spawned.js @@ -6,7 +6,10 @@ import { Far } from '@endo/marshal'; const endowments = { VatData, console, - assert, + // This is the underlying unstructured assert that @endo/errors + // uses to build the structured assert that it exports. So we + // cannot use the assert imported from @endo/errors here. + assert: globalThis.assert, Base64: globalThis.Base64, // Present only on XSnap URL: globalThis.URL, // Absent only on XSnap }; diff --git a/packages/swingset-xsnap-supervisor/lib/supervisor-subprocess-xsnap.js b/packages/swingset-xsnap-supervisor/lib/supervisor-subprocess-xsnap.js index 4f2798797221..550d9a54750e 100644 --- a/packages/swingset-xsnap-supervisor/lib/supervisor-subprocess-xsnap.js +++ b/packages/swingset-xsnap-supervisor/lib/supervisor-subprocess-xsnap.js @@ -255,7 +255,10 @@ function makeWorker(port) { const workerEndowments = { console: makeVatConsole(makeLogMaker('vat')), - assert, + // This is the underlying unstructured assert that @endo/errors + // uses to build the structured assert that it exports. So we + // cannot use the assert imported from @endo/errors here. + assert: globalThis.assert, // bootstrap provides HandledPromise HandledPromise: globalThis.HandledPromise, TextEncoder, diff --git a/packages/vats/src/core/chain-behaviors.js b/packages/vats/src/core/chain-behaviors.js index d40e0e48fd54..048171099c8b 100644 --- a/packages/vats/src/core/chain-behaviors.js +++ b/packages/vats/src/core/chain-behaviors.js @@ -39,7 +39,10 @@ export const bridgeCoreEval = async allPowers => { const endowments = { VatData: globalThis.VatData, console, - assert, + // This is the underlying unstructured assert that @endo/errors + // uses to build the structured assert that it exports. So we + // cannot use the assert imported from @endo/errors here. + assert: globalThis.assert, Base64: globalThis.Base64, // Present only on XSnap URL: globalThis.URL, // Absent only on XSnap }; diff --git a/packages/vats/src/repl.js b/packages/vats/src/repl.js index 1d00a23ad0d3..a5d1af684dbf 100644 --- a/packages/vats/src/repl.js +++ b/packages/vats/src/repl.js @@ -194,7 +194,10 @@ export function getReplHandler(replObjects, send) { ...farExports, ...vowExports, E, - assert, + // This is the underlying unstructured assert that @endo/errors + // uses to build the structured assert that it exports. So we + // cannot use the assert imported from @endo/errors here. + assert: globalThis.assert, console: replConsole, commands, history, diff --git a/packages/xsnap/src/avaAssertXS.js b/packages/xsnap/src/avaAssertXS.js index 7522d1108aee..e63c37ac9697 100644 --- a/packages/xsnap/src/avaAssertXS.js +++ b/packages/xsnap/src/avaAssertXS.js @@ -228,7 +228,7 @@ function makeTester(htest, out) { fail(message) { assert(false, message); }, - assert, + assert, // Not the SES assert truthy, /** * @param {unknown} value diff --git a/packages/zoe/src/contractFacet/evalContractCode.js b/packages/zoe/src/contractFacet/evalContractCode.js index b357f3d2d00c..503e4f39cee2 100644 --- a/packages/zoe/src/contractFacet/evalContractCode.js +++ b/packages/zoe/src/contractFacet/evalContractCode.js @@ -4,7 +4,6 @@ /* global globalThis */ import { importBundle } from '@endo/import-bundle'; -import { assert } from '@agoric/assert'; import { handlePWarning } from '../handleWarning.js'; const evalContractBundle = (bundle, additionalEndowments = {}) => { @@ -16,7 +15,10 @@ const evalContractBundle = (bundle, additionalEndowments = {}) => { const defaultEndowments = { console: louderConsole, - assert, + // This is the underlying unstructured assert that @endo/errors + // uses to build the structured assert that it exports. So we + // cannot use the assert imported from @endo/errors here. + assert: globalThis.assert, VatData: globalThis.VatData, };