Skip to content

Commit a25c302

Browse files
author
Liulei
committed
feat(crypto): add ckzg jni files and tests
1 parent a6c44c5 commit a25c302

5 files changed

Lines changed: 23 additions & 6 deletions

File tree

254 KB
Binary file not shown.
351 KB
Binary file not shown.
293 KB
Binary file not shown.

framework/src/test/java/org/tron/common/runtime/vm/PrecompiledContractsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ private static byte[] encodeMultiWord(byte[]... words) {
11711171
}
11721172

11731173
@Test
1174-
public void ckzgPointEvaluationTest() {
1174+
public void kzgPointEvaluationTest() {
11751175
VMConfig.initAllowTvmBlob(1);
11761176

11771177
PrecompiledContract contract =
Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
package org.tron.core.zksnark;
22

33
import lombok.extern.slf4j.Slf4j;
4+
import org.bouncycastle.util.encoders.Hex;
45
import org.junit.Test;
5-
import org.tron.common.BaseTest;
6+
import org.tron.common.crypto.ckzg4844.CKZG4844JNI;
67
import org.tron.core.zen.KZGPointEvaluationInitService;
78

9+
import static org.junit.Assert.assertArrayEquals;
10+
import static org.junit.Assert.assertTrue;
11+
812
@Slf4j
9-
public class KZGPointEvaluationTest extends BaseTest {
13+
public class KZGPointEvaluationTest {
1014

1115
@Test
12-
public void testKZGPointEvaluation() {
13-
KZGPointEvaluationInitService.freeSetup();
14-
16+
public void testVerifyBlobKzgProof() {
1517
KZGPointEvaluationInitService.initCKZG4844();
1618

19+
byte[] blob = new byte[131072];
20+
blob[0] = 0x01;
21+
byte[] commitment = CKZG4844JNI.blobToKzgCommitment(blob);
22+
byte[] expectedCommitment =
23+
Hex.decode("a70477b56251e8770969c83eaed665d3ab99b96b72270a41009f27"
24+
+ "52b5c06a06bd089ad48952c12b1dbf83dccd9d373f");
25+
assertArrayEquals(expectedCommitment, commitment);
1726

27+
byte[] proof = CKZG4844JNI.computeBlobKzgProof(blob, commitment);
28+
byte[] expectedProof =
29+
Hex.decode("b7f576f2442febaa035d3c6f34bbdad6acebcaec70236ff40b3373b"
30+
+ "d2ca00547d3ca7bb1d0ed3e728ca9dab610a4cfa4");
31+
assertArrayEquals(expectedProof, proof);
1832

33+
boolean isValidProof = CKZG4844JNI.verifyBlobKzgProof(blob, commitment, proof);
34+
assertTrue(isValidProof);
1935

36+
KZGPointEvaluationInitService.freeSetup();
2037
}
2138
}

0 commit comments

Comments
 (0)