refactor(handler): polish TxValidator API and add preset constructors#3400
Draft
refactor(handler): polish TxValidator API and add preset constructors#3400
Conversation
Add a new TxValidator struct that uses bitflags for fine-grained control over which validation checks to perform. This allows L2s and custom EVM implementations to easily skip specific validations (e.g., for deposit transactions) without duplicating validation logic. The existing validation functions in validation.rs and pre_execution.rs now delegate to the new module internally, maintaining backward compatibility.
Improvements to the TxValidator module for better usability and performance: ## API Improvements - Add `Copy` derive to TxValidator and CallerFee for efficient passing - Add preset constructors: `for_deposit()`, `for_tx_pool()`, `for_block_builder()` - Add composite `GAS_FEES` flag for all gas/fee related checks - Add missing skip methods: `skip_tx_gas_limit_check()`, `skip_blob_fee_check()`, `skip_auth_list_check()`, `skip_max_initcode_size_check()`, `skip_caller_checks()`, `skip_gas_fee_checks()` - Add missing enable methods for all checks: `enable_tx_gas_limit_check()`, `enable_base_fee_check()`, `enable_priority_fee_check()`, `enable_blob_fee_check()`, `enable_auth_list_check()`, `enable_block_gas_limit_check()`, `enable_max_initcode_size_check()`, `enable_eip3607_check()`, `enable_eip7623_check()`, `enable_header_check()`, `enable_all()`, `enable_caller_checks()` - Add query methods: `has_any_checks()`, `has_all_checks()`, `enabled_checks()` ## Performance Improvements - Add `#[inline]` annotations to all builder methods and validation hot paths - Derive `Copy` to avoid unnecessary cloning ## Tests - Add tests for preset constructors - Add tests for composite skip/enable methods - Add tests for query methods - Add test verifying TxValidator is Copy
CodSpeed Performance ReportMerging this PR will degrade performance by 3.59%Comparing Summary
Performance Changes
|
… method Move ValidationChecks bitflags from handler to primitives crate to avoid circular dependencies and enable broader usage. Add `disabled_validation_checks()` method to Cfg trait that aggregates all 8 individual `is_*_disabled()` calls into a single method returning a ValidationChecks bitflags. This reduces TxValidator initialization overhead by computing disabled checks once. Key changes: - Move ValidationChecks to primitives/src/validation.rs - Add bitflags dependency to primitives - Add disabled_validation_checks() to Cfg trait with default impl - Simplify TxValidator::from_cfg_and_block to use single method call - Remove bitflags dependency from handler (now imports from primitives)
Polish the transaction validation API based on review feedback: ValidationChecks (primitives): - Change Default to return ALL instead of empty for safety - Add comprehensive documentation with examples - Add tests for composite flags (TX_STATELESS, CALLER, GAS_FEES) Cfg trait (context-interface): - Add #[inline] to disabled_validation_checks - Add enabled_validation_checks() convenience method - Improve documentation listing covered/uncovered checks TxValidator (handler): - Add with_spec(), with_disabled_checks(), with_enabled_checks() builders - Fix validate_caller to avoid Bytecode::default() allocation - Fix pre_execution.rs to use CALLER instead of ALL for caller validation - Add comprehensive tests for new builder methods
- Rename enable_gas_checks to enable_gas_fee_checks for consistency with skip_gas_fee_checks - Add #[must_use] to TxValidator struct for builder safety - Improve CallerFee documentation with usage examples
- TxValidator is now `TxValidator<C: Cfg, B: Block>` to work with references - Added `disabled_checks: ValidationChecks` field to CfgEnv for pre-computed checks - Added builder methods for fluent ValidationChecks configuration - Cfg trait now provides `disabled_validation_checks()` method - Simplified validation.rs to use new TxValidator API directly - Maintains backwards compatibility with legacy feature-gated boolean fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR polishes the
TxValidatormodule for better usability, performance, and L2 integration support. The improvements were identified through multiple iterations of analysis focusing on:CopysemanticsChanges
API Improvements
Copyderive toTxValidatorandCallerFeefor efficient passingfor_deposit()- L2 deposit transactions (skips fees, balance, nonce)for_tx_pool()- Transaction pool validation (stateless checks only)for_block_builder()- Block builder with lenient checksGAS_FEESflag for all gas/fee related checksskip_tx_gas_limit_check()skip_blob_fee_check()skip_auth_list_check()skip_max_initcode_size_check()skip_caller_checks()(composite)skip_gas_fee_checks()(composite)has_any_checks(),has_all_checks(),enabled_checks()Performance Improvements
#[inline]annotations to all builder methods and validation hot pathsCopyto avoid unnecessary cloningTests
Usage Examples
Test plan
cargo check -p revm-handlerpassescargo test -p revm-handler -- tx_validationpasses (12 tests)