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

test: wasm memory object config tests #12

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const nextConfig = {

### Instantiating a new web assembly instance.

If you are using the web bundle, you will first need to initialize a web assembly module before you can use any of the methods exposed by the engine. To do this import the default export from `@ezkljs/engine/web/ezkl.js` and then call it. If you want to overide the default WASM memory size, you can pass in a WebAssembly.Memory object as the second argument. We highly recommend doing this if you want your application to be compatible with mobile browsers, as the default memory allocation is too large for iOS browsers. From our experimentation, we have found that the maximum memory allocation that iOS browsers can handle is 1024 mb (default is 65536 mb).
If you are using the web bundle, you will first need to initialize a web assembly module before you can use any of the methods exposed by the engine. To do this import the default export from `@ezkljs/engine/web/ezkl.js` and then call it. If you want to overide the default WASM memory size, you can pass in a WebAssembly.Memory object as the second argument. We highly recommend doing this if you want your application to be compatible with mobile browsers, as the default memory allocation is too large for iOS browsers. From our experimentation, we have found that the maximum memory allocation that iOS browsers can handle is 4096 mb (default is 65536 mb).

```typescript

Expand All @@ -84,7 +84,7 @@ export default function Home() {
useEffect(() => {
async function run() {
// Initialize the WASM module. Here we are overiding the default memory allocation with the recommend allocation for the best performance across all mobile browsers.
await init(undefined, new WebAssembly.Memory({initial:20,maximum:1024,shared:true}))
await init(undefined, new WebAssembly.Memory({initial:20,maximum:4096,shared:true}))
}
run()
})
Expand Down
142 changes: 95 additions & 47 deletions app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function Home() {
useEffect(() => {
async function run() {
// Initialize the WASM module
await init(undefined, new WebAssembly.Memory({initial:20,maximum:1024,shared:true}))
await init(undefined, new WebAssembly.Memory({initial:20,maximum:4096,shared:true}))
}
run()
})
Expand All @@ -34,7 +34,7 @@ export default function Home() {
setFiles((prevFiles) => ({ ...prevFiles, [id]: file }))
}

async function populateWithSampleFiles() {
async function populateWithSampleFiles(MNIST: boolean = false) {

const sampleFiles: Files = {};

Expand Down Expand Up @@ -63,50 +63,97 @@ export default function Home() {
const rBlob: Blob = await rResponse.blob();
sampleFiles['elgamal_r'] = new File([rBlob], "elgamal_r.txt");

// Fetch the data_prove.txt file
const dataProveResponse = await fetch('/data/test.witness.json');
const dataProveBlob: Blob = await dataProveResponse.blob();
sampleFiles['data_prove'] = new File([dataProveBlob], "data_prove.txt");

// Fetch the pk_prove.txt file
const pkProveResponse = await fetch('/data/test.provekey');
const pkProveBlob: Blob = await pkProveResponse.blob();
sampleFiles['pk_prove'] = new File([pkProveBlob], "pk_prove.txt");

// Fetch the model_ser_prove.txt file
const modelSerProveResponse = await fetch('/data/test_network.compiled');
const modelSerProveBlob: Blob = await modelSerProveResponse.blob();
sampleFiles['model_ser_prove'] = new File([modelSerProveBlob], "model_ser_prove.txt");

// Fetch the circuit_settings_ser_prove.txt file
const circuitSettingsSerProveResponse = await fetch('/data/settings.json');
const circuitSettingsSerProveBlob: Blob = await circuitSettingsSerProveResponse.blob();
sampleFiles['circuit_settings_ser_prove'] = new File([circuitSettingsSerProveBlob], "circuit_settings_ser_prove.txt");

// Fetch the srs_ser_prove.txt file
const srsSerProveResponse = await fetch('/data/kzg');
const srsSerProveBlob: Blob = await srsSerProveResponse.blob();
sampleFiles['srs_ser_prove'] = new File([srsSerProveBlob], "srs_ser_prove.txt");

// Fetch the proof_js.txt file
const proofJsResponse = await fetch('/data/test.proof');
const proofJsBlob: Blob = await proofJsResponse.blob();
sampleFiles['proof_js'] = new File([proofJsBlob], "proof_js.txt");

// Fetch the vk.txt file
const vkResponse = await fetch('/data/test.key');
const vkBlob: Blob = await vkResponse.blob();
sampleFiles['vk'] = new File([vkBlob], "vk.txt");

// Fetch the circuit_settings_ser_verify.txt file
const circuitSettingsSerVerifyResponse = await fetch('/data/settings.json');
const circuitSettingsSerVerifyBlob: Blob = await circuitSettingsSerVerifyResponse.blob();
sampleFiles['circuit_settings_ser_verify'] = new File([circuitSettingsSerVerifyBlob], "circuit_settings_ser_verify.txt");

// Fetch the srs_ser_verify.txt file
const srsSerVerifyResponse = await fetch('/data/kzg');
const srsSerVerifyBlob: Blob = await srsSerVerifyResponse.blob();
sampleFiles['srs_ser_verify'] = new File([srsSerVerifyBlob], "srs_ser_verify.txt");
if(MNIST) {
// Fetch the data_prove.txt file
const dataProveResponse = await fetch('/data/mnist/witness.json');
const dataProveBlob: Blob = await dataProveResponse.blob();
sampleFiles['data_prove'] = new File([dataProveBlob], "data_prove.txt");

// Fetch the pk_prove.txt file
const pkProveResponse = await fetch('/data/mnist/key.pk');
const pkProveBlob: Blob = await pkProveResponse.blob();
sampleFiles['pk_prove'] = new File([pkProveBlob], "pk_prove.txt");

// Fetch the model_ser_prove.txt file
const modelSerProveResponse = await fetch('/data/mnist/compiled_net.onnx');
const modelSerProveBlob: Blob = await modelSerProveResponse.blob();
sampleFiles['model_ser_prove'] = new File([modelSerProveBlob], "model_ser_prove.txt");

// Fetch the circuit_settings_ser_prove.txt file
const circuitSettingsSerProveResponse = await fetch('/data/mnist/settings.json');
const circuitSettingsSerProveBlob: Blob = await circuitSettingsSerProveResponse.blob();
sampleFiles['circuit_settings_ser_prove'] = new File([circuitSettingsSerProveBlob], "circuit_settings_ser_prove.txt");

// Fetch the srs_ser_prove.txt file
const srsSerProveResponse = await fetch('/data/mnist/srs-10');
const srsSerProveBlob: Blob = await srsSerProveResponse.blob();
sampleFiles['srs_ser_prove'] = new File([srsSerProveBlob], "srs_ser_prove.txt");

// Fetch the proof_js.txt file
const proofJsResponse = await fetch('/data/mnist/proof.pf');
const proofJsBlob: Blob = await proofJsResponse.blob();
sampleFiles['proof_js'] = new File([proofJsBlob], "proof_js.txt");

// Fetch the vk.txt file
const vkResponse = await fetch('/data/mnist/key.vk');
const vkBlob: Blob = await vkResponse.blob();
sampleFiles['vk'] = new File([vkBlob], "vk.txt");

// Fetch the circuit_settings_ser_verify.txt file
const circuitSettingsSerVerifyResponse = await fetch('/data/mnist/settings.json');
const circuitSettingsSerVerifyBlob: Blob = await circuitSettingsSerVerifyResponse.blob();
sampleFiles['circuit_settings_ser_verify'] = new File([circuitSettingsSerVerifyBlob], "circuit_settings_ser_verify.txt");

// Fetch the srs_ser_verify.txt file
const srsSerVerifyResponse = await fetch('/data/mnist/srs-10');
const srsSerVerifyBlob: Blob = await srsSerVerifyResponse.blob();
sampleFiles['srs_ser_verify'] = new File([srsSerVerifyBlob], "srs_ser_verify.txt");
} else {
// Fetch the data_prove.txt file
const dataProveResponse = await fetch('/data/test.witness.json');
const dataProveBlob: Blob = await dataProveResponse.blob();
sampleFiles['data_prove'] = new File([dataProveBlob], "data_prove.txt");

// Fetch the pk_prove.txt file
const pkProveResponse = await fetch('/data/test.provekey');
const pkProveBlob: Blob = await pkProveResponse.blob();
sampleFiles['pk_prove'] = new File([pkProveBlob], "pk_prove.txt");

// Fetch the model_ser_prove.txt file
const modelSerProveResponse = await fetch('/data/test_network.compiled');
const modelSerProveBlob: Blob = await modelSerProveResponse.blob();
sampleFiles['model_ser_prove'] = new File([modelSerProveBlob], "model_ser_prove.txt");

// Fetch the circuit_settings_ser_prove.txt file
const circuitSettingsSerProveResponse = await fetch('/data/settings.json');
const circuitSettingsSerProveBlob: Blob = await circuitSettingsSerProveResponse.blob();
sampleFiles['circuit_settings_ser_prove'] = new File([circuitSettingsSerProveBlob], "circuit_settings_ser_prove.txt");

// Fetch the srs_ser_prove.txt file
const srsSerProveResponse = await fetch('/data/kzg');
const srsSerProveBlob: Blob = await srsSerProveResponse.blob();
sampleFiles['srs_ser_prove'] = new File([srsSerProveBlob], "srs_ser_prove.txt");

// Fetch the proof_js.txt file
const proofJsResponse = await fetch('/data/test.proof');
const proofJsBlob: Blob = await proofJsResponse.blob();
sampleFiles['proof_js'] = new File([proofJsBlob], "proof_js.txt");

// Fetch the vk.txt file
const vkResponse = await fetch('/data/test.key');
const vkBlob: Blob = await vkResponse.blob();
sampleFiles['vk'] = new File([vkBlob], "vk.txt");

// Fetch the circuit_settings_ser_verify.txt file
const circuitSettingsSerVerifyResponse = await fetch('/data/settings.json');
const circuitSettingsSerVerifyBlob: Blob = await circuitSettingsSerVerifyResponse.blob();
sampleFiles['circuit_settings_ser_verify'] = new File([circuitSettingsSerVerifyBlob], "circuit_settings_ser_verify.txt");

// Fetch the srs_ser_verify.txt file
const srsSerVerifyResponse = await fetch('/data/kzg');
const srsSerVerifyBlob: Blob = await srsSerVerifyResponse.blob();
sampleFiles['srs_ser_verify'] = new File([srsSerVerifyBlob], "srs_ser_verify.txt");
}

// Fetch the message_hash.txt file
const messageHashResponse = await fetch('/data/message.txt');
Expand Down Expand Up @@ -143,7 +190,8 @@ export default function Home() {

return (
<div className='App'>
<button onClick={populateWithSampleFiles}>Populate with sample files</button>
<button onClick={() => populateWithSampleFiles()}>Populate with sample files</button>
<button onClick={() => populateWithSampleFiles(true)}>Populate with sample MNIST files</button>

<GenWitness
files={{
Expand Down
Binary file added public/data/mnist/compiled_net.onnx
Binary file not shown.
Loading