Skip to content

Commit bb8b4be

Browse files
authored
Merge pull request #6611 from ouy95917/implement-eip-7823
feat(vm): implement TIP-7823
2 parents 0ebf4c3 + 0663e17 commit bb8b4be

13 files changed

Lines changed: 147 additions & 3 deletions

File tree

actuator/src/main/java/org/tron/core/utils/ProposalUtil.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,21 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
871871
}
872872
break;
873873
}
874+
case ALLOW_TVM_OSAKA: {
875+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_2)) {
876+
throw new ContractValidateException(
877+
"Bad chain parameter id [ALLOW_TVM_OSAKA]");
878+
}
879+
if (dynamicPropertiesStore.getAllowTvmOsaka() == 1) {
880+
throw new ContractValidateException(
881+
"[ALLOW_TVM_OSAKA] has been valid, no need to propose again");
882+
}
883+
if (value != 1) {
884+
throw new ContractValidateException(
885+
"This value[ALLOW_TVM_OSAKA] is only allowed to be 1");
886+
}
887+
break;
888+
}
874889
default:
875890
break;
876891
}
@@ -955,7 +970,8 @@ public enum ProposalType { // current value, value range
955970
CONSENSUS_LOGIC_OPTIMIZATION(88), // 0, 1
956971
ALLOW_TVM_BLOB(89), // 0, 1
957972
PROPOSAL_EXPIRE_TIME(92), // (0, 31536003000)
958-
ALLOW_TVM_SELFDESTRUCT_RESTRICTION(94); // 0, 1
973+
ALLOW_TVM_SELFDESTRUCT_RESTRICTION(94), // 0, 1
974+
ALLOW_TVM_OSAKA(96); // 0, 1
959975

960976
private long code;
961977

actuator/src/main/java/org/tron/core/vm/PrecompiledContracts.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ public static class ModExp extends PrecompiledContract {
622622

623623
private static final int ARGS_OFFSET = 32 * 3; // addresses length part
624624

625+
private static final int UPPER_BOUND = 1024;
626+
625627
@Override
626628
public long getEnergyForData(byte[] data) {
627629

@@ -660,6 +662,11 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
660662
int expLen = parseLen(data, 1);
661663
int modLen = parseLen(data, 2);
662664

665+
if (VMConfig.allowTvmOsaka()
666+
&& (baseLen > UPPER_BOUND || expLen > UPPER_BOUND || modLen > UPPER_BOUND)) {
667+
return Pair.of(false, EMPTY_BYTE_ARRAY);
668+
}
669+
663670
BigInteger base = parseArg(data, ARGS_OFFSET, baseLen);
664671
BigInteger exp = parseArg(data, addSafely(ARGS_OFFSET, baseLen), expLen);
665672
BigInteger mod = parseArg(data, addSafely(addSafely(ARGS_OFFSET, baseLen), expLen), modLen);

actuator/src/main/java/org/tron/core/vm/config/ConfigLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static void load(StoreFactory storeFactory) {
4545
VMConfig.initDisableJavaLangMath(ds.getConsensusLogicOptimization());
4646
VMConfig.initAllowTvmBlob(ds.getAllowTvmBlob());
4747
VMConfig.initAllowTvmSelfdestructRestriction(ds.getAllowTvmSelfdestructRestriction());
48+
VMConfig.initAllowTvmOsaka(ds.getAllowTvmOsaka());
4849
}
4950
}
5051
}

chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
238238
private static final byte[] ALLOW_TVM_SELFDESTRUCT_RESTRICTION =
239239
"ALLOW_TVM_SELFDESTRUCT_RESTRICTION".getBytes();
240240

241+
private static final byte[] ALLOW_TVM_OSAKA = "ALLOW_TVM_OSAKA".getBytes();
242+
241243
@Autowired
242244
private DynamicPropertiesStore(@Value("properties") String dbName) {
243245
super(dbName);
@@ -2980,6 +2982,17 @@ public long getProposalExpireTime() {
29802982
.orElse(CommonParameter.getInstance().getProposalExpireTime());
29812983
}
29822984

2985+
public long getAllowTvmOsaka() {
2986+
return Optional.ofNullable(getUnchecked(ALLOW_TVM_OSAKA))
2987+
.map(BytesCapsule::getData)
2988+
.map(ByteArray::toLong)
2989+
.orElse(CommonParameter.getInstance().getAllowTvmOsaka());
2990+
}
2991+
2992+
public void saveAllowTvmOsaka(long value) {
2993+
this.put(ALLOW_TVM_OSAKA, new BytesCapsule(ByteArray.fromLong(value)));
2994+
}
2995+
29832996
private static class DynamicResourceProperties {
29842997

29852998
private static final byte[] ONE_DAY_NET_LIMIT = "ONE_DAY_NET_LIMIT".getBytes();

common/src/main/java/org/tron/common/parameter/CommonParameter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,10 @@ public class CommonParameter {
633633
@Setter
634634
public long allowTvmBlob;
635635

636+
@Getter
637+
@Setter
638+
public long allowTvmOsaka;
639+
636640
private static double calcMaxTimeRatio() {
637641
return 5.0;
638642
}

common/src/main/java/org/tron/core/config/Parameter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public enum ForkBlockVersionEnum {
2828
VERSION_4_7_7(31, 1596780000000L, 80),
2929
VERSION_4_8_0(32, 1596780000000L, 80),
3030
VERSION_4_8_0_1(33, 1596780000000L, 70),
31-
VERSION_4_8_1(34, 1596780000000L, 80);
31+
VERSION_4_8_1(34, 1596780000000L, 80),
32+
VERSION_4_8_2(35, 1596780000000L, 80);
3233
// if add a version, modify BLOCK_VERSION simultaneously
3334

3435
@Getter
@@ -77,7 +78,7 @@ public class ChainConstant {
7778
public static final int SINGLE_REPEAT = 1;
7879
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
7980
public static final int MAX_FROZEN_NUMBER = 1;
80-
public static final int BLOCK_VERSION = 34;
81+
public static final int BLOCK_VERSION = 35;
8182
public static final long FROZEN_PERIOD = 86_400_000L;
8283
public static final long DELEGATE_PERIOD = 3 * 86_400_000L;
8384
public static final long TRX_PRECISION = 1000_000L;

common/src/main/java/org/tron/core/vm/config/VMConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public class VMConfig {
6161

6262
private static boolean ALLOW_TVM_SELFDESTRUCT_RESTRICTION = false;
6363

64+
private static boolean ALLOW_TVM_OSAKA = false;
65+
6466
private VMConfig() {
6567
}
6668

@@ -172,6 +174,10 @@ public static void initAllowTvmSelfdestructRestriction(long allow) {
172174
ALLOW_TVM_SELFDESTRUCT_RESTRICTION = allow == 1;
173175
}
174176

177+
public static void initAllowTvmOsaka(long allow) {
178+
ALLOW_TVM_OSAKA = allow == 1;
179+
}
180+
175181
public static boolean getEnergyLimitHardFork() {
176182
return CommonParameter.ENERGY_LIMIT_HARD_FORK;
177183
}
@@ -271,4 +277,8 @@ public static boolean allowTvmBlob() {
271277
public static boolean allowTvmSelfdestructRestriction() {
272278
return ALLOW_TVM_SELFDESTRUCT_RESTRICTION;
273279
}
280+
281+
public static boolean allowTvmOsaka() {
282+
return ALLOW_TVM_OSAKA;
283+
}
274284
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,11 @@ public Protocol.ChainParameters getChainParameters() {
15091509
.setValue(dbManager.getDynamicPropertiesStore().getProposalExpireTime())
15101510
.build());
15111511

1512+
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
1513+
.setKey("getAllowTvmOsaka")
1514+
.setValue(dbManager.getDynamicPropertiesStore().getAllowTvmOsaka())
1515+
.build());
1516+
15121517
return builder.build();
15131518
}
15141519

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,10 @@ public static void applyConfigParams(
10371037
config.hasPath(ConfigKey.COMMITTEE_ALLOW_TVM_BLOB) ? config
10381038
.getInt(ConfigKey.COMMITTEE_ALLOW_TVM_BLOB) : 0;
10391039

1040+
PARAMETER.allowTvmOsaka =
1041+
config.hasPath(ConfigKey.COMMITTEE_ALLOW_TVM_OSAKA) ? config
1042+
.getInt(ConfigKey.COMMITTEE_ALLOW_TVM_OSAKA) : 0;
1043+
10401044
logConfig();
10411045
}
10421046

framework/src/main/java/org/tron/core/config/args/ConfigKey.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ private ConfigKey() {
247247
public static final String COMMITTEE_ALLOW_TVM_CANCUN = "committee.allowTvmCancun";
248248
public static final String COMMITTEE_ALLOW_TVM_BLOB = "committee.allowTvmBlob";
249249
public static final String COMMITTEE_PROPOSAL_EXPIRE_TIME = "committee.proposalExpireTime";
250+
public static final String COMMITTEE_ALLOW_TVM_OSAKA = "committee.allowTvmOsaka";
250251
public static final String ALLOW_ACCOUNT_ASSET_OPTIMIZATION =
251252
"committee.allowAccountAssetOptimization";
252253
public static final String ALLOW_ASSET_OPTIMIZATION = "committee.allowAssetOptimization";

0 commit comments

Comments
 (0)