Class CKZG4844JNI

java.lang.Object
ethereum.ckzg4844.CKZG4844JNI

public class CKZG4844JNI extends Object
  • Field Details

    • BLS_MODULUS

      public static final BigInteger BLS_MODULUS
      Scalar field modulus of BLS12-381.
    • BYTES_PER_G1

      protected static final int BYTES_PER_G1
      The number of bytes in a g1 point.
      See Also:
    • BYTES_PER_G2

      protected static final int BYTES_PER_G2
      The number of bytes in a g2 point.
      See Also:
    • BYTES_PER_FIELD_ELEMENT

      public static final int BYTES_PER_FIELD_ELEMENT
      The number of bytes in a BLS scalar field element.
      See Also:
    • BITS_PER_FIELD_ELEMENT

      protected static final int BITS_PER_FIELD_ELEMENT
      The number of bits in a BLS scalar field element.
      See Also:
    • FIELD_ELEMENTS_PER_BLOB

      public static final int FIELD_ELEMENTS_PER_BLOB
      The number of field elements in a blob.
      See Also:
    • FIELD_ELEMENTS_PER_EXT_BLOB

      protected static final int FIELD_ELEMENTS_PER_EXT_BLOB
      The number of field elements in an extended blob.
      See Also:
    • FIELD_ELEMENTS_PER_CELL

      public static final int FIELD_ELEMENTS_PER_CELL
      The number of field elements in a cell.
      See Also:
    • BYTES_PER_COMMITMENT

      public static final int BYTES_PER_COMMITMENT
      The number of bytes in a KZG commitment.
      See Also:
    • BYTES_PER_PROOF

      public static final int BYTES_PER_PROOF
      The number of bytes in a KZG proof.
      See Also:
    • BYTES_PER_BLOB

      public static final int BYTES_PER_BLOB
      The number of bytes in a blob.
      See Also:
    • BYTES_PER_CELL

      public static final int BYTES_PER_CELL
      The number of bytes in a single cell.
      See Also:
    • CELLS_PER_EXT_BLOB

      public static final int CELLS_PER_EXT_BLOB
      The number of cells in an extended blob.
      See Also:
  • Method Details

    • loadNativeLibrary

      public static void loadNativeLibrary()
      Loads the appropriate native library based on your platform.
    • loadTrustedSetup

      public static void loadTrustedSetup(String file, long precompute)
      Loads the trusted setup from a file. Once loaded, the same setup will be used for all the crypto native calls. To load a new setup, free the current one by calling freeTrustedSetup() and then load the new one. If no trusted setup has been loaded, all the crypto native calls will throw a RuntimeException.
      Parameters:
      file - a path to a trusted setup file
      precompute - configurable value between 0-15
      Throws:
      CKZGException - if there is a crypto error
    • loadTrustedSetup

      public static void loadTrustedSetup(byte[] g1MonomialBytes, byte[] g1LagrangeBytes, byte[] g2MonomialBytes, long precompute)
      An alternative to loadTrustedSetup(String,long). Loads the trusted setup from method parameters instead of a file.
      Parameters:
      g1MonomialBytes - g1 values in monomial form as bytes
      g1LagrangeBytes - g1 values in Lagrange form as bytes
      g2MonomialBytes - g2 values in monomial form as bytes
      precompute - configurable value between 0-15
      Throws:
      CKZGException - if there is a crypto error
    • loadTrustedSetupFromResource

      public static <T> void loadTrustedSetupFromResource(String resource, Class<T> clazz, long precompute)
      An alternative to loadTrustedSetup(String,long). Loads the trusted setup from a resource.
      Type Parameters:
      T - the type of the class
      Parameters:
      resource - the resource name that contains the trusted setup
      clazz - the class to use to get the resource
      precompute - configurable value between 0-15
      Throws:
      CKZGException - if there is a crypto error
      IllegalArgumentException - if the resource does not exist
    • freeTrustedSetup

      public static void freeTrustedSetup()
      Free the current trusted setup. This method will throw an exception if no trusted setup has been loaded.
    • blobToKzgCommitment

      public static byte[] blobToKzgCommitment(byte[] blob)
      Calculates commitment for a given blob
      Parameters:
      blob - blob bytes
      Returns:
      the commitment
      Throws:
      CKZGException - if there is a crypto error
    • computeKzgProof

      public static ProofAndY computeKzgProof(byte[] blob, byte[] zBytes)
      Compute proof at point z for the polynomial represented by blob.
      Parameters:
      blob - blob bytes
      zBytes - a point
      Returns:
      an instance of ProofAndY holding the proof and the value y = f(z)
      Throws:
      CKZGException - if there is a crypto error
    • computeBlobKzgProof

      public static byte[] computeBlobKzgProof(byte[] blob, byte[] commitmentBytes)
      Given a blob, return the KZG proof that is used to verify it against the commitment
      Parameters:
      blob - blob bytes
      commitmentBytes - commitment bytes
      Returns:
      the proof
      Throws:
      CKZGException - if there is a crypto error
    • verifyKzgProof

      public static boolean verifyKzgProof(byte[] commitmentBytes, byte[] zBytes, byte[] yBytes, byte[] proofBytes)
      Verify the proof by point evaluation for the given commitment
      Parameters:
      commitmentBytes - commitment bytes
      zBytes - Z
      yBytes - Y
      proofBytes - the proof that needs verifying
      Returns:
      true if the proof is valid and false otherwise
      Throws:
      CKZGException - if there is a crypto error
    • verifyBlobKzgProof

      public static boolean verifyBlobKzgProof(byte[] blob, byte[] commitmentBytes, byte[] proofBytes)
      Given a blob and a KZG proof, verify that the blob data corresponds to the provided commitment.
      Parameters:
      blob - blob bytes
      commitmentBytes - commitment bytes
      proofBytes - proof bytes
      Returns:
      true if the proof is valid and false otherwise
      Throws:
      CKZGException - if there is a crypto error
    • verifyBlobKzgProofBatch

      public static boolean verifyBlobKzgProofBatch(byte[] blobs, byte[] commitmentsBytes, byte[] proofsBytes, long count)
      Given a list of blobs and blob KZG proofs, verify that they correspond to the provided commitments.
      Parameters:
      blobs - flattened blobs bytes
      commitmentsBytes - flattened commitments bytes
      proofsBytes - flattened proofs bytes
      count - the number of blobs (should be same as the number of proofs and commitments)
      Returns:
      true if the proof is valid and false otherwise
      Throws:
      CKZGException - if there is a crypto error
    • computeCells

      public static byte[] computeCells(byte[] blob)
      Get the cells for a given blob.
      Parameters:
      blob - the blob to get cells for
      Returns:
      the cells
      Throws:
      CKZGException - if there is a crypto error
    • computeCellsAndKzgProofs

      public static CellsAndProofs computeCellsAndKzgProofs(byte[] blob)
      Get the cells and proofs for a given blob.
      Parameters:
      blob - the blob to get cells/proofs for
      Returns:
      a CellsAndProofs object
      Throws:
      CKZGException - if there is a crypto error
    • recoverCellsAndKzgProofs

      public static CellsAndProofs recoverCellsAndKzgProofs(long[] cellIndices, byte[] cells)
      Given at least 50% of cells, reconstruct the missing cells/proofs.
      Parameters:
      cellIndices - the identifiers for the cells you have
      cells - the cells you have
      Returns:
      all cells/proofs for that blob
      Throws:
      CKZGException - if there is a crypto error
    • verifyCellKzgProofBatch

      public static boolean verifyCellKzgProofBatch(byte[] commitmentsBytes, long[] cellIndices, byte[] cells, byte[] proofsBytes)
      Verify that multiple cells' proofs are valid.
      Parameters:
      commitmentsBytes - the commitments for each cell
      cellIndices - the column index for each cell
      cells - the cells to verify
      proofsBytes - the proof for each cell
      Returns:
      true if the cells are valid with respect to the given commitments
      Throws:
      CKZGException - if there is a crypto error