Skip to content

Commit 64d2e6e

Browse files
Refactor: removed obsolete game code, updated ZKP tutorial scenes
1 parent cb0f687 commit 64d2e6e

File tree

3 files changed

+126
-31
lines changed

3 files changed

+126
-31
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import sys
2+
import subprocess
3+
from PyQt5.QtWidgets import (
4+
QApplication, QWidget, QPushButton, QLabel, QVBoxLayout
5+
)
6+
from PyQt5.QtGui import QFont
7+
from PyQt5.QtCore import Qt
8+
9+
class ZKPSceneLauncher(QWidget):
10+
def __init__(self):
11+
super().__init__()
12+
self.setWindowTitle("🔐 Zero-Knowledge Proof Demo Launcher")
13+
self.setGeometry(300, 200, 500, 320)
14+
self.setStyleSheet("background-color: #1e1e1e; color: white;")
15+
16+
layout = QVBoxLayout()
17+
layout.setSpacing(15)
18+
19+
title = QLabel("🎓 Launch a Scene")
20+
title.setFont(QFont("Arial", 18, QFont.Bold))
21+
title.setAlignment(Qt.AlignCenter)
22+
layout.addWidget(title)
23+
24+
# Scene 1
25+
scene1_btn = QPushButton(" Scene 1: Introduction to Commitment")
26+
scene1_btn.clicked.connect(lambda: self.launch("tutorial_scene.py"))
27+
layout.addWidget(scene1_btn)
28+
29+
# Scene 2
30+
scene2_btn = QPushButton("🎮 Scene 2: Commitment Game")
31+
scene2_btn.clicked.connect(lambda: self.launch("scene2_commitment.py"))
32+
layout.addWidget(scene2_btn)
33+
34+
# Scene 3
35+
scene3_btn = QPushButton("🔀 Scene 3: Bipartite Graph ZKP")
36+
scene3_btn.clicked.connect(lambda: self.launch("scene3_bipartate.py"))
37+
layout.addWidget(scene3_btn)
38+
39+
# Style all buttons
40+
for btn in [scene1_btn, scene2_btn, scene3_btn]:
41+
btn.setStyleSheet("padding: 12px; font-size: 14px; background-color: #2a2a2a; border-radius: 8px;")
42+
43+
self.setLayout(layout)
44+
45+
def launch(self, script_path):
46+
subprocess.Popen(["python", script_path])
47+
48+
if __name__ == "__main__":
49+
app = QApplication(sys.argv)
50+
launcher = ZKPSceneLauncher()
51+
launcher.show()
52+
sys.exit(app.exec_())

ZKP_Demo_Tool/tutorial/scene2_commitment.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import sys
2+
import subprocess
23
import hashlib
34
import random
45
from PyQt5.QtWidgets import (
56
QApplication, QWidget, QLabel, QPushButton, QVBoxLayout, QGraphicsScene,
6-
QGraphicsView, QGraphicsEllipseItem, QGraphicsTextItem, QGraphicsLineItem, QMessageBox, QHBoxLayout, QGraphicsOpacityEffect
7+
QGraphicsView, QGraphicsEllipseItem, QGraphicsTextItem, QGraphicsLineItem,
8+
QHBoxLayout, QScrollArea
79
)
810
from PyQt5.QtGui import QFont, QPen, QBrush, QColor
9-
from PyQt5.QtCore import Qt, QPointF, QLineF, QPropertyAnimation, QEasingCurve
11+
from PyQt5.QtCore import Qt, QPointF, QLineF
12+
1013

1114
class ZKPNode:
1215
def __init__(self, name, role_label, position, color):
@@ -19,6 +22,7 @@ def __init__(self, name, role_label, position, color):
1922
self.revealed_role = role_label
2023
self.revealed_nonce = self.nonce
2124

25+
2226
class NarrationEngine:
2327
@staticmethod
2428
def format_log(node1, node2, binding_ok, hiding_ok, binding_broken=False):
@@ -43,12 +47,12 @@ def format_log(node1, node2, binding_ok, hiding_ok, binding_broken=False):
4347
log += " ✅ Matches original commitments — Binding held.\n\n"
4448

4549
if not binding_broken and hiding_ok:
46-
log += "✅ Hiding held — Verifier only learns that roles are different.\n ZKP passed successfully.\n"
50+
log += "✅ Hiding held — Verifier only learns that roles are different.\nZKP passed successfully.\n"
4751
elif not binding_broken and not hiding_ok:
48-
log += f"⚠️ Hiding broken — {node1.name} and {node2.name} revealed same role!\n ZKP failed. Verifier now knows part of the secret mapping.\n"
52+
log += f"⚠️ Hiding broken — {node1.name} and {node2.name} revealed same role!\nZKP failed. Verifier now knows part of the secret mapping.\n"
4953

