diff --git a/src/main/java/org/tron/common/runtime/Runtime.java b/src/main/java/org/tron/common/runtime/Runtime.java index 5db5c592b04..f7cd67f0ef6 100644 --- a/src/main/java/org/tron/common/runtime/Runtime.java +++ b/src/main/java/org/tron/common/runtime/Runtime.java @@ -224,7 +224,7 @@ private long getEnergyLimit(AccountCapsule account, long feeLimit, long callValu if (leftBalanceForEnergyFreeze >= feeLimit) { energyFromFeeLimit = BigInteger.valueOf(totalEnergyFromFreeze) .multiply(BigInteger.valueOf(feeLimit)) - .divide(BigInteger.valueOf(totalBalanceForEnergyFreeze)).longValue(); + .divide(BigInteger.valueOf(totalBalanceForEnergyFreeze)).longValueExact(); } else { energyFromFeeLimit = Math .addExact(leftEnergyFromFreeze, @@ -326,7 +326,7 @@ private void create() AccountCapsule creator = this.deposit .getAccount(newSmartContract.getOriginAddress().toByteArray()); // if (executorType == ET_NORMAL_TYPE) { - // long blockENERGYLeftInUs = getBlockENERGYLeftInUs().longValue(); + // long blockENERGYLeftInUs = getBlockENERGYLeftInUs().longValueExact(); // thisTxENERGYLimitInUs = min(blockENERGYLeftInUs, // Constant.ENERGY_LIMIT_IN_ONE_TX_OF_SMART_CONTRACT); // } else { @@ -337,6 +337,7 @@ private void create() .getMaxCpuTimeOfOneTX() * 1000; long thisTxCPULimitInUs = (long) (MAX_CPU_TIME_OF_ONE_TX * getThisTxCPULimitInUsRatio()); + long vmStartInUs = System.nanoTime() / 1000; long vmShouldEndInUs = vmStartInUs + thisTxCPULimitInUs; @@ -413,12 +414,11 @@ private void call() long feeLimit = trx.getRawData().getFeeLimit(); long energyLimit; - if (isCallConstant(contractAddress)) { energyLimit = Constant.MAX_ENERGY_IN_TX; - } - else + } else { energyLimit = getEnergyLimit(creator, caller, contract, feeLimit, callValue); + } ProgramInvoke programInvoke = programInvokeFactory .createProgramInvoke(TRX_CONTRACT_CALL_TYPE, executorType, trx, @@ -498,7 +498,7 @@ private long getEnergyFee(long callerEnergyUsage, long callerEnergyFrozen, return 0; } return BigInteger.valueOf(callerEnergyFrozen).multiply(BigInteger.valueOf(callerEnergyUsage)) - .divide(BigInteger.valueOf(callerEnergyTotal)).longValue(); + .divide(BigInteger.valueOf(callerEnergyTotal)).longValueExact(); } public boolean isCallConstant() throws ContractValidateException { diff --git a/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java b/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java index a686254c5d4..152979d6867 100644 --- a/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java +++ b/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java @@ -35,11 +35,9 @@ import java.util.HashMap; import java.util.List; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.spongycastle.util.encoders.Hex; import org.tron.common.crypto.ECKey; -import org.tron.common.crypto.Hash; import org.tron.common.crypto.zksnark.BN128; import org.tron.common.crypto.zksnark.BN128Fp; import org.tron.common.crypto.zksnark.BN128G1; @@ -47,19 +45,15 @@ import org.tron.common.crypto.zksnark.Fp; import org.tron.common.crypto.zksnark.PairingCheck; import org.tron.common.runtime.vm.program.Program; -import org.tron.common.runtime.vm.program.Program.PrecompiledContractException; import org.tron.common.runtime.vm.program.ProgramResult; import org.tron.common.storage.Deposit; import org.tron.common.utils.BIUtil; import org.tron.common.utils.ByteArray; -import org.tron.common.utils.ByteUtil; import org.tron.common.utils.Sha256Hash; -import org.tron.core.Constant; import org.tron.core.Wallet; import org.tron.core.actuator.Actuator; import org.tron.core.actuator.ActuatorFactory; import org.tron.core.capsule.TransactionCapsule; -import org.tron.core.config.args.Args; import org.tron.core.exception.ContractExeException; import org.tron.core.exception.ContractValidateException; import org.tron.protos.Contract; @@ -88,7 +82,7 @@ public class PrecompiledContracts { private static final BN128Multiplication altBN128Mul = new BN128Multiplication(); private static final BN128Pairing altBN128Pairing = new BN128Pairing(); private static final VoteWitnessNative voteContract = new VoteWitnessNative(); -// private static final FreezeBalanceNative freezeBalance = new FreezeBalanceNative(); + // private static final FreezeBalanceNative freezeBalance = new FreezeBalanceNative(); // private static final UnfreezeBalanceNative unFreezeBalance = new UnfreezeBalanceNative(); private static final WithdrawBalanceNative withdrawBalance = new WithdrawBalanceNative(); private static final ProposalApproveNative proposalApprove = new ProposalApproveNative(); @@ -97,10 +91,11 @@ public class PrecompiledContracts { private static final ConvertFromTronBytesAddressNative convertFromTronBytesAddress = new ConvertFromTronBytesAddressNative(); private static final ConvertFromTronBase58AddressNative convertFromTronBase58Address = new ConvertFromTronBase58AddressNative(); private static final TransferAssetNative transferAsset = new TransferAssetNative(); - private static final GetTransferAssetNative getTransferAssetAmount = new GetTransferAssetNative(); + private static final GetTransferAssetNative getTransferAssetAmount = new GetTransferAssetNative(); private static final ECKey addressCheckECKey = new ECKey(); - private static final String addressCheckECKeyAddress = Wallet.encode58Check(addressCheckECKey.getAddress()); + private static final String addressCheckECKeyAddress = Wallet + .encode58Check(addressCheckECKey.getAddress()); private static final DataWord ecRecoverAddr = new DataWord( @@ -121,7 +116,7 @@ public class PrecompiledContracts { "0000000000000000000000000000000000000000000000000000000000000008"); private static final DataWord voteContractAddr = new DataWord( "0000000000000000000000000000000000000000000000000000000000010001"); -// private static final DataWord freezeBalanceAddr = new DataWord( + // private static final DataWord freezeBalanceAddr = new DataWord( // "0000000000000000000000000000000000000000000000000000000000010002"); // private static final DataWord unFreezeBalanceAddr = new DataWord( // "0000000000000000000000000000000000000000000000000000000000010003"); @@ -194,10 +189,18 @@ public static PrecompiledContract getContractForAddress(DataWord address) { } // Byzantium precompiles - if (address.equals(modExpAddr)) return modExp; - if (address.equals(altBN128AddAddr)) return altBN128Add; - if (address.equals(altBN128MulAddr)) return altBN128Mul; - if (address.equals(altBN128PairingAddr)) return altBN128Pairing; + if (address.equals(modExpAddr)) { + return modExp; + } + if (address.equals(altBN128AddAddr)) { + return altBN128Add; + } + if (address.equals(altBN128MulAddr)) { + return altBN128Mul; + } + if (address.equals(altBN128PairingAddr)) { + return altBN128Pairing; + } return null; } @@ -423,7 +426,7 @@ public long getEnergyForData(byte[] data) { .multiply(BigInteger.valueOf(Math.max(adjExpLen, 1))) .divide(GQUAD_DIVISOR); - return isLessThan(energy, BigInteger.valueOf(Long.MAX_VALUE)) ? energy.longValue() + return isLessThan(energy, BigInteger.valueOf(Long.MAX_VALUE)) ? energy.longValueExact() : Long.MAX_VALUE; } @@ -701,7 +704,7 @@ public long getEnergyForData(byte[] data) { @Override public Pair execute(byte[] data) { - if (isRootCallConstant()){ + if (isRootCallConstant()) { return Pair.of(true, new DataWord(0).getData()); } if (data == null || data.length != 2 * DataWord.DATAWORD_UNIT_SIZE) { @@ -887,7 +890,7 @@ public long getEnergyForData(byte[] data) { @Override public Pair execute(byte[] data) { - if (isRootCallConstant()){ + if (isRootCallConstant()) { return Pair.of(true, new DataWord(0).getData()); } @@ -944,7 +947,7 @@ public long getEnergyForData(byte[] data) { @Override public Pair execute(byte[] data) { - if (isRootCallConstant()){ + if (isRootCallConstant()) { return Pair.of(true, new DataWord(0).getData()); } @@ -1008,11 +1011,12 @@ public long getEnergyForData(byte[] data) { @Override public Pair execute(byte[] data) { - if (isRootCallConstant()){ + if (isRootCallConstant()) { return Pair.of(true, new DataWord(0).getData()); } - if (data == null || data.length == 0 || (data.length % (2 * DataWord.DATAWORD_UNIT_SIZE) != 0 )) { + if (data == null || data.length == 0 || (data.length % (2 * DataWord.DATAWORD_UNIT_SIZE) + != 0)) { return Pair.of(false, new DataWord(0).getData()); } @@ -1078,7 +1082,7 @@ public long getEnergyForData(byte[] data) { @Override public Pair execute(byte[] data) { - if (isRootCallConstant()){ + if (isRootCallConstant()) { return Pair.of(true, new DataWord(0).getData()); } @@ -1175,8 +1179,7 @@ public Pair execute(byte[] data) { } /** - * Native function for transferring Asset to another account.
- *
+ * Native function for transferring Asset to another account.

* * Input data[]:
toAddress, amount, assetName
* @@ -1192,11 +1195,12 @@ public long getEnergyForData(byte[] data) { @Override public Pair execute(byte[] data) { - if (isRootCallConstant()){ + if (isRootCallConstant()) { return Pair.of(true, new DataWord(0).getData()); } - if (data == null || (data.length <= DataWord.DATAWORD_UNIT_SIZE * 2 || data.length > DataWord.DATAWORD_UNIT_SIZE * 3)) { + if (data == null || (data.length <= DataWord.DATAWORD_UNIT_SIZE * 2 + || data.length > DataWord.DATAWORD_UNIT_SIZE * 3)) { return Pair.of(false, new DataWord(0).getData()); } @@ -1206,20 +1210,20 @@ public Pair execute(byte[] data) { System.arraycopy(data, 32 + 16 + 8, amount, 0, 8); // we already have a restrict for token name length, no more than 32 bytes. don't need to check again byte[] name = new byte[32]; - System.arraycopy(data, 64, name, 0, data.length-64); - int length =name.length; - while(length>0 && name[length -1] ==0){ + System.arraycopy(data, 64, name, 0, data.length - 64); + int length = name.length; + while (length > 0 && name[length - 1] == 0) { length--; } - name = ByteArray.subArray(name,0,length); + name = ByteArray.subArray(name, 0, length); Contract.TransferAssetContract.Builder builder = Contract.TransferAssetContract .newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(getCallerAddress())); - builder.setToAddress(ByteString.copyFrom(convertToTronAddress(new DataWord(toAddress).getLast20Bytes()))); + builder.setToAddress( + ByteString.copyFrom(convertToTronAddress(new DataWord(toAddress).getLast20Bytes()))); builder.setAmount(Longs.fromByteArray(amount)); builder.setAssetName(ByteString.copyFrom(name)); - TransferAssetContract contract = builder.build(); TransactionCapsule trx = new TransactionCapsule(contract, @@ -1246,10 +1250,8 @@ public Pair execute(byte[] data) { } - /** - * Native function for check Asset balance basing on targetAddress and Asset name.
- *
+ * Native function for check Asset balance basing on targetAddress and Asset name.

* * Input data[]:
address targetAddress, byte[] assetName
* @@ -1274,11 +1276,11 @@ public Pair execute(byte[] data) { // we already have a restrict for token name length, no more than 32 bytes. don't need to check again byte[] name = new byte[32]; System.arraycopy(data, 32, name, 0, 32); - int length =name.length; - while(length>0 && name[length -1] ==0){ + int length = name.length; + while (length > 0 && name[length - 1] == 0) { length--; } - name = ByteArray.subArray(name,0,length); + name = ByteArray.subArray(name, 0, length); long assetBalance = this.getDeposit().getDbManager().getAccountStore(). get(convertToTronAddress(new DataWord(targetAddress).getLast20Bytes())). diff --git a/src/main/java/org/tron/common/runtime/vm/VM.java b/src/main/java/org/tron/common/runtime/vm/VM.java index f8daf49ebed..e3548a993e9 100644 --- a/src/main/java/org/tron/common/runtime/vm/VM.java +++ b/src/main/java/org/tron/common/runtime/vm/VM.java @@ -71,7 +71,7 @@ private long calcMemEnergy(EnergyCost energyCosts, long oldMemSize, BigInteger n checkMemorySize(op, newMemSize); // memory drop consume calc - long memoryUsage = (newMemSize.longValue() + 31) / 32 * 32; + long memoryUsage = (newMemSize.longValueExact() + 31) / 32 * 32; if (memoryUsage > oldMemSize) { long memWords = (memoryUsage / 32); long memWordsOld = (oldMemSize / 32); @@ -258,7 +258,7 @@ public void step(Program program) { throw new OutOfEnergyException( "Not enough energy for '%s' operation executing: opEnergy[%d], programEnergy[%d]", op.name(), - dataCost.longValue(), program.getEnergyLimitLeft().longValueSafe()); + dataCost.longValueExact(), program.getEnergyLimitLeft().longValueSafe()); } energyCost = energyCosts.getLOG_ENERGY() + energyCosts.getLOG_TOPIC_ENERGY() * nTopics + @@ -1331,7 +1331,7 @@ public void play(Program program) { this.step(program); } - } catch (JVMStackOverFlowException e){ + } catch (JVMStackOverFlowException e) { throw new JVMStackOverFlowException(); } catch (RuntimeException e) { if (StringUtils.isEmpty(e.getMessage())) { diff --git a/src/main/java/org/tron/common/runtime/vm/program/Program.java b/src/main/java/org/tron/common/runtime/vm/program/Program.java index 4122a40161e..63db089b583 100644 --- a/src/main/java/org/tron/common/runtime/vm/program/Program.java +++ b/src/main/java/org/tron/common/runtime/vm/program/Program.java @@ -111,13 +111,13 @@ public static Boolean getRootCallConstant() { return isRootCallConstant; } - public static void setRootCallConstant(Boolean rootCallConstant) { + public static void setRootCallConstant(Boolean rootCallConstant) { isRootCallConstant = rootCallConstant; } private static long nonce = 0; private static byte[] rootTransactionId = null; - private static Boolean isRootCallConstant = null; + private static Boolean isRootCallConstant = null; private InternalTransaction transaction; @@ -445,7 +445,7 @@ public void createContract(DataWord value, DataWord memStart, DataWord memSize) byte[] senderAddress = convertToTronAddress(this.getOwnerAddress().getLast20Bytes()); // todo: need check the value > 0? - long endowment = value.value().longValue(); + long endowment = value.value().longValueExact(); if (getContractState().getBalance(senderAddress) < endowment) { stackPushZero(); return; @@ -508,7 +508,7 @@ public void createContract(DataWord value, DataWord memStart, DataWord memSize) newBalance = deposit.addBalance(newAddress, endowment); } - // BlockchainConfig blockchainConfig = config.getBlockchainConfig().getConfigForBlock(getNumber().longValue()); + // BlockchainConfig blockchainConfig = config.getBlockchainConfig().getConfigForBlock(getNumber().longValueExact()); // actual energy subtract DataWord energyLimit = this.getCreateEnergy(getEnergyLimitLeft()); spendEnergy(energyLimit.longValue(), "internal call"); @@ -637,7 +637,7 @@ public void callToAddress(MessageCall msg) { // 2.1 PERFORM THE VALUE (endowment) PART // todo: need to check value >= 0? - long endowment = msg.getEndowment().value().longValue(); + long endowment = msg.getEndowment().value().longValueExact(); long senderBalance = deposit.getBalance(senderAddress); if (senderBalance < endowment) { stackPushZero(); @@ -739,7 +739,7 @@ this, new DataWord(contextAddress), if (result != null) { BigInteger refundEnergy = msg.getEnergy().value().subtract(toBI(result.getEnergyUsed())); if (isPositive(refundEnergy)) { - refundEnergy(refundEnergy.longValue(), "remaining energy from the internal call"); + refundEnergy(refundEnergy.longValueExact(), "remaining energy from the internal call"); if (logger.isInfoEnabled()) { logger.info("The remaining energy refunded, account: [{}], energy: [{}] ", Hex.toHexString(senderAddress), @@ -1278,7 +1278,7 @@ public void callToPrecompiledAddress(MessageCall msg, byte[] contextAddress = msg.getType().callIsStateless() ? senderAddress : codeAddress; // todo: need check endowment > 0 and not exceed?? because of "senderBalance < endowment" - long endowment = msg.getEndowment().value().longValue(); + long endowment = msg.getEndowment().value().longValueExact(); long senderBalance = deposit.getBalance(senderAddress); if (senderBalance < endowment) { stackPushZero(); @@ -1291,9 +1291,10 @@ public void callToPrecompiledAddress(MessageCall msg, // Charge for endowment - is not reversible by rollback if (!ArrayUtils.isEmpty(senderAddress) && !ArrayUtils.isEmpty(contextAddress) - && senderAddress != contextAddress && msg.getEndowment().value().longValue() > 0) { + && senderAddress != contextAddress && msg.getEndowment().value().longValueExact() > 0) { try { - transfer(deposit, senderAddress, contextAddress, msg.getEndowment().value().longValue()); + transfer(deposit, senderAddress, contextAddress, + msg.getEndowment().value().longValueExact()); } catch (ContractValidateException e) { throw new BytecodeExecutionException("transfer failure"); } @@ -1490,7 +1491,7 @@ public static PrecompiledContractException contractExecuteException(TronExceptio public static OutOfEnergyException energyOverflow(BigInteger actualEnergy, BigInteger energyLimit) { return new OutOfEnergyException("Energy value overflow: actualEnergy[%d], energyLimit[%d];", - actualEnergy.longValue(), energyLimit.longValue()); + actualEnergy.longValueExact(), energyLimit.longValueExact()); } public static IllegalOperationException invalidOpCode(byte... opCode) { diff --git a/src/main/java/org/tron/common/utils/ByteUtil.java b/src/main/java/org/tron/common/utils/ByteUtil.java index d50cd9cceec..204300c0a1c 100644 --- a/src/main/java/org/tron/common/utils/ByteUtil.java +++ b/src/main/java/org/tron/common/utils/ByteUtil.java @@ -18,22 +18,12 @@ package org.tron.common.utils; -import java.io.ByteArrayOutputStream; -import java.io.IOException; +import com.google.common.base.Preconditions; +import com.google.common.primitives.UnsignedBytes; import java.math.BigInteger; -import java.net.InetAddress; -import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import com.google.common.base.Preconditions; -import com.google.common.base.Predicates; -import com.google.common.primitives.Bytes; -import com.google.common.primitives.UnsignedBytes; import org.spongycastle.util.encoders.Hex; -import org.tron.core.db.ByteArrayWrapper; public class ByteUtil { @@ -61,13 +51,12 @@ public static byte[] bigIntegerToBytes(BigInteger b, int numBytes) { } /** - * Omitting sign indication byte.

Instead of - * {@link org.spongycastle.util.BigIntegers#asUnsignedByteArray(BigInteger)} + * Omitting sign indication byte.

Instead of {@link org.spongycastle.util.BigIntegers#asUnsignedByteArray(BigInteger)} *
we use this custom method to avoid an empty array in case of BigInteger.ZERO * * @param value - any big integer number. A null-value will return null * @return A byte array without a leading zero byte if present in the signed encoding. - * BigInteger.ZERO will return an array with length 1 and byte-value 0. + * BigInteger.ZERO will return an array with length 1 and byte-value 0. */ public static byte[] bigIntegerToBytes(BigInteger value) { if (value == null) { @@ -86,6 +75,7 @@ public static byte[] bigIntegerToBytes(BigInteger value) { /** * merge arrays. + * * @param arrays - arrays to merge * @return - merged array */ @@ -215,8 +205,7 @@ public static byte[] intToBytes(int val) { } /** - * Cast hex encoded value from byte[] to BigInteger - * null is parsed like byte[0] + * Cast hex encoded value from byte[] to BigInteger null is parsed like byte[0] * * @param bb byte array contains the values * @return unsigned positive BigInteger value. @@ -226,8 +215,7 @@ public static BigInteger bytesToBigInteger(byte[] bb) { } /** - * Cast hex encoded value from byte[] to long - * null is parsed like byte[0] + * Cast hex encoded value from byte[] to long null is parsed like byte[0] * * Limited to Long.MAX_VALUE: 263-1 (8 bytes) * @@ -235,9 +223,10 @@ public static BigInteger bytesToBigInteger(byte[] bb) { * @return unsigned positive long value. */ public static long byteArrayToLong(byte[] b) { - if (b == null || b.length == 0) + if (b == null || b.length == 0) { return 0; - return new BigInteger(1, b).longValue(); + } + return new BigInteger(1, b).longValueExact(); } public static int firstNonZeroByte(byte[] data) { @@ -251,8 +240,9 @@ public static int firstNonZeroByte(byte[] data) { public static byte[] stripLeadingZeroes(byte[] data) { - if (data == null) + if (data == null) { return null; + } final int firstNonZero = firstNonZeroByte(data); switch (firstNonZero) { @@ -271,9 +261,8 @@ public static byte[] stripLeadingZeroes(byte[] data) { } /** - * Utility function to copy a byte array into a new byte array with given size. - * If the src length is smaller than the given size, the result will be left-padded - * with zeros. + * Utility function to copy a byte array into a new byte array with given size. If the src length + * is smaller than the given size, the result will be left-padded with zeros. * * @param value - a BigInteger with a maximum value of 2^256-1 * @return Byte array of given size with a copy of the src @@ -281,15 +270,15 @@ public static byte[] stripLeadingZeroes(byte[] data) { public static byte[] copyToArray(BigInteger value) { byte[] dest = ByteBuffer.allocate(32).array(); byte[] src = ByteUtil.bigIntegerToBytes(value); - if(src != null) { + if (src != null) { System.arraycopy(src, 0, dest, dest.length - src.length, src.length); } return dest; } /** - * Returns a number of zero bits preceding the highest-order ("leftmost") one-bit - * interpreting input array as a big-endian integer value + * Returns a number of zero bits preceding the highest-order ("leftmost") one-bit interpreting + * input array as a big-endian integer value */ public static int numberOfLeadingZeros(byte[] bytes) { @@ -298,20 +287,22 @@ public static int numberOfLeadingZeros(byte[] bytes) { if (i == -1) { return bytes.length * 8; } else { - int byteLeadingZeros = Integer.numberOfLeadingZeros((int)bytes[i] & 0xff) - 24; + int byteLeadingZeros = Integer.numberOfLeadingZeros((int) bytes[i] & 0xff) - 24; return i * 8 + byteLeadingZeros; } } /** - * Parses fixed number of bytes starting from {@code offset} in {@code input} array. - * If {@code input} has not enough bytes return array will be right padded with zero bytes. - * I.e. if {@code offset} is higher than {@code input.length} then zero byte array of length {@code len} will be returned + * Parses fixed number of bytes starting from {@code offset} in {@code input} array. If {@code + * input} has not enough bytes return array will be right padded with zero bytes. I.e. if {@code + * offset} is higher than {@code input.length} then zero byte array of length {@code len} will be + * returned */ public static byte[] parseBytes(byte[] input, int offset, int len) { - if (offset >= input.length || len == 0) + if (offset >= input.length || len == 0) { return EMPTY_BYTE_ARRAY; + } byte[] bytes = new byte[len]; System.arraycopy(input, offset, bytes, 0, Math.min(input.length - offset, len)); @@ -319,9 +310,8 @@ public static byte[] parseBytes(byte[] input, int offset, int len) { } /** - * Parses 32-bytes word from given input. - * Uses {@link #parseBytes(byte[], int, int)} method, - * thus, result will be right-padded with zero bytes if there is not enough bytes in {@code input} + * Parses 32-bytes word from given input. Uses {@link #parseBytes(byte[], int, int)} method, thus, + * result will be right-padded with zero bytes if there is not enough bytes in {@code input} * * @param idx an index of the word starting from {@code 0} */ @@ -330,9 +320,8 @@ public static byte[] parseWord(byte[] input, int idx) { } /** - * Parses 32-bytes word from given input. - * Uses {@link #parseBytes(byte[], int, int)} method, - * thus, result will be right-padded with zero bytes if there is not enough bytes in {@code input} + * Parses 32-bytes word from given input. Uses {@link #parseBytes(byte[], int, int)} method, thus, + * result will be right-padded with zero bytes if there is not enough bytes in {@code input} * * @param idx an index of the word starting from {@code 0} * @param offset an offset in {@code input} array to start parsing from diff --git a/src/main/java/org/tron/common/utils/Value.java b/src/main/java/org/tron/common/utils/Value.java index 6ed437c369b..1f9fb32118f 100644 --- a/src/main/java/org/tron/common/utils/Value.java +++ b/src/main/java/org/tron/common/utils/Value.java @@ -100,7 +100,7 @@ public long asLong() { if (isLong()) { return (Long) value; } else if (isBytes()) { - return new BigInteger(1, asBytes()).longValue(); + return new BigInteger(1, asBytes()).longValueExact(); } return 0; } @@ -343,8 +343,8 @@ public int countBranchNodes() { // decode(); if (this.isList()) { return this.asList().stream() - .mapToInt(obj -> (new Value(obj)).countBranchNodes()) - .sum(); + .mapToInt(obj -> (new Value(obj)).countBranchNodes()) + .sum(); } else if (this.isBytes()) { this.asBytes(); } diff --git a/src/main/java/org/tron/core/services/http/JsonFormat.java b/src/main/java/org/tron/core/services/http/JsonFormat.java index 7f2143820ce..d7e6d1fbfc9 100644 --- a/src/main/java/org/tron/core/services/http/JsonFormat.java +++ b/src/main/java/org/tron/core/services/http/JsonFormat.java @@ -626,9 +626,9 @@ private static Object handlePrimitive(Tokenizer tokenizer, FieldDescriptor field } } else { String id = tokenizer.consumeIdentifier(); - if (StringUtils.isAllLowerCase(id)){ + if (StringUtils.isAllLowerCase(id)) { char b = id.charAt(0); - b = (char)(b + 'A' - 'a'); + b = (char) (b + 'A' - 'a'); String s = id.substring(1); id = b + s; } @@ -1008,7 +1008,7 @@ private static long parseInteger(String text, boolean isSigned, boolean isLong) } } - result = bigValue.longValue(); + result = bigValue.longValueExact(); } return result;