diff --git a/templates/mopro-example-app/android/app/src/main/java/com/example/mopro/KeccakComponent.kt b/templates/mopro-example-app/android/app/src/main/java/com/example/mopro/KeccakComponent.kt new file mode 100644 index 00000000..3a0990bd --- /dev/null +++ b/templates/mopro-example-app/android/app/src/main/java/com/example/mopro/KeccakComponent.kt @@ -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(proof = ByteArray(size = 0), inputs = ByteArray(size = 0)) + ) + } + + val inputs = mutableMapOf>() + 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)) + } +} \ No newline at end of file diff --git a/templates/mopro-example-app/android/app/src/main/java/com/example/mopro/MainActivity.kt b/templates/mopro-example-app/android/app/src/main/java/com/example/mopro/MainActivity.kt index 3a347713..3f9de210 100644 --- a/templates/mopro-example-app/android/app/src/main/java/com/example/mopro/MainActivity.kt +++ b/templates/mopro-example-app/android/app/src/main/java/com/example/mopro/MainActivity.kt @@ -1,26 +1,15 @@ package com.example.mopro +import KeccakComponent +import MultiplierComponent import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -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.MaterialTheme import androidx.compose.material3.Surface -import androidx.compose.material3.Text -import androidx.compose.runtime.* -import androidx.compose.runtime.Composable -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.unit.dp import com.example.mopro.ui.theme.moproTheme -import uniffi.mopro.GenerateProofResult class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -33,338 +22,11 @@ class MainActivity : ComponentActivity() { Surface( modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background - ) { ProofComponent() } + ) { + MultiplierComponent() + //KeccakComponent() + } } } } } - -@Composable -fun ProofComponent() { - 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(proof = ByteArray(size = 0), inputs = ByteArray(size = 0)) - ) - } - - val inputs = mutableMapOf>() - 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() - uniffi.mopro.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 = uniffi.mopro.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: " + uniffi.mopro.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)) - } -} diff --git a/templates/mopro-example-app/android/app/src/main/java/com/example/mopro/MultiplierComponent.kt b/templates/mopro-example-app/android/app/src/main/java/com/example/mopro/MultiplierComponent.kt new file mode 100644 index 00000000..49866fc7 --- /dev/null +++ b/templates/mopro-example-app/android/app/src/main/java/com/example/mopro/MultiplierComponent.kt @@ -0,0 +1,95 @@ +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 MultiplierComponent() { + 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 output by remember { mutableStateOf("output:") } + var res by remember { + mutableStateOf( + GenerateProofResult(proof = ByteArray(size = 0), inputs = ByteArray(size = 0)) + ) + } + + val inputs = mutableMapOf>() + inputs["a"] = listOf("3") + inputs["b"] = listOf("5") + + 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" + output = "output: " + uniffi.mopro.toEthereumInputs(res.inputs) + }, + modifier = Modifier.padding(top = 120.dp) + ) { Text(text = "verify proof") } + Text( + text = "Multiplier 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)) + Text(text = output, modifier = Modifier.padding(top = 400.dp).width(200.dp)) + } +} \ No newline at end of file