File size: 2,578 Bytes
42472b3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import os
import tempfile
import uuid
import subprocess
import gradio as gr
BIN = os.path.join(os.path.dirname(__file__), "bin", "zkProver_linux_gpu")
def run_zk_prover(network, block_number, contract, file):
if not contract:
raise gr.Error("contract is required")
if not file:
raise gr.Error('file is required')
args = [
BIN,
"evm", "-r", "https://rpc.flashbots.net/"
]
if block_number:
args.extend(["-b", str(block_number)])
proof_path = "/tmp/" + str(uuid.uuid4()) + ".bin"
args.extend(["-o", proof_path])
args.append(file.name + ":" + contract)
proc = subprocess.Popen(args,)
proc.wait()
if proc.returncode != 0:
raise gr.Error("generate proof failed")
return proof_path
with gr.Blocks() as demo:
gr.Markdown(
"""
# 0xHacked
This is the demo for [0xHacked](https://0xHacked.com), a trustless bug bounty platform. You can generate the proof of exploit here. However, due to the constraints of ZKP, the generation might be low on Huggingface.
<br/>
We recommend [compiling it from the source](https://github.com/0xHackedLabs/zkProver). The generation can be very quick on GPU. For more details, please refer to [0xHacked Documentation](https://docs.0xHacked.com).
<br/>
The sample PoC provided below takes ~800s to generate the proof. You can click "SushiRouterExploit.sol" below and hit "Run" to try it!
"""
)
with gr.Column():
with gr.Row():
with gr.Column():
network_input = gr.Dropdown(["Ethereum"], value="Ethereum", label='Network')
block_number_input = gr.Number(precision=0, label='Block Number')
contract_input = gr.Textbox(label='Poc Contract')
file_input = gr.File(file_types=[".sol"], label='Solidity File')
submit_btn = gr.Button(label="Submit")
with gr.Column():
fileout = gr.File(label='Proof File')
gr.Examples(
examples=[[
"Ethereum",
17007841,
"SushiExpProxy",
"./examples/SushiRouterExploit.sol"],
],
fn=run_zk_prover,
inputs=[network_input, block_number_input, contract_input, file_input],
outputs=fileout
)
submit_btn.click(
fn=run_zk_prover,
inputs=[network_input, block_number_input, contract_input, file_input],
outputs=fileout
)
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860)
|