From 8683fac75a582ca4217dfd03d5fdde18fb052f8b Mon Sep 17 00:00:00 2001 From: dancoffman Date: Fri, 4 Nov 2022 16:56:16 -0700 Subject: [PATCH 1/9] Basic setup instructions in README --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 1f2be84..ec0668e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # C-KZG-4844: A minimal library for EIP-4844 Polynomial Commitments This is a copy of C-KZG stripped down to support the [Polynomial Commitments](https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/polynomial-commitments.md) API: + - `compute_aggregate_kzg_proof` - `verify_aggregate_kzg_proof` - `blob_to_kzg_commitment` @@ -9,3 +10,25 @@ This is a copy of C-KZG stripped down to support the [Polynomial Commitments](ht We also provide `load_trusted_setup` and `free_trusted_setup` to load the trusted setup data from a file into an object that can be passed to the API functions, and functions for converting commitments/proofs/points to/from bytes. + +## Installation + +Install the blst submodule + +``` +git submodule update --init +``` + +Build blst + +``` +cd src +make blst +``` + +Build the C-KZG code + +``` +cd src +make +``` From 1d1254e3803689dc168095d6870a4022838b0ab5 Mon Sep 17 00:00:00 2001 From: dancoffman Date: Fri, 4 Nov 2022 17:00:26 -0700 Subject: [PATCH 2/9] gitignore dist --- bindings/node.js/dist/dts/kzg.d.ts | 11 -------- bindings/node.js/dist/dts/test.d.ts | 1 - bindings/node.js/dist/kzg.js | 44 ----------------------------- 3 files changed, 56 deletions(-) delete mode 100644 bindings/node.js/dist/dts/kzg.d.ts delete mode 100644 bindings/node.js/dist/dts/test.d.ts delete mode 100644 bindings/node.js/dist/kzg.js diff --git a/bindings/node.js/dist/dts/kzg.d.ts b/bindings/node.js/dist/dts/kzg.d.ts deleted file mode 100644 index c542a1f..0000000 --- a/bindings/node.js/dist/dts/kzg.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export declare type BLSFieldElement = Uint8Array; -export declare type KZGProof = Uint8Array; -export declare type KZGCommitment = Uint8Array; -export declare type Blob = Uint8Array; -export declare const FIELD_ELEMENTS_PER_BLOB: number; -export declare const BYTES_PER_FIELD_ELEMENT: number; -export declare function loadTrustedSetup(filePath: string): void; -export declare function freeTrustedSetup(): void; -export declare function blobToKzgCommitment(blob: Blob): KZGCommitment; -export declare function computeAggregateKzgProof(blobs: Blob[]): KZGProof; -export declare function verifyAggregateKzgProof(blobs: Blob[], expectedKzgCommitments: KZGCommitment[], kzgAggregatedProof: KZGProof): boolean; diff --git a/bindings/node.js/dist/dts/test.d.ts b/bindings/node.js/dist/dts/test.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/bindings/node.js/dist/dts/test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/bindings/node.js/dist/kzg.js b/bindings/node.js/dist/kzg.js deleted file mode 100644 index d4aeac5..0000000 --- a/bindings/node.js/dist/kzg.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -/** - * The public interface of this module exposes the functions as specified by - * https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/polynomial-commitments.md#kzg - */ -const kzg = require("./kzg.node"); -const FIELD_ELEMENTS_PER_BLOB = kzg.FIELD_ELEMENTS_PER_BLOB; -const BYTES_PER_FIELD_ELEMENT = kzg.BYTES_PER_FIELD_ELEMENT; -// Stored as internal state -let setupHandle; -function requireSetupHandle() { - if (!setupHandle) { - throw new Error("You must call loadTrustedSetup to initialize KZG."); - } - return setupHandle; -} -function loadTrustedSetup(filePath) { - if (setupHandle) { - throw new Error("Call freeTrustedSetup before loading a new trusted setup."); - } - setupHandle = kzg.loadTrustedSetup(filePath); -} -function freeTrustedSetup() { - kzg.freeTrustedSetup(requireSetupHandle()); - setupHandle = undefined; -} -function blobToKzgCommitment(blob) { - return kzg.blobToKzgCommitment(blob, requireSetupHandle()); -} -function computeAggregateKzgProof(blobs) { - return kzg.computeAggregateKzgProof(blobs, requireSetupHandle()); -} -function verifyAggregateKzgProof(blobs, expectedKzgCommitments, kzgAggregatedProof) { - return kzg.verifyAggregateKzgProof(blobs, expectedKzgCommitments, kzgAggregatedProof, requireSetupHandle()); -} - -exports.BYTES_PER_FIELD_ELEMENT = BYTES_PER_FIELD_ELEMENT; -exports.FIELD_ELEMENTS_PER_BLOB = FIELD_ELEMENTS_PER_BLOB; -exports.blobToKzgCommitment = blobToKzgCommitment; -exports.computeAggregateKzgProof = computeAggregateKzgProof; -exports.freeTrustedSetup = freeTrustedSetup; -exports.loadTrustedSetup = loadTrustedSetup; -exports.verifyAggregateKzgProof = verifyAggregateKzgProof; From c033f782b84167d6fe1a4280690f8929a009c0ed Mon Sep 17 00:00:00 2001 From: dancoffman Date: Fri, 4 Nov 2022 18:47:30 -0700 Subject: [PATCH 3/9] Start working on NPM publish --- bindings/node.js/.npmignore | 16 ++++++++++++++++ bindings/node.js/Makefile | 11 +++++++++-- bindings/node.js/package.json | 2 +- bindings/node.js/rollup.config.js | 6 +++++- 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 bindings/node.js/.npmignore diff --git a/bindings/node.js/.npmignore b/bindings/node.js/.npmignore new file mode 100644 index 0000000..f1513e1 --- /dev/null +++ b/bindings/node.js/.npmignore @@ -0,0 +1,16 @@ +.vscode +build +node_modules +.gitignore +.npmignore +.prettierignore +.prettierrc.json +*.o +*.node +test.ts +kzg.ts +jest.config.js +rollup.config.js +tsconfig.json +babel.config.js +dist/blst/bindings diff --git a/bindings/node.js/Makefile b/bindings/node.js/Makefile index 9aae264..8280cb6 100644 --- a/bindings/node.js/Makefile +++ b/bindings/node.js/Makefile @@ -3,8 +3,8 @@ all: clean build format test bundle clean: yarn node-gyp clean rm -rf build + rm -rf dist rm -f *.node - rm -f dist/kzg.node rm -f *.a rm -f *.o @@ -18,5 +18,12 @@ test: build format: yarn prettier --write . -bundle: +bundle: clean yarn rollup --config rollup.config.js --bundleConfigAsCjs + mkdir -p dist/deps/c-kzg + cp -r ../../blst dist/deps + cp ../../src/c_kzg_4844.c dist/deps/c-kzg + cp ../../src/c_kzg_4844.h dist/deps/c-kzg + +publish: + npm publish diff --git a/bindings/node.js/package.json b/bindings/node.js/package.json index 5c15850..7103aa9 100644 --- a/bindings/node.js/package.json +++ b/bindings/node.js/package.json @@ -1,6 +1,6 @@ { "name": "c-kzg", - "version": "0.0.1", + "version": "0.0.2", "description": "NodeJS bindings for C-KZG", "author": "Dan Coffman", "license": "MIT", diff --git a/bindings/node.js/rollup.config.js b/bindings/node.js/rollup.config.js index 383c4bc..5d0528d 100644 --- a/bindings/node.js/rollup.config.js +++ b/bindings/node.js/rollup.config.js @@ -6,5 +6,9 @@ export default { dir: "dist", format: "cjs", }, - plugins: [typescript()], + plugins: [ + typescript({ + exclude: ["test.ts"], + }), + ], }; From d09b1009b6f73a4d564d22ea42edafdea86bfca7 Mon Sep 17 00:00:00 2001 From: dancoffman Date: Sat, 5 Nov 2022 00:28:36 -0700 Subject: [PATCH 4/9] gyp that maybe works on yarn install --- bindings/node.js/.gitignore | 1 + bindings/node.js/.npmignore | 2 +- bindings/node.js/Makefile | 4 +++ bindings/node.js/binding.dist.gyp | 60 +++++++++++++++++++++++++++++++ bindings/node.js/binding.gyp | 4 --- 5 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 bindings/node.js/binding.dist.gyp diff --git a/bindings/node.js/.gitignore b/bindings/node.js/.gitignore index 6a76a2b..38f45ff 100644 --- a/bindings/node.js/.gitignore +++ b/bindings/node.js/.gitignore @@ -1,3 +1,4 @@ build +dist *.node node_modules diff --git a/bindings/node.js/.npmignore b/bindings/node.js/.npmignore index f1513e1..2d92dbf 100644 --- a/bindings/node.js/.npmignore +++ b/bindings/node.js/.npmignore @@ -13,4 +13,4 @@ jest.config.js rollup.config.js tsconfig.json babel.config.js -dist/blst/bindings +*.bak diff --git a/bindings/node.js/Makefile b/bindings/node.js/Makefile index 8280cb6..0dc2dc7 100644 --- a/bindings/node.js/Makefile +++ b/bindings/node.js/Makefile @@ -26,4 +26,8 @@ bundle: clean cp ../../src/c_kzg_4844.h dist/deps/c-kzg publish: + mv binding.gyp binding.gyp.bak + mv binding.dist.gyp binding.gyp npm publish + mv binding.gyp binding.dist.gyp + mv binding.gyp.bak binding.gyp diff --git a/bindings/node.js/binding.dist.gyp b/bindings/node.js/binding.dist.gyp new file mode 100644 index 0000000..9746356 --- /dev/null +++ b/bindings/node.js/binding.dist.gyp @@ -0,0 +1,60 @@ +{ + "targets": [ + { + "target_name": "kzg", + "cflags!": ["-fno-exceptions"], + "cflags_cc!": ["-fno-exceptions"], + "xcode_settings": { + "GCC_ENABLE_CPP_EXCEPTIONS": "YES", + "CLANG_CXX_LIBRARY": "libc++", + "MACOSX_DEPLOYMENT_TARGET": "13.0" + }, + "sources": ["kzg.cxx"], + "include_dirs": [ + "../../inc", + "../../src", + " Date: Sat, 5 Nov 2022 00:36:38 -0700 Subject: [PATCH 5/9] Required to publish blst/build --- bindings/node.js/.npmignore | 1 + bindings/node.js/Makefile | 2 +- bindings/node.js/package.json | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bindings/node.js/.npmignore b/bindings/node.js/.npmignore index 2d92dbf..de0f059 100644 --- a/bindings/node.js/.npmignore +++ b/bindings/node.js/.npmignore @@ -1,5 +1,6 @@ .vscode build +!dist/deps/blst/build node_modules .gitignore .npmignore diff --git a/bindings/node.js/Makefile b/bindings/node.js/Makefile index 0dc2dc7..da40fbe 100644 --- a/bindings/node.js/Makefile +++ b/bindings/node.js/Makefile @@ -25,7 +25,7 @@ bundle: clean cp ../../src/c_kzg_4844.c dist/deps/c-kzg cp ../../src/c_kzg_4844.h dist/deps/c-kzg -publish: +publish: bundle mv binding.gyp binding.gyp.bak mv binding.dist.gyp binding.gyp npm publish diff --git a/bindings/node.js/package.json b/bindings/node.js/package.json index 7103aa9..dc9c20e 100644 --- a/bindings/node.js/package.json +++ b/bindings/node.js/package.json @@ -1,6 +1,6 @@ { "name": "c-kzg", - "version": "0.0.2", + "version": "0.0.4", "description": "NodeJS bindings for C-KZG", "author": "Dan Coffman", "license": "MIT", From f3069d1ec9848fe6bdc9eaa89daeed9e3818d4aa Mon Sep 17 00:00:00 2001 From: dancoffman Date: Sat, 5 Nov 2022 00:46:26 -0700 Subject: [PATCH 6/9] Messy publish but it works --- bindings/node.js/.prettierrc.json | 2 +- bindings/node.js/binding.dist.gyp | 4 ++-- bindings/node.js/package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/node.js/.prettierrc.json b/bindings/node.js/.prettierrc.json index 6b2adca..3ec457f 100644 --- a/bindings/node.js/.prettierrc.json +++ b/bindings/node.js/.prettierrc.json @@ -2,7 +2,7 @@ "trailingComma": "all", "overrides": [ { - "files": "binding.gyp", + "files": "*.gyp", "options": { "parser": "json" } } ] diff --git a/bindings/node.js/binding.dist.gyp b/bindings/node.js/binding.dist.gyp index 9746356..f1a7267 100644 --- a/bindings/node.js/binding.dist.gyp +++ b/bindings/node.js/binding.dist.gyp @@ -11,8 +11,8 @@ }, "sources": ["kzg.cxx"], "include_dirs": [ - "../../inc", - "../../src", + "<(module_root_dir)/dist/deps/blst/bindings", + "<(module_root_dir)/dist/deps/c-kzg", " Date: Mon, 7 Nov 2022 11:45:36 -0800 Subject: [PATCH 7/9] cc works on Linux --- bindings/node.js/binding.dist.gyp | 2 +- bindings/node.js/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/node.js/binding.dist.gyp b/bindings/node.js/binding.dist.gyp index f1a7267..82e2a2b 100644 --- a/bindings/node.js/binding.dist.gyp +++ b/bindings/node.js/binding.dist.gyp @@ -36,7 +36,7 @@ ], "outputs": ["<(module_root_dir)/c_kzg_4844.o"], "action": [ - "clang", + "cc", "-I<(module_root_dir)/dist/deps/blst/bindings", "-O2", "-c", diff --git a/bindings/node.js/package.json b/bindings/node.js/package.json index df1cedf..1d16a00 100644 --- a/bindings/node.js/package.json +++ b/bindings/node.js/package.json @@ -1,6 +1,6 @@ { "name": "c-kzg", - "version": "0.0.6", + "version": "0.0.7", "description": "NodeJS bindings for C-KZG", "author": "Dan Coffman", "license": "MIT", From 26f5178d06b4f80e5fc7be27d3e5e8dbb2b41e06 Mon Sep 17 00:00:00 2001 From: dancoffman Date: Mon, 7 Nov 2022 14:35:10 -0800 Subject: [PATCH 8/9] git ignore xcode autogenerated file --- .gitignore | 1 + bindings/node.js/Makefile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4523091..370b496 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ inc/blst_aux.h* *bindings/csharp/*.exe *bindings/csharp/*.dll __pycache__ +.DS_Store diff --git a/bindings/node.js/Makefile b/bindings/node.js/Makefile index da40fbe..dafc576 100644 --- a/bindings/node.js/Makefile +++ b/bindings/node.js/Makefile @@ -27,7 +27,7 @@ bundle: clean publish: bundle mv binding.gyp binding.gyp.bak - mv binding.dist.gyp binding.gyp + cp binding.dist.gyp binding.gyp npm publish mv binding.gyp binding.dist.gyp mv binding.gyp.bak binding.gyp From e98ffa8c8e5b9dce8a48453257dfc85940aaa15f Mon Sep 17 00:00:00 2001 From: dancoffman Date: Mon, 7 Nov 2022 14:37:46 -0800 Subject: [PATCH 9/9] Make publish less able to leave files in bad state --- bindings/node.js/Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bindings/node.js/Makefile b/bindings/node.js/Makefile index dafc576..c5b56f7 100644 --- a/bindings/node.js/Makefile +++ b/bindings/node.js/Makefile @@ -28,6 +28,4 @@ bundle: clean publish: bundle mv binding.gyp binding.gyp.bak cp binding.dist.gyp binding.gyp - npm publish - mv binding.gyp binding.dist.gyp - mv binding.gyp.bak binding.gyp + npm publish && mv binding.gyp.bak binding.gyp || mv binding.gyp.bak binding.gyp