Skip to content

Commit

Permalink
appropriate precompile failure error (#3066)
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge authored Oct 4, 2024
1 parent 46a89da commit ae5919e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion programs/ed25519-tests/tests/process_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async fn test_failure_without_move_precompiles_feature() {
assert_matches!(
client.process_transaction(transaction).await,
Err(BanksClientError::TransactionError(
TransactionError::InvalidAccountIndex
TransactionError::InstructionError(0, InstructionError::Custom(3))
))
);
}
Expand Down
10 changes: 8 additions & 2 deletions runtime/src/verify_precompiles.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
solana_feature_set::FeatureSet,
solana_sdk::{
instruction::InstructionError,
precompiles::get_precompiles,
transaction::{Result, TransactionError},
},
Expand All @@ -11,14 +12,19 @@ pub fn verify_precompiles(message: &impl SVMMessage, feature_set: &FeatureSet) -
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 (index, (program_id, instruction)) in message.program_instructions_iter().enumerate() {
for precompile in precompiles {
if precompile.check_id(program_id, |id| feature_set.is_active(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)?;
.map_err(|err| {
TransactionError::InstructionError(
index as u8,
InstructionError::Custom(err as u32),
)
})?;
break;
}
}
Expand Down
13 changes: 10 additions & 3 deletions sdk/src/transaction/sanitized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use {
transaction::{Result, Transaction, TransactionError, VersionedTransaction},
},
solana_feature_set as feature_set,
solana_program::message::SanitizedVersionedMessage,
solana_program::{instruction::InstructionError, message::SanitizedVersionedMessage},
solana_sanitize::Sanitize,
std::collections::HashSet,
};
Expand Down Expand Up @@ -262,14 +262,21 @@ impl SanitizedTransaction {

/// Verify the precompiled programs in this transaction
pub fn verify_precompiles(&self, feature_set: &feature_set::FeatureSet) -> Result<()> {
for (program_id, instruction) in self.message.program_instructions_iter() {
for (index, (program_id, instruction)) in
self.message.program_instructions_iter().enumerate()
{
verify_if_precompile(
program_id,
instruction,
self.message().instructions(),
feature_set,
)
.map_err(|_| TransactionError::InvalidAccountIndex)?;
.map_err(|err| {
TransactionError::InstructionError(
index as u8,
InstructionError::Custom(err as u32),
)
})?;
}
Ok(())
}
Expand Down

0 comments on commit ae5919e

Please sign in to comment.