Better UI elements

main
Bazsalanszky 2022-12-07 03:36:09 +01:00
parent 425b6ae6dd
commit dfb39edb99
No known key found for this signature in database
GPG Key ID: B40814F4EFE23F96
4 changed files with 203 additions and 65 deletions

View File

@ -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<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
application {
mainClass.set("MainKt")
}

View File

@ -1,51 +1,69 @@
<!DOCTYPE html>
<html lang="en">
<head>
<head>
<title>Flag Submission Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="dist/bundle.js"></script>
</head>
<body style="height:1500px">
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.6.1/web3.min.js" integrity="sha512-5erpERW8MxcHDF7Xea9eBQPiRtxbse70pFcaHJuOhdEBQeAxGQjUwgJbuBDWve+xP/u5IoJbKjyJk50qCnMD7A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<nav class="navbar navbar-inverse navbar-fixed-top">
<!--<script src="dist/bundle.js"></script>-->
</head>
<body style="height:1500px">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Flag Submission Page</a>
</div>
<ul class="nav navbar-nav">
<li><a href="leaderboard.html">Leaderboard</a></li>
<li class="active"><a href="sendflag.html">Send Flag</a></li>
<li>
<a href="leaderboard.html">Leaderboard</a>
</li>
<li class="active">
<a href="sendflag.html">Send Flag</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><button class="btn btn-default navbar-btn" id="metamask-login" type="button" style="margin-right:20px"><span class="glyphicon glyphicon-log-in"></span> Connect Wallet</button></li>
<li>
<button class="btn btn-default navbar-btn" id="metamask-login" type="button" style="margin-right:20px">
<span class="glyphicon glyphicon-log-in"></span>
Connect Wallet</button>
</li>
<!--<button class="btn btn-danger navbar-btn">Button</button>-->
</ul>
</div>
</nav>
</nav>
<div class="container" style="margin-top:50px">
<div class="container" style="margin-top:50px">
<h1>Send the flag</h1>
<form class="form-inline" id="flag-form" style="display:none">
<div class="form-group">
<label for="flagbox">Flag:</label>
<label for="flagbox">Flag id:</label>
<input type="number" class="form-control" id="flagID">
</div>
<div class="form-group">
<label for="flagbox">Proof:</label>
<input type="text" class="form-control" id="flagbox">
</div>
<button id="submitFlagBtn" type="button" class="btn btn-default">Submit Flag</button>
</form>
</div>
<button id="submitFlagBtn" type="button" class="btn btn-default btn-warning">Submit Flag</button>
</form>
</div>
<script type='module'>
<script type='module'>
var web3js;
var accounts;
const contractAddress = "0x970e1d481CEDbeaeFE776275F0d1b4E1B301bB3b";
window.addEventListener("load", function () {
let loginbutton = document.getElementById('metamask-login');
let accounts;
ethereum.request({method: 'eth_requestAccounts'}).then(accounts => {
console.log(accounts);
if (accounts.length > 0) {
ethereum.request({method: 'eth_requestAccounts'}).then(acc => {
console.log(acc);
accounts = acc;
if (acc.length > 0) {
document.getElementById('flag-form').style.display = "block";
loginbutton.textContent = accounts[0];
loginbutton.disabled = true;
@ -56,14 +74,42 @@
let loginbutton = document.getElementById('metamask-login');
loginbutton.addEventListener('click', event => {
let account;
ethereum.request({method: 'eth_requestAccounts'}).then(accounts =>{
ethereum.request({method: 'eth_requestAccounts'}).then(accounts => {
account = accounts[0];
document.getElementById('flag-form').style.display = "block";
loginbutton.textContent = account;
loginbutton.disabled = true;
})
})
</script>
</body>
let flagID = document.getElementById('flagID');
let flagbox = document.getElementById('flagbox');
let submitFlagBtn = document.getElementById('submitFlagBtn');
submitFlagBtn.addEventListener('click', event => {
contract.methods.SubmitFlag(JSON.parse(flagbox.value),flagID.value).send( { from: accounts[0] });
})
var contactABI;
var contract;
async function getAbi() {
fetch("/abi.json").then(a => a.json().then(abi => {
contactABI = abi
contract = new web3js.eth.Contract(contactABI, contractAddress);
}));
}
window.addEventListener("load", function () {
if (typeof web3 !== "undefined") {
web3js = new Web3(web3.currentProvider);
// console.log(web3);
getAbi();
} else {
console.log("No web3? You should consider trying MetaMask!");
}
});
</script>
</body>
</html>

View File

@ -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) {

View File

@ -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<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 = 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<String>()
@ -23,4 +109,4 @@ fun main() {
Zokrates.generateProof(scheme = Zokrates.ProvingScheme.GM17)
Zokrates.verify()
}
}*/