diff --git a/rskj-core/src/test/java/co/rsk/vm/opcode/TransientStorageDslTest.java b/rskj-core/src/test/java/co/rsk/vm/opcode/TransientStorageDslTest.java index b47b3eb9a5..00502ca38d 100644 --- a/rskj-core/src/test/java/co/rsk/vm/opcode/TransientStorageDslTest.java +++ b/rskj-core/src/test/java/co/rsk/vm/opcode/TransientStorageDslTest.java @@ -31,9 +31,13 @@ import org.ethereum.core.util.TransactionReceiptUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import java.io.FileNotFoundException; import java.math.BigInteger; +import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -44,7 +48,7 @@ class TransientStorageDslTest { @Test void testTransientStorageOpcodesExecutionsWithRSKIPActivated() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/tload_tstore_basic_tests.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/tload_tstore_basic_tests.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -66,7 +70,7 @@ void testTransientStorageOpcodesExecutionsWithRSKIPActivated() throws FileNotFou @Test void testTransientStorageOpcodesShareMemorySameTransaction() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/tload_tstore_basic_tests.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/tload_tstore_basic_tests.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -84,7 +88,7 @@ void testTransientStorageOpcodesShareMemorySameTransaction() throws FileNotFound @Test void testTransientStorageOpcodesDoesntShareMemoryFromOtherContract() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/tload_tstore_basic_tests.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/tload_tstore_basic_tests.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -106,7 +110,7 @@ void testTransientStorageOpcodesExecutionFailsWithRSKIPDeactivated() throws File rawConfig.withValue("blockchain.config.hardforkActivationHeights.lovell700", ConfigValueFactory.fromAnyRef(-1)) ); - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/tload_tstore_basic_tests.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/tload_tstore_basic_tests.txt"); World world = new World(rskip446Disabled); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -123,7 +127,7 @@ void testTransientStorageOpcodesExecutionFailsWithRSKIPDeactivated() throws File @Test void testTransientStorageTestsEip1153BasicScenarios() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/eip1153_basic_tests.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/eip1153_basic_tests.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -150,7 +154,7 @@ void testTransientStorageTestsEip1153BasicScenarios() throws FileNotFoundExcepti @Test void testOnlyConstructorCodeCreateContext() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/only_constructor_code_create_context.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/only_constructor_code_create_context.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -165,7 +169,7 @@ void testOnlyConstructorCodeCreateContext() throws FileNotFoundException, DslPro @Test void testInConstructorAndCodeCreateContext() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/in_constructor_and_deploy_code_create_context.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/in_constructor_and_deploy_code_create_context.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -180,7 +184,7 @@ void testInConstructorAndCodeCreateContext() throws FileNotFoundException, DslPr @Test void testAccrossConstructorAndCodeV0CreateContext() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/accross_constructor_and_deploy_code_v0_create_context.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/accross_constructor_and_deploy_code_v0_create_context.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -195,7 +199,7 @@ void testAccrossConstructorAndCodeV0CreateContext() throws FileNotFoundException @Test void testAccrossConstructorAndCodeV1CreateContext() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/accross_constructor_and_deploy_code_v1_create_context.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/accross_constructor_and_deploy_code_v1_create_context.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -210,7 +214,7 @@ void testAccrossConstructorAndCodeV1CreateContext() throws FileNotFoundException @Test void testNoConstructorCodeCreateContext() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/no_constructor_code_create_context.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/no_constructor_code_create_context.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -225,7 +229,7 @@ void testNoConstructorCodeCreateContext() throws FileNotFoundException, DslProce @Test void testDynamicExecutionContextSimpleScenario() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/dynamic_execution_context_simple.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/dynamic_execution_context_simple.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -244,7 +248,7 @@ void testDynamicExecutionContextSimpleScenario() throws FileNotFoundException, D @Test void testDynamicExecutionContextWithRevert() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/dynamic_execution_context_with_revert.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/dynamic_execution_context_with_revert.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -267,7 +271,7 @@ void testDynamicExecutionContextWithRevert() throws FileNotFoundException, DslPr @Test void testDynamicExecutionContextWithInvalid() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/dynamic_execution_context_with_invalid.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/dynamic_execution_context_with_invalid.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -290,7 +294,7 @@ void testDynamicExecutionContextWithInvalid() throws FileNotFoundException, DslP @Test void testDynamicExecutionContextWithStackOverflow() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/dynamic_execution_context_with_stack_overflow.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/dynamic_execution_context_with_stack_overflow.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -313,7 +317,7 @@ void testDynamicExecutionContextWithStackOverflow() throws FileNotFoundException @Test void testDynamicExecutionCallContextSubcall() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/dynamic_execution_context_call_subcall.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/dynamic_execution_context_call_subcall.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -328,7 +332,7 @@ void testDynamicExecutionCallContextSubcall() throws FileNotFoundException, DslP @Test void testDynamicExecutionStaticCallSubcallCantUseTstore() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/dynamic_execution_context_staticcall_subcall_cant_call_tstore.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/dynamic_execution_context_staticcall_subcall_cant_call_tstore.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -343,7 +347,7 @@ void testDynamicExecutionStaticCallSubcallCantUseTstore() throws FileNotFoundExc @Test void testDynamicReentrancyContextsTstoreBeforeRevertOrInvalidHasNoEffect() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/dynamic_reentrancy_context_tstore_before_revert_or_invalid_has_no_effect.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/dynamic_reentrancy_context_tstore_before_revert_or_invalid_has_no_effect.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -361,7 +365,7 @@ void testDynamicReentrancyContextsTstoreBeforeRevertOrInvalidHasNoEffect() throw @Test void testDynamicReentrancyContextsRevertOrInvalidUndoesAll() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/dynamic_reentrancy_context_revert_or_invalid_undoes_all.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/dynamic_reentrancy_context_revert_or_invalid_undoes_all.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -379,7 +383,7 @@ void testDynamicReentrancyContextsRevertOrInvalidUndoesAll() throws FileNotFound @Test void testDynamicReentrancyContextsRevertOrInvalidUndoesTstorageAfterSuccessfullCall() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/dynamic_reentrancy_context_revert_or_invalid_undoes_tstorage_after_successfull_call.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/dynamic_reentrancy_context_revert_or_invalid_undoes_tstorage_after_successfull_call.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -404,7 +408,7 @@ void testDynamicReentrancyContextsRevertOrInvalidUndoesTstorageAfterSuccessfullC @Test void testReentrancyContextsTstoreAfterReentrantCall() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/reentrancy_context_tstore_after_reentrant_call.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/reentrancy_context_tstore_after_reentrant_call.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -422,7 +426,7 @@ void testReentrancyContextsTstoreAfterReentrantCall() throws FileNotFoundExcepti @Test void testReentrancyContextsTloadAfterReentrantTstore() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/reentrancy_context_tload_after_reentrant_tstore.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/reentrancy_context_tload_after_reentrant_tstore.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -440,7 +444,7 @@ void testReentrancyContextsTloadAfterReentrantTstore() throws FileNotFoundExcept @Test void testReentrancyContextsManipulateInReentrantCall() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/reentrancy_context_manipulate_in_reentrant_call.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/reentrancy_context_manipulate_in_reentrant_call.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -458,7 +462,7 @@ void testReentrancyContextsManipulateInReentrantCall() throws FileNotFoundExcept @Test void testReentrancyContextsTstoreInCallThenTloadReturnInStaticCall() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/reentrancy_context_tstore_in_call_then_tload_return_in_static_call.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/reentrancy_context_tstore_in_call_then_tload_return_in_static_call.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -476,7 +480,7 @@ void testReentrancyContextsTstoreInCallThenTloadReturnInStaticCall() throws File @Test void testTransientStorageGasMeasureTests() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/tstorage_gas_measure_tests.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/tstorage_gas_measure_tests.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -491,7 +495,7 @@ void testTransientStorageGasMeasureTests() throws FileNotFoundException, DslProc @Test void testTstoreLoopUntilOutOfGas() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/tstore_loop_until_out_of_gas.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/tstore_loop_until_out_of_gas.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -507,7 +511,7 @@ void testTstoreLoopUntilOutOfGas() throws FileNotFoundException, DslProcessorExc @Test void testTstoreWideAddressSpaceLoopUntilOutOfGas() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/tstore_wide_address_space_loop_until_out_of_gas.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/tstore_wide_address_space_loop_until_out_of_gas.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -523,7 +527,7 @@ void testTstoreWideAddressSpaceLoopUntilOutOfGas() throws FileNotFoundException, @Test void testTstoreAndTloadLoopUntilOutOfGas() throws FileNotFoundException, DslProcessorException { - DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/tstore_and_tload_loop_until_out_of_gas.txt"); + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/tstore_and_tload_loop_until_out_of_gas.txt"); World world = new World(); WorldDslProcessor processor = new WorldDslProcessor(world); processor.processCommands(parser); @@ -537,6 +541,35 @@ void testTstoreAndTloadLoopUntilOutOfGas() throws FileNotFoundException, DslProc assertEquals(700000, txRunOutOfGas); // Assert that it consumed all the gas configured in the transaction } + + @ParameterizedTest + @MethodSource("provideParametersForSelfDestructCases") + void testTstorageSelfDestructCases_OnEachTest_TheEventsEmittedAreTheExpected(String dslFile, Integer numberOfOksEmitted) throws FileNotFoundException, DslProcessorException { + + DslParser parser = DslParser.fromResource("dsl/transient_storage_rskip446/" + dslFile); + World world = new World(); + WorldDslProcessor processor = new WorldDslProcessor(world); + processor.processCommands(parser); + + String txDeployTestContract = "txDeployTestContract"; + assertTransactionReceiptWithStatus(world, txDeployTestContract, "b01", true); + + String txCheckValuesStoredInTstorage = "txPerformTest"; + TransactionReceipt txReceipt = assertTransactionReceiptWithStatus(world, txCheckValuesStoredInTstorage, "b02", true); + Assertions.assertEquals(numberOfOksEmitted, TransactionReceiptUtil.getEventCount(txReceipt, "OK", null)); + } + + private static Stream provideParametersForSelfDestructCases() { + return Stream.of( + Arguments.of("tload_after_selfdestruct_pre_existing_contract.txt", 3 ), + Arguments.of("tload_after_selfdestruct_new_contract.txt", 3 ), + Arguments.of("tload_after_inner_selfdestruct_pre_existing_contract.txt", 2 ), + Arguments.of("tload_after_inner_selfdestruct_new_contract.txt", 2 ), + Arguments.of("tstore_after_selfdestruct_pre_existing_contract.txt", 4 ), + Arguments.of("tstore_after_selfdestruct_new_contract.txt", 4 ) + ); + } + private static TransactionReceipt assertTransactionReceiptWithStatus(World world, String txName, String blockName, boolean withSuccess) { Transaction txCreation = world.getTransactionByName(txName); assertNotNull(txCreation); diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/accross_constructor_and_deploy_code_v0_create_context.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/accross_constructor_and_deploy_code_v0_create_context.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/accross_constructor_and_deploy_code_v0_create_context.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/accross_constructor_and_deploy_code_v0_create_context.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/accross_constructor_and_deploy_code_v1_create_context.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/accross_constructor_and_deploy_code_v1_create_context.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/accross_constructor_and_deploy_code_v1_create_context.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/accross_constructor_and_deploy_code_v1_create_context.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_call_subcall.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_execution_context_call_subcall.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_call_subcall.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_execution_context_call_subcall.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_simple.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_execution_context_simple.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_simple.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_execution_context_simple.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_staticcall_subcall_can_call_tload.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_execution_context_staticcall_subcall_can_call_tload.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_staticcall_subcall_can_call_tload.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_execution_context_staticcall_subcall_can_call_tload.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_staticcall_subcall_cant_call_tstore.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_execution_context_staticcall_subcall_cant_call_tstore.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_staticcall_subcall_cant_call_tstore.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_execution_context_staticcall_subcall_cant_call_tstore.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_with_invalid.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_execution_context_with_invalid.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_with_invalid.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_execution_context_with_invalid.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_with_revert.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_execution_context_with_revert.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_with_revert.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_execution_context_with_revert.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_with_stack_overflow.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_execution_context_with_stack_overflow.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_with_stack_overflow.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_execution_context_with_stack_overflow.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_reentrancy_context_revert_or_invalid_undoes_all.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_reentrancy_context_revert_or_invalid_undoes_all.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_reentrancy_context_revert_or_invalid_undoes_all.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_reentrancy_context_revert_or_invalid_undoes_all.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_reentrancy_context_revert_or_invalid_undoes_tstorage_after_successfull_call.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_reentrancy_context_revert_or_invalid_undoes_tstorage_after_successfull_call.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_reentrancy_context_revert_or_invalid_undoes_tstorage_after_successfull_call.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_reentrancy_context_revert_or_invalid_undoes_tstorage_after_successfull_call.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_reentrancy_context_tstore_before_revert_or_invalid_has_no_effect.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_reentrancy_context_tstore_before_revert_or_invalid_has_no_effect.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/dynamic_reentrancy_context_tstore_before_revert_or_invalid_has_no_effect.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/dynamic_reentrancy_context_tstore_before_revert_or_invalid_has_no_effect.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/eip1153_basic_tests.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/eip1153_basic_tests.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/eip1153_basic_tests.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/eip1153_basic_tests.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/in_constructor_and_deploy_code_create_context.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/in_constructor_and_deploy_code_create_context.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/in_constructor_and_deploy_code_create_context.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/in_constructor_and_deploy_code_create_context.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/no_constructor_code_create_context.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/no_constructor_code_create_context.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/no_constructor_code_create_context.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/no_constructor_code_create_context.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/only_constructor_code_create_context.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/only_constructor_code_create_context.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/only_constructor_code_create_context.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/only_constructor_code_create_context.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/reentrancy_context_manipulate_in_reentrant_call.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/reentrancy_context_manipulate_in_reentrant_call.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/reentrancy_context_manipulate_in_reentrant_call.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/reentrancy_context_manipulate_in_reentrant_call.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/reentrancy_context_tload_after_reentrant_tstore.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/reentrancy_context_tload_after_reentrant_tstore.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/reentrancy_context_tload_after_reentrant_tstore.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/reentrancy_context_tload_after_reentrant_tstore.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/reentrancy_context_tstore_after_reentrant_call.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/reentrancy_context_tstore_after_reentrant_call.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/reentrancy_context_tstore_after_reentrant_call.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/reentrancy_context_tstore_after_reentrant_call.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/reentrancy_context_tstore_in_call_then_tload_return_in_static_call.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/reentrancy_context_tstore_in_call_then_tload_return_in_static_call.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/reentrancy_context_tstore_in_call_then_tload_return_in_static_call.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/reentrancy_context_tstore_in_call_then_tload_return_in_static_call.txt diff --git a/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tload_after_inner_selfdestruct_new_contract.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tload_after_inner_selfdestruct_new_contract.txt new file mode 100644 index 0000000000..4aeaf2dbd1 --- /dev/null +++ b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tload_after_inner_selfdestruct_new_contract.txt @@ -0,0 +1,136 @@ +comment + +// CONTRACT CODE + +pragma solidity ^0.8.24; + +contract TloadAfterInnerSelfdestructingNewContract { + + constructor() { + } + + event OK(); + event ERROR(string, uint256); + + function performTest() external { + Callee callee = new Callee(); + address calleeAddress = address(callee); + uint256 resultCallOption1; + uint256 valueLoadedFromMemory; + bytes4 executeSignature = bytes4(keccak256("execute(uint256)")); + + assembly { + // Call Option 1: Executes tstore, inner call to selfdestruct and then tload and return data + let availablePointerCallOption1 := mload(0x40) + mstore(availablePointerCallOption1, executeSignature) + mstore(add(availablePointerCallOption1, 4), 1) + resultCallOption1 := call(gas(), calleeAddress, 0, availablePointerCallOption1, 0x24, availablePointerCallOption1, 0x20) + + // Copy returndata into memory to retrieve the returned value + returndatacopy(availablePointerCallOption1, 0, returndatasize()) + valueLoadedFromMemory := mload(availablePointerCallOption1) + } + + checkReturnValueExpected(resultCallOption1, 'Checking result call option 1', 0x01); + checkReturnValueExpected(valueLoadedFromMemory, 'Checking value from mload 0', 0x100); + } + + function checkReturnValueExpected(uint256 valueReceived, string memory message, uint256 expectedValue) private { + if( valueReceived == expectedValue){ + emit OK(); + } else { + emit ERROR(message, valueReceived); + } + } +} + +contract Callee { + + event OK(); + event ERROR(string, uint256); + + function execute(uint256 callOption) external returns (uint256) { + address calleeAddress = address(this); + bytes4 executeSignature = bytes4(keccak256("execute(uint256)")); + uint256 resultCallOption2; + assembly { + switch callOption + case 1 { + tstore(0xFF, 0x100) + // Call Option 2: Executes tload and returns data + let availablePointerCallOption2 := mload(0x40) + mstore(availablePointerCallOption2, executeSignature) + mstore(add(availablePointerCallOption2, 4), 2) + resultCallOption2 := call(gas(), calleeAddress, 0, availablePointerCallOption2, 0x24, availablePointerCallOption2, 0x20) + + // Load value from transient storage + let value := tload(0xFF) + mstore(0x00, value) // Store it in memory to return + return(0x00, 0x20) // Return 32 bytes from memory + } + case 2 { + selfdestruct(0) + } + } + } +} + +// DESCRIPTION + +// CONTRACT BYTECODE + +TloadAfterInnerSelfdestructingNewContract: 608060405234801561000f575f80fd5b506104708061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c80630d0b85f11461002d575b5f80fd5b610035610037565b005b5f604051610044906101ad565b604051809103905ff08015801561005d573d5f803e3d5ffd5b5090505f8190505f805f7ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b9050604051818152600160048201526020816024835f895af193503d5f823e80519250506100ed836040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e20310000008152506001610136565b61012f826040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d206d6c6f616420300000000000815250610100610136565b5050505050565b80830361016e577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a16101a8565b7fc9e730d5b570f89e168eb8c3d29f8c396b957e540af248c95c9519ac47c2c69f828460405161019f92919061025c565b60405180910390a15b505050565b6101b08061028b83390190565b5f81519050919050565b5f82825260208201905092915050565b5f5b838110156101f15780820151818401526020810190506101d6565b5f8484015250505050565b5f601f19601f8301169050919050565b5f610216826101ba565b61022081856101c4565b93506102308185602086016101d4565b610239816101fc565b840191505092915050565b5f819050919050565b61025681610244565b82525050565b5f6040820190508181035f830152610274818561020c565b9050610283602083018461024d565b939250505056fe608060405234801561000f575f80fd5b506101938061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063fe0d94c11461002d575b5f80fd5b6100476004803603810190610042919061010a565b61005d565b6040516100549190610144565b60405180910390f35b5f803090505f7ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b90505f846001811461009d57600281146100c7576100ca565b61010060ff5d604051838152600260048201526020816024835f895af1925060ff5c805f5260205ff35b5fff5b50505050919050565b5f80fd5b5f819050919050565b6100e9816100d7565b81146100f3575f80fd5b50565b5f81359050610104816100e0565b92915050565b5f6020828403121561011f5761011e6100d3565b5b5f61012c848285016100f6565b91505092915050565b61013e816100d7565b82525050565b5f6020820190506101575f830184610135565b9291505056fea2646970667358221220df3fda34f805973d73508c3bff5aa075ac36fd7769240906d19a4ade4713155464736f6c63430008180033a26469706673582212202ee0175c4410ed0d1259c8ad0377835933ddf29c77105e09bac218f55b6c5f3464736f6c63430008180033 + +function hashes:s + +- 0d0b85f1: performTest() + +end + +# Create and fund new account +account_new acc1 10000000 + +# Create transaction to deploy TloadAfterSelfdestructPreExistingContract contract +transaction_build txDeployTestContract + sender acc1 + receiverAddress 00 + value 0 + data 608060405234801561000f575f80fd5b506104708061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c80630d0b85f11461002d575b5f80fd5b610035610037565b005b5f604051610044906101ad565b604051809103905ff08015801561005d573d5f803e3d5ffd5b5090505f8190505f805f7ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b9050604051818152600160048201526020816024835f895af193503d5f823e80519250506100ed836040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e20310000008152506001610136565b61012f826040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d206d6c6f616420300000000000815250610100610136565b5050505050565b80830361016e577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a16101a8565b7fc9e730d5b570f89e168eb8c3d29f8c396b957e540af248c95c9519ac47c2c69f828460405161019f92919061025c565b60405180910390a15b505050565b6101b08061028b83390190565b5f81519050919050565b5f82825260208201905092915050565b5f5b838110156101f15780820151818401526020810190506101d6565b5f8484015250505050565b5f601f19601f8301169050919050565b5f610216826101ba565b61022081856101c4565b93506102308185602086016101d4565b610239816101fc565b840191505092915050565b5f819050919050565b61025681610244565b82525050565b5f6040820190508181035f830152610274818561020c565b9050610283602083018461024d565b939250505056fe608060405234801561000f575f80fd5b506101938061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063fe0d94c11461002d575b5f80fd5b6100476004803603810190610042919061010a565b61005d565b6040516100549190610144565b60405180910390f35b5f803090505f7ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b90505f846001811461009d57600281146100c7576100ca565b61010060ff5d604051838152600260048201526020816024835f895af1925060ff5c805f5260205ff35b5fff5b50505050919050565b5f80fd5b5f819050919050565b6100e9816100d7565b81146100f3575f80fd5b50565b5f81359050610104816100e0565b92915050565b5f6020828403121561011f5761011e6100d3565b5b5f61012c848285016100f6565b91505092915050565b61013e816100d7565b82525050565b5f6020820190506101575f830184610135565b9291505056fea2646970667358221220df3fda34f805973d73508c3bff5aa075ac36fd7769240906d19a4ade4713155464736f6c63430008180033a26469706673582212202ee0175c4410ed0d1259c8ad0377835933ddf29c77105e09bac218f55b6c5f3464736f6c63430008180033 + gas 1000000 + build + +# Create block to hold txDeployTestContract transaction +block_build b01 + parent g00 + transactions txDeployTestContract + gasLimit 1200000 + build + +# Connect block +block_connect b01 + +# Check b01 is best block +assert_best b01 + +# Create transaction to execute performTest function from contract +transaction_build txPerformTest + sender acc1 + nonce 1 + contract txDeployTestContract + value 0 + data 0d0b85f1 + gas 300000 + build + +# Create block to hold txPerformTest transaction +block_build b02 + parent b01 + transactions txPerformTest + gasLimit 350000 + build + +# Connect block +block_connect b02 + +# Check b02 is best block +assert_best b02 \ No newline at end of file diff --git a/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tload_after_inner_selfdestruct_pre_existing_contract.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tload_after_inner_selfdestruct_pre_existing_contract.txt new file mode 100644 index 0000000000..c9aa4f4565 --- /dev/null +++ b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tload_after_inner_selfdestruct_pre_existing_contract.txt @@ -0,0 +1,136 @@ +comment + +// CONTRACT CODE +pragma solidity ^0.8.24; + +contract TloadAfterInnerSelfdestructingPreExistingContract { + Callee callee; + + constructor() { + callee = new Callee(); + } + + event OK(); + event ERROR(string, uint256); + + function performTest() external { + address calleeAddress = address(callee); + uint256 resultCallOption1; + uint256 valueLoadedFromMemory; + bytes4 executeSignature = bytes4(keccak256("execute(uint256)")); + + assembly { + // Call Option 1: Executes tstore, inner call to selfdestruct and then tload and return data + let availablePointerCallOption1 := mload(0x40) + mstore(availablePointerCallOption1, executeSignature) + mstore(add(availablePointerCallOption1, 4), 1) + resultCallOption1 := call(gas(), calleeAddress, 0, availablePointerCallOption1, 0x24, availablePointerCallOption1, 0x20) + + // Copy returndata into memory to retrieve the returned value + returndatacopy(availablePointerCallOption1, 0, returndatasize()) + valueLoadedFromMemory := mload(availablePointerCallOption1) + } + + checkReturnValueExpected(resultCallOption1, 'Checking result call option 1', 0x01); + checkReturnValueExpected(valueLoadedFromMemory, 'Checking value from mload 0', 0x100); + } + + function checkReturnValueExpected(uint256 valueReceived, string memory message, uint256 expectedValue) private { + if( valueReceived == expectedValue){ + emit OK(); + } else { + emit ERROR(message, valueReceived); + } + } +} + +contract Callee { + + event OK(); + event ERROR(string, uint256); + + function execute(uint256 callOption) external returns (uint256) { + address calleeAddress = address(this); + bytes4 executeSignature = bytes4(keccak256("execute(uint256)")); + uint256 resultCallOption2; + assembly { + switch callOption + case 1 { + tstore(0xFF, 0x100) + // Call Option 2: Executes tload and returns data + let availablePointerCallOption2 := mload(0x40) + mstore(availablePointerCallOption2, executeSignature) + mstore(add(availablePointerCallOption2, 4), 2) + resultCallOption2 := call(gas(), calleeAddress, 0, availablePointerCallOption2, 0x24, availablePointerCallOption2, 0x20) + + // Load value from transient storage + let value := tload(0xFF) + mstore(0x00, value) // Store it in memory to return + return(0x00, 0x20) // Return 32 bytes from memory + } + case 2 { + selfdestruct(0) + } + } + } +} + +// DESCRIPTION + +// CONTRACT BYTECODE + +TloadAfterInnerSelfdestructingPreExistingContract: 608060405234801561000f575f80fd5b5060405161001c90610079565b604051809103905ff080158015610035573d5f803e3d5ffd5b505f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610086565b6101b08061033c83390190565b6102a9806100935f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c80630d0b85f11461002d575b5f80fd5b610035610037565b005b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505f805f7ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b9050604051818152600160048201526020816024835f895af193503d5f823e80519250506100e4836040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e2031000000815250600161012c565b610126826040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d206d6c6f61642030000000000081525061010061012c565b50505050565b808303610164577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a161019e565b7fc9e730d5b570f89e168eb8c3d29f8c396b957e540af248c95c9519ac47c2c69f8284604051610195929190610245565b60405180910390a15b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b838110156101da5780820151818401526020810190506101bf565b5f8484015250505050565b5f601f19601f8301169050919050565b5f6101ff826101a3565b61020981856101ad565b93506102198185602086016101bd565b610222816101e5565b840191505092915050565b5f819050919050565b61023f8161022d565b82525050565b5f6040820190508181035f83015261025d81856101f5565b905061026c6020830184610236565b939250505056fea2646970667358221220314f4ea23497493d6086e14a2ebfdd4290728740c02f4713001e260d7d662c4164736f6c63430008180033608060405234801561000f575f80fd5b506101938061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063fe0d94c11461002d575b5f80fd5b6100476004803603810190610042919061010a565b61005d565b6040516100549190610144565b60405180910390f35b5f803090505f7ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b90505f846001811461009d57600281146100c7576100ca565b61010060ff5d604051838152600260048201526020816024835f895af1925060ff5c805f5260205ff35b5fff5b50505050919050565b5f80fd5b5f819050919050565b6100e9816100d7565b81146100f3575f80fd5b50565b5f81359050610104816100e0565b92915050565b5f6020828403121561011f5761011e6100d3565b5b5f61012c848285016100f6565b91505092915050565b61013e816100d7565b82525050565b5f6020820190506101575f830184610135565b9291505056fea264697066735822122000dadba91902cd6d3eaf38fdb47cdccbbf9036448d79da3ff9b15dc0012e4a0864736f6c63430008180033 + +function hashes:s + +- 0d0b85f1: performTest() + +end + +# Create and fund new account +account_new acc1 10000000 + +# Create transaction to deploy TloadAfterSelfdestructPreExistingContract contract +transaction_build txDeployTestContract + sender acc1 + receiverAddress 00 + value 0 + data 608060405234801561000f575f80fd5b5060405161001c90610079565b604051809103905ff080158015610035573d5f803e3d5ffd5b505f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610086565b6101b08061033c83390190565b6102a9806100935f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c80630d0b85f11461002d575b5f80fd5b610035610037565b005b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505f805f7ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b9050604051818152600160048201526020816024835f895af193503d5f823e80519250506100e4836040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e2031000000815250600161012c565b610126826040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d206d6c6f61642030000000000081525061010061012c565b50505050565b808303610164577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a161019e565b7fc9e730d5b570f89e168eb8c3d29f8c396b957e540af248c95c9519ac47c2c69f8284604051610195929190610245565b60405180910390a15b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b838110156101da5780820151818401526020810190506101bf565b5f8484015250505050565b5f601f19601f8301169050919050565b5f6101ff826101a3565b61020981856101ad565b93506102198185602086016101bd565b610222816101e5565b840191505092915050565b5f819050919050565b61023f8161022d565b82525050565b5f6040820190508181035f83015261025d81856101f5565b905061026c6020830184610236565b939250505056fea2646970667358221220314f4ea23497493d6086e14a2ebfdd4290728740c02f4713001e260d7d662c4164736f6c63430008180033608060405234801561000f575f80fd5b506101938061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063fe0d94c11461002d575b5f80fd5b6100476004803603810190610042919061010a565b61005d565b6040516100549190610144565b60405180910390f35b5f803090505f7ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b90505f846001811461009d57600281146100c7576100ca565b61010060ff5d604051838152600260048201526020816024835f895af1925060ff5c805f5260205ff35b5fff5b50505050919050565b5f80fd5b5f819050919050565b6100e9816100d7565b81146100f3575f80fd5b50565b5f81359050610104816100e0565b92915050565b5f6020828403121561011f5761011e6100d3565b5b5f61012c848285016100f6565b91505092915050565b61013e816100d7565b82525050565b5f6020820190506101575f830184610135565b9291505056fea264697066735822122000dadba91902cd6d3eaf38fdb47cdccbbf9036448d79da3ff9b15dc0012e4a0864736f6c63430008180033 + gas 1000000 + build + +# Create block to hold txDeployTestContract transaction +block_build b01 + parent g00 + transactions txDeployTestContract + gasLimit 1200000 + build + +# Connect block +block_connect b01 + +# Check b01 is best block +assert_best b01 + +# Create transaction to execute performTest function from contract +transaction_build txPerformTest + sender acc1 + nonce 1 + contract txDeployTestContract + value 0 + data 0d0b85f1 + gas 300000 + build + +# Create block to hold txPerformTest transaction +block_build b02 + parent b01 + transactions txPerformTest + gasLimit 350000 + build + +# Connect block +block_connect b02 + +# Check b02 is best block +assert_best b02 \ No newline at end of file diff --git a/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tload_after_selfdestruct_new_contract.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tload_after_selfdestruct_new_contract.txt new file mode 100644 index 0000000000..ef46b4f70d --- /dev/null +++ b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tload_after_selfdestruct_new_contract.txt @@ -0,0 +1,132 @@ +comment + +// CONTRACT CODE + +pragma solidity ^0.8.24; + +contract TloadAfterSelfdestructNewContract { + constructor() { + } + + event OK(); + event ERROR(string, uint256); + + function performTest() external { + Callee callee = new Callee(); + address calleeAddress = address(callee); + uint256 resultCallOption1; + uint256 resultCallOption2; + uint256 valueLoadedFromMemory; + bytes4 executeSignature = bytes4(keccak256("execute(uint256)")); + + assembly { + // Call Option 1: Executes tstore and selfdestruct + let availablePointerCallOption1 := mload(0x40) + mstore(availablePointerCallOption1, executeSignature) + mstore(add(availablePointerCallOption1, 4), 1) + resultCallOption1 := call(gas(), calleeAddress, 0, availablePointerCallOption1, 0x24, availablePointerCallOption1, 0x20) + // Note: Callee will self-destruct, no return data expected for callOption == 1. + + // Call Option 2: Executes tload and returns data + let availablePointerCallOption2 := mload(0x40) + mstore(availablePointerCallOption2, executeSignature) + mstore(add(availablePointerCallOption2, 4), 2) + resultCallOption2 := call(gas(), calleeAddress, 0, availablePointerCallOption2, 0x24, availablePointerCallOption2, 0x2) + + // Copy returndata into memory to retrieve the returned value + returndatacopy(availablePointerCallOption2, 0, returndatasize()) + valueLoadedFromMemory := mload(availablePointerCallOption2) + } + + checkReturnValueExpected(resultCallOption1, 'Checking result call option 1', 0x01); + checkReturnValueExpected(resultCallOption2, 'Checking result call option 2', 0x01); + checkReturnValueExpected(valueLoadedFromMemory, 'Checking value from mload 0', 0x100); + } + + function checkReturnValueExpected(uint256 valueReceived, string memory message, uint256 expectedValue) private { + if( valueReceived == expectedValue){ + emit OK(); + } else { + emit ERROR(message, valueReceived); + } + } +} + +contract Callee { + + function execute(uint256 callOption) external returns (uint256) { + assembly { + switch callOption + case 1 { + tstore(0xFF, 0x100) + selfdestruct(0) + } + case 2 { + // Load value from transient storage + let value := tload(0xFF) + mstore(0x00, value) // Store it in memory to return + return(0x00, 0x20) // Return 32 bytes from memory + } + } + } +} + +// DESCRIPTION + +// CONTRACT BYTECODE + +TloadAfterSelfdestructNewContract: 608060405234801561000f575f80fd5b506104888061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c80630d0b85f11461002d575b5f80fd5b610035610037565b005b5f6040516100449061020a565b604051809103905ff08015801561005d573d5f803e3d5ffd5b5090505f8190505f805f807ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b9050604051818152600160048201526020816024835f8a5af19450604051828152600260048201526002816024835f8b5af194503d5f823e805193505050610108846040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e20310000008152506001610193565b610149836040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e20320000008152506001610193565b61018b826040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d206d6c6f616420300000000000815250610100610193565b505050505050565b8083036101cb577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a1610205565b7fc9e730d5b570f89e168eb8c3d29f8c396b957e540af248c95c9519ac47c2c69f82846040516101fc9291906102b9565b60405180910390a15b505050565b61016b806102e883390190565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561024e578082015181840152602081019050610233565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61027382610217565b61027d8185610221565b935061028d818560208601610231565b61029681610259565b840191505092915050565b5f819050919050565b6102b3816102a1565b82525050565b5f6040820190508181035f8301526102d18185610269565b90506102e060208301846102aa565b939250505056fe608060405234801561000f575f80fd5b5061014e8061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063fe0d94c11461002d575b5f80fd5b610047600480360381019061004291906100c5565b61005d565b60405161005491906100ff565b60405180910390f35b5f8160018114610074576002811461007d57610088565b61010060ff5d5fff5b60ff5c805f5260205ff35b50919050565b5f80fd5b5f819050919050565b6100a481610092565b81146100ae575f80fd5b50565b5f813590506100bf8161009b565b92915050565b5f602082840312156100da576100d961008e565b5b5f6100e7848285016100b1565b91505092915050565b6100f981610092565b82525050565b5f6020820190506101125f8301846100f0565b9291505056fea264697066735822122055ccf41b608b610b0f0b3c6343fb66efe3d487da32a8a6981a907e22d0d4722e64736f6c63430008180033a264697066735822122076e62ebfbdf54923ba4920877ca4a8354142b8a1b5a18492fd7b0f1da3956cb964736f6c63430008180033 + +function hashes:s + +- 0d0b85f1: performTest() + +end + +# Create and fund new account +account_new acc1 10000000 + +# Create transaction to deploy TloadAfterSelfdestructPreExistingContract contract +transaction_build txDeployTestContract + sender acc1 + receiverAddress 00 + value 0 + data 608060405234801561000f575f80fd5b506104888061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c80630d0b85f11461002d575b5f80fd5b610035610037565b005b5f6040516100449061020a565b604051809103905ff08015801561005d573d5f803e3d5ffd5b5090505f8190505f805f807ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b9050604051818152600160048201526020816024835f8a5af19450604051828152600260048201526002816024835f8b5af194503d5f823e805193505050610108846040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e20310000008152506001610193565b610149836040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e20320000008152506001610193565b61018b826040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d206d6c6f616420300000000000815250610100610193565b505050505050565b8083036101cb577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a1610205565b7fc9e730d5b570f89e168eb8c3d29f8c396b957e540af248c95c9519ac47c2c69f82846040516101fc9291906102b9565b60405180910390a15b505050565b61016b806102e883390190565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561024e578082015181840152602081019050610233565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61027382610217565b61027d8185610221565b935061028d818560208601610231565b61029681610259565b840191505092915050565b5f819050919050565b6102b3816102a1565b82525050565b5f6040820190508181035f8301526102d18185610269565b90506102e060208301846102aa565b939250505056fe608060405234801561000f575f80fd5b5061014e8061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063fe0d94c11461002d575b5f80fd5b610047600480360381019061004291906100c5565b61005d565b60405161005491906100ff565b60405180910390f35b5f8160018114610074576002811461007d57610088565b61010060ff5d5fff5b60ff5c805f5260205ff35b50919050565b5f80fd5b5f819050919050565b6100a481610092565b81146100ae575f80fd5b50565b5f813590506100bf8161009b565b92915050565b5f602082840312156100da576100d961008e565b5b5f6100e7848285016100b1565b91505092915050565b6100f981610092565b82525050565b5f6020820190506101125f8301846100f0565b9291505056fea264697066735822122055ccf41b608b610b0f0b3c6343fb66efe3d487da32a8a6981a907e22d0d4722e64736f6c63430008180033a264697066735822122076e62ebfbdf54923ba4920877ca4a8354142b8a1b5a18492fd7b0f1da3956cb964736f6c63430008180033 + gas 1000000 + build + +# Create block to hold txDeployTestContract transaction +block_build b01 + parent g00 + transactions txDeployTestContract + gasLimit 1200000 + build + +# Connect block +block_connect b01 + +# Check b01 is best block +assert_best b01 + +# Create transaction to execute performTest function from contract +transaction_build txPerformTest + sender acc1 + nonce 1 + contract txDeployTestContract + value 0 + data 0d0b85f1 + gas 300000 + build + +# Create block to hold txPerformTest transaction +block_build b02 + parent b01 + transactions txPerformTest + gasLimit 350000 + build + +# Connect block +block_connect b02 + +# Check b02 is best block +assert_best b02 \ No newline at end of file diff --git a/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tload_after_selfdestruct_pre_existing_contract.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tload_after_selfdestruct_pre_existing_contract.txt new file mode 100644 index 0000000000..2ae3bbe240 --- /dev/null +++ b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tload_after_selfdestruct_pre_existing_contract.txt @@ -0,0 +1,130 @@ +comment + +// CONTRACT CODE +pragma solidity ^0.8.24; + +contract TloadAfterSelfdestructPreExistingContract { + Callee callee; + + constructor() { + callee = new Callee(); + } + + event OK(); + event ERROR(string, uint256); + + function performTest() external { + address calleeAddress = address(callee); + uint256 resultCallOption1; + uint256 resultCallOption2; + uint256 valueLoadedFromMemory; + bytes4 executeSignature = bytes4(keccak256("execute(uint256)")); + + assembly { + let availablePointerCallOption1 := mload(0x40) + mstore(availablePointerCallOption1, executeSignature) + mstore(add(availablePointerCallOption1, 4), 1) + resultCallOption1 := call(gas(), calleeAddress, 0, availablePointerCallOption1, 0x24, availablePointerCallOption1, 0x20) + + let availablePointerCallOption2 := mload(0x40) + mstore(availablePointerCallOption2, executeSignature) + mstore(add(availablePointerCallOption2, 4), 2) + resultCallOption2 := call(gas(), calleeAddress, 0, availablePointerCallOption2, 0x24, availablePointerCallOption2, 0x2) + + // Copy returndata into memory to retrieve the returned value + returndatacopy(availablePointerCallOption2, 0, returndatasize()) + valueLoadedFromMemory := mload(availablePointerCallOption2) + } + + checkReturnValueExpected(resultCallOption1, 'Checking result call option 1', 0x01); + checkReturnValueExpected(resultCallOption2, 'Checking result call option 2', 0x01); + checkReturnValueExpected(valueLoadedFromMemory, 'Checking value from mload 0', 0x100); + } + + function checkReturnValueExpected(uint256 valueReceived, string memory message, uint256 expectedValue) private { + if( valueReceived == expectedValue){ + emit OK(); + } else { + emit ERROR(message, valueReceived); + } + } +} + +contract Callee { + + function execute(uint256 callOption) external returns (uint256) { + assembly { + switch callOption + case 1 { + tstore(0xFF, 0x100) + selfdestruct(0) + } + case 2 { + // Load value from transient storage + let value := tload(0xFF) + mstore(0x00, value) // Store it in memory to return + return(0x00, 0x20) // Return 32 bytes from memory + } + } + } +} + +// DESCRIPTION + +// CONTRACT BYTECODE + +TloadAfterSelfdestructPreExistingContract: 608060405234801561000f575f80fd5b5060405161001c90610079565b604051809103905ff080158015610035573d5f803e3d5ffd5b505f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610086565b61016b8061039983390190565b610306806100935f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c80630d0b85f11461002d575b5f80fd5b610035610037565b005b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505f805f807ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b9050604051818152600160048201526020816024835f8a5af19450604051828152600260048201526002816024835f8b5af194503d5f823e8051935050506100ff846040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e20310000008152506001610189565b610140836040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e20320000008152506001610189565b610182826040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d206d6c6f616420300000000000815250610100610189565b5050505050565b8083036101c1577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a16101fb565b7fc9e730d5b570f89e168eb8c3d29f8c396b957e540af248c95c9519ac47c2c69f82846040516101f29291906102a2565b60405180910390a15b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561023757808201518184015260208101905061021c565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61025c82610200565b610266818561020a565b935061027681856020860161021a565b61027f81610242565b840191505092915050565b5f819050919050565b61029c8161028a565b82525050565b5f6040820190508181035f8301526102ba8185610252565b90506102c96020830184610293565b939250505056fea26469706673582212205534fa1e929c43e2b37b29d413d4548878f2de78cb0752060df934815275576864736f6c63430008180033608060405234801561000f575f80fd5b5061014e8061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063fe0d94c11461002d575b5f80fd5b610047600480360381019061004291906100c5565b61005d565b60405161005491906100ff565b60405180910390f35b5f8160018114610074576002811461007d57610088565b61010060ff5d5fff5b60ff5c805f5260205ff35b50919050565b5f80fd5b5f819050919050565b6100a481610092565b81146100ae575f80fd5b50565b5f813590506100bf8161009b565b92915050565b5f602082840312156100da576100d961008e565b5b5f6100e7848285016100b1565b91505092915050565b6100f981610092565b82525050565b5f6020820190506101125f8301846100f0565b9291505056fea26469706673582212209845c65124ff773997c6f9fecd143ae783a790c95fab788e181664dce3129d7d64736f6c63430008180033 + +function hashes:s + +- 0d0b85f1: performTest() + +end + +# Create and fund new account +account_new acc1 10000000 + +# Create transaction to deploy TloadAfterSelfdestructPreExistingContract contract +transaction_build txDeployTestContract + sender acc1 + receiverAddress 00 + value 0 + data 608060405234801561000f575f80fd5b5060405161001c90610079565b604051809103905ff080158015610035573d5f803e3d5ffd5b505f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610086565b61016b8061039983390190565b610306806100935f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c80630d0b85f11461002d575b5f80fd5b610035610037565b005b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505f805f807ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b9050604051818152600160048201526020816024835f8a5af19450604051828152600260048201526002816024835f8b5af194503d5f823e8051935050506100ff846040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e20310000008152506001610189565b610140836040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e20320000008152506001610189565b610182826040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d206d6c6f616420300000000000815250610100610189565b5050505050565b8083036101c1577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a16101fb565b7fc9e730d5b570f89e168eb8c3d29f8c396b957e540af248c95c9519ac47c2c69f82846040516101f29291906102a2565b60405180910390a15b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561023757808201518184015260208101905061021c565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61025c82610200565b610266818561020a565b935061027681856020860161021a565b61027f81610242565b840191505092915050565b5f819050919050565b61029c8161028a565b82525050565b5f6040820190508181035f8301526102ba8185610252565b90506102c96020830184610293565b939250505056fea26469706673582212205534fa1e929c43e2b37b29d413d4548878f2de78cb0752060df934815275576864736f6c63430008180033608060405234801561000f575f80fd5b5061014e8061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063fe0d94c11461002d575b5f80fd5b610047600480360381019061004291906100c5565b61005d565b60405161005491906100ff565b60405180910390f35b5f8160018114610074576002811461007d57610088565b61010060ff5d5fff5b60ff5c805f5260205ff35b50919050565b5f80fd5b5f819050919050565b6100a481610092565b81146100ae575f80fd5b50565b5f813590506100bf8161009b565b92915050565b5f602082840312156100da576100d961008e565b5b5f6100e7848285016100b1565b91505092915050565b6100f981610092565b82525050565b5f6020820190506101125f8301846100f0565b9291505056fea26469706673582212209845c65124ff773997c6f9fecd143ae783a790c95fab788e181664dce3129d7d64736f6c63430008180033 + gas 1000000 + build + +# Create block to hold txDeployTestContract transaction +block_build b01 + parent g00 + transactions txDeployTestContract + gasLimit 1200000 + build + +# Connect block +block_connect b01 + +# Check b01 is best block +assert_best b01 + +# Create transaction to execute performTest function from contract +transaction_build txPerformTest + sender acc1 + nonce 1 + contract txDeployTestContract + value 0 + data 0d0b85f1 + gas 300000 + build + +# Create block to hold txPerformTest transaction +block_build b02 + parent b01 + transactions txPerformTest + gasLimit 350000 + build + +# Connect block +block_connect b02 + +# Check b02 is best block +assert_best b02 \ No newline at end of file diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/tload_tstore_basic_tests.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tload_tstore_basic_tests.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/tload_tstore_basic_tests.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/tload_tstore_basic_tests.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/tstorage_gas_measure_tests.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tstorage_gas_measure_tests.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/tstorage_gas_measure_tests.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/tstorage_gas_measure_tests.txt diff --git a/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tstore_after_selfdestruct_new_contract.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tstore_after_selfdestruct_new_contract.txt new file mode 100644 index 0000000000..7902b36f36 --- /dev/null +++ b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tstore_after_selfdestruct_new_contract.txt @@ -0,0 +1,146 @@ +comment + +// CONTRACT CODE + +pragma solidity ^0.8.24; + +contract TstoreAfterSelfdestructingNewContract { + + constructor() { + } + + event OK(); + event ERROR(string, uint256); + + function performtTest() external { + Callee callee = new Callee(); + address calleeAddress = address(callee); + uint256 resultCallOption1; + uint256 resultCallOption2; + uint256 resultCallOption3; + uint256 valueLoadedFromMemory; + bytes4 executeSignature = bytes4(keccak256("execute(uint256)")); + + assembly { + // Call Option 1: Executes selfdestruct in callee contract + let availablePointerCallOption1 := mload(0x40) + mstore(availablePointerCallOption1, executeSignature) + mstore(add(availablePointerCallOption1, 4), 1) + resultCallOption1 := call(gas(), calleeAddress, 0, availablePointerCallOption1, 0x24, availablePointerCallOption1, 0x20) + + // Call Option 2: Executes tstore in callee contract + let availablePointerCallOption2 := mload(0x40) + mstore(availablePointerCallOption2, executeSignature) + mstore(add(availablePointerCallOption2, 4), 2) + resultCallOption2 := call(gas(), calleeAddress, 0, availablePointerCallOption2, 0x24, availablePointerCallOption2, 0x20) + + + // Call Option 3: Executes tload, store it in memory and return data + let availablePointerCallOption3 := mload(0x40) + mstore(availablePointerCallOption3, executeSignature) + mstore(add(availablePointerCallOption3, 4), 3) + resultCallOption3 := call(gas(), calleeAddress, 0, availablePointerCallOption3, 0x24, availablePointerCallOption3, 0x20) + + // Copy returndata into memory to retrieve the returned value + returndatacopy(availablePointerCallOption3, 0, returndatasize()) + valueLoadedFromMemory := mload(availablePointerCallOption3) + } + + checkReturnValueExpected(resultCallOption1, 'Checking result call option 1', 0x01); + checkReturnValueExpected(resultCallOption2, 'Checking result call option 2', 0x01); + checkReturnValueExpected(resultCallOption3, 'Checking result call option 3', 0x01); + checkReturnValueExpected(valueLoadedFromMemory, 'Checking value from mload 0', 0x100); + } + + function checkReturnValueExpected(uint256 valueReceived, string memory message, uint256 expectedValue) private { + if( valueReceived == expectedValue){ + emit OK(); + } else { + emit ERROR(message, valueReceived); + } + } +} + +contract Callee { + + event OK(); + event ERROR(string, uint256); + + function execute(uint256 callOption) external returns (uint256) { + assembly { + switch callOption + case 1 { + selfdestruct(0) + } + case 2 { + tstore(0xFF, 0x100) + } + case 3 { + // Load value from transient storage + let value := tload(0xFF) + mstore(0x00, value) // Store it in memory to return + return(0x00, 0x20) // Return 32 bytes from memory + } + } + } +} + +// DESCRIPTION + +// CONTRACT BYTECODE + +TstoreAfterSelfdestructingNewContract: 608060405234801561000f575f80fd5b506104f28061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c80630d0b85f11461002d575b5f80fd5b610035610037565b005b5f60405161004490610267565b604051809103905ff08015801561005d573d5f803e3d5ffd5b5090505f8190505f805f805f7ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b9050604051818152600160048201526020816024835f8b5af19550604051828152600260048201526020816024835f8c5af19550604051838152600360048201526020816024835f8d5af195503d5f823e80519450505050610123856040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e203100000081525060016101f0565b610164846040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e203200000081525060016101f0565b6101a5836040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e203300000081525060016101f0565b6101e7826040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d206d6c6f6164203000000000008152506101006101f0565b50505050505050565b808303610228577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a1610262565b7fc9e730d5b570f89e168eb8c3d29f8c396b957e540af248c95c9519ac47c2c69f8284604051610259929190610316565b60405180910390a15b505050565b6101788061034583390190565b5f81519050919050565b5f82825260208201905092915050565b5f5b838110156102ab578082015181840152602081019050610290565b5f8484015250505050565b5f601f19601f8301169050919050565b5f6102d082610274565b6102da818561027e565b93506102ea81856020860161028e565b6102f3816102b6565b840191505092915050565b5f819050919050565b610310816102fe565b82525050565b5f6040820190508181035f83015261032e81856102c6565b905061033d6020830184610307565b939250505056fe608060405234801561000f575f80fd5b5061015b8061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063fe0d94c11461002d575b5f80fd5b610047600480360381019061004291906100d2565b61005d565b604051610054919061010c565b60405180910390f35b5f816001811461007c576002811461007f576003811461008a57610095565b5fff5b61010060ff5d610095565b60ff5c805f5260205ff35b50919050565b5f80fd5b5f819050919050565b6100b18161009f565b81146100bb575f80fd5b50565b5f813590506100cc816100a8565b92915050565b5f602082840312156100e7576100e661009b565b5b5f6100f4848285016100be565b91505092915050565b6101068161009f565b82525050565b5f60208201905061011f5f8301846100fd565b9291505056fea264697066735822122052a1869c2ba9a2749479c068cda41ba0a57aa6967098ab6a0fdc351722448d5d64736f6c63430008180033a264697066735822122004e2a48494b3e22b144f5f63708a43173ddd8cff969f549ce7636f99245196da64736f6c63430008180033 + +function hashes: + +- 0d0b85f1: performTest() + +end + +# Create and fund new account +account_new acc1 10000000 + +# Create transaction to deploy TloadAfterSelfdestructPreExistingContract contract +transaction_build txDeployTestContract + sender acc1 + receiverAddress 00 + value 0 + data 608060405234801561000f575f80fd5b506104f28061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c80630d0b85f11461002d575b5f80fd5b610035610037565b005b5f60405161004490610267565b604051809103905ff08015801561005d573d5f803e3d5ffd5b5090505f8190505f805f805f7ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b9050604051818152600160048201526020816024835f8b5af19550604051828152600260048201526020816024835f8c5af19550604051838152600360048201526020816024835f8d5af195503d5f823e80519450505050610123856040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e203100000081525060016101f0565b610164846040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e203200000081525060016101f0565b6101a5836040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e203300000081525060016101f0565b6101e7826040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d206d6c6f6164203000000000008152506101006101f0565b50505050505050565b808303610228577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a1610262565b7fc9e730d5b570f89e168eb8c3d29f8c396b957e540af248c95c9519ac47c2c69f8284604051610259929190610316565b60405180910390a15b505050565b6101788061034583390190565b5f81519050919050565b5f82825260208201905092915050565b5f5b838110156102ab578082015181840152602081019050610290565b5f8484015250505050565b5f601f19601f8301169050919050565b5f6102d082610274565b6102da818561027e565b93506102ea81856020860161028e565b6102f3816102b6565b840191505092915050565b5f819050919050565b610310816102fe565b82525050565b5f6040820190508181035f83015261032e81856102c6565b905061033d6020830184610307565b939250505056fe608060405234801561000f575f80fd5b5061015b8061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063fe0d94c11461002d575b5f80fd5b610047600480360381019061004291906100d2565b61005d565b604051610054919061010c565b60405180910390f35b5f816001811461007c576002811461007f576003811461008a57610095565b5fff5b61010060ff5d610095565b60ff5c805f5260205ff35b50919050565b5f80fd5b5f819050919050565b6100b18161009f565b81146100bb575f80fd5b50565b5f813590506100cc816100a8565b92915050565b5f602082840312156100e7576100e661009b565b5b5f6100f4848285016100be565b91505092915050565b6101068161009f565b82525050565b5f60208201905061011f5f8301846100fd565b9291505056fea264697066735822122052a1869c2ba9a2749479c068cda41ba0a57aa6967098ab6a0fdc351722448d5d64736f6c63430008180033a264697066735822122004e2a48494b3e22b144f5f63708a43173ddd8cff969f549ce7636f99245196da64736f6c63430008180033 + gas 1000000 + build + +# Create block to hold txDeployTestContract transaction +block_build b01 + parent g00 + transactions txDeployTestContract + gasLimit 1200000 + build + +# Connect block +block_connect b01 + +# Check b01 is best block +assert_best b01 + +# Create transaction to execute performTest function from contract +transaction_build txPerformTest + sender acc1 + nonce 1 + contract txDeployTestContract + value 0 + data 0d0b85f1 + gas 300000 + build + +# Create block to hold txPerformTest transaction +block_build b02 + parent b01 + transactions txPerformTest + gasLimit 350000 + build + +# Connect block +block_connect b02 + +# Check b02 is best block +assert_best b02 \ No newline at end of file diff --git a/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tstore_after_selfdestruct_pre_existing_contract.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tstore_after_selfdestruct_pre_existing_contract.txt new file mode 100644 index 0000000000..3766de4765 --- /dev/null +++ b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tstore_after_selfdestruct_pre_existing_contract.txt @@ -0,0 +1,147 @@ +comment + +// CONTRACT CODE + +pragma solidity ^0.8.24; + +contract TstoreAfterSelfdestructingPreExistingContract { + Callee callee; + + constructor() { + callee = new Callee(); + } + + event OK(); + event ERROR(string, uint256); + + function performTest() external { + address calleeAddress = address(callee); + uint256 resultCallOption1; + uint256 resultCallOption2; + uint256 resultCallOption3; + uint256 valueLoadedFromMemory; + bytes4 executeSignature = bytes4(keccak256("execute(uint256)")); + + assembly { + // Call Option 1: Executes selfdestruct in callee contract + let availablePointerCallOption1 := mload(0x40) + mstore(availablePointerCallOption1, executeSignature) + mstore(add(availablePointerCallOption1, 4), 1) + resultCallOption1 := call(gas(), calleeAddress, 0, availablePointerCallOption1, 0x24, availablePointerCallOption1, 0x20) + + // Call Option 2: Executes tstore in callee contract + let availablePointerCallOption2 := mload(0x40) + mstore(availablePointerCallOption2, executeSignature) + mstore(add(availablePointerCallOption2, 4), 2) + resultCallOption2 := call(gas(), calleeAddress, 0, availablePointerCallOption2, 0x24, availablePointerCallOption2, 0x20) + + + // Call Option 3: Executes tload, store it in memory and return data + let availablePointerCallOption3 := mload(0x40) + mstore(availablePointerCallOption3, executeSignature) + mstore(add(availablePointerCallOption3, 4), 3) + resultCallOption3 := call(gas(), calleeAddress, 0, availablePointerCallOption3, 0x24, availablePointerCallOption3, 0x20) + + // Copy returndata into memory to retrieve the returned value + returndatacopy(availablePointerCallOption3, 0, returndatasize()) + valueLoadedFromMemory := mload(availablePointerCallOption3) + } + + checkReturnValueExpected(resultCallOption1, 'Checking result call option 1', 0x01); + checkReturnValueExpected(resultCallOption2, 'Checking result call option 2', 0x01); + checkReturnValueExpected(resultCallOption3, 'Checking result call option 3', 0x01); + checkReturnValueExpected(valueLoadedFromMemory, 'Checking value from mload 0', 0x100); + } + + function checkReturnValueExpected(uint256 valueReceived, string memory message, uint256 expectedValue) private { + if( valueReceived == expectedValue){ + emit OK(); + } else { + emit ERROR(message, valueReceived); + } + } +} + +contract Callee { + + event OK(); + event ERROR(string, uint256); + + function execute(uint256 callOption) external returns (uint256) { + assembly { + switch callOption + case 1 { + selfdestruct(0) + } + case 2 { + tstore(0xFF, 0x100) + } + case 3 { + // Load value from transient storage + let value := tload(0xFF) + mstore(0x00, value) // Store it in memory to return + return(0x00, 0x20) // Return 32 bytes from memory + } + } + } +} + +// DESCRIPTION + +// CONTRACT BYTECODE + +TstoreAfterSelfdestructingPreExistingContract: 608060405234801561000f575f80fd5b5060405161001c90610079565b604051809103905ff080158015610035573d5f803e3d5ffd5b505f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610086565b610178806103f683390190565b610363806100935f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c80630d0b85f11461002d575b5f80fd5b610035610037565b005b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505f805f805f7ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b9050604051818152600160048201526020816024835f8b5af19550604051828152600260048201526020816024835f8c5af19550604051838152600360048201526020816024835f8d5af195503d5f823e8051945050505061011a856040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e203100000081525060016101e6565b61015b846040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e203200000081525060016101e6565b61019c836040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e203300000081525060016101e6565b6101de826040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d206d6c6f6164203000000000008152506101006101e6565b505050505050565b80830361021e577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a1610258565b7fc9e730d5b570f89e168eb8c3d29f8c396b957e540af248c95c9519ac47c2c69f828460405161024f9291906102ff565b60405180910390a15b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b83811015610294578082015181840152602081019050610279565b5f8484015250505050565b5f601f19601f8301169050919050565b5f6102b98261025d565b6102c38185610267565b93506102d3818560208601610277565b6102dc8161029f565b840191505092915050565b5f819050919050565b6102f9816102e7565b82525050565b5f6040820190508181035f83015261031781856102af565b905061032660208301846102f0565b939250505056fea2646970667358221220430065adaea3ec55b26991f3b100cb73215160e30134979bc834001868b7049464736f6c63430008180033608060405234801561000f575f80fd5b5061015b8061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063fe0d94c11461002d575b5f80fd5b610047600480360381019061004291906100d2565b61005d565b604051610054919061010c565b60405180910390f35b5f816001811461007c576002811461007f576003811461008a57610095565b5fff5b61010060ff5d610095565b60ff5c805f5260205ff35b50919050565b5f80fd5b5f819050919050565b6100b18161009f565b81146100bb575f80fd5b50565b5f813590506100cc816100a8565b92915050565b5f602082840312156100e7576100e661009b565b5b5f6100f4848285016100be565b91505092915050565b6101068161009f565b82525050565b5f60208201905061011f5f8301846100fd565b9291505056fea26469706673582212202863e4706ef82faa6ad13fcf9e1ee1699e2008d0c74aa076910f6421a8bacd5b64736f6c63430008180033 + +function hashes: + +- 0d0b85f1: performTest() + +end + +# Create and fund new account +account_new acc1 10000000 + +# Create transaction to deploy TloadAfterSelfdestructPreExistingContract contract +transaction_build txDeployTestContract + sender acc1 + receiverAddress 00 + value 0 + data 608060405234801561000f575f80fd5b5060405161001c90610079565b604051809103905ff080158015610035573d5f803e3d5ffd5b505f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610086565b610178806103f683390190565b610363806100935f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c80630d0b85f11461002d575b5f80fd5b610035610037565b005b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505f805f805f7ffe0d94c1a8f5608a1172c49cc7704ac011b690506896af15ba9aab651ff44e1b9050604051818152600160048201526020816024835f8b5af19550604051828152600260048201526020816024835f8c5af19550604051838152600360048201526020816024835f8d5af195503d5f823e8051945050505061011a856040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e203100000081525060016101e6565b61015b846040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e203200000081525060016101e6565b61019c836040518060400160405280601d81526020017f436865636b696e6720726573756c742063616c6c206f7074696f6e203300000081525060016101e6565b6101de826040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d206d6c6f6164203000000000008152506101006101e6565b505050505050565b80830361021e577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a1610258565b7fc9e730d5b570f89e168eb8c3d29f8c396b957e540af248c95c9519ac47c2c69f828460405161024f9291906102ff565b60405180910390a15b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b83811015610294578082015181840152602081019050610279565b5f8484015250505050565b5f601f19601f8301169050919050565b5f6102b98261025d565b6102c38185610267565b93506102d3818560208601610277565b6102dc8161029f565b840191505092915050565b5f819050919050565b6102f9816102e7565b82525050565b5f6040820190508181035f83015261031781856102af565b905061032660208301846102f0565b939250505056fea2646970667358221220430065adaea3ec55b26991f3b100cb73215160e30134979bc834001868b7049464736f6c63430008180033608060405234801561000f575f80fd5b5061015b8061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063fe0d94c11461002d575b5f80fd5b610047600480360381019061004291906100d2565b61005d565b604051610054919061010c565b60405180910390f35b5f816001811461007c576002811461007f576003811461008a57610095565b5fff5b61010060ff5d610095565b60ff5c805f5260205ff35b50919050565b5f80fd5b5f819050919050565b6100b18161009f565b81146100bb575f80fd5b50565b5f813590506100cc816100a8565b92915050565b5f602082840312156100e7576100e661009b565b5b5f6100f4848285016100be565b91505092915050565b6101068161009f565b82525050565b5f60208201905061011f5f8301846100fd565b9291505056fea26469706673582212202863e4706ef82faa6ad13fcf9e1ee1699e2008d0c74aa076910f6421a8bacd5b64736f6c63430008180033 + gas 1000000 + build + +# Create block to hold txDeployTestContract transaction +block_build b01 + parent g00 + transactions txDeployTestContract + gasLimit 1200000 + build + +# Connect block +block_connect b01 + +# Check b01 is best block +assert_best b01 + +# Create transaction to execute performTest function from contract +transaction_build txPerformTest + sender acc1 + nonce 1 + contract txDeployTestContract + value 0 + data 0d0b85f1 + gas 300000 + build + +# Create block to hold txPerformTest transaction +block_build b02 + parent b01 + transactions txPerformTest + gasLimit 350000 + build + +# Connect block +block_connect b02 + +# Check b02 is best block +assert_best b02 \ No newline at end of file diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/tstore_and_tload_loop_until_out_of_gas.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tstore_and_tload_loop_until_out_of_gas.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/tstore_and_tload_loop_until_out_of_gas.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/tstore_and_tload_loop_until_out_of_gas.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/tstore_loop_until_out_of_gas.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tstore_loop_until_out_of_gas.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/tstore_loop_until_out_of_gas.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/tstore_loop_until_out_of_gas.txt diff --git a/rskj-core/src/test/resources/dsl/transaction_storage_rskip446/tstore_wide_address_space_loop_until_out_of_gas.txt b/rskj-core/src/test/resources/dsl/transient_storage_rskip446/tstore_wide_address_space_loop_until_out_of_gas.txt similarity index 100% rename from rskj-core/src/test/resources/dsl/transaction_storage_rskip446/tstore_wide_address_space_loop_until_out_of_gas.txt rename to rskj-core/src/test/resources/dsl/transient_storage_rskip446/tstore_wide_address_space_loop_until_out_of_gas.txt