From b769c03b3c5c57fc4c4b0bd79ec9d59db29ed061 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 12 Sep 2023 10:23:51 -0500 Subject: [PATCH 1/8] Add script for converting trusted setups --- .github/workflows/trusted-setup-tests.yml | 31 ++++++++++++++++ scripts/convert_trusted_setup.py | 44 +++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 .github/workflows/trusted-setup-tests.yml create mode 100755 scripts/convert_trusted_setup.py diff --git a/.github/workflows/trusted-setup-tests.yml b/.github/workflows/trusted-setup-tests.yml new file mode 100644 index 000000000..02eb9eb16 --- /dev/null +++ b/.github/workflows/trusted-setup-tests.yml @@ -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 diff --git a/scripts/convert_trusted_setup.py b/scripts/convert_trusted_setup.py new file mode 100755 index 000000000..93847813b --- /dev/null +++ b/scripts/convert_trusted_setup.py @@ -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() From b4bdc6dd77864db7a4691c6f612a39969021a1ee Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 12 Sep 2023 10:31:48 -0500 Subject: [PATCH 2/8] Fix problem in CI tests --- .github/workflows/trusted-setup-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/trusted-setup-tests.yml b/.github/workflows/trusted-setup-tests.yml index 02eb9eb16..f71ec6916 100644 --- a/.github/workflows/trusted-setup-tests.yml +++ b/.github/workflows/trusted-setup-tests.yml @@ -19,13 +19,13 @@ jobs: - 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 + run: python3 ./scripts/convert_trusted_setup.py --json testing_trusted_setup.json --text 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 + run: python3 ./scripts/convert_trusted_setup.py --json testing_trusted_setup.json --text trusted_setup_mainnet.txt - name: Compare to existing file run: cmp src/trusted_setup.txt trusted_setup_mainnet.txt From 09f44de4c908ec2cf8fbff6b534b41f2854035d9 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 12 Sep 2023 10:36:02 -0500 Subject: [PATCH 3/8] Try with absolute paths --- .github/workflows/trusted-setup-tests.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/trusted-setup-tests.yml b/.github/workflows/trusted-setup-tests.yml index f71ec6916..018fdd6a1 100644 --- a/.github/workflows/trusted-setup-tests.yml +++ b/.github/workflows/trusted-setup-tests.yml @@ -19,13 +19,13 @@ jobs: - 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 --json testing_trusted_setup.json --text trusted_setup_minimal.txt + run: python3 ./scripts/convert_trusted_setup.py --json ${{github.workspace}}/testing_trusted_setup.json --text ${{github.workspace}}/trusted_setup_minimal.txt - name: Compare to existing file - run: cmp src/trusted_setup_4.txt trusted_setup_minimal.txt + run: cmp src/trusted_setup_4.txt ${{github.workspace}}/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 --json testing_trusted_setup.json --text trusted_setup_mainnet.txt + run: python3 ./scripts/convert_trusted_setup.py --json ${{github.workspace}}/testing_trusted_setup.json --text ${{github.workspace}}/trusted_setup_mainnet.txt - name: Compare to existing file - run: cmp src/trusted_setup.txt trusted_setup_mainnet.txt + run: cmp src/trusted_setup.txt ${{github.workspace}}/trusted_setup_mainnet.txt From 82fdc56f0584f5c620d8629002a8eaa95855c7c6 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 12 Sep 2023 10:37:51 -0500 Subject: [PATCH 4/8] Use correct filename --- .github/workflows/trusted-setup-tests.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/trusted-setup-tests.yml b/.github/workflows/trusted-setup-tests.yml index 018fdd6a1..488fc6b7e 100644 --- a/.github/workflows/trusted-setup-tests.yml +++ b/.github/workflows/trusted-setup-tests.yml @@ -19,13 +19,13 @@ jobs: - 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 --json ${{github.workspace}}/testing_trusted_setup.json --text ${{github.workspace}}/trusted_setup_minimal.txt + run: python3 ./scripts/convert_trusted_setup.py --json testing_trusted_setups.json --text trusted_setup_minimal.txt - name: Compare to existing file - run: cmp src/trusted_setup_4.txt ${{github.workspace}}/trusted_setup_minimal.txt + 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 --json ${{github.workspace}}/testing_trusted_setup.json --text ${{github.workspace}}/trusted_setup_mainnet.txt + run: python3 ./scripts/convert_trusted_setup.py --json testing_trusted_setups.json --text trusted_setup_mainnet.txt - name: Compare to existing file - run: cmp src/trusted_setup.txt ${{github.workspace}}/trusted_setup_mainnet.txt + run: cmp src/trusted_setup.txt trusted_setup_mainnet.txt From 73220cca030bb1ceddb2a6754e967a31dffc7fa2 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 12 Sep 2023 10:47:36 -0500 Subject: [PATCH 5/8] Name downloaded files --- .github/workflows/trusted-setup-tests.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/trusted-setup-tests.yml b/.github/workflows/trusted-setup-tests.yml index 488fc6b7e..275b889ed 100644 --- a/.github/workflows/trusted-setup-tests.yml +++ b/.github/workflows/trusted-setup-tests.yml @@ -17,15 +17,15 @@ jobs: 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 + run: wget -O minimal.json 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 --json testing_trusted_setups.json --text trusted_setup_minimal.txt + run: python3 ./scripts/convert_trusted_setup.py --json minimal.json --text minimal.txt - name: Compare to existing file - run: cmp src/trusted_setup_4.txt trusted_setup_minimal.txt + run: cmp src/trusted_setup_4.txt minimal.txt - name: Download mainnet preset - run: wget https://github.com/ethereum/consensus-specs/raw/dev/presets/mainnet/trusted_setups/testing_trusted_setups.json + run: wget -O mainnet.json 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 --json testing_trusted_setups.json --text trusted_setup_mainnet.txt + run: python3 ./scripts/convert_trusted_setup.py --json mainnet.json --text mainnet.txt - name: Compare to existing file - run: cmp src/trusted_setup.txt trusted_setup_mainnet.txt + run: cmp src/trusted_setup.txt mainnet.txt From acefdd0a3a2bc7bcb4f09ed02a0e4ed00329fb4a Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 12 Sep 2023 10:57:01 -0500 Subject: [PATCH 6/8] Rename input/output arguments --- .github/workflows/trusted-setup-tests.yml | 4 ++-- scripts/convert_trusted_setup.py | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/trusted-setup-tests.yml b/.github/workflows/trusted-setup-tests.yml index 275b889ed..705a2f473 100644 --- a/.github/workflows/trusted-setup-tests.yml +++ b/.github/workflows/trusted-setup-tests.yml @@ -19,13 +19,13 @@ jobs: - name: Download minimal preset run: wget -O minimal.json 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 --json minimal.json --text minimal.txt + run: python3 ./scripts/convert_trusted_setup.py --input minimal.json --output minimal.txt - name: Compare to existing file run: cmp src/trusted_setup_4.txt minimal.txt - name: Download mainnet preset run: wget -O mainnet.json 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 --json mainnet.json --text mainnet.txt + run: python3 ./scripts/convert_trusted_setup.py --input mainnet.json --output mainnet.txt - name: Compare to existing file run: cmp src/trusted_setup.txt mainnet.txt diff --git a/scripts/convert_trusted_setup.py b/scripts/convert_trusted_setup.py index 93847813b..89655c7a8 100755 --- a/scripts/convert_trusted_setup.py +++ b/scripts/convert_trusted_setup.py @@ -24,21 +24,21 @@ def convert(ts_json: TextIO, ts_text: TextIO) -> None: description="Convert trusted setup from JSON to text format.", ) parser.add_argument( - "--json", + "--input", required=True, type=argparse.FileType("r"), - help="The trusted setup in JSON format (input)", + help="The trusted setup in JSON format", ) parser.add_argument( - "--text", + "--output", required=True, type=argparse.FileType("w"), - help="The trusted setup in text format (output)", + help="The trusted setup in text format", ) args = parser.parse_args() try: - convert(args.json, args.text) + convert(args.input, args.output) finally: - args.json.close() - args.text.close() + args.input.close() + args.output.close() From bb5890085735d9e27d0ee4da40576f6d9fc5f42c Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 12 Sep 2023 13:47:46 -0500 Subject: [PATCH 7/8] Make help strings lowercase --- scripts/convert_trusted_setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/convert_trusted_setup.py b/scripts/convert_trusted_setup.py index 89655c7a8..a42b13829 100755 --- a/scripts/convert_trusted_setup.py +++ b/scripts/convert_trusted_setup.py @@ -27,13 +27,13 @@ def convert(ts_json: TextIO, ts_text: TextIO) -> None: "--input", required=True, type=argparse.FileType("r"), - help="The trusted setup in JSON format", + help="the trusted setup in JSON format", ) parser.add_argument( "--output", required=True, type=argparse.FileType("w"), - help="The trusted setup in text format", + help="the trusted setup in text format", ) args = parser.parse_args() From 594c6d7152f33511bcb2caf6681f96c460eaaecf Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Wed, 18 Oct 2023 08:24:25 -0500 Subject: [PATCH 8/8] Update to reflect new changes in #3521 --- .github/workflows/trusted-setup-tests.yml | 19 ++++++------------- scripts/convert_trusted_setup.py | 4 ++-- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.github/workflows/trusted-setup-tests.yml b/.github/workflows/trusted-setup-tests.yml index 705a2f473..d5e3b19d3 100644 --- a/.github/workflows/trusted-setup-tests.yml +++ b/.github/workflows/trusted-setup-tests.yml @@ -16,16 +16,9 @@ jobs: with: python-version: '3.x' - - name: Download minimal preset - run: wget -O minimal.json 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 minimal.json --output minimal.txt - - name: Compare to existing file - run: cmp src/trusted_setup_4.txt minimal.txt - - - name: Download mainnet preset - run: wget -O mainnet.json 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 mainnet.json --output mainnet.txt - - name: Compare to existing file - run: cmp src/trusted_setup.txt mainnet.txt + - 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 diff --git a/scripts/convert_trusted_setup.py b/scripts/convert_trusted_setup.py index a42b13829..e1586d556 100755 --- a/scripts/convert_trusted_setup.py +++ b/scripts/convert_trusted_setup.py @@ -8,8 +8,8 @@ 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"] + 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)