Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,21 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}
break;
}
case ALLOW_TVM_OSAKA: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_2)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_TVM_OSAKA]");
}
if (dynamicPropertiesStore.getAllowTvmOsaka() == 1) {
throw new ContractValidateException(
"[ALLOW_TVM_OSAKA] has been valid, no need to propose again");
}
if (value != 1) {
throw new ContractValidateException(
"This value[ALLOW_TVM_OSAKA] is only allowed to be 1");
}
break;
}
default:
break;
}
Expand Down Expand Up @@ -955,7 +970,8 @@ public enum ProposalType { // current value, value range
CONSENSUS_LOGIC_OPTIMIZATION(88), // 0, 1
ALLOW_TVM_BLOB(89), // 0, 1
PROPOSAL_EXPIRE_TIME(92), // (0, 31536003000)
ALLOW_TVM_SELFDESTRUCT_RESTRICTION(94); // 0, 1
ALLOW_TVM_SELFDESTRUCT_RESTRICTION(94), // 0, 1
ALLOW_TVM_OSAKA(95); // 0, 1

private long code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.tron.core.capsule.TransactionCapsule;
import org.tron.core.capsule.WitnessCapsule;
import org.tron.core.db.TransactionTrace;
import org.tron.core.exception.TronException;
import org.tron.core.exception.ZksnarkException;
import org.tron.core.vm.config.VMConfig;
import org.tron.core.vm.program.Program;
Expand Down Expand Up @@ -622,6 +623,8 @@ public static class ModExp extends PrecompiledContract {

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

private static final int UPPER_BOUND = 1024;

@Override
public long getEnergyForData(byte[] data) {

Expand Down Expand Up @@ -660,6 +663,12 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
int expLen = parseLen(data, 1);
int modLen = parseLen(data, 2);

if (VMConfig.allowTvmOsaka() &&
(baseLen > UPPER_BOUND || expLen > UPPER_BOUND || modLen > UPPER_BOUND)) {
throw Program.Exception.contractExecuteException(
new TronException("one or more of base/exponent/modulus length exceeded 1024 bytes"));
}

BigInteger base = parseArg(data, ARGS_OFFSET, baseLen);
BigInteger exp = parseArg(data, addSafely(ARGS_OFFSET, baseLen), expLen);
BigInteger mod = parseArg(data, addSafely(addSafely(ARGS_OFFSET, baseLen), expLen), modLen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void load(StoreFactory storeFactory) {
VMConfig.initDisableJavaLangMath(ds.getConsensusLogicOptimization());
VMConfig.initAllowTvmBlob(ds.getAllowTvmBlob());
VMConfig.initAllowTvmSelfdestructRestriction(ds.getAllowTvmSelfdestructRestriction());
VMConfig.initAllowTvmOsaka(ds.getAllowTvmOsaka());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
private static final byte[] ALLOW_TVM_SELFDESTRUCT_RESTRICTION =
"ALLOW_TVM_SELFDESTRUCT_RESTRICTION".getBytes();

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

@Autowired
private DynamicPropertiesStore(@Value("properties") String dbName) {
super(dbName);
Expand Down Expand Up @@ -2980,6 +2982,17 @@ public long getProposalExpireTime() {
.orElse(CommonParameter.getInstance().getProposalExpireTime());
}

public long getAllowTvmOsaka() {
return Optional.ofNullable(getUnchecked(ALLOW_TVM_OSAKA))
.map(BytesCapsule::getData)
.map(ByteArray::toLong)
.orElse(0L);
}

public void saveAllowTvmOsaka(long value) {
this.put(ALLOW_TVM_OSAKA, new BytesCapsule(ByteArray.fromLong(value)));
}

private static class DynamicResourceProperties {

private static final byte[] ONE_DAY_NET_LIMIT = "ONE_DAY_NET_LIMIT".getBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,10 @@ public class CommonParameter {
@Setter
public long allowTvmBlob;

@Getter
@Setter
public long allowTvmOsaka;

private static double calcMaxTimeRatio() {
//return max(2.0, min(5.0, 5 * 4.0 / max(Runtime.getRuntime().availableProcessors(), 1)));
return 5.0;
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/org/tron/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,6 @@ public class Constant {

public static final String COMMITTEE_PROPOSAL_EXPIRE_TIME = "committee.proposalExpireTime";

public static final String COMMITTEE_ALLOW_TVM_OSAKA = "committee.allowTvmOsaka";

}
5 changes: 3 additions & 2 deletions common/src/main/java/org/tron/core/config/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public enum ForkBlockVersionEnum {
VERSION_4_7_7(31, 1596780000000L, 80),
VERSION_4_8_0(32, 1596780000000L, 80),
VERSION_4_8_0_1(33, 1596780000000L, 70),
VERSION_4_8_1(34, 1596780000000L, 80);
VERSION_4_8_1(34, 1596780000000L, 80),
VERSION_4_8_2(35, 1596780000000L, 80);
// if add a version, modify BLOCK_VERSION simultaneously

@Getter
Expand Down Expand Up @@ -77,7 +78,7 @@ public class ChainConstant {
public static final int SINGLE_REPEAT = 1;
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
public static final int MAX_FROZEN_NUMBER = 1;
public static final int BLOCK_VERSION = 34;
public static final int BLOCK_VERSION = 35;
public static final long FROZEN_PERIOD = 86_400_000L;
public static final long DELEGATE_PERIOD = 3 * 86_400_000L;
public static final long TRX_PRECISION = 1000_000L;
Expand Down
10 changes: 10 additions & 0 deletions common/src/main/java/org/tron/core/vm/config/VMConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class VMConfig {

private static boolean ALLOW_TVM_SELFDESTRUCT_RESTRICTION = false;

private static boolean ALLOW_TVM_OSAKA = false;

private VMConfig() {
}

Expand Down Expand Up @@ -172,6 +174,10 @@ public static void initAllowTvmSelfdestructRestriction(long allow) {
ALLOW_TVM_SELFDESTRUCT_RESTRICTION = allow == 1;
}

public static void initAllowTvmOsaka(long allow) {
ALLOW_TVM_OSAKA = allow == 1;
}

public static boolean getEnergyLimitHardFork() {
return CommonParameter.ENERGY_LIMIT_HARD_FORK;
}
Expand Down Expand Up @@ -271,4 +277,8 @@ public static boolean allowTvmBlob() {
public static boolean allowTvmSelfdestructRestriction() {
return ALLOW_TVM_SELFDESTRUCT_RESTRICTION;
}

public static boolean allowTvmOsaka() {
return ALLOW_TVM_OSAKA;
}
}
5 changes: 5 additions & 0 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,11 @@ public Protocol.ChainParameters getChainParameters() {
.setValue(dbManager.getDynamicPropertiesStore().getProposalExpireTime())
.build());

builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
.setKey("getAllowTvmOsaka")
.setValue(dbManager.getDynamicPropertiesStore().getAllowTvmOsaka())
.build());

return builder.build();
}

Expand Down
5 changes: 5 additions & 0 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public static void clearParam() {
PARAMETER.allowTvmBlob = 0;
PARAMETER.rpcMaxRstStream = 0;
PARAMETER.rpcSecondsPerWindow = 0;
PARAMETER.allowTvmOsaka = 0;
}

/**
Expand Down Expand Up @@ -1289,6 +1290,10 @@ public static void setParam(final Config config) {
config.hasPath(Constant.COMMITTEE_ALLOW_TVM_BLOB) ? config
.getInt(Constant.COMMITTEE_ALLOW_TVM_BLOB) : 0;

PARAMETER.allowTvmOsaka =
config.hasPath(Constant.COMMITTEE_ALLOW_TVM_OSAKA) ? config
.getInt(Constant.COMMITTEE_ALLOW_TVM_OSAKA) : 0;

logConfig();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
manager.getDynamicPropertiesStore().saveProposalExpireTime(entry.getValue());
break;
}
case ALLOW_TVM_OSAKA: {
manager.getDynamicPropertiesStore().saveAllowTvmOsaka(entry.getValue());
break;
}
default:
find = false;
break;
Expand Down
1 change: 1 addition & 0 deletions framework/src/main/resources/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ committee = {
# allowTvmBlob = 0
# consensusLogicOptimization = 0
# allowOptimizedReturnValueOfChainId = 0
# allowTvmOsaka = 0
}

event.subscribe = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.tron.common.runtime.vm;

import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;
import org.tron.common.utils.ByteUtil;
import org.tron.core.vm.PrecompiledContracts;
import org.tron.core.vm.config.ConfigLoader;
import org.tron.core.vm.config.VMConfig;
import org.tron.core.vm.program.Program;

@Slf4j
public class AllowTvmOsakaTest extends VMTestBase {

@Test
public void testEIP7823() {
ConfigLoader.disable = true;
VMConfig.initAllowTvmOsaka(1);

byte[] baseLen = new byte[32];
byte[] expLen = new byte[32];
byte[] modLen = new byte[32];

PrecompiledContracts.PrecompiledContract modExp = new PrecompiledContracts.ModExp();

// Valid lens
try {
modExp.execute(ByteUtil.merge(baseLen, expLen, modLen));
} catch (Exception e) {
Assert.fail();
}

// Invalid lens
try {
baseLen[0] = 0x01;
modExp.execute(ByteUtil.merge(baseLen, expLen, modLen));
} catch (Exception e) {
Assert.assertTrue(e instanceof Program.PrecompiledContractException);
return;
} finally {
VMConfig.initAllowTvmOsaka(0);
ConfigLoader.disable = false;
}

Assert.fail();
}
}