Class KZG

java.lang.Object
org.logolith.kzgo.KZG

public class KZG extends Object
Public Java wrapper for the KZG Bridge native library. Provides static methods for interacting with the KZG functions.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Custom exception class for KZG errors.
    static class 
    Simple data class to hold the results from the open function.
  • Constructor Summary

    Constructors
    Constructor
    Description
    KZG()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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.
    open(byte[] polyCoeffsBytes, byte[] pointZBytes)
    Computes the KZG opening proof for a polynomial at a given point.
    static boolean
    verify(byte[] commitmentBytes, byte[] proofHBytes, byte[] pointZBytes, byte[] claimedValueBytes)
    Verifies a KZG opening proof using the globally loaded VK (Server-side).
    static boolean
    verifyWithVk(byte[] commitmentBytes, byte[] proofHBytes, byte[] pointZBytes, byte[] claimedValueBytes, byte[] vkBytes)
    Verifies a KZG opening proof using a provided Verifying Key (Client-side).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • KZG

      public KZG()
  • Method Details

    • commit

      public static byte[] commit(byte[] polyCoeffsBytes) throws KZG.KZGException
      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

      public static byte[] commitFromEvaluations(byte[] evaluationsBytes) throws KZG.KZGException
      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

      public static byte[] interpolate(byte[] valuesBytes) throws KZG.KZGException
      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

      public static byte[] hashToFr(byte[] msgBytes, byte[] domainBytes) throws KZG.KZGException
      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

      public static byte[] commitNode(byte[] nodeDataBytes) throws KZG.KZGException
      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

      public static byte[] interpolateNode(byte[] nodeDataBytes) throws KZG.KZGException
      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.