Skip to content

Commit c64d5dd

Browse files
committed
use new proposal instead of hard fork to upgrade tvm
1 parent 46dda5c commit c64d5dd

14 files changed

Lines changed: 68 additions & 33 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ public void finalization() {
768768

769769
public void checkTokenValueAndId(long tokenValue, long tokenId) throws ContractValidateException {
770770
if (VMConfig.allowTvmTransferTrc10()) {
771-
if (VMConfig.isVERSION_3_5_HARD_FORK()) { //3.5 hard fork
771+
if (VMConfig.improveTransferTrc10Security()) { //improve_transfer_trc10_security proposal
772772
// tokenid can only be 0
773773
// or (MIN_TOKEN_ID, Long.Max]
774774
if (tokenId <= VMConstant.MIN_TOKEN_ID && tokenId != 0) {

‎src/main/java/org/tron/common/runtime/config/VMConfig.java‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ public class VMConfig {
4141
@Setter
4242
private static boolean ENERGY_LIMIT_HARD_FORK = false;
4343

44-
@Getter
45-
@Setter
46-
private static boolean VERSION_3_5_HARD_FORK = false;
44+
// @Getter
45+
// @Setter
46+
// private static boolean VERSION_3_5_HARD_FORK = false;
4747

4848
@Setter
4949
private static boolean ALLOW_TVM_TRANSFER_TRC10 = false;
5050

51+
@Setter
52+
private static boolean IMPROVE_TRANSFER_TRC10_SECURITY = false;
53+
5154
private VMConfig() {
5255
}
5356

@@ -70,7 +73,10 @@ public boolean vmTraceCompressed() {
7073

7174
public static void initVmHardFork() {
7275
ENERGY_LIMIT_HARD_FORK = ForkController.instance().pass(ForkBlockVersionConsts.ENERGY_LIMIT);
73-
VERSION_3_5_HARD_FORK = ForkController.instance().pass(ForkBlockVersionEnum.VERSION_3_5);
76+
//VERSION_3_5_HARD_FORK = ForkController.instance().pass(ForkBlockVersionEnum.VERSION_3_5);
77+
}
78+
public static void initImproveTransferTrc10Security(long allow) {
79+
IMPROVE_TRANSFER_TRC10_SECURITY = allow ==1 ;
7480
}
7581

7682
public static void initAllowTvmTransferTrc10(long allow) { ALLOW_TVM_TRANSFER_TRC10 = allow == 1;
@@ -84,4 +90,8 @@ public static boolean allowTvmTransferTrc10() {
8490
return ALLOW_TVM_TRANSFER_TRC10;
8591
}
8692

93+
public static boolean improveTransferTrc10Security() {
94+
return IMPROVE_TRANSFER_TRC10_SECURITY;
95+
}
96+
8797
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ public void step(Program program) {
637637
*/
638638
case ADDRESS: {
639639
DataWord address = program.getContractAddress();
640-
if (VMConfig.isVERSION_3_5_HARD_FORK()) { //3.5 hard fork
640+
if (VMConfig.improveTransferTrc10Security()) { // improve_transfer_trc10_security proposal
641641
address = new DataWord(address.getLast20Bytes());
642642
}
643643

@@ -666,7 +666,7 @@ public void step(Program program) {
666666
case ORIGIN: {
667667
DataWord originAddress = program.getOriginAddress();
668668

669-
if (VMConfig.isVERSION_3_5_HARD_FORK()) { //3.5 hard fork
669+
if (VMConfig.improveTransferTrc10Security()) { //improve_transfer_trc10_security proposal
670670
originAddress = new DataWord(originAddress.getLast20Bytes());
671671
}
672672

@@ -1247,7 +1247,7 @@ public void step(Program program) {
12471247
boolean isTokenTransferMsg = false;
12481248
if (op == CALLTOKEN) {
12491249
tokenId = program.stackPop();
1250-
if (VMConfig.isVERSION_3_5_HARD_FORK()) { // 3.5 hard fork
1250+
if (VMConfig.improveTransferTrc10Security()) { // improve_transfer_trc10_security proposal
12511251
isTokenTransferMsg = true;
12521252
}
12531253
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ public interface ProgramOutListener {
14191419
* @param msg
14201420
*/
14211421
public void checkTokenId(MessageCall msg) {
1422-
if(VMConfig.isVERSION_3_5_HARD_FORK()){ //3.5 hard fork
1422+
if(VMConfig.improveTransferTrc10Security()){ //improve_transfer_trc10_security proposal
14231423
// tokenid should not get Long type overflow
14241424
long tokenId = msg.getTokenId().sValue().longValueExact();
14251425
// tokenId can only be 0 when isTokenTransferMsg == false
@@ -1433,7 +1433,7 @@ public void checkTokenId(MessageCall msg) {
14331433
}
14341434

14351435
public boolean isTokenTransfer(MessageCall msg) {
1436-
if(VMConfig.isVERSION_3_5_HARD_FORK()) { //3.5 hard fork
1436+
if(VMConfig.improveTransferTrc10Security()) { //improve_transfer_trc10_security proposal
14371437
return msg.isTokenTransferMsg();
14381438
}
14391439
else {
@@ -1442,7 +1442,7 @@ public boolean isTokenTransfer(MessageCall msg) {
14421442
}
14431443

14441444
public void checkTokenIdInTokenBalance(DataWord tokenIdDataWord) {
1445-
if(VMConfig.isVERSION_3_5_HARD_FORK()){ //3.5 hard fork
1445+
if(VMConfig.improveTransferTrc10Security()){ //improve_transfer_trc10_security proposal
14461446
// tokenid should not get Long type overflow
14471447
long tokenId = tokenIdDataWord.sValue().longValueExact();
14481448
// or tokenId can only be (MIN_TOKEN_ID, Long.Max]

‎src/main/java/org/tron/common/storage/Value.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public Value(byte[] any, int type) {
4343
System.arraycopy(any, 0, this.any, 0, any.length);
4444
this.type = new Type(type);
4545
} else {
46-
if (VMConfig.isVERSION_3_5_HARD_FORK()) {
46+
if (VMConfig.improveTransferTrc10Security()) {
4747
this.type = new Type(VALUE_TYPE_UNKNOWN);
4848
}
4949
}
@@ -58,7 +58,7 @@ private Value(Value value) {
5858
System.arraycopy(value.getAny(), 0, this.any, 0, value.getAny().length);
5959
this.type = value.getType().clone();
6060
} else {
61-
if (VMConfig.isVERSION_3_5_HARD_FORK()) {
61+
if (VMConfig.improveTransferTrc10Security()) {
6262
this.type = new Type(VALUE_TYPE_UNKNOWN);
6363
}
6464
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,12 @@ public Protocol.ChainParameters getChainParameters() {
867867
.setKey("getAllowAdaptiveEnergy")
868868
.setValue(dbManager.getDynamicPropertiesStore().getAllowAdaptiveEnergy())
869869
.build());
870+
// IMPROVE_TRANSFER_TRC10_SECURITY, // 1, 22
871+
builder.addChainParameter(
872+
Protocol.ChainParameters.ChainParameter.newBuilder()
873+
.setKey("getImproveTransferTrc10Security")
874+
.setValue(dbManager.getDynamicPropertiesStore().getImproveTransferTrc10Security())
875+
.build());
870876
//other chainParameters
871877
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
872878
.setKey("getTotalEnergyTargetLimit")

‎src/main/java/org/tron/core/capsule/TransactionCapsule.java‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@
4848
import org.tron.common.runtime.vm.program.Program.StackTooLargeException;
4949
import org.tron.common.runtime.vm.program.Program.StackTooSmallException;
5050
import org.tron.common.utils.ByteArray;
51-
import org.tron.common.utils.ForkController;
5251
import org.tron.common.utils.Sha256Hash;
5352
import org.tron.core.Wallet;
54-
import org.tron.core.config.Parameter.ForkBlockVersionEnum;
5553
import org.tron.core.db.AccountStore;
5654
import org.tron.core.db.Manager;
5755
import org.tron.core.db.TransactionTrace;
@@ -755,12 +753,6 @@ public void setResult(Runtime runtime) {
755753
this.setResultCode(contractResult.JVM_STACK_OVER_FLOW);
756754
return;
757755
}
758-
if (ForkController.instance().pass(ForkBlockVersionEnum.VERSION_3_5)){
759-
if (exception instanceof BytecodeExecutionException) {
760-
this.setResultCode(contractResult.BYTECODE_EXECUTION_EXCEPTION);
761-
return;
762-
}
763-
}
764756
this.setResultCode(contractResult.UNKNOWN);
765757
return;
766758
}

‎src/main/java/org/tron/core/config/args/Args.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ public class Args {
327327
@Setter
328328
private long allowTvmTransferTrc10; //committee parameter
329329

330+
@Getter
331+
@Setter
332+
private long improveTransferTrc10Security; //committee parameter
333+
330334
@Getter
331335
@Setter
332336
private int tcpNettyWorkThreadNum;
@@ -465,6 +469,7 @@ public static void clearParam() {
465469
INSTANCE.allowCreationOfContracts = 0;
466470
INSTANCE.allowAdaptiveEnergy = 0;
467471
INSTANCE.allowTvmTransferTrc10 = 0;
472+
INSTANCE.improveTransferTrc10Security = 0;
468473
INSTANCE.allowDelegateResource = 0;
469474
INSTANCE.allowSameTokenName = 0;
470475
INSTANCE.tcpNettyWorkThreadNum = 0;
@@ -784,6 +789,10 @@ public static void setParam(final String[] args, final String confFileName) {
784789
config.hasPath("committee.allowTvmTransferTrc10") ? config
785790
.getInt("committee.allowTvmTransferTrc10") : 0;
786791

792+
INSTANCE.improveTransferTrc10Security =
793+
config.hasPath("committee.improveTransferTrc10Security") ? config
794+
.getInt("committee.improveTransferTrc10Security") : 0;
795+
787796
INSTANCE.tcpNettyWorkThreadNum = config.hasPath("node.tcpNettyWorkThreadNum") ? config
788797
.getInt("node.tcpNettyWorkThreadNum") : 0;
789798

‎src/main/java/org/tron/core/db/DynamicPropertiesStore.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ private static class DynamicResourceProperties {
158158
private static final byte[] AVAILABLE_CONTRACT_TYPE = "AVAILABLE_CONTRACT_TYPE".getBytes();
159159
private static final byte[] ACTIVE_DEFAULT_OPERATIONS = "ACTIVE_DEFAULT_OPERATIONS".getBytes();
160160

161+
private static final byte[] IMPROVE_TRANSFER_TRC10_SECURITY = "IMPROVE_TRANSFER_TRC10_SECURITY".getBytes();
162+
161163

162164
@Autowired
163165
private DynamicPropertiesStore(@Value("properties") String dbName) {
@@ -469,6 +471,12 @@ private DynamicPropertiesStore(@Value("properties") String dbName) {
469471
this.saveAllowTvmTransferTrc10(Args.getInstance().getAllowTvmTransferTrc10());
470472
}
471473

474+
try {
475+
this.getImproveTransferTrc10Security();
476+
} catch (IllegalArgumentException e) {
477+
this.saveImproveTransferTrc10Security(Args.getInstance().getImproveTransferTrc10Security());
478+
}
479+
472480
try {
473481
this.getAvailableContractType();
474482
} catch (IllegalArgumentException e) {
@@ -1206,6 +1214,19 @@ public long getAllowTvmTransferTrc10() {
12061214
() -> new IllegalArgumentException("not found ALLOW_TVM_TRANSFER_TRC10"));
12071215
}
12081216

1217+
public void saveImproveTransferTrc10Security(long value) {
1218+
this.put(IMPROVE_TRANSFER_TRC10_SECURITY,
1219+
new BytesCapsule(ByteArray.fromLong(value)));
1220+
}
1221+
1222+
public long getImproveTransferTrc10Security() {
1223+
return Optional.ofNullable(getUnchecked(IMPROVE_TRANSFER_TRC10_SECURITY))
1224+
.map(BytesCapsule::getData)
1225+
.map(ByteArray::toLong)
1226+
.orElseThrow(
1227+
() -> new IllegalArgumentException("not found IMPROVE_TRANSFER_TRC10_SECURITY"));
1228+
}
1229+
12091230
public void saveAvailableContractType(byte[] value) {
12101231
this.put(AVAILABLE_CONTRACT_TYPE,
12111232
new BytesCapsule(value));

‎src/main/java/org/tron/core/db/Manager.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@ public boolean processTransaction(final TransactionCapsule trxCap, BlockCapsule
11911191
consumeBandwidth(trxCap, trace);
11921192

11931193
VMConfig.initVmHardFork();
1194+
VMConfig.initImproveTransferTrc10Security(dynamicPropertiesStore.getImproveTransferTrc10Security());
11941195
VMConfig.initAllowTvmTransferTrc10(dynamicPropertiesStore.getAllowTvmTransferTrc10());
11951196
trace.init(blockCap, eventPluginLoaded);
11961197
trace.checkIsConstant();

0 commit comments

Comments
 (0)