Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ses): Add XS variant of shim #2471

Open
wants to merge 4 commits into
base: kriskowal-xs-module-source-shim
Choose a base branch
from

Conversation

kriskowal
Copy link
Member

Closes: #2251

Description

To take advantage of native XS compartments while retaining backward compatibility and parity with the SES shim, we introduce an xs specific Compartment adapter that requires two levels of opt-in.

  1. The SES shim must be bundled with the xs package export/import condition.
  2. The constructor of a Compartment must specify the __native__ option to sacrifice the ability to use precompiled module sources (as generated by @endo/module-source without the xs package export/import condition) and instead use adapted native ModuleSource (as generated by @endo/module-source with the xs package export/import condition). This allows @endo/import-bundle, for example, to use the JSON serialization of a precompiled module source that is captured in a bundle and also opt-in for __native__ treatment if the archive/bundle contains original sources.

This change introduces an XS-specific shim that is an adapter for Compartment and lockdown, and also papers over parity gaps like the XS Object.freeze second boolean argument. The adapter creates parallel native and shim (virtual) compartment trees, where any individual Compartment can elect to use the native or shim variant for a child Compartment.

We have not yet found a workable design that obviates the need for the __native__ opt-in. Such a design would need to create an adapter from precompiled module sources to XS’s virtual module source protocol. To do that would require native module to emit notifications for the mutation of exported live bindings and also require the native Compartment evaluate method to accept an argument like the shim’s __moduleGlobalLexicals__.

Security Considerations

Uncountably numerous. Among them, with the __native__ option, censorship does not occur, so dynamic import and direct eval are possible.

Scaling Considerations

The native ModuleSource makes it practical to defer module parsing to runtime, and should improve the performance of execution as well.

Documentation Considerations

The NEWS.md qualifies these changes as under "incubation". When the shape of these changes settles, the NEWS will need to reiterate the final user facing API in README.md and NEWS.md. With the __native__ option, censorship does not occur, so dynamic import and direct eval are possible.

Testing Considerations

This change contains a token of xst testing that is exercised in CI with test:xs. This demonstrates the use of @endo/compartment-mapper/bundle.js to thread the xs package export/import condition and generate a script that can xst can run directly. This gives us some modest confidence that lockdown works and demonstrates the __native__ feature but does not provide sufficient confidence of parity for the gamut of Compartment usage, both legacy and XS, for all of the accepted module descriptors and other Compartment features. This is an exercise that will begin with a subsequent change that introduces hardened262, a comprehensive parity checking framework for the full cross-product of [ SES on Node.js, SES on XS, and XS stand-alone ] ⨉ [ Lockdown, not Lockdown ] ⨉ [ Compartment, no Compartment ] ⨉ [ Sloppy, Strict, Module ].

Compatibility Considerations

This change preserves all existing usage and introduces an unstable alternate version of SES for XS that requires two layers of opt-in. The use of the xs condition introduces an adapter for Compartment that may not have full parity with the underlying implementation, and requires additional testing. The __native__ option elects to break some usage (precompiled moduels) in favor of others (dynamic import, direct eval, top-level-await).

Upgrade Considerations

In order to realize these changes on the Agoric chain will likely require a more recent version of XS and switching the bundle format for the lockdown/bootstrap script for xsnap swingset workers.

@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 8ddbfc3 to 70beef1 Compare September 27, 2024 05:23
@kriskowal kriskowal force-pushed the kriskowal-ses-xs-shim branch 2 times, most recently from 5e2a457 to edb5c78 Compare September 27, 2024 05:34
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 70beef1 to 5342ea3 Compare October 9, 2024 06:04
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 5342ea3 to 607b4ee Compare October 17, 2024 22:54
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 607b4ee to a02438f Compare October 18, 2024 00:05
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from a02438f to 82a89a8 Compare October 18, 2024 00:50
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 82a89a8 to 84a2fb7 Compare October 18, 2024 01:18
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 84a2fb7 to c1cdb57 Compare October 18, 2024 05:40
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from c1cdb57 to 7312722 Compare October 18, 2024 19:32
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 7312722 to f8dd207 Compare October 18, 2024 19:49
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from f8dd207 to 13eb35a Compare October 18, 2024 20:01
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 13eb35a to 9f9b0ae Compare October 18, 2024 20:28
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 9f9b0ae to f6a6bac Compare October 18, 2024 20:33
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from f6a6bac to 69152ea Compare October 18, 2024 20:39
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from e853ee6 to 6375752 Compare October 18, 2024 22:45
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 6375752 to a4b58b6 Compare October 18, 2024 22:53
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from a4b58b6 to 8c51679 Compare October 18, 2024 22:57
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 8c51679 to 3b5df29 Compare October 18, 2024 22:59
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 3b5df29 to 8ca8e06 Compare October 18, 2024 23:23
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 8ca8e06 to 4a3848c Compare October 18, 2024 23:27
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 4a3848c to 6639091 Compare October 18, 2024 23:32
@kriskowal kriskowal force-pushed the kriskowal-ses-xs-shim branch 7 times, most recently from 5a01c91 to 14b0197 Compare October 19, 2024 02:58
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from 6639091 to fd90e45 Compare October 19, 2024 02:59
@kriskowal kriskowal force-pushed the kriskowal-xs-module-source-shim branch from fd90e45 to 555ea34 Compare October 19, 2024 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant