Package ethereum.ckzg4844
Class CKZG4844JNI
java.lang.Object
ethereum.ckzg4844.CKZG4844JNI
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intThe number of bits in a BLS scalar field element.static final BigIntegerScalar field modulus of BLS12-381.static final intThe number of bytes in a blob.static final intThe number of bytes in a single cell.static final intThe number of bytes in a KZG commitment.static final intThe number of bytes in a BLS scalar field element.protected static final intThe number of bytes in a g1 point.protected static final intThe number of bytes in a g2 point.static final intThe number of bytes in a KZG proof.static final intThe number of cells in an extended blob.static final intThe number of field elements in a blob.static final intThe number of field elements in a cell.protected static final intThe number of field elements in an extended blob. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]blobToKzgCommitment(byte[] blob) Calculates commitment for a given blobstatic byte[]computeBlobKzgProof(byte[] blob, byte[] commitmentBytes) Given a blob, return the KZG proof that is used to verify it against the commitmentstatic byte[]computeCells(byte[] blob) Get the cells for a given blob.static CellsAndProofscomputeCellsAndKzgProofs(byte[] blob) Get the cells and proofs for a given blob.static ProofAndYcomputeKzgProof(byte[] blob, byte[] zBytes) Compute proof at point z for the polynomial represented by blob.static voidFree the current trusted setup.static voidLoads the appropriate native library based on your platform.static voidloadTrustedSetup(byte[] g1MonomialBytes, byte[] g1LagrangeBytes, byte[] g2MonomialBytes, long precompute) An alternative toloadTrustedSetup(String,long).static voidloadTrustedSetup(String file, long precompute) Loads the trusted setup from a file.static <T> voidloadTrustedSetupFromResource(String resource, Class<T> clazz, long precompute) An alternative toloadTrustedSetup(String,long).static CellsAndProofsrecoverCellsAndKzgProofs(long[] cellIndices, byte[] cells) Given at least 50% of cells, reconstruct the missing cells/proofs.static booleanverifyBlobKzgProof(byte[] blob, byte[] commitmentBytes, byte[] proofBytes) Given a blob and a KZG proof, verify that the blob data corresponds to the provided commitment.static booleanverifyBlobKzgProofBatch(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.static booleanverifyCellKzgProofBatch(byte[] commitmentsBytes, long[] cellIndices, byte[] cells, byte[] proofsBytes) Verify that multiple cells' proofs are valid.static booleanverifyKzgProof(byte[] commitmentBytes, byte[] zBytes, byte[] yBytes, byte[] proofBytes) Verify the proof by point evaluation for the given commitment
-
Field Details
-
BLS_MODULUS
Scalar field modulus of BLS12-381. -
BYTES_PER_G1
protected static final int BYTES_PER_G1The number of bytes in a g1 point.- See Also:
-
BYTES_PER_G2
protected static final int BYTES_PER_G2The number of bytes in a g2 point.- See Also:
-
BYTES_PER_FIELD_ELEMENT
public static final int BYTES_PER_FIELD_ELEMENTThe number of bytes in a BLS scalar field element.- See Also:
-
BITS_PER_FIELD_ELEMENT
protected static final int BITS_PER_FIELD_ELEMENTThe number of bits in a BLS scalar field element.- See Also:
-
FIELD_ELEMENTS_PER_BLOB
public static final int FIELD_ELEMENTS_PER_BLOBThe number of field elements in a blob.- See Also:
-
FIELD_ELEMENTS_PER_EXT_BLOB
protected static final int FIELD_ELEMENTS_PER_EXT_BLOBThe number of field elements in an extended blob.- See Also:
-
FIELD_ELEMENTS_PER_CELL
public static final int FIELD_ELEMENTS_PER_CELLThe number of field elements in a cell.- See Also:
-
BYTES_PER_COMMITMENT
public static final int BYTES_PER_COMMITMENTThe number of bytes in a KZG commitment.- See Also:
-
BYTES_PER_PROOF
public static final int BYTES_PER_PROOFThe number of bytes in a KZG proof.- See Also:
-
BYTES_PER_BLOB
public static final int BYTES_PER_BLOBThe number of bytes in a blob.- See Also:
-
BYTES_PER_CELL
public static final int BYTES_PER_CELLThe number of bytes in a single cell.- See Also:
-
CELLS_PER_EXT_BLOB
public static final int CELLS_PER_EXT_BLOBThe 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
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 callingfreeTrustedSetup()and then load the new one. If no trusted setup has been loaded, all the crypto native calls will throw aRuntimeException.- Parameters:
file- a path to a trusted setup fileprecompute- 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 toloadTrustedSetup(String,long). Loads the trusted setup from method parameters instead of a file.- Parameters:
g1MonomialBytes- g1 values in monomial form as bytesg1LagrangeBytes- g1 values in Lagrange form as bytesg2MonomialBytes- g2 values in monomial form as bytesprecompute- 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 toloadTrustedSetup(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 setupclazz- the class to use to get the resourceprecompute- configurable value between 0-15- Throws:
CKZGException- if there is a crypto errorIllegalArgumentException- 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
Compute proof at point z for the polynomial represented by blob.- Parameters:
blob- blob byteszBytes- a point- Returns:
- an instance of
ProofAndYholding 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 bytescommitmentBytes- 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 byteszBytes- ZyBytes- YproofBytes- 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 bytescommitmentBytes- commitment bytesproofBytes- 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 bytescommitmentsBytes- flattened commitments bytesproofsBytes- flattened proofs bytescount- 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
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
Given at least 50% of cells, reconstruct the missing cells/proofs.- Parameters:
cellIndices- the identifiers for the cells you havecells- 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 cellcellIndices- the column index for each cellcells- the cells to verifyproofsBytes- 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
-