Skip to content

Commit db9f326

Browse files
svpolonskyStas Polonsky
andauthored
Stas/android/parallel (#6)
* Android development: Fix NDK download, update README, and improve build scripts - Fix NDK download issue by adding --save-ndk flag to build_lib.sh - Update ExampleApp README.md with correct .zkey file placement instructions - Remove --features android flag from Rust build (not supported) - Add Java 23 support to build scripts - Move .zkey files to correct src/main/assets/ directories - Add comprehensive directory structure documentation * feat: implement parallel proof functionality for Android - Add parallel proof generation UI and logic to MainActivity - Implement JNI bridge for parallel_prove function calls - Fix critical JNI pointer array alignment issue using GetStringUTFChars - Add proper memory management for JNI string references - Update NativeBridge with parallel proof methods - Tested and verified working with up to 9 witnesses - Brings Android example app to feature parity with iOS version * add parallel proofs * better UI * restructure MainActivity.kt * PR ready * answers to PR review * Update icicle-snark submodule to latest mobile branch commit * features android support * cleaner code for setting the number of parallel proofs --------- Co-authored-by: Stas Polonsky <stas@ingonyama.com>
1 parent df5c750 commit db9f326

26 files changed

Lines changed: 3374 additions & 342 deletions

File tree

android/ExampleApp/README.md

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,56 @@
22

33
## Zkey files
44

5-
As zkey files are quite large, none of the example circuits' zkey files are part of the repo. They must be downloaded separately and added to each zkey_pack_X as follows:
5+
As zkey files are quite large, none of the example circuits' zkey files are part of the repo. They must be downloaded separately and placed in the correct directory structure for Android asset packs.
66

7-
- zkey_pack_0 should contain:
7+
### Important: Correct Directory Structure
8+
9+
The .zkey files must be placed in the `src/main/assets/` subdirectory within each zkey_pack directory:
10+
11+
```
12+
ExampleApp/
13+
├── zkey_pack_0/
14+
│ └── src/main/assets/
15+
│ ├── 100k_circuit_final.zkey
16+
│ ├── 200k_circuit_final.zkey
17+
│ └── 400k_circuit_final.zkey
18+
├── zkey_pack_1/
19+
│ └── src/main/assets/
20+
│ ├── 800k_circuit_final.zkey
21+
│ ├── 1600k_circuit_final.zkey
22+
│ ├── keccak_circuit_final.zkey
23+
│ └── sha256_circuit_final.zkey
24+
├── zkey_pack_rarimo/
25+
│ └── src/main/assets/
26+
│ └── rarimo_circuit_final.zkey
27+
└── zkey_pack_zkp2p/
28+
└── src/main/assets/
29+
├── aes_128_ctr_circuit_final.zkey
30+
├── aes_256_ctr_circuit_final.zkey
31+
└── chacha20_circuit_final.zkey
32+
```
33+
34+
### Required Files by Asset Pack
35+
36+
- **zkey_pack_0** should contain in `src/main/assets/`:
837
- 100k_circuit_final.zkey
938
- 200k_circuit_final.zkey
1039
- 400k_circuit_final.zkey
11-
- zkey_pack_1 should contain:
40+
- **zkey_pack_1** should contain in `src/main/assets/`:
1241
- 800k_circuit_final.zkey
1342
- 1600k_circuit_final.zkey
1443
- keccak_circuit_final.zkey
1544
- sha256_circuit_final.zkey
16-
- zkey_pack_rarimo should contain:
45+
- **zkey_pack_rarimo** should contain in `src/main/assets/`:
1746
- rarimo_circuit_final.zkey
18-
- zkey_pack_zkp2p should contain:
47+
- **zkey_pack_zkp2p** should contain in `src/main/assets/`:
1948
- aes_128_ctr_circuit_final.zkey
2049
- aes_256_ctr_circuit_final.zkey
2150
- chacha20_circuit_final.zkey
2251

52+
### Note
53+
The .wtns and .json files are placed in the main app's assets directory (`app/src/main/assets/`), while the .zkey files go in the asset pack directories as shown above.
54+
2355
## Build
2456

2557
Use the [build_example_app](../scripts/build_example_app.sh) to build the app for both debug and release buildTypes.
-372 KB
Binary file not shown.
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
package com.ingonyama.imp1_aar_example
2+
3+
/**
4+
* Centralized constants for the IMP1 Android example app.
5+
* This file contains all magic numbers, strings, and configuration values
6+
* used throughout the application to improve maintainability.
7+
*/
8+
object Constants {
9+
10+
// ============================================================================
11+
// PARALLEL PROOF CONFIGURATION
12+
// ============================================================================
13+
14+
/** Minimum number of parallel proofs allowed */
15+
const val MIN_PARALLEL_PROOFS = 1
16+
17+
/** Maximum number of parallel proofs allowed */
18+
const val MAX_PARALLEL_PROOFS = 50
19+
20+
/** Default number of parallel proofs */
21+
const val DEFAULT_PARALLEL_PROOFS = 2
22+
23+
// ============================================================================
24+
// FILE EXTENSIONS AND PATTERNS
25+
// ============================================================================
26+
27+
/** File extension for proof files */
28+
const val PROOF_FILE_EXTENSION = ".proof"
29+
30+
/** File extension for public input files */
31+
const val PUBLIC_FILE_EXTENSION = ".public"
32+
33+
/** File extension for witness files */
34+
const val WITNESS_FILE_EXTENSION = ".wtns"
35+
36+
/** File extension for zkey files */
37+
const val ZKEY_FILE_EXTENSION = ".zkey"
38+
39+
/** File extension for verification key files */
40+
const val VK_FILE_EXTENSION = ".json"
41+
42+
// ============================================================================
43+
// DEFAULT FILE NAMES
44+
// ============================================================================
45+
46+
/** Default witness file name */
47+
const val DEFAULT_WITNESS_FILE = "witness.wtns"
48+
49+
/** Default zkey file name */
50+
const val DEFAULT_ZKEY_FILE = "zkey.zkey"
51+
52+
/** Default verification key file name */
53+
const val DEFAULT_VK_FILE = "vk.json"
54+
55+
/** Default proof file name */
56+
const val DEFAULT_PROOF_FILE = "test.proof"
57+
58+
/** Default public file name */
59+
const val DEFAULT_PUBLIC_FILE = "test.public"
60+
61+
// ============================================================================
62+
// PARALLEL FILE NAMING PATTERNS
63+
// ============================================================================
64+
65+
/** Pattern for parallel witness files */
66+
const val PARALLEL_WITNESS_PATTERN = "witness_%d.wtns"
67+
68+
/** Pattern for parallel proof files */
69+
const val PARALLEL_PROOF_PATTERN = "proof_%d.proof"
70+
71+
/** Pattern for parallel public files */
72+
const val PARALLEL_PUBLIC_PATTERN = "public_%d.public"
73+
74+
75+
// ============================================================================
76+
// LOG MESSAGES
77+
// ============================================================================
78+
79+
/** Log message for starting test */
80+
const val LOG_STARTING_TEST = "Starting test for: %s"
81+
82+
/** Log message for starting parallel test */
83+
const val LOG_STARTING_PARALLEL_TEST = "Starting parallel proof test for: %s"
84+
85+
/** Log message for number of parallel proofs */
86+
const val LOG_NUM_PARALLEL_PROOFS = "Number of parallel proofs: %d"
87+
88+
/** Log message for copying assets */
89+
const val LOG_COPYING_ASSETS = "Copying assets to device storage..."
90+
91+
/** Log message for copying complete */
92+
const val LOG_COPYING_COMPLETE = "...copying complete."
93+
94+
/** Log message for running prover */
95+
const val LOG_RUNNING_PROVER = "\nRunning Prover..."
96+
97+
/** Log message for running parallel prover */
98+
const val LOG_RUNNING_PARALLEL_PROVER = "\nRunning Parallel Prover..."
99+
100+
/** Log message for running verifier */
101+
const val LOG_RUNNING_VERIFIER = "\nRunning Verifier..."
102+
103+
/** Log message for running verifier for all proofs */
104+
const val LOG_RUNNING_VERIFIER_ALL = "\nRunning Verifier for all proofs..."
105+
106+
/** Log message for prove success */
107+
const val LOG_PROVE_SUCCESS = "✅ Prove SUCCESSFUL"
108+
109+
/** Log message for parallel prove completed */
110+
const val LOG_PARALLEL_PROVE_COMPLETED = "✅ Parallel Prove completed"
111+
112+
/** Log message for verify success */
113+
const val LOG_VERIFY_SUCCESS = "✅ Verify SUCCESSFUL"
114+
115+
/** Log message for verify failed */
116+
const val LOG_VERIFY_FAILED = "❌ Verify FAILED"
117+
118+
/** Log message for verification completed */
119+
const val LOG_VERIFICATION_COMPLETED = "✅ Verification completed"
120+
121+
/** Log message for prove failed */
122+
const val LOG_PROVE_FAILED = "❌ Prove FAILED"
123+
124+
/** Log message for parallel prove failed */
125+
const val LOG_PARALLEL_PROVE_FAILED = "❌ Parallel Prove FAILED"
126+
127+
/** Log message for critical file error */
128+
const val LOG_CRITICAL_FILE_ERROR = "\n❌ CRITICAL ERROR: Could not copy asset files."
129+
130+
/** Log message for file error instructions */
131+
const val LOG_FILE_ERROR_INSTRUCTIONS = " Make sure the filenames in the `examples` list are correct."
132+
133+
/** Log message for time taken */
134+
const val LOG_TIME_TAKEN = " Time taken: %d ms"
135+
136+
/** Log message for runtime */
137+
const val LOG_RUNTIME = " Runtime: %s"
138+
139+
/** Log message for error details */
140+
const val LOG_ERROR_DETAILS = " Error: %s"
141+
142+
/** Log message for proof success */
143+
const val LOG_PROOF_SUCCESS = "✅ Proof %d: Success"
144+
145+
/** Log message for proof failed */
146+
const val LOG_PROOF_FAILED = "❌ Proof %d: Failed"
147+
148+
/** Log message for proof unknown result */
149+
const val LOG_PROOF_UNKNOWN = "❓ Proof %d: Unknown result"
150+
151+
/** Log message for proof verified */
152+
const val LOG_PROOF_VERIFIED = "✅ Proof %d: Verified"
153+
154+
/** Log message for proof verification failed */
155+
const val LOG_PROOF_VERIFICATION_FAILED = "❌ Proof %d: Verification Failed"
156+
157+
// ============================================================================
158+
// ASSET PACK STATUS MESSAGES
159+
// ============================================================================
160+
161+
/** Status message for all packs ready */
162+
const val STATUS_ALL_PACKS_READY = "All asset packs ready (%d/%d)"
163+
164+
/** Status message for downloading packs */
165+
const val STATUS_DOWNLOADING_PACKS = "Downloading asset packs: %d%% (%d/%d ready)"
166+
167+
/** Status message for failed downloads */
168+
const val STATUS_DOWNLOADS_FAILED = "Some asset pack downloads failed (%d/%d ready)"
169+
170+
/** Status message for checking packs */
171+
const val STATUS_CHECKING_PACKS = "Checking asset packs... (%d/%d ready)"
172+
173+
// ============================================================================
174+
// TIME FORMATTING
175+
// ============================================================================
176+
177+
/** Time threshold for milliseconds display (ms) */
178+
const val TIME_MS_THRESHOLD = 1000.0
179+
180+
181+
/** Time threshold for seconds display (ms) */
182+
const val TIME_SECONDS_THRESHOLD = 60000.0
183+
184+
/** Milliseconds per second */
185+
const val MS_PER_SECOND = 1000.0
186+
187+
/** Milliseconds per minute */
188+
const val MS_PER_MINUTE = 60000.0
189+
190+
/** Time format for milliseconds */
191+
const val TIME_FORMAT_MS = "%.1f ms"
192+
193+
/** Time format for seconds */
194+
const val TIME_FORMAT_SECONDS = "%.2f seconds"
195+
196+
/** Time format for minutes and seconds */
197+
const val TIME_FORMAT_MINUTES_SECONDS = "%d minutes %.2f seconds"
198+
199+
// ============================================================================
200+
// JNI RESULT VALUES
201+
// ============================================================================
202+
203+
/** JNI success result value */
204+
const val JNI_SUCCESS = 0
205+
206+
/** JNI failure result value */
207+
const val JNI_FAILURE = 1
208+
209+
// ============================================================================
210+
// UI ALPHA VALUES
211+
// ============================================================================
212+
213+
/** Alpha value for enabled UI elements */
214+
const val UI_ALPHA_ENABLED = 1.0f
215+
216+
/** Alpha value for disabled UI elements */
217+
const val UI_ALPHA_DISABLED = 0.3f
218+
219+
// ============================================================================
220+
// COROUTINE NAMES
221+
// ============================================================================
222+
223+
/** Coroutine name for single proof operations */
224+
const val COROUTINE_NAME_SINGLE_PROOF = "IMP1 Single Proof"
225+
226+
/** Coroutine name for parallel proof operations */
227+
const val COROUTINE_NAME_PARALLEL_PROOF = "IMP1 Parallel Proof"
228+
}

0 commit comments

Comments
 (0)