Skip to content

Commit

Permalink
reverify_transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Oct 7, 2024
1 parent 8a78fdd commit 9f17ee5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
12 changes: 2 additions & 10 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,16 +440,8 @@ impl Consumer {
// or account lookup tables may have been closed.
let pre_results = txs.iter().zip(max_slot_ages).map(|(tx, max_slot_age)| {
if *max_slot_age < bank.slot() {
// Pre-compiles are verified here.
// Attempt re-sanitization after epoch-cross.
// Re-sanitized transaction should be equal to the original transaction,
// but whether it will pass sanitization needs to be checked.
let resanitized_tx =
bank.fully_verify_transaction(tx.to_versioned_transaction())?;
if resanitized_tx != *tx {
// Sanitization before/after epoch give different transaction data - do not execute.
return Err(TransactionError::ResanitizationNeeded);
}
// Re-verify all state that depends on features or state.
bank.reverify_transaction(tx)?;
} else {
// Verify pre-compiles.
if !move_precompile_verification_to_svm {
Expand Down
29 changes: 29 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5756,6 +5756,35 @@ impl Bank {
self.verify_transaction(tx, TransactionVerificationMode::FullVerification)
}

/// Re-performs **feature** or state dependent verification on the transaction.
pub fn reverify_transaction(&self, tx: &impl SVMMessage) -> Result<()> {
// Loaded addresses depend on address table account state.
// We need only verify that loading works correctly.
// Since the address table is append only there is no chance addresses
// are different than the first time this was resolved.
let _loaded_addresses = self.load_addresses_from_ref(tx.message_address_table_lookups())?;

// Precompiles may be verified at this time if feature is not activated.
// Precompile verification can be dependent on features of the bank.
let move_precompile_verification_to_svm = self
.feature_set
.is_active(&feature_set::move_precompile_verification_to_svm::id());
if !move_precompile_verification_to_svm {
verify_precompiles(tx, &self.feature_set)?;
}

// Check keys against the reserved set - these failures simply require us
// to re-sanitize the transaction. We do not need to drop the transaction.
let reserved_keys = self.get_reserved_account_keys();
for (index, key) in tx.account_keys().iter().enumerate() {
if tx.is_writable(index) && reserved_keys.contains(key) {
return Err(TransactionError::ResanitizationNeeded);
}
}

Ok(())
}

/// only called from ledger-tool or tests
fn calculate_capitalization(&self, debug_verify: bool) -> u64 {
let is_startup = true;
Expand Down

0 comments on commit 9f17ee5

Please sign in to comment.