From 359ad2afc88534687a49dd24f3e4b005900d28de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 21 Jan 2025 13:57:50 +0100 Subject: [PATCH 1/3] evm: refactor bailout option handling Implement the bailout option by pure state modification before the transaction validation and execution. --- silkworm/core/execution/processor.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/silkworm/core/execution/processor.cpp b/silkworm/core/execution/processor.cpp index 6b42762249..04f2260f45 100644 --- a/silkworm/core/execution/processor.cpp +++ b/silkworm/core/execution/processor.cpp @@ -264,10 +264,6 @@ CallResult ExecutionProcessor::call(const Transaction& txn, const std::vector(g0)); From bd7a32d4c306dc26d5f011b2250c6f7f837db76f Mon Sep 17 00:00:00 2001 From: lupin012 <58134934+lupin012@users.noreply.github.com.> Date: Thu, 30 Jan 2025 17:19:57 +0100 Subject: [PATCH 2/3] fix on calculation required_funds in case of bailout --- silkworm/core/execution/processor.cpp | 5 ++++- silkworm/core/protocol/validation.cpp | 20 ++++++++++++++------ silkworm/core/protocol/validation.hpp | 2 ++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/silkworm/core/execution/processor.cpp b/silkworm/core/execution/processor.cpp index 04f2260f45..997dd00825 100644 --- a/silkworm/core/execution/processor.cpp +++ b/silkworm/core/execution/processor.cpp @@ -280,11 +280,14 @@ CallResult ExecutionProcessor::call(const Transaction& txn, const std::vector= evm.block().header.base_fee_per_gas ? txn.effective_gas_price(base_fee) : txn.max_priority_fee_per_gas}; - const auto required_funds = compute_call_cost(txn, effective_gas_price, evm); - intx::uint512 maximum_cost = required_funds; - if (txn.type != TransactionType::kLegacy && txn.type != TransactionType::kAccessList) { - maximum_cost = txn.maximum_gas_cost(); - } - if (owned_funds < maximum_cost + txn.value) { + const auto required_funds = compute_call_required_funds(txn, effective_gas_price, evm); + if (owned_funds < required_funds) { return ValidationResult::kInsufficientFunds; } return ValidationResult::kOk; @@ -258,6 +254,18 @@ intx::uint256 compute_call_cost(const Transaction& txn, const intx::uint256& eff return required_funds; } +intx::uint256 compute_call_required_funds(const Transaction& txn, const intx::uint256& effective_gas_price, const EVM& evm) { + auto required_funds = compute_call_cost(txn, effective_gas_price, evm); + + intx::uint512 maximum_cost = required_funds; + if (txn.type != TransactionType::kLegacy && txn.type != TransactionType::kAccessList) { + maximum_cost = txn.maximum_gas_cost(); + } + + return static_cast(maximum_cost) + txn.value; +} + + intx::uint256 expected_base_fee_per_gas(const BlockHeader& parent) { if (!parent.base_fee_per_gas) { return kInitialBaseFee; diff --git a/silkworm/core/protocol/validation.hpp b/silkworm/core/protocol/validation.hpp index 6cdde03597..5c9e5b86aa 100644 --- a/silkworm/core/protocol/validation.hpp +++ b/silkworm/core/protocol/validation.hpp @@ -149,6 +149,8 @@ namespace protocol { intx::uint256 compute_call_cost(const Transaction& txn, const intx::uint256& effective_gas_price, const EVM& evm); + intx::uint256 compute_call_required_funds(const Transaction& txn, const intx::uint256& effective_gas_price, const EVM& evm); + //! \see EIP-1559: Fee market change for ETH 1.0 chain intx::uint256 expected_base_fee_per_gas(const BlockHeader& parent); From a9e88410c31ebf5cd28cf79e2f3cce6f80838858 Mon Sep 17 00:00:00 2001 From: GitHub Date: Thu, 30 Jan 2025 16:20:35 +0000 Subject: [PATCH 3/3] make fmt --- silkworm/core/protocol/validation.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/silkworm/core/protocol/validation.cpp b/silkworm/core/protocol/validation.cpp index f651015c28..47565ef66b 100644 --- a/silkworm/core/protocol/validation.cpp +++ b/silkworm/core/protocol/validation.cpp @@ -265,7 +265,6 @@ intx::uint256 compute_call_required_funds(const Transaction& txn, const intx::ui return static_cast(maximum_cost) + txn.value; } - intx::uint256 expected_base_fee_per_gas(const BlockHeader& parent) { if (!parent.base_fee_per_gas) { return kInitialBaseFee;