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: post EIP1559 balance check done on max_fee_per_gas and max_blob_per_gas #2063

Merged
merged 12 commits into from
Jun 14, 2024
23 changes: 14 additions & 9 deletions silkworm/rpc/core/evm_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,19 @@ std::optional<EVMExecutor::PreCheckResult> EVMExecutor::pre_check(const EVM& evm

if (rev >= EVMC_LONDON) {
if (txn.max_fee_per_gas > 0 || txn.max_priority_fee_per_gas > 0) {
if (txn.max_fee_per_gas < base_fee_per_gas) {
const std::string from = address_to_hex(*txn.sender());
std::string error = "fee cap less than block base fee: address " + from + ", gasFeeCap: " +
intx::to_string(txn.max_fee_per_gas) + " baseFee: " + intx::to_string(base_fee_per_gas);
return PreCheckResult{error, PreCheckErrorCode::kFeeCapLessThanBlockFeePerGas};
}

if (txn.max_fee_per_gas < txn.max_priority_fee_per_gas) {
std::string from = address_to_hex(*txn.sender());
std::string error = "tip higher than fee cap: address " + from + ", tip: " + intx::to_string(txn.max_priority_fee_per_gas) + " gasFeeCap: " +
intx::to_string(txn.max_fee_per_gas);
return PreCheckResult{error, PreCheckErrorCode::kTipHigherThanFeeCap};
}

if (txn.max_fee_per_gas < base_fee_per_gas) {
const std::string from = address_to_hex(*txn.sender());
std::string error = "fee cap less than block base fee: address " + from + ", gasFeeCap: " +
intx::to_string(txn.max_fee_per_gas) + " baseFee: " + intx::to_string(base_fee_per_gas);
return PreCheckResult{error, PreCheckErrorCode::kFeeCapLessThanBlockFeePerGas};
}
}
} else {
if (txn.type != silkworm::TransactionType::kLegacy && txn.type != silkworm::TransactionType::kAccessList) {
Expand Down Expand Up @@ -282,12 +282,17 @@ ExecutionResult EVMExecutor::call(
want += txn.total_blob_gas() * blob_gas_price;
}

intx::uint512 max_want = want;
if (txn.type != silkworm::TransactionType::kLegacy && txn.type != silkworm::TransactionType::kAccessList) {
max_want = txn.maximum_gas_cost();
}

const auto have = ibs_state_.get_balance(*txn.sender());
if (have < want + txn.value) {
if (have < max_want + txn.value) {
if (!gas_bailout) {
Bytes data{};
std::string from = address_to_hex(*txn.sender());
std::string msg = "insufficient funds for gas * price + value: address " + from + " have " + intx::to_string(have) + " want " + intx::to_string(want + txn.value);
std::string msg = "insufficient funds for gas * price + value: address " + from + " have " + intx::to_string(have) + " want " + intx::to_string(max_want + txn.value);
return {std::nullopt, txn.gas_limit, data, msg, PreCheckErrorCode::kInsufficientFunds};
}
} else {
Expand Down
6 changes: 6 additions & 0 deletions silkworm/rpc/json/call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ void from_json(const nlohmann::json& json, Call& call) {
if (json.count("gasPrice") != 0) {
call.gas_price = json.at("gasPrice").get<intx::uint256>();
}
if (json.count("maxFeePerGas") != 0) {
call.max_fee_per_gas = json.at("maxFeePerGas").get<intx::uint256>();
}
if (json.count("maxPriorityFeePerGas") != 0) {
call.max_priority_fee_per_gas = json.at("maxPriorityFeePerGas").get<intx::uint256>();
}
if (json.count("value") != 0) {
call.value = json.at("value").get<intx::uint256>();
}
Expand Down
6 changes: 4 additions & 2 deletions silkworm/rpc/types/call.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ struct Call {
}

if (gas_price) {
SILKWORM_ASSERT(!max_priority_fee_per_gas && !max_fee_per_gas);
// We need to update JSON RPC validation spec to uncomment the following assertion
// SILKWORM_ASSERT(!max_priority_fee_per_gas && !max_fee_per_gas);
txn.type = TransactionType::kLegacy;
txn.max_priority_fee_per_gas = gas_price.value();
txn.max_fee_per_gas = gas_price.value();
} else {
SILKWORM_ASSERT(!gas_price);
// We need to update JSON RPC validation spec to uncomment the following assertion
// SILKWORM_ASSERT(!gas_price);
txn.type = TransactionType::kDynamicFee;
txn.max_priority_fee_per_gas = max_priority_fee_per_gas.value_or(intx::uint256{0});
txn.max_fee_per_gas = max_fee_per_gas.value_or(base_fee_per_gas.value_or(intx::uint256{0}));
Expand Down
Loading