From dfb39edb998694e10079635b0e98ed4c1e2b9559 Mon Sep 17 00:00:00 2001 From: Bazsalanszky Date: Wed, 7 Dec 2022 03:36:09 +0100 Subject: [PATCH] Better UI elements --- CCTF_Solutions_main/build.gradle.kts | 6 + CCTF_Solutions_main/frontend/sendflag.html | 170 +++++++++++------- CCTF_Solutions_main/frontend/src/main.mjs | 2 +- .../src/main/kotlin/hu/bmeta/cctf/Main.kt | 90 +++++++++- 4 files changed, 203 insertions(+), 65 deletions(-) diff --git a/CCTF_Solutions_main/build.gradle.kts b/CCTF_Solutions_main/build.gradle.kts index e11951b..2e18fad 100644 --- a/CCTF_Solutions_main/build.gradle.kts +++ b/CCTF_Solutions_main/build.gradle.kts @@ -2,6 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") version "1.7.10" + id("org.jetbrains.compose") version "1.2.1" application } @@ -10,9 +11,12 @@ version = "1.0-SNAPSHOT" repositories { mavenCentral() + maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") + google() } dependencies { + implementation(compose.desktop.currentOs) testImplementation(kotlin("test")) } @@ -24,6 +28,8 @@ tasks.withType { kotlinOptions.jvmTarget = "1.8" } + + application { mainClass.set("MainKt") } \ No newline at end of file diff --git a/CCTF_Solutions_main/frontend/sendflag.html b/CCTF_Solutions_main/frontend/sendflag.html index e9be996..db21659 100644 --- a/CCTF_Solutions_main/frontend/sendflag.html +++ b/CCTF_Solutions_main/frontend/sendflag.html @@ -1,69 +1,115 @@ - - Flag Submission Page - - - - - - - - + + Flag Submission Page + + + + + + - - -
-

Send the flag

- -
+ + + - +
  • + +
  • + + + + - +
    +

    Send the flag

    + +
    + + + + diff --git a/CCTF_Solutions_main/frontend/src/main.mjs b/CCTF_Solutions_main/frontend/src/main.mjs index 15f4c64..b7300a5 100644 --- a/CCTF_Solutions_main/frontend/src/main.mjs +++ b/CCTF_Solutions_main/frontend/src/main.mjs @@ -71,7 +71,7 @@ def main(public u32[8] hash,public u32[5] address,private u8[64] flag){ /* Get the proving key from the local server */ -const PROVING_KEY_URI = 'http://localhost:8080/proving.key'; +const PROVING_KEY_URI = '/proving.key'; const proving_key = await (await fetch(PROVING_KEY_URI)).text(); function submitFlag(flag) { diff --git a/CCTF_Solutions_main/src/main/kotlin/hu/bmeta/cctf/Main.kt b/CCTF_Solutions_main/src/main/kotlin/hu/bmeta/cctf/Main.kt index 65c564c..db88f77 100644 --- a/CCTF_Solutions_main/src/main/kotlin/hu/bmeta/cctf/Main.kt +++ b/CCTF_Solutions_main/src/main/kotlin/hu/bmeta/cctf/Main.kt @@ -1,8 +1,94 @@ 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() + 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() + 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 = listOf("104","116","116","112","115","58","47","47","119","119","119","46","121","111","117","116","117","98","101","46","99","111","109","47","119","97","116","99","104","63","118","61","100","81","119","52","119","57","87","103","88","99","81","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0") + 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() @@ -23,4 +109,4 @@ fun main() { Zokrates.generateProof(scheme = Zokrates.ProvingScheme.GM17) Zokrates.verify() -} \ No newline at end of file +}*/ \ No newline at end of file