|
1 | 1 | package org.tron.core.vm; |
2 | 2 |
|
3 | 3 | 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; |
6 | 4 | import static org.tron.common.math.Maths.max; |
7 | 5 | import static org.tron.common.math.Maths.min; |
8 | 6 | import static org.tron.common.runtime.vm.DataWord.WORD_SIZE; |
|
34 | 32 | import java.util.concurrent.ExecutorService; |
35 | 33 | import java.util.concurrent.Future; |
36 | 34 | import java.util.concurrent.TimeUnit; |
37 | | -import org.tron.common.crypto.ckzg4844.CKZG4844JNI; |
38 | 35 | import lombok.AllArgsConstructor; |
39 | 36 | import lombok.Getter; |
40 | 37 | import lombok.Setter; |
@@ -107,7 +104,6 @@ public class PrecompiledContracts { |
107 | 104 |
|
108 | 105 | private static final EthRipemd160 ethRipemd160 = new EthRipemd160(); |
109 | 106 | private static final Blake2F blake2F = new Blake2F(); |
110 | | - private static final KZGPointEvaluation kzgPointEvaluation = new KZGPointEvaluation(); |
111 | 107 |
|
112 | 108 | // FreezeV2 PrecompileContracts |
113 | 109 | private static final GetChainParameter getChainParameter = new GetChainParameter(); |
@@ -202,9 +198,6 @@ public class PrecompiledContracts { |
202 | 198 | private static final DataWord blake2FAddr = new DataWord( |
203 | 199 | "0000000000000000000000000000000000000000000000000000000000020009"); |
204 | 200 |
|
205 | | - private static final DataWord kzgPointEvaluationAddr = new DataWord( |
206 | | - "000000000000000000000000000000000000000000000000000000000002000a"); |
207 | | - |
208 | 201 | public static PrecompiledContract getOptimizedContractForConstant(PrecompiledContract contract) { |
209 | 202 | try { |
210 | 203 | Constructor<?> constructor = contract.getClass().getDeclaredConstructor(); |
@@ -286,9 +279,6 @@ public static PrecompiledContract getContractForAddress(DataWord address) { |
286 | 279 | if (VMConfig.allowTvmCompatibleEvm() && address.equals(blake2FAddr)) { |
287 | 280 | return blake2F; |
288 | 281 | } |
289 | | - if (VMConfig.allowTvmBlob() && address.equals(kzgPointEvaluationAddr)) { |
290 | | - return kzgPointEvaluation; |
291 | | - } |
292 | 282 |
|
293 | 283 | if (VMConfig.allowTvmFreezeV2()) { |
294 | 284 | if (address.equals(getChainParameterAddr)) { |
@@ -2200,49 +2190,4 @@ public Pair<Boolean, byte[]> execute(byte[] data) { |
2200 | 2190 | } |
2201 | 2191 | } |
2202 | 2192 |
|
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 | | - |
2248 | 2193 | } |
0 commit comments