snarkVM
snarkVM copied to clipboard
[Feature] Async parameter preloading
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:
- 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
wasmfor the download) and degrading end user experience in both performance & time waiting for network i/o. - 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.
- 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.