-
Notifications
You must be signed in to change notification settings - Fork 759
Description
With a restriction that contacts can not start with 0xEF
and with the possibility that in future we will have different ByteCode
for EVM Object Format, it makes sense to introduce support for it into the revm. https://eips.ethereum.org/EIPS/eip-3541
The biggest benefit atm would be introducing ByteCode
type that will contain jumptable and gas blocks and with that we would skip the needed analysis of the contract. This is a fairly big speed-u for some use cases noticed in the foundry as fuzzing tests call a lot of contracts with not much execution and analysis, in that case, is taking a lot of time.
The proposal is to introduce enum ByteCode
that would somehow return: code
, code_size
and jumptable
.
Basically replace this input with ByteCode
:
code: Bytes, |
and propagate change wherever needed.
ByteCode
should set these fields in the contract:
revm/crates/revm/src/interpreter/contract.rs
Lines 11 to 13 in 0852824
pub code: Bytes, /// code size of original code. Note that current code is extended with push padding and STOP at end pub code_size: usize, jumpdest: ValidJumpAddress,
and do the same for database struct:
- Return
ByteCode
:revm/crates/revm/src/db/traits.rs
Line 14 in 0852824
fn code_by_hash(&mut self, code_hash: H256) -> Bytes; - Replace bytes with
BytesCode
:revm/crates/revm/src/models.rs
Line 24 in 0852824
pub code: Option<Bytes>,
To fully circle the story with EVM Object Format, CREATE and CREATE2 will need to return 0xEF type format in bytes that would get transformed to ByteCode
for evm usage here:
revm/crates/revm/src/evm_impl.rs
Lines 395 to 399 in 0852824
// EIP-3541: Reject new contract code starting with the 0xEF byte | |
if SPEC::enabled(LONDON) && !code.is_empty() && code.get(0) == Some(&0xEF) { | |
self.data.subroutine.checkpoint_revert(checkpoint); | |
return (Return::CreateContractWithEF, ret, interp.gas, b); | |
} |
But this is a consensus rule and out of scope for this feat, we should just continue using legacy
ByteCode
here. If needed we could in Inspector create_end
transform that into ByteCode
.