-
Notifications
You must be signed in to change notification settings - Fork 201
feat(l1): reject contract senders at mempool admission (EIP-3607) #6600
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
Open
ilitteri
wants to merge
7
commits into
main
Choose a base branch
from
feat/mempool-eip3607-sender-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−6
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0fb606b
feat(l1): reject contract senders at mempool admission (EIP-3607)
ilitteri 376ae58
fix(l1): collapse EIP-3607 match block to `is_some_and`
ilitteri db12e3b
perf(l1): length pre-check before fetching sender bytecode for EIP-3607
ilitteri c1ed9c0
fix(l1): surface missing-code DB inconsistency as StoreError in EIP-3…
ilitteri 9856400
refactor(l1): collapse levm code_has_delegation onto common is_eip770…
ilitteri 0c2c8d6
docs(l1): drop reviewer mentions from EIP-3607 code comments
ilitteri 75437f3
Merge branch 'main' into feat/mempool-eip3607-sender-check
ilitteri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -57,7 +57,7 @@ use constants::{ | |||||||
| }; | ||||||||
| use error::MempoolError; | ||||||||
| use error::{ChainError, InvalidBlockError}; | ||||||||
| use ethrex_common::constants::{EMPTY_TRIE_HASH, MIN_BASE_FEE_PER_BLOB_GAS}; | ||||||||
| use ethrex_common::constants::{EMPTY_KECCACK_HASH, EMPTY_TRIE_HASH, MIN_BASE_FEE_PER_BLOB_GAS}; | ||||||||
|
|
||||||||
| use crossbeam::channel::{self as cb, TryRecvError, select}; | ||||||||
| // Re-export stateless validation functions for backwards compatibility | ||||||||
|
|
@@ -70,6 +70,7 @@ use ethrex_common::types::{ | |||||||
| AccountInfo, AccountState, AccountUpdate, Block, BlockHash, BlockHeader, BlockNumber, | ||||||||
| ChainConfig, Code, Receipt, Transaction, WrappedEIP4844Transaction, validate_block_body, | ||||||||
| }; | ||||||||
| use ethrex_common::types::{EIP7702_DELEGATED_CODE_LEN, is_eip7702_delegation}; | ||||||||
| use ethrex_common::types::{ELASTICITY_MULTIPLIER, P2PTransaction}; | ||||||||
| use ethrex_common::types::{Fork, MempoolTransaction}; | ||||||||
| use ethrex_common::utils::keccak; | ||||||||
|
|
@@ -2491,6 +2492,46 @@ impl Blockchain { | |||||||
| return Err(MempoolError::NonceTooLow); | ||||||||
| } | ||||||||
|
|
||||||||
| // EIP-3607: reject txs from senders with deployed code, unless | ||||||||
| // the code is an EIP-7702 delegation designation (the account is | ||||||||
| // still an EOA in spirit, just pointing at delegate code). | ||||||||
| // | ||||||||
| // Length-based fast path: any code whose length isn't exactly | ||||||||
| // `EIP7702_DELEGATED_CODE_LEN` (23) cannot be a delegation, so | ||||||||
| // we reject without loading the bytecode. Only when the metadata | ||||||||
| // length matches do we fetch + verify the prefix. This avoids | ||||||||
| // pulling potentially large contract bytecode on every contract | ||||||||
| // sender that hits admission (Copilot / @MegaRedHand review). | ||||||||
| if sender_acc_info.code_hash != *EMPTY_KECCACK_HASH { | ||||||||
| let metadata_len = self | ||||||||
| .storage | ||||||||
| .get_code_metadata(sender_acc_info.code_hash)? | ||||||||
| .map(|m| m.length); | ||||||||
| let is_delegation = if metadata_len == Some(EIP7702_DELEGATED_CODE_LEN as u64) { | ||||||||
| // Metadata says the code is delegation-shaped; if the | ||||||||
| // bytecode is then missing from the store, the DB is | ||||||||
| // inconsistent — surface that as `StoreError` instead of | ||||||||
| // silently treating the sender as a contract (which would | ||||||||
| // wrongly reject a valid 7702-delegated EOA per | ||||||||
| // Copilot/@codex review). | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| let code = self | ||||||||
| .storage | ||||||||
| .get_account_code(sender_acc_info.code_hash)? | ||||||||
| .ok_or_else(|| { | ||||||||
| StoreError::Custom(format!( | ||||||||
| "code missing for hash {:?} despite present metadata", | ||||||||
| sender_acc_info.code_hash | ||||||||
| )) | ||||||||
| })?; | ||||||||
| is_eip7702_delegation(code.bytecode.as_ref()) | ||||||||
| } else { | ||||||||
| false | ||||||||
| }; | ||||||||
| if !is_delegation { | ||||||||
| return Err(MempoolError::SenderIsContract); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| let tx_cost = tx | ||||||||
| .cost_without_base_fee() | ||||||||
| .ok_or(MempoolError::InvalidTxGasvalues)?; | ||||||||
|
|
||||||||
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.