From b337eefdaf1d3f17d596f8f08f3b01aee070ec2c Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Fri, 14 Jul 2023 16:32:48 -0700 Subject: [PATCH 1/5] fix: add passStyleOf to VatData global --- packages/SwingSet/package.json | 1 + packages/swingset-liveslots/src/vatDataTypes.d.ts | 1 + packages/swingset-liveslots/tools/setup-vat-data.js | 2 ++ packages/vat-data/src/vat-data-bindings.js | 1 + packages/vats/package.json | 1 + 5 files changed, 6 insertions(+) diff --git a/packages/SwingSet/package.json b/packages/SwingSet/package.json index c946369346b..1af7f5eb216 100644 --- a/packages/SwingSet/package.json +++ b/packages/SwingSet/package.json @@ -49,6 +49,7 @@ "@endo/init": "^1.0.4", "@endo/marshal": "^1.3.0", "@endo/nat": "^5.0.4", + "@endo/pass-style": "^1.2.0", "@endo/patterns": "^1.2.0", "@endo/promise-kit": "^1.0.4", "@endo/ses-ava": "^1.1.2", diff --git a/packages/swingset-liveslots/src/vatDataTypes.d.ts b/packages/swingset-liveslots/src/vatDataTypes.d.ts index c417bef14fc..d1731cf0742 100644 --- a/packages/swingset-liveslots/src/vatDataTypes.d.ts +++ b/packages/swingset-liveslots/src/vatDataTypes.d.ts @@ -194,6 +194,7 @@ export type VatData = { options?: StoreOptions, ) => WeakSetStore; canBeDurable: (specimen: unknown) => boolean; + passStyleOf: (specimen: unknown) => string; }; // The JSDoc is repeated here and at the function definition so it appears diff --git a/packages/swingset-liveslots/tools/setup-vat-data.js b/packages/swingset-liveslots/tools/setup-vat-data.js index 7ffa9e37224..58e4e57269b 100644 --- a/packages/swingset-liveslots/tools/setup-vat-data.js +++ b/packages/swingset-liveslots/tools/setup-vat-data.js @@ -3,6 +3,7 @@ // This file produces the globalThis.VatData property outside of a running // SwingSet so that it can be used by '@agoric/vat-data' (which only *consumes* // `globalThis.VatData`) in code under test. +import { passStyleOf } from '@endo/pass-style'; import { makeFakeVirtualStuff } from './fakeVirtualSupport.js'; const { WeakMap, WeakSet } = globalThis; @@ -35,6 +36,7 @@ globalThis.VatData = harden({ fakeVomKit.cm.makeScalarBigSetStore(...args), makeScalarBigWeakSetStore: (...args) => fakeVomKit.cm.makeScalarBigWeakSetStore(...args), + passStyleOf, }); export const reincarnate = (options = {}) => { diff --git a/packages/vat-data/src/vat-data-bindings.js b/packages/vat-data/src/vat-data-bindings.js index d5b214de7c0..096ee374d2d 100644 --- a/packages/vat-data/src/vat-data-bindings.js +++ b/packages/vat-data/src/vat-data-bindings.js @@ -26,6 +26,7 @@ if ('VatData' in globalThis) { makeScalarBigSetStore: unavailable, makeScalarBigWeakSetStore: unavailable, canBeDurable: unavailable, + passStyleOf: unavailable, // not exported from here in any case }; } diff --git a/packages/vats/package.json b/packages/vats/package.json index 02537ef765f..b374420fb06 100644 --- a/packages/vats/package.json +++ b/packages/vats/package.json @@ -38,6 +38,7 @@ "@endo/import-bundle": "^1.0.4", "@endo/marshal": "^1.3.0", "@endo/nat": "^5.0.4", + "@endo/pass-style": "^1.2.0", "@endo/patterns": "^1.2.0", "@endo/promise-kit": "^1.0.4", "import-meta-resolve": "^2.2.1", From 2ace6d98c0da2c64d650dab02997a019fbeafb89 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Thu, 30 May 2024 18:40:04 -0700 Subject: [PATCH 2/5] add globalThis.VatData.passStyleOf to liveslots-hosted vat environment --- packages/SwingSet/package.json | 1 - packages/SwingSet/test/test-vat-env.js | 1 + packages/swingset-liveslots/src/liveslots.js | 9 +++------ 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/SwingSet/package.json b/packages/SwingSet/package.json index 1af7f5eb216..c946369346b 100644 --- a/packages/SwingSet/package.json +++ b/packages/SwingSet/package.json @@ -49,7 +49,6 @@ "@endo/init": "^1.0.4", "@endo/marshal": "^1.3.0", "@endo/nat": "^5.0.4", - "@endo/pass-style": "^1.2.0", "@endo/patterns": "^1.2.0", "@endo/promise-kit": "^1.0.4", "@endo/ses-ava": "^1.1.2", diff --git a/packages/SwingSet/test/test-vat-env.js b/packages/SwingSet/test/test-vat-env.js index 0f1f29c9298..1b422c06a6a 100644 --- a/packages/SwingSet/test/test-vat-env.js +++ b/packages/SwingSet/test/test-vat-env.js @@ -97,6 +97,7 @@ async function testForExpectedGlobals(t, workerType) { 'VatData.makeScalarBigWeakMapStore: function', 'VatData.makeScalarBigSetStore: function', 'VatData.makeScalarBigWeakSetStore: function', + 'VatData.passStyleOf: function', ]); } diff --git a/packages/swingset-liveslots/src/liveslots.js b/packages/swingset-liveslots/src/liveslots.js index 1474a5d0dd5..704ca4e5230 100644 --- a/packages/swingset-liveslots/src/liveslots.js +++ b/packages/swingset-liveslots/src/liveslots.js @@ -1,11 +1,7 @@ /* eslint @typescript-eslint/no-floating-promises: "warn" */ -import { - Remotable, - passStyleOf, - getInterfaceOf, - makeMarshal, -} from '@endo/marshal'; +import { Remotable, getInterfaceOf, makeMarshal } from '@endo/marshal'; import { assert, Fail } from '@agoric/assert'; +import { passStyleOf } from '@endo/pass-style'; import { isPromise } from '@endo/promise-kit'; import { E, HandledPromise } from '@endo/eventual-send'; import { insistVatType, makeVatSlot, parseVatSlot } from './parseVatSlots.js'; @@ -1337,6 +1333,7 @@ function build( makeScalarBigWeakMapStore: collectionManager.makeScalarBigWeakMapStore, makeScalarBigSetStore: collectionManager.makeScalarBigSetStore, makeScalarBigWeakSetStore: collectionManager.makeScalarBigWeakSetStore, + passStyleOf, }, }); From f262d8c4cb99480835c7a0d1ef220198dee1a88a Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 31 May 2024 15:57:19 -0700 Subject: [PATCH 3/5] use symbol-named property instead of globalThis.passStyleOf Update the swingset test to look for it there, and compare against a bundle-generated version (they should be different). This currently fails because importBundle() does not respect symbol-named properties of `vatGlobals`. Restored the SwingSet/package.json dependency on `@endo/pass-style` so the vat-under-test can get a bundle-generated version, for comparison. Added a liveslots-local test of the same, which passes because it's only looking at the `vatGlobals` given to `buildVatNamespace()`, and doesn't use `importBundle()`. --- packages/SwingSet/package.json | 1 + packages/SwingSet/test/test-vat-env.js | 3 +- packages/SwingSet/test/vat-envtest.js | 5 ++ packages/swingset-liveslots/src/liveslots.js | 8 ++- .../test/test-vat-environment.js | 60 +++++++++++++++++++ 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 packages/swingset-liveslots/test/test-vat-environment.js diff --git a/packages/SwingSet/package.json b/packages/SwingSet/package.json index c946369346b..1af7f5eb216 100644 --- a/packages/SwingSet/package.json +++ b/packages/SwingSet/package.json @@ -49,6 +49,7 @@ "@endo/init": "^1.0.4", "@endo/marshal": "^1.3.0", "@endo/nat": "^5.0.4", + "@endo/pass-style": "^1.2.0", "@endo/patterns": "^1.2.0", "@endo/promise-kit": "^1.0.4", "@endo/ses-ava": "^1.1.2", diff --git a/packages/SwingSet/test/test-vat-env.js b/packages/SwingSet/test/test-vat-env.js index 1b422c06a6a..61848df986b 100644 --- a/packages/SwingSet/test/test-vat-env.js +++ b/packages/SwingSet/test/test-vat-env.js @@ -97,7 +97,8 @@ async function testForExpectedGlobals(t, workerType) { 'VatData.makeScalarBigWeakMapStore: function', 'VatData.makeScalarBigSetStore: function', 'VatData.makeScalarBigWeakSetStore: function', - 'VatData.passStyleOf: function', + 'global has passStyleOf: true', + 'global passStyleOf is special: true', ]); } diff --git a/packages/SwingSet/test/vat-envtest.js b/packages/SwingSet/test/vat-envtest.js index e66efd4f9c0..11d2de7b7c3 100644 --- a/packages/SwingSet/test/vat-envtest.js +++ b/packages/SwingSet/test/vat-envtest.js @@ -1,6 +1,8 @@ // @ts-nocheck /* global VatData */ import { Far } from '@endo/far'; +import { passStyleOf } from '@endo/pass-style'; +import { PassStyleOfEndowmentSymbol } from '@endo/pass-style/endow.js'; export function buildRootObject(vatPowers) { const log = vatPowers.testLog; @@ -13,6 +15,9 @@ export function buildRootObject(vatPowers) { for (const prop of Object.keys(VatData)) { log(`VatData.${prop}: ${typeof VatData[prop]}`); } + const globalPassStyleOf = globalThis && globalThis[PassStyleOfEndowmentSymbol]; + log(`global has passStyleOf: ${!!globalPassStyleOf}`); + log(`global passStyleOf is special: ${globalPassStyleOf !== passStyleOf}`); }, }); } diff --git a/packages/swingset-liveslots/src/liveslots.js b/packages/swingset-liveslots/src/liveslots.js index 704ca4e5230..e7e9d91c4f6 100644 --- a/packages/swingset-liveslots/src/liveslots.js +++ b/packages/swingset-liveslots/src/liveslots.js @@ -2,6 +2,7 @@ import { Remotable, getInterfaceOf, makeMarshal } from '@endo/marshal'; import { assert, Fail } from '@agoric/assert'; import { passStyleOf } from '@endo/pass-style'; +import { PassStyleOfEndowmentSymbol } from '@endo/pass-style/endow.js'; import { isPromise } from '@endo/promise-kit'; import { E, HandledPromise } from '@endo/eventual-send'; import { insistVatType, makeVatSlot, parseVatSlot } from './parseVatSlots.js'; @@ -1319,7 +1320,7 @@ function build( syscall.dropImports([slot]); } - const vatGlobals = harden({ + const vatGlobals = { VatData: { defineKind: vom.defineKind, defineKindMulti: vom.defineKindMulti, @@ -1333,9 +1334,10 @@ function build( makeScalarBigWeakMapStore: collectionManager.makeScalarBigWeakMapStore, makeScalarBigSetStore: collectionManager.makeScalarBigSetStore, makeScalarBigWeakSetStore: collectionManager.makeScalarBigWeakSetStore, - passStyleOf, }, - }); + [PassStyleOfEndowmentSymbol]: passStyleOf, + }; + harden(vatGlobals); const inescapableGlobalProperties = harden({ WeakMap: vom.VirtualObjectAwareWeakMap, diff --git a/packages/swingset-liveslots/test/test-vat-environment.js b/packages/swingset-liveslots/test/test-vat-environment.js new file mode 100644 index 00000000000..a6382c54a06 --- /dev/null +++ b/packages/swingset-liveslots/test/test-vat-environment.js @@ -0,0 +1,60 @@ +import '@endo/init/debug.js'; +import test from 'ava'; +import { Far } from '@endo/marshal'; +import { kser } from '@agoric/kmarshal'; +import { passStyleOf } from '@endo/pass-style'; +import { PassStyleOfEndowmentSymbol } from '@endo/pass-style/endow.js'; +import { makeLiveSlots } from '../src/index.js'; +import { makeStartVat } from './util.js'; +import { buildSyscall } from './liveslots-helpers.js'; +import { makeMockGC } from './mock-gc.js'; + +test('vat globals', async t => { + const { syscall } = buildSyscall(); + const gcTools = makeMockGC(); + const buildRootObject = () => Far('root', {}); + let called = 0; + let vatGlobals; + let inescapableGlobalProperties; + const vatNS = harden({ buildRootObject }); + // buildVatNamespace + const bVN = async (vG, iGP) => { + called += 1; + vatGlobals = vG; + inescapableGlobalProperties = iGP; + return vatNS; + }; + + const ls = makeLiveSlots(syscall, 'vatA', {}, {}, gcTools, undefined, bVN); + t.is(called, 0); // not called yet + await ls.dispatch(makeStartVat(kser())); + t.is(called, 1); + t.truthy(vatGlobals); + + // 'harden' is provided by SES (installed by the supervisor), not liveslots + t.is(typeof vatGlobals.harden, 'undefined'); + + // but liveslots provides VatData + t.is(typeof vatGlobals.VatData, 'object'); + t.is(typeof vatGlobals.VatData, 'object'); + t.is(typeof vatGlobals.VatData.defineKind, 'function'); + t.is(typeof vatGlobals.VatData.defineKindMulti, 'function'); + t.is(typeof vatGlobals.VatData.defineDurableKind, 'function'); + t.is(typeof vatGlobals.VatData.defineDurableKindMulti, 'function'); + t.is(typeof vatGlobals.VatData.makeKindHandle, 'function'); + t.is(typeof vatGlobals.VatData.canBeDurable, 'function'); + t.is(typeof vatGlobals.VatData.providePromiseWatcher, 'function'); + t.is(typeof vatGlobals.VatData.watchPromise, 'function'); + t.is(typeof vatGlobals.VatData.makeScalarBigMapStore, 'function'); + t.is(typeof vatGlobals.VatData.makeScalarBigWeakMapStore, 'function'); + t.is(typeof vatGlobals.VatData.makeScalarBigSetStore, 'function'); + t.is(typeof vatGlobals.VatData.makeScalarBigWeakSetStore, 'function'); + t.is(typeof vatGlobals[PassStyleOfEndowmentSymbol], 'function'); + // this is the passStyleOf created by liveslots, with a real WeakMap + t.is(vatGlobals[PassStyleOfEndowmentSymbol], passStyleOf); + + t.is(typeof inescapableGlobalProperties.WeakMap, 'function'); + t.not(inescapableGlobalProperties.WeakMap, WeakMap); + t.is(typeof inescapableGlobalProperties.WeakSet, 'function'); + t.not(inescapableGlobalProperties.WeakSet, WeakSet); +}); From 978a59ee0071f20a295e03139434d9d05e969eac Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 24 Jul 2024 12:06:05 -0400 Subject: [PATCH 4/5] change liveslots to provide passStyleOf on a symbol-named property --- packages/swingset-liveslots/src/vatDataTypes.d.ts | 1 - .../swingset-liveslots/test/test-vat-environment.js | 3 ++- packages/swingset-liveslots/tools/setup-vat-data.js | 13 +++++++++---- packages/vat-data/src/vat-data-bindings.js | 1 - 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/swingset-liveslots/src/vatDataTypes.d.ts b/packages/swingset-liveslots/src/vatDataTypes.d.ts index d1731cf0742..c417bef14fc 100644 --- a/packages/swingset-liveslots/src/vatDataTypes.d.ts +++ b/packages/swingset-liveslots/src/vatDataTypes.d.ts @@ -194,7 +194,6 @@ export type VatData = { options?: StoreOptions, ) => WeakSetStore; canBeDurable: (specimen: unknown) => boolean; - passStyleOf: (specimen: unknown) => string; }; // The JSDoc is repeated here and at the function definition so it appears diff --git a/packages/swingset-liveslots/test/test-vat-environment.js b/packages/swingset-liveslots/test/test-vat-environment.js index a6382c54a06..ed1f0caa6cc 100644 --- a/packages/swingset-liveslots/test/test-vat-environment.js +++ b/packages/swingset-liveslots/test/test-vat-environment.js @@ -31,7 +31,8 @@ test('vat globals', async t => { t.is(called, 1); t.truthy(vatGlobals); - // 'harden' is provided by SES (installed by the supervisor), not liveslots + // 'harden' is provided by SES (installed by the lockdown bundle), + // not liveslots t.is(typeof vatGlobals.harden, 'undefined'); // but liveslots provides VatData diff --git a/packages/swingset-liveslots/tools/setup-vat-data.js b/packages/swingset-liveslots/tools/setup-vat-data.js index 58e4e57269b..c3781d904ce 100644 --- a/packages/swingset-liveslots/tools/setup-vat-data.js +++ b/packages/swingset-liveslots/tools/setup-vat-data.js @@ -1,9 +1,13 @@ // @ts-check /* global globalThis */ -// This file produces the globalThis.VatData property outside of a running -// SwingSet so that it can be used by '@agoric/vat-data' (which only *consumes* -// `globalThis.VatData`) in code under test. + +// This file produces the globalThis.VatData property outside of a +// running SwingSet so that it can be used by '@agoric/vat-data' +// (which only *consumes* `globalThis.VatData`) in code under test. It +// also populates the passStyleOf symbol-named property. + import { passStyleOf } from '@endo/pass-style'; +import { PassStyleOfEndowmentSymbol } from '@endo/pass-style/endow.js'; import { makeFakeVirtualStuff } from './fakeVirtualSupport.js'; const { WeakMap, WeakSet } = globalThis; @@ -36,9 +40,10 @@ globalThis.VatData = harden({ fakeVomKit.cm.makeScalarBigSetStore(...args), makeScalarBigWeakSetStore: (...args) => fakeVomKit.cm.makeScalarBigWeakSetStore(...args), - passStyleOf, }); +globalThis[PassStyleOfEndowmentSymbol] = passStyleOf; + export const reincarnate = (options = {}) => { const { fakeStore = new Map(), fakeVomKit: fvk } = options; diff --git a/packages/vat-data/src/vat-data-bindings.js b/packages/vat-data/src/vat-data-bindings.js index 096ee374d2d..d5b214de7c0 100644 --- a/packages/vat-data/src/vat-data-bindings.js +++ b/packages/vat-data/src/vat-data-bindings.js @@ -26,7 +26,6 @@ if ('VatData' in globalThis) { makeScalarBigSetStore: unavailable, makeScalarBigWeakSetStore: unavailable, canBeDurable: unavailable, - passStyleOf: unavailable, // not exported from here in any case }; } From 9f0d4b8ef83babcf26f21ec1b75bd621e3ccc0c8 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 24 Jul 2024 13:14:44 -0400 Subject: [PATCH 5/5] move harden() back to original spot --- packages/swingset-liveslots/src/liveslots.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/swingset-liveslots/src/liveslots.js b/packages/swingset-liveslots/src/liveslots.js index e7e9d91c4f6..d5a9ac4b2d6 100644 --- a/packages/swingset-liveslots/src/liveslots.js +++ b/packages/swingset-liveslots/src/liveslots.js @@ -1320,7 +1320,7 @@ function build( syscall.dropImports([slot]); } - const vatGlobals = { + const vatGlobals = harden({ VatData: { defineKind: vom.defineKind, defineKindMulti: vom.defineKindMulti, @@ -1336,8 +1336,7 @@ function build( makeScalarBigWeakSetStore: collectionManager.makeScalarBigWeakSetStore, }, [PassStyleOfEndowmentSymbol]: passStyleOf, - }; - harden(vatGlobals); + }); const inescapableGlobalProperties = harden({ WeakMap: vom.VirtualObjectAwareWeakMap,