Skip to content

feat(tvm): update kzg jni links #6270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public enum ErrCode {
PROMETHEUS_INIT(1),
TRON_NET_SERVICE_INIT(1),
ZCASH_INIT(1),
CKZG_INIT(1),
LOG_LOAD(1),
WITNESS_INIT(1),
RATE_LIMITER_INIT(1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,28 @@ public static void loadNativeLibrary() {
public static final BigInteger BLS_MODULUS =
new BigInteger(
"52435875175126190479447740508185965837690552500527637822603658699938581184513");

/** The number of bytes in a g1 point. */
protected static final int BYTES_PER_G1 = 48;

/** The number of bytes in a g2 point. */
protected static final int BYTES_PER_G2 = 96;

/** The number of bytes in a BLS scalar field element. */
public static final int BYTES_PER_FIELD_ELEMENT = 32;

/** The number of bits in a BLS scalar field element. */
protected static final int BITS_PER_FIELD_ELEMENT = 255;

/** The number of field elements in a blob. */
public static final int FIELD_ELEMENTS_PER_BLOB = 4096;

/** The number of field elements in an extended blob. */
protected static final int FIELD_ELEMENTS_PER_EXT_BLOB = FIELD_ELEMENTS_PER_BLOB * 2;

/** The number of field elements in a cell. */
public static final int FIELD_ELEMENTS_PER_CELL = 64;

/** The number of bytes in a KZG commitment. */
public static final int BYTES_PER_COMMITMENT = 48;

/** The number of bytes in a KZG proof. */
public static final int BYTES_PER_PROOF = 48;

/** The number of bytes in a blob. */
public static final int BYTES_PER_BLOB = FIELD_ELEMENTS_PER_BLOB * BYTES_PER_FIELD_ELEMENT;

/** The number of bytes in a single cell. */
public static final int BYTES_PER_CELL = BYTES_PER_FIELD_ELEMENT * FIELD_ELEMENTS_PER_CELL;

/** The number of cells in an extended blob. */
public static final int CELLS_PER_EXT_BLOB =
FIELD_ELEMENTS_PER_EXT_BLOB / FIELD_ELEMENTS_PER_CELL;
Expand Down Expand Up @@ -214,15 +202,6 @@ public static native boolean verifyBlobKzgProof(
public static native boolean verifyBlobKzgProofBatch(
byte[] blobs, byte[] commitmentsBytes, byte[] proofsBytes, long count);

/**
* Get the cells for a given blob.
*
* @param blob the blob to get cells for
* @return the cells
* @throws CKZGException if there is a crypto error
*/
public static native byte[] computeCells(byte[] blob);

/**
* Get the cells and proofs for a given blob.
*
Expand Down
Binary file modified crypto/src/main/resources/lib/aarch64/libckzg4844jni.dylib
Binary file not shown.
Binary file modified crypto/src/main/resources/lib/aarch64/libckzg4844jni.so
Binary file not shown.
Binary file modified crypto/src/main/resources/lib/amd64/ckzg4844jni.dll
Binary file not shown.
Binary file modified crypto/src/main/resources/lib/amd64/libckzg4844jni.so
Binary file not shown.
Binary file modified crypto/src/main/resources/lib/x86_64/libckzg4844jni.dylib
100755 → 100644
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Component;
import org.tron.common.crypto.ckzg4844.CKZG4844JNI;
import org.tron.core.exception.TronError;

@Slf4j
@Component
Expand All @@ -31,11 +32,15 @@ public static void initCKZG4844() {
if (loaded.compareAndSet(false, true)) {
logger.info("init ckzg 4844 begin");

CKZG4844JNI.loadNativeLibrary();
try {
CKZG4844JNI.loadNativeLibrary();

String setupFile = getSetupFile("trusted_setup.txt");
String setupFile = getSetupFile("trusted_setup.txt");

CKZG4844JNI.loadTrustedSetup(setupFile, 0);
CKZG4844JNI.loadTrustedSetup(setupFile, 0);
} catch (Exception e) {
throw new TronError(e, TronError.ErrCode.CKZG_INIT);
}

logger.info("init ckzg 4844 done");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package org.tron.core.zksnark;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.mockStatic;

import java.util.Arrays;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.MockedStatic;
import org.tron.common.crypto.ckzg4844.CKZG4844JNI;
import org.tron.common.crypto.ckzg4844.CKZGException;
import org.tron.common.crypto.ckzg4844.CellsAndProofs;
import org.tron.common.crypto.ckzg4844.ProofAndY;
import org.tron.core.exception.TronError;
import org.tron.core.zen.KZGPointEvaluationInitService;

@Slf4j
Expand Down Expand Up @@ -79,5 +85,12 @@ public void testVerifyBlobKzgProof() {
}

KZGPointEvaluationInitService.freeSetup();

try (MockedStatic<CKZG4844JNI> mock = mockStatic(CKZG4844JNI.class)) {
mock.when(CKZG4844JNI::loadNativeLibrary).thenThrow(new RuntimeException());
TronError thrown = assertThrows(TronError.class,
KZGPointEvaluationInitService::initCKZG4844);
assertEquals(TronError.ErrCode.CKZG_INIT, thrown.getErrCode());
}
}
}