Skip to content

Commit d4e7dd3

Browse files
authored
feat: support SPL Token lamports read & write (#872)
1 parent 31f4eff commit d4e7dd3

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

kmir/src/kmir/kdist/mir-semantics/symbolic/spl-token.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,26 @@ module KMIR-SPL-TOKEN
117117
118118
syntax Bool ::= #isSPLRcRefCellDerefFunc ( String ) [function, total]
119119
rule #isSPLRcRefCellDerefFunc("<std::rc::Rc<std::cell::RefCell<&mut [u8]>> as std::ops::Deref>::deref") => true
120+
rule #isSPLRcRefCellDerefFunc("<std::rc::Rc<std::cell::RefCell<&mut u64>> as std::ops::Deref>::deref") => true
120121
rule #isSPLRcRefCellDerefFunc(_) => false [owise]
121122
122123
syntax Bool ::= #isSPLBorrowFunc ( String ) [function, total]
123124
rule #isSPLBorrowFunc("std::cell::RefCell::<&mut [u8]>::borrow") => true
124125
rule #isSPLBorrowFunc("std::cell::RefCell::<&mut [u8]>::borrow_mut") => true
126+
rule #isSPLBorrowFunc("std::cell::RefCell::<&mut u64>::borrow") => true
127+
rule #isSPLBorrowFunc("std::cell::RefCell::<&mut u64>::borrow_mut") => true
125128
rule #isSPLBorrowFunc(_) => false [owise]
126129
127130
syntax Bool ::= #isSPLBorrowMutFunc ( String ) [function, total]
128131
rule #isSPLBorrowMutFunc("std::cell::RefCell::<&mut [u8]>::borrow_mut") => true
132+
rule #isSPLBorrowMutFunc("std::cell::RefCell::<&mut u64>::borrow_mut") => true
129133
rule #isSPLBorrowMutFunc(_) => false [owise]
130134
131135
syntax Bool ::= #isSPLRefDerefFunc ( String ) [function, total]
132136
rule #isSPLRefDerefFunc("<std::cell::Ref<'_, &mut [u8]> as std::ops::Deref>::deref") => true
133137
rule #isSPLRefDerefFunc("<std::cell::RefMut<'_, &mut [u8]> as std::ops::DerefMut>::deref_mut") => true
138+
rule #isSPLRefDerefFunc("<std::cell::Ref<'_, &mut u64> as std::ops::Deref>::deref") => true
139+
rule #isSPLRefDerefFunc("<std::cell::RefMut<'_, &mut u64> as std::ops::DerefMut>::deref_mut") => true
134140
rule #isSPLRefDerefFunc(_) => false [owise]
135141
136142
syntax Bool ::= #isSPLUnpackFunc ( String ) [function, total]

kmir/src/tests/integration/data/prove-rs/spl_token_domain_data.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ fn main() {
6363
);
6464

6565
test_spltoken_domain_data(&acc, &mint, &multisig, &rent);
66+
// Keep lamports read/write harness reachable so stable-mir emits it.
67+
test_spl_account_lamports_read_then_write(&[acc.clone()]);
6668
}
6769

6870
#[derive(Clone)]
@@ -205,6 +207,16 @@ fn test_spl_multisig_domain_data(multisig: &AccountInfo<'_>) {
205207
assert_eq!(unpacked_multisig.signers[2], MULTISIG_SIGNER_C);
206208
}
207209

210+
/// Read symbolic lamports, write a concrete value, then read again to mirror the close_account stuck case and ensure writes propagate.
211+
#[inline(never)]
212+
fn test_spl_account_lamports_read_then_write(accounts: &[AccountInfo; 1]) -> (u64, u64) {
213+
cheatcode_is_spl_account(&accounts[0]);
214+
let before = **accounts[0].lamports.borrow();
215+
**accounts[0].lamports.borrow_mut() = 42;
216+
let after = **accounts[0].lamports.borrow();
217+
(before, after)
218+
}
219+
208220
fn test_spl_rent_domain_data(rent: &AccountInfo<'_>) {
209221
// Compare rent burn semantics with the canonical sysvar value
210222
let sysrent = Rent::get().unwrap();

kmir/src/tests/integration/test_integration.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@
3737
'assume-cheatcode': ['check_assume'],
3838
'assume-cheatcode-conflict-fail': ['check_assume_conflict'],
3939
'transmute-bytes': ['bytes_to_u64', 'u64_to_bytes'],
40-
'spl_token_domain_data': ['test_spl_account_domain_data', 'test_spl_mint_domain_data', 'test_spl_rent_domain_data'],
40+
'spl_token_domain_data': [
41+
'test_spl_account_domain_data',
42+
'test_spl_mint_domain_data',
43+
'test_spl_rent_domain_data',
44+
'test_spl_account_lamports_read_then_write',
45+
],
4146
}
4247
PROVE_RS_SHOW_SPECS = [
4348
'local-raw-fail',

0 commit comments

Comments
 (0)