-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script for converting trusted setups
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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 minimal preset | ||
run: wget https://github.com/ethereum/consensus-specs/raw/dev/presets/minimal/trusted_setups/testing_trusted_setups.json | ||
- name: Convert minimal to txt | ||
run: python3 ./scripts/convert_trusted_setup.py --input testing_trusted_setup.json --output trusted_setup_minimal.txt | ||
- name: Compare to existing file | ||
run: cmp src/trusted_setup_4.txt trusted_setup_minimal.txt | ||
|
||
- name: Download mainnet preset | ||
run: wget https://github.com/ethereum/consensus-specs/raw/dev/presets/mainnet/trusted_setups/testing_trusted_setups.json | ||
- name: Convert mainnet to txt | ||
run: python3 ./scripts/convert_trusted_setup.py --input testing_trusted_setup.json --output trusted_setup_mainnet.txt | ||
- name: Compare to existing file | ||
run: cmp src/trusted_setup.txt trusted_setup_mainnet.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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["setup_G1_lagrange"] | ||
g2_values = trusted_setup["setup_G2"] | ||
|
||
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( | ||
"--json", | ||
required=True, | ||
type=argparse.FileType("r"), | ||
help="The trusted setup in JSON format (input)", | ||
) | ||
parser.add_argument( | ||
"--text", | ||
required=True, | ||
type=argparse.FileType("w"), | ||
help="The trusted setup in text format (output)", | ||
) | ||
args = parser.parse_args() | ||
|
||
try: | ||
convert(args.json, args.text) | ||
finally: | ||
args.json.close() | ||
args.text.close() |