112 lines
4.5 KiB
Kotlin
112 lines
4.5 KiB
Kotlin
package hu.bmeta.cctf
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.material.*
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.window.Window
|
|
import androidx.compose.ui.window.application
|
|
import androidx.compose.ui.window.rememberWindowState
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.GlobalScope
|
|
import kotlinx.coroutines.launch
|
|
|
|
fun main() {
|
|
Zokrates.initZokrates()
|
|
application {
|
|
Window(
|
|
onCloseRequest = ::exitApplication,
|
|
title = "ZoKrates CTF Proof generator",
|
|
state = rememberWindowState(width = 300.dp, height = 300.dp)
|
|
) {
|
|
val count = remember { mutableStateOf(0) }
|
|
val address = remember { mutableStateOf("") }
|
|
val flag = remember { mutableStateOf("") }
|
|
val enabled = remember { mutableStateOf(true) }
|
|
MaterialTheme {
|
|
Column(Modifier.fillMaxSize().padding(5.dp), Arrangement.spacedBy(5.dp)) {
|
|
Text("ZoKrates Proof generator")
|
|
OutlinedTextField(address.value, {
|
|
address.value = it
|
|
}, placeholder = {
|
|
Text("Address")
|
|
})
|
|
|
|
OutlinedTextField(flag.value, {
|
|
flag.value = it
|
|
}, placeholder = {
|
|
Text("Flag")
|
|
})
|
|
Button(modifier = Modifier.align(Alignment.CenterHorizontally),
|
|
onClick = {
|
|
enabled.value = false
|
|
val address_ch = address.value.replace("0x","").chunked(8).map { java.lang.Long.parseLong(it.uppercase(),16).toString() }
|
|
val message = flag.value.map { it.code.toByte().toInt().toString() }.toMutableList()
|
|
for (i in 0 until 64 - message.size) {
|
|
message.add("0")
|
|
}
|
|
val hashArgs = mutableListOf<String>()
|
|
hashArgs.addAll(address_ch)
|
|
hashArgs.addAll(message)
|
|
GlobalScope.launch(Dispatchers.IO) {
|
|
Zokrates.compile("hash.zok","hash")
|
|
val result = Zokrates.computeWithness(hashArgs,"hash")
|
|
println(result)
|
|
val zkpArgs = mutableListOf<String>()
|
|
zkpArgs.addAll(result)
|
|
zkpArgs.addAll(address_ch)
|
|
zkpArgs.addAll(message)
|
|
|
|
Zokrates.compile("root.zok")
|
|
val results2 = Zokrates.computeWithness(zkpArgs)
|
|
println(results2)
|
|
|
|
Zokrates.generateProof(scheme = Zokrates.ProvingScheme.GM17)
|
|
println("Proof done!")
|
|
}
|
|
enabled.value = true
|
|
}, enabled = enabled.value) {
|
|
Text("Generate Proof!")
|
|
}
|
|
if(enabled.value.not()){
|
|
CircularProgressIndicator()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/*fun main() {
|
|
val address = listOf("1530452586","1880905349","1172110512","1070303071","1455349188")
|
|
val message = mutableListOf("116", "101", "115","116","0")
|
|
val random = Random()
|
|
for(i in 0 until 64-message.size){
|
|
message.add("0")
|
|
}
|
|
Zokrates.initZokrates()
|
|
Zokrates.compile("hash.zok","hash")
|
|
val hashArgs = mutableListOf<String>()
|
|
hashArgs.addAll(address)
|
|
hashArgs.addAll(message)
|
|
val result = Zokrates.computeWithness(hashArgs,"hash")
|
|
println(result)
|
|
|
|
val zkpArgs = mutableListOf<String>()
|
|
zkpArgs.addAll(result)
|
|
zkpArgs.addAll(address)
|
|
zkpArgs.addAll(message)
|
|
|
|
Zokrates.compile("root.zok")
|
|
val results2 = Zokrates.computeWithness(zkpArgs)
|
|
println(results2)
|
|
|
|
Zokrates.generateProof(scheme = Zokrates.ProvingScheme.GM17)
|
|
Zokrates.verify()
|
|
|
|
}*/ |