commit
3d101c7cd3
|
@ -0,0 +1,73 @@
|
||||||
|
name: Cross Compile
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-ckzg:
|
||||||
|
runs-on: ${{ matrix.target.host }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
target:
|
||||||
|
- clang: x86_64-linux
|
||||||
|
native: linux-x64
|
||||||
|
host: ubuntu-latest
|
||||||
|
#- clang: arm64-linux
|
||||||
|
# native: linux-arm64
|
||||||
|
# host: ubuntu-latest
|
||||||
|
#- clang: arm64-darwin
|
||||||
|
# native: osx-arm64
|
||||||
|
# host: macos-latest
|
||||||
|
- clang: x86_64-darwin
|
||||||
|
native: osx-x64
|
||||||
|
host: macos-latest
|
||||||
|
- clang: x86_64-win
|
||||||
|
native: win-x64
|
||||||
|
host: windows-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
- name: Build native library for ${{ matrix.target.native }}
|
||||||
|
run: cd bindings/csharp && make -B ckzg CSHARP_PLATFORM=${{ matrix.target.native }} CLANG_PLATFORM=${{ matrix.target.clang }}
|
||||||
|
- name: Upload artifacts
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: ckzg-library-${{ matrix.target.native }}
|
||||||
|
path: bindings/csharp/Ckzg/runtimes/${{ matrix.target.native }}/native
|
||||||
|
|
||||||
|
build-ckzg-dotnet:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build-ckzg
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: ckzg-library-linux-x64
|
||||||
|
path: bindings/csharp/Ckzg/runtimes/linux-x64/native
|
||||||
|
- uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: ckzg-library-osx-x64
|
||||||
|
path: bindings/csharp/Ckzg/runtimes/osx-x64/native
|
||||||
|
- uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: ckzg-library-win-x64
|
||||||
|
path: bindings/csharp/Ckzg/runtimes/win-x64/native
|
||||||
|
|
||||||
|
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
|
||||||
|
uses: actions/setup-dotnet@v3
|
||||||
|
with:
|
||||||
|
dotnet-version: ${{ matrix.dotnet-version }}
|
||||||
|
- name: Install dependencies
|
||||||
|
run: cd bindings/csharp && dotnet restore
|
||||||
|
- name: Build
|
||||||
|
run: cd bindings/csharp && dotnet build --configuration Release --no-restore -o build
|
||||||
|
- name: Upload package
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: Ckzg.nuget
|
||||||
|
path: bindings/csharp/build/Ckzg.1.0.0.nupkg
|
|
@ -1,3 +1,11 @@
|
||||||
bin/
|
**/bin
|
||||||
obj/
|
**/obj
|
||||||
.vs/
|
|
||||||
|
.vs
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
Ckzg/runtimes/*/native/*
|
||||||
|
!**/.gitkeep
|
||||||
|
test_ckzg*
|
||||||
|
*.so
|
||||||
|
*.dll
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Launch",
|
||||||
|
"preLaunchTask": "build",
|
||||||
|
"program": "${fileDirname}/tests.exe",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"stdbool.h": "c",
|
||||||
|
"c_kzg_4844.h": "c",
|
||||||
|
"stdint.h": "c",
|
||||||
|
"string.h": "c",
|
||||||
|
"inttypes.h": "c",
|
||||||
|
"stdlib.h": "c",
|
||||||
|
"sha256.h": "c"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"type": "cppbuild",
|
||||||
|
"label": "build",
|
||||||
|
"command": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\Llvm\\x64\\bin\\clang.exe",
|
||||||
|
"args": [
|
||||||
|
"-fcolor-diagnostics",
|
||||||
|
"-fansi-escape-codes",
|
||||||
|
"-g",
|
||||||
|
"${file}",
|
||||||
|
"-w",
|
||||||
|
"-o",
|
||||||
|
"${fileDirname}\\${fileBasenameNoExtension}.exe",
|
||||||
|
"-I../../src",
|
||||||
|
"-I../../blst/bindings",
|
||||||
|
"-I../../blst/src",
|
||||||
|
"../../blst/blst.lib",
|
||||||
|
"../../src/c_kzg_4844.c",
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${fileDirname}"
|
||||||
|
},
|
||||||
|
"problemMatcher": [
|
||||||
|
"$gcc"
|
||||||
|
],
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
},
|
||||||
|
"detail": "Task generated by Debugger."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": "2.0.0"
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
|
||||||
|
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Ckzg\Ckzg.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="ckzg.dll">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="devnetv2-geth.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="devnetv2.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1 @@
|
||||||
|
global using Xunit;
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,51 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.0.31903.59
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ckzg.Tests", "Ckzg.Tests\Ckzg.Tests.csproj", "{BE6A0DC4-3B28-4957-AE17-F57A26C3B674}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ckzg", "Ckzg\Ckzg.csproj", "{4BE5C759-C998-47AB-A7F3-FA5E115A06DD}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{BE6A0DC4-3B28-4957-AE17-F57A26C3B674}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{BE6A0DC4-3B28-4957-AE17-F57A26C3B674}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{BE6A0DC4-3B28-4957-AE17-F57A26C3B674}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{BE6A0DC4-3B28-4957-AE17-F57A26C3B674}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{BE6A0DC4-3B28-4957-AE17-F57A26C3B674}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{BE6A0DC4-3B28-4957-AE17-F57A26C3B674}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{BE6A0DC4-3B28-4957-AE17-F57A26C3B674}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{BE6A0DC4-3B28-4957-AE17-F57A26C3B674}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{BE6A0DC4-3B28-4957-AE17-F57A26C3B674}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{BE6A0DC4-3B28-4957-AE17-F57A26C3B674}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{BE6A0DC4-3B28-4957-AE17-F57A26C3B674}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{BE6A0DC4-3B28-4957-AE17-F57A26C3B674}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{4BE5C759-C998-47AB-A7F3-FA5E115A06DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4BE5C759-C998-47AB-A7F3-FA5E115A06DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4BE5C759-C998-47AB-A7F3-FA5E115A06DD}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{4BE5C759-C998-47AB-A7F3-FA5E115A06DD}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{4BE5C759-C998-47AB-A7F3-FA5E115A06DD}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{4BE5C759-C998-47AB-A7F3-FA5E115A06DD}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{4BE5C759-C998-47AB-A7F3-FA5E115A06DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4BE5C759-C998-47AB-A7F3-FA5E115A06DD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{4BE5C759-C998-47AB-A7F3-FA5E115A06DD}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{4BE5C759-C998-47AB-A7F3-FA5E115A06DD}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{4BE5C759-C998-47AB-A7F3-FA5E115A06DD}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{4BE5C759-C998-47AB-A7F3-FA5E115A06DD}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {F45DF31F-80A9-46CD-9941-FEE2FD0FF651}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
|
@ -0,0 +1,41 @@
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Runtime.Loader;
|
||||||
|
|
||||||
|
namespace Ckzg;
|
||||||
|
|
||||||
|
public class Ckzg
|
||||||
|
{
|
||||||
|
static Ckzg()
|
||||||
|
{
|
||||||
|
AssemblyLoadContext.Default.ResolvingUnmanagedDll += (assembly, path) => NativeLibrary.Load($"runtimes/{(
|
||||||
|
RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "linux" :
|
||||||
|
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "osx" :
|
||||||
|
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win" : "")}-{RuntimeInformation.ProcessArchitecture switch
|
||||||
|
{
|
||||||
|
Architecture.X86 => "x86",
|
||||||
|
Architecture.Arm => "arm",
|
||||||
|
Architecture.X64 => "x64",
|
||||||
|
Architecture.Arm64 => "arm64",
|
||||||
|
_ => ""
|
||||||
|
}}/native/{path}.{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "dll" : "so")}");
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("ckzg", EntryPoint = "blob_to_kzg_commitment_wrap", CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static unsafe extern void blob_to_kzg_commitment(byte[] retval, byte[] blob, IntPtr ts);
|
||||||
|
|
||||||
|
[DllImport("ckzg", EntryPoint = "compute_aggregate_kzg_proof_wrap", CallingConvention = CallingConvention.Cdecl)] // returns 0 on success
|
||||||
|
public static unsafe extern int compute_aggregate_kzg_proof(byte[] retval, byte[] blobs, int n, IntPtr ts);
|
||||||
|
|
||||||
|
[DllImport("ckzg", EntryPoint = "verify_aggregate_kzg_proof_wrap", CallingConvention = CallingConvention.Cdecl)] // returns 0 on success
|
||||||
|
public static unsafe extern int verify_aggregate_kzg_proof(byte[] blobs, byte[] commitments, int blobCount, byte[] proof, IntPtr ts);
|
||||||
|
|
||||||
|
[DllImport("ckzg", EntryPoint = "verify_kzg_proof_wrap", CallingConvention = CallingConvention.Cdecl)] // returns 0 on success
|
||||||
|
public static extern int verify_kzg_proof(byte[/*48*/] commitment, byte[/*32*/] x, byte[/*32*/] y, byte[/*48*/] proof, IntPtr ts);
|
||||||
|
|
||||||
|
[DllImport("ckzg", EntryPoint = "load_trusted_setup_wrap", CallingConvention = CallingConvention.Cdecl)] // free result with free_trusted_setup()
|
||||||
|
public static extern IntPtr load_trusted_setup(string filename);
|
||||||
|
|
||||||
|
[DllImport("ckzg", EntryPoint = "free_trusted_setup_wrap", CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern void free_trusted_setup(IntPtr ts);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<RootNamespace>Ckzg</RootNamespace>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<LangVersion>10</LangVersion>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<LangVersion>preview</LangVersion>
|
||||||
|
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||||
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
|
<Title>Ckzg</Title>
|
||||||
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\..\..\LICENSE">
|
||||||
|
<Pack>True</Pack>
|
||||||
|
<PackagePath>\</PackagePath>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="runtimes\*\native\*.dll">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
<Pack>true</Pack>
|
||||||
|
<PackagePath>lib\$(TargetFramework)\runtimes</PackagePath>
|
||||||
|
</Content>
|
||||||
|
<Content Include="runtimes\*\native\*.so">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
<Pack>true</Pack>
|
||||||
|
<PackagePath>lib\$(TargetFramework)\runtimes</PackagePath>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -1,8 +1,53 @@
|
||||||
INCLUDE_DIRS = .. ../../src ../../inc
|
INCLUDE_DIRS = ../../src ../../blst/bindings
|
||||||
|
|
||||||
test: tests.cs ckzg.dll
|
ifeq ($(OS),Windows_NT)
|
||||||
mcs tests.cs -r:System.Numerics
|
BLST_BUILDSCRIPT=./build.sh
|
||||||
./tests.exe
|
BLST_OBJ=libblst.a
|
||||||
|
TESTS_EXECUTABLE=test_ckzg.exe
|
||||||
|
CSHARP_PLATFORM?=win-x64
|
||||||
|
CLANG_PLATFROM?=x86_64-win
|
||||||
|
CLANG_FLAGS=
|
||||||
|
CLANG_EXECUTABLE=gcc
|
||||||
|
CKZG_LIBRARY_PATH=Ckzg\runtimes\$(CSHARP_PLATFORM)\native\ckzg.dll
|
||||||
|
else
|
||||||
|
BLST_BUILDSCRIPT=./build.sh
|
||||||
|
BLST_OBJ=libblst.a
|
||||||
|
TESTS_EXECUTABLE=./test_ckzg
|
||||||
|
CSHARP_PLATFORM?=linux-x64
|
||||||
|
CLANG_PLATFORM?=x86_64-linux
|
||||||
|
CLANG_FLAGS=-fPIC
|
||||||
|
CLANG_EXECUTABLE=cc
|
||||||
|
CKZG_LIBRARY_PATH=Ckzg/runtimes/$(CSHARP_PLATFORM)/native/ckzg.so
|
||||||
|
endif
|
||||||
|
|
||||||
ckzg.dll: ckzg.c ../../src/c_kzg_4844.o ../../lib/libblst.a
|
.blst:
|
||||||
clang -O -Wall -shared ${addprefix -I,${INCLUDE_DIRS}} -o $@ $^
|
cd ../../blst &&\
|
||||||
|
git apply ../blst_sha.patch &&\
|
||||||
|
$(BLST_BUILDSCRIPT) &&\
|
||||||
|
uname -a && ls -a &&\
|
||||||
|
git apply -R ../blst_sha.patch &&\
|
||||||
|
cd ../bindings/csharp
|
||||||
|
|
||||||
|
.ckzg: ckzg.c ../../src/c_kzg_4844.c ../../blst/$(BLST_OBJ)
|
||||||
|
$(CLANG_EXECUTABLE) -O -Wall -shared $(CLANG_FLAGS) ${addprefix -I,${INCLUDE_DIRS}} -o $(CKZG_LIBRARY_PATH) $^
|
||||||
|
|
||||||
|
# Ckzg library
|
||||||
|
ckzg:
|
||||||
|
@make .blst
|
||||||
|
@make .ckzg
|
||||||
|
|
||||||
|
# E2e tests as an executable
|
||||||
|
test: tests.c ckzg.c ../../src/c_kzg_4844.c ../../blst/$(BLST_OBJ)
|
||||||
|
@make .blst
|
||||||
|
clang -O -w -Wall $(CLANG_FLAGS) ${addprefix -I,${INCLUDE_DIRS}} -o $(TESTS_EXECUTABLE) $^
|
||||||
|
|
||||||
|
# E2e tests are built and run
|
||||||
|
run-test:
|
||||||
|
@make test
|
||||||
|
$(TESTS_EXECUTABLE)
|
||||||
|
|
||||||
|
# Makes a build and a nuget package just for windows or linux
|
||||||
|
# To build full package - use ckzg command on every plaform and dotnet build
|
||||||
|
ckzg-dotnet:
|
||||||
|
@make ckzg
|
||||||
|
dotnet build
|
|
@ -0,0 +1,22 @@
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "c_kzg_4844.h"
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define DLLEXPORT __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define DLLEXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
DLLEXPORT KZGSettings* load_trusted_setup_wrap(const char* file);
|
||||||
|
|
||||||
|
DLLEXPORT void free_trusted_setup_wrap(KZGSettings *s);
|
||||||
|
|
||||||
|
DLLEXPORT void blob_to_kzg_commitment_wrap(uint8_t out[48], const Blob blob, const KZGSettings *s);
|
||||||
|
|
||||||
|
DLLEXPORT int verify_aggregate_kzg_proof_wrap(const Blob blobs[], const uint8_t commitments[], size_t n, const uint8_t proof[48], const KZGSettings *s);
|
||||||
|
|
||||||
|
DLLEXPORT C_KZG_RET compute_aggregate_kzg_proof_wrap(uint8_t out[48], const Blob blobs[], size_t n, const KZGSettings *s);
|
||||||
|
|
||||||
|
DLLEXPORT int verify_kzg_proof_wrap(const uint8_t c[48], const uint8_t x[32], const uint8_t y[32], const uint8_t p[48], KZGSettings *s);
|
|
@ -1,11 +0,0 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<RootNamespace>csharp</RootNamespace>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
|
@ -1,25 +0,0 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio Version 17
|
|
||||||
VisualStudioVersion = 17.3.32922.545
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "csharp", "csharp.csproj", "{108ACE4B-334D-4D63-9897-9895DFF35FEE}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{108ACE4B-334D-4D63-9897-9895DFF35FEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{108ACE4B-334D-4D63-9897-9895DFF35FEE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{108ACE4B-334D-4D63-9897-9895DFF35FEE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{108ACE4B-334D-4D63-9897-9895DFF35FEE}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
||||||
SolutionGuid = {1FCEC58A-285C-4F22-8B55-68B1A312EE7E}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -1,214 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Numerics;
|
|
||||||
using System.Text;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
class ckzg
|
|
||||||
{
|
|
||||||
[DllImport("ckzg.dll", EntryPoint = "blob_to_kzg_commitment_wrap")]
|
|
||||||
public static extern void blob_to_kzg_commitment(byte[/*48*/] retval, byte[/*4096 * 32*/] blob, IntPtr ts);
|
|
||||||
|
|
||||||
[DllImport("ckzg.dll", EntryPoint = "compute_aggregate_kzg_proof_wrap")] // returns 0 on success
|
|
||||||
public static extern int compute_aggregate_kzg_proof(byte[/*48*/] retval, byte[] blobs, int n, IntPtr ts);
|
|
||||||
|
|
||||||
[DllImport("ckzg.dll", EntryPoint = "verify_aggregate_kzg_proof_wrap")] // returns 0 on success
|
|
||||||
public static extern int verify_aggregate_kzg_proof(byte[] blobs, byte[] commitments, int n, byte[/*48*/] proof, IntPtr ts);
|
|
||||||
|
|
||||||
[DllImport("ckzg.dll", EntryPoint = "verify_kzg_proof_wrap")] // returns 0 on success
|
|
||||||
public static extern int verify_kzg_proof(byte[/*48*/] c, byte[/*32*/] x, byte[/*32*/] y, byte[/*48*/] p, IntPtr ts);
|
|
||||||
|
|
||||||
[DllImport("ckzg.dll", EntryPoint = "load_trusted_setup_wrap")] // free result with free_trusted_setup()
|
|
||||||
public static extern IntPtr load_trusted_setup(string filename);
|
|
||||||
|
|
||||||
[DllImport("ckzg.dll", EntryPoint = "free_trusted_setup_wrap")]
|
|
||||||
public static extern void free_trusted_setup(IntPtr ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
class tests
|
|
||||||
{
|
|
||||||
IntPtr ts = ckzg.load_trusted_setup("../../src/trusted_setup.txt");
|
|
||||||
|
|
||||||
byte[] ssz_of(params object[] anything)
|
|
||||||
{
|
|
||||||
return new byte[1]; //mock
|
|
||||||
}
|
|
||||||
byte[] hash(byte[] data)
|
|
||||||
{
|
|
||||||
return data; //mock
|
|
||||||
}
|
|
||||||
byte[] flatten(byte[][] data)
|
|
||||||
{
|
|
||||||
return data[0]; //mock
|
|
||||||
}
|
|
||||||
|
|
||||||
(byte[], byte[]) compute_aggregated_poly_and_commitment(byte[][] blobs, byte[][] kzg_commitments)
|
|
||||||
{
|
|
||||||
// Generate random linear combination challenges
|
|
||||||
var r = hash_to_bls_field(ssz_of("BlobsAndCommitments", blobs, kzg_commitments));
|
|
||||||
var r_powers = ckzg.compute_powers(r, (ulong)kzg_commitments.Length);
|
|
||||||
|
|
||||||
// Create aggregated polynomial in evaluation form
|
|
||||||
byte[] aggregated_poly = ckzg.vector_lincomb(flatten(blobs), r_powers, (ulong)blobs.Length, (ulong)4096);
|
|
||||||
|
|
||||||
// Compute commitment to aggregated polynomial
|
|
||||||
byte[] aggregated_poly_commitment = ckzg.g1_lincomb(flatten(kzg_commitments), r_powers, (ulong)kzg_commitments.Length);
|
|
||||||
|
|
||||||
return (aggregated_poly, aggregated_poly_commitment);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] hash_to_bls_field(byte[] data)
|
|
||||||
{
|
|
||||||
return ckzg.bytes_to_bls_field(hash(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
const byte BLOB_COMMITMENT_VERSION_KZG = 1;
|
|
||||||
|
|
||||||
byte[] kzg_to_versioned_hash(byte[] data_kzg)
|
|
||||||
{
|
|
||||||
var res = hash(data_kzg);
|
|
||||||
res[0] = BLOB_COMMITMENT_VERSION_KZG;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool validate_blob_transaction_wrapper(
|
|
||||||
byte[][] versioned_hashes,
|
|
||||||
byte[][] commitments,
|
|
||||||
byte[][] blobs
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (versioned_hashes.Length != commitments.Length || commitments.Length != blobs.Length)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("args");
|
|
||||||
}
|
|
||||||
var (aggregated_poly, aggregated_poly_commitment) = compute_aggregated_poly_and_commitment(
|
|
||||||
blobs,
|
|
||||||
commitments
|
|
||||||
);
|
|
||||||
|
|
||||||
// Generate challenge `x` and evaluate the aggregated polynomial at `x`
|
|
||||||
var x = hash_to_bls_field(
|
|
||||||
ssz_of("PolynomialAndCommitment", aggregated_poly, aggregated_poly_commitment)
|
|
||||||
);
|
|
||||||
// Evaluate aggregated polynomial at `x` (evaluation function checks for div-by-zero)
|
|
||||||
var y = ckzg.evaluate_polynomial_in_evaluation_form(aggregated_poly, x, ts);
|
|
||||||
|
|
||||||
// Verify aggregated proof
|
|
||||||
if (!ckzg.verify_kzg_proof(aggregated_poly_commitment, x, y, "need to clarify", ts))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now that all commitments have been verified, check that versioned_hashes matches the commitments
|
|
||||||
return versioned_hashes.Zip(commitments).All(x => Enumerable.SequenceEqual(x.First, kzg_to_versioned_hash(x.Second)));
|
|
||||||
}
|
|
||||||
readonly UInt256 BLS_MODULUS = UInt256.Parse("52435875175126190479447740508185965837690552500527637822603658699938581184513");
|
|
||||||
|
|
||||||
struct UInt256
|
|
||||||
{
|
|
||||||
public UInt256(params byte[] data)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool operator >=(in UInt256 a, in UInt256 b) => true;
|
|
||||||
public static bool operator <=(in UInt256 a, in UInt256 b) => false;
|
|
||||||
|
|
||||||
internal static UInt256 Parse(string v)
|
|
||||||
{
|
|
||||||
return new UInt256();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool point_evaluation_precompile(byte[] input)
|
|
||||||
{
|
|
||||||
var versioned_hash = input[..32];
|
|
||||||
// Evaluation point: next 32 bytes
|
|
||||||
var x = input[32..64];
|
|
||||||
if (new UInt256(x) >= BLS_MODULUS)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Expected output: next 32 bytes
|
|
||||||
var y = input[64..96];
|
|
||||||
if (new UInt256(y) >= BLS_MODULUS)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// The remaining data will always be the proof, including in future versions
|
|
||||||
// input kzg point: next 48 bytes
|
|
||||||
var data_kzg = input[96..144];
|
|
||||||
if (!kzg_to_versioned_hash(data_kzg).SequenceEqual(versioned_hash))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Quotient kzg: next 48 bytes
|
|
||||||
var quotient_kzg = input[144..192];
|
|
||||||
if (!ckzg.verify_kzg_proof(data_kzg, x, y, quotient_kzg, ts))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Convert.FromHexString replacement (since mono does not seem to have new enough C# libs)
|
|
||||||
public static byte[] HexadecimalStringToByteArray(String hexadecimalString)
|
|
||||||
{
|
|
||||||
int length = hexadecimalString.Length;
|
|
||||||
byte[] byteArray = new byte[length / 2];
|
|
||||||
for (int i = 0; i < length; i += 2)
|
|
||||||
{
|
|
||||||
byteArray[i / 2] = Convert.ToByte(hexadecimalString.Substring(i, 2), 16);
|
|
||||||
}
|
|
||||||
return byteArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void Main(string[] args)
|
|
||||||
{
|
|
||||||
/* TODO: update for new interface
|
|
||||||
Console.WriteLine("Test 1: verify_kzg_proof");
|
|
||||||
|
|
||||||
IntPtr ts = ckzg.load_trusted_setup("../../src/trusted_setup.txt");
|
|
||||||
System.Diagnostics.Trace.Assert(ts != IntPtr.Zero, "Failed to load trusted setup.");
|
|
||||||
|
|
||||||
byte[] c = HexadecimalStringToByteArray("b91c022acf7bd3b63be69a4c19b781ea7a3d5df1cd66ceb7dd0f399610f0ee04695dace82e04bfb83af2b17d7319f87f");
|
|
||||||
byte[] x = HexadecimalStringToByteArray("0345f802a75a6c0d9cc5b8a1e71642b8fa80b0a78938edc6da1e591149578d1a");
|
|
||||||
byte[] y = HexadecimalStringToByteArray("3b17cab634c3795d311380f3bc93ce8e768efc0e2b9e79496cfc8f351594b472");
|
|
||||||
byte[] p = HexadecimalStringToByteArray("a5ddd6da04c47a9cd4628beb8d55ebd2e930a64dfa29f876ebf393cfd6574d48a3ce96ac5a2af4a4f9ec9caa47d304d3");
|
|
||||||
int result = ckzg.verify_kzg_proof(c, x, y, p, ts);
|
|
||||||
System.Diagnostics.Trace.Assert(result == 1, "Verification failed");
|
|
||||||
|
|
||||||
x[0] = 0x42;
|
|
||||||
result = ckzg.verify_kzg_proof(c, x, y, p, ts);
|
|
||||||
System.Diagnostics.Trace.Assert(result == 0, "Verification succeeded incorrectly");
|
|
||||||
|
|
||||||
ckzg.free_trusted_setup(ts);
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* TODO: update for new interface
|
|
||||||
Console.WriteLine("Test 2: evaluate_polynomial_in_evaluation_form");
|
|
||||||
|
|
||||||
ts = ckzg.load_trusted_setup("../python/tiny_trusted_setup.txt");
|
|
||||||
System.Diagnostics.Trace.Assert(ts != IntPtr.Zero, "Failed to load trusted setup.");
|
|
||||||
|
|
||||||
p = HexadecimalStringToByteArray("10000000000000000d00000000000000000000000000000000000000000000000a000000000000000d00000000000000000000000000000000000000000000000b000000000001000d000376020003ecd0040376cecc518d00000000000000000c000000fffffeff0b5cfb8900a4ba6734d39e93390be8a5477d9d2953a7ed73");
|
|
||||||
x = HexadecimalStringToByteArray("0200000000000000000000000000000000000000000000000000000000000000");
|
|
||||||
UInt64 n = Convert.ToUInt64(p.Length) / 32;
|
|
||||||
result = ckzg.evaluate_polynomial_in_evaluation_form(y, p, n, x, ts);
|
|
||||||
System.Diagnostics.Trace.Assert(result == 0, "Evaluation failed");
|
|
||||||
System.Diagnostics.Trace.Assert(y == HexadecimalStringToByteArray("1c000000000000000d0000000000000000000000000000000000000000000000"),
|
|
||||||
"Evaluation produced incorrect value");
|
|
||||||
|
|
||||||
x[11] = 0x11;
|
|
||||||
result = ckzg.evaluate_polynomial_in_evaluation_form(y, p, n, x, ts);
|
|
||||||
System.Diagnostics.Trace.Assert(result == 0, "Second evaluation failed");
|
|
||||||
System.Diagnostics.Trace.Assert(y != HexadecimalStringToByteArray("1c000000000000000d0000000000000000000000000000000000000000000000"),
|
|
||||||
"Second evaluation produced incorrect value");
|
|
||||||
|
|
||||||
ckzg.free_trusted_setup(ts);
|
|
||||||
*/
|
|
||||||
|
|
||||||
Console.WriteLine("Tests passed");
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue