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

Instruction parameters are overwritten with random bytes, when instruction size is close to the limit and constraints are being used #3196

Closed
serejkaaa512 opened this issue Aug 24, 2024 · 3 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists lang

Comments

@serejkaaa512
Copy link

If instruction has some #[account] constraints with a lot of accounts being used and there is byte arrays or pubkeys in instruction parameters, then some random part inside them is overwritten with random bytes.

I've made an example.

If you run anchor test, you can see, for example, the following:

  • In test address in parameters is Dcc6XavF27YRghRAbRz6nXdkPPCxFQn6QGARe3zNtDEL
  • In program log address is 11111111MTqikiemb67RkFxGXUHYRnutwFgf1dF9R

If i remove #[account] constraint from one of the accounts inside the instruction, params are becoming equal.
If i use less accounts, params are becoming equal also.

Versions:
anchor-lang = "0.30.1"
solana-program = "1.18.22"

@serejkaaa512 serejkaaa512 changed the title Instruction parameters are overwritten with random bytes, when instruction size is close to the limit and constraints being used Instruction parameters are overwritten with random bytes, when instruction size is close to the limit and constraints are being used Aug 24, 2024
@acheroncrypto acheroncrypto added bug Something isn't working duplicate This issue or pull request already exists lang labels Aug 25, 2024
@acheroncrypto
Copy link
Collaborator

Thanks for the report. This is a known issue and is being worked on. You're essentially going over the stack limit, but the compiler has a bug (as mentioned in #3060), and it doesn't always tell you that you've gone over the stack, resulting in undefined behavior (same as #3113 (comment)).

The compiler not telling you've gone over the stack should be fixed with solana v2, and we'll also have optimizations for our stack usage to fix this problem in the next version (see #3194).

@cryptopapi997
Copy link
Contributor

cryptopapi997 commented Sep 2, 2024

Thanks for the answer here, I ran into the same problem. If i understand your answer correctly the compiler detecting this problem will not be fixed in anchor versions supporting solana versions lower than v2 right (although tools like LazyAccount will be added to mitigate this better)?

If so, I'd suggest keeping this issue open and only marking it as complete once anchor supports solana v2 to make it clearer that this is a known issue which currently isn't solved yet.

@acheroncrypto
Copy link
Collaborator

I'd suggest keeping this issue open and only marking it as complete once anchor supports solana v2 to make it clearer that this is a known issue which currently isn't solved yet.

This was closed because we have a bunch similar issues that are basically duplicate of #2955 (don't mind the completed flag).

We're also upgrading to Solana v2 (#3219), Solana v2 combined with #2939 mostly solves this issue, which will be included in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists lang
Projects
None yet
Development

No branches or pull requests

3 participants