Skip to content

Commit a8fa3d4

Browse files
committed
fix(vm): correct osaka proposal id, default config and modexp behavior
1. Change ALLOW_TVM_OSAKA proposal id from 95 to 96 2. DynamicPropertiesStore.getAllowTvmOsaka() defaults to CommonParameter 3. ModExp returns Pair.of(false, EMPTY_BYTE_ARRAY) instead of throwing PrecompiledContractException when inputs exceed 1024 bytes, matching geth/besu behavior where only the CALL fails (not the whole tx) 4. Update test to verify return value instead of catching exception
1 parent 708c9b1 commit a8fa3d4

5 files changed

Lines changed: 18 additions & 26 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ public enum ProposalType { // current value, value range
971971
ALLOW_TVM_BLOB(89), // 0, 1
972972
PROPOSAL_EXPIRE_TIME(92), // (0, 31536003000)
973973
ALLOW_TVM_SELFDESTRUCT_RESTRICTION(94), // 0, 1
974-
ALLOW_TVM_OSAKA(95); // 0, 1
974+
ALLOW_TVM_OSAKA(96); // 0, 1
975975

976976
private long code;
977977

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import org.tron.core.capsule.TransactionCapsule;
6666
import org.tron.core.capsule.WitnessCapsule;
6767
import org.tron.core.db.TransactionTrace;
68-
import org.tron.core.exception.TronException;
6968
import org.tron.core.exception.ZksnarkException;
7069
import org.tron.core.vm.config.VMConfig;
7170
import org.tron.core.vm.program.Program;
@@ -663,10 +662,9 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
663662
int expLen = parseLen(data, 1);
664663
int modLen = parseLen(data, 2);
665664

666-
if (VMConfig.allowTvmOsaka() &&
667-
(baseLen > UPPER_BOUND || expLen > UPPER_BOUND || modLen > UPPER_BOUND)) {
668-
throw Program.Exception.contractExecuteException(
669-
new TronException("one or more of base/exponent/modulus length exceeded 1024 bytes"));
665+
if (VMConfig.allowTvmOsaka()
666+
&& (baseLen > UPPER_BOUND || expLen > UPPER_BOUND || modLen > UPPER_BOUND)) {
667+
return Pair.of(false, EMPTY_BYTE_ARRAY);
670668
}
671669

672670
BigInteger base = parseArg(data, ARGS_OFFSET, baseLen);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2986,7 +2986,7 @@ public long getAllowTvmOsaka() {
29862986
return Optional.ofNullable(getUnchecked(ALLOW_TVM_OSAKA))
29872987
.map(BytesCapsule::getData)
29882988
.map(ByteArray::toLong)
2989-
.orElse(0L);
2989+
.orElse(CommonParameter.getInstance().getAllowTvmOsaka());
29902990
}
29912991

29922992
public void saveAllowTvmOsaka(long value) {

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";
Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package org.tron.common.runtime.vm;
22

33
import lombok.extern.slf4j.Slf4j;
4+
import org.apache.commons.lang3.tuple.Pair;
45
import org.junit.Assert;
56
import org.junit.Test;
67
import org.tron.common.utils.ByteUtil;
78
import org.tron.core.vm.PrecompiledContracts;
89
import org.tron.core.vm.config.ConfigLoader;
910
import org.tron.core.vm.config.VMConfig;
10-
import org.tron.core.vm.program.Program;
1111

1212
@Slf4j
1313
public class AllowTvmOsakaTest extends VMTestBase {
@@ -17,31 +17,24 @@ public void testEIP7823() {
1717
ConfigLoader.disable = true;
1818
VMConfig.initAllowTvmOsaka(1);
1919

20-
byte[] baseLen = new byte[32];
21-
byte[] expLen = new byte[32];
22-
byte[] modLen = new byte[32];
20+
try {
21+
byte[] baseLen = new byte[32];
22+
byte[] expLen = new byte[32];
23+
byte[] modLen = new byte[32];
2324

24-
PrecompiledContracts.PrecompiledContract modExp = new PrecompiledContracts.ModExp();
25+
PrecompiledContracts.PrecompiledContract modExp = new PrecompiledContracts.ModExp();
2526

26-
// Valid lens
27-
try {
28-
modExp.execute(ByteUtil.merge(baseLen, expLen, modLen));
29-
} catch (Exception e) {
30-
Assert.fail();
31-
}
27+
// Valid lens: all zeros (0 <= 1024)
28+
Pair<Boolean, byte[]> result = modExp.execute(ByteUtil.merge(baseLen, expLen, modLen));
29+
Assert.assertTrue(result.getLeft());
3230

33-
// Invalid lens
34-
try {
31+
// Invalid lens: baseLen = 0x01000000... = 16777216 > 1024
3532
baseLen[0] = 0x01;
36-
modExp.execute(ByteUtil.merge(baseLen, expLen, modLen));
37-
} catch (Exception e) {
38-
Assert.assertTrue(e instanceof Program.PrecompiledContractException);
39-
return;
33+
result = modExp.execute(ByteUtil.merge(baseLen, expLen, modLen));
34+
Assert.assertFalse(result.getLeft());
4035
} finally {
4136
VMConfig.initAllowTvmOsaka(0);
4237
ConfigLoader.disable = false;
4338
}
44-
45-
Assert.fail();
4639
}
4740
}

0 commit comments

Comments
 (0)