-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(vm): check CREATE2 max depth under Osaka #6807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CodeNinjaEvan
merged 2 commits into
tronprotocol:release_v4.8.2
from
yanghang8612:create2-depth-osaka
Jun 12, 2026
+166
−1
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
framework/src/test/java/org/tron/common/runtime/VMActuatorMockTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package org.tron.common.runtime; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.any; | ||
|
|
||
| import java.lang.reflect.Field; | ||
| import java.util.Collections; | ||
| import org.junit.Assert; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
| import org.mockito.MockedStatic; | ||
| import org.mockito.Mockito; | ||
| import org.tron.common.runtime.vm.DataWord; | ||
| import org.tron.common.runtime.vm.LogInfo; | ||
| import org.tron.core.actuator.VMActuator; | ||
| import org.tron.core.db.TransactionContext; | ||
| import org.tron.core.vm.OperationRegistry; | ||
| import org.tron.core.vm.VM; | ||
| import org.tron.core.vm.config.VMConfig; | ||
| import org.tron.core.vm.program.Program; | ||
|
|
||
| public class VMActuatorMockTest { | ||
|
|
||
| @BeforeClass | ||
| public static void init() { | ||
| // warm up the registry so VM.play(..., OperationRegistry.getTable()) arg eval is safe | ||
| OperationRegistry.init(); | ||
| } | ||
|
|
||
| private void runCatchPathTest(Throwable thrownByVm, boolean osakaOn, int expectedSize) | ||
| throws Exception { | ||
| boolean prevOsaka = VMConfig.allowTvmOsaka(); | ||
| VMConfig.initAllowTvmOsaka(osakaOn ? 1 : 0); | ||
| try (MockedStatic<VM> vmMock = Mockito.mockStatic(VM.class)) { | ||
| Program program = Mockito.mock(Program.class); | ||
| ProgramResult result = new ProgramResult(); | ||
| result.addLogInfo(new LogInfo(new byte[20], Collections.emptyList(), new byte[0])); | ||
| result.addDeleteAccount(new DataWord(1)); | ||
| Mockito.when(program.getResult()).thenReturn(result); | ||
|
|
||
| vmMock.when(() -> VM.play(any(), any())).thenThrow(thrownByVm); | ||
|
|
||
| VMActuator actuator = new VMActuator(false); | ||
| Field f = VMActuator.class.getDeclaredField("program"); | ||
| f.setAccessible(true); | ||
| f.set(actuator, program); | ||
|
|
||
| TransactionContext context = Mockito.mock(TransactionContext.class); | ||
| Mockito.when(context.getProgramResult()).thenReturn(new ProgramResult()); | ||
|
|
||
| actuator.execute(context); | ||
|
|
||
| Assert.assertEquals(expectedSize, result.getLogInfoList().size()); | ||
| Assert.assertEquals(expectedSize, result.getDeleteAccounts().size()); | ||
| } finally { | ||
| VMConfig.initAllowTvmOsaka(prevOsaka ? 1 : 0); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void osakaClearsLogOnOutOfTime() throws Exception { | ||
| runCatchPathTest(new Program.OutOfTimeException("timeout"), true, 0); | ||
| } | ||
|
|
||
| @Test | ||
| public void osakaClearsLogOnJvmStackOverflow() throws Exception { | ||
| runCatchPathTest(new Program.JVMStackOverFlowException(), true, 0); | ||
| } | ||
|
|
||
| @Test | ||
| public void osakaClearsLogOnThrowable() throws Exception { | ||
| runCatchPathTest(new RuntimeException("boom"), true, 0); | ||
| } | ||
|
|
||
| @Test | ||
| public void preOsakaKeepsLogOnOutOfTime() throws Exception { | ||
| runCatchPathTest(new Program.OutOfTimeException("timeout"), false, 1); | ||
| } | ||
|
|
||
| @Test | ||
| public void preOsakaKeepsLogOnJvmStackOverflow() throws Exception { | ||
| runCatchPathTest(new Program.JVMStackOverFlowException(), false, 1); | ||
| } | ||
|
|
||
| @Test | ||
| public void preOsakaKeepsLogOnThrowable() throws Exception { | ||
| runCatchPathTest(new RuntimeException("boom"), false, 1); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great to add a test case where both allowTvmCompatibleEvm and allowTvmOsaka are false, just to explicitly confirm that CREATE2 behaves as expected when neither flag is enabled. Helps make the intent clear for future readers!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, thanks! Added
testCreate2MaxDepthWithNeitherFlagin the latest push: with bothallowTvmCompatibleEvmandallowTvmOsakadisabled, theMAX_DEPTHshort-circuit is not taken, so at max depth CREATE2 still proceeds as before — it records an internal transaction and pushes the new contract address instead of0. This documents the baseline behavior alongside the Osaka-only case for future readers. PTAL.