forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |