Skip to content
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

Merged
merged 7 commits into from
Feb 7, 2022
Merged

Conversation

armaniferrante
Copy link
Member

No description provided.

@armaniferrante armaniferrante merged commit 598c7b0 into master Feb 7, 2022
@armaniferrante armaniferrante deleted the armani/bump branch February 7, 2022 18:26
@vpontis
Copy link
Contributor

vpontis commented Feb 22, 2022

@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 bump when initing an account since that way the program consumes less compute.

@armaniferrante
Copy link
Member Author

armaniferrante commented Feb 23, 2022

I think it may be nice to pass in a bump when initing an account since that way the program consumes less compute.

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.

@vpontis
Copy link
Contributor

vpontis commented Feb 23, 2022

@armaniferrante thanks, that makes a lot of sense and I agree w/ your conclusions 👍.

@olegggatttor
Copy link

olegggatttor commented Feb 23, 2022

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:

let (vault_authority, _vault_authority_bump) = Pubkey::find_program_address(&[// some seeds //], ctx.program_id);

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!

@armaniferrante
Copy link
Member Author

armaniferrante commented Feb 23, 2022

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:

Whenever you "find" the bump in the accounts context via #[account(seeds = [...], bump)]), the bump is accessible in your instruction handler via ctx.bumps.get("<account_name>").unwrap().

@olegggatttor
Copy link

olegggatttor commented Feb 23, 2022

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:

Whenever you "find" the bump in the accounts context via #[account(seeds = [...], bump)]), the bump is accessible in your instruction handler via ctx.bumps.get("<account_name>").unwrap().

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.

@ozyman42
Copy link

ozyman42 commented Feb 28, 2022

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 <account_name> in the bumps.get call?

@gaa2118
Copy link

gaa2118 commented Apr 1, 2022

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!

@olegggatttor
Copy link

olegggatttor commented Apr 1, 2022

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.

@avishkarabhishek786
Copy link

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.

6 participants