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

Try loading (ark)zkey into app after the fact #65

Closed
Tracked by #57
oskarth opened this issue Jan 30, 2024 · 2 comments
Closed
Tracked by #57

Try loading (ark)zkey into app after the fact #65

oskarth opened this issue Jan 30, 2024 · 2 comments
Labels
moperf Project MoPerf

Comments

@oskarth
Copy link
Collaborator

oskarth commented Jan 30, 2024

Problem

Currently we are reading in the arkzkey into the mopro-core library directly: https://github.com/oskarth/mopro/blob/main/mopro-core/src/middleware/circom/mod.rs#L68

While this might be faster, it is less than ideal for very big circuits. Ideally we can download these after the fact and load them in.

This would also increase flexibility a bit in terms of other circuits being used.

There might be complications with doing it this way, in terms of performance (load time) and compliance (what exactly can we load in to app after the binary? executable code etc...).

Acceptance criteria

  • Simple PoC of above (can mock download)
  • Feasibility of above (both in terms of perf and compliance)

Notes

Max iPhone app size seems to be 500mb https://developer.apple.com/help/app-store-connect/reference/maximum-build-file-sizes/

File size vs constraints:

➜  target git:(main) ✗ ls -lhS *final*zkey | awk '{print $5, $9}'
751M complex-circuit-1600k-1600k_final.zkey
455M complex-circuit-1600k-1600k_final.arkzkey
375M complex-circuit-800k-800k_final.zkey
227M complex-circuit-800k-800k_final.arkzkey
188M complex-circuit-400k-400k_final.zkey
114M complex-circuit-400k-400k_final.arkzkey
94M complex-circuit-200k-200k_final.zkey
57M complex-circuit-200k-200k_final.arkzkey
47M complex-circuit-100k-100k_final.zkey
28M complex-circuit-100k-100k_final.arkzkey
@oskarth
Copy link
Collaborator Author

oskarth commented Feb 1, 2024

Rough sketch

Something (very rough) like this should work:

#[cfg(feature = "use_external_zkey")]
fn load_zkey_from_file() -> Result<(ProvingKey<Bn254>, ConstraintMatrices<Fr>), MoproError> {
    let zkey_path = "path/to/your/zkey/file";
    let mut file = File::open(zkey_path).map_err(|e| MoproError::IoError(e.to_string()))?;
    read_arkzkey_from_file(&mut file).map_err(|e| MoproError::CircomError(e.to_string()))
}

#[cfg(not(feature = "use_external_zkey"))]
static ARKZKEY: Lazy<(ProvingKey<Bn254>, ConstraintMatrices<Fr>)> = Lazy::new(|| {
    read_arkzkey_from_bytes(ARKZKEY_BYTES).expect("Failed to read arkzkey")
});

#[must_use]
pub fn arkzkey() -> Result<(ProvingKey<Bn254>, ConstraintMatrices<Fr>), MoproError> {
    #[cfg(feature = "use_external_zkey")]
    return load_zkey_from_file();

    #[cfg(not(feature = "use_external_zkey"))]
    Ok(*ARKZKEY)
}

Things to check

  1. Implement above and make sure it works on a real device (ideally disconnected) iOS device

  2. Check how long it takes to read in file (related to Improve zkey load time #25) for reasonable sized circuit

  3. iOS App Review

From what I can tell it should be ok with zkey since it is just data not code. But if they are very strict they might say app doesn't work without external data. I think this is out of scope of current effort, but something to be mindful of in terms of releasing a production app. It might also be arbitrary and require some back and forth with Apple (common when releasing iOS apps).

From https://developer.apple.com/app-store/review/guidelines/#software-requirements:

2.5.2ASR & NR Apps should be self-contained in their bundles, and may not read or write data outside the designated container area, nor may they download, install, or execute code which introduces or changes features or functionality of the app, including other apps. Educational apps designed to teach, develop, or allow students to test executable code may, in limited circumstances, download code provided that such code is not used for other purposes. Such apps must make the source code provided by the app completely viewable and editable by the user.

@oskarth
Copy link
Collaborator Author

oskarth commented Feb 23, 2024

This issue can be closed with above PR #75

@oskarth oskarth closed this as completed Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
moperf Project MoPerf
Projects
None yet
Development

No branches or pull requests

1 participant