-
Notifications
You must be signed in to change notification settings - Fork 347
Expand file tree
/
Copy pathmain.py
More file actions
278 lines (226 loc) · 10.1 KB
/
main.py
File metadata and controls
278 lines (226 loc) · 10.1 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/usr/bin/env python3
"""
gnark-crypto CMD - Interactive CLI for gnark-crypto cryptographic library
"""
import subprocess
import sys
from pathlib import Path
from rich.console import Console
from rich.panel import Panel
from rich.prompt import Prompt, IntPrompt
from rich.table import Table
from rich import box
from rich.theme import Theme
from utils import ensure_env
# Custom theme for gnark-crypto styling
theme = Theme({
"info": "cyan",
"success": "green",
"warning": "yellow",
"error": "red bold",
"logo": "bright_blue",
"highlight": "bright_magenta",
})
console = Console(theme=theme)
GNARK_LOGO = r"""
__ __
/ | / |
______ _______ ______ ______ $$ | __ _______ ______ __ __ ______ _$$ |_ ______
/ \ / \ / \ / \ $$ | / |______ / | / \ / | / | / \ / $$ | / \
/$$$$$$ |$$$$$$$ | $$$$$$ |/$$$$$$ |$$ |_/$$// |/$$$$$$$/ /$$$$$$ |$$ | $$ |/$$$$$$ |$$$$$$/ /$$$$$$ |
$$ | $$ |$$ | $$ | / $$ |$$ | $$/ $$ $$< $$$$$$/ $$ | $$ | $$/ $$ | $$ |$$ | $$ | $$ | __ $$ | $$ |
$$ \__$$ |$$ | $$ |/$$$$$$$ |$$ | $$$$$$ \ $$ \_____ $$ | $$ \__$$ |$$ |__$$ | $$ |/ |$$ \__$$ |
$$ $$ |$$ | $$ |$$ $$ |$$ | $$ | $$ | $$ |$$ | $$ $$ |$$ $$/ $$ $$/ $$ $$/
$$$$$$$ |$$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$/ $$$$$$$ |$$$$$$$/ $$$$/ $$$$$$/
/ \__$$ | / \__$$ |$$ |
$$ $$/ $$ $$/ $$ |
$$$$$$/ $$$$$$/ $$/
"""
GNARK_MODULE = "github.com/Consensys/gnark-crypto"
def display_logo():
"""Display the gnark-crypto logo"""
console.print(GNARK_LOGO, style="logo")
console.print("\n[bold cyan]Efficient cryptographic primitives in Go[/bold cyan]\n")
def show_install_dependencies():
"""Install gnark-crypto via go get"""
console.print(Panel(
f"[info]Executing:[/info] [bold]go get {GNARK_MODULE}[/bold]\n\n"
"[dim]Note: In go.mod the module path is case sensitive (use consensys, not ConsenSys)[/dim]",
title="[success]Install Dependencies[/success]",
border_style="green",
))
try:
result = subprocess.run(
["go", "get", GNARK_MODULE],
capture_output=True,
text=True,
)
if result.returncode == 0:
console.print("[success]✓ gnark-crypto installed successfully![/success]")
if result.stdout:
console.print(result.stdout)
else:
console.print("[error]✗ Installation failed:[/error]")
console.print(result.stderr or result.stdout)
except FileNotFoundError:
console.print("[error]✗ Go is not installed or not in PATH. Please install Go first.[/error]")
def show_settings():
"""Display and configure settings"""
table = Table(title="Settings", box=box.ROUNDED)
table.add_column("Setting", style="cyan")
table.add_column("Value", style="green")
table.add_column("Description", style="dim")
table.add_row("Go Module Path", GNARK_MODULE, "Case sensitive: use Consensys")
table.add_row("Go Version", "1.19+", "Tested with last 2 major releases")
table.add_row("Architecture", "x86 amd64", "Optimized for 64-bit")
table.add_row("Platform", "Unix (Linux/macOS)", "Primary testing target")
console.print(Panel(table, title="[highlight]gnark-crypto Configuration[/highlight]", border_style="blue"))
console.print("\n[dim]Supported elliptic curves:[/dim]")
curves = ["bn254", "bls12-381", "bls24-317", "bls12-377/bw6-761", "bls24-315/bw6-633"]
for curve in curves:
console.print(f" • [info]{curve}[/info]")
console.print("\n[warning]⚠ Warning:[/warning] gnark-crypto is not fully audited. Use at your own risk.")
console.print("No security guarantees for constant-time implementation or side-channel resistance.")
def show_about():
"""Display About information and hashtags"""
about_path = Path(__file__).parent / "about"
panel_content = """
[bold]gnark-crypto[/bold] provides efficient cryptographic primitives in Go:
• [cyan]Elliptic curve cryptography & Pairing[/cyan] on bn254, bls12-381, bls24-317, bls12-377, bls24-315
• [cyan]field/generator[/cyan] - Finite field arithmetic code generator
• [cyan]fft[/cyan] - Fast Fourier Transform
• [cyan]fri[/cyan] - FRI commitment scheme
• [cyan]mimc[/cyan] - MiMC hash function
• [cyan]kzg[/cyan] - KZG commitment scheme
• [cyan]eddsa[/cyan] - EdDSA signatures
[bold]Developed by:[/bold] gnark team (gnark@consensys.net)
[bold]Related:[/bold] gnark - framework to execute algorithms in zero-knowledge
"""
console.print(Panel(panel_content, title="[success]About gnark-crypto[/success]", border_style="green"))
if about_path.exists():
console.print("\n[highlight]Hashtags (from about/):[/highlight]\n")
for f in sorted(about_path.glob("*.txt")):
content = f.read_text(encoding="utf-8").strip()
if content:
console.print(f" [dim]{f.stem}:[/dim] {content}")
def show_generate_code():
"""Run go generate"""
console.print(Panel(
"[info]Executing:[/info] [bold]go generate ./...[/bold]\n\n"
"[dim]Regenerates files from templates in internal/generator[/dim]",
title="[success]Generate Code[/success]",
border_style="green",
))
try:
result = subprocess.run(
["go", "generate", "./..."],
capture_output=True,
text=True,
cwd=Path(__file__).parent.parent,
)
if result.returncode == 0:
console.print("[success]✓ Code generation completed![/success]")
if result.stdout:
console.print(result.stdout)
else:
console.print("[error]✗ Generation failed. Run from gnark-crypto root.[/error]")
if result.stderr:
console.print(result.stderr)
except Exception as e:
console.print(f"[error]✗ Error: {e}[/error]")
def show_benchmark():
"""Display benchmark information"""
content = """
[bold]Benchmarking pairing-friendly elliptic curve libraries[/bold]
gnark-crypto is one of the [green]fastest[/green] pairing-friendly elliptic curve libraries
for zkp projects with different curves.
Libraries vary by:
• Implementation language
• Assembly code usage
• Constant-time vs performance trade-offs
[dim]See: Benchmarking pairing-friendly elliptic curves libraries[/dim]
"""
console.print(Panel(content, title="[highlight]Benchmark Info[/highlight]", border_style="blue"))
def show_citing():
"""Display BibTeX citation"""
bibtex = """
@software{gnark-crypto-v0.15,
author = {Gautam Botrel and
Thomas Piellard and
Youssef El Housni and
Arya Tabaie and
Gus Gutoski and
Ivo Kubjas},
title = {Consensys/gnark-crypto: v0.15.0},
month = jan,
year = {2025},
publisher = {Zenodo},
version = {v0.15.0},
doi = {10.5281/zenodo.5815453},
url = {https://doi.org/10.5281/zenodo.5815453}
}
"""
console.print(Panel(bibtex, title="[success]BibTeX Citation[/success]", border_style="green"))
console.print("[dim]If you use gnark-crypto in research, a citation would be appreciated.[/dim]")
def show_version():
"""Display versioning information"""
content = """
[bold]SemVer[/bold] versioning is used.
[info]Current release:[/info] v0.15.0
[dim]See repository tags for available versions.[/dim]
[bold]Security:[/bold] Report bugs via gnark Security Policy
"""
console.print(Panel(content, title="[highlight]Versioning[/highlight]", border_style="blue"))
def show_security():
"""Display security warning"""
content = """
[warning]⚠ SECURITY NOTICE[/warning]
gnark-crypto is [bold]not fully audited[/bold] and is provided as-is.
[bold]Use at your own risk.[/bold]
No guarantees for:
• Constant-time implementation
• Side-channel attack resistance
[info]To report security bugs:[/info] See gnark Security Policy
"""
console.print(Panel(content, title="[error]Security Warning[/error]", border_style="red"))
@ensure_env
def main_menu():
"""Display main menu and handle selection"""
actions = {
1: ("Install Dependencies", show_install_dependencies),
2: ("Settings", show_settings),
3: ("About", show_about),
4: ("Generate Code", show_generate_code),
5: ("Benchmark Info", show_benchmark),
6: ("Citing (BibTeX)", show_citing),
7: ("Version Info", show_version),
8: ("Security Notice", show_security),
0: ("Exit", None),
}
while True:
console.clear()
display_logo()
table = Table(show_header=False, box=box.SIMPLE)
table.add_column("Key", style="highlight", width=4)
table.add_column("Action", style="info")
for key, (label, _) in actions.items():
table.add_row(str(key), label)
console.print(Panel(table, title="[bold]Menu[/bold]", border_style="cyan"))
console.print()
try:
choice = IntPrompt.ask("[bold]Select option[/bold]", default=0)
except (ValueError, KeyboardInterrupt):
choice = 0
if choice not in actions:
console.print("[warning]Invalid option. Try again.[/warning]")
Prompt.ask("\nPress Enter to continue")
continue
_, action = actions[choice]
if action is None:
console.print("[success]Goodbye![/success]")
sys.exit(0)
console.print()
action()
Prompt.ask("\n[dim]Press Enter to continue[/dim]")
if __name__ == "__main__":
main_menu()