Skip to main content

neo_devpack/
native_contracts.rs

1// Copyright (c) 2025-2026 R3E Network
2// Licensed under the MIT License
3
4//! Canonical Neo N3 native contract and native library script hashes.
5//!
6//! `*_CONTRACT` values are big-endian RPC-style hex strings.
7//! `*_LE` values are little-endian bytes suitable for NeoVM Hash160 usage.
8
9use neo_types::NeoByteString;
10
11pub const NEO_CONTRACT: &str = "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5";
12pub const GAS_CONTRACT: &str = "0xd2a4cff31913016155e38e474a2c06d08be276cf";
13pub const CONTRACT_MANAGEMENT: &str = "0xfffdc93764dbaddd97c48f252a53ea4643faa3fd";
14pub const POLICY_CONTRACT: &str = "0xcc5e4edd9f5f8dba8bb65734541df7a1c081c67b";
15pub const ORACLE_CONTRACT: &str = "0xfe924b7cfe89ddd271abaf7210a80a7e11178758";
16pub const ROLE_MANAGEMENT: &str = "0x49cf4e5378ffcd4dec034fd98a174c5491e395e2";
17pub const NOTARY_CONTRACT: &str = "0xc1e14f19c3e60d0b9244d06dd7ba9b113135ec3b";
18pub const TREASURY_CONTRACT: &str = "0x156326f25b1b5d839a4d326aeaa75383c9563ac1";
19pub const LEDGER_CONTRACT: &str = "0xda65b600f7124ce6c79950c1772a36403104f2be";
20pub const CRYPTO_LIB: &str = "0x726cb6e0cd8628a1350a611384688911ab75f51b";
21pub const STD_LIB: &str = "0xacce6fd80d44e1796aa0c2c625e9e4e0ce39efc0";
22
23pub const NEO_CONTRACT_LE: [u8; 20] = [
24    0xf5, 0x63, 0xea, 0x40, 0xbc, 0x28, 0x3d, 0x4d, 0x0e, 0x05, 0xc4, 0x8e, 0xa3, 0x05, 0xb3, 0xf2,
25    0xa0, 0x73, 0x40, 0xef,
26];
27pub const GAS_CONTRACT_LE: [u8; 20] = [
28    0xcf, 0x76, 0xe2, 0x8b, 0xd0, 0x06, 0x2c, 0x4a, 0x47, 0x8e, 0xe3, 0x55, 0x61, 0x01, 0x13, 0x19,
29    0xf3, 0xcf, 0xa4, 0xd2,
30];
31pub const CONTRACT_MANAGEMENT_LE: [u8; 20] = [
32    0xfd, 0xa3, 0xfa, 0x43, 0x46, 0xea, 0x53, 0x2a, 0x25, 0x8f, 0xc4, 0x97, 0xdd, 0xad, 0xdb, 0x64,
33    0x37, 0xc9, 0xfd, 0xff,
34];
35pub const POLICY_CONTRACT_LE: [u8; 20] = [
36    0x7b, 0xc6, 0x81, 0xc0, 0xa1, 0xf7, 0x1d, 0x54, 0x34, 0x57, 0xb6, 0x8b, 0xba, 0x8d, 0x5f, 0x9f,
37    0xdd, 0x4e, 0x5e, 0xcc,
38];
39pub const ORACLE_CONTRACT_LE: [u8; 20] = [
40    0x58, 0x87, 0x17, 0x11, 0x7e, 0x0a, 0xa8, 0x10, 0x72, 0xaf, 0xab, 0x71, 0xd2, 0xdd, 0x89, 0xfe,
41    0x7c, 0x4b, 0x92, 0xfe,
42];
43pub const ROLE_MANAGEMENT_LE: [u8; 20] = [
44    0xe2, 0x95, 0xe3, 0x91, 0x54, 0x4c, 0x17, 0x8a, 0xd9, 0x4f, 0x03, 0xec, 0x4d, 0xcd, 0xff, 0x78,
45    0x53, 0x4e, 0xcf, 0x49,
46];
47pub const NOTARY_CONTRACT_LE: [u8; 20] = [
48    0x3b, 0xec, 0x35, 0x31, 0x11, 0x9b, 0xba, 0xd7, 0x6d, 0xd0, 0x44, 0x92, 0x0b, 0x0d, 0xe6, 0xc3,
49    0x19, 0x4f, 0xe1, 0xc1,
50];
51pub const TREASURY_CONTRACT_LE: [u8; 20] = [
52    0xc1, 0x3a, 0x56, 0xc9, 0x83, 0x53, 0xa7, 0xea, 0x6a, 0x32, 0x4d, 0x9a, 0x83, 0x5d, 0x1b, 0x5b,
53    0xf2, 0x26, 0x63, 0x15,
54];
55pub const LEDGER_CONTRACT_LE: [u8; 20] = [
56    0xbe, 0xf2, 0x04, 0x31, 0x40, 0x36, 0x2a, 0x77, 0xc1, 0x50, 0x99, 0xc7, 0xe6, 0x4c, 0x12, 0xf7,
57    0x00, 0xb6, 0x65, 0xda,
58];
59pub const CRYPTO_LIB_LE: [u8; 20] = [
60    0x1b, 0xf5, 0x75, 0xab, 0x11, 0x89, 0x68, 0x84, 0x13, 0x61, 0x0a, 0x35, 0xa1, 0x28, 0x86, 0xcd,
61    0xe0, 0xb6, 0x6c, 0x72,
62];
63pub const STD_LIB_LE: [u8; 20] = [
64    0xc0, 0xef, 0x39, 0xce, 0xe0, 0xe4, 0xe9, 0x25, 0xc6, 0xc2, 0xa0, 0x6a, 0x79, 0xe1, 0x44, 0x0d,
65    0xd8, 0x6f, 0xce, 0xac,
66];
67
68pub fn neo_contract_hash() -> NeoByteString {
69    NeoByteString::from_slice(&NEO_CONTRACT_LE)
70}
71
72pub fn gas_contract_hash() -> NeoByteString {
73    NeoByteString::from_slice(&GAS_CONTRACT_LE)
74}
75
76pub fn contract_management_hash() -> NeoByteString {
77    NeoByteString::from_slice(&CONTRACT_MANAGEMENT_LE)
78}
79
80pub fn policy_contract_hash() -> NeoByteString {
81    NeoByteString::from_slice(&POLICY_CONTRACT_LE)
82}
83
84pub fn oracle_contract_hash() -> NeoByteString {
85    NeoByteString::from_slice(&ORACLE_CONTRACT_LE)
86}
87
88pub fn role_management_hash() -> NeoByteString {
89    NeoByteString::from_slice(&ROLE_MANAGEMENT_LE)
90}
91
92pub fn notary_contract_hash() -> NeoByteString {
93    NeoByteString::from_slice(&NOTARY_CONTRACT_LE)
94}
95
96pub fn treasury_contract_hash() -> NeoByteString {
97    NeoByteString::from_slice(&TREASURY_CONTRACT_LE)
98}
99
100pub fn ledger_contract_hash() -> NeoByteString {
101    NeoByteString::from_slice(&LEDGER_CONTRACT_LE)
102}
103
104pub fn crypto_lib_hash() -> NeoByteString {
105    NeoByteString::from_slice(&CRYPTO_LIB_LE)
106}
107
108pub fn std_lib_hash() -> NeoByteString {
109    NeoByteString::from_slice(&STD_LIB_LE)
110}
111
112#[cfg(test)]
113mod tests {
114    use super::*;
115
116    fn hex_nibble(byte: u8) -> Option<u8> {
117        match byte {
118            b'0'..=b'9' => Some(byte - b'0'),
119            b'a'..=b'f' => Some(byte - b'a' + 10),
120            b'A'..=b'F' => Some(byte - b'A' + 10),
121            _ => None,
122        }
123    }
124
125    fn parse_rpc_hash_to_le_bytes(hash: &str) -> [u8; 20] {
126        assert!(hash.starts_with("0x"), "hash must be 0x-prefixed");
127        let hex = hash.as_bytes();
128        assert_eq!(hex.len(), 42, "hash must have 40 hex chars");
129
130        let mut be = [0u8; 20];
131        let mut i = 0usize;
132        while i < 20 {
133            let hi = hex_nibble(hex[2 + i * 2]).expect("valid hex high nibble");
134            let lo = hex_nibble(hex[3 + i * 2]).expect("valid hex low nibble");
135            be[i] = (hi << 4) | lo;
136            i += 1;
137        }
138
139        let mut le = [0u8; 20];
140        let mut j = 0usize;
141        while j < 20 {
142            le[j] = be[19 - j];
143            j += 1;
144        }
145        le
146    }
147
148    #[test]
149    fn native_hashes_have_expected_shapes() {
150        assert_eq!(NEO_CONTRACT.len(), 42);
151        assert!(NEO_CONTRACT.starts_with("0x"));
152        assert_eq!(ORACLE_CONTRACT.len(), 42);
153        assert!(ORACLE_CONTRACT.starts_with("0x"));
154
155        assert_eq!(neo_contract_hash().len(), 20);
156        assert_eq!(gas_contract_hash().len(), 20);
157        assert_eq!(oracle_contract_hash().len(), 20);
158    }
159
160    #[test]
161    fn oracle_little_endian_bytes_match_known_value() {
162        assert_eq!(
163            oracle_contract_hash().as_slice(),
164            &[
165                0x58, 0x87, 0x17, 0x11, 0x7e, 0x0a, 0xa8, 0x10, 0x72, 0xaf, 0xab, 0x71, 0xd2, 0xdd,
166                0x89, 0xfe, 0x7c, 0x4b, 0x92, 0xfe
167            ]
168        );
169    }
170
171    #[test]
172    fn rpc_hex_and_little_endian_constants_stay_in_sync() {
173        let pairs: [(&str, [u8; 20]); 11] = [
174            (NEO_CONTRACT, NEO_CONTRACT_LE),
175            (GAS_CONTRACT, GAS_CONTRACT_LE),
176            (CONTRACT_MANAGEMENT, CONTRACT_MANAGEMENT_LE),
177            (POLICY_CONTRACT, POLICY_CONTRACT_LE),
178            (ORACLE_CONTRACT, ORACLE_CONTRACT_LE),
179            (ROLE_MANAGEMENT, ROLE_MANAGEMENT_LE),
180            (NOTARY_CONTRACT, NOTARY_CONTRACT_LE),
181            (TREASURY_CONTRACT, TREASURY_CONTRACT_LE),
182            (LEDGER_CONTRACT, LEDGER_CONTRACT_LE),
183            (CRYPTO_LIB, CRYPTO_LIB_LE),
184            (STD_LIB, STD_LIB_LE),
185        ];
186
187        for (rpc_hex, expected_le) in pairs {
188            let derived = parse_rpc_hash_to_le_bytes(rpc_hex);
189            assert_eq!(derived, expected_le, "mismatch for {rpc_hex}");
190        }
191    }
192}