Skip to main content

I understand that the init keyword in anchor creates and set the default values of an account ,while the ini_if_needed does the same thing and also doesn’t throw an error if the account has already been created/initialized. A use case iI can think of about the init_if_needed is a case of a staking smart contract in which when a user stakestakes,the amount staked is mapped to his address through PDA,In In that case,if a user already staked and wanna stake again,there there is no need in creating/mapping a new account with a PDA.The The already existing one can be used. My question is, 1.What are the security vulnerabilities of this use case 2.How can it be solved.

  1. What are the security vulnerabilities of this use case

  2. How can it be solved.

I understand that the init keyword in anchor creates and set the default values of an account ,while the ini_if_needed does the same thing and also doesn’t throw an error if the account has already been created/initialized. A use case i can think of about the init_if_needed is a case of a staking smart contract in which when a user stake,the amount staked is mapped to his address through PDA,In that case,if a user already staked and wanna stake again,there is no need in creating/mapping a new account with a PDA.The already existing one can be used. My question is, 1.What are the security vulnerabilities of this use case 2.How can it be solved.

I understand that the init keyword in anchor creates and set the default values of an account ,while the ini_if_needed does the same thing and also doesn’t throw an error if the account has already been created/initialized. A use case I can think of about the init_if_needed is a case of a staking smart contract in which when a user stakes,the amount staked is mapped to his address through PDA, In that case,if a user already staked and wanna stake again, there is no need in creating/mapping a new account with a PDA. The already existing one can be used. My question is,

  1. What are the security vulnerabilities of this use case

  2. How can it be solved.

Bumped by Community user
Source Link
Icus1
  • 451
  • 2
  • 10

Vulnerabilities of the init_if_needed in anchor

I understand that the init keyword in anchor creates and set the default values of an account ,while the ini_if_needed does the same thing and also doesn’t throw an error if the account has already been created/initialized. A use case i can think of about the init_if_needed is a case of a staking smart contract in which when a user stake,the amount staked is mapped to his address through PDA,In that case,if a user already staked and wanna stake again,there is no need in creating/mapping a new account with a PDA.The already existing one can be used. My question is, 1.What are the security vulnerabilities of this use case 2.How can it be solved.