Skip to content

Commit 0a2fb53

Browse files
committed
feat(tvm): add allowTvmBlob proposal for TVM blob related ops and precompiles
1 parent a30a3b7 commit 0a2fb53

15 files changed

Lines changed: 74 additions & 12 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
@@ -824,6 +824,21 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
824824
}
825825
break;
826826
}
827+
case ALLOW_TVM_BLOB: {
828+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_0)) {
829+
throw new ContractValidateException(
830+
"Bad chain parameter id [ALLOW_TVM_BLOB]");
831+
}
832+
if (dynamicPropertiesStore.getAllowTvmBlob() == 1) {
833+
throw new ContractValidateException(
834+
"[ALLOW_TVM_BLOB] has been valid, no need to propose again");
835+
}
836+
if (value != 1) {
837+
throw new ContractValidateException(
838+
"This value[ALLOW_TVM_BLOB] is only allowed to be 1");
839+
}
840+
break;
841+
}
827842
default:
828843
break;
829844
}
@@ -905,7 +920,8 @@ public enum ProposalType { // current value, value range
905920
MAX_CREATE_ACCOUNT_TX_SIZE(82), // [500, 10000]
906921
ALLOW_TVM_CANCUN(83), // 0, 1
907922
ALLOW_STRICT_MATH(87), // 0, 1
908-
CONSENSUS_LOGIC_OPTIMIZATION(88); // 0, 1
923+
CONSENSUS_LOGIC_OPTIMIZATION(88), // 0, 1
924+
ALLOW_TVM_BLOB(89); // 0, 1
909925

910926
private long code;
911927

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public class Op {
121121
// (0x48) Get block's basefee
122122
public static final int BASEFEE = 0x48;
123123
// (0x49) Get blob hash
124-
public static final int BLOBAHASH = 0x49;
124+
public static final int BLOBHASH = 0x49;
125125
// (0x4a) Get block's blob basefee
126126
public static final int BLOBBASEFEE = 0x4a;
127127

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ public static void mCopyAction(Program program) {
678678
}
679679

680680
public static void blobHashAction(Program program) {
681+
program.stackPop();
681682
program.stackPush(DataWord.ZERO());
682683
program.step();
683684
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ public static void adjustForFairEnergy(JumpTable table) {
663663

664664
public static void appendCancunOperations(JumpTable table) {
665665
BooleanSupplier proposal = VMConfig::allowTvmCancun;
666+
BooleanSupplier tvmBlobProposal = VMConfig::allowTvmBlob;
666667

667668
table.set(new Operation(
668669
Op.TLOAD, 1, 1,
@@ -683,15 +684,15 @@ public static void appendCancunOperations(JumpTable table) {
683684
proposal));
684685

685686
table.set(new Operation(
686-
Op.BLOBAHASH, 1, 1,
687+
Op.BLOBHASH, 1, 1,
687688
EnergyCost::getVeryLowTierCost,
688689
OperationActions::blobHashAction,
689-
proposal));
690+
tvmBlobProposal));
690691

691692
table.set(new Operation(
692693
Op.BLOBBASEFEE, 0, 1,
693694
EnergyCost::getBaseTierCost,
694695
OperationActions::blobBaseFeeAction,
695-
proposal));
696+
tvmBlobProposal));
696697
}
697698
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public static PrecompiledContract getContractForAddress(DataWord address) {
285285
if (VMConfig.allowTvmCompatibleEvm() && address.equals(blake2FAddr)) {
286286
return blake2F;
287287
}
288-
if (VMConfig.allowTvmCancun() && address.equals(kzgPointEvaluationAddr)) {
288+
if (VMConfig.allowTvmBlob() && address.equals(kzgPointEvaluationAddr)) {
289289
return kzgPointEvaluation;
290290
}
291291

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
@@ -43,6 +43,7 @@ public static void load(StoreFactory storeFactory) {
4343
VMConfig.initAllowStrictMath(ds.getAllowStrictMath());
4444
VMConfig.initAllowTvmCancun(ds.getAllowTvmCancun());
4545
VMConfig.initDisableJavaLangMath(ds.getConsensusLogicOptimization());
46+
VMConfig.initAllowTvmBlob(ds.getAllowTvmBlob());
4647
}
4748
}
4849
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
230230

231231
private static final byte[] ALLOW_TVM_CANCUN = "ALLOW_TVM_CANCUN".getBytes();
232232

233+
private static final byte[] ALLOW_TVM_BLOB = "ALLOW_TVM_BLOB".getBytes();
234+
233235
@Autowired
234236
private DynamicPropertiesStore(@Value("properties") String dbName) {
235237
super(dbName);
@@ -2933,6 +2935,17 @@ public long getAllowTvmCancun() {
29332935
.orElse(CommonParameter.getInstance().getAllowTvmCancun());
29342936
}
29352937

2938+
public void saveAllowTvmBlob(long allowTvmBlob) {
2939+
this.put(ALLOW_TVM_BLOB, new BytesCapsule(ByteArray.fromLong(allowTvmBlob)));
2940+
}
2941+
2942+
public long getAllowTvmBlob() {
2943+
return Optional.ofNullable(getUnchecked(ALLOW_TVM_BLOB))
2944+
.map(BytesCapsule::getData)
2945+
.map(ByteArray::toLong)
2946+
.orElse(CommonParameter.getInstance().getAllowTvmBlob());
2947+
}
2948+
29362949
private static class DynamicResourceProperties {
29372950

29382951
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
@@ -713,6 +713,10 @@ public class CommonParameter {
713713
@Setter
714714
public long allowTvmCancun;
715715

716+
@Getter
717+
@Setter
718+
public long allowTvmBlob;
719+
716720
private static double calcMaxTimeRatio() {
717721
//return max(2.0, min(5.0, 5 * 4.0 / max(Runtime.getRuntime().availableProcessors(), 1)));
718722
return 5.0;

common/src/main/java/org/tron/core/Constant.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,6 @@ public class Constant {
401401
= "committee.consensusLogicOptimization";
402402

403403
public static final String COMMITTEE_ALLOW_TVM_CANCUN = "committee.allowTvmCancun";
404+
405+
public static final String COMMITTEE_ALLOW_TVM_BLOB = "committee.allowTvmBlob";
404406
}

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
@@ -57,6 +57,8 @@ public class VMConfig {
5757

5858
private static Boolean DISABLE_JAVA_LANG_MATH = false;
5959

60+
private static boolean ALLOW_TVM_BLOB = false;
61+
6062
private VMConfig() {
6163
}
6264

@@ -160,6 +162,10 @@ public static void initDisableJavaLangMath(long allow) {
160162
DISABLE_JAVA_LANG_MATH = allow == 1;
161163
}
162164

165+
public static void initAllowTvmBlob(long allow) {
166+
ALLOW_TVM_BLOB = allow == 1;
167+
}
168+
163169
public static boolean getEnergyLimitHardFork() {
164170
return CommonParameter.ENERGY_LIMIT_HARD_FORK;
165171
}
@@ -251,4 +257,8 @@ public static boolean allowTvmCancun() {
251257
public static boolean disableJavaLangMath() {
252258
return DISABLE_JAVA_LANG_MATH;
253259
}
260+
261+
public static boolean allowTvmBlob() {
262+
return ALLOW_TVM_BLOB;
263+
}
254264
}

0 commit comments

Comments
 (0)