-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lang: error if bump target is given on init #1380
Conversation
@armaniferrante what's the logic around this? Why's it better for the program to generate the bump itself than to let the client pass in a bump? Is it to make the client's job easier? I think it may be nice to pass in a |
Although it is definitely possible to do this securely, a lot of people in practice don't. So the logic here is foot gun elimination, favoring security over compute unit performance. There's no good reason to use a bump other than the canonical bump, and so the framework encourages that. Moreover, there's no reason to even be aware that the bump exists in the first place, and in future work, we can even hide it completely. However, in the rare, but extreme case that one needs to save compute from find_program_address, one can still initialize the account outside of the macro and pass the bump in through the instruction data. But even when doing this, I'd first consider whether it's possible to init the account in a separate instruction altogether. |
@armaniferrante thanks, that makes a lot of sense and I agree w/ your conclusions 👍. |
Hi, @armaniferrante! Can you explain please how to generate PDA now in program itself and not pass it (pda, bump) via arguments? I suppose it can be done like this:
but vault_authority now is PubKey and it is not AccountInfo. How to transform it to AccountInfo if I rightly took the idea od PDA's creation. Thx! |
Whenever you "find" the bump in the accounts context via |
But it returns Option<u8> and it is bump but not AccountInfo. Currently I am trying to create escrow program, but all examples are now outdated and not working. Maybe you have some that shows how to transfer tokens from one account to pda account that will actually store some additional data? Thanks for your fast reply. |
This doesn't seem very type safe. Can the type checker know whether you passed in the correct account name? Will a refactor to an Accounts struct field also update the |
Hi @olegggatttor, I am also trying to run the anchor-escrow program, what changes did you make to the program to fix the bump issue? Thanks! |
Hey! We have decided to use previous version of anchor: 0.18.2:( We didn't figure out how to use in it in newer versions. If you find out please let me know. |
This example gives some clue - https://book.anchor-lang.com/anchor_in_depth/PDAs.html#how-to-build-pda-hashmaps-in-anchor |
No description provided.