-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: seperate multiplier and keccak proof
- Loading branch information
1 parent
04fdba0
commit 2e82854
Showing
3 changed files
with
450 additions
and
344 deletions.
There are no files selected for viewing
349 changes: 349 additions & 0 deletions
349
templates/mopro-example-app/android/app/src/main/java/com/example/mopro/KeccakComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,349 @@ | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import uniffi.mopro.GenerateProofResult | ||
import uniffi.mopro.generateProof2 | ||
import uniffi.mopro.initializeMopro | ||
import uniffi.mopro.verifyProof2 | ||
|
||
@Composable | ||
fun KeccakComponent() { | ||
var initTime by remember { mutableStateOf("init time:") } | ||
var provingTime by remember { mutableStateOf("proving time:") } | ||
var verifyingTime by remember { mutableStateOf("verifying time: ") } | ||
var valid by remember { mutableStateOf("valid:") } | ||
var res by remember { | ||
mutableStateOf<GenerateProofResult>( | ||
GenerateProofResult(proof = ByteArray(size = 0), inputs = ByteArray(size = 0)) | ||
) | ||
} | ||
|
||
val inputs = mutableMapOf<String, List<String>>() | ||
inputs["in"] = | ||
listOf( | ||
"0", | ||
"0", | ||
"1", | ||
"0", | ||
"1", | ||
"1", | ||
"1", | ||
"0", | ||
"1", | ||
"0", | ||
"1", | ||
"0", | ||
"0", | ||
"1", | ||
"1", | ||
"0", | ||
"1", | ||
"1", | ||
"0", | ||
"0", | ||
"1", | ||
"1", | ||
"1", | ||
"0", | ||
"0", | ||
"0", | ||
"1", | ||
"0", | ||
"1", | ||
"1", | ||
"1", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0", | ||
"0" | ||
) | ||
|
||
Box(modifier = Modifier.fillMaxSize().padding(16.dp), contentAlignment = Alignment.Center) { | ||
Button( | ||
onClick = { | ||
Thread( | ||
Runnable { | ||
val startTime = System.currentTimeMillis() | ||
initializeMopro() | ||
val endTime = System.currentTimeMillis() | ||
initTime = | ||
"init time: " + | ||
(endTime - startTime).toString() + | ||
" ms" | ||
} | ||
) | ||
.start() | ||
}, | ||
modifier = Modifier.padding(bottom = 80.dp) | ||
) { Text(text = "init") } | ||
Button( | ||
onClick = { | ||
Thread( | ||
Runnable { | ||
val startTime = System.currentTimeMillis() | ||
res = generateProof2(inputs) | ||
val endTime = System.currentTimeMillis() | ||
provingTime = | ||
"proving time: " + | ||
(endTime - startTime).toString() + | ||
" ms" | ||
} | ||
) | ||
.start() | ||
}, | ||
modifier = Modifier.padding(top = 20.dp) | ||
) { Text(text = "generate proof") } | ||
Button( | ||
onClick = { | ||
val startTime = System.currentTimeMillis() | ||
valid = "valid: " + verifyProof2(res.proof, res.inputs).toString() | ||
val endTime = System.currentTimeMillis() | ||
verifyingTime = "verifying time: " + (endTime - startTime).toString() + " ms" | ||
}, | ||
modifier = Modifier.padding(top = 120.dp) | ||
) { Text(text = "verify proof") } | ||
Text( | ||
text = "Keccak256 proof", | ||
modifier = Modifier.padding(bottom = 180.dp), | ||
fontWeight = FontWeight.Bold | ||
) | ||
|
||
Text(text = initTime, modifier = Modifier.padding(top = 200.dp).width(200.dp)) | ||
Text(text = provingTime, modifier = Modifier.padding(top = 250.dp).width(200.dp)) | ||
Text(text = valid, modifier = Modifier.padding(top = 300.dp).width(200.dp)) | ||
Text(text = verifyingTime, modifier = Modifier.padding(top = 350.dp).width(200.dp)) | ||
} | ||
} |
Oops, something went wrong.