From df09b012894bf80b3aaf772dee8fff471d919e83 Mon Sep 17 00:00:00 2001 From: Matias Romeo Date: Tue, 4 Jun 2024 02:53:30 -0300 Subject: [PATCH 1/6] Restrict rlp formats when decoding transaction --- include/evm_runtime/transaction.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/evm_runtime/transaction.hpp b/include/evm_runtime/transaction.hpp index 4d1eab30..5d0fe228 100644 --- a/include/evm_runtime/transaction.hpp +++ b/include/evm_runtime/transaction.hpp @@ -32,7 +32,7 @@ struct transaction { eosio::check(rlptx_.has_value(), "no rlptx"); ByteView bv{(const uint8_t*)rlptx_->data(), rlptx_->size()}; silkworm::Transaction tmp; - eosio::check(silkworm::rlp::decode_transaction(bv, tmp, silkworm::rlp::Eip2718Wrapping::kBoth) && bv.empty(), "unable to decode transaction"); + eosio::check(silkworm::rlp::decode_transaction(bv, tmp, silkworm::rlp::Eip2718Wrapping::kNone) && bv.empty(), "unable to decode transaction"); tx_.emplace(tmp); } return tx_.value(); @@ -50,4 +50,4 @@ struct transaction { mutable std::optional tx_; }; -} //namespace evm_runtime \ No newline at end of file +} //namespace evm_runtime From 11dc563ed750685f61093902e2c9cb861c1434b2 Mon Sep 17 00:00:00 2001 From: Matias Romeo Date: Tue, 4 Jun 2024 02:57:28 -0300 Subject: [PATCH 2/6] Fix test_actions --- src/test_actions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test_actions.cpp b/src/test_actions.cpp index 7f6c3bbf..1425772d 100644 --- a/src/test_actions.cpp +++ b/src/test_actions.cpp @@ -24,7 +24,7 @@ using namespace silkworm; if(orlptx) { Transaction tx; ByteView bv{(const uint8_t*)orlptx->data(), orlptx->size()}; - eosio::check(rlp::decode(bv,tx) && bv.empty(), "unable to decode transaction"); + eosio::check(rlp::decode_transaction(bv, tx, rlp::Eip2718Wrapping::kNone) && bv.empty(), "unable to decode transaction"); runtime_config rc { .allow_special_signature = false, From bdca3185d0031e43ff488aba5f96a8e7a7372959 Mon Sep 17 00:00:00 2001 From: Matias Romeo Date: Tue, 4 Jun 2024 14:36:57 -0300 Subject: [PATCH 3/6] Use the valid encoding of non-legacy transactions in unit_tests --- tests/basic_evm_tester.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/basic_evm_tester.cpp b/tests/basic_evm_tester.cpp index 07bd5e58..2fcd6844 100644 --- a/tests/basic_evm_tester.cpp +++ b/tests/basic_evm_tester.cpp @@ -440,7 +440,7 @@ transaction_trace_ptr basic_evm_tester::assertnonce(name account, uint64_t next_ transaction_trace_ptr basic_evm_tester::pushtx(const silkworm::Transaction& trx, name miner, std::optional min_inclusion_price) { silkworm::Bytes rlp; - silkworm::rlp::encode(rlp, trx); + silkworm::rlp::encode(rlp, trx, false); bytes rlp_bytes; rlp_bytes.resize(rlp.size()); From 5455f04779b22e43905efbb5b639136bad7b57a7 Mon Sep 17 00:00:00 2001 From: Matias Romeo Date: Tue, 4 Jun 2024 17:22:27 -0300 Subject: [PATCH 4/6] Fix test_actions --- src/test_actions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test_actions.cpp b/src/test_actions.cpp index 1425772d..6b84c5d4 100644 --- a/src/test_actions.cpp +++ b/src/test_actions.cpp @@ -24,7 +24,7 @@ using namespace silkworm; if(orlptx) { Transaction tx; ByteView bv{(const uint8_t*)orlptx->data(), orlptx->size()}; - eosio::check(rlp::decode_transaction(bv, tx, rlp::Eip2718Wrapping::kNone) && bv.empty(), "unable to decode transaction"); + eosio::check(rlp::decode_transaction(bv, tx, rlp::Eip2718Wrapping::kString) && bv.empty(), "unable to decode transaction"); runtime_config rc { .allow_special_signature = false, @@ -378,4 +378,4 @@ using namespace silkworm; } } -} \ No newline at end of file +} From 6864b194375009c72130fa0aa765bf2682ee11a6 Mon Sep 17 00:00:00 2001 From: Matias Romeo Date: Thu, 6 Jun 2024 20:57:29 -0300 Subject: [PATCH 5/6] Add pushtx encoding tests --- tests/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8ce09740..7499bf0a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,6 +22,7 @@ include_directories( ) add_eosio_test_executable( unit_test + ${CMAKE_SOURCE_DIR}/rlp_encoding_tests.cpp ${CMAKE_SOURCE_DIR}/different_gas_token_tests.cpp ${CMAKE_SOURCE_DIR}/version_tests.cpp ${CMAKE_SOURCE_DIR}/account_id_tests.cpp From d6f291baaa8edbd9242d36cf089d002a6047f3ac Mon Sep 17 00:00:00 2001 From: Matias Romeo Date: Thu, 6 Jun 2024 21:03:04 -0300 Subject: [PATCH 6/6] Add missing source file --- tests/rlp_encoding_tests.cpp | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/rlp_encoding_tests.cpp diff --git a/tests/rlp_encoding_tests.cpp b/tests/rlp_encoding_tests.cpp new file mode 100644 index 00000000..e10b6adc --- /dev/null +++ b/tests/rlp_encoding_tests.cpp @@ -0,0 +1,55 @@ +#include "basic_evm_tester.hpp" +#include + +using namespace evm_test; +struct rlp_encoding_tester : basic_evm_tester { + rlp_encoding_tester() { + create_accounts({"alice"_n}); + transfer_token(faucet_account_name, "alice"_n, make_asset(10000'0000)); + init(); + } + + transaction_trace_ptr my_pushtx(const silkworm::Transaction& trx, bool wrap_eip2718_into_string) + { + silkworm::Bytes rlp; + silkworm::rlp::encode(rlp, trx, wrap_eip2718_into_string); + + bytes rlp_bytes; + rlp_bytes.resize(rlp.size()); + memcpy(rlp_bytes.data(), rlp.data(), rlp.size()); + + return push_action(evm_account_name, "pushtx"_n, evm_account_name, mvo()("miner", evm_account_name)("rlptx", rlp_bytes)); + } + +}; + +BOOST_AUTO_TEST_SUITE(rlp_encoding_tests) + +BOOST_FIXTURE_TEST_CASE(wrap_tx_in_string, rlp_encoding_tester) try { + + setversion(1, evm_account_name); + produce_blocks(2); + + // Fund evm1 address with 10.0000 EOS (triggers version 1 change) + evm_eoa evm1; + transfer_token("alice"_n, evm_account_name, make_asset(10'0000), evm1.address_0x()); + + evm_eoa evm2; + + auto tx = generate_tx(evm2.address, 1); + tx.type = silkworm::TransactionType::kDynamicFee; + tx.max_priority_fee_per_gas = 0; + tx.max_fee_per_gas = suggested_gas_price; + + evm1.sign(tx); + + // Wrap kDynamicFee tx in string + BOOST_REQUIRE_EXCEPTION(my_pushtx(tx, true), eosio_assert_message_exception, + [](const eosio_assert_message_exception& e) {return testing::expect_assert_message(e, "unable to decode transaction");}); + + // Don't wrap kDynamicFee tx in string + BOOST_CHECK_NO_THROW(my_pushtx(tx, false)); + +} FC_LOG_AND_RETHROW() + +BOOST_AUTO_TEST_SUITE_END()