Skip to main content

hopper_token/
layout.rs

1//! Kani proofs and golden-vector tests for the **shipped** SPL Token and
2//! System-program CPI instruction-data encoders.
3//!
4//! ## What is proven, and where the bytes come from
5//!
6//! The SPL Token builders and the System-program builders in
7//! [`hopper_runtime::token`] / [`hopper_runtime::system`] now construct every
8//! instruction-data buffer by calling a small, pure, `#[inline(always)]`
9//! encoder in `hopper_runtime::{token,system}::encoders`. Those encoders
10//! return the bytes that leave the program on a CPI. Because a builder's
11//! `invoke_signed*` path delegates to one of them (instead of building the
12//! buffer inline and dropping it straight into the syscall), the shipped bytes
13//! are directly callable and model-checkable.
14//!
15//! The `#[cfg(kani)]` proofs below call the shipped
16//! `hopper_runtime::{token,system}::encoders::*` functions **directly** and
17//! pin, over symbolic inputs, each field's discriminator, byte offset,
18//! endianness, and total encoded length. The proofs therefore exercise the
19//! encoder functions called by the CPI builders.
20//!
21//! ## The reference encoders are now a differential oracle
22//!
23//! The [`spl_token`] and [`system`] modules in this file retain an
24//! independent, second implementation of the same wire formats. They are no
25//! longer the proof target. They serve as a **differential oracle**. The
26//! `*_matches_reference` proofs assert, byte-for-byte over symbolic inputs,
27//! that the shipped encoder equals this independent reference, so the shipped
28//! bytes are pinned from two directions at once: a direct wire-format proof
29//! *and* N-version agreement with a separately-authored encoder. A divergence
30//! in either implementation fails a proof.
31//!
32//! ## CBMC tractability
33//!
34//! Scalars are compared as one word
35//! (`u64::from_le_bytes(..)`), never a slice `==`, and a 32-byte pubkey region
36//! is proven with a single symbolic index `i in 0..32` and one assertion,
37//! universal over all offsets, with no 32-iteration `memcmp` loop that would
38//! blow up the SAT formula. The differential proofs use the same discipline
39//! (field-wise / symbolic-index equality between the two fixed-size buffers),
40//! which avoids large comparison loops in the harnesses.
41//!
42//! ## Provenance of the shipped encoders (runtime source)
43//!
44//! SPL Token: `crates/hopper-runtime/src/token.rs`, `pub mod encoders`:
45//! Transfer 3, Approve 4, MintTo 7, Burn 8, TransferChecked 12,
46//! ApproveChecked 13, MintToChecked 14, BurnChecked 15, Revoke 5,
47//! CloseAccount 9, FreezeAccount 10, ThawAccount 11, SyncNative 17,
48//! InitializeAccount 1, InitializeAccount2 16 / InitializeAccount3 18
49//! (`encode_initialize_account_with_owner`), SetAuthority 6
50//! (`encode_set_authority`).
51//!
52//! System: `crates/hopper-runtime/src/system.rs`, `pub mod encoders`:
53//! CreateAccount 0, Transfer 2, Assign 1, Allocate 8,
54//! CreateAccountAllowPrefund 13. System discriminators are 4-byte `u32` LE
55//! (only the low byte is nonzero for these tags).
56
57// =====================================================================
58// Differential-oracle reference encoders (SPL Token wire format).
59//
60// These are an independent second implementation kept only as a proof
61// oracle: the `#[cfg(kani)]` `*_matches_reference` harnesses prove the
62// shipped `hopper_runtime::token::encoders` byte-equal to these for all
63// symbolic inputs. Do not call these from production code, use the
64// builders in `hopper_runtime::token`.
65// =====================================================================
66
67/// SPL Token instruction discriminators (`TokenInstruction` tags), plus an
68/// independent reference encoder per instruction used as a differential
69/// oracle for the shipped `hopper_runtime::token::encoders`.
70pub mod spl_token {
71    /// `InitializeAccount2` discriminator.
72    pub const IX_INITIALIZE_ACCOUNT2: u8 = 16;
73    /// `InitializeAccount3` discriminator.
74    pub const IX_INITIALIZE_ACCOUNT3: u8 = 18;
75    /// `Transfer` discriminator.
76    pub const IX_TRANSFER: u8 = 3;
77    /// `Approve` discriminator.
78    pub const IX_APPROVE: u8 = 4;
79    /// `Revoke` discriminator.
80    pub const IX_REVOKE: u8 = 5;
81    /// `SetAuthority` discriminator.
82    pub const IX_SET_AUTHORITY: u8 = 6;
83    /// `MintTo` discriminator.
84    pub const IX_MINT_TO: u8 = 7;
85    /// `Burn` discriminator.
86    pub const IX_BURN: u8 = 8;
87    /// `CloseAccount` discriminator.
88    pub const IX_CLOSE_ACCOUNT: u8 = 9;
89    /// `FreezeAccount` discriminator.
90    pub const IX_FREEZE_ACCOUNT: u8 = 10;
91    /// `ThawAccount` discriminator.
92    pub const IX_THAW_ACCOUNT: u8 = 11;
93    /// `TransferChecked` discriminator.
94    pub const IX_TRANSFER_CHECKED: u8 = 12;
95    /// `ApproveChecked` discriminator.
96    pub const IX_APPROVE_CHECKED: u8 = 13;
97    /// `MintToChecked` discriminator.
98    pub const IX_MINT_TO_CHECKED: u8 = 14;
99    /// `BurnChecked` discriminator.
100    pub const IX_BURN_CHECKED: u8 = 15;
101    /// `SyncNative` discriminator.
102    pub const IX_SYNC_NATIVE: u8 = 17;
103
104    #[inline(always)]
105    fn amount_ix(disc: u8, amount: u64) -> [u8; 9] {
106        let mut data = [0u8; 9];
107        data[0] = disc;
108        data[1..9].copy_from_slice(&amount.to_le_bytes());
109        data
110    }
111
112    #[inline(always)]
113    fn amount_checked_ix(disc: u8, amount: u64, decimals: u8) -> [u8; 10] {
114        let mut data = [0u8; 10];
115        data[0] = disc;
116        data[1..9].copy_from_slice(&amount.to_le_bytes());
117        data[9] = decimals;
118        data
119    }
120
121    /// Reference `Transfer { amount }`, `[3][amount: u64 LE]` (9 bytes).
122    #[inline(always)]
123    pub fn encode_transfer(amount: u64) -> [u8; 9] {
124        amount_ix(IX_TRANSFER, amount)
125    }
126
127    /// Reference `Approve { amount }`, `[4][amount: u64 LE]` (9 bytes).
128    #[inline(always)]
129    pub fn encode_approve(amount: u64) -> [u8; 9] {
130        amount_ix(IX_APPROVE, amount)
131    }
132
133    /// Reference `MintTo { amount }`, `[7][amount: u64 LE]` (9 bytes).
134    #[inline(always)]
135    pub fn encode_mint_to(amount: u64) -> [u8; 9] {
136        amount_ix(IX_MINT_TO, amount)
137    }
138
139    /// Reference `Burn { amount }`, `[8][amount: u64 LE]` (9 bytes).
140    #[inline(always)]
141    pub fn encode_burn(amount: u64) -> [u8; 9] {
142        amount_ix(IX_BURN, amount)
143    }
144
145    /// Reference `TransferChecked { amount, decimals }`,
146    /// `[12][amount: u64 LE][decimals: u8]` (10 bytes).
147    #[inline(always)]
148    pub fn encode_transfer_checked(amount: u64, decimals: u8) -> [u8; 10] {
149        amount_checked_ix(IX_TRANSFER_CHECKED, amount, decimals)
150    }
151
152    /// Reference `ApproveChecked { amount, decimals }`,
153    /// `[13][amount: u64 LE][decimals: u8]` (10 bytes).
154    #[inline(always)]
155    pub fn encode_approve_checked(amount: u64, decimals: u8) -> [u8; 10] {
156        amount_checked_ix(IX_APPROVE_CHECKED, amount, decimals)
157    }
158
159    /// Reference `MintToChecked { amount, decimals }`,
160    /// `[14][amount: u64 LE][decimals: u8]` (10 bytes).
161    #[inline(always)]
162    pub fn encode_mint_to_checked(amount: u64, decimals: u8) -> [u8; 10] {
163        amount_checked_ix(IX_MINT_TO_CHECKED, amount, decimals)
164    }
165
166    /// Reference `BurnChecked { amount, decimals }`,
167    /// `[15][amount: u64 LE][decimals: u8]` (10 bytes).
168    #[inline(always)]
169    pub fn encode_burn_checked(amount: u64, decimals: u8) -> [u8; 10] {
170        amount_checked_ix(IX_BURN_CHECKED, amount, decimals)
171    }
172
173    /// Reference `Revoke`, `[5]` (1 byte).
174    #[inline(always)]
175    pub fn encode_revoke() -> [u8; 1] {
176        [IX_REVOKE]
177    }
178
179    /// Reference `CloseAccount`, `[9]` (1 byte).
180    #[inline(always)]
181    pub fn encode_close_account() -> [u8; 1] {
182        [IX_CLOSE_ACCOUNT]
183    }
184
185    /// Reference `FreezeAccount`, `[10]` (1 byte).
186    #[inline(always)]
187    pub fn encode_freeze_account() -> [u8; 1] {
188        [IX_FREEZE_ACCOUNT]
189    }
190
191    /// Reference `ThawAccount`, `[11]` (1 byte).
192    #[inline(always)]
193    pub fn encode_thaw_account() -> [u8; 1] {
194        [IX_THAW_ACCOUNT]
195    }
196
197    /// Reference `SyncNative`, `[17]` (1 byte).
198    #[inline(always)]
199    pub fn encode_sync_native() -> [u8; 1] {
200        [IX_SYNC_NATIVE]
201    }
202
203    /// Reference `InitializeAccount2 { owner }`, `[16][owner: 32 bytes]`
204    /// (33 bytes).
205    #[inline(always)]
206    pub fn encode_initialize_account2(owner: &[u8; 32]) -> [u8; 33] {
207        let mut data = [0u8; 33];
208        data[0] = IX_INITIALIZE_ACCOUNT2;
209        data[1..33].copy_from_slice(owner);
210        data
211    }
212
213    /// Reference `InitializeAccount3 { owner }`, `[18][owner: 32 bytes]`
214    /// (33 bytes).
215    #[inline(always)]
216    pub fn encode_initialize_account3(owner: &[u8; 32]) -> [u8; 33] {
217        let mut data = [0u8; 33];
218        data[0] = IX_INITIALIZE_ACCOUNT3;
219        data[1..33].copy_from_slice(owner);
220        data
221    }
222
223    /// Reference `SetAuthority { authority_type, new_authority }`.
224    ///
225    /// Layout: `[6][authority_type: u8][COption tag: u8]` and, when
226    /// `new_authority` is `Some`, `[new_authority: 32 bytes]`. The tag byte
227    /// is 1 (Some) or 0 (None). Returns the fixed 35-byte buffer and the
228    /// number of meaningful bytes (35 for Some, 3 for None).
229    #[inline(always)]
230    pub fn encode_set_authority(
231        authority_type: u8,
232        new_authority: Option<&[u8; 32]>,
233    ) -> ([u8; 35], usize) {
234        let mut data = [0u8; 35];
235        data[0] = IX_SET_AUTHORITY;
236        data[1] = authority_type;
237        match new_authority {
238            Some(key) => {
239                data[2] = 1;
240                data[3..35].copy_from_slice(key);
241                (data, 35)
242            }
243            None => {
244                data[2] = 0;
245                (data, 3)
246            }
247        }
248    }
249}
250
251// =====================================================================
252// Differential-oracle reference encoders (System wire format).
253// Discriminators are 4-byte u32 LE.
254// =====================================================================
255
256/// System program instruction reference encoders, used as a differential
257/// oracle for the shipped `hopper_runtime::system::encoders`.
258pub mod system {
259    /// `CreateAccount` discriminator (u32 LE).
260    pub const IX_CREATE_ACCOUNT: u32 = 0;
261    /// `Assign` discriminator (u32 LE).
262    pub const IX_ASSIGN: u32 = 1;
263    /// `Transfer` discriminator (u32 LE).
264    pub const IX_TRANSFER: u32 = 2;
265    /// `Allocate` discriminator (u32 LE).
266    pub const IX_ALLOCATE: u32 = 8;
267    pub const IX_CREATE_ACCOUNT_ALLOW_PREFUND: u32 = 13;
268
269    /// Reference `CreateAccount { lamports, space, owner }`.
270    ///
271    /// Layout: `[disc: u32 LE = 0][lamports: u64 LE][space: u64 LE]
272    /// [owner: 32 bytes]`, 52 bytes.
273    #[inline(always)]
274    pub fn encode_create_account(lamports: u64, space: u64, owner: &[u8; 32]) -> [u8; 52] {
275        let mut data = [0u8; 52];
276        data[0..4].copy_from_slice(&IX_CREATE_ACCOUNT.to_le_bytes());
277        data[4..12].copy_from_slice(&lamports.to_le_bytes());
278        data[12..20].copy_from_slice(&space.to_le_bytes());
279        data[20..52].copy_from_slice(owner);
280        data
281    }
282
283    /// Reference `CreateAccountAllowPrefund { lamports, space, owner }`.
284    ///
285    /// Layout: `[disc: u32 LE = 13][lamports: u64 LE][space: u64 LE]
286    /// [owner: 32 bytes]`, 52 bytes. Byte-identical to `CreateAccount`
287    /// except the tag.
288    #[inline(always)]
289    pub fn encode_create_account_allow_prefund(
290        lamports: u64,
291        space: u64,
292        owner: &[u8; 32],
293    ) -> [u8; 52] {
294        let mut data = [0u8; 52];
295        data[0..4].copy_from_slice(&IX_CREATE_ACCOUNT_ALLOW_PREFUND.to_le_bytes());
296        data[4..12].copy_from_slice(&lamports.to_le_bytes());
297        data[12..20].copy_from_slice(&space.to_le_bytes());
298        data[20..52].copy_from_slice(owner);
299        data
300    }
301
302    /// Reference `Transfer { lamports }`.
303    ///
304    /// Layout: `[disc: u32 LE = 2][lamports: u64 LE]`, 12 bytes.
305    #[inline(always)]
306    pub fn encode_transfer(lamports: u64) -> [u8; 12] {
307        let mut data = [0u8; 12];
308        data[0..4].copy_from_slice(&IX_TRANSFER.to_le_bytes());
309        data[4..12].copy_from_slice(&lamports.to_le_bytes());
310        data
311    }
312
313    /// Reference `Assign { owner }`.
314    ///
315    /// Layout: `[disc: u32 LE = 1][owner: 32 bytes]`, 36 bytes.
316    #[inline(always)]
317    pub fn encode_assign(owner: &[u8; 32]) -> [u8; 36] {
318        let mut data = [0u8; 36];
319        data[0..4].copy_from_slice(&IX_ASSIGN.to_le_bytes());
320        data[4..36].copy_from_slice(owner);
321        data
322    }
323
324    /// Reference `Allocate { space }`.
325    ///
326    /// Layout: `[disc: u32 LE = 8][space: u64 LE]`, 12 bytes.
327    #[inline(always)]
328    pub fn encode_allocate(space: u64) -> [u8; 12] {
329        let mut data = [0u8; 12];
330        data[0..4].copy_from_slice(&IX_ALLOCATE.to_le_bytes());
331        data[4..12].copy_from_slice(&space.to_le_bytes());
332        data
333    }
334
335    // ── Durable-nonce family (fixed-size, seed-free) ────────────────
336
337    /// `AdvanceNonceAccount` discriminator (u32 LE).
338    pub const IX_ADVANCE_NONCE: u32 = 4;
339    /// `WithdrawNonceAccount` discriminator (u32 LE).
340    pub const IX_WITHDRAW_NONCE: u32 = 5;
341    /// `InitializeNonceAccount` discriminator (u32 LE).
342    pub const IX_INITIALIZE_NONCE: u32 = 6;
343    /// `AuthorizeNonceAccount` discriminator (u32 LE).
344    pub const IX_AUTHORIZE_NONCE: u32 = 7;
345    /// `UpgradeNonceAccount` discriminator (u32 LE).
346    pub const IX_UPGRADE_NONCE: u32 = 12;
347
348    /// Reference `AdvanceNonceAccount`, `[4u32 LE]`, 4 bytes.
349    #[inline(always)]
350    pub fn encode_advance_nonce_account() -> [u8; 4] {
351        IX_ADVANCE_NONCE.to_le_bytes()
352    }
353
354    /// Reference `WithdrawNonceAccount { lamports }`,
355    /// `[5u32 LE][lamports: u64 LE]`, 12 bytes.
356    #[inline(always)]
357    pub fn encode_withdraw_nonce_account(lamports: u64) -> [u8; 12] {
358        let mut data = [0u8; 12];
359        data[0..4].copy_from_slice(&IX_WITHDRAW_NONCE.to_le_bytes());
360        data[4..12].copy_from_slice(&lamports.to_le_bytes());
361        data
362    }
363
364    /// Reference `InitializeNonceAccount { authority }`,
365    /// `[6u32 LE][authority: 32 bytes]`, 36 bytes.
366    #[inline(always)]
367    pub fn encode_initialize_nonce_account(authority: &[u8; 32]) -> [u8; 36] {
368        let mut data = [0u8; 36];
369        data[0..4].copy_from_slice(&IX_INITIALIZE_NONCE.to_le_bytes());
370        data[4..36].copy_from_slice(authority);
371        data
372    }
373
374    /// Reference `AuthorizeNonceAccount { new_authority }`,
375    /// `[7u32 LE][new_authority: 32 bytes]`, 36 bytes.
376    #[inline(always)]
377    pub fn encode_authorize_nonce_account(new_authority: &[u8; 32]) -> [u8; 36] {
378        let mut data = [0u8; 36];
379        data[0..4].copy_from_slice(&IX_AUTHORIZE_NONCE.to_le_bytes());
380        data[4..36].copy_from_slice(new_authority);
381        data
382    }
383
384    /// Reference `UpgradeNonceAccount`, `[12u32 LE]`, 4 bytes.
385    #[inline(always)]
386    pub fn encode_upgrade_nonce_account() -> [u8; 4] {
387        IX_UPGRADE_NONCE.to_le_bytes()
388    }
389}
390
391// =====================================================================
392// Golden-vector unit tests.
393//
394// These pin the exact byte strings the *shipped* encoders emit against the
395// SPL Token / System program specification for concrete inputs, and anchor
396// the differential oracle by asserting the reference encoders agree with the
397// shipped bytes at the same vectors.
398// =====================================================================
399#[cfg(test)]
400extern crate std;
401
402#[cfg(test)]
403mod tests {
404    use hopper_runtime::system::encoders as rt_system;
405    use hopper_runtime::token::encoders as rt_token;
406
407    const AMOUNT: u64 = 0x0102_0304_0506_0708;
408    const AMOUNT_LE: [u8; 8] = [0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01];
409    // Distinct per-byte pattern so an offset/order bug is visible.
410    const OWNER: [u8; 32] = [
411        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
412        25, 26, 27, 28, 29, 30, 31,
413    ];
414
415    #[test]
416    fn spl_amount_instructions_golden() {
417        for (bytes, disc) in [
418            (rt_token::encode_transfer(AMOUNT), 3u8),
419            (rt_token::encode_approve(AMOUNT), 4),
420            (rt_token::encode_mint_to(AMOUNT), 7),
421            (rt_token::encode_burn(AMOUNT), 8),
422        ] {
423            assert_eq!(bytes[0], disc);
424            assert_eq!(&bytes[1..9], &AMOUNT_LE);
425        }
426    }
427
428    #[test]
429    fn spl_checked_instructions_golden() {
430        for (bytes, disc) in [
431            (rt_token::encode_transfer_checked(AMOUNT, 9), 12u8),
432            (rt_token::encode_approve_checked(AMOUNT, 9), 13),
433            (rt_token::encode_mint_to_checked(AMOUNT, 9), 14),
434            (rt_token::encode_burn_checked(AMOUNT, 9), 15),
435        ] {
436            assert_eq!(bytes[0], disc);
437            assert_eq!(&bytes[1..9], &AMOUNT_LE);
438            assert_eq!(bytes[9], 9);
439        }
440    }
441
442    #[test]
443    fn spl_single_byte_instructions_golden() {
444        assert_eq!(rt_token::encode_revoke(), [5]);
445        assert_eq!(rt_token::encode_close_account(), [9]);
446        assert_eq!(rt_token::encode_freeze_account(), [10]);
447        assert_eq!(rt_token::encode_thaw_account(), [11]);
448        assert_eq!(rt_token::encode_sync_native(), [17]);
449        assert_eq!(rt_token::encode_initialize_account(), [1]);
450    }
451
452    #[test]
453    fn spl_initialize_account_golden() {
454        let a2 = rt_token::encode_initialize_account_with_owner(16, &OWNER);
455        assert_eq!(a2[0], 16);
456        assert_eq!(&a2[1..33], &OWNER);
457        let a3 = rt_token::encode_initialize_account_with_owner(18, &OWNER);
458        assert_eq!(a3[0], 18);
459        assert_eq!(&a3[1..33], &OWNER);
460    }
461
462    #[test]
463    fn spl_set_authority_golden() {
464        let (some, some_len) = rt_token::encode_set_authority(2, Some(&OWNER));
465        assert_eq!(some_len, 35);
466        assert_eq!(some[0], 6);
467        assert_eq!(some[1], 2);
468        assert_eq!(some[2], 1);
469        assert_eq!(&some[3..35], &OWNER);
470
471        let (none, none_len) = rt_token::encode_set_authority(3, None);
472        assert_eq!(none_len, 3);
473        assert_eq!(none[0], 6);
474        assert_eq!(none[1], 3);
475        assert_eq!(none[2], 0);
476    }
477
478    #[test]
479    fn system_create_account_golden() {
480        let d = rt_system::encode_create_account(AMOUNT, 165, &OWNER);
481        assert_eq!(&d[0..4], &[0, 0, 0, 0]);
482        assert_eq!(&d[4..12], &AMOUNT_LE);
483        assert_eq!(&d[12..20], &165u64.to_le_bytes());
484        assert_eq!(&d[20..52], &OWNER);
485    }
486
487    #[test]
488    fn system_create_account_allow_prefund_golden() {
489        let d = rt_system::encode_create_account_allow_prefund(AMOUNT, 165, &OWNER);
490        assert_eq!(&d[0..4], &[13, 0, 0, 0]);
491        assert_eq!(&d[4..12], &AMOUNT_LE);
492        assert_eq!(&d[12..20], &165u64.to_le_bytes());
493        assert_eq!(&d[20..52], &OWNER);
494        // Everything but the tag matches CreateAccount.
495        let plain = rt_system::encode_create_account(AMOUNT, 165, &OWNER);
496        assert_eq!(&d[4..], &plain[4..]);
497    }
498
499    #[test]
500    fn system_transfer_golden() {
501        let d = rt_system::encode_transfer(AMOUNT);
502        assert_eq!(&d[0..4], &[2, 0, 0, 0]);
503        assert_eq!(&d[4..12], &AMOUNT_LE);
504    }
505
506    #[test]
507    fn system_assign_golden() {
508        let d = rt_system::encode_assign(&OWNER);
509        assert_eq!(&d[0..4], &[1, 0, 0, 0]);
510        assert_eq!(&d[4..36], &OWNER);
511    }
512
513    #[test]
514    fn system_allocate_golden() {
515        let d = rt_system::encode_allocate(AMOUNT);
516        assert_eq!(&d[0..4], &[8, 0, 0, 0]);
517        assert_eq!(&d[4..12], &AMOUNT_LE);
518    }
519
520    #[test]
521    fn system_nonce_family_golden() {
522        assert_eq!(rt_system::encode_advance_nonce_account(), [4, 0, 0, 0]);
523        let w = rt_system::encode_withdraw_nonce_account(AMOUNT);
524        assert_eq!(&w[0..4], &[5, 0, 0, 0]);
525        assert_eq!(&w[4..12], &AMOUNT_LE);
526        let init = rt_system::encode_initialize_nonce_account(&OWNER);
527        assert_eq!(&init[0..4], &[6, 0, 0, 0]);
528        assert_eq!(&init[4..36], &OWNER);
529        let auth = rt_system::encode_authorize_nonce_account(&OWNER);
530        assert_eq!(&auth[0..4], &[7, 0, 0, 0]);
531        assert_eq!(&auth[4..36], &OWNER);
532        assert_eq!(rt_system::encode_upgrade_nonce_account(), [12, 0, 0, 0]);
533    }
534
535    /// Anchor the differential oracle: the independent reference encoders must
536    /// reproduce the shipped bytes at the golden vectors. Combined with the
537    /// symbolic `*_matches_reference` Kani proofs, this pins the oracle both
538    /// concretely and universally.
539    #[test]
540    fn reference_oracle_agrees_with_shipped_at_golden_vectors() {
541        use super::{spl_token, system};
542
543        assert_eq!(
544            spl_token::encode_transfer(AMOUNT),
545            rt_token::encode_transfer(AMOUNT)
546        );
547        assert_eq!(
548            spl_token::encode_approve(AMOUNT),
549            rt_token::encode_approve(AMOUNT)
550        );
551        assert_eq!(
552            spl_token::encode_mint_to(AMOUNT),
553            rt_token::encode_mint_to(AMOUNT)
554        );
555        assert_eq!(
556            spl_token::encode_burn(AMOUNT),
557            rt_token::encode_burn(AMOUNT)
558        );
559        assert_eq!(
560            spl_token::encode_transfer_checked(AMOUNT, 9),
561            rt_token::encode_transfer_checked(AMOUNT, 9)
562        );
563        assert_eq!(
564            spl_token::encode_approve_checked(AMOUNT, 9),
565            rt_token::encode_approve_checked(AMOUNT, 9)
566        );
567        assert_eq!(
568            spl_token::encode_mint_to_checked(AMOUNT, 9),
569            rt_token::encode_mint_to_checked(AMOUNT, 9)
570        );
571        assert_eq!(
572            spl_token::encode_burn_checked(AMOUNT, 9),
573            rt_token::encode_burn_checked(AMOUNT, 9)
574        );
575        assert_eq!(spl_token::encode_revoke(), rt_token::encode_revoke());
576        assert_eq!(
577            spl_token::encode_close_account(),
578            rt_token::encode_close_account()
579        );
580        assert_eq!(
581            spl_token::encode_freeze_account(),
582            rt_token::encode_freeze_account()
583        );
584        assert_eq!(
585            spl_token::encode_thaw_account(),
586            rt_token::encode_thaw_account()
587        );
588        assert_eq!(
589            spl_token::encode_sync_native(),
590            rt_token::encode_sync_native()
591        );
592        assert_eq!(
593            spl_token::encode_initialize_account2(&OWNER),
594            rt_token::encode_initialize_account_with_owner(16, &OWNER)
595        );
596        assert_eq!(
597            spl_token::encode_initialize_account3(&OWNER),
598            rt_token::encode_initialize_account_with_owner(18, &OWNER)
599        );
600        assert_eq!(
601            spl_token::encode_set_authority(2, Some(&OWNER)),
602            rt_token::encode_set_authority(2, Some(&OWNER))
603        );
604        assert_eq!(
605            spl_token::encode_set_authority(3, None),
606            rt_token::encode_set_authority(3, None)
607        );
608        assert_eq!(
609            system::encode_create_account(AMOUNT, 165, &OWNER),
610            rt_system::encode_create_account(AMOUNT, 165, &OWNER)
611        );
612        assert_eq!(
613            system::encode_create_account_allow_prefund(AMOUNT, 165, &OWNER),
614            rt_system::encode_create_account_allow_prefund(AMOUNT, 165, &OWNER)
615        );
616        assert_eq!(
617            system::encode_transfer(AMOUNT),
618            rt_system::encode_transfer(AMOUNT)
619        );
620        assert_eq!(
621            system::encode_assign(&OWNER),
622            rt_system::encode_assign(&OWNER)
623        );
624        assert_eq!(
625            system::encode_allocate(AMOUNT),
626            rt_system::encode_allocate(AMOUNT)
627        );
628        assert_eq!(
629            system::encode_advance_nonce_account(),
630            rt_system::encode_advance_nonce_account()
631        );
632        assert_eq!(
633            system::encode_withdraw_nonce_account(AMOUNT),
634            rt_system::encode_withdraw_nonce_account(AMOUNT)
635        );
636        assert_eq!(
637            system::encode_initialize_nonce_account(&OWNER),
638            rt_system::encode_initialize_nonce_account(&OWNER)
639        );
640        assert_eq!(
641            system::encode_authorize_nonce_account(&OWNER),
642            rt_system::encode_authorize_nonce_account(&OWNER)
643        );
644        assert_eq!(
645            system::encode_upgrade_nonce_account(),
646            rt_system::encode_upgrade_nonce_account()
647        );
648    }
649}
650
651// =====================================================================
652// Kani layout proofs.
653//
654// Two families, both driven by the `scripts/kani-spl-layouts.{sh,ps1}` lane
655// (CI lane `kani-spl-layout-proofs`):
656//
657//   * `*_layout`, prove the SHIPPED `hopper_runtime::{token,system}::encoders`
658//     directly: correct discriminator, little-endian field offsets, exact
659//     total length, over fully symbolic inputs.
660//   * `*_matches_reference`, differential-oracle proofs: the shipped encoder
661//     is byte-equal to the independent reference encoder in this file for all
662//     symbolic inputs.
663//
664// Conventions (per the raw_input `PID_WORD` lesson):
665//   * scalars are compared as one word (`u64::from_le_bytes(...)`), never a
666//     slice `==`;
667//   * a 32-byte pubkey region is compared with a single symbolic index
668//     `i in 0..32` and one assertion, which universally covers all 32 offsets
669//     without a 32-iteration loop.
670// =====================================================================
671#[cfg(kani)]
672mod kani_proofs {
673    use super::{spl_token, system};
674    use hopper_runtime::system::encoders as rt_system;
675    use hopper_runtime::token::encoders as rt_token;
676
677    #[inline]
678    fn word_at(d: &[u8], off: usize) -> u64 {
679        u64::from_le_bytes([
680            d[off],
681            d[off + 1],
682            d[off + 2],
683            d[off + 3],
684            d[off + 4],
685            d[off + 5],
686            d[off + 6],
687            d[off + 7],
688        ])
689    }
690
691    /// Symbolic-index equality of a byte slice against a 32-byte pubkey:
692    /// universal over all offsets, no loop.
693    #[inline]
694    fn assert_pubkey_region(d: &[u8], off: usize, owner: &[u8; 32]) {
695        let i: usize = kani::any();
696        kani::assume(i < 32);
697        assert_eq!(d[off + i], owner[i]);
698    }
699
700    /// Symbolic-index equality of the 32-byte region at `off` between two
701    /// buffers: universal over all offsets, no loop. Used by the differential
702    /// proofs so shipped == reference is checked without a 32-byte `memcmp`.
703    #[inline]
704    fn assert_regions_eq(a: &[u8], b: &[u8], off: usize) {
705        let i: usize = kani::any();
706        kani::assume(i < 32);
707        assert_eq!(a[off + i], b[off + i]);
708    }
709
710    // ── SPL Token: amount instructions, shipped-encoder layout ─────
711
712    #[kani::proof]
713    fn spl_transfer_layout() {
714        let amount: u64 = kani::any();
715        let d = rt_token::encode_transfer(amount);
716        assert_eq!(d.len(), 9);
717        assert_eq!(d[0], 3);
718        assert_eq!(word_at(&d, 1), amount);
719    }
720
721    #[kani::proof]
722    fn spl_approve_layout() {
723        let amount: u64 = kani::any();
724        let d = rt_token::encode_approve(amount);
725        assert_eq!(d.len(), 9);
726        assert_eq!(d[0], 4);
727        assert_eq!(word_at(&d, 1), amount);
728    }
729
730    #[kani::proof]
731    fn spl_mint_to_layout() {
732        let amount: u64 = kani::any();
733        let d = rt_token::encode_mint_to(amount);
734        assert_eq!(d.len(), 9);
735        assert_eq!(d[0], 7);
736        assert_eq!(word_at(&d, 1), amount);
737    }
738
739    #[kani::proof]
740    fn spl_burn_layout() {
741        let amount: u64 = kani::any();
742        let d = rt_token::encode_burn(amount);
743        assert_eq!(d.len(), 9);
744        assert_eq!(d[0], 8);
745        assert_eq!(word_at(&d, 1), amount);
746    }
747
748    // ── SPL Token: checked instructions, shipped-encoder layout ────
749
750    #[kani::proof]
751    fn spl_transfer_checked_layout() {
752        let amount: u64 = kani::any();
753        let decimals: u8 = kani::any();
754        let d = rt_token::encode_transfer_checked(amount, decimals);
755        assert_eq!(d.len(), 10);
756        assert_eq!(d[0], 12);
757        assert_eq!(word_at(&d, 1), amount);
758        assert_eq!(d[9], decimals);
759    }
760
761    #[kani::proof]
762    fn spl_approve_checked_layout() {
763        let amount: u64 = kani::any();
764        let decimals: u8 = kani::any();
765        let d = rt_token::encode_approve_checked(amount, decimals);
766        assert_eq!(d.len(), 10);
767        assert_eq!(d[0], 13);
768        assert_eq!(word_at(&d, 1), amount);
769        assert_eq!(d[9], decimals);
770    }
771
772    #[kani::proof]
773    fn spl_mint_to_checked_layout() {
774        let amount: u64 = kani::any();
775        let decimals: u8 = kani::any();
776        let d = rt_token::encode_mint_to_checked(amount, decimals);
777        assert_eq!(d.len(), 10);
778        assert_eq!(d[0], 14);
779        assert_eq!(word_at(&d, 1), amount);
780        assert_eq!(d[9], decimals);
781    }
782
783    #[kani::proof]
784    fn spl_burn_checked_layout() {
785        let amount: u64 = kani::any();
786        let decimals: u8 = kani::any();
787        let d = rt_token::encode_burn_checked(amount, decimals);
788        assert_eq!(d.len(), 10);
789        assert_eq!(d[0], 15);
790        assert_eq!(word_at(&d, 1), amount);
791        assert_eq!(d[9], decimals);
792    }
793
794    // ── SPL Token: single-byte instructions (deterministic) ─────────
795
796    #[kani::proof]
797    fn spl_single_byte_discriminators() {
798        assert_eq!(rt_token::encode_revoke(), [5]);
799        assert_eq!(rt_token::encode_close_account(), [9]);
800        assert_eq!(rt_token::encode_freeze_account(), [10]);
801        assert_eq!(rt_token::encode_thaw_account(), [11]);
802        assert_eq!(rt_token::encode_sync_native(), [17]);
803        assert_eq!(rt_token::encode_initialize_account(), [1]);
804    }
805
806    // ── SPL Token: initialize-account-with-owner, shipped layout ───
807
808    #[kani::proof]
809    fn spl_initialize_account2_layout() {
810        let owner: [u8; 32] = kani::any();
811        let d = rt_token::encode_initialize_account_with_owner(16, &owner);
812        assert_eq!(d.len(), 33);
813        assert_eq!(d[0], 16);
814        assert_pubkey_region(&d, 1, &owner);
815    }
816
817    #[kani::proof]
818    fn spl_initialize_account3_layout() {
819        let owner: [u8; 32] = kani::any();
820        let d = rt_token::encode_initialize_account_with_owner(18, &owner);
821        assert_eq!(d.len(), 33);
822        assert_eq!(d[0], 18);
823        assert_pubkey_region(&d, 1, &owner);
824    }
825
826    // ── SPL Token: SetAuthority (both COption branches), shipped ───
827
828    #[kani::proof]
829    fn spl_set_authority_some_layout() {
830        let authority_type: u8 = kani::any();
831        let owner: [u8; 32] = kani::any();
832        let (d, len) = rt_token::encode_set_authority(authority_type, Some(&owner));
833        assert_eq!(len, 35);
834        assert_eq!(d[0], 6);
835        assert_eq!(d[1], authority_type);
836        assert_eq!(d[2], 1);
837        assert_pubkey_region(&d, 3, &owner);
838    }
839
840    #[kani::proof]
841    fn spl_set_authority_none_layout() {
842        let authority_type: u8 = kani::any();
843        let (d, len) = rt_token::encode_set_authority(authority_type, None);
844        assert_eq!(len, 3);
845        assert_eq!(d[0], 6);
846        assert_eq!(d[1], authority_type);
847        assert_eq!(d[2], 0);
848    }
849
850    // ── System program, shipped-encoder layout ─────────────────────
851
852    /// The 4-byte u32 discriminator: low byte = tag, high 3 bytes = 0.
853    #[inline]
854    fn assert_system_disc(d: &[u8], tag: u8) {
855        assert_eq!(d[0], tag);
856        assert_eq!(d[1], 0);
857        assert_eq!(d[2], 0);
858        assert_eq!(d[3], 0);
859    }
860
861    #[kani::proof]
862    fn system_transfer_layout() {
863        let lamports: u64 = kani::any();
864        let d = rt_system::encode_transfer(lamports);
865        assert_eq!(d.len(), 12);
866        assert_system_disc(&d, 2);
867        assert_eq!(word_at(&d, 4), lamports);
868    }
869
870    #[kani::proof]
871    fn system_allocate_layout() {
872        let space: u64 = kani::any();
873        let d = rt_system::encode_allocate(space);
874        assert_eq!(d.len(), 12);
875        assert_system_disc(&d, 8);
876        assert_eq!(word_at(&d, 4), space);
877    }
878
879    #[kani::proof]
880    fn system_assign_layout() {
881        let owner: [u8; 32] = kani::any();
882        let d = rt_system::encode_assign(&owner);
883        assert_eq!(d.len(), 36);
884        assert_system_disc(&d, 1);
885        assert_pubkey_region(&d, 4, &owner);
886    }
887
888    #[kani::proof]
889    fn system_create_account_layout() {
890        let lamports: u64 = kani::any();
891        let space: u64 = kani::any();
892        let owner: [u8; 32] = kani::any();
893        let d = rt_system::encode_create_account(lamports, space, &owner);
894        assert_eq!(d.len(), 52);
895        assert_system_disc(&d, 0);
896        assert_eq!(word_at(&d, 4), lamports);
897        assert_eq!(word_at(&d, 12), space);
898        assert_pubkey_region(&d, 20, &owner);
899    }
900
901    #[kani::proof]
902    fn system_create_account_allow_prefund_layout() {
903        let lamports: u64 = kani::any();
904        let space: u64 = kani::any();
905        let owner: [u8; 32] = kani::any();
906        let d = rt_system::encode_create_account_allow_prefund(lamports, space, &owner);
907        assert_eq!(d.len(), 52);
908        assert_system_disc(&d, 13);
909        assert_eq!(word_at(&d, 4), lamports);
910        assert_eq!(word_at(&d, 12), space);
911        assert_pubkey_region(&d, 20, &owner);
912    }
913
914    // ── System durable-nonce family (fixed-size), shipped layout ───
915
916    #[kani::proof]
917    fn system_advance_nonce_account_layout() {
918        let d = rt_system::encode_advance_nonce_account();
919        assert_eq!(d.len(), 4);
920        assert_system_disc(&d, 4);
921    }
922
923    #[kani::proof]
924    fn system_withdraw_nonce_account_layout() {
925        let lamports: u64 = kani::any();
926        let d = rt_system::encode_withdraw_nonce_account(lamports);
927        assert_eq!(d.len(), 12);
928        assert_system_disc(&d, 5);
929        assert_eq!(word_at(&d, 4), lamports);
930    }
931
932    #[kani::proof]
933    fn system_initialize_nonce_account_layout() {
934        let authority: [u8; 32] = kani::any();
935        let d = rt_system::encode_initialize_nonce_account(&authority);
936        assert_eq!(d.len(), 36);
937        assert_system_disc(&d, 6);
938        assert_pubkey_region(&d, 4, &authority);
939    }
940
941    #[kani::proof]
942    fn system_authorize_nonce_account_layout() {
943        let new_authority: [u8; 32] = kani::any();
944        let d = rt_system::encode_authorize_nonce_account(&new_authority);
945        assert_eq!(d.len(), 36);
946        assert_system_disc(&d, 7);
947        assert_pubkey_region(&d, 4, &new_authority);
948    }
949
950    #[kani::proof]
951    fn system_upgrade_nonce_account_layout() {
952        let d = rt_system::encode_upgrade_nonce_account();
953        assert_eq!(d.len(), 4);
954        assert_system_disc(&d, 12);
955    }
956
957    // ── Differential oracle: shipped encoder == reference encoder ───
958    //
959    // Each proof compares the shipped `rt_*` encoder against the independent
960    // reference in `super::{spl_token, system}`, field-wise / word-wise /
961    // symbolic-index, so equality is proven for all symbolic inputs without a
962    // large `memcmp` loop.
963
964    #[kani::proof]
965    fn spl_transfer_matches_reference() {
966        let amount: u64 = kani::any();
967        let s = rt_token::encode_transfer(amount);
968        let r = spl_token::encode_transfer(amount);
969        assert_eq!(s[0], r[0]);
970        assert_eq!(word_at(&s, 1), word_at(&r, 1));
971    }
972
973    #[kani::proof]
974    fn spl_approve_matches_reference() {
975        let amount: u64 = kani::any();
976        let s = rt_token::encode_approve(amount);
977        let r = spl_token::encode_approve(amount);
978        assert_eq!(s[0], r[0]);
979        assert_eq!(word_at(&s, 1), word_at(&r, 1));
980    }
981
982    #[kani::proof]
983    fn spl_mint_to_matches_reference() {
984        let amount: u64 = kani::any();
985        let s = rt_token::encode_mint_to(amount);
986        let r = spl_token::encode_mint_to(amount);
987        assert_eq!(s[0], r[0]);
988        assert_eq!(word_at(&s, 1), word_at(&r, 1));
989    }
990
991    #[kani::proof]
992    fn spl_burn_matches_reference() {
993        let amount: u64 = kani::any();
994        let s = rt_token::encode_burn(amount);
995        let r = spl_token::encode_burn(amount);
996        assert_eq!(s[0], r[0]);
997        assert_eq!(word_at(&s, 1), word_at(&r, 1));
998    }
999
1000    #[kani::proof]
1001    fn spl_transfer_checked_matches_reference() {
1002        let amount: u64 = kani::any();
1003        let decimals: u8 = kani::any();
1004        let s = rt_token::encode_transfer_checked(amount, decimals);
1005        let r = spl_token::encode_transfer_checked(amount, decimals);
1006        assert_eq!(s[0], r[0]);
1007        assert_eq!(word_at(&s, 1), word_at(&r, 1));
1008        assert_eq!(s[9], r[9]);
1009    }
1010
1011    #[kani::proof]
1012    fn spl_approve_checked_matches_reference() {
1013        let amount: u64 = kani::any();
1014        let decimals: u8 = kani::any();
1015        let s = rt_token::encode_approve_checked(amount, decimals);
1016        let r = spl_token::encode_approve_checked(amount, decimals);
1017        assert_eq!(s[0], r[0]);
1018        assert_eq!(word_at(&s, 1), word_at(&r, 1));
1019        assert_eq!(s[9], r[9]);
1020    }
1021
1022    #[kani::proof]
1023    fn spl_mint_to_checked_matches_reference() {
1024        let amount: u64 = kani::any();
1025        let decimals: u8 = kani::any();
1026        let s = rt_token::encode_mint_to_checked(amount, decimals);
1027        let r = spl_token::encode_mint_to_checked(amount, decimals);
1028        assert_eq!(s[0], r[0]);
1029        assert_eq!(word_at(&s, 1), word_at(&r, 1));
1030        assert_eq!(s[9], r[9]);
1031    }
1032
1033    #[kani::proof]
1034    fn spl_burn_checked_matches_reference() {
1035        let amount: u64 = kani::any();
1036        let decimals: u8 = kani::any();
1037        let s = rt_token::encode_burn_checked(amount, decimals);
1038        let r = spl_token::encode_burn_checked(amount, decimals);
1039        assert_eq!(s[0], r[0]);
1040        assert_eq!(word_at(&s, 1), word_at(&r, 1));
1041        assert_eq!(s[9], r[9]);
1042    }
1043
1044    #[kani::proof]
1045    fn spl_single_byte_matches_reference() {
1046        assert_eq!(rt_token::encode_revoke(), spl_token::encode_revoke());
1047        assert_eq!(
1048            rt_token::encode_close_account(),
1049            spl_token::encode_close_account()
1050        );
1051        assert_eq!(
1052            rt_token::encode_freeze_account(),
1053            spl_token::encode_freeze_account()
1054        );
1055        assert_eq!(
1056            rt_token::encode_thaw_account(),
1057            spl_token::encode_thaw_account()
1058        );
1059        assert_eq!(
1060            rt_token::encode_sync_native(),
1061            spl_token::encode_sync_native()
1062        );
1063    }
1064
1065    #[kani::proof]
1066    fn spl_initialize_account2_matches_reference() {
1067        let owner: [u8; 32] = kani::any();
1068        let s = rt_token::encode_initialize_account_with_owner(16, &owner);
1069        let r = spl_token::encode_initialize_account2(&owner);
1070        assert_eq!(s[0], r[0]);
1071        assert_regions_eq(&s, &r, 1);
1072    }
1073
1074    #[kani::proof]
1075    fn spl_initialize_account3_matches_reference() {
1076        let owner: [u8; 32] = kani::any();
1077        let s = rt_token::encode_initialize_account_with_owner(18, &owner);
1078        let r = spl_token::encode_initialize_account3(&owner);
1079        assert_eq!(s[0], r[0]);
1080        assert_regions_eq(&s, &r, 1);
1081    }
1082
1083    #[kani::proof]
1084    fn spl_set_authority_some_matches_reference() {
1085        let authority_type: u8 = kani::any();
1086        let owner: [u8; 32] = kani::any();
1087        let (s, s_len) = rt_token::encode_set_authority(authority_type, Some(&owner));
1088        let (r, r_len) = spl_token::encode_set_authority(authority_type, Some(&owner));
1089        assert_eq!(s_len, r_len);
1090        assert_eq!(s[0], r[0]);
1091        assert_eq!(s[1], r[1]);
1092        assert_eq!(s[2], r[2]);
1093        assert_regions_eq(&s, &r, 3);
1094    }
1095
1096    #[kani::proof]
1097    fn spl_set_authority_none_matches_reference() {
1098        let authority_type: u8 = kani::any();
1099        let (s, s_len) = rt_token::encode_set_authority(authority_type, None);
1100        let (r, r_len) = spl_token::encode_set_authority(authority_type, None);
1101        assert_eq!(s_len, r_len);
1102        assert_eq!(s[0], r[0]);
1103        assert_eq!(s[1], r[1]);
1104        assert_eq!(s[2], r[2]);
1105    }
1106
1107    #[kani::proof]
1108    fn system_transfer_matches_reference() {
1109        let lamports: u64 = kani::any();
1110        let s = rt_system::encode_transfer(lamports);
1111        let r = system::encode_transfer(lamports);
1112        assert_eq!(word_at(&s, 0), word_at(&r, 0));
1113        assert_eq!(word_at(&s, 4), word_at(&r, 4));
1114    }
1115
1116    #[kani::proof]
1117    fn system_allocate_matches_reference() {
1118        let space: u64 = kani::any();
1119        let s = rt_system::encode_allocate(space);
1120        let r = system::encode_allocate(space);
1121        assert_eq!(word_at(&s, 0), word_at(&r, 0));
1122        assert_eq!(word_at(&s, 4), word_at(&r, 4));
1123    }
1124
1125    #[kani::proof]
1126    fn system_assign_matches_reference() {
1127        let owner: [u8; 32] = kani::any();
1128        let s = rt_system::encode_assign(&owner);
1129        let r = system::encode_assign(&owner);
1130        assert_eq!(word_at(&s, 0), word_at(&r, 0));
1131        assert_regions_eq(&s, &r, 4);
1132    }
1133
1134    #[kani::proof]
1135    fn system_create_account_matches_reference() {
1136        let lamports: u64 = kani::any();
1137        let space: u64 = kani::any();
1138        let owner: [u8; 32] = kani::any();
1139        let s = rt_system::encode_create_account(lamports, space, &owner);
1140        let r = system::encode_create_account(lamports, space, &owner);
1141        assert_eq!(word_at(&s, 0), word_at(&r, 0));
1142        assert_eq!(word_at(&s, 4), word_at(&r, 4));
1143        assert_eq!(word_at(&s, 12), word_at(&r, 12));
1144        assert_regions_eq(&s, &r, 20);
1145    }
1146
1147    // ── Differential oracle: durable-nonce family ───────────────────
1148
1149    #[kani::proof]
1150    fn system_advance_nonce_account_matches_reference() {
1151        // 4-byte deterministic buffers: direct array equality is 4 elements.
1152        assert_eq!(
1153            rt_system::encode_advance_nonce_account(),
1154            system::encode_advance_nonce_account()
1155        );
1156    }
1157
1158    #[kani::proof]
1159    fn system_withdraw_nonce_account_matches_reference() {
1160        let lamports: u64 = kani::any();
1161        let s = rt_system::encode_withdraw_nonce_account(lamports);
1162        let r = system::encode_withdraw_nonce_account(lamports);
1163        assert_eq!(word_at(&s, 0), word_at(&r, 0));
1164        assert_eq!(word_at(&s, 4), word_at(&r, 4));
1165    }
1166
1167    #[kani::proof]
1168    fn system_initialize_nonce_account_matches_reference() {
1169        let authority: [u8; 32] = kani::any();
1170        let s = rt_system::encode_initialize_nonce_account(&authority);
1171        let r = system::encode_initialize_nonce_account(&authority);
1172        assert_eq!(word_at(&s, 0), word_at(&r, 0));
1173        assert_regions_eq(&s, &r, 4);
1174    }
1175
1176    #[kani::proof]
1177    fn system_authorize_nonce_account_matches_reference() {
1178        let new_authority: [u8; 32] = kani::any();
1179        let s = rt_system::encode_authorize_nonce_account(&new_authority);
1180        let r = system::encode_authorize_nonce_account(&new_authority);
1181        assert_eq!(word_at(&s, 0), word_at(&r, 0));
1182        assert_regions_eq(&s, &r, 4);
1183    }
1184
1185    #[kani::proof]
1186    fn system_upgrade_nonce_account_matches_reference() {
1187        assert_eq!(
1188            rt_system::encode_upgrade_nonce_account(),
1189            system::encode_upgrade_nonce_account()
1190        );
1191    }
1192}