Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 61794be

Browse files
authored
token-2022: [L-03] Require memo on self-transfer with memo-transfer (#6865)
token-2022: Require memo on self-transfer with memo-transfer
1 parent 6df92af commit 61794be

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

token/program-2022-test/tests/memo_transfer.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ async fn test_memo_transfers(
7575
let bob_state = token.get_account_info(&bob_account).await.unwrap();
7676
assert_eq!(bob_state.base.amount, 0);
7777

78+
// attempt to transfer from bob to bob without memo
79+
let err = token
80+
.transfer(&bob_account, &bob_account, &bob.pubkey(), 0, &[&bob])
81+
.await
82+
.unwrap_err();
83+
assert_eq!(
84+
err,
85+
TokenClientError::Client(Box::new(TransportError::TransactionError(
86+
TransactionError::InstructionError(
87+
0,
88+
InstructionError::Custom(TokenError::NoMemo as u32)
89+
)
90+
)))
91+
);
92+
let bob_state = token.get_account_info(&bob_account).await.unwrap();
93+
assert_eq!(bob_state.base.amount, 0);
94+
7895
// attempt to transfer from alice to bob with misplaced memo, v1 and current
7996
let mut memo_ix = spl_memo::build_memo(&[240, 159, 166, 150], &[]);
8097
for program_id in [spl_memo::id(), spl_memo::v1::id()] {

token/program-2022/src/processor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ impl Processor {
449449
// This check MUST occur just before the amounts are manipulated
450450
// to ensure self-transfers are fully validated
451451
if self_transfer {
452+
if memo_required(&source_account) {
453+
check_previous_sibling_instruction_is_memo()?;
454+
}
452455
return Ok(());
453456
}
454457

0 commit comments

Comments
 (0)