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

Large Stack Variables Error in Anchor 0.29.0 #2835

Open
chenmoonmo opened this issue Mar 7, 2024 · 17 comments
Open

Large Stack Variables Error in Anchor 0.29.0 #2835

chenmoonmo opened this issue Mar 7, 2024 · 17 comments
Labels

Comments

@chenmoonmo
Copy link

I encountered an error when I tried to compile my Solana program (https://github.com/chenmoonmo/anchor-dex):
Error: Function ZN157$LT$anchor_dex..instructions..init_pool..InitializePool$u20$as$u20$anchor_lang..Accounts$LT$anchor_dex..instructions..init_pool..InitializePoolBumps$GT$$GT$12try_accounts17hc6503ec5b47d6f18E Stack offset of 5672 exceeded max offset of 4096 by 1576 bytes, please minimize large stack variables

how can i fix it?

rustc 1.76.0
anchor-cli 0.29.0
solana-cli 1.18.3
solana-program 1.18.3

@chenmoonmo
Copy link
Author

After I do this, the error still appears, but when I import the code into solana playground, the compiled program can be called normally.

@acheroncrypto
Copy link
Collaborator

Does it only happen in solana-cli 1.18? Solana Playground has the same Anchor version but it's not on solana-cli 1.18.

Also, this error is more of a warning and usually doesn't cause runtime errors. Does it work if you test it locally?

@chenmoonmo
Copy link
Author

In local testing the instruction is called correctly, but when I build and deploy to devnet the instruction is called with an error

@zfedoran
Copy link

Also seeing something similar but in a different place.

Error: Function _ZN112_$LT$solana_program..instruction..InstructionError$u20$as$u20$solana_frozen_abi..abi_example..AbiEnumVisitor$GT$13visit_for_abi17h31964a789f899580E Stack offset of 4504 exceeded max offset of 4096 by 408 bytes, please minimize large stack variables

I suspect there is something up with the latest solana program or cli. I'm on 1.18.4, going to try older versions...

@Bhargavamacha
Copy link
Contributor

Hey @acheroncrypto we upgraded a different program to v29 and got a Stack offset exceeded max offset by a huge amount. Could the bumps change cause an increased stack usage by any chance?

@acheroncrypto
Copy link
Collaborator

Yes, the bumps change increased the stack usage slightly but it shouldn't be a huge amount. Did you also upgrade to 1.18 CLI? That also has some memory issues.

Some people have reported an issue regards to it but not a lot. Does #2766 fix your issue?

@Bhargavamacha
Copy link
Contributor

I did yeah, I haven't checked, will do and get back. Could it be possible the new struct is over allocating if you cross a threshold of accounts?

@acheroncrypto
Copy link
Collaborator

acheroncrypto commented Mar 14, 2024

I think it may be getting copied multiple times since the fields are u8, which is Copy, and combined with a lot of accounts it could cause excessive stack usage.

@Bhargavamacha
Copy link
Contributor

okay I will investigate a bit further and get back

@acheroncrypto
Copy link
Collaborator

Related: anza-xyz/agave#252

@acheroncrypto
Copy link
Collaborator

Solana 1.18.8 includes fixes to memory related issues (anza-xyz/agave#362).

Try to see if upgrading fixes this problem.

@chenmoonmo
Copy link
Author

stack offset problems associated with bumps still exist

@ThallesP
Copy link

ThallesP commented Apr 2, 2024

same here, i was getting some errors with stack size in 0.28.0 and thought of giving 0.29.0 a try again because someone told me that 0.29.0 reduces heap stack a little.

in 0.28.0 my stack would only exceed by 40 bytes or so
image

in 0.29.0 it exceeds by a whopping 1368 bytes (even if I try https://github.com/febo/anchor boxed bumps)
image

And before we blame it in the handler, my entire handler is commented out, it just returns Ok(()).
All of my accounts are boxed and I'm on solana-cli 1.18.8.
image

cc @chenmoonmo @acheroncrypto

@Bhargavamacha
Copy link
Contributor

@acheroncrypto I dont think the issue is fixed in 1.18.8. Can you think of anything that changed in 1.18 that could be causing this

@belakm
Copy link

belakm commented May 13, 2024

Same issue here, Boxing helps, but not enough

@etodanik
Copy link

We still get issues with 1.18.15, so the fixes certainly didn't help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants