Skip to content

Commit

Permalink
generic verify_precompiles
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Oct 2, 2024
1 parent 9b5525d commit 3a5f523
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod stakes;
pub mod static_ids;
pub mod status_cache;
pub mod transaction_batch;
mod verify_precompiles;
pub mod vote_sender_types;

#[macro_use]
Expand Down
28 changes: 28 additions & 0 deletions runtime/src/verify_precompiles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use {
solana_feature_set::FeatureSet,
solana_sdk::{
precompiles::get_precompiles,
transaction::{Result, TransactionError},
},
solana_svm_transaction::svm_message::SVMMessage,
};

pub fn verify_precompiles(message: &impl SVMMessage, feature_set: &FeatureSet) -> Result<()> {
let mut all_instruction_data = None; // lazily collect this on first pre-compile

let precompiles = get_precompiles();
for (program_id, instruction) in message.program_instructions_iter() {
for precompile in precompiles {
if program_id == &precompile.program_id {
let all_instruction_data: &Vec<&[u8]> = all_instruction_data
.get_or_insert_with(|| message.instructions_iter().map(|ix| ix.data).collect());
precompile
.verify(instruction.data, all_instruction_data, feature_set)
.map_err(|_| TransactionError::InvalidAccountIndex)?;
break;
}
}
}

Ok(())
}

0 comments on commit 3a5f523

Please sign in to comment.