anchor: lang: Disallow duplicate accounts by default
Anchor programs should error when duplicate accounts are given to a program. We can have some type of attribute to override this check and allow the duplicate, e.g., #[account(dup)]
or something else.
Suggested by @jstarry.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 25 (24 by maintainers)
One default which I haven’t seen proposed: I think in a large amount of cases you can do automated checks on a program to see if it is vulnerable to duplicate account cases. So perhaps
anchor build
could include this audit. You can automatically check if I have multiple mutable refs of the same type and nono_dup
flag on them, no constraints on their addresses that would preclude them from being duplicates, etc.I’ll leave the decision to @armaniferrante but my perspective is that simple and safe is a great starting point. Adding more complex knobs can come later when devs need them.
Remaining accounts doesn’t provide any validation guarantees and the api is the same as regular solana. So I think it’s ok to have no checks there, since if you’re using it, you know you’re already doing unsafe things (relatively speaking).