Skip to content

Commit 4e80f8f

Browse files
halibobo1205kuny0707zz
authored
feat(version): merge master to 4.8.2 (tronprotocol#6817)
* feat(*): disable exchange transaction (tronprotocol#6507) * update a new version. version name:GreatVoyage-v4.8.0-1-g45e3bf88ca,version code:18634 (tronprotocol#6508) * Merge release_v4.8.1 to master (tronprotocol#6541) * update a new version. version name:GreatVoyage-v4.8.0.1-1-g44a4bc8263,version code:18636 (tronprotocol#6542) * feat(vm): optimize the check for create2 * feat(vm): optimize the check for ModExp * test(vm): add tests for create2/modExp checks * feat(version): update version to 4.8.1.1 * feat(ci): add PR pipeline and system-test workflows New workflows: - pr-build.yml: multi-OS build matrix (macOS, Ubuntu, RockyLinux, Debian11) and changed-line/overall coverage gate - pr-check.yml: PR title/body lint + Checkstyle - pr-reviewer.yml: scope-based reviewer auto-assignment - pr-cancel.yml: cancel in-progress runs when PR is closed unmerged - system-test.yml: spin up FullNode and run the system-test suite Existing workflows: - codeql.yml: bump to v4/v5 actions, switch to manual build-mode with JDK 8, add paths-ignore for docs-only changes - math-check.yml: bump checkout/upload-artifact/github-script versions * feat(config): fix git.properties NPE * update a new version. version name:GreatVoyage-v4.8.1-6-g52d7d9d23e,version code:18643 --------- Co-authored-by: YAaron <4241080+kuny0707@users.noreply.github.com> Co-authored-by: zz <aaa@bb.cc>
1 parent ba5b012 commit 4e80f8f

6 files changed

Lines changed: 202 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,10 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
699699
return Pair.of(false, EMPTY_BYTE_ARRAY);
700700
}
701701

702+
if (baseLen == 0 && modLen == 0 && expLen > UPPER_BOUND) {
703+
MUtil.checkCPUTimeForModExp();
704+
}
705+
702706
BigInteger base = parseArg(data, ARGS_OFFSET, baseLen);
703707
BigInteger exp = parseArg(data, addSafely(ARGS_OFFSET, baseLen), expLen);
704708
BigInteger mod = parseArg(data, addSafely(addSafely(ARGS_OFFSET, baseLen), expLen), modLen);

actuator/src/main/java/org/tron/core/vm/program/Program.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,9 @@ public void createContract2(DataWord value, DataWord memStart, DataWord memSize,
16251625
stackPushZero();
16261626
return;
16271627
}
1628+
if (getCallDeep() == MAX_DEPTH) {
1629+
MUtil.checkCPUTimeForCreate2();
1630+
}
16281631
if (VMConfig.allowTvmIstanbul()) {
16291632
senderAddress = getContextAddress();
16301633
} else {

actuator/src/main/java/org/tron/core/vm/utils/MUtil.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,16 @@ public static void checkCPUTime() {
6464
throw new OutOfTimeException("CPU timeout for 0x0a executing");
6565
}
6666
}
67+
68+
public static void checkCPUTimeForCreate2() {
69+
if (ForkController.instance().pass(Parameter.ForkBlockVersionEnum.VERSION_4_8_1_1)) {
70+
throw new OutOfTimeException("CPU timeout for create2 executing");
71+
}
72+
}
73+
74+
public static void checkCPUTimeForModExp() {
75+
if (ForkController.instance().pass(Parameter.ForkBlockVersionEnum.VERSION_4_8_1_1)) {
76+
throw new OutOfTimeException("CPU timeout for modExp executing");
77+
}
78+
}
6779
}

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

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

