1

I am following the soldev tutorials. At the Crossing Account and Revival attacks.The program has two methods a lottery initialisation account and a redeem tokens based on the time of entering. After redeeming the account's data is setted to zero and the tokens are given to the signer. In the tutorial the reinitialisation is is stopped by adding an anchor constraint (close=). I understand that the close constraint sets zero data and adds a Close Account discriminator. My question is the following. Once an account which has been closed with this constraint and zero data, can't be reused as an account, throughout calling create_account or the init constraint in anchor? The complete program src is at https://github.com/Unboxed-Software/solana-closing-accounts/blob/starter/programs/closing-accounts/src/lib.rs. Thanks everybody for answers,

1 Answer 1

3

Quick answer: yes!

When Anchor closes an account, it transfers out all of the lamports from the account, which means that the account is eventually cleaned up by the runtime and can be reinitialized.

In the past, it would set a "tombstone" discriminator so that the account isn't "resurrected" later in the same transaction, and now it reassigns the account back to the system program and reallocates its size to 0.

4
  • Could you explain please, why the solana tutorial specifies that a closed account can be reinitialised. I am talking about the code provided by them in the git rep., this would mean that their provided code would be faulty?
    – Mr.H
    Mar 22, 2023 at 5:55
  • A closed account can be reinitialized, as I said in my answer.
    – Jon C
    Mar 23, 2023 at 21:12
  • The docs do not mention that the account can be later recreated (docs.rs/anchor-lang/latest/anchor_lang/derive.Accounts.html), where did you get that info? Aug 15, 2023 at 15:36
  • I'm reading the source code, which shows that close reallocs the account to 0 and assigns it back to the system program: github.com/coral-xyz/anchor/blob/… -- it doesn't look like CLOSED_ACCOUNT_DISCRIMINATOR is used anymore github.com/…
    – Jon C
    Aug 15, 2023 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.