Code Monkey home page Code Monkey logo

jc-kzg-4844's Introduction

jc-kzg-4844

Build Status GitHub license Version of 'c-kzg-4844' Latest version of 'jc-kzg-4844' @ Cloudsmith

Provides building and packaging of the Java bindings in C-KZG-4844.

Dependency

repositories {
    maven { url "https://artifacts.consensys.net/public/maven/maven/" }
}

dependencies {
    implementation("tech.pegasys:jc-kzg-4844:<version>")
}

The library is also available on Maven Central

Maven Central

Minimal sample

// load the library once at startup
CKZG4844JNI.loadNativeLibrary();

// once a trusted setup is loaded, all methods will use it
CKZG4844JNI.loadTrustedSetup("trusted-setup.txt");

byte[] blob = ...;
byte[] commitment = CKZG4844JNI.blobToKzgCommitment(blob);
byte[] proof = CKZG4844JNI.computeBlobKzgProof(blob, commitment);

boolean isValidProof = CKZG4844JNI.verifyBlobKzgProof(blob, commitment, proof);

// the current trusted setup should be freed before a new one is loaded
CKZG4844JNI.freeTrustedSetup();

Loading trusted setup

There are two ways to load the trusted setup.

File

The file needs to be of the following format: trusted_setup.txt

Method parameters

Look at the loadTrustedSetup(byte[], long, byte[], long) method.

Supported platforms

  • x86-64
    • Windows
    • Linux
    • MacOS
  • aarch64
    • Linux
    • MacOS

jc-kzg-4844's People

Contributors

fab-10 avatar jtraglia avatar mehdi-aouadi avatar stefanbratanov avatar tbenr avatar zilm13 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jc-kzg-4844's Issues

Publish Library to maven central

Web3j has included this Library for adding EIP4844 support. But this has resulted for our users to add this as an explicit repo dependency in their projects in order to use it. There is high demand from the Web3J users if we can publish it to maven central and will really appreciate any help in this direction.

Attaching issues from web3j related to this -

hyperledger/web3j-gradle-plugin#81
hyperledger/web3j#2013

Opening this issue to track the progress and for users to refer this.

Thank you

Figure out segmentation fault errors when passing 0 element blobs

As a workaround for #5, there was a change to throw an exception in the JNI binding rather than a segmentation fault error.

In blobToKzgCommitment, computeAggregateKzgProof and verifyAggregateKzgProof currently there are if checks to check the size of the jbyteArray and throw if it is 0.

This prevents the segmentation fault errors when calling the C library. Apparently the C library support passing empty blobs, so there could be something happening when converting the jbyteArray to uint8_t *

You can use the following test in the bindings repo to test a potential fix:

passingZeroElementArraysForBlobsDoesNotCauseSegmentationFaultErrors()

Note
computeAggregateKzgProof and verifyAggregateKzgProof works when using a count of 0.

Make library methods not static

Currently, there is a limitation to the library that all methods are static in the library. This means that if the class is used concurrently with two different trusted setups it won't work.

The JNI binding could be changed to store a trusted setup per jobject. C doesn't have a map data structure, so some sort of custom map could be created (binary tree could be a solution)

Facing App Crash

Hey,
I have included this library in web3j - hyperledger/web3j#2000 for sending Blob Txs
But I am facing app crash and errors when running any function that includes functions from this library.

Errors -

JVMDUMP039I Processing dump event "abort", detail "" at 2024/02/06 16:20:07 - please wait.
JVMDUMP032I JVM requested System dump using '/Users/nicks/Desktop/coding/projects/Web3App/core.20240206.162007.59144.0001.dmp' in response to an event
JVMDUMP010I System dump written to /Users/nicks/Desktop/coding/projects/Web3App/core.20240206.162007.59144.0001.dmp
JVMDUMP032I JVM requested Java dump using '/Users/nicks/Desktop/coding/projects/Web3App/javacore.20240206.162007.59144.0002.txt' in response to an event

Let me know if I should share other details or I am missing something

Segmentation fault with blobToKzgCommitment

Getting segmentation fault when doing this. Not a correct call, anyway, segmentation fault is very dangerous for the whole application, we need and exception here instead

CKzg4844JNI.loadTrustedSetup("trusted_setup.txt");
CKzg4844JNI.blobToKzgCommitment(new byte[0]));

Reload native library with different preset at runtime

Currently there is a limitation that once the class is loaded and library is loaded with a specific Preset, there is no way to change the Preset. This is fine for running Teku or Besu for example since the library is loaded on startup, but for tests It would be good to have more flexibility.

One possible solution is to have a different c_kzg_4844_jni.c for minimal and mainnet and two different classes with the same native methods and then have a wrapper on top where you can change between the two. Another possible solution is to unload the native library dynamically, but this should be further researched if it is viable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.