3536
@Getter
@@ -78,7 +79,7 @@ public class ChainConstant {
7879
public static final int SINGLE_REPEAT = 1;
7980
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
8081
public static final int MAX_FROZEN_NUMBER = 1;
81-
public static final int BLOCK_VERSION = 35;
82+
public static final int BLOCK_VERSION = 36;
8283
public static final long FROZEN_PERIOD = 86_400_000L;
8384
public static final long DELEGATE_PERIOD = 3 * 86_400_000L;
8485
public static final long TRX_PRECISION = 1000_000L;

framework/src/main/java/org/tron/program/Version.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
public class Version {
44

5-
public static final String VERSION_NAME = "GreatVoyage-v4.8.0.1-1-g44a4bc8263";
6-
public static final String VERSION_CODE = "18636";
5+
public static final String VERSION_NAME = "GreatVoyage-v4.8.1-6-g52d7d9d23e";
6+
public static final String VERSION_CODE = "18643";
77
private static final String VERSION = "4.8.2";
88

99
public static String getVersion() {
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
package org.tron.common.runtime.vm;
2+
3+
import java.util.Arrays;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.apache.commons.lang3.tuple.Pair;
6+
import org.junit.AfterClass;
7+
import org.junit.Assert;
8+
import org.junit.Before;
9+
import org.junit.BeforeClass;
10+
import org.junit.Test;
11+
import org.tron.common.BaseTest;
12+
import org.tron.common.TestConstants;
13+
import org.tron.common.parameter.CommonParameter;
14+
import org.tron.common.runtime.InternalTransaction;
15+
import org.tron.common.utils.ForkController;
16+
import org.tron.core.Constant;
17+
import org.tron.core.config.Parameter.ForkBlockVersionEnum;
18+
import org.tron.core.config.args.Args;
19+
import org.tron.core.exception.ContractValidateException;
20+
import org.tron.core.store.StoreFactory;
21+
import org.tron.core.vm.PrecompiledContracts;
22+
import org.tron.core.vm.PrecompiledContracts.PrecompiledContract;
23+
import org.tron.core.vm.config.ConfigLoader;
24+
import org.tron.core.vm.config.VMConfig;
25+
import org.tron.core.vm.program.Program;
26+
import org.tron.core.vm.program.Program.OutOfTimeException;
27+
import org.tron.core.vm.program.invoke.ProgramInvokeMockImpl;
28+
import org.tron.core.vm.utils.MUtil;
29+
import org.tron.protos.Protocol;
30+
31+
32+
@Slf4j
33+
public class Create2ModExpForkTest extends BaseTest {
34+
35+
// mirrors the private Program.MAX_DEPTH
36+
private static final int MAX_CALL_DEPTH = 64;
37+
38+
// mirrors PrecompiledContracts.ModExp.UPPER_BOUND
39+
private static final int MOD_EXP_UPPER_BOUND = 1024;
40+
41+
// ModExp precompile address (0x05)
42+
private static final DataWord MOD_EXP_ADDR = new DataWord(
43+
"0000000000000000000000000000000000000000000000000000000000000005");
44+
45+
@BeforeClass
46+
public static void init() {
47+
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, TestConstants.TEST_CONF);
48+
CommonParameter.getInstance().setDebug(true);
49+
}
50+
51+
@AfterClass
52+
public static void destroy() {
53+
ConfigLoader.disable = false;
54+
VMConfig.initVmHardFork(false);
55+
VMConfig.initAllowTvmCompatibleEvm(0);
56+
Args.clearParam();
57+
}
58+
59+
@Before
60+
public void setUp() {
61+
ForkController.instance().init(chainBaseManager);
62+
deactivateFork(ForkBlockVersionEnum.VERSION_4_8_1_1);
63+
}
64+
65+
@Test
66+
public void checkCPUTimeForCreate2_isGatedByFork() {
67+
MUtil.checkCPUTimeForCreate2();
68+
69+
activateFork(ForkBlockVersionEnum.VERSION_4_8_1_1);
70+
71+
OutOfTimeException ex =
72+
Assert.assertThrows(OutOfTimeException.class, MUtil::checkCPUTimeForCreate2);
73+
Assert.assertEquals("CPU timeout for create2 executing", ex.getMessage());
74+
}
75+
76+
@Test
77+
public void checkCPUTimeForModExp_isGatedByFork() {
78+
MUtil.checkCPUTimeForModExp();
79+
80+
activateFork(ForkBlockVersionEnum.VERSION_4_8_1_1);
81+
82+
OutOfTimeException ex =
83+
Assert.assertThrows(OutOfTimeException.class, MUtil::checkCPUTimeForModExp);
84+
Assert.assertEquals("CPU timeout for modExp executing", ex.getMessage());
85+
}
86+
87+
@Test
88+
public void modExp_degenerateInput_throwsOnlyAfterFork() {
89+
PrecompiledContract modExp = PrecompiledContracts.getContractForAddress(MOD_EXP_ADDR);
90+
byte[] data = buildModExpInput(MOD_EXP_UPPER_BOUND + 1);
91+
92+
Pair<Boolean, byte[]> out = modExp.execute(data);
93+
Assert.assertTrue(out.getLeft());
94+
95+
activateFork(ForkBlockVersionEnum.VERSION_4_8_1_1);
96+
97+
OutOfTimeException ex =
98+
Assert.assertThrows(OutOfTimeException.class, () -> modExp.execute(data));
99+
Assert.assertEquals("CPU timeout for modExp executing", ex.getMessage());
100+
}
101+
102+
@Test
103+
public void modExp_atUpperBound_doesNotThrowAfterFork() {
104+
activateFork(ForkBlockVersionEnum.VERSION_4_8_1_1);
105+
106+
PrecompiledContract modExp = PrecompiledContracts.getContractForAddress(MOD_EXP_ADDR);
107+
Pair<Boolean, byte[]> out = modExp.execute(buildModExpInput(MOD_EXP_UPPER_BOUND));
108+
Assert.assertTrue(out.getLeft());
109+
}
110+
111+
@Test
112+
public void createContract2_atMaxDepth_legacyPath_throwsAfterFork()
113+
throws ContractValidateException {
114+
VMConfig.initAllowTvmCompatibleEvm(0);
115+
activateFork(ForkBlockVersionEnum.VERSION_4_8_1_1);
116+
117+
Program program = buildProgramAtMaxDepth();
118+
OutOfTimeException ex = Assert.assertThrows(OutOfTimeException.class,
119+
() -> program.createContract2(
120+
DataWord.ZERO(), DataWord.ZERO(), DataWord.ZERO(), DataWord.ZERO()));
121+
Assert.assertEquals("CPU timeout for create2 executing", ex.getMessage());
122+
}
123+
124+
@Test
125+
public void createContract2_atMaxDepth_compatibleEvmOn_doesNotThrow()
126+
throws ContractValidateException {
127+
VMConfig.initAllowTvmCompatibleEvm(1);
128+
activateFork(ForkBlockVersionEnum.VERSION_4_8_1_1);
129+
130+
Program program = buildProgramAtMaxDepth();
131+
program.createContract2(DataWord.ZERO(), DataWord.ZERO(), DataWord.ZERO(), DataWord.ZERO());
132+
Assert.assertEquals(DataWord.ZERO(), program.getStack().pop());
133+
}
134+
135+
// ---- helpers ---------------------------------------------------------------------------------
136+
137+
private Program buildProgramAtMaxDepth() throws ContractValidateException {
138+
StoreFactory.init();
139+
StoreFactory storeFactory = StoreFactory.getInstance();
140+
storeFactory.setChainBaseManager(chainBaseManager);
141+
byte[] ops = new byte[] {0};
142+
ProgramInvokeMockImpl invoke = new ProgramInvokeMockImpl(storeFactory, ops, ops) {
143+
@Override
144+
public int getCallDeep() {
145+
return MAX_CALL_DEPTH;
146+
}
147+
};
148+
Program program = new Program(ops, ops, invoke,
149+
new InternalTransaction(Protocol.Transaction.getDefaultInstance(),
150+
InternalTransaction.TrxType.TRX_UNKNOWN_TYPE));
151+
program.setRootTransactionId(new byte[32]);
152+
return program;
153+
}
154+
155+
private byte[] buildModExpInput(int expLen) {
156+
byte[] data = new byte[96];
157+
byte[] expLenWord = new DataWord(expLen).getData();
158+
System.arraycopy(expLenWord, 0, data, 32, 32);
159+
return data;
160+
}
161+
162+
private void activateFork(ForkBlockVersionEnum forkVersion) {
163+
byte[] stats = new byte[27];
164+
Arrays.fill(stats, (byte) 1);
165+
chainBaseManager.getDynamicPropertiesStore().statsByVersion(forkVersion.getValue(), stats);
166+
long maintenanceTimeInterval =
167+
chainBaseManager.getDynamicPropertiesStore().getMaintenanceTimeInterval();
168+
long hardForkTime = ((forkVersion.getHardForkTime() - 1) / maintenanceTimeInterval + 1)
169+
* maintenanceTimeInterval;
170+
chainBaseManager.getDynamicPropertiesStore().saveLatestBlockHeaderTimestamp(hardForkTime + 1);
171+
}
172+
173+
private void deactivateFork(ForkBlockVersionEnum forkVersion) {
174+
chainBaseManager.getDynamicPropertiesStore()
175+
.statsByVersion(forkVersion.getValue(), new byte[27]);
176+
chainBaseManager.getDynamicPropertiesStore().saveLatestBlockHeaderTimestamp(0L);
177+
}
178+
}

0 commit comments

Comments
 (0)