5054
log += """
51-
Explanation:
55+
📘 Explanation:
5256
- Binding ensures that once a role is committed with a hash, it can't be changed.
5357
- Hiding ensures that the hash doesn't reveal the actual role until the reveal phase.
5458
- If two adjacent nodes share the same role, it can indicate a conflict of interest or security flaw.
@@ -57,6 +61,7 @@ def format_log(node1, node2, binding_ok, hiding_ok, binding_broken=False):
5761
"""
5862
return log
5963

64+
6065
class SceneZKPGraph(QWidget):
6166
def __init__(self):
6267
super().__init__()
@@ -68,20 +73,40 @@ def __init__(self):
6873
self.view = QGraphicsView(self.scene)
6974
self.view.setStyleSheet("background-color: #1e1e1e; border: none;")
7075

76+
# Scrollable narration box
7177
self.text_output = QLabel()
7278
self.text_output.setWordWrap(True)
7379
self.text_output.setFont(QFont("Courier New", 12))
7480
self.text_output.setStyleSheet("background-color: #1c1c1c; padding: 10px; border: 1px solid #444; color: white;")
81+
scroll = QScrollArea()
82+
scroll.setWidgetResizable(True)
83+
scroll.setWidget(self.text_output)
84+
scroll.setMinimumHeight(250)
7585

7686
self.verify_button = QPushButton("🎯 Simulate ZKP Verification")
7787
self.verify_button.setFont(QFont("Arial", 14))
7888
self.verify_button.setStyleSheet("padding: 10px; background-color: #2d3436; color: white; border-radius: 8px;")
7989
self.verify_button.clicked.connect(self.reveal_connection)
8090

91+
self.next_button = QPushButton("➡ Next: Scene 3 - Bipartate Graph")
92+
self.next_button.setFont(QFont("Arial", 13, QFont.Bold))
93+
self.next_button.setStyleSheet(
94+
"background-color: #0055ff; color: white; padding: 10px; border-radius: 10px;"
95+
)
96+
self.next_button.clicked.connect(self.go_to_next_scene)
97+
8198
layout = QVBoxLayout()
8299
layout.addWidget(self.view)
83100
layout.addWidget(self.verify_button)
84-
layout.addWidget(self.text_output)
101+
layout.addWidget(scroll)
102+
103+
# Center the button using a horizontal layout
104+
button_layout = QHBoxLayout()
105+
button_layout.addStretch()
106+
button_layout.addWidget(self.next_button)
107+
button_layout.addStretch()
108+
layout.addLayout(button_layout)
109+
85110
self.setLayout(layout)
86111

87112
self.nodes = []
@@ -100,7 +125,7 @@ def build_graph(self):
100125
("Insider", "Validator", QPointF(150, 450), QColor("#f1c40f"))
101126
]
102127

103-
connections = [(0,1), (1,2), (2,4), (3,1), (5,2), (0,5)]
128+
connections = [(0, 1), (1, 2), (2, 4), (3, 1), (5, 2), (0, 5)]
104129

105130
for name, role, pos, color in layout:
106131
node = ZKPNode(name, role, pos, color)
@@ -156,6 +181,11 @@ def reveal_connection(self):
156181
)
157182
self.text_output.setText(log)
158183

184+
def go_to_next_scene(self):
185+
subprocess.Popen(["python", "scene3_bipartate.py"])
186+
self.close()
187+
188+
159189
if __name__ == "__main__":
160190
app = QApplication(sys.argv)
161191
window = SceneZKPGraph()

ZKP_Demo_Tool/tutorial/tutorial_scene.py

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
1+
import sys
2+
import subprocess
13
from PyQt5.QtWidgets import (
2-
QWidget, QLabel, QPushButton, QVBoxLayout, QHBoxLayout, QApplication, QGraphicsOpacityEffect
4+
QWidget, QLabel, QPushButton, QVBoxLayout, QHBoxLayout, QApplication,
5+
QGraphicsOpacityEffect, QTextEdit
36
)
4-
from PyQt5.QtGui import QPixmap, QFont, QColor, QPalette
7+
from PyQt5.QtGui import QPixmap, QFont
58
from PyQt5.QtCore import Qt, QPropertyAnimation, QEasingCurve
6-
import sys
7-
from PyQt5.QtGui import QIcon
8-
from PyQt5.QtCore import QResource
9-
109

1110
class ZKPTutorial(QWidget):
1211
def __init__(self):
1312
super().__init__()
14-
self.setWindowTitle("ZKP Animated Tutorial - Scene 1")
15-
self.setGeometry(300, 200, 900, 650)
13+
self.setWindowTitle("Scene 1: Introduction to ZKP")
14+
self.setGeometry(300, 200, 900, 700)
1615
self.setStyleSheet("background-color: #121212; color: white;")
1716

