Skip to content

Commit 8de86f6

Browse files
committed
change longValue Exact.
1 parent cbf6ea4 commit 8de86f6

File tree

6 files changed

+74
-82
lines changed

6 files changed

+74
-82
lines changed

src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,25 @@
3535
import java.util.HashMap;
3636
import java.util.List;
3737
import lombok.extern.slf4j.Slf4j;
38-
import org.apache.commons.lang3.StringUtils;
3938
import org.apache.commons.lang3.tuple.Pair;
4039
import org.spongycastle.util.encoders.Hex;
4140
import org.tron.common.crypto.ECKey;
42-
import org.tron.common.crypto.Hash;
4341
import org.tron.common.crypto.zksnark.BN128;
4442
import org.tron.common.crypto.zksnark.BN128Fp;
4543
import org.tron.common.crypto.zksnark.BN128G1;
4644
import org.tron.common.crypto.zksnark.BN128G2;
4745
import org.tron.common.crypto.zksnark.Fp;
4846
import org.tron.common.crypto.zksnark.PairingCheck;
4947
import org.tron.common.runtime.vm.program.Program;
50-
import org.tron.common.runtime.vm.program.Program.PrecompiledContractException;
5148
import org.tron.common.runtime.vm.program.ProgramResult;
5249
import org.tron.common.storage.Deposit;
5350
import org.tron.common.utils.BIUtil;
5451
import org.tron.common.utils.ByteArray;
55-
import org.tron.common.utils.ByteUtil;
5652
import org.tron.common.utils.Sha256Hash;
57-
import org.tron.core.Constant;
5853
import org.tron.core.Wallet;
5954
import org.tron.core.actuator.Actuator;
6055
import org.tron.core.actuator.ActuatorFactory;
6156
import org.tron.core.capsule.TransactionCapsule;
62-
import org.tron.core.config.args.Args;
6357
import org.tron.core.exception.ContractExeException;
6458
import org.tron.core.exception.ContractValidateException;
6559
import org.tron.protos.Contract;
@@ -88,7 +82,7 @@ public class PrecompiledContracts {
8882
private static final BN128Multiplication altBN128Mul = new BN128Multiplication();
8983
private static final BN128Pairing altBN128Pairing = new BN128Pairing();
9084
private static final VoteWitnessNative voteContract = new VoteWitnessNative();
91-
// private static final FreezeBalanceNative freezeBalance = new FreezeBalanceNative();
85+
// private static final FreezeBalanceNative freezeBalance = new FreezeBalanceNative();
9286
// private static final UnfreezeBalanceNative unFreezeBalance = new UnfreezeBalanceNative();
9387
private static final WithdrawBalanceNative withdrawBalance = new WithdrawBalanceNative();
9488
private static final ProposalApproveNative proposalApprove = new ProposalApproveNative();
@@ -97,10 +91,11 @@ public class PrecompiledContracts {
9791
private static final ConvertFromTronBytesAddressNative convertFromTronBytesAddress = new ConvertFromTronBytesAddressNative();
9892
private static final ConvertFromTronBase58AddressNative convertFromTronBase58Address = new ConvertFromTronBase58AddressNative();
9993
private static final TransferAssetNative transferAsset = new TransferAssetNative();
100-
private static final GetTransferAssetNative getTransferAssetAmount = new GetTransferAssetNative();
94+
private static final GetTransferAssetNative getTransferAssetAmount = new GetTransferAssetNative();
10195

10296
private static final ECKey addressCheckECKey = new ECKey();
103-
private static final String addressCheckECKeyAddress = Wallet.encode58Check(addressCheckECKey.getAddress());
97+
private static final String addressCheckECKeyAddress = Wallet
98+
.encode58Check(addressCheckECKey.getAddress());
10499

105100

106101
private static final DataWord ecRecoverAddr = new DataWord(
@@ -121,7 +116,7 @@ public class PrecompiledContracts {
121116
"0000000000000000000000000000000000000000000000000000000000000008");
122117
private static final DataWord voteContractAddr = new DataWord(
123118
"0000000000000000000000000000000000000000000000000000000000010001");
124-
// private static final DataWord freezeBalanceAddr = new DataWord(
119+
// private static final DataWord freezeBalanceAddr = new DataWord(
125120
// "0000000000000000000000000000000000000000000000000000000000010002");
126121
// private static final DataWord unFreezeBalanceAddr = new DataWord(
127122
// "0000000000000000000000000000000000000000000000000000000000010003");
@@ -194,10 +189,18 @@ public static PrecompiledContract getContractForAddress(DataWord address) {
194189
}
195190

196191
// Byzantium precompiles
197-
if (address.equals(modExpAddr)) return modExp;
198-
if (address.equals(altBN128AddAddr)) return altBN128Add;
199-
if (address.equals(altBN128MulAddr)) return altBN128Mul;
200-
if (address.equals(altBN128PairingAddr)) return altBN128Pairing;
192+
if (address.equals(modExpAddr)) {
193+
return modExp;
194+
}
195+
if (address.equals(altBN128AddAddr)) {
196+
return altBN128Add;
197+
}
198+
if (address.equals(altBN128MulAddr)) {
199+
return altBN128Mul;
200+
}
201+
if (address.equals(altBN128PairingAddr)) {
202+
return altBN128Pairing;
203+
}
201204
return null;
202205
}
203206

@@ -701,7 +704,7 @@ public long getEnergyForData(byte[] data) {
701704
@Override
702705
public Pair<Boolean, byte[]> execute(byte[] data) {
703706

704-
if (isRootCallConstant()){
707+
if (isRootCallConstant()) {
705708
return Pair.of(true, new DataWord(0).getData());
706709
}
707710
if (data == null || data.length != 2 * DataWord.DATAWORD_UNIT_SIZE) {
@@ -887,7 +890,7 @@ public long getEnergyForData(byte[] data) {
887890
@Override
888891
public Pair<Boolean, byte[]> execute(byte[] data) {
889892

890-
if (isRootCallConstant()){
893+
if (isRootCallConstant()) {
891894
return Pair.of(true, new DataWord(0).getData());
892895
}
893896

@@ -944,7 +947,7 @@ public long getEnergyForData(byte[] data) {
944947
@Override
945948
public Pair<Boolean, byte[]> execute(byte[] data) {
946949

947-
if (isRootCallConstant()){
950+
if (isRootCallConstant()) {
948951
return Pair.of(true, new DataWord(0).getData());
949952
}
950953

@@ -1008,11 +1011,12 @@ public long getEnergyForData(byte[] data) {
10081011
@Override
10091012
public Pair<Boolean, byte[]> execute(byte[] data) {
10101013

1011-
if (isRootCallConstant()){
1014+
if (isRootCallConstant()) {
10121015
return Pair.of(true, new DataWord(0).getData());
10131016
}
10141017

1015-
if (data == null || data.length == 0 || (data.length % (2 * DataWord.DATAWORD_UNIT_SIZE) != 0 )) {
1018+
if (data == null || data.length == 0 || (data.length % (2 * DataWord.DATAWORD_UNIT_SIZE)
1019+
!= 0)) {
10161020
return Pair.of(false, new DataWord(0).getData());
10171021
}
10181022

@@ -1078,7 +1082,7 @@ public long getEnergyForData(byte[] data) {
10781082
@Override
10791083
public Pair<Boolean, byte[]> execute(byte[] data) {
10801084

1081-
if (isRootCallConstant()){
1085+
if (isRootCallConstant()) {
10821086
return Pair.of(true, new DataWord(0).getData());
10831087
}
10841088

@@ -1175,8 +1179,7 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
11751179
}
11761180

11771181
/**
1178-
* Native function for transferring Asset to another account. <br/>
1179-
* <br/>
1182+
* Native function for transferring Asset to another account. <br/> <br/>
11801183
*
11811184
* Input data[]: <br/> toAddress, amount, assetName <br/>
11821185
*
@@ -1192,11 +1195,12 @@ public long getEnergyForData(byte[] data) {
11921195
@Override
11931196
public Pair<Boolean, byte[]> execute(byte[] data) {
11941197

1195-
if (isRootCallConstant()){
1198+
if (isRootCallConstant()) {
11961199
return Pair.of(true, new DataWord(0).getData());
11971200
}
11981201

1199-
if (data == null || (data.length <= DataWord.DATAWORD_UNIT_SIZE * 2 || data.length > DataWord.DATAWORD_UNIT_SIZE * 3)) {
1202+
if (data == null || (data.length <= DataWord.DATAWORD_UNIT_SIZE * 2
1203+
|| data.length > DataWord.DATAWORD_UNIT_SIZE * 3)) {
12001204
return Pair.of(false, new DataWord(0).getData());
12011205
}
12021206

@@ -1206,20 +1210,20 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
12061210
System.arraycopy(data, 32 + 16 + 8, amount, 0, 8);
12071211
// we already have a restrict for token name length, no more than 32 bytes. don't need to check again
12081212
byte[] name = new byte[32];
1209-
System.arraycopy(data, 64, name, 0, data.length-64);
1210-
int length =name.length;
1211-
while(length>0 && name[length -1] ==0){
1213+
System.arraycopy(data, 64, name, 0, data.length - 64);
1214+
int length = name.length;
1215+
while (length > 0 && name[length - 1] == 0) {
12121216
length--;
12131217
}
1214-
name = ByteArray.subArray(name,0,length);
1218+
name = ByteArray.subArray(name, 0, length);
12151219
Contract.TransferAssetContract.Builder builder = Contract.TransferAssetContract
12161220
.newBuilder();
12171221
builder.setOwnerAddress(ByteString.copyFrom(getCallerAddress()));
1218-
builder.setToAddress(ByteString.copyFrom(convertToTronAddress(new DataWord(toAddress).getLast20Bytes())));
1222+
builder.setToAddress(
1223+
ByteString.copyFrom(convertToTronAddress(new DataWord(toAddress).getLast20Bytes())));
12191224
builder.setAmount(Longs.fromByteArray(amount));
12201225
builder.setAssetName(ByteString.copyFrom(name));
12211226

1222-
12231227
TransferAssetContract contract = builder.build();
12241228

12251229
TransactionCapsule trx = new TransactionCapsule(contract,
@@ -1246,10 +1250,8 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
12461250
}
12471251

12481252

1249-
12501253
/**
1251-
* Native function for check Asset balance basing on targetAddress and Asset name. <br/>
1252-
* <br/>
1254+
* Native function for check Asset balance basing on targetAddress and Asset name. <br/> <br/>
12531255
*
12541256
* Input data[]: <br/> address targetAddress, byte[] assetName <br/>
12551257
*
@@ -1274,11 +1276,11 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
12741276
// we already have a restrict for token name length, no more than 32 bytes. don't need to check again
12751277
byte[] name = new byte[32];
12761278
System.arraycopy(data, 32, name, 0, 32);
1277-
int length =name.length;
1278-
while(length>0 && name[length -1] ==0){
1279+
int length = name.length;
1280+
while (length > 0 && name[length - 1] == 0) {
12791281
length--;
12801282
}
1281-
name = ByteArray.subArray(name,0,length);
1283+
name = ByteArray.subArray(name, 0, length);
12821284

12831285
long assetBalance = this.getDeposit().getDbManager().getAccountStore().
12841286
get(convertToTronAddress(new DataWord(targetAddress).getLast20Bytes())).

src/main/java/org/tron/common/runtime/vm/VM.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ public void play(Program program) {
13311331
this.step(program);
13321332
}
13331333

1334-
} catch (JVMStackOverFlowException e){
1334+
} catch (JVMStackOverFlowException e) {
13351335
throw new JVMStackOverFlowException();
13361336
} catch (RuntimeException e) {
13371337
if (StringUtils.isEmpty(e.getMessage())) {

src/main/java/org/tron/common/runtime/vm/program/Program.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ public static Boolean getRootCallConstant() {
111111
return isRootCallConstant;
112112
}
113113

114-
public static void setRootCallConstant(Boolean rootCallConstant) {
114+
public static void setRootCallConstant(Boolean rootCallConstant) {
115115
isRootCallConstant = rootCallConstant;
116116
}
117117

118118
private static long nonce = 0;
119119
private static byte[] rootTransactionId = null;
120-
private static Boolean isRootCallConstant = null;
120+
private static Boolean isRootCallConstant = null;
121121

122122
private InternalTransaction transaction;
123123

@@ -1293,7 +1293,8 @@ public void callToPrecompiledAddress(MessageCall msg,
12931293
if (!ArrayUtils.isEmpty(senderAddress) && !ArrayUtils.isEmpty(contextAddress)
12941294
&& senderAddress != contextAddress && msg.getEndowment().value().longValueExact() > 0) {
12951295
try {
1296-
transfer(deposit, senderAddress, contextAddress, msg.getEndowment().value().longValueExact());
1296+
transfer(deposit, senderAddress, contextAddress,
1297+
msg.getEndowment().value().longValueExact());
12971298
} catch (ContractValidateException e) {
12981299
throw new BytecodeExecutionException("transfer failure");
12991300
}

0 commit comments

Comments
 (0)