1use core::fmt;
4use primitives::{b256, hex, B256};
5
6pub const EIP7702_MAGIC_HASH: B256 =
8 b256!("0xeadcdba66a79ab5dce91622d1d75c8cff5cff0b96944c3bf1072cd08ce018329");
9
10pub const EIP7702_MAGIC: u16 = 0xEF01;
12
13pub const EIP7702_MAGIC_BYTES: &[u8] = &hex!("ef01");
15
16pub const EIP7702_VERSION: u8 = 0;
18
19pub const EIP7702_BYTECODE_LEN: usize = 23;
21
22#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
24#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
25pub enum Eip7702DecodeError {
26 InvalidLength,
30 InvalidMagic,
34 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 {}
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56 use primitives::keccak256;
57
58 #[test]
59 fn verify_magic_hash() {
60 assert_eq!(keccak256(EIP7702_MAGIC_BYTES), EIP7702_MAGIC_HASH);
61 }
62
63 #[test]
64 fn verify_magic_bytes() {
65 assert_eq!(EIP7702_MAGIC.to_be_bytes(), EIP7702_MAGIC_BYTES);
66 }
67}