1817
self.init_ui()
1918
self.animate_scene()
2019

2120
def init_ui(self):
22-
# Main layout
2321
self.layout = QVBoxLayout()
2422

2523
# Title
26-
self.title_label = QLabel("\u2728 Scene 1: Roles in the Network")
24+
self.title_label = QLabel("Scene 1: Roles in the Network + Commitment Primer")
2725
self.title_label.setAlignment(Qt.AlignCenter)
2826
self.title_label.setFont(QFont("Arial", 24, QFont.Bold))
2927
self.layout.addWidget(self.title_label)
3028

31-
# Image area (placeholder)
29+
# Image placeholder
3230
self.image_label = QLabel()
3331
pixmap = QPixmap("../assets/scene1.png")
3432
if pixmap.isNull():
@@ -40,20 +38,20 @@ def init_ui(self):
4038
self.image_label.setAlignment(Qt.AlignCenter)
4139
self.layout.addWidget(self.image_label)
4240

43-
# Narration text
41+
# Story-style narration
4442
self.narration_label = QLabel()
4543
self.narration_label.setWordWrap(True)
46-
self.narration_label.setFont(QFont("Georgia", 16))
44+
self.narration_label.setFont(QFont("Georgia", 15))
4745
self.narration_label.setAlignment(Qt.AlignLeft)
4846
self.narration_label.setText(
4947
"<p>✨ <b>Every adventure needs a team —</b><br>"
5048
"and in the world of secure transactions, three heroes take the stage!</p>"
5149

5250
"<p>🟦 <b>Initiator</b> starts the quest:<br>"
53-
"They say, “I want to make a move!” 💸</p>"
51+
"They say, “I want to make a move!” </p>"
5452

5553
"<p>🔺 <b>Validator</b> checks the map:<br>"
56-
"“Is this legit? Let me verify...” 🔍</p>"
54+
"“Is this legit? Let me verify...” </p>"
5755

5856
"<p>🟩 <b>Receiver</b> opens the treasure chest:<br>"
5957
"“It’s real. I’m in. Transaction complete!” </p>"
@@ -63,19 +61,34 @@ def init_ui(self):
6361
"💡 <i>without showing the treasure itself?</i></p>"
6462

6563
"<p>That’s where <b>Zero-Knowledge Proofs</b> enter the story.<br>"
66-
" Ready to see some cryptographic magic?</p>"
64+
"Ready to see some cryptographic magic?</p>"
6765
)
6866
self.layout.addWidget(self.narration_label)
6967

70-
# Navigation button
71-
self.next_button = QPushButton("▶ Next")
68+
# Technical ZKP Explanation
69+
self.technical_box = QTextEdit()
70+
self.technical_box.setReadOnly(True)
71+
self.technical_box.setStyleSheet("background-color: #1a1a1a; color: #ccc; font-family: Courier; font-size: 13px;")
72+
self.technical_box.setText(
73+
"Cryptographic Primer:\n\n"
74+
"We create a commitment to the secret:\n"
75+
" commit = H(secret || nonce)\n\n"
76+
"This hash is like a sealed envelope.\n"
77+
"The verifier can challenge us to reveal only part of the secret.\n\n"
78+
"✅ Binding: We can't change the secret after committing.\n"
79+
"Hiding: The verifier sees only what we show — never the full secret.\n"
80+
)
81+
self.layout.addWidget(self.technical_box)
82+
83+
# Next button
84+
self.next_button = QPushButton("➡ Next: Scene 2 - Commitment Game")
7285
self.next_button.setFont(QFont("Arial", 13, QFont.Bold))
7386
self.next_button.setStyleSheet(
74-
"background-color: #1f1f1f; color: white; padding: 10px; border-radius: 10px;"
87+
"background-color: #0055ff; color: white; padding: 10px; border-radius: 10px;"
7588
)
7689
self.next_button.clicked.connect(self.go_to_next_scene)
7790

78-
# Center the button
91+
# Center next button
7992
button_layout = QHBoxLayout()
8093
button_layout.addStretch()
8194
button_layout.addWidget(self.next_button)
@@ -93,12 +106,12 @@ def animate_scene(self):
93106
animation.setStartValue(0.0)
94107
animation.setEndValue(1.0)
95108
animation.setEasingCurve(QEasingCurve.InOutQuad)
96-
animation.start()
97-
self.fade_animation = animation # Keep reference to avoid garbage collection
109+
animation.start()
110+
self.fade_animation = animation # prevent garbage collection
98111

99112
def go_to_next_scene(self):
100-
print("Next scene triggered (hook this up later)")
101-
113+
subprocess.Popen(["python", "scene2_commitment.py"])
114+
self.close()
102115

103116
if __name__ == '__main__':
104117
app = QApplication(sys.argv)

0 commit comments

Comments
 (0)