Skip to content

Commit 669286c

Browse files
committed
feat(has_cfg): chain id check enabling / disabling
1 parent 1c9029f commit 669286c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/evm/has_cfg.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,35 @@ where
5757
self.set_code_size_limit(0x6000)
5858
}
5959

60+
/// Disable the [EIP-155] chain ID check.
61+
///
62+
/// [`EIP-155`]: https://eips.ethereum.org/EIPS/eip-155
63+
pub fn disable_chain_id_check(&mut self) {
64+
self.inner.ctx.modify_cfg(|cfg| cfg.tx_chain_id_check = false);
65+
}
66+
67+
/// Enable the [EIP-155] chain ID check.
68+
///
69+
/// [`EIP-155`]: https://eips.ethereum.org/EIPS/eip-155
70+
pub fn enable_chain_id_check(&mut self) {
71+
self.inner.ctx.modify_cfg(|cfg| cfg.tx_chain_id_check = true);
72+
}
73+
74+
/// Run a closure with the chain ID check disabled, then restore the previous
75+
/// setting.
76+
///
77+
/// [`EIP-155`]: https://eips.ethereum.org/EIPS/eip-155
78+
pub fn without_chain_id_check<F, NewState: HasCfg>(mut self, f: F) -> Trevm<Db, Insp, NewState>
79+
where
80+
F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,
81+
{
82+
let previous = self.inner.cfg().tx_chain_id_check;
83+
self.disable_chain_id_check();
84+
let mut new = f(self);
85+
new.inner.ctx.modify_cfg(|cfg| cfg.tx_chain_id_check = previous);
86+
new
87+
}
88+
6089
/// Run a function with the provided configuration, then restore the
6190
/// previous configuration. This will not affect the block and tx, if those
6291
/// have been filled.

0 commit comments

Comments
 (0)