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

[Feature] Async parameter preloading #1987

Open
wants to merge 19 commits into
base: testnet3
Choose a base branch
from

Conversation

iamalwaysuncomfortable
Copy link
Contributor

@iamalwaysuncomfortable iamalwaysuncomfortable commented Sep 15, 2023

Motivation

Currently parameter downloads in SnarkVM in a wasm environment use a synchronous version of XmlHttpRequest to download parameters. However this has been considered deprecated behavior for browsers for a long time and enforce suboptimal restrictions on them. Further, upcoming changes to Chrome Manifest v3 are not allowing XmlHttpRequest to be used in chrome extensions whatsoever and are enforcing the move to fetch.

Chrome manifest V3 changes are explained here

This has the following consequences for parameter & key downloads during program execution:

  1. Downloads have 3x Memory Footprint: XmlHttpRequest in syncronous mode only allows text encodings (byte encodings are not allowed by modern browsers in synchronous mode). This has the effect of requiring the 3x the memory (i.e. a 250mb proving key requires 750mb memory reserved in wasm for the download) and degrading end user experience in both performance & time waiting for network i/o.
  2. Chrome Extension Support is currently limited: Because XmlHttpRequest is deprecated for new chrome apps, chrome extensions which perform executions that involve parameter or key downloads will not be able to built without resorting to suboptimal techniques such as popup windows.
  3. Risk of deprecation: If web browsers decide to eliminate support for synchronous XmlHttpRequest, parameter downloads will cease to work in the web.

To support modern web standards & enable future chrome apps to be built on Aleo, this PR introduces an option to download necessary powers asynchronously prior to program execution. The asynchronous downloads use the reqwest library which uses fetch under the hood in wasm environments (therefore eliminating reliance on XmlHttpRequest) and enables bytes to be downloaded directly without needing a conversion to text encoding beforehand.

This enables both Chrome extensions & NodeJS to perform a normal synchronous execution flow without having to reach out to the web for parameters during execution. Acceptance of the asynchronous download path in this PR would reduce wasm memory needed by 3x, enable support for modern chrome extensions, de-risk possible future deprecation of synchronous XmlHttpRequests in web browsers. Further, the option to use fetch (instead of XmlHttpRequest) for parameter downloads enables Aleo program key synthesis & Deployment within NodeJS.

Test Plan

Tests to test changes made in order to support this have have been added as well as a test demonstrating program execution in wasm after parameter pre-downloads

Related PRs

https://github.com/AleoHQ/snarkVM/pull/1955 proposes a single committer key. In #1955 - ProvingKeys don't contain CommiterKeys (this is delegated to a UniversalProver). ProvingKeys will continue to contain Degree Information required to download parameters for the Universal Prover and the preload_powers method in this PR would be provide a Browser/Wasm friendly path for downloading these parameters.

algorithms/src/polycommit/kzg10/data_structures.rs Outdated Show resolved Hide resolved
parameters/src/testnet3/powers.rs Show resolved Hide resolved
wasm/src/tests.rs Outdated Show resolved Hide resolved
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.

None yet

3 participants