Skip to content

reclaim buffer account - #60

Open
kaze-cow wants to merge 6 commits into
kaze/sc-151-state-receiverfrom
kaze/sc-151-close-buffer-account
Open

reclaim buffer account#60
kaze-cow wants to merge 6 commits into
kaze/sc-151-state-receiverfrom
kaze/sc-151-close-buffer-account

Conversation

@kaze-cow

@kaze-cow kaze-cow commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

Adds the ReclaimBuffers instruction. Also add some more capabilities to the test helpers.

Stacked on #84, which adds the receiver field to the state PDA that this instruction reads. Review that one first; the diff here is against it.

Changes

The instruction takes in 3 accounts, state_account, receiver_account, token_account, plus two additional accounts buffer_pda, mint for each buffer to clear. The mint is required to help verify the canonical status of buffer_pda, as well as to call Burn if the account happens to hold excess funds.

The instruction can only be called by the receiver account which is registered in the state_pda (see #84).

Since a bad actor could send 1 wei/lamport of a token to the buffers just before we close them, the buffer may become unable to be closed and the instruction would fail. This could be used as a griefing tactic, so this instruction will additionally Burn any remaining tokens found in the buffer before closing. Burn is used instead of Transfer because a transfer would likely require conditional allocation and sending--all for what is almost certainly a tiny . So its much easier to simply burn this amount entirely and move on. As this is a potentially destructive operation, multiple warnings have been added around the codebase to prevent this from being overlooked. Additionally, while most tokens support anyone being able to Burn their own tokens, there may exist certain 2022 tokens which disallow it, and so the buffer could not be closed unless we were to empty the account completely.

How to test

  • Confirm ReclaimBuffer general methodology.
  • Consider behavior of burning tokens as a way of reducing the security impact

@kaze-cow kaze-cow self-assigned this Jul 6, 2026
@kaze-cow
kaze-cow requested a review from a team as a code owner July 6, 2026 14:47
@linear-code

linear-code Bot commented Jul 6, 2026

Copy link
Copy Markdown

SC-151

@kaze-cow kaze-cow changed the title Kaze/sc 151 close buffer account reclaim buffer account Jul 7, 2026

@fedgiac fedgiac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is fairly large so I'd suggest to split it in 2: first, introducing the new state PDA data and the initialization; then, introducing the new reclaim buffer instruction. If that's large as well you can consider splitting parsing/ix building to the processing but maybe it isn't needed (the burn logic is nontrivial though).

Comment thread programs/settlement/src/reclaim_buffer.rs Outdated
Comment thread programs/settlement/src/reclaim_buffer.rs Outdated
Base automatically changed from kaze/sc-150-close-order-account to main July 17, 2026 09:54
@kaze-cow
kaze-cow force-pushed the kaze/sc-151-close-buffer-account branch from 1221424 to fc9e0ca Compare July 30, 2026 09:02
Closes buffer PDAs and returns their rent to the `receiver` recorded in the
state PDA, which must sign. Each buffer is paired with its `mint` so the
canonical buffer PDA can be re-derived and verified.

Any token balance still sitting in a buffer is burned before the close: a
bad actor could otherwise send dust to a buffer to keep it from closing, and
recovering the dust would cost more than it's worth. This is destructive, so
it's flagged at every level of the call chain.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@kaze-cow
kaze-cow force-pushed the kaze/sc-151-close-buffer-account branch from e785bfa to c413b9a Compare July 30, 2026 09:19
@kaze-cow
kaze-cow changed the base branch from main to kaze/sc-151-state-receiver July 30, 2026 09:19
Comment thread interface/src/instruction/reclaim_buffer.rs
Comment thread programs/settlement/src/reclaim_buffer.rs Outdated
Comment thread interface/src/instruction/reclaim_buffer.rs
@kaze-cow
kaze-cow requested a review from fedgiac August 3, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants