Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpcdaemon: add blob check on evm executor #1990

Merged
merged 6 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rpc-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Checkout RPC Tests Repository & Install Requirements
run: |
rm -rf ${{runner.workspace}}/rpc-tests
git -c advice.detachedHead=false clone --depth 1 --branch v0.12.0 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
git -c advice.detachedHead=false clone --depth 1 --branch v0.16.0 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
cd ${{runner.workspace}}/rpc-tests
pip3 install -r requirements.txt

Expand Down
26 changes: 26 additions & 0 deletions silkworm/rpc/core/evm_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,23 @@ std::optional<EVMExecutor::PreCheckResult> EVMExecutor::pre_check(const EVM& evm
}
}
}

if (evm.block().header.blob_gas_used && rev >= EVMC_CANCUN) {
if (evm.block().header.excess_blob_gas) {
std::string error = "internal Error Cancun is active but ExcessBlobGas is nil";
return PreCheckResult{error, PreCheckErrorCode::kInternalError};
}
auto blob_gas_price = evm.block().header.blob_gas_price();
auto max_fee_per_blob_gas = txn.max_fee_per_blob_gas;
if (blob_gas_price > max_fee_per_blob_gas) {
std::string from = address_to_hex(*txn.sender());
std::string error = "max fee per blob gas too low: address " + from + ", maxFeePerBlobGas: " + intx::to_string(max_fee_per_blob_gas) +
" blobGasPrice: " + intx::to_string(*blob_gas_price) +
", excessBlobGas: " + std::to_string(*evm.block().header.excess_blob_gas);
return PreCheckResult{error, PreCheckErrorCode::kMaxFeePerBlobGasTooLowError};
}
}

if (txn.gas_limit < g0) {
std::string from = address_to_hex(*txn.sender());
std::string error = "intrinsic gas too low: address " + from + ", have " + std::to_string(txn.gas_limit) + ", want " + intx::to_string(g0);
Expand Down Expand Up @@ -246,6 +263,7 @@ ExecutionResult EVMExecutor::call(
return {std::nullopt, txn.gas_limit, data, pre_check_result->pre_check_error, pre_check_result->pre_check_error_code};
}

// EIP-1559 normal gas cost
intx::uint256 want;
if (txn.max_fee_per_gas > 0 || txn.max_priority_fee_per_gas > 0) {
// This method should be called after check (max_fee and base_fee) present in pre_check() method
Expand All @@ -254,6 +272,14 @@ ExecutionResult EVMExecutor::call(
} else {
want = 0;
}

// EIP-4844 blob gas cost (calc_data_fee)
if (evm.block().header.blob_gas_used && rev >= EVMC_CANCUN) {
// compute blob fee for eip-4844 data blobs if any
const intx::uint256 blob_gas_price{evm.block().header.blob_gas_price().value_or(0)};
want += txn.total_blob_gas() * blob_gas_price;
}

const auto have = ibs_state_.get_balance(*txn.sender());
if (have < want + txn.value) {
if (!gas_bailout) {
Expand Down
6 changes: 4 additions & 2 deletions silkworm/rpc/core/evm_executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
namespace silkworm::rpc {

enum PreCheckErrorCode {
kIntrinsicGasTooLow,
kInsufficientFunds,
kFeeCapLessThanBlockFeePerGas,
kInsufficientFunds,
kInternalError,
kIntrinsicGasTooLow,
kMaxFeePerBlobGasTooLowError,
kTipHigherThanFeeCap
};

Expand Down
Loading