Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVM: add check for check results length mismatch #3259

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
environment: &TransactionProcessingEnvironment,
config: &TransactionProcessingConfig,
) -> LoadAndExecuteSanitizedTransactionsOutput {
// If `check_results` does not have the same length as `sanitized_txs`,
// transactions could be truncated as a result of `.iter().zip()` in
// many of the below methods.
// See <https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.zip>.
debug_assert_eq!(
sanitized_txs.len(),
check_results.len(),
"Length of check_results does not match length of sanitized_txs"
);

// Initialize metrics.
let mut error_metrics = TransactionErrorMetrics::default();
let mut execute_timings = ExecuteTimings::default();
Expand Down Expand Up @@ -1038,6 +1048,7 @@ mod tests {
transaction::{SanitizedTransaction, Transaction, TransactionError},
transaction_context::TransactionContext,
},
test_case::test_case,
};

fn new_unchecked_sanitized_message(message: Message) -> SanitizedMessage {
Expand Down Expand Up @@ -1112,6 +1123,51 @@ mod tests {
}
}

#[test_case(1; "Check results too small")]
#[test_case(3; "Check results too large")]
#[should_panic(expected = "Length of check_results does not match length of sanitized_txs")]
fn test_check_results_txs_length_mismatch(check_results_len: usize) {
let sanitized_message = new_unchecked_sanitized_message(Message {
account_keys: vec![Pubkey::new_from_array([0; 32])],
header: MessageHeader::default(),
instructions: vec![CompiledInstruction {
program_id_index: 0,
accounts: vec![],
data: vec![],
}],
recent_blockhash: Hash::default(),
});

// Transactions, length 2.
let sanitized_txs = vec![
SanitizedTransaction::new_for_tests(
sanitized_message,
vec![Signature::new_unique()],
false,
);
2
];

let check_results = vec![
TransactionCheckResult::Ok(CheckedTransactionDetails {
nonce: None,
lamports_per_signature: 0
});
check_results_len
];

let batch_processor = TransactionBatchProcessor::<TestForkGraph>::default();
let callback = MockBankCallback::default();

batch_processor.load_and_execute_sanitized_transactions(
&callback,
&sanitized_txs,
check_results,
&TransactionProcessingEnvironment::default(),
&TransactionProcessingConfig::default(),
);
}

#[test]
fn test_inner_instructions_list_from_instruction_trace() {
let instruction_trace = [1, 2, 1, 1, 2, 3, 2];
Expand Down
Loading