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

feat: Add check for chainID #393

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/primitives/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub enum InvalidTransaction {
},
/// EIP-3860: Limit and meter initcode
CreateInitcodeSizeLimit,
InvalidChainId,
}

/// When transaction return successfully without halts.
Expand Down
5 changes: 5 additions & 0 deletions crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> Transact<DB::Error>
return Err(InvalidTransaction::RejectCallerWithCode.into());
}

// Check that the transaction's chain id is correct
if self.data.env.cfg.chain_id != U256::from(self.data.env.tx.chain_id.unwrap_or_default()) {
chirag-bgh marked this conversation as resolved.
Show resolved Hide resolved
return Err(InvalidTransaction::InvalidChainId.into());
}

// Check that the transaction's nonce is correct
if self.data.env.tx.nonce.is_some() {
let state_nonce = self
Expand Down
1 change: 1 addition & 0 deletions crates/revm/src/inspector/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ mod tests {
evm.env.tx.transact_to =
TransactTo::Call(B160(hex!("0000000000000000000000000000000000000000")));
evm.env.tx.gas_limit = 21100;
evm.env.tx.chain_id = Some(1);
chirag-bgh marked this conversation as resolved.
Show resolved Hide resolved

let mut inspector = StackInspector::default();
let ResultAndState { result, state } = evm.inspect(&mut inspector).unwrap();
Expand Down