Feat: gasometr refactoring and improvements#100
Feat: gasometr refactoring and improvements#100mrLSD merged 4 commits intocurrent-prague-hard-forkfrom
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes introduce a new public verification and calculation API for transaction gas costs in the gasometer, factoring out intrinsic gas computations into reusable functions and centralizing gas validation against limits and EIP-7623 floor rules, while refactoring existing transaction recording to leverage the new verification path. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@evm/src/gasometer/mod.rs`:
- Around line 393-401: The floor gas calculation for EIP-7623 wrongly uses the
configurable value config.gas_transaction_call instead of the spec-mandated
constant 21000; in the block computing floor_gas (look for variables floor_gas,
tokens_in_calldata, config.total_cost_floor_per_token and config.has_floor_gas
in mod.rs) replace the use of config.gas_transaction_call with the hardcoded
literal 21000 so the formula becomes 21000 + tokens_in_calldata *
TOTAL_COST_FLOOR_PER_TOKEN (preserving types/casting as needed).
🧹 Nitpick comments (2)
evm/src/gasometer/mod.rs (2)
322-336: Consider adding documentation for this public API function.Other public methods in this file (e.g.,
intrinsic_gas_and_gas_floor,verify_transaction) include doc comments explaining purpose and related EIPs. This function should be consistent.📝 Suggested documentation
#[must_use] +/// Calculate intrinsic gas and gas floor directly from transaction data. +/// +/// This is a convenience function that constructs the appropriate `TransactionCost` +/// based on `is_contract_creation` and delegates to `intrinsic_gas_and_gas_floor`. +/// +/// Related EIPs: +/// - [EIP-2028](https://eips.ethereum.org/EIPS/eip-2028) +/// - [EIP-7623](https://eips.ethereum.org/EIPS/eip-7623) pub fn calculate_intrinsic_gas_and_gas_floor(
363-371: Potential integer overflow in token calculation before cast.The expression
zero_data_len + non_zero_data_len * 4is computed inusizebefore casting tou64. On 32-bit targets, ifnon_zero_data_lenexceeds ~1GB, the multiplication could wrap. While practical calldata limits make this unlikely, using checked arithmetic would be defensive.The same pattern appears on line 396 for Create transactions.
🛡️ Defensive fix using u64 arithmetic
- let tokens_in_calldata = (zero_data_len + non_zero_data_len * 4) as u64; + let tokens_in_calldata = zero_data_len as u64 + non_zero_data_len as u64 * 4;
| let floor_gas = if config.has_floor_gas { | ||
| // According to EIP-2028: non-zero byte = 16, zero-byte = 4 | ||
| // According to EIP-7623: tokens_in_calldata = zero_bytes_in_calldata + nonzero_bytes_in_calldata * 4 | ||
| let tokens_in_calldata = (zero_data_len + non_zero_data_len * 4) as u64; | ||
| tokens_in_calldata * config.total_cost_floor_per_token | ||
| + config.gas_transaction_call | ||
| } else { | ||
| 0 | ||
| }; |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
EIP-7623 floor gas calculation formula Create transaction
💡 Result:
Short answer — formula and create-tx gas requirement:
-
Define tokens_in_calldata = zero_bytes_in_calldata + 4 * nonzero_bytes_in_calldata. [1][2]
-
Parameters (EIP‑7623): STANDARD_TOKEN_COST = 4; TOTAL_COST_FLOOR_PER_TOKEN = 10. [1][2]
-
New gas-used formula per transaction:
tx.gasUsed = 21000 + max(
STANDARD_TOKEN_COST * tokens_in_calldata- execution_gas_used
- isContractCreation * (32000 + INITCODE_WORD_COST * words(calldata)),
TOTAL_COST_FLOOR_PER_TOKEN * tokens_in_calldata
). [1][2]
-
Create-transaction (gas-limit) requirement: any transaction whose gas limit is below
21000 + TOTAL_COST_FLOOR_PER_TOKEN * tokens_in_calldata (or below its intrinsic gas) is invalid — i.e., you must reserve at least that floor in the tx gas limit. [1][2]
Sources: EIP‑7623 specification and related summary. [1] eips.ethereum.org/EIPS/eip-7623. [2] eip.directory/eips/eip-7623.
🏁 Script executed:
# Search for EIP-7623 references in codebase
rg "7623" --type rust -B 2 -A 2Repository: aurora-is-near/aurora-evm
Length of output: 5150
🏁 Script executed:
# Check the config structure and gas_transaction_call definition
rg "gas_transaction_call" --type rust -B 3 -A 3Repository: aurora-is-near/aurora-evm
Length of output: 4197
🏁 Script executed:
# Look for Create-specific gas handling
rg -i "create" evm/src/gasometer/mod.rs -B 2 -A 2 | head -50Repository: aurora-is-near/aurora-evm
Length of output: 1683
Use hardcoded 21000 instead of config.gas_transaction_call for EIP-7623 floor base.
Per EIP-7623, the floor gas formula uses a fixed 21000 base regardless of transaction type: floor = 21000 + tokens_in_calldata * TOTAL_COST_FLOOR_PER_TOKEN. The Create branch currently uses config.gas_transaction_call for this base, which happens to equal 21000 in all current configurations, but using a config parameter for a spec-defined constant violates the principle that config should only control variable values. If gas_transaction_call were ever modified, the floor calculation would break. Use a hardcoded 21000 instead.
🤖 Prompt for AI Agents
In `@evm/src/gasometer/mod.rs` around lines 393 - 401, The floor gas calculation
for EIP-7623 wrongly uses the configurable value config.gas_transaction_call
instead of the spec-mandated constant 21000; in the block computing floor_gas
(look for variables floor_gas, tokens_in_calldata,
config.total_cost_floor_per_token and config.has_floor_gas in mod.rs) replace
the use of config.gas_transaction_call with the hardcoded literal 21000 so the
formula becomes 21000 + tokens_in_calldata * TOTAL_COST_FLOOR_PER_TOKEN
(preserving types/casting as needed).
There was a problem hiding this comment.
The value 21000 is a protocol-defined constant originating from the Ethereum Yellow Paper (Appendix G), where it is specified as G_transaction—the base gas cost for any transaction in the Ethereum network. This value is not subject to configuration changes, as it is a fundamental part of the Ethereum protocol specification.
For EIP-7623, the floor gas formula explicitly requires this fixed base (21000) to ensure compliance with the protocol’s design. Using a hardcoded 21000 aligns with the principle that specification-defined constants should not be exposed to configuration variability, which could lead to inconsistencies or unintended behavior if the configuration were ever modified.
Thus, replacing config.gas_transaction_call with the hardcoded value 21000 is the correct approach to maintain adherence to the protocol and avoid potential future discrepancies.
There was a problem hiding this comment.
@mrLSD, thank you for the detailed explanation and for confirming the rationale behind using the hardcoded constant! You're absolutely right that G_transaction = 21000 is a protocol-defined constant from the Yellow Paper and should not be subject to configuration variability.
Your explanation perfectly captures why this change is important: it ensures strict compliance with EIP-7623's specification and prevents potential issues if config.gas_transaction_call were ever modified for other purposes. Using the hardcoded literal maintains the integrity of the floor gas calculation as defined in the EIP.
I appreciate you taking the time to provide this context—it reinforces the importance of distinguishing between configurable parameters and immutable protocol constants.
* feat: introduce gas_floor_base_cost for EIP-7623 compliance * fix: replace simple arithmetic operations with saturating_* analogs for gas calculations * chore: remove gas_floor_base_cost constant
* Feat: gasometr refactoring and improvements (#100) * Gasometr: refactoring and improvements * Bump from version: v2.2.1 * Extend doc comment for calculate_intrinsic_gas_and_gas_floor * feat: introduce gas_floor_base_cost for EIP-7623 compliance (#101) * feat: introduce gas_floor_base_cost for EIP-7623 compliance * fix: replace simple arithmetic operations with saturating_* analogs for gas calculations * chore: remove gas_floor_base_cost constant --------- Co-authored-by: Oleksandr Anyshchenko <oleksandr.anyshchenko@aurora.dev> * Fix typo --------- Co-authored-by: Oleksandr Anyshchenko <oleksandr.anyshchenko@aurora.dev>
Summary by CodeRabbit
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.