Package org.logolith.kzgo
Class KZG
java.lang.Object
org.logolith.kzgo.KZG
Public Java wrapper for the KZG Bridge native library.
Provides static methods for interacting with the KZG functions.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCustom exception class for KZG errors.static classSimple data class to hold the results from the open function. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]commit(byte[] polyCoeffsBytes) Computes the KZG commitment for a polynomial defined by its coefficients.static byte[]commitFromEvaluations(byte[] evaluationsBytes) Computes the KZG commitment by performing interpolation on evaluations within the bridge.static byte[]commitNode(byte[] nodeDataBytes) Computes the KZG commitment directly from serialized raw node data.static byte[]hashToFr(byte[] msgBytes, byte[] domainBytes) Hashes arbitrary message bytes to a single Fr field element using a domain separation tag.static byte[]interpolate(byte[] valuesBytes) Performs polynomial interpolation given values (y-coordinates) corresponding to domain 0, 1, 2, ...static byte[]interpolateNode(byte[] nodeDataBytes) Parses node data, computes polynomial evaluations, interpolates, pads to SRS size, and returns the serialized padded polynomial coefficients.static KZG.OpenResultDataopen(byte[] polyCoeffsBytes, byte[] pointZBytes) Computes the KZG opening proof for a polynomial at a given point.static booleanverify(byte[] commitmentBytes, byte[] proofHBytes, byte[] pointZBytes, byte[] claimedValueBytes) Verifies a KZG opening proof using the globally loaded VK (Server-side).static booleanverifyWithVk(byte[] commitmentBytes, byte[] proofHBytes, byte[] pointZBytes, byte[] claimedValueBytes, byte[] vkBytes) Verifies a KZG opening proof using a provided Verifying Key (Client-side).
-
Constructor Details
-
KZG
public KZG()
-
-
Method Details
-
commit
Computes the KZG commitment for a polynomial defined by its coefficients.- Parameters:
polyCoeffsBytes- A single byte array containing the concatenated 32-byte Fr elements (coefficients), MUST match the size defined by the loaded SRS.- Returns:
- The KZG commitment as a byte array.
- Throws:
KZG.KZGException- If the native call fails or if the number of coefficients doesn't match the SRS size.
-
commitFromEvaluations
Computes the KZG commitment by performing interpolation on evaluations within the bridge.- Parameters:
evaluationsBytes- A single byte array containing the concatenated 32-byte Fr elements (evaluations/y-coordinates). The number of evaluations determines the polynomial degree, which must be less than the SRS size.- Returns:
- The KZG commitment as a byte array.
- Throws:
KZG.KZGException- If the native call fails, input is invalid, or the interpolated polynomial degree exceeds the SRS size.
-
open
public static KZG.OpenResultData open(byte[] polyCoeffsBytes, byte[] pointZBytes) throws KZG.KZGException Computes the KZG opening proof for a polynomial at a given point.- Parameters:
polyCoeffsBytes- A single byte array containing the concatenated 32-byte Fr elements (coefficients). The number of coefficients MUST match the SRS size.pointZBytes- The 32-byte representation of the evaluation point Fr element.- Returns:
- An OpenResultData object containing the proof (H point) and claimed value bytes.
- Throws:
KZG.KZGException- If the native call fails.
-
verify
public static boolean verify(byte[] commitmentBytes, byte[] proofHBytes, byte[] pointZBytes, byte[] claimedValueBytes) throws KZG.KZGException Verifies a KZG opening proof using the globally loaded VK (Server-side).- Parameters:
commitmentBytes- The commitment bytes.proofHBytes- The proof bytes (H point).pointZBytes- The evaluation point bytes.claimedValueBytes- The claimed value bytes.- Returns:
- true if the proof is valid, false otherwise.
- Throws:
KZG.KZGException- If the native call encounters an error other than verification failure.
-
verifyWithVk
public static boolean verifyWithVk(byte[] commitmentBytes, byte[] proofHBytes, byte[] pointZBytes, byte[] claimedValueBytes, byte[] vkBytes) throws KZG.KZGException Verifies a KZG opening proof using a provided Verifying Key (Client-side).- Parameters:
commitmentBytes- The commitment bytes.proofHBytes- The proof bytes (H point).pointZBytes- The evaluation point bytes.claimedValueBytes- The claimed value bytes.vkBytes- The serialized Verifying Key bytes.- Returns:
- true if the proof is valid, false otherwise.
- Throws:
KZG.KZGException- If the native call encounters an error other than verification failure.
-
interpolate
Performs polynomial interpolation given values (y-coordinates) corresponding to domain 0, 1, 2, ...- Parameters:
valuesBytes- A single byte array containing the concatenated 32-byte Fr elements (y-coordinates).- Returns:
- The coefficients of the interpolated polynomial as a byte array.
- Throws:
KZG.KZGException- If the native call fails or if input is invalid.
-
hashToFr
Hashes arbitrary message bytes to a single Fr field element using a domain separation tag.- Parameters:
msgBytes- The message bytes to hash.domainBytes- The domain separation tag bytes.- Returns:
- The resulting Fr element as a 32-byte array.
- Throws:
KZG.KZGException- If the native hash-to-field call fails.
-
commitNode
Computes the KZG commitment directly from serialized raw node data. This performs hashing, evaluation generation, interpolation, padding, and commitment within Go.- Parameters:
nodeDataBytes- Serialized node data (type, count, keys, values/commits) according to the agreed format.- Returns:
- The KZG commitment as a byte array.
- Throws:
KZG.KZGException- If the native call fails.
-
interpolateNode
Parses node data, computes polynomial evaluations, interpolates, pads to SRS size, and returns the serialized padded polynomial coefficients.- Parameters:
nodeDataBytes- The serialized node data (following the expected format).- Returns:
- The byte array of the serialized padded polynomial coefficients.
- Throws:
KZG.KZGException- if the underlying Go call fails.
-