Skip to content

Commit 212a4ec

Browse files
Merge pull request #6283 from raymondliu0711/feature/remove_precompile
feat(tvm): remove kzg precompile
2 parents 6474c7d + 4fff540 commit 212a4ec

File tree

16 files changed

+0
-17114
lines changed

16 files changed

+0
-17114
lines changed

actuator/src/main/java/org/tron/core/vm/PrecompiledContracts.java

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package org.tron.core.vm;
22

33
import static java.util.Arrays.copyOfRange;
4-
import static org.tron.common.crypto.ckzg4844.CKZG4844JNI.BLS_MODULUS;
5-
import static org.tron.common.crypto.ckzg4844.CKZG4844JNI.FIELD_ELEMENTS_PER_BLOB;
64
import static org.tron.common.math.Maths.max;
75
import static org.tron.common.math.Maths.min;
86
import static org.tron.common.runtime.vm.DataWord.WORD_SIZE;
@@ -34,7 +32,6 @@
3432
import java.util.concurrent.ExecutorService;
3533
import java.util.concurrent.Future;
3634
import java.util.concurrent.TimeUnit;
37-
import org.tron.common.crypto.ckzg4844.CKZG4844JNI;
3835
import lombok.AllArgsConstructor;
3936
import lombok.Getter;
4037
import lombok.Setter;
@@ -107,7 +104,6 @@ public class PrecompiledContracts {
107104

108105
private static final EthRipemd160 ethRipemd160 = new EthRipemd160();
109106
private static final Blake2F blake2F = new Blake2F();
110-
private static final KZGPointEvaluation kzgPointEvaluation = new KZGPointEvaluation();
111107

112108
// FreezeV2 PrecompileContracts
113109
private static final GetChainParameter getChainParameter = new GetChainParameter();
@@ -202,9 +198,6 @@ public class PrecompiledContracts {
202198
private static final DataWord blake2FAddr = new DataWord(
203199
"0000000000000000000000000000000000000000000000000000000000020009");
204200

205-
private static final DataWord kzgPointEvaluationAddr = new DataWord(
206-
"000000000000000000000000000000000000000000000000000000000002000a");
207-
208201
public static PrecompiledContract getOptimizedContractForConstant(PrecompiledContract contract) {
209202
try {
210203
Constructor<?> constructor = contract.getClass().getDeclaredConstructor();
@@ -286,9 +279,6 @@ public static PrecompiledContract getContractForAddress(DataWord address) {
286279
if (VMConfig.allowTvmCompatibleEvm() && address.equals(blake2FAddr)) {
287280
return blake2F;
288281
}
289-
if (VMConfig.allowTvmBlob() && address.equals(kzgPointEvaluationAddr)) {
290-
return kzgPointEvaluation;
291-
}
292282

293283
if (VMConfig.allowTvmFreezeV2()) {
294284
if (address.equals(getChainParameterAddr)) {
@@ -2200,49 +2190,4 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
22002190
}
22012191
}
22022192

2203-
public static class KZGPointEvaluation extends PrecompiledContract {
2204-
2205-
private static final int BLOB_VERIFY_INPUT_LENGTH = 192;
2206-
private static final byte BLOB_COMMITMENT_VERSION_KZG = 0x01;
2207-
private static final byte[] BLOB_PRECOMPILED_RETURN_VALUE =
2208-
ByteUtil.merge(ByteUtil.longTo32Bytes(FIELD_ELEMENTS_PER_BLOB),
2209-
ByteUtil.bigIntegerToBytes(BLS_MODULUS, 32));
2210-
2211-
@Override
2212-
public long getEnergyForData(byte[] data) {
2213-
return 50000;
2214-
}
2215-
2216-
@Override
2217-
public Pair<Boolean, byte[]> execute(byte[] data) {
2218-
if (data == null || data.length != BLOB_VERIFY_INPUT_LENGTH) {
2219-
return Pair.of(false, DataWord.ZERO().getData());
2220-
}
2221-
2222-
byte[] versionedHash = parseBytes(data, 0, 32);
2223-
byte[] z = parseBytes(data, 32, 32);
2224-
byte[] y = parseBytes(data, 64, 32);
2225-
byte[] commitment = parseBytes(data, 96, 48);
2226-
byte[] proof = parseBytes(data, 144, 48);
2227-
2228-
byte[] hash = Sha256Hash.hash(
2229-
CommonParameter.getInstance().isECKeyCryptoEngine(), commitment);
2230-
hash[0] = BLOB_COMMITMENT_VERSION_KZG;
2231-
if (!Arrays.equals(versionedHash, hash)) {
2232-
return Pair.of(false, DataWord.ZERO().getData());
2233-
}
2234-
2235-
try {
2236-
if (CKZG4844JNI.verifyKzgProof(commitment, z, y, proof)) {
2237-
return Pair.of(true, BLOB_PRECOMPILED_RETURN_VALUE);
2238-
} else {
2239-
return Pair.of(false, DataWord.ZERO().getData());
2240-
}
2241-
} catch (RuntimeException e) {
2242-
logger.warn("KZG point evaluation precompile contract failed {}", e.getMessage());
2243-
return Pair.of(false, DataWord.ZERO().getData());
2244-
}
2245-
}
2246-
}
2247-
22482193
}

common/src/main/java/org/tron/core/exception/TronError.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public enum ErrCode {
4444
PROMETHEUS_INIT(1),
4545
TRON_NET_SERVICE_INIT(1),
4646
ZCASH_INIT(1),
47-
CKZG_INIT(1),
4847
LOG_LOAD(1),
4948
WITNESS_INIT(1),
5049
RATE_LIMITER_INIT(1),

crypto/src/main/java/org/tron/common/crypto/ckzg4844/CKZG4844JNI.java

Lines changed: 0 additions & 236 deletions
This file was deleted.

crypto/src/main/java/org/tron/common/crypto/ckzg4844/CKZGException.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)