Revert "Remove feature switch for secp256k1 program (#18467)"

This reverts commit fd574dcb3b.
This commit is contained in:
Trent Nelson
2021-07-13 14:20:02 -06:00
committed by mergify[bot]
parent c19fce1b19
commit 568660b402
10 changed files with 103 additions and 41 deletions

View File

@@ -359,6 +359,7 @@ pub trait EntrySlice {
fn verify_and_hash_transactions(
&self,
skip_verification: bool,
secp256k1_program_enabled: bool,
verify_tx_signatures_len: bool,
) -> Option<Vec<EntryType<'_>>>;
}
@@ -514,6 +515,7 @@ impl EntrySlice for [Entry] {
fn verify_and_hash_transactions<'a>(
&'a self,
skip_verification: bool,
secp256k1_program_enabled: bool,
verify_tx_signatures_len: bool,
) -> Option<Vec<EntryType<'a>>> {
let verify_and_hash = |tx: &'a Transaction| -> Option<HashedTransaction<'a>> {
@@ -522,7 +524,10 @@ impl EntrySlice for [Entry] {
if size > PACKET_DATA_SIZE as u64 {
return None;
}
tx.verify_precompiles().ok()?;
if secp256k1_program_enabled {
// Verify tx precompiles if secp256k1 program is enabled.
tx.verify_precompiles().ok()?;
}
if verify_tx_signatures_len && !tx.verify_signatures_len() {
return None;
}
@@ -922,10 +927,10 @@ mod tests {
let tx = make_transaction(TestCase::RemoveSignature);
let entries = vec![next_entry(&recent_blockhash, 1, vec![tx])];
assert!(entries[..]
.verify_and_hash_transactions(false, false)
.verify_and_hash_transactions(false, false, false)
.is_some());
assert!(entries[..]
.verify_and_hash_transactions(false, true)
.verify_and_hash_transactions(false, false, true)
.is_none());
}
// Too many signatures.
@@ -933,10 +938,10 @@ mod tests {
let tx = make_transaction(TestCase::AddSignature);
let entries = vec![next_entry(&recent_blockhash, 1, vec![tx])];
assert!(entries[..]
.verify_and_hash_transactions(false, false)
.verify_and_hash_transactions(false, false, false)
.is_some());
assert!(entries[..]
.verify_and_hash_transactions(false, true)
.verify_and_hash_transactions(false, false, true)
.is_none());
}
}
@@ -962,7 +967,7 @@ mod tests {
let entries = vec![next_entry(&recent_blockhash, 1, vec![tx.clone()])];
assert!(bincode::serialized_size(&tx).unwrap() <= PACKET_DATA_SIZE as u64);
assert!(entries[..]
.verify_and_hash_transactions(false, false)
.verify_and_hash_transactions(false, false, false)
.is_some());
}
// Big transaction.
@@ -971,7 +976,7 @@ mod tests {
let entries = vec![next_entry(&recent_blockhash, 1, vec![tx.clone()])];
assert!(bincode::serialized_size(&tx).unwrap() > PACKET_DATA_SIZE as u64);
assert!(entries[..]
.verify_and_hash_transactions(false, false)
.verify_and_hash_transactions(false, false, false)
.is_none());
}
// Assert that verify fails as soon as serialized
@@ -982,7 +987,7 @@ mod tests {
assert_eq!(
bincode::serialized_size(&tx).unwrap() <= PACKET_DATA_SIZE as u64,
entries[..]
.verify_and_hash_transactions(false, false)
.verify_and_hash_transactions(false, false, false)
.is_some(),
);
}