Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ Always verify that account offsets and lengths match expectations. Use [sbpf.xyz

```rust
if *input == 4
&& (*input.add(ACCOUNT1_DATA_LEN).cast::<u64>() == 165)
&& (*input.add(ACCOUNT2_DATA_LEN).cast::<u64>() == 82)
&& (*input.add(IX12_ACCOUNT3_DATA_LEN).cast::<u64>() == 165)
&& (input.add(ACCOUNT1_DATA_LEN).cast::<u64>().read_unaligned() == 165)
&& (input.add(ACCOUNT2_DATA_LEN).cast::<u64>().read_unaligned() == 82)
&& (input.add(IX12_ACCOUNT3_DATA_LEN).cast::<u64>().read_unaligned() == 165)
{
//...
}
Expand All @@ -145,16 +145,16 @@ fn align(input: u64) -> u64 {

// The `authority` account can have variable data length.
let account_4_data_len_aligned =
align(*input.add(IX12_ACCOUNT4_DATA_LEN).cast::<u64>()) as usize;
align(input.add(IX12_ACCOUNT4_DATA_LEN).cast::<u64>().read_unaligned()) as usize;
let offset = IX12_EXPECTED_INSTRUCTION_DATA_LEN_OFFSET + account_4_data_len_aligned;
```

Once validation passes, extract instruction data, transmute accounts, and process normally:

```rust
// Check that we have enough instruction data.
if input.add(offset).cast::<usize>().read() >= INSTRUCTION_DATA_SIZE {
let discriminator = input.add(offset + size_of::<u64>()).cast::<u8>().read();
if unsafe { input.add(offset).cast::<usize>().read_unaligned() } >= INSTRUCTION_DATA_SIZE {
let discriminator = unsafe { input.add(offset + size_of::<u64>()).cast::<u8>().read() };

// Check for instruction discriminator.
if likely(discriminator == 12) {
Expand All @@ -179,4 +179,4 @@ if input.add(offset).cast::<usize>().read() >= INSTRUCTION_DATA_SIZE {
};
}
}
```
```