Skip to content

Commit dcc138f

Browse files
authored
fix(spl): refactor the domain data constructor for Pubkey and & Pubkey (#860)
1 parent 4d819f7 commit dcc138f

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ module KMIR-SPL-TOKEN
9393
| SPLDataBuffer ( Value )
9494
| SPLDataBorrow ( Place , Value )
9595
| SPLDataBorrowMut ( Place , Value )
96+
| SPLPubkeyRef ( Value )
9697
```
9798

9899
## Helper predicates
@@ -103,9 +104,8 @@ module KMIR-SPL-TOKEN
103104
104105
syntax Bool ::= #isSplCOptionPubkey ( Value ) [function, total]
105106
rule #isSplCOptionPubkey(Aggregate(variantIdx(0), .List)) => true
106-
rule #isSplCOptionPubkey(Aggregate(variantIdx(1), ListItem(Range(KEY)) REST))
107+
rule #isSplCOptionPubkey(Aggregate(variantIdx(1), ListItem(Aggregate(variantIdx(0), ListItem(Range(KEY))))))
107108
=> #isSplPubkey(KEY)
108-
requires REST ==K .List
109109
rule #isSplCOptionPubkey(_) => false [owise]
110110
111111
syntax Bool ::= #isSplCOptionU64 ( Value ) [function, total]
@@ -166,7 +166,7 @@ module KMIR-SPL-TOKEN
166166
=> #setLocalValue(
167167
place(LOCAL, appendP(PROJS, projectionElemDeref .ProjectionElems)),
168168
Aggregate(variantIdx(0),
169-
ListItem(Range(?SplAccountKey:List)) // pub key: &'a Pubkey
169+
ListItem(SPLPubkeyRef(Aggregate(variantIdx(0), ListItem(Range(?SplAccountKey:List))))) // pub key: &'a Pubkey
170170
ListItem(
171171
SPLRefCell(
172172
place(
@@ -184,8 +184,8 @@ module KMIR-SPL-TOKEN
184184
),
185185
SPLDataBuffer( // data: Rc<RefCell<&'a mut [u8]>>, Aggregate is for &account.data
186186
Aggregate(variantIdx(0),
187-
ListItem(Range(?SplMintKey:List)) // Account.mint: Pubkey
188-
ListItem(Range(?SplTokenOwnerKey:List)) // Account.owner: Pubkey
187+
ListItem(Aggregate(variantIdx(0), ListItem(Range(?SplMintKey:List)))) // Account.mint: Pubkey
188+
ListItem(Aggregate(variantIdx(0), ListItem(Range(?SplTokenOwnerKey:List)))) // Account.owner: Pubkey
189189
ListItem(Integer(?SplAmount:Int, 64, false)) // Account.amount: u64
190190
ListItem(?SplDelegateCOpt:Value) // Account.delegate: COption<Pubkey>
191191
ListItem(Integer(?SplAccountState:Int, 8, false)) // Account.state: AccountState (repr u8)
@@ -196,7 +196,7 @@ module KMIR-SPL-TOKEN
196196
)
197197
)
198198
)
199-
ListItem(Range(?SplOwnerKey)) // owner: &'a Pubkey
199+
ListItem(SPLPubkeyRef(Aggregate(variantIdx(0), ListItem(Range(?SplOwnerKey:List))))) // owner: &'a Pubkey
200200
ListItem(Integer(?SplRentEpoch:Int, 64, false)) // rent_epoch: u64
201201
ListItem(BoolVal(?_SplIsSigner:Bool)) // is_signer: bool
202202
ListItem(BoolVal(?_SplIsWritable:Bool)) // is_writable: bool
@@ -227,7 +227,7 @@ module KMIR-SPL-TOKEN
227227
=> #setLocalValue(
228228
place(LOCAL, appendP(PROJS, projectionElemDeref .ProjectionElems)),
229229
Aggregate(variantIdx(0),
230-
ListItem(Range(?SplMintAccountKey:List))
230+
ListItem(SPLPubkeyRef(Aggregate(variantIdx(0), ListItem(Range(?SplMintAccountKey:List))))) // pub key: &'a Pubkey
231231
ListItem(
232232
SPLRefCell(
233233
place(
@@ -254,7 +254,7 @@ module KMIR-SPL-TOKEN
254254
)
255255
)
256256
)
257-
ListItem(Range(?SplMintOwnerKey:List))
257+
ListItem(SPLPubkeyRef(Aggregate(variantIdx(0), ListItem(Range(?SplMintOwnerKey:List))))) // owner: &'a Pubkey
258258
ListItem(Integer(?SplMintRentEpoch:Int, 64, false))
259259
ListItem(BoolVal(?_SplMintIsSigner:Bool))
260260
ListItem(BoolVal(?_SplMintIsWritable:Bool))
@@ -341,6 +341,30 @@ expose the wrapped payload directly.
341341
</k>
342342
```
343343

344+
## Pubkey references
345+
346+
```k
347+
syntax Context ::= "CtxSPLPubkeyRef"
348+
349+
rule <k> #traverseProjection(
350+
DEST,
351+
SPLPubkeyRef(VAL),
352+
projectionElemDeref PROJS,
353+
CTXTS
354+
)
355+
=> #traverseProjection(
356+
DEST,
357+
VAL,
358+
PROJS,
359+
CtxSPLPubkeyRef CTXTS
360+
)
361+
...
362+
</k>
363+
[priority(30)]
364+
rule #buildUpdate(VAL, CtxSPLPubkeyRef CTXS) => #buildUpdate(SPLPubkeyRef(VAL), CTXS)
365+
rule #projectionsFor(CtxSPLPubkeyRef CTXS, PROJS) => #projectionsFor(CTXS, projectionElemDeref PROJS)
366+
```
367+
344368
## Borrowed buffer projections
345369

346370
```k

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ fn test_spltoken_domain_data(
136136
fn test_spl_account_domain_data(acc: &AccountInfo<'_>) {
137137
cheatcode_is_spl_account(acc);
138138

139+
let owner = acc.owner;
140+
assert_eq!(acc.owner, owner);
141+
139142
let mut account = get_account(acc);
140143
account.is_native = COption::Some(0);
141144
account.mint = MINT_KEY;

0 commit comments

Comments
 (0)