How can I fix this error? This is a basic anchor smart contract that initializes an account. There's only one value, an integer, stored. I tried boxing the account (to put the storage on the heap, according to other questions), but that did not fix.

Warning: cargo-build-bpf is deprecated. Please, use cargo-build-sbf
cargo-build-bpf child: /home/user/.local/share/solana/install/active_release/bin/cargo-build-sbf --arch bpf
Error: Function _ZN14solana_program4vote5state9VoteState11deserialize17h4e0d3b92a7040b50E Stack offset of 6344 exceeded max offset of 4096 by 2248 bytes, please minimize large stack variables
Error: Function _ZN229_$LT$solana_program..vote..state..vote_state_0_23_5.._..$LT$impl$u20$serde..de..Deserialize$u20$for$u20$solana_program..vote..state..vote_state_0_23_5..VoteState0_23_5$GT$..deserialize..__Visitor$u20$as$u20$serde..de..Visitor$GT$9visit_seq17h1fa296554d54dcceE Stack offset of 5752 exceeded max offset of 4096 by 1656 bytes, please minimize large stack variables
    Finished release [optimized] target(s) in 0.24s

Smart contract:

use anchor_lang::prelude::*;


pub mod testw {
    use super::*;

    pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
        let account 
            = &mut ctx.accounts.counter_account;
        account.counter_number = 0;
        return Ok(());

pub struct Initialize<'info> {
    #[account(init, payer=signer, space=64)]
    counter_account: Box<Account<'info, CounterAccount>>,
    signer: Signer<'info>,
    system_program: Program<'info, System>,

pub struct CounterAccount {
    counter_number: i64,
  • Hi @djd , how did you fix this problem?
    – marethyu
    Feb 7, 2023 at 3:40
  • @marethyu I haven't found a solution, but running anchor test runs a basic initialize account test that is successful. The stack offset error is still there.
    – djd
    Feb 7, 2023 at 23:37

4 Answers 4


If we look at the error closely it says Error: Function _ZN14solana_program4vote5state9VoteState11deserialize17h4e0d3b92a7040b50E Stack offset of 6344 exceeded max offset of 4096 by 2248 bytes, please minimize large stack variables, meaning that solana_program::vote::state::VoteState::deserialize uses too much stack space, and will fail if used on-chain.

As long as you don't deserialize a VoteState in your program, you will never have an issue. On the flip side, I'm curious about why it gets pulled into your program at all, so probably something needs to be fixed on the Anchor side.


I got the same problem after fully re-building my dependencies (i.e. after deleting the lock file and target directory).

I shared a full description of the error as an issue in the main solana repo: https://github.com/solana-labs/solana/issues/30188


I am also getting this error after upgrading to latest anchor / latest solana. There are actually two errors, both stack offset related.

Error: Function ZN94$LT$$RF$mut$u20$bincode..de..Deserializer Error: Function _ZN14solana_program4vote5state9VoteState11deseria

it feels like it's definitely related to these upgrades, and doesn't stop me from working, but I am scared it will pop up later.


You likely have a very large instruction that has exceeded the max amount of Accounts on the stack. But no problem, just Box the accounts, and they'll go on the heap, which makes no practical difference.

Turn pub some_mint: Account<'info, Mint>

into pub some_mint: Box<Account<'info, Mint>>

Turn some_acc: Account<'info, TokenAccount>,

into some_acc: Box<Account<'info, TokenAccount>>,

and so forth.

Note that AccountLoader can't be boxed, so if you have boxed all the accounts you can and have still exceeded the max size, it's time to start cutting down your Account sizes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.