Skip to main content

revm_bytecode/
eip7702.rs

1//! EIP-7702 bytecode constants and error types.
2
3use core::fmt;
4use primitives::{b256, hex, B256};
5
6/// Hash of EF01 bytes that is used for EXTCODEHASH when called from legacy bytecode.
7pub const EIP7702_MAGIC_HASH: B256 =
8    b256!("0xeadcdba66a79ab5dce91622d1d75c8cff5cff0b96944c3bf1072cd08ce018329");
9
10/// EIP-7702 Version Magic in u16 form.
11pub const EIP7702_MAGIC: u16 = 0xEF01;
12
13/// EIP-7702 magic number in array form.
14pub const EIP7702_MAGIC_BYTES: &[u8] = &hex!("ef01");
15
16/// EIP-7702 first version of bytecode.
17pub const EIP7702_VERSION: u8 = 0;
18
19/// EIP-7702 bytecode length: 2 (magic) + 1 (version) + 20 (address) = 23 bytes.
20pub const EIP7702_BYTECODE_LEN: usize = 23;
21
22/// EIP-7702 decode errors.
23#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
24#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
25pub enum Eip7702DecodeError {
26    /// Invalid length of the raw bytecode.
27    ///
28    /// It should be 23 bytes.
29    InvalidLength,
30    /// Invalid magic number.
31    ///
32    /// All EIP-7702 bytecodes should start with the magic number 0xEF01.
33    InvalidMagic,
34    /// Unsupported version.
35    ///
36    /// Only supported version is version 0x00.
37    UnsupportedVersion,
38}
39
40impl fmt::Display for Eip7702DecodeError {
41    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42        let s = match self {
43            Self::InvalidLength => "Eip7702 is not 23 bytes long",
44            Self::InvalidMagic => "Bytecode is not starting with 0xEF01",
45            Self::UnsupportedVersion => "Unsupported Eip7702 version.",
46        };
47        f.write_str(s)
48    }
49}
50
51impl core::error::Error for Eip7702DecodeError {}