From f2bdbca6bdf10ce58b5463c488449f6d35f6f670 Mon Sep 17 00:00:00 2001 From: Joe C Date: Mon, 9 Dec 2024 13:15:56 +0900 Subject: [PATCH] slot hashes rectification with modulus (#178) --- src/lib.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ffa3d27..1ee04f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,7 +51,11 @@ use std::sync::Arc; use thiserror::Error; #[cfg(any(feature = "core-bpf", feature = "core-bpf-conformance"))] -use solana_sdk::{account::WritableAccount, slot_hashes::SlotHashes, sysvar::Sysvar}; +use solana_sdk::{ + account::WritableAccount, + slot_hashes::{SlotHash, SlotHashes}, + sysvar::Sysvar, +}; // macro to rewrite &[IDENTIFIER, ...] to &[feature_u64(IDENTIFIER::id()), ...] #[macro_export] @@ -620,11 +624,16 @@ fn execute_instr(mut input: InstrContext) -> Option { if &input.instruction.program_id == &solana_sdk::address_lookup_table::program::id() && pubkey == &SlotHashes::id() { - if account.1.data.len() < SlotHashes::size_of() { - // Extend the data to the right size. - let mut data = vec![0; SlotHashes::size_of()]; - data[..account.1.data.len()].copy_from_slice(&account.1.data); - return callbackback(&data); + let data_len = account.1.data.len(); + if (data_len > 8 && (data_len - 8) % std::mem::size_of::() == 0) + || data_len == 8 + { + if data_len < SlotHashes::size_of() { + // Extend the data to the right size. + let mut data = vec![0; SlotHashes::size_of()]; + data[..data_len].copy_from_slice(&account.1.data); + return callbackback(&data); + } } } callbackback(&account.1.data);