1

The zero copy version of the following struct adds 4 bytes of padding between arg_1 and arg_2. This makes the idl not able to decode the struct correctly as arg_2 is being decoded based on the 4 bytes of padding and its own first 4 bytes.

#[account(zero_copy)]
#[derive(Default)]
pub struct MyStruct  {
    pub version: u8,
    pub bump: u8,
    pub active: bool,
    pub authority: Pubkey,
    pub arg_1: u8,
    pub arg_2: u64,
} 

How do I fix this?

1

1 Answer 1

2

Anchor zero copy doesn't follow the rules of how Pod (the backing trait from bytemuck) is supposed to be implemented (violates the unsafe constraints). To fix it you need to add #[repr(packed)] to get rid of the padding (will mis-align reference but follow the clippy warnings to be fine) and not use and non-Pod types in the struct.

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.