aztec_core/constants.rs
1//! Well-known protocol contract addresses and domain separators.
2//!
3//! These addresses and constants are deterministic and identical across all Aztec networks.
4
5use crate::types::{AztecAddress, Fr};
6
7/// Well-known protocol contract addresses.
8pub mod protocol_contract_address {
9 use super::*;
10
11 /// The Fee Juice contract — manages fee token balances and claims.
12 ///
13 /// In the TS SDK this is `ProtocolContractAddress.FeeJuice` with
14 /// the numeric value `5` (see `constants.gen.ts: FEE_JUICE_ADDRESS = 5`).
15 pub fn fee_juice() -> AztecAddress {
16 AztecAddress(Fr::from(5u64))
17 }
18
19 /// The AuthRegistry protocol contract — manages public authorization witnesses.
20 ///
21 /// In the TS SDK this is `ProtocolContractAddress.AuthRegistry` with
22 /// the numeric value `1` (see `constants.gen.ts: CANONICAL_AUTH_REGISTRY_ADDRESS = 1`).
23 pub fn auth_registry() -> AztecAddress {
24 AztecAddress(Fr::from(1u64))
25 }
26}
27
28/// Domain separators used in Poseidon2 hashing throughout the protocol.
29///
30/// These must match the TS constants in `constants.gen.ts`.
31pub mod domain_separator {
32 /// Domain separator for authwit inner hash.
33 ///
34 /// TS: `DomainSeparator.AUTHWIT_INNER = 221354163`
35 pub const AUTHWIT_INNER: u32 = 221_354_163;
36
37 /// Domain separator for authwit outer hash.
38 ///
39 /// TS: `DomainSeparator.AUTHWIT_OUTER = 3283595782`
40 pub const AUTHWIT_OUTER: u32 = 3_283_595_782;
41
42 /// Domain separator for function args hashing.
43 ///
44 /// TS: `DomainSeparator.FUNCTION_ARGS = 3576554347`
45 pub const FUNCTION_ARGS: u32 = 3_576_554_347;
46}
47
48#[cfg(test)]
49#[allow(clippy::expect_used)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn fee_juice_address_is_5() {
55 let addr = protocol_contract_address::fee_juice();
56 assert_eq!(addr, AztecAddress(Fr::from(5u64)));
57 }
58
59 #[test]
60 fn auth_registry_address_is_1() {
61 let addr = protocol_contract_address::auth_registry();
62 assert_eq!(addr, AztecAddress(Fr::from(1u64)));
63 }
64
65 #[test]
66 fn domain_separator_values_match_ts() {
67 assert_eq!(domain_separator::AUTHWIT_INNER, 221_354_163);
68 assert_eq!(domain_separator::AUTHWIT_OUTER, 3_283_595_782);
69 assert_eq!(domain_separator::FUNCTION_ARGS, 3_576_554_347);
70 }
71}