arbos/util/
address_alias.rs1use alloy_primitives::Address;
2
3pub const ADDRESS_ALIAS_OFFSET: Address = {
6 let bytes: [u8; 20] = [
7 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8 0x00, 0x00, 0x00, 0x11, 0x11,
9 ];
10 Address::new(bytes)
11};
12
13pub const INVERSE_ADDRESS_ALIAS_OFFSET: Address = {
18 let bytes: [u8; 20] = [
19 0xee, 0xee, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
20 0xff, 0xff, 0xff, 0xee, 0xef,
21 ];
22 Address::new(bytes)
23};
24
25pub fn remap_l1_address(l1_address: Address) -> Address {
27 address_add(l1_address, ADDRESS_ALIAS_OFFSET)
28}
29
30pub fn inverse_remap_l1_address(l2_address: Address) -> Address {
32 address_add(l2_address, INVERSE_ADDRESS_ALIAS_OFFSET)
33}
34
35fn address_add(a: Address, b: Address) -> Address {
37 let a_bytes = a.0 .0;
38 let b_bytes = b.0 .0;
39 let mut result = [0u8; 20];
40 let mut carry: u16 = 0;
41 for i in (0..20).rev() {
42 let sum = a_bytes[i] as u16 + b_bytes[i] as u16 + carry;
43 result[i] = sum as u8;
44 carry = sum >> 8;
45 }
46 Address::new(result)
47}
48
49pub fn does_tx_type_alias(tx_type: u8) -> bool {
51 matches!(tx_type, 0x65 | 0x66 | 0x68)
53}
54
55pub fn tx_type_has_poster_costs(tx_type: u8) -> bool {
60 !matches!(
61 tx_type,
62 0x64 | 0x65 | 0x66 | 0x68 | 0x69 | 0x6a )
69}