|
16 | 16 | import static org.tron.common.utils.ByteUtil.parseWord; |
17 | 17 | import static org.tron.common.utils.ByteUtil.stripLeadingZeroes; |
18 | 18 | import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION; |
| 19 | +import static org.tron.core.vm.VMConstant.SIG_LENGTH; |
19 | 20 |
|
20 | 21 | import com.google.protobuf.ByteString; |
21 | 22 |
|
@@ -202,7 +203,7 @@ public class PrecompiledContracts { |
202 | 203 | public static PrecompiledContract getOptimizedContractForConstant(PrecompiledContract contract) { |
203 | 204 | try { |
204 | 205 | Constructor<?> constructor = contract.getClass().getDeclaredConstructor(); |
205 | | - return (PrecompiledContracts.PrecompiledContract) constructor.newInstance(); |
| 206 | + return (PrecompiledContracts.PrecompiledContract) constructor.newInstance(); |
206 | 207 | } catch (Exception e) { |
207 | 208 | throw new RuntimeException(e); |
208 | 209 | } |
@@ -395,6 +396,20 @@ private static byte[][] extractBytesArray(DataWord[] words, int offset, byte[] d |
395 | 396 | return bytesArray; |
396 | 397 | } |
397 | 398 |
|
| 399 | + private static byte[][] extractSigArray(DataWord[] words, int offset, byte[] data) { |
| 400 | + if (offset > words.length - 1) { |
| 401 | + return new byte[0][]; |
| 402 | + } |
| 403 | + int len = words[offset].intValueSafe(); |
| 404 | + byte[][] bytesArray = new byte[len][]; |
| 405 | + for (int i = 0; i < len; i++) { |
| 406 | + int bytesOffset = words[offset + i + 1].intValueSafe() / WORD_SIZE; |
| 407 | + bytesArray[i] = extractBytes(data, (bytesOffset + offset + 2) * WORD_SIZE, |
| 408 | + SIG_LENGTH); |
| 409 | + } |
| 410 | + return bytesArray; |
| 411 | + } |
| 412 | + |
398 | 413 | private static byte[] extractBytes(byte[] data, int offset, int len) { |
399 | 414 | return Arrays.copyOfRange(data, offset, offset + len); |
400 | 415 | } |
@@ -936,8 +951,15 @@ public Pair<Boolean, byte[]> execute(byte[] rawData) { |
936 | 951 | byte[] hash = Sha256Hash.hash(CommonParameter |
937 | 952 | .getInstance().isECKeyCryptoEngine(), combine); |
938 | 953 |
|
939 | | - byte[][] signatures = extractBytesArray( |
940 | | - words, words[3].intValueSafe() / WORD_SIZE, rawData); |
| 954 | + if (VMConfig.allowTvmSelfdestructRestriction()) { |
| 955 | + int sigArraySize = words[words[3].intValueSafe() / WORD_SIZE].intValueSafe(); |
| 956 | + if (sigArraySize > MAX_SIZE) { |
| 957 | + return Pair.of(true, DATA_FALSE); |
| 958 | + } |
| 959 | + } |
| 960 | + byte[][] signatures = VMConfig.allowTvmSelfdestructRestriction() ? |
| 961 | + extractSigArray(words, words[3].intValueSafe() / WORD_SIZE, rawData) : |
| 962 | + extractBytesArray(words, words[3].intValueSafe() / WORD_SIZE, rawData); |
941 | 963 |
|
942 | 964 | if (signatures.length == 0 || signatures.length > MAX_SIZE) { |
943 | 965 | return Pair.of(true, DATA_FALSE); |
@@ -1021,8 +1043,18 @@ private Pair<Boolean, byte[]> doExecute(byte[] data) |
1021 | 1043 | throws InterruptedException, ExecutionException { |
1022 | 1044 | DataWord[] words = DataWord.parseArray(data); |
1023 | 1045 | byte[] hash = words[0].getData(); |
1024 | | - byte[][] signatures = extractBytesArray( |
1025 | | - words, words[1].intValueSafe() / WORD_SIZE, data); |
| 1046 | + |
| 1047 | + if (VMConfig.allowTvmSelfdestructRestriction()) { |
| 1048 | + int sigArraySize = words[words[1].intValueSafe() / WORD_SIZE].intValueSafe(); |
| 1049 | + int addrArraySize = words[words[2].intValueSafe() / WORD_SIZE].intValueSafe(); |
| 1050 | + if (sigArraySize > MAX_SIZE || addrArraySize > MAX_SIZE) { |
| 1051 | + return Pair.of(true, DATA_FALSE); |
| 1052 | + } |
| 1053 | + } |
| 1054 | + |
| 1055 | + byte[][] signatures = VMConfig.allowTvmSelfdestructRestriction() ? |
| 1056 | + extractSigArray(words, words[1].intValueSafe() / WORD_SIZE, data) : |
| 1057 | + extractBytesArray(words, words[1].intValueSafe() / WORD_SIZE, data); |
1026 | 1058 | byte[][] addresses = extractBytes32Array( |
1027 | 1059 | words, words[2].intValueSafe() / WORD_SIZE); |
1028 | 1060 | int cnt = signatures.length; |
|
0 commit comments