Skip to content

Commit 6405454

Browse files
authored
Merge pull request #2864 from tronprotocol/release_3.6.6
Release 3.6.6
2 parents 3373eaa + cc1c40f commit 6405454

20 files changed

+153
-62
lines changed

src/main/java/org/tron/common/runtime/RuntimeImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ private double getCpuLimitInUsRatio() {
338338
if (ExecutorType.ET_NORMAL_TYPE == executorType) {
339339
// self witness generates block
340340
if (this.blockCap != null && blockCap.generatedByMyself &&
341-
this.blockCap.getInstance().getBlockHeader().getWitnessSignature().isEmpty()) {
341+
!this.blockCap.hasWitnessSignature()) {
342342
cpuLimitRatio = 1.0;
343343
} else {
344344
// self witness or other witness or fullnode verifies block
@@ -602,7 +602,8 @@ public void go() {
602602
try {
603603
if (vm != null) {
604604
TransactionCapsule trxCap = new TransactionCapsule(trx);
605-
if (null != blockCap && blockCap.generatedByMyself && null != trxCap.getContractRet()
605+
if (null != blockCap && blockCap.generatedByMyself
606+
&& blockCap.hasWitnessSignature() && null != trxCap.getContractRet()
606607
&& contractResult.OUT_OF_TIME == trxCap.getContractRet()) {
607608
result = program.getResult();
608609
program.spendAllEnergy();

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,11 @@ private static boolean validateV(byte[] v) {
353353

354354
/**
355355
* Computes modular exponentiation on big numbers
356-
*
356+
* <p>
357357
* format of data[] array: [length_of_BASE] [length_of_EXPONENT] [length_of_MODULUS] [BASE]
358358
* [EXPONENT] [MODULUS] where every length is a 32-byte left-padded integer representing the
359359
* number of bytes. Call data is assumed to be infinitely right-padded with zero bytes.
360-
*
360+
* <p>
361361
* Returns an output as a byte array with the same length as the modulus
362362
*/
363363
public static class ModExp extends PrecompiledContract {
@@ -470,11 +470,11 @@ private BigInteger parseArg(byte[] data, int offset, int len) {
470470

471471
/**
472472
* Computes point addition on Barreto–Naehrig curve. See {@link BN128Fp} for details<br/> <br/>
473-
*
473+
* <p>
474474
* input data[]:<br/> two points encoded as (x, y), where x and y are 32-byte left-padded
475475
* integers,<br/> if input is shorter than expected, it's assumed to be right-padded with zero
476476
* bytes<br/> <br/>
477-
*
477+
* <p>
478478
* output:<br/> resulting point (x', y'), where x and y encoded as 32-byte left-padded
479479
* integers<br/>
480480
*/
@@ -517,11 +517,11 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
517517
/**
518518
* Computes multiplication of scalar value on a point belonging to Barreto–Naehrig curve. See
519519
* {@link BN128Fp} for details<br/> <br/>
520-
*
520+
* <p>
521521
* input data[]:<br/> point encoded as (x, y) is followed by scalar s, where x, y and s are
522522
* 32-byte left-padded integers,<br/> if input is shorter than expected, it's assumed to be
523523
* right-padded with zero bytes<br/> <br/>
524-
*
524+
* <p>
525525
* output:<br/> resulting point (x', y'), where x and y encoded as 32-byte left-padded
526526
* integers<br/>
527527
*/
@@ -557,15 +557,15 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
557557

558558
/**
559559
* Computes pairing check. <br/> See {@link PairingCheck} for details.<br/> <br/>
560-
*
560+
* <p>
561561
* Input data[]: <br/> an array of points (a1, b1, ... , ak, bk), <br/> where "ai" is a point of
562562
* {@link BN128Fp} curve and encoded as two 32-byte left-padded integers (x; y) <br/> "bi" is a
563563
* point of {@link BN128G2} curve and encoded as four 32-byte left-padded integers {@code (ai + b;
564564
* ci + d)}, each coordinate of the point is a big-endian {@link } number, so {@code b} precedes
565565
* {@code a} in the encoding: {@code (b, a; d, c)} <br/> thus each pair (ai, bi) has 192 bytes
566566
* length, if 192 is not a multiple of {@code data.length} then execution fails <br/> the number
567567
* of pairs is derived from input length by dividing it by 192 (the length of a pair) <br/> <br/>
568-
*
568+
* <p>
569569
* output: <br/> pairing product which is either 0 or 1, encoded as 32-byte left-padded integer
570570
* <br/>
571571
*/
@@ -648,7 +648,6 @@ private Pair<BN128G1, BN128G2> decodePair(byte[] in, int offset) {
648648
}
649649

650650

651-
652651
public static class ValidateMultiSign extends PrecompiledContract {
653652

654653
private static final int ENGERYPERSIGN = 1500;
@@ -716,6 +715,7 @@ public Pair<Boolean, byte[]> execute(byte[] rawData) {
716715

717716

718717
public static class BatchValidateSign extends PrecompiledContract {
718+
719719
private static final ExecutorService workers;
720720
private static final int ENGERYPERSIGN = 1500;
721721
private static final int MAX_SIZE = 16;
@@ -779,7 +779,7 @@ private Pair<Boolean, byte[]> doExecute(byte[] data)
779779
}
780780
byte[] res = new byte[WORD_SIZE];
781781
if (isConstantCall()) {
782-
//for static call not use thread pool to avoid potential effect
782+
//for constant call not use thread pool to avoid potential effect
783783
for (int i = 0; i < cnt; i++) {
784784
if (DataWord
785785
.equalAddressByteArray(addresses[i], recoverAddrBySign(signatures[i], hash))) {
@@ -816,7 +816,6 @@ private Pair<Boolean, byte[]> doExecute(byte[] data)
816816
}
817817

818818

819-
820819
}
821820

822821
private static byte[] recoverAddrBySign(byte[] sign, byte[] hash) {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ public void step(Program program) {
10741074
case LOG3:
10751075
case LOG4: {
10761076

1077-
if (program.isConstantCall()) {
1077+
if (program.isStaticCall()) {
10781078
throw new Program.StaticCallModificationException();
10791079
}
10801080
DataWord address = program.getContractAddress();
@@ -1152,7 +1152,7 @@ public void step(Program program) {
11521152
}
11531153
break;
11541154
case SSTORE: {
1155-
if (program.isConstantCall()) {
1155+
if (program.isStaticCall()) {
11561156
throw new Program.StaticCallModificationException();
11571157
}
11581158

@@ -1283,7 +1283,7 @@ public void step(Program program) {
12831283
}
12841284
break;
12851285
case CREATE: {
1286-
if (program.isConstantCall()) {
1286+
if (program.isStaticCall()) {
12871287
throw new Program.StaticCallModificationException();
12881288
}
12891289
DataWord value = program.stackPop();
@@ -1295,7 +1295,7 @@ public void step(Program program) {
12951295
}
12961296
break;
12971297
case CREATE2: {
1298-
if (program.isConstantCall()) {
1298+
if (program.isStaticCall()) {
12991299
throw new Program.StaticCallModificationException();
13001300
}
13011301
DataWord value = program.stackPop();
@@ -1330,7 +1330,7 @@ public void step(Program program) {
13301330
value = DataWord.ZERO;
13311331
}
13321332

1333-
if (program.isConstantCall() && (op == CALL || op == CALLTOKEN) && !value.isZero()) {
1333+
if (program.isStaticCall() && (op == CALL || op == CALLTOKEN) && !value.isZero()) {
13341334
throw new Program.StaticCallModificationException();
13351335
}
13361336

@@ -1409,7 +1409,7 @@ public void step(Program program) {
14091409
break;
14101410
}
14111411
case SUICIDE: {
1412-
if (program.isConstantCall()) {
1412+
if (program.isStaticCall()) {
14131413
throw new Program.StaticCallModificationException();
14141414
}
14151415

@@ -1478,7 +1478,7 @@ private boolean isDeadAccount(Program program, DataWord address) {
14781478
* + size, unless size is 0, in which case the result is also 0.
14791479
*
14801480
* @param offset starting position of the memory
1481-
* @param size number of bytes needed
1481+
* @param size number of bytes needed
14821482
* @return offset + size, unless size is 0. In that case memNeeded is also 0.
14831483
*/
14841484
private static BigInteger memNeeded(DataWord offset, DataWord size) {

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public int getCallDeep() {
182182

183183
/**
184184
* @param transferAddress the address send trx to.
185-
* @param value the trx value transferred in the internaltransaction
185+
* @param value the trx value transferred in the internaltransaction
186186
*/
187187
private InternalTransaction addInternalTx(DataWord energyLimit, byte[] senderAddress,
188188
byte[] transferAddress,
@@ -349,9 +349,9 @@ public void memorySave(int addr, byte[] value) {
349349
/**
350350
* . Allocates a piece of memory and stores value at given offset address
351351
*
352-
* @param addr is the offset address
352+
* @param addr is the offset address
353353
* @param allocSize size of memory needed to write
354-
* @param value the data to write to memory
354+
* @param value the data to write to memory
355355
*/
356356
public void memorySave(int addr, int allocSize, byte[] value) {
357357
memory.extendAndWrite(addr, allocSize, value);
@@ -383,7 +383,7 @@ public byte[] memoryChunk(int offset, int size) {
383383
* . Allocates extra memory in the program for a specified size, calculated from a given offset
384384
*
385385
* @param offset the memory address offset
386-
* @param size the number of bytes to allocate
386+
* @param size the number of bytes to allocate
387387
*/
388388
public void allocateMemory(int offset, int size) {
389389
memory.extend(offset, size);
@@ -537,7 +537,9 @@ this, new DataWord(newAddress), getContractAddress(), value, new DataWord(0),
537537
new DataWord(0),
538538
newBalance, null, deposit, false, byTestingSuite(), vmStartInUs,
539539
getVmShouldEndInUs(), energyLimit.longValueSafe());
540-
540+
if (isConstantCall()) {
541+
programInvoke.setConstantCall();
542+
}
541543
ProgramResult createResult = ProgramResult.createEmpty();
542544

543545
if (contractAlreadyExists) {
@@ -751,8 +753,11 @@ this, new DataWord(contextAddress),
751753
!isTokenTransfer ? callValue : new DataWord(0),
752754
!isTokenTransfer ? new DataWord(0) : callValue,
753755
!isTokenTransfer ? new DataWord(0) : msg.getTokenId(),
754-
contextBalance, data, deposit, msg.getType().callIsStatic() || isConstantCall(),
756+
contextBalance, data, deposit, msg.getType().callIsStatic() || isStaticCall(),
755757
byTestingSuite(), vmStartInUs, getVmShouldEndInUs(), msg.getEnergy().longValueSafe());
758+
if (isConstantCall()) {
759+
programInvoke.setConstantCall();
760+
}
756761
VM vm = new VM(config);
757762
Program program = new Program(programCode, programInvoke, internalTx, config,
758763
this.blockCap);
@@ -1046,6 +1051,10 @@ public DataWord getDifficulty() {
10461051
return invoke.getDifficulty().clone();
10471052
}
10481053

1054+
public boolean isStaticCall() {
1055+
return invoke.isStaticCall();
1056+
}
1057+
10491058
public boolean isConstantCall() {
10501059
return invoke.isConstantCall();
10511060
}

src/main/java/org/tron/common/runtime/vm/program/invoke/ProgramInvoke.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@ public interface ProgramInvoke {
6363

6464
Deposit getDeposit();
6565

66-
boolean isConstantCall();
66+
boolean isStaticCall();
6767

6868
long getVmShouldEndInUs();
6969

7070
long getVmStartInUs();
7171

7272
long getEnergyLimit();
7373

74+
BlockCapsule getBlockByNum(int index);
75+
7476
void setConstantCall();
7577

76-
BlockCapsule getBlockByNum(int index);
78+
boolean isConstantCall();
7779
}

src/main/java/org/tron/common/runtime/vm/program/invoke/ProgramInvokeImpl.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ public class ProgramInvokeImpl implements ProgramInvoke {
5555
private boolean byTransaction = true;
5656
private boolean byTestingSuite = false;
5757
private int callDeep = 0;
58+
private boolean isStaticCall = false;
5859
private boolean isConstantCall = false;
5960

6061
public ProgramInvokeImpl(DataWord address, DataWord origin, DataWord caller, DataWord balance,
6162
DataWord callValue, DataWord tokenValue, DataWord tokenId, byte[] msgData,
6263
DataWord lastHash, DataWord coinbase, DataWord timestamp, DataWord number,
6364
DataWord difficulty,
64-
Deposit deposit, int callDeep, boolean isConstantCall, boolean byTestingSuite,
65+
Deposit deposit, int callDeep, boolean isStaticCall, boolean byTestingSuite,
6566
long vmStartInUs, long vmShouldEndInUs, long energyLimit) {
6667
this.address = address;
6768
this.origin = origin;
@@ -83,7 +84,7 @@ public ProgramInvokeImpl(DataWord address, DataWord origin, DataWord caller, Dat
8384

8485
this.deposit = deposit;
8586
this.byTransaction = false;
86-
this.isConstantCall = isConstantCall;
87+
this.isStaticCall = isStaticCall;
8788
this.byTestingSuite = byTestingSuite;
8889
this.vmStartInUs = vmStartInUs;
8990
this.vmShouldEndInUs = vmShouldEndInUs;
@@ -260,8 +261,8 @@ public Deposit getDeposit() {
260261
}
261262

262263
@Override
263-
public boolean isConstantCall() {
264-
return isConstantCall;
264+
public boolean isStaticCall() {
265+
return isStaticCall;
265266
}
266267

267268
@Override
@@ -371,11 +372,6 @@ public long getEnergyLimit() {
371372
return energyLimit;
372373
}
373374

374-
@Override
375-
public void setConstantCall() {
376-
isConstantCall = true;
377-
}
378-
379375
@Override
380376
public BlockCapsule getBlockByNum(int index) {
381377
try {
@@ -385,4 +381,14 @@ public BlockCapsule getBlockByNum(int index) {
385381
}
386382
}
387383

384+
@Override
385+
public void setConstantCall() {
386+
isConstantCall = true;
387+
}
388+
389+
@Override
390+
public boolean isConstantCall() {
391+
return isConstantCall;
392+
}
393+
388394
}

src/main/java/org/tron/common/runtime/vm/program/invoke/ProgramInvokeMockImpl.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class ProgramInvokeMockImpl implements ProgramInvoke {
5050

5151
private boolean isConstantCall;
5252

53+
private boolean isStaticCall;
54+
5355
public ProgramInvokeMockImpl(byte[] msgDataRaw) {
5456
this();
5557
this.msgData = Arrays.clone(msgDataRaw);
@@ -224,8 +226,8 @@ public void setOwnerAddress(byte[] ownerAddress) {
224226
}
225227

226228
@Override
227-
public boolean isConstantCall() {
228-
return isConstantCall;
229+
public boolean isStaticCall() {
230+
return isStaticCall;
229231
}
230232

231233
@Override
@@ -242,11 +244,6 @@ public void setEnergyLimit(long customizedEnergyLimit) {
242244
energyLimit = customizedEnergyLimit;
243245
}
244246

245-
@Override
246-
public void setConstantCall() {
247-
isConstantCall = true;
248-
}
249-
250247
@Override
251248
public BlockCapsule getBlockByNum(int index) {
252249
try {
@@ -256,6 +253,16 @@ public BlockCapsule getBlockByNum(int index) {
256253
}
257254
}
258255

256+
@Override
257+
public void setConstantCall() {
258+
isConstantCall = true;
259+
}
260+
261+
@Override
262+
public boolean isConstantCall() {
263+
return isConstantCall;
264+
}
265+
259266
@Override
260267
public boolean byTestingSuite() {
261268
return true;

src/main/java/org/tron/core/Wallet.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,11 @@ public Protocol.ChainParameters getChainParameters() {
921921
.setValue(dbManager.getDynamicPropertiesStore().getAllowTvmSolidity059())
922922
.build());
923923

924+
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
925+
.setKey("getForbidTransferToContract")
926+
.setValue(dbManager.getDynamicPropertiesStore().getForbidTransferToContract())
927+
.build());
928+
924929
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
925930
.setKey("getAdaptiveResourceLimitTargetRatio")
926931
.setValue(

src/main/java/org/tron/core/actuator/TransferActuator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ public boolean validate() throws ContractValidateException {
124124
if (toAccount == null) {
125125
fee = fee + dbManager.getDynamicPropertiesStore().getCreateNewAccountFeeInSystemContract();
126126
}
127-
//after TvmSolidity059 proposal, send trx to smartContract by actuator is not allowed.
128-
if (dbManager.getDynamicPropertiesStore().getAllowTvmSolidity059() == 1
127+
//after ForbidTransferToContract proposal, send trx to smartContract by actuator is not allowed.
128+
if (dbManager.getDynamicPropertiesStore().getForbidTransferToContract() == 1
129129
&& toAccount != null
130130
&& toAccount.getType() == AccountType.Contract) {
131131
throw new ContractValidateException("Cannot transfer trx to smartContract.");

0 commit comments

Comments
 (0)