Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script for converting trusted setups #359

Merged
merged 9 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/trusted-setup-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Trusted Setup
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Download
run: wget -O trusted_setup.json https://github.com/ethereum/consensus-specs/raw/dev/presets/mainnet/trusted_setups/trusted_setup_4096.json
- name: Convert
run: python3 ./scripts/convert_trusted_setup.py --input trusted_setup.json --output trusted_setup.txt
- name: Compare
run: cmp src/trusted_setup.txt trusted_setup.txt
44 changes: 44 additions & 0 deletions scripts/convert_trusted_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/python3

import argparse
import json
from typing import TextIO


def convert(ts_json: TextIO, ts_text: TextIO) -> None:
"""Convert trusted setup to text format."""
trusted_setup = json.load(ts_json)
g1_values = trusted_setup["g1_lagrange"]
g2_values = trusted_setup["g2_monomial"]

print(len(g1_values), file=ts_text)
print(len(g2_values), file=ts_text)
for g1 in g1_values:
print(g1.replace("0x", ""), file=ts_text)
for g2 in g2_values:
print(g2.replace("0x", ""), file=ts_text)


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Convert trusted setup from JSON to text format.",
)
parser.add_argument(
"--input",
required=True,
type=argparse.FileType("r"),
help="the trusted setup in JSON format",
)
parser.add_argument(
"--output",
required=True,
type=argparse.FileType("w"),
help="the trusted setup in text format",
)
args = parser.parse_args()

try:
convert(args.input, args.output)
finally:
args.input.close()
args.output.close()
Loading