From 638835bd8b2858d80f67a950abf40a79b4874ae9 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Wed, 8 Jan 2025 17:47:49 +0100 Subject: [PATCH] add trusted setup constant (#36) This helps load the trusted setup whose location is relative to the kzg module, which can be fluid --- kzg4844/kzg.nim | 2 +- kzg4844/kzg_abi.nim | 20 ++++++++++---------- tests/test_all.nim | 5 +++++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/kzg4844/kzg.nim b/kzg4844/kzg.nim index 8150b01..74b100b 100644 --- a/kzg4844/kzg.nim +++ b/kzg4844/kzg.nim @@ -18,4 +18,4 @@ import ./kzg_abi # compile sha256.c export - kzg + kzg, kzg_abi.trustedSetup diff --git a/kzg4844/kzg_abi.nim b/kzg4844/kzg_abi.nim index d0ea0b3..ec50c05 100644 --- a/kzg4844/kzg_abi.nim +++ b/kzg4844/kzg_abi.nim @@ -9,17 +9,17 @@ # Ensure "c_kzg_4844.h" in this directory takes precedence import std/[os, strutils] -{.passc: "-I" & quoteShell(currentSourcePath.rsplit({DirSep, AltSep}, 1)[0]).} -import - ./csources/bindings/nim/kzg_abi +const + currentDir = currentSourcePath.rsplit({DirSep, AltSep}, 1)[0] + trustedSetup* = + staticRead(currentDir & "/csources/src/trusted_setup.txt") -export - kzg_abi +{.passc: "-I" & quoteShell(currentDir).} + +import ./csources/bindings/nim/kzg_abi + +export kzg_abi when defined(kzgExternalBlstNoSha256): - import std/strutils - from os import DirSep - const - kzgPath = currentSourcePath.rsplit(DirSep, 1)[0] & "/" - {.compile: kzgPath & "sha256.c"} + {.compile: currentDir & "/sha256.c".} diff --git a/tests/test_all.nim b/tests/test_all.nim index 56e8b27..dee6dd4 100644 --- a/tests/test_all.nim +++ b/tests/test_all.nim @@ -10,8 +10,13 @@ {.warning[UnusedImport]:off.} import + unittest2, ../kzg4844/kzg, ../kzg4844/kzg_abi # do nothing else, all tests are done in c-kzg-4844. # we only need to make sure our imports are compileable + +test "Check that trusted setup can be loaded": + check: + loadTrustedSetupFromString(trustedSetup, 0) == Result[void, string].ok()