arb_alloy_predeploys/
lib.rs

1#![no_std]
2#![allow(dead_code)]
3
4extern crate alloc;
5
6use alloc::vec::Vec;
7use alloy_primitives::keccak256;
8
9pub const ARB_SYS: [u8; 20] = hex20(0x64);
10pub const ARB_ADDRESS_TABLE: [u8; 20] = hex20(0x66);
11pub const ARB_BLS: [u8; 20] = hex20(0x67);
12pub const ARB_FUNCTION_TABLE: [u8; 20] = hex20(0x68);
13pub const ARB_INFO: [u8; 20] = hex20(0x65);
14pub const ARB_GAS_INFO: [u8; 20] = hex20(0x6c);
15pub const ARB_OWNER_PUBLIC: [u8; 20] = hex20(0x6b);
16pub const ARB_RETRYABLE_TX: [u8; 20] = hex20(0x6e);
17pub const ARB_STATISTICS: [u8; 20] = hex20(0x6f);
18pub const ARB_OWNER: [u8; 20] = hex20(0x70);
19pub const ARB_WASM: [u8; 20] = hex20(0x71);
20pub const ARB_WASM_CACHE: [u8; 20] = hex20(0x72);
21pub const ARB_NATIVE_TOKEN_MANAGER: [u8; 20] = hex20(0x73);
22pub const NODE_INTERFACE: [u8; 20] = hex20(0xc8);
23pub const NODE_INTERFACE_DEBUG: [u8; 20] = hex20(0xc9);
24pub const ARB_DEBUG: [u8; 20] = hex20(0xff);
25
26/* ArbSys core */
27pub const SIG_WITHDRAW_ETH: &str = "withdrawEth(address)";
28pub const SIG_SEND_TX_TO_L1: &str = "sendTxToL1(address,bytes)";
29pub const SIG_ARB_BLOCK_NUMBER: &str = "arbBlockNumber()";
30pub const SIG_ARB_BLOCK_HASH: &str = "arbBlockHash(uint256)";
31pub const SIG_ARB_CHAIN_ID: &str = "arbChainID()";
32pub const SIG_ARB_OS_VERSION: &str = "arbOSVersion()";
33pub const SIG_GET_STORAGE_GAS_AVAILABLE: &str = "getStorageGasAvailable()";
34pub const SIG_IS_TOP_LEVEL_CALL: &str = "isTopLevelCall()";
35pub const SIG_MAP_L1_SENDER_TO_L2_ALIAS: &str =
36    "mapL1SenderContractAddressToL2Alias(address,address)";
37pub const SIG_WAS_MY_CALLERS_ADDRESS_ALIASED: &str = "wasMyCallersAddressAliased()";
38pub const SIG_MY_CALLERS_ADDRESS_WITHOUT_ALIASING: &str = "myCallersAddressWithoutAliasing()";
39pub const SIG_SEND_MERKLE_TREE_STATE: &str = "sendMerkleTreeState()";
40/* ArbOwner */
41pub const SIG_OWNER_ADD_CHAIN_OWNER: &str = "addChainOwner(address)";
42pub const SIG_OWNER_REMOVE_CHAIN_OWNER: &str = "removeChainOwner(address)";
43pub const SIG_OWNER_IS_CHAIN_OWNER: &str = "isChainOwner(address)";
44pub const SIG_OWNER_GET_ALL_CHAIN_OWNERS: &str = "getAllChainOwners()";
45pub const SIG_OWNER_GET_NETWORK_FEE_ACCOUNT: &str = "getNetworkFeeAccount()";
46pub const SIG_OWNER_GET_INFRA_FEE_ACCOUNT: &str = "getInfraFeeAccount()";
47pub const SIG_OWNER_SET_NETWORK_FEE_ACCOUNT: &str = "setNetworkFeeAccount(address)";
48pub const SIG_OWNER_SET_INFRA_FEE_ACCOUNT: &str = "setInfraFeeAccount(address)";
49/* ArbRetryableTx */
50pub const SIG_RETRY_GET_LIFETIME: &str = "getLifetime()";
51pub const SIG_RETRY_GET_TIMEOUT: &str = "getTimeout(bytes32)";
52pub const SIG_RETRY_KEEPALIVE: &str = "keepalive(bytes32)";
53pub const SIG_RETRY_GET_BENEFICIARY: &str = "getBeneficiary(bytes32)";
54pub const SIG_RETRY_REDEEM: &str = "redeem(bytes32)";
55pub const SIG_RETRY_CANCEL: &str = "cancel(bytes32)";
56pub const SIG_RETRY_GET_CURRENT_REDEEMER: &str = "getCurrentRedeemer()";
57/* Non-callable but present for explorers */
58pub const SIG_RETRY_SUBMIT_RETRYABLE: &str = "submitRetryable(bytes32,uint256,uint256,uint256,uint256,uint64,uint256,address,address,address,bytes)";
59
60/* ArbAddressTable */
61pub const SIG_AT_ADDRESS_EXISTS: &str = "addressExists(address)";
62pub const SIG_AT_COMPRESS: &str = "compress(address)";
63pub const SIG_AT_DECOMPRESS: &str = "decompress(bytes,uint256)";
64pub const SIG_AT_LOOKUP: &str = "lookup(address)";
65pub const SIG_AT_LOOKUP_INDEX: &str = "lookupIndex(uint256)";
66pub const SIG_AT_REGISTER: &str = "register(address)";
67pub const SIG_AT_SIZE: &str = "size()";
68
69/* ArbGasInfo */
70pub const SIG_GI_GET_PRICES_IN_WEI: &str = "getPricesInWei()";
71pub const SIG_GI_GET_PRICES_IN_WEI_WITH_AGG: &str = "getPricesInWeiWithAggregator(address)";
72pub const SIG_GI_GET_PRICES_IN_ARBGAS: &str = "getPricesInArbGas()";
73pub const SIG_GI_GET_PRICES_IN_ARBGAS_WITH_AGG: &str = "getPricesInArbGasWithAggregator(address)";
74pub const SIG_GI_GET_MIN_GAS_PRICE: &str = "getMinimumGasPrice()";
75pub const SIG_GI_GET_L1_BASEFEE_ESTIMATE: &str = "getL1BaseFeeEstimate()";
76pub const SIG_GI_GET_L1_BASEFEE_INERTIA: &str = "getL1BaseFeeEstimateInertia()";
77pub const SIG_GI_GET_L1_REWARD_RATE: &str = "getL1RewardRate()";
78pub const SIG_GI_GET_L1_REWARD_RECIPIENT: &str = "getL1RewardRecipient()";
79pub const SIG_GI_GET_L1_GAS_PRICE_ESTIMATE: &str = "getL1GasPriceEstimate()";
80pub const SIG_GI_GET_CURRENT_TX_L1_FEES: &str = "getCurrentTxL1GasFees()";
81
82/* NodeInterface (virtual at 0xc8) */
83pub const SIG_NI_ESTIMATE_RETRYABLE_TICKET: &str =
84    "estimateRetryableTicket(address,uint256,address,uint256,address,address,bytes)";
85pub const SIG_NI_CONSTRUCT_OUTBOX_PROOF: &str = "constructOutboxProof(uint64,uint64)";
86pub const SIG_NI_FIND_BATCH_CONTAINING_BLOCK: &str = "findBatchContainingBlock(uint64)";
87pub const SIG_NI_GET_L1_CONFIRMATIONS: &str = "getL1Confirmations(bytes32)";
88pub const SIG_NI_GAS_ESTIMATE_COMPONENTS: &str = "gasEstimateComponents(address,bool,bytes)";
89pub const SIG_NI_GAS_ESTIMATE_L1_COMPONENT: &str = "gasEstimateL1Component(address,bool,bytes)";
90pub const SIG_NI_LEGACY_LOOKUP_MESSAGE_BATCH_PROOF: &str =
91    "legacyLookupMessageBatchProof(uint256,uint64)";
92pub const SIG_NI_NITRO_GENESIS_BLOCK: &str = "nitroGenesisBlock()";
93pub const SIG_NI_BLOCK_L1_NUM: &str = "blockL1Num(uint64)";
94/* NodeInterfaceDebug (virtual at 0xc9) */
95pub const SIG_NID_RETRYABLE_DETAILS: &str = "getRetryable(bytes32)";
96
97pub const SIG_NI_L2_BLOCK_RANGE_FOR_L1: &str = "l2BlockRangeForL1(uint64)";
98
99/* ArbInfo */
100pub const SIG_INFO_GET_BALANCE: &str = "getBalance(address)";
101pub const SIG_INFO_GET_CODE: &str = "getCode(address)";
102
103/* ArbFunctionTable */
104pub const SIG_FT_UPLOAD: &str = "upload(bytes)";
105pub const SIG_FT_SIZE: &str = "size(address)";
106pub const SIG_FT_GET: &str = "get(address,uint256)";
107
108/* ArbStatistics */
109pub const SIG_STATS_GET_STATS: &str = "getStats()";
110
111/* ArbWasm */
112pub const SIG_WASM_ACTIVATE_PROGRAM: &str = "activateProgram(address)";
113pub const SIG_WASM_STYLUS_VERSION: &str = "stylusVersion()";
114pub const SIG_WASM_CODEHASH_VERSION: &str = "codehashVersion(bytes32)";
115pub const SIG_WASM_CODEHASH_KEEPALIVE: &str = "codehashKeepalive(bytes32)";
116pub const SIG_WASM_CODEHASH_ASM_SIZE: &str = "codehashAsmSize(bytes32)";
117pub const SIG_WASM_PROGRAM_VERSION: &str = "programVersion(address)";
118pub const SIG_WASM_PROGRAM_INIT_GAS: &str = "programInitGas(address)";
119pub const SIG_WASM_PROGRAM_MEMORY_FOOTPRINT: &str = "programMemoryFootprint(address)";
120pub const SIG_WASM_PROGRAM_TIME_LEFT: &str = "programTimeLeft(address)";
121pub const SIG_WASM_INK_PRICE: &str = "inkPrice()";
122pub const SIG_WASM_MAX_STACK_DEPTH: &str = "maxStackDepth()";
123pub const SIG_WASM_FREE_PAGES: &str = "freePages()";
124pub const SIG_WASM_PAGE_GAS: &str = "pageGas()";
125pub const SIG_WASM_PAGE_RAMP: &str = "pageRamp()";
126pub const SIG_WASM_PAGE_LIMIT: &str = "pageLimit()";
127pub const SIG_WASM_MIN_INIT_GAS: &str = "minInitGas()";
128pub const SIG_WASM_INIT_COST_SCALAR: &str = "initCostScalar()";
129pub const SIG_WASM_EXPIRY_DAYS: &str = "expiryDays()";
130pub const SIG_WASM_KEEPALIVE_DAYS: &str = "keepaliveDays()";
131pub const SIG_WASM_BLOCK_CACHE_SIZE: &str = "blockCacheSize()";
132
133/* ArbWasmCache */
134pub const SIG_WASMC_IS_CACHE_MANAGER: &str = "isCacheManager(address)";
135pub const SIG_WASMC_ALL_CACHE_MANAGERS: &str = "allCacheManagers()";
136pub const SIG_WASMC_CACHE_CODEHASH: &str = "cacheCodehash(bytes32)";
137pub const SIG_WASMC_CACHE_PROGRAM: &str = "cacheProgram(address)";
138pub const SIG_WASMC_EVICT_CODEHASH: &str = "evictCodehash(bytes32)";
139pub const SIG_WASMC_CODEHASH_IS_CACHED: &str = "codehashIsCached(bytes32)";
140
141/* ArbNativeTokenManager */
142pub const SIG_NTM_MINT_NATIVE_TOKEN: &str = "mintNativeToken(uint256)";
143pub const SIG_NTM_BURN_NATIVE_TOKEN: &str = "burnNativeToken(uint256)";
144
145/* ArbOwnerPublic */
146pub const SIG_OWNER_PUB_IS_CHAIN_OWNER: &str = "isChainOwner(address)";
147pub const SIG_OWNER_PUB_RECTIFY_CHAIN_OWNER: &str = "rectifyChainOwner(address)";
148pub const SIG_OWNER_PUB_GET_ALL_CHAIN_OWNERS: &str = "getAllChainOwners()";
149pub const SIG_OWNER_PUB_IS_NATIVE_TOKEN_OWNER: &str = "isNativeTokenOwner(address)";
150pub const SIG_OWNER_PUB_GET_ALL_NATIVE_TOKEN_OWNERS: &str = "getAllNativeTokenOwners()";
151pub const SIG_OWNER_PUB_GET_NETWORK_FEE_ACCOUNT: &str = "getNetworkFeeAccount()";
152pub const SIG_OWNER_PUB_GET_INFRA_FEE_ACCOUNT: &str = "getInfraFeeAccount()";
153pub const SIG_OWNER_PUB_GET_BROTLI_COMPRESSION_LEVEL: &str = "getBrotliCompressionLevel()";
154pub const SIG_OWNER_PUB_GET_SCHEDULED_UPGRADE: &str = "getScheduledUpgrade()";
155pub const SIG_OWNER_PUB_IS_CALLDATA_PRICE_INCREASE_ENABLED: &str =
156    "isCalldataPriceIncreaseEnabled()";
157
158pub const EVT_TICKET_CREATED: &str = "TicketCreated(bytes32)";
159pub const EVT_LIFETIME_EXTENDED: &str = "LifetimeExtended(bytes32,uint256)";
160pub const EVT_REDEEM_SCHEDULED: &str =
161    "RedeemScheduled(bytes32,bytes32,uint64,uint64,address,uint256,uint256)";
162pub const EVT_TICKET_CANCELED: &str = "Canceled(bytes32)";
163pub const EVT_REDEEMED_DEPRECATED: &str = "Redeemed(bytes32)";
164
165/* ArbSys events */
166pub const EVT_L2_TO_L1_TX: &str =
167    "L2ToL1Tx(address,address,uint256,uint256,uint256,uint256,uint256,bytes)";
168pub const EVT_L2_TO_L1_TRANSACTION_DEPRECATED: &str =
169    "L2ToL1Transaction(address,address,uint256,uint256,uint256,uint256,uint256,uint256,uint256,bytes)";
170pub const EVT_SEND_MERKLE_UPDATE: &str = "SendMerkleUpdate(uint256,bytes32,uint256)";
171
172pub fn signature_bytes(sig: &str) -> Vec<u8> {
173    sig.as_bytes().to_vec()
174}
175
176pub const fn selector_for(sig_hash: [u8; 32]) -> [u8; 4] {
177    [sig_hash[0], sig_hash[1], sig_hash[2], sig_hash[3]]
178}
179
180pub const fn topic_for(sig_hash: [u8; 32]) -> [u8; 32] {
181    sig_hash
182}
183
184pub fn selector(sig: &str) -> [u8; 4] {
185    selector_for(keccak256(sig.as_bytes()).0)
186}
187
188pub fn topic(sig: &str) -> [u8; 32] {
189    topic_for(keccak256(sig.as_bytes()).0)
190}
191
192const fn hex20(last: u8) -> [u8; 20] {
193    let mut out = [0u8; 20];
194    out[19] = last;
195    out
196}
197
198#[cfg(test)]
199mod tests {
200    use super::*;
201
202    #[test]
203    fn predeploy_addresses_match_expected_suffixes() {
204        assert_eq!(&ARB_SYS[12..], &[0, 0, 0, 0, 0, 0, 0, 0x64]);
205        assert_eq!(&ARB_RETRYABLE_TX[12..], &[0, 0, 0, 0, 0, 0, 0, 0x6e]);
206        assert_eq!(&ARB_OWNER[12..], &[0, 0, 0, 0, 0, 0, 0, 0x70]);
207        assert_eq!(&NODE_INTERFACE[12..], &[0, 0, 0, 0, 0, 0, 0, 0xc8]);
208        assert_eq!(&ARB_DEBUG[12..], &[0, 0, 0, 0, 0, 0, 0, 0xff]);
209    }
210
211    #[test]
212    fn selectors_and_topics_are_derived() {
213        let s = selector(SIG_SEND_TX_TO_L1);
214        assert_eq!(s.len(), 4);
215        let t = topic(EVT_TICKET_CREATED);
216        assert_eq!(t.len(), 32);
217        let sel_again = selector(SIG_SEND_TX_TO_L1);
218        assert_eq!(s, sel_again);
219        let topic_again = topic(EVT_TICKET_CREATED);
220        assert_eq!(t, topic_again);
221    }
222
223    #[test]
224    fn more_selectors_and_topics_are_derived_consistently() {
225        let s1 = selector(SIG_ARB_BLOCK_NUMBER);
226        let s1b = selector(SIG_ARB_BLOCK_NUMBER);
227        assert_eq!(s1, s1b);
228        let s2 = selector(SIG_ARB_BLOCK_HASH);
229        let s2b = selector(SIG_ARB_BLOCK_HASH);
230        assert_eq!(s2, s2b);
231
232        let s3 = selector(SIG_GET_STORAGE_GAS_AVAILABLE);
233        let s3b = selector(SIG_GET_STORAGE_GAS_AVAILABLE);
234        assert_eq!(s3, s3b);
235
236        let t1 = topic(EVT_L2_TO_L1_TX);
237        let t1b = topic(EVT_L2_TO_L1_TX);
238        assert_eq!(t1, t1b);
239    }
240
241    #[test]
242    fn node_interface_and_gasinfo_selectors_compile() {
243        for sig in [
244            SIG_NI_ESTIMATE_RETRYABLE_TICKET,
245            SIG_NI_GAS_ESTIMATE_COMPONENTS,
246            SIG_NI_GAS_ESTIMATE_L1_COMPONENT,
247            SIG_GI_GET_L1_BASEFEE_ESTIMATE,
248            SIG_AT_REGISTER,
249        ] {
250            let sel = selector(sig);
251            assert_eq!(sel.len(), 4);
252        }
253    }
254
255    #[test]
256    fn owner_selectors_compile() {
257        for sig in [
258            SIG_OWNER_ADD_CHAIN_OWNER,
259            SIG_OWNER_REMOVE_CHAIN_OWNER,
260            SIG_OWNER_IS_CHAIN_OWNER,
261            SIG_OWNER_GET_ALL_CHAIN_OWNERS,
262            SIG_OWNER_GET_NETWORK_FEE_ACCOUNT,
263            SIG_OWNER_GET_INFRA_FEE_ACCOUNT,
264            SIG_OWNER_SET_NETWORK_FEE_ACCOUNT,
265            SIG_OWNER_SET_INFRA_FEE_ACCOUNT,
266        ] {
267            let sel = selector(sig);
268            assert_eq!(sel.len(), 4);
269        }
270    }
271}