Skip to content

Feat: gasometr refactoring and improvements#100

Merged
mrLSD merged 4 commits intocurrent-prague-hard-forkfrom
feat/gasometr-refactoring
Jan 23, 2026
Merged

Feat: gasometr refactoring and improvements#100
mrLSD merged 4 commits intocurrent-prague-hard-forkfrom
feat/gasometr-refactoring

Conversation

@mrLSD
Copy link
Copy Markdown
Member

@mrLSD mrLSD commented Jan 22, 2026

Summary by CodeRabbit

  • New Features

    • Added consolidated gas calculation and verification utilities for improved transaction handling consistency.
  • Improvements

    • Enhanced transaction verification to enforce gas limit and EIP-7623 gas floor validations.
    • Streamlined gas computation logic to reduce redundancy across call and contract creation paths.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 22, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The 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

Cohort / File(s) Summary
Gas Verification Refactoring
evm/src/gasometer/mod.rs
Added public intrinsic_gas_and_gas_floor() and calculate_intrinsic_gas_and_gas_floor() for reusable gas computation; introduced verify_transaction() to centralize gas validation against limits and EIP-7623 floor checks; refactored record_transaction() to delegate to verification path

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 Hop hop, the gasometer refines,
With verification's clean design,
EIP-7623 rules take the stage,
Gas floors enforced with careful gauge!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Feat: gasometr refactoring and improvements' contains a typo ('gasometr' should be 'gasometer') and is overly vague, using generic terms like 'refactoring and improvements' that don't specify the main change despite the PR introducing specific new functionality like intrinsic_gas_and_gas_floor, calculate_intrinsic_gas_and_gas_floor, and verify_transaction. Revise the title to be more specific and fix the typo: e.g., 'Feat: refactor gasometer to centralize intrinsic gas and gas floor calculations' or similar to clearly convey the primary purpose.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@mrLSD
Copy link
Copy Markdown
Member Author

mrLSD commented Jan 22, 2026

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 22, 2026

✅ Actions performed

Full review triggered.

@mrLSD mrLSD requested review from aleksuss and birchmd January 22, 2026 15:05
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 * 4 is computed in usize before casting to u64. On 32-bit targets, if non_zero_data_len exceeds ~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;

Comment thread evm/src/gasometer/mod.rs Outdated
Comment on lines +393 to +401
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
};
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 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 2

Repository: 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 3

Repository: 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 -50

Repository: 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).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Comment thread evm/src/gasometer/mod.rs
Comment thread evm/src/gasometer/mod.rs Outdated
Comment thread evm/src/gasometer/mod.rs Outdated
* 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
@mrLSD mrLSD merged commit da5a313 into current-prague-hard-fork Jan 23, 2026
7 checks passed
@mrLSD mrLSD deleted the feat/gasometr-refactoring branch January 23, 2026 10:46
mrLSD added a commit that referenced this pull request Feb 3, 2026
* 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>
@coderabbitai coderabbitai Bot mentioned this pull request Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants