Closed oskarth closed 8 months ago
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)
}
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 https://github.com/oskarth/mopro/issues/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.
This issue can be closed with above PR #75
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
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: