1

I am trying to produce a stack frame error by loading a big struct in an account.

pub struct HitStackSize {
    board: [Option<BigStruct>; 10],
}

#[derive(AnchorSerialize, AnchorDeserialize, Copy, Clone, PartialEq, Eq)]
// Size of this struct is 32 bytes * 4 = 128 bytes
pub struct BigStruct {
    pub public_key_1: Pubkey,
    pub public_key_2: Pubkey,
    pub public_key_3: Pubkey,
    pub public_key_4: Pubkey,
    pub small_scrut: SmallScrut,
    pub padding: [u8; 199],
}

#[derive(AnchorSerialize, AnchorDeserialize, Copy, Clone, PartialEq, Eq)]
pub struct SmallScrut {
    pub public_key_1: u64,
    pub public_key_2: u64,
    pub public_key_3: u64,
    pub public_key_4: u64,
}

But instead of a stack frame error like in anchor 0.27.0 I am now getting:

     Simulation failed. 
Message: Transaction simulation failed: Error processing Instruction 0: Program failed to complete. 
Logs: 
[
  "Program E7GebMdwaGevhj7G9EZFhkrMz6gQKyTnTNbx8gWvf8KF invoke [1]",
  "Program log: Instruction: InitializeHitStackSize",
  "Program 11111111111111111111111111111111 invoke [2]",
  "Program 11111111111111111111111111111111 success",
  "Program E7GebMdwaGevhj7G9EZFhkrMz6gQKyTnTNbx8gWvf8KF consumed 12887 of 200000 compute units",
  "Program E7GebMdwaGevhj7G9EZFhkrMz6gQKyTnTNbx8gWvf8KF failed: Overlapping copy"
]. 
Catch the `SendTransactionError` and call `getLogs()` on it for full details.

What does this error mean? Is it the same as stack frame violation?

Im using anchor 0.30.0 with zero copy and solana 1.18.16.

1 Answer 1

1

It looks like that logic for this changed recently and anchor 0.30.0 or 1.18 added a check for this. Not quite sure, but instead of a stack frame error we will now see the error Overlapping copy.

The error is triggered here:

https://github.com/anza-xyz/agave/blob/master/programs/bpf_loader/src/syscalls/mem_ops.rs#L30

It is a syscall error that is triggered when writing into an overlapping area. So when there is still 4 bytes free on the stack and I am trying to load another 8 this error would be thrown.

https://docs.rs/crate/solana-bpf-loader-program/1.8.9/source/src/syscalls.rs

This is the check: https://github.com/anza-xyz/agave/blob/5194daf89b07df1a624c2b89a59c4a05b121ae49/sdk/program/src/program_stubs.rs#L260-L275

Most likely this change is related to https://github.com/solana-labs/solana/pull/28053

"When enabled, account data is directly mapped into vm memory at vm setup time. This removes the need to have large copies during transaction execution, going in and out of the vm at each instruction/CPI boundary."

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.