simplify based on feedback

This commit is contained in:
Hardhat Chad
2024-07-29 00:18:48 +00:00
parent c26fde97cc
commit 47a242f87a
4 changed files with 29 additions and 64 deletions

View File

@@ -150,3 +150,11 @@ pub const TREASURY_TOKENS_ADDRESS: Pubkey = Pubkey::new_from_array(
)
.0,
);
/// The address of the Solana compute budget program.
pub const COMPUTE_BUDGET_PROGRAM_ID: Pubkey =
pubkey!("ComputeBudget111111111111111111111111111111");
/// The address of the CU-optimized Solana noop program.
// pub const NOOP_PROGRAM_ID: Pubkey = pubkey!("noop8ytexvkpCuqbf6FB89BSuNemHtPRqaNC31GWivW");
pub const NOOP_PROGRAM_ID: Pubkey = pubkey!("noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV");

View File

@@ -17,10 +17,6 @@ use crate::{
#[derive(Clone, Copy, Debug, Eq, PartialEq, ShankInstruction, TryFromPrimitive)]
#[rustfmt::skip]
pub enum OreInstruction {
#[account(0, name = "ore_program", desc = "Ore program")]
#[account(1, name = "proof", desc = "Ore proof account")]
Auth = 0,
#[account(0, name = "ore_program", desc = "Ore program")]
#[account(1, name = "signer", desc = "Signer", signer)]
#[account(2, name = "beneficiary", desc = "Beneficiary token account", writable)]
@@ -28,13 +24,13 @@ pub enum OreInstruction {
#[account(4, name = "treasury", desc = "Ore treasury account", writable)]
#[account(5, name = "treasury_tokens", desc = "Ore treasury token account", writable)]
#[account(6, name = "token_program", desc = "SPL token program")]
Claim = 1,
Claim = 0,
#[account(0, name = "ore_program", desc = "Ore program")]
#[account(1, name = "signer", desc = "Signer", signer)]
#[account(2, name = "proof", desc = "Ore proof account", writable)]
#[account(3, name = "system_program", desc = "Solana system program")]
Close = 2,
Close = 1,
#[account(0, name = "ore_program", desc = "Ore program")]
#[account(1, name = "signer", desc = "Signer", signer)]
@@ -43,7 +39,7 @@ pub enum OreInstruction {
#[account(4, name = "noise", desc = "Ore noise account")]
#[account(5, name = "proof", desc = "Ore proof account", writable)]
#[account(6, name = "slot_hashes", desc = "Solana slot hashes sysvar")]
Mine = 3,
Mine = 2,
#[account(0, name = "ore_program", desc = "Ore program")]
#[account(1, name = "signer", desc = "Signer", signer)]
@@ -52,7 +48,7 @@ pub enum OreInstruction {
#[account(4, name = "proof", desc = "Ore proof account", writable)]
#[account(5, name = "system_program", desc = "Solana system program")]
#[account(6, name = "slot_hashes", desc = "Solana slot hashes sysvar")]
Open = 4,
Open = 3,
#[account(0, name = "ore_program", desc = "Ore program")]
#[account(1, name = "signer", desc = "Signer", signer)]
@@ -69,7 +65,7 @@ pub enum OreInstruction {
#[account(12, name = "treasury", desc = "Ore treasury account", writable)]
#[account(13, name = "treasury_tokens", desc = "Ore treasury token account", writable)]
#[account(14, name = "token_program", desc = "SPL token program")]
Reset = 5,
Reset = 4,
#[account(0, name = "ore_program", desc = "Ore program")]
#[account(1, name = "signer", desc = "Signer", signer)]
@@ -77,12 +73,12 @@ pub enum OreInstruction {
#[account(3, name = "sender", desc = "Signer token account", writable)]
#[account(4, name = "treasury_tokens", desc = "Ore treasury token account", writable)]
#[account(5, name = "token_program", desc = "SPL token program")]
Stake = 6,
Stake = 5,
#[account(0, name = "ore_program", desc = "Ore program")]
#[account(1, name = "signer", desc = "Signer", signer)]
#[account(2, name = "proof", desc = "Ore proof account", writable)]
Update = 7,
Update = 6,
#[account(0, name = "ore_program", desc = "Ore program")]
#[account(1, name = "signer", desc = "Signer", signer)]
@@ -92,7 +88,7 @@ pub enum OreInstruction {
#[account(5, name = "mint", desc = "Ore token mint account", writable)]
#[account(6, name = "mint_v1", desc = "Ore v1 token mint account", writable)]
#[account(7, name = "token_program", desc = "SPL token program")]
Upgrade = 8,
Upgrade = 7,
#[account(0, name = "ore_program", desc = "Ore program")]
#[account(1, name = "signer", desc = "Admin signer", signer)]
@@ -231,9 +227,9 @@ pub fn close(signer: Pubkey) -> Instruction {
/// Builds an auth instruction.
pub fn auth(proof: Pubkey) -> Instruction {
Instruction {
program_id: crate::id(),
accounts: vec![AccountMeta::new_readonly(proof, false)],
data: OreInstruction::Auth.to_vec(),
program_id: NOOP_PROGRAM_ID,
accounts: vec![],
data: proof.to_bytes().to_vec(),
}
}

View File

@@ -1,27 +1,11 @@
use ore_api::instruction::OreInstruction;
use ore_api::consts::COMPUTE_BUDGET_PROGRAM_ID;
use solana_program::{
account_info::AccountInfo,
entrypoint::ProgramResult,
program_error::ProgramError,
pubkey,
pubkey::Pubkey,
sanitize::SanitizeError,
serialize_utils::{read_pubkey, read_u16, read_u8},
serialize_utils::{read_pubkey, read_u16},
};
/// Auth is used to authenticate a proof account address via transaction introspection.
///
/// Safety requirements:
/// - No safety requirements are required in this instruction to keep CUs low.
/// - Other instructions are expected to validate the provided account is a valid proof.
/// - Only one account should be provided.
pub fn process_auth<'a, 'info>(accounts: &'a [AccountInfo<'info>], _data: &[u8]) -> ProgramResult {
let [_proof_info] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
};
Ok(())
}
/// Get the authenticated pubkey.
///
/// The intent here is to disincentivize sybil. If a user can fit multiple hashes into a single
@@ -45,45 +29,23 @@ pub fn authenticate(data: &[u8]) -> Result<Option<Pubkey>, SanitizeError> {
let num_instructions = read_u16(&mut curr, data)?;
let pc = curr;
// Iterate through the top-level instructions
// Iterate through the transaction instructions
for i in 0..num_instructions as usize {
// Get byte counter
curr = pc + i * 2;
curr = read_u16(&mut curr, data)? as usize;
// Read num accounts on this ix
let num_accounts = read_u16(&mut curr, data)? as usize;
// Hold a pointer to the first account in the accounts array
let mut ac = curr + 1;
// Read the instruction program id
let num_accounts = read_u16(&mut curr, data)? as usize;
curr += num_accounts * 33;
let program_id = read_pubkey(&mut curr, data)?;
// We only need to introspect on the first ore ix
if program_id.eq(&ore_api::ID) {
// Introspect on the first non compute budget instruction
if program_id.ne(&COMPUTE_BUDGET_PROGRAM_ID) {
// Read address from ix data
curr += 2;
// Parse the instruction data
if let Ok(ix) = OreInstruction::try_from(read_u8(&mut curr, data)?) {
// Return immediately if the ix is not an auth
if ix.ne(&OreInstruction::Auth) {
return Ok(None);
}
// Valid the num accounts is expected
if num_accounts.ne(&1) {
return Ok(None);
}
// Return the address of the authenticated account
let address = read_pubkey(&mut ac, data)?;
return Ok(Some(address));
}
// Return if instruction data can't be parsed
return Ok(None);
let address = read_pubkey(&mut curr, data)?;
return Ok(Some(address));
}
}

View File

@@ -45,7 +45,6 @@ pub fn process_instruction(
.ok_or(ProgramError::InvalidInstructionData)?;
match OreInstruction::try_from(*tag).or(Err(ProgramError::InvalidInstructionData))? {
OreInstruction::Auth => process_auth(accounts, data)?,
OreInstruction::Claim => process_claim(accounts, data)?,
OreInstruction::Close => process_close(accounts, data)?,
OreInstruction::Mine => process_mine(accounts, data)?,