From 30d814780fcb33149984b7b7709a58ad82e30ddb Mon Sep 17 00:00:00 2001 From: yperbasis Date: Tue, 7 Sep 2021 16:41:26 +0200 Subject: [PATCH 1/4] Move test_util to core --- {node => core}/silkworm/common/test_util.cpp | 0 {node => core}/silkworm/common/test_util.hpp | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {node => core}/silkworm/common/test_util.cpp (100%) rename {node => core}/silkworm/common/test_util.hpp (100%) diff --git a/node/silkworm/common/test_util.cpp b/core/silkworm/common/test_util.cpp similarity index 100% rename from node/silkworm/common/test_util.cpp rename to core/silkworm/common/test_util.cpp diff --git a/node/silkworm/common/test_util.hpp b/core/silkworm/common/test_util.hpp similarity index 100% rename from node/silkworm/common/test_util.hpp rename to core/silkworm/common/test_util.hpp From 9c3a50570b9f02f60998f41e30930a641b635071 Mon Sep 17 00:00:00 2001 From: yperbasis Date: Tue, 7 Sep 2021 17:02:49 +0200 Subject: [PATCH 2/4] EIP-3607: Reject transactions from senders with deployed code --- core/silkworm/chain/validity.hpp | 29 ++++++++++--------- core/silkworm/execution/processor.cpp | 4 +++ core/silkworm/execution/processor_test.cpp | 33 ++++++++++++++++++---- core/silkworm/rlp/decode_test.cpp | 2 -- 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/core/silkworm/chain/validity.hpp b/core/silkworm/chain/validity.hpp index 1c9c1a060f..9a7f1cabbf 100644 --- a/core/silkworm/chain/validity.hpp +++ b/core/silkworm/chain/validity.hpp @@ -48,27 +48,28 @@ enum class [[nodiscard]] ValidationResult{ // See [YP] Section 6.2 "Execution", Eq (58) kMissingSender = 15, // S(T) = ∅ - kWrongNonce = 16, // Tn ≠ σ[S(T)]n - kIntrinsicGas = 17, // g0 > Tg - kInsufficientFunds = 18, // v0 > σ[S(T)]b - kBlockGasLimitExceeded = 19, // Tg > BHl - l(BR)u - kMaxFeeLessThanBase = 20, // max_fee_per_gas < base_fee_per_gas (EIP-1559) - kMaxPriorityFeeGreaterThanMax = 21, // max_priority_fee_per_gas > max_fee_per_gas (EIP-1559) + kSenderNoEOA = 16, // EIP-3607: σ[S(T)]c ≠ KEC( () ) + kWrongNonce = 17, // Tn ≠ σ[S(T)]n + kIntrinsicGas = 18, // g0 > Tg + kInsufficientFunds = 19, // v0 > σ[S(T)]b + kBlockGasLimitExceeded = 20, // Tg > BHl - l(BR)u + kMaxFeeLessThanBase = 21, // max_fee_per_gas < base_fee_per_gas (EIP-1559) + kMaxPriorityFeeGreaterThanMax = 22, // max_priority_fee_per_gas > max_fee_per_gas (EIP-1559) // See [YP] Section 11.1 "Ommer Validation", Eq (157) - kTooManyOmmers = 22, // ‖BU‖ > 2 - kInvalidOmmerHeader = 23, // ¬V(U) - kNotAnOmmer = 24, // ¬k(U, P(BH)H, 6) - kDuplicateOmmer = 25, // not well covered by the YP actually + kTooManyOmmers = 23, // ‖BU‖ > 2 + kInvalidOmmerHeader = 24, // ¬V(U) + kNotAnOmmer = 25, // ¬k(U, P(BH)H, 6) + kDuplicateOmmer = 26, // not well covered by the YP actually // See [YP] Section 11.2 "Transaction Validation", Eq (160) - kWrongBlockGas = 26, // BHg ≠ l(BR)u + kWrongBlockGas = 27, // BHg ≠ l(BR)u - kInvalidSignature = 27, // EIP-2 + kInvalidSignature = 28, // EIP-2 - kWrongChainId = 28, // EIP-155 + kWrongChainId = 29, // EIP-155 - kUnsupportedTransactionType = 29, // EIP-2718 + kUnsupportedTransactionType = 30, // EIP-2718 }; // Performs validation of a transaction that can be done prior to sender recovery and block execution. diff --git a/core/silkworm/execution/processor.cpp b/core/silkworm/execution/processor.cpp index 01459eb60f..2b8d88eae2 100644 --- a/core/silkworm/execution/processor.cpp +++ b/core/silkworm/execution/processor.cpp @@ -36,6 +36,10 @@ ValidationResult ExecutionProcessor::validate_transaction(const Transaction& txn return ValidationResult::kMissingSender; } + if (state_.get_code_hash(*txn.from) != kEmptyHash) { + return ValidationResult::kSenderNoEOA; // EIP-3607 + } + const uint64_t nonce{state_.get_nonce(*txn.from)}; if (nonce != txn.nonce) { return ValidationResult::kWrongNonce; diff --git a/core/silkworm/execution/processor_test.cpp b/core/silkworm/execution/processor_test.cpp index 23d219d641..0f9c16604b 100644 --- a/core/silkworm/execution/processor_test.cpp +++ b/core/silkworm/execution/processor_test.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include "address.hpp" @@ -28,8 +29,6 @@ namespace silkworm { TEST_CASE("Zero gas price") { - using Catch::Message; - Block block{}; block.header.number = 2'687'232; block.header.gas_limit = 3'303'221; @@ -63,6 +62,26 @@ TEST_CASE("Zero gas price") { CHECK(receipt.success); } +TEST_CASE("EIP-3607: Reject transactions from senders with deployed code") { + Block block{}; + block.header.number = 1; + block.header.gas_limit = 3'000'000; + + const evmc::address sender{0x71562b71999873DB5b286dF957af199Ec94617F7_address}; + + Transaction txn{test_util::sample_transactions()[0]}; + txn.nonce = 0; + txn.from = sender; + + InMemoryState state; + ExecutionProcessor processor{block, state, kMainnetConfig}; + + processor.evm().state().add_to_balance(sender, 10 * kEther); + processor.evm().state().set_code(sender, *from_hex("B0B0FACE")); + + CHECK(processor.validate_transaction(txn) == ValidationResult::kSenderNoEOA); +} + TEST_CASE("No refund on error") { Block block{}; block.header.number = 10'050'107; @@ -139,8 +158,10 @@ TEST_CASE("Self-destruct") { block.header.number = 1'487'375; block.header.gas_limit = 4'712'388; block.header.beneficiary = 0x61c808d82a3ac53231750dadc13c777b59310bd9_address; - evmc::address suicidal_address{0x6d20c1c07e56b7098eb8c50ee03ba0f6f498a91d_address}; - evmc::address caller_address{0x4bf2054ffae7a454a35fd8cf4be21b23b1f25a6f_address}; + + const evmc::address suicidal_address{0x6d20c1c07e56b7098eb8c50ee03ba0f6f498a91d_address}; + const evmc::address caller_address{0x4bf2054ffae7a454a35fd8cf4be21b23b1f25a6f_address}; + const evmc::address originator{0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c_address}; // The contract self-destructs if called with zero value. Bytes suicidal_code{*from_hex("346007576000ff5b")}; @@ -191,7 +212,7 @@ TEST_CASE("Self-destruct") { InMemoryState state; ExecutionProcessor processor{block, state, kMainnetConfig}; - processor.evm().state().add_to_balance(caller_address, kEther); + processor.evm().state().add_to_balance(originator, kEther); processor.evm().state().set_code(caller_address, caller_code); processor.evm().state().set_code(suicidal_address, suicidal_code); @@ -209,7 +230,7 @@ TEST_CASE("Self-destruct") { 1, // r 1, // s }; - txn.from = caller_address; + txn.from = originator; evmc::bytes32 address_as_hash{to_bytes32(full_view(suicidal_address))}; txn.data = full_view(address_as_hash); diff --git a/core/silkworm/rlp/decode_test.cpp b/core/silkworm/rlp/decode_test.cpp index 05e6c32a95..a62d0863bb 100644 --- a/core/silkworm/rlp/decode_test.cpp +++ b/core/silkworm/rlp/decode_test.cpp @@ -51,8 +51,6 @@ static std::vector decode_vector_success(std::string_view hex) { } TEST_CASE("RLP decoding") { - using Catch::Message; - SECTION("strings") { CHECK(to_hex(decode_success("00")) == "00"); CHECK(to_hex(decode_success("8D6F62636465666768696A6B6C6D")) == "6f62636465666768696a6b6c6d"); From 0a44f7da8c4fada269cdc7d820d80c9fe36837df Mon Sep 17 00:00:00 2001 From: yperbasis Date: Tue, 7 Sep 2021 17:05:25 +0200 Subject: [PATCH 3/4] Update consensus tests to 9.0.5 --- tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests b/tests index 5d534e37b8..6f41f7b617 160000 --- a/tests +++ b/tests @@ -1 +1 @@ -Subproject commit 5d534e37b80e9310e8c7751f805ca481a451123e +Subproject commit 6f41f7b6171f6da759060db177b440030dadd5b0 From 5ad67bfeeec893601ec2d94b2d05b5b40bf3585d Mon Sep 17 00:00:00 2001 From: yperbasis Date: Tue, 7 Sep 2021 17:35:37 +0200 Subject: [PATCH 4/4] Bump no_output_timeout --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e6a54c9704..baa6598793 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -100,7 +100,7 @@ jobs: - run: name: "Ethereum consensus tests" working_directory: ~/build - no_output_timeout: 15m + no_output_timeout: 20m command: | cmd/consensus mv default.profraw consensus.profraw