forked from bellard/quickjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Deterministic init #1
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
Open
mjwebblue
wants to merge
19
commits into
master
Choose a base branch
from
deterministic-init
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…on features This commit introduces a new deterministic runtime in QuickJS, allowing for controlled execution by disabling the 'eval' and 'Function' features. It includes functions to initialize the deterministic context and define properties for the host environment. The changes enhance the runtime's capabilities for deterministic execution scenarios.
This commit extends the deterministic runtime by introducing a mechanism to disable the 'Math.random' function. It includes a new function to handle the disabling and updates the context initialization to incorporate this feature, enhancing the control over random number generation in deterministic execution scenarios.
This commit introduces a new feature to the deterministic runtime in QuickJS, allowing the 'Promise' constructor to be disabled. It includes a function to handle the disabling and updates the context initialization to incorporate this feature, enhancing control over asynchronous operations in deterministic execution scenarios.
…time This commit enhances the deterministic runtime in QuickJS by introducing the ability to disable the 'RegExp' and 'Proxy' constructors. It includes functions to handle the disabling of these features and updates the context initialization accordingly, providing greater control over the execution environment in deterministic scenarios.
…s in deterministic runtime This commit enhances the deterministic runtime in QuickJS by introducing the ability to disable Typed Arrays, WebAssembly, and Atomics. It includes new functions to handle the disabling of these features and updates the context initialization accordingly, providing greater control over the execution environment in deterministic scenarios.
…ntime This commit enhances the deterministic runtime in QuickJS by introducing the ability to disable the 'console' and 'print' features. It includes new functions to handle the disabling of these features and updates the context initialization accordingly, providing greater control over the execution environment in deterministic scenarios.
This commit enhances the deterministic runtime in QuickJS by introducing the ability to prevent extensions on host objects. It includes checks to ensure that extensions are disabled during context initialization, further improving control over the execution environment in deterministic scenarios.
This commit adds a gas management system to the QuickJS runtime, allowing for resource usage tracking and control. It introduces new functions to set gas limits, check remaining gas, and handle out-of-gas scenarios. The changes enhance the deterministic runtime by providing mechanisms to prevent excessive resource consumption during execution, improving overall control in deterministic environments.
This commit enhances the QuickJS runtime by introducing gas allocation tracking in memory management functions. It adds a mechanism to charge gas for memory allocations, preventing excessive resource consumption. The changes include new functions for calculating gas costs and handling out-of-gas scenarios, improving control over resource usage in deterministic environments.
This commit introduces new features to the QuickJS deterministic runtime, including support for a checkpoint-based garbage collection mechanism. It adds fields to track the state of deterministic garbage collection and modifies the garbage collection trigger to respect the deterministic mode. Additionally, a new function, JS_RunGCCheckpoint, is implemented to manage garbage collection in a controlled manner, improving resource management in deterministic environments.
This commit introduces a gas tracing system to the QuickJS runtime, allowing for detailed tracking of gas usage during execution. It adds a new structure, JSGasTraceData, to store gas usage metrics, and functions to enable, reset, and read gas trace data. The changes enhance resource management by providing insights into gas consumption for opcode execution, array callbacks, and memory allocations, improving control in deterministic environments.
This commit updates the gas tracing functionality in the QuickJS runtime by replacing the direct memory reset with a call to the new function js_gas_trace_reset_counts. This change improves code clarity and ensures that gas trace counts are reset correctly, enhancing the overall reliability of the gas tracing system.
Add a Deterministic Values (DV) codec to the QuickJS fork. - Add quickjs-dv.c implementing JS_EncodeDV / JS_DecodeDV for a restricted CBOR subset (null/bool/finite numbers, UTF-8 text, arrays, plain objects as maps). - Enforce canonical encoding: shortest-length integers, float64-only (no non-finite), no indefinite lengths, canonical map key ordering, and duplicate key rejection. - Add public API types JSDvLimits/JSDvBuffer, defaults (JS_DV_LIMIT_DEFAULTS), and JS_FreeDVBuffer for output ownership cleanup. - Validate UTF-8 and normalize -0 to 0 for deterministic round-trips.
…check Introduce JS_InitDeterministicContext() and JSDeterministicInitOptions to initialize a deterministic JSContext from an ABI manifest + optional context blob and gas limit. Validate manifest size and required hash, compute/compare SHA-256, throw a ManifestError (ABI_MANIFEST_HASH_MISMATCH) on mismatch, and store owned copies on the context (freed in JS_FreeContext). Add internal SHA-256 helpers and link quickjs-dv/quickjs-sha256 into the QuickJS lib build.
…t + reentrancy guard) - add JS_SetHostCallDispatcher() and JS_HostCall() public API, including JSHostCallFunc/JSHostCallResult and JS_HOST_CALL_TRANSPORT_ERROR - implement host_call plumbing in deterministic runtime with per-context scratch response buffer + bounds/limit checks - on Emscripten, default dispatcher calls imported host.host_call; otherwise dispatcher is unset by default - prevent reentrant host calls via rt->in_host_call and free host_call response buffer on context teardown
Add `quickjs-host.{c,h}` implementing `HostError` construction and host response envelope parsing (T-039), including DV decode, strict envelope validation, units bounds checks, and whitelisted error code→tag mapping.
- Wire `quickjs-host.o` into `QJS_LIB_OBJS`
- Use `JS_ThrowHostTransportError()` instead of a generic `TypeError` on transport failure
Refs: T-039
…host bindings (T-040) - add DV manifest parser + validation (sorted fn_id, js_path collision checks, reserved error codes) - generate/install Host.v1 namespaces + per-function CFunction wrappers with pre/post gas charging - validate args/return types (string/null/dv) and enforce per-arg utf8 limits - expose host lifecycle API: JS_InitHostFromManifest / JS_FreeHostManifest - init deterministic contexts from manifest and free manifest state on JS_FreeContext - prevent extensions on Host namespaces created from the manifest Refs: T-040
…text blob (T-041)
- add JS_InitErgonomicGlobals() to install:
- global document() wrapper + document.canonical() backed by Host.v1.document.{get,getCanonical}
- global canon.{unwrap,at} for canonical DV clone+freeze and safe path lookup
- global event/eventCanonical/steps decoded from context blob (deep-frozen)
- implement deep freeze utilities and canonical clone via DV roundtrip
- wire ergonomic globals init into JS_InitDeterministicContext when a context blob is provided
Refs: T-041
…(T-043) - quickjs-host: store per-context tape state alongside the loaded host manifest - add tape API: JS_EnableHostTape / JS_ResetHostTape / JS_GetHostTapeLength / JS_ReadHostTape - record Host.v1 call metadata (fn_id, req/resp lengths, units, is_error, charge_failed) - hash request/response bytes (sha256) and record computed pre/post gas charges - ensure tape memory is freed with JS_FreeHostManifest Refs: T-043
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.