secure logs

This commit is contained in:
Hardhat Chad
2025-07-15 12:08:09 -07:00
parent 39cbd72f00
commit d129591638
4 changed files with 24 additions and 12 deletions

View File

@@ -48,7 +48,9 @@ pub struct Deposit {
#[repr(C)] #[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)] #[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Log {} pub struct Log {
pub block_id: [u8; 8],
}
#[repr(C)] #[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)] #[derive(Clone, Copy, Debug, Pod, Zeroable)]

View File

@@ -91,12 +91,15 @@ pub fn close(
} }
} }
pub fn log(signer: Pubkey, msg: &[u8]) -> Instruction { pub fn log(signer: Pubkey, block_id: u64, msg: &[u8]) -> Instruction {
let mut data = Log {}.to_bytes(); let mut data = Log {
block_id: block_id.to_le_bytes(),
}
.to_bytes();
data.extend_from_slice(msg); data.extend_from_slice(msg);
Instruction { Instruction {
program_id: crate::ID, program_id: crate::ID,
accounts: vec![AccountMeta::new(signer, false)], accounts: vec![AccountMeta::new(signer, true)],
data: data, data: data,
} }
} }
@@ -107,7 +110,7 @@ pub fn program_log(
msg: &[u8], msg: &[u8],
) -> Result<(), ProgramError> { ) -> Result<(), ProgramError> {
invoke_signed( invoke_signed(
&log(*accounts[0].key, msg), &log(*accounts[0].key, block_id, msg),
accounts, accounts,
&crate::ID, &crate::ID,
&[BLOCK, &block_id.to_le_bytes()], &[BLOCK, &block_id.to_le_bytes()],

View File

@@ -12,7 +12,6 @@ use solana_sdk::{
signature::{read_keypair_file, Signer}, signature::{read_keypair_file, Signer},
transaction::Transaction, transaction::Transaction,
}; };
use spl_token::amount_to_ui_amount;
use steel::{AccountDeserialize, Clock, Discriminator}; use steel::{AccountDeserialize, Clock, Discriminator};
#[tokio::main] #[tokio::main]
@@ -247,7 +246,7 @@ async fn get_blocks(rpc: &RpcClient) -> Result<Vec<(Pubkey, Block)>, anyhow::Err
Ok(blocks) Ok(blocks)
} }
async fn simulate_transaction( async fn _simulate_transaction(
rpc: &RpcClient, rpc: &RpcClient,
payer: &solana_sdk::signer::keypair::Keypair, payer: &solana_sdk::signer::keypair::Keypair,
instructions: &[solana_sdk::instruction::Instruction], instructions: &[solana_sdk::instruction::Instruction],

View File

@@ -1,13 +1,21 @@
use ore_api::prelude::*; use ore_api::prelude::*;
use solana_program::log::sol_log;
use steel::*; use steel::*;
/// No-op, use instruction data for logging w/o truncation. /// No-op, use instruction data for logging w/o truncation.
pub fn process_log(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { pub fn process_log(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
// Load data
let block_id_bytes = data[..8].try_into().unwrap();
let block_id = u64::from_le_bytes(block_id_bytes);
sol_log(format!("Block ID: {}", block_id).as_str());
// Load accounts. // Load accounts.
// let [signer_info] = accounts else { let [signer_info] = accounts else {
// return Err(ProgramError::NotEnoughAccountKeys); return Err(ProgramError::NotEnoughAccountKeys);
// }; };
// signer_info.as_account::<Block>(&ore_api::ID)?; signer_info
.is_signer()?
.has_seeds(&[BLOCK, &block_id.to_le_bytes()], &ore_api::ID)?;
// For data integrity, only a block can log messages. // For data integrity, only a block can log messages.