From 36b51e2f1853ffba15a08df1cfd1a1b1c266ccd4 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Mon, 1 Jul 2024 22:52:06 +0100 Subject: [PATCH 01/21] add script for building rust lib --- build_peerdas_lib.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 build_peerdas_lib.sh diff --git a/build_peerdas_lib.sh b/build_peerdas_lib.sh new file mode 100755 index 0000000000..d49d58fe5e --- /dev/null +++ b/build_peerdas_lib.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# Current usage: ./build_peerdas_lib.sh vendor/nimpeerdaskzg + +set -e # Exit immediately if a command exits with a non-zero status. + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + + +DESTINATION_FOLDER=$1 # Destination folder to copy the built nim library with the static lib include to + +COMMIT_HASH="2becff04b0058c032b30886dac479130a62db792" # commit to checkout rust lib at +REPO_URL="https://github.com/crate-crypto/peerdas-kzg" + +echo "Building peerdas-kzg with commit hash: $COMMIT_HASH and destination: $DESTINATION_FOLDER" + +TEMP_DIR=$(mktemp -d) +echo "Created temporary directory: $TEMP_DIR" + +echo "Cloning repository..." +git clone "$REPO_URL" "$TEMP_DIR" + +cd "$TEMP_DIR" + +echo "Checking out commit: $COMMIT_HASH" +git checkout "$COMMIT_HASH" + +echo "Building Rust Library: Running ./scripts/compile.sh nim" +if [ -f "./scripts/compile.sh" ]; then + ./scripts/compile.sh nim +else + echo "Error: ./scripts/compile.sh not found" + exit 1 +fi + +if [ ! -d "bindings/nim" ]; then + echo "Error: bindings/nim directory not found" + exit 1 +fi + +# Move back to the original directory that the script was called from +cd - + +echo "Creating destination folder: $DESTINATION_FOLDER" +mkdir -p "$DESTINATION_FOLDER" + +# Copy the nim code to the destination folder (includes the built static lib) +echo "Copying contents of bindings/nim/nim_code to $DESTINATION_FOLDER" +cp -a "$TEMP_DIR/bindings/nim/nim_code/." "$DESTINATION_FOLDER" + +# Clean up the temporary directory +rm -rf "$TEMP_DIR" + +echo "Successfully built peerdas-kzg library and copied the nimble package to $DESTINATION_FOLDER" From c3dd731daae6dc544b2457f65e994bbbf46487fc Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Mon, 1 Jul 2024 23:05:02 +0100 Subject: [PATCH 02/21] update commit hash --- build_peerdas_lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_peerdas_lib.sh b/build_peerdas_lib.sh index d49d58fe5e..b3d469846d 100755 --- a/build_peerdas_lib.sh +++ b/build_peerdas_lib.sh @@ -12,7 +12,7 @@ fi DESTINATION_FOLDER=$1 # Destination folder to copy the built nim library with the static lib include to -COMMIT_HASH="2becff04b0058c032b30886dac479130a62db792" # commit to checkout rust lib at +COMMIT_HASH="4205937b69945f23731d90ba2970f19fa4a5e06b" # commit to checkout rust lib at REPO_URL="https://github.com/crate-crypto/peerdas-kzg" echo "Building peerdas-kzg with commit hash: $COMMIT_HASH and destination: $DESTINATION_FOLDER" From 10e4f528da4b9247e5cdf8ec85d9509c03bc360e Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Mon, 1 Jul 2024 23:05:39 +0100 Subject: [PATCH 03/21] example usage --- tests/consensus_spec/test_fixture_kzg.nim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/consensus_spec/test_fixture_kzg.nim b/tests/consensus_spec/test_fixture_kzg.nim index 029007673b..e35bc25e19 100644 --- a/tests/consensus_spec/test_fixture_kzg.nim +++ b/tests/consensus_spec/test_fixture_kzg.nim @@ -12,6 +12,7 @@ import std/json, yaml, kzg4844/kzg_ex, + ../../../vendor/nimpeerdaskzg/nim_peerdas_kzg/nim_peerdas_kzg, stint, chronicles, stew/[byteutils, results], @@ -39,7 +40,10 @@ func fromHex[N: static int](s: string): Opt[array[N, byte]] = except ValueError: Opt.none array[N, byte] +var ctx: nim_peerdas_kzg.KZGCtx + block: + ctx = newKZGCtx() template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0] doAssert Kzg.loadTrustedSetup( sourceDir & @@ -61,10 +65,13 @@ proc runBlobToKzgCommitmentTest(suiteName, suitePath, path: string) = check output.kind == JNull else: let commitment = blobToKzgCommitment(blob.get) + # var blobObject = Blob(bytes: blob.get) + # let commitment = ctx.blobToKzgCommitment(blobObject) check: if commitment.isErr: output.kind == JNull else: + # commitment.get.bytes == fromHex[48](output.getStr).get commitment.get == fromHex[48](output.getStr).get proc runVerifyKzgProofTest(suiteName, suitePath, path: string) = From 26f34b93fc490cafd61efc347b3dc4f44bf72669 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Mon, 1 Jul 2024 23:14:13 +0100 Subject: [PATCH 04/21] show how to use one of the methods in rust-kzg library --- tests/consensus_spec/test_fixture_kzg.nim | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/consensus_spec/test_fixture_kzg.nim b/tests/consensus_spec/test_fixture_kzg.nim index e35bc25e19..9e61509945 100644 --- a/tests/consensus_spec/test_fixture_kzg.nim +++ b/tests/consensus_spec/test_fixture_kzg.nim @@ -64,15 +64,13 @@ proc runBlobToKzgCommitmentTest(suiteName, suitePath, path: string) = if blob.isNone: check output.kind == JNull else: - let commitment = blobToKzgCommitment(blob.get) - # var blobObject = Blob(bytes: blob.get) - # let commitment = ctx.blobToKzgCommitment(blobObject) + var blobObject = Blob(bytes: blob.get) + let commitment = ctx.blobToKzgCommitment(blobObject) check: if commitment.isErr: output.kind == JNull else: - # commitment.get.bytes == fromHex[48](output.getStr).get - commitment.get == fromHex[48](output.getStr).get + commitment.get.bytes == fromHex[48](output.getStr).get proc runVerifyKzgProofTest(suiteName, suitePath, path: string) = let relativePathComponent = path.relativeTestPathComponent(suitePath) From 222599d0c5a67ef7d8f2c12b0bf9d4c1eaf3b884 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 2 Jul 2024 11:00:15 +0100 Subject: [PATCH 05/21] modify test to use compile time flag --- tests/consensus_spec/test_fixture_kzg.nim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/consensus_spec/test_fixture_kzg.nim b/tests/consensus_spec/test_fixture_kzg.nim index 9e61509945..485d48f5dd 100644 --- a/tests/consensus_spec/test_fixture_kzg.nim +++ b/tests/consensus_spec/test_fixture_kzg.nim @@ -64,13 +64,19 @@ proc runBlobToKzgCommitmentTest(suiteName, suitePath, path: string) = if blob.isNone: check output.kind == JNull else: - var blobObject = Blob(bytes: blob.get) - let commitment = ctx.blobToKzgCommitment(blobObject) + when defined(USE_NIMPEERDAS_KZG): + var blobObject = Blob(bytes: blob.get) + let commitment = ctx.blobToKzgCommitment(blobObject) + else: + let commitment = blobToKzgCommitment(blob.get) check: if commitment.isErr: output.kind == JNull else: - commitment.get.bytes == fromHex[48](output.getStr).get + when defined(USE_NIMPEERDAS_KZG): + commitment.get.bytes == fromHex[48](output.getStr).get + else: + commitment.get == fromHex[48](output.getStr).get proc runVerifyKzgProofTest(suiteName, suitePath, path: string) = let relativePathComponent = path.relativeTestPathComponent(suitePath) From 644c10856ded204f41f0c39aa166b0e120041bbe Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 2 Jul 2024 11:03:29 +0100 Subject: [PATCH 06/21] temporarily add make commands to make testing a bit easier --- Makefile | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6607d92cf2..570cfede06 100644 --- a/Makefile +++ b/Makefile @@ -152,7 +152,7 @@ GIT_SUBMODULE_UPDATE := git $(GIT_SUBMODULE_CONFIG) submodule update --init --re else # "variables.mk" was included. Business as usual until the end of this file. # default target, because it's the first one that doesn't start with '.' -all: | $(TOOLS) libnfuzz.so libnfuzz.a $(PLATFORM_SPECIFIC_TARGETS) +all: | $(TOOLS) libnfuzz.so libnfuzz.a $(PLATFORM_SPECIFIC_TARGETS) build-rust-peerdas-kzg # must be included after the default target -include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk @@ -391,7 +391,7 @@ block_sim: | build deps DISABLE_TEST_FIXTURES_SCRIPT := 0 # This parameter passing scheme is ugly, but short. -test: | $(XML_TEST_BINARIES) $(TEST_BINARIES) +test: | $(XML_TEST_BINARIES) $(TEST_BINARIES) test-rust-peerdas-kzg ifeq ($(DISABLE_TEST_FIXTURES_SCRIPT), 0) V=$(V) scripts/setup_scenarios.sh endif @@ -606,6 +606,13 @@ define CLEAN_NETWORK rm -rf build/data/shared_$(1)*/*.log endef +# Build the rust peerdas-kzg library +build-rust-peerdas-kzg: + @./build_peerdas_lib.sh vendor/nimpeerdaskzg +test-rust-peerdas-kzg: # | build deps + + echo -e $(BUILD_MSG) "Running KZG fixture test" && \ + $(ENV_SCRIPT) nim c -r -d:USE_NIMPEERDAS_KZG tests/consensus_spec/test_fixture_kzg.nim && \ + echo -e $(BUILD_END_MSG) "KZG fixture test completed" ### ### Sepolia ### From b280e45e9dcd83a6b9aca94ef5facd6703948f1e Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 2 Jul 2024 11:55:40 +0100 Subject: [PATCH 07/21] add a kzg.nim shim file --- beacon_chain/kzg.nim | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 beacon_chain/kzg.nim diff --git a/beacon_chain/kzg.nim b/beacon_chain/kzg.nim new file mode 100644 index 0000000000..b8429c61df --- /dev/null +++ b/beacon_chain/kzg.nim @@ -0,0 +1,40 @@ +# beacon_chain +# Copyright (c) 2024 Status Research & Development GmbH +# Licensed and distributed under either of +# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). +# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). +# at your option. This file may not be copied, modified, or distributed except according to those terms. + +{.push raises: [].} +{.used.} + +import + std/os, + stew/results, + kzg4844/kzg_ex, + ../../../vendor/nimpeerdaskzg/nim_peerdas_kzg/nim_peerdas_kzg + + +from std/strutils import rsplit + +var ctx: nim_peerdas_kzg.KZGCtx + +proc init_kzg*(): bool = + # TODO: no compilation flag here because c-kzg does more than peerdas functionality. + ctx = newKZGCtx() + template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0] + return Kzg.loadTrustedSetup( + sourceDir & + "/../vendor/nim-kzg4844/kzg4844/csources/src/trusted_setup.txt").isOk + +proc free_kzg*(): Result[void, string] = + # TODO: add code to free nim_peerdas_kzg. Removed due to nim not allowing + # TODO; the particular destory function being called. + Kzg.freeTrustedSetup() + +proc blobToKZGCommitment*(blob : array[131_072, byte]): Result[array[48, byte], string] = + when defined(USE_NIMPEERDAS_KZG): + let commitment = ?ctx.blobToKzgCommitment(Blob(bytes: blob)) + ok(commitment.bytes) + else: + kzg_ex.blobToKZGCommitment(blob) From 69719ff91ce057a604696375360f335222da470b Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 2 Jul 2024 11:56:29 +0100 Subject: [PATCH 08/21] edit tests to use kzg shim --- tests/consensus_spec/test_fixture_kzg.nim | 28 ++++++++--------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/tests/consensus_spec/test_fixture_kzg.nim b/tests/consensus_spec/test_fixture_kzg.nim index 485d48f5dd..b01b04cab1 100644 --- a/tests/consensus_spec/test_fixture_kzg.nim +++ b/tests/consensus_spec/test_fixture_kzg.nim @@ -11,14 +11,17 @@ import std/json, yaml, - kzg4844/kzg_ex, - ../../../vendor/nimpeerdaskzg/nim_peerdas_kzg/nim_peerdas_kzg, + ../../../beacon_chain/kzg, stint, chronicles, stew/[byteutils, results], ../testutil, ./fixtures_utils, ./os_ops +# TODO: don't import blobToKzgCommitment since we +# TODO: are using the beacon_chain/kzg module for it +import kzg4844/kzg_ex except blobToKzgCommitment + from std/sequtils import anyIt, mapIt, toSeq from std/strutils import rsplit @@ -40,14 +43,8 @@ func fromHex[N: static int](s: string): Opt[array[N, byte]] = except ValueError: Opt.none array[N, byte] -var ctx: nim_peerdas_kzg.KZGCtx - block: - ctx = newKZGCtx() - template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0] - doAssert Kzg.loadTrustedSetup( - sourceDir & - "/../../vendor/nim-kzg4844/kzg4844/csources/src/trusted_setup.txt").isOk + doAssert init_kzg() proc runBlobToKzgCommitmentTest(suiteName, suitePath, path: string) = let relativePathComponent = path.relativeTestPathComponent(suitePath) @@ -64,19 +61,12 @@ proc runBlobToKzgCommitmentTest(suiteName, suitePath, path: string) = if blob.isNone: check output.kind == JNull else: - when defined(USE_NIMPEERDAS_KZG): - var blobObject = Blob(bytes: blob.get) - let commitment = ctx.blobToKzgCommitment(blobObject) - else: - let commitment = blobToKzgCommitment(blob.get) + let commitment = blobToKzgCommitment(blob.get) check: if commitment.isErr: output.kind == JNull else: - when defined(USE_NIMPEERDAS_KZG): - commitment.get.bytes == fromHex[48](output.getStr).get - else: - commitment.get == fromHex[48](output.getStr).get + commitment.get == fromHex[48](output.getStr).get proc runVerifyKzgProofTest(suiteName, suitePath, path: string) = let relativePathComponent = path.relativeTestPathComponent(suitePath) @@ -410,4 +400,4 @@ suite suiteName: for kind, path in walkDir(testsDir, relative = true, checkDir = true): runVerifyCellKzgProofBatchTest(suiteName, testsDir, testsDir/path) -doAssert Kzg.freeTrustedSetup().isOk \ No newline at end of file +doAssert free_kzg().isOk \ No newline at end of file From 215f4842b3532a0c948fef0b6ab6b1abf9c54746 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 2 Jul 2024 12:03:27 +0100 Subject: [PATCH 09/21] camelCase --- beacon_chain/kzg.nim | 4 ++-- tests/consensus_spec/test_fixture_kzg.nim | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/beacon_chain/kzg.nim b/beacon_chain/kzg.nim index b8429c61df..15ac26af23 100644 --- a/beacon_chain/kzg.nim +++ b/beacon_chain/kzg.nim @@ -19,7 +19,7 @@ from std/strutils import rsplit var ctx: nim_peerdas_kzg.KZGCtx -proc init_kzg*(): bool = +proc initKZG*(): bool = # TODO: no compilation flag here because c-kzg does more than peerdas functionality. ctx = newKZGCtx() template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0] @@ -27,7 +27,7 @@ proc init_kzg*(): bool = sourceDir & "/../vendor/nim-kzg4844/kzg4844/csources/src/trusted_setup.txt").isOk -proc free_kzg*(): Result[void, string] = +proc freeKZG*(): Result[void, string] = # TODO: add code to free nim_peerdas_kzg. Removed due to nim not allowing # TODO; the particular destory function being called. Kzg.freeTrustedSetup() diff --git a/tests/consensus_spec/test_fixture_kzg.nim b/tests/consensus_spec/test_fixture_kzg.nim index b01b04cab1..5c5356356e 100644 --- a/tests/consensus_spec/test_fixture_kzg.nim +++ b/tests/consensus_spec/test_fixture_kzg.nim @@ -44,7 +44,7 @@ func fromHex[N: static int](s: string): Opt[array[N, byte]] = Opt.none array[N, byte] block: - doAssert init_kzg() + doAssert initKZG() proc runBlobToKzgCommitmentTest(suiteName, suitePath, path: string) = let relativePathComponent = path.relativeTestPathComponent(suitePath) @@ -400,4 +400,4 @@ suite suiteName: for kind, path in walkDir(testsDir, relative = true, checkDir = true): runVerifyCellKzgProofBatchTest(suiteName, testsDir, testsDir/path) -doAssert free_kzg().isOk \ No newline at end of file +doAssert freeKZG().isOk \ No newline at end of file From 19148b64fe80118ed5542a771bd7a578ad43b63b Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Wed, 3 Jul 2024 10:57:10 +0100 Subject: [PATCH 10/21] add copyright information --- build_peerdas_lib.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build_peerdas_lib.sh b/build_peerdas_lib.sh index b3d469846d..e859cba5cc 100755 --- a/build_peerdas_lib.sh +++ b/build_peerdas_lib.sh @@ -1,6 +1,13 @@ #!/bin/bash -# Current usage: ./build_peerdas_lib.sh vendor/nimpeerdaskzg +# Copyright (c) 2020-2023 Status Research & Development GmbH. Licensed under +# either of: +# - Apache License, version 2.0 +# - MIT license +# at your option. This file may not be copied, modified, or distributed except +# according to those terms. + +# Current usage: ./build_peerdas_lib.sh nimpeerdaskzg set -e # Exit immediately if a command exits with a non-zero status. From 2b4c36e681691a6d1e555662d3eea52e554723f0 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Wed, 3 Jul 2024 10:59:29 +0100 Subject: [PATCH 11/21] do not put rust lib in vendor folder since nimbus-build-system uses that for git submodules --- Makefile | 2 +- beacon_chain/kzg.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 570cfede06..b21d166b91 100644 --- a/Makefile +++ b/Makefile @@ -608,7 +608,7 @@ endef # Build the rust peerdas-kzg library build-rust-peerdas-kzg: - @./build_peerdas_lib.sh vendor/nimpeerdaskzg + @./build_peerdas_lib.sh nimpeerdaskzg test-rust-peerdas-kzg: # | build deps + echo -e $(BUILD_MSG) "Running KZG fixture test" && \ $(ENV_SCRIPT) nim c -r -d:USE_NIMPEERDAS_KZG tests/consensus_spec/test_fixture_kzg.nim && \ diff --git a/beacon_chain/kzg.nim b/beacon_chain/kzg.nim index 15ac26af23..415753dbf0 100644 --- a/beacon_chain/kzg.nim +++ b/beacon_chain/kzg.nim @@ -12,7 +12,7 @@ import std/os, stew/results, kzg4844/kzg_ex, - ../../../vendor/nimpeerdaskzg/nim_peerdas_kzg/nim_peerdas_kzg + ../../../nimpeerdaskzg/nim_peerdas_kzg/nim_peerdas_kzg from std/strutils import rsplit From 6b76b2b5bfa40538b2fb919273500749c180e3e0 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Wed, 3 Jul 2024 11:48:59 +0100 Subject: [PATCH 12/21] add rust to the CI to build --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f8a85ef77..405b5a85f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,6 +71,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.78.0 - name: Restore llvm-mingw (Windows) from cache if: runner.os == 'Windows' From b81dd3975341f4d609134050a3ca356bfb87ffad Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Wed, 3 Jul 2024 12:05:58 +0100 Subject: [PATCH 13/21] Setup -> Set up --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 405b5a85f7..73b488241a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Setup Rust toolchain + - name: Set up Rust toolchain uses: dtolnay/rust-toolchain@master with: toolchain: 1.78.0 From 086d100f69154b3aeee67792df47970d0aff3f74 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Wed, 3 Jul 2024 12:09:14 +0100 Subject: [PATCH 14/21] address rest of feedback --- beacon_chain/kzg.nim | 5 ++--- build_peerdas_lib.sh | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/beacon_chain/kzg.nim b/beacon_chain/kzg.nim index 415753dbf0..dc8a230250 100644 --- a/beacon_chain/kzg.nim +++ b/beacon_chain/kzg.nim @@ -6,11 +6,10 @@ # at your option. This file may not be copied, modified, or distributed except according to those terms. {.push raises: [].} -{.used.} import std/os, - stew/results, + results, kzg4844/kzg_ex, ../../../nimpeerdaskzg/nim_peerdas_kzg/nim_peerdas_kzg @@ -23,7 +22,7 @@ proc initKZG*(): bool = # TODO: no compilation flag here because c-kzg does more than peerdas functionality. ctx = newKZGCtx() template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0] - return Kzg.loadTrustedSetup( + Kzg.loadTrustedSetup( sourceDir & "/../vendor/nim-kzg4844/kzg4844/csources/src/trusted_setup.txt").isOk diff --git a/build_peerdas_lib.sh b/build_peerdas_lib.sh index e859cba5cc..fae407df51 100755 --- a/build_peerdas_lib.sh +++ b/build_peerdas_lib.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2020-2023 Status Research & Development GmbH. Licensed under # either of: @@ -9,7 +9,7 @@ # Current usage: ./build_peerdas_lib.sh nimpeerdaskzg -set -e # Exit immediately if a command exits with a non-zero status. +set -eu # Exit immediately if a command exits with a non-zero status. if [ "$#" -ne 1 ]; then echo "Usage: $0 " From 1c7a542d0d8f0530c5779ac5408c59c76c81228c Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Wed, 3 Jul 2024 12:33:45 +0100 Subject: [PATCH 15/21] update copyright year --- build_peerdas_lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_peerdas_lib.sh b/build_peerdas_lib.sh index fae407df51..9d6da82835 100755 --- a/build_peerdas_lib.sh +++ b/build_peerdas_lib.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright (c) 2020-2023 Status Research & Development GmbH. Licensed under +# Copyright (c) 2024 Status Research & Development GmbH. Licensed under # either of: # - Apache License, version 2.0 # - MIT license From 1847e35dce6aa9648da711fd071bb78d7b292caf Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Wed, 3 Jul 2024 12:38:59 +0100 Subject: [PATCH 16/21] install gnu target for windows instead of default msvc --- build_peerdas_lib.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build_peerdas_lib.sh b/build_peerdas_lib.sh index 9d6da82835..8144f8133e 100755 --- a/build_peerdas_lib.sh +++ b/build_peerdas_lib.sh @@ -29,12 +29,17 @@ echo "Created temporary directory: $TEMP_DIR" echo "Cloning repository..." git clone "$REPO_URL" "$TEMP_DIR" - cd "$TEMP_DIR" echo "Checking out commit: $COMMIT_HASH" git checkout "$COMMIT_HASH" +# Check if the user is on Windows and install gnu target instead of msvc +if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then + echo "Detected Windows environment. Adding x86_64-pc-windows-gnu target..." + rustup target add x86_64-pc-windows-gnu +fi + echo "Building Rust Library: Running ./scripts/compile.sh nim" if [ -f "./scripts/compile.sh" ]; then ./scripts/compile.sh nim From 79477840583aa441bf8b9d5a73ef6b4e64b09c7e Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Wed, 3 Jul 2024 14:43:28 +0100 Subject: [PATCH 17/21] update to remove java building --- build_peerdas_lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_peerdas_lib.sh b/build_peerdas_lib.sh index 8144f8133e..5b23506604 100755 --- a/build_peerdas_lib.sh +++ b/build_peerdas_lib.sh @@ -19,7 +19,7 @@ fi DESTINATION_FOLDER=$1 # Destination folder to copy the built nim library with the static lib include to -COMMIT_HASH="4205937b69945f23731d90ba2970f19fa4a5e06b" # commit to checkout rust lib at +COMMIT_HASH="fc339dc9bb886432871b4fd706cf4fdaa8269cce" # commit to checkout rust lib at REPO_URL="https://github.com/crate-crypto/peerdas-kzg" echo "Building peerdas-kzg with commit hash: $COMMIT_HASH and destination: $DESTINATION_FOLDER" From 9b99d48f1df65b00dace5b8248c74287419733ec Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Sun, 14 Jul 2024 21:43:07 +0100 Subject: [PATCH 18/21] chore: update commit hash --- build_peerdas_lib.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/build_peerdas_lib.sh b/build_peerdas_lib.sh index 5b23506604..95cfd804c0 100755 --- a/build_peerdas_lib.sh +++ b/build_peerdas_lib.sh @@ -19,7 +19,7 @@ fi DESTINATION_FOLDER=$1 # Destination folder to copy the built nim library with the static lib include to -COMMIT_HASH="fc339dc9bb886432871b4fd706cf4fdaa8269cce" # commit to checkout rust lib at +COMMIT_HASH="5bb15ec0ecba4f1265ab171d0b952f3f074f808f" # commit to checkout rust lib at REPO_URL="https://github.com/crate-crypto/peerdas-kzg" echo "Building peerdas-kzg with commit hash: $COMMIT_HASH and destination: $DESTINATION_FOLDER" @@ -35,18 +35,18 @@ echo "Checking out commit: $COMMIT_HASH" git checkout "$COMMIT_HASH" # Check if the user is on Windows and install gnu target instead of msvc -if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then - echo "Detected Windows environment. Adding x86_64-pc-windows-gnu target..." - rustup target add x86_64-pc-windows-gnu -fi - -echo "Building Rust Library: Running ./scripts/compile.sh nim" -if [ -f "./scripts/compile.sh" ]; then - ./scripts/compile.sh nim -else - echo "Error: ./scripts/compile.sh not found" - exit 1 -fi +# if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then +# echo "Detected Windows environment. Adding x86_64-pc-windows-gnu target..." +# rustup target add x86_64-pc-windows-gnu +# fi + +# echo "Building Rust Library: Running ./scripts/compile.sh nim" +# if [ -f "./scripts/compile.sh" ]; then +# ./scripts/compile.sh nim +# else +# echo "Error: ./scripts/compile.sh not found" +# exit 1 +# fi if [ ! -d "bindings/nim" ]; then echo "Error: bindings/nim directory not found" From d4de37961e7e1c16bfef18becde4ae06422dfc10 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Sun, 14 Jul 2024 22:21:57 +0100 Subject: [PATCH 19/21] chore: fix import paths --- beacon_chain/kzg.nim | 2 +- tests/consensus_spec/test_fixture_kzg.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/beacon_chain/kzg.nim b/beacon_chain/kzg.nim index dc8a230250..e7647ac57d 100644 --- a/beacon_chain/kzg.nim +++ b/beacon_chain/kzg.nim @@ -11,7 +11,7 @@ import std/os, results, kzg4844/kzg_ex, - ../../../nimpeerdaskzg/nim_peerdas_kzg/nim_peerdas_kzg + ../nimpeerdaskzg/nim_peerdas_kzg/nim_peerdas_kzg from std/strutils import rsplit diff --git a/tests/consensus_spec/test_fixture_kzg.nim b/tests/consensus_spec/test_fixture_kzg.nim index 5c5356356e..48f70a277a 100644 --- a/tests/consensus_spec/test_fixture_kzg.nim +++ b/tests/consensus_spec/test_fixture_kzg.nim @@ -11,7 +11,7 @@ import std/json, yaml, - ../../../beacon_chain/kzg, + ../../beacon_chain/kzg, stint, chronicles, stew/[byteutils, results], From 590bb896d4d6879c630349c734c2a722dc61874f Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 16 Jul 2024 14:26:33 +0100 Subject: [PATCH 20/21] Patch by agnish Co-authored-by: Agnish Ghosh --- tests/consensus_spec/test_fixture_kzg.nim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/consensus_spec/test_fixture_kzg.nim b/tests/consensus_spec/test_fixture_kzg.nim index 48f70a277a..79a83782ff 100644 --- a/tests/consensus_spec/test_fixture_kzg.nim +++ b/tests/consensus_spec/test_fixture_kzg.nim @@ -213,8 +213,9 @@ proc runComputeCellsTest(suiteName, suitePath, path: string) = if p.isErr: check output.kind == JNull else: + let p_val = newClone p.get for i in 0.. Date: Tue, 16 Jul 2024 20:00:54 +0100 Subject: [PATCH 21/21] Copy agnish patch Co-authored-by: Agnish Ghosh --- tests/consensus_spec/test_fixture_kzg.nim | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/consensus_spec/test_fixture_kzg.nim b/tests/consensus_spec/test_fixture_kzg.nim index 79a83782ff..a275786de8 100644 --- a/tests/consensus_spec/test_fixture_kzg.nim +++ b/tests/consensus_spec/test_fixture_kzg.nim @@ -209,13 +209,12 @@ proc runComputeCellsTest(suiteName, suitePath, path: string) = if blob.isNone: check output.kind == JNull else: - let p = computeCells(blob.get) - if p.isErr: + let p = newClone computeCells(blob.get) + if p[].isErr: check output.kind == JNull else: - let p_val = newClone p.get - for i in 0..