hijack secp256k1 enablement feature plumbing for libsecp256k1 upgrade
This commit is contained in:
parent
568660b402
commit
3a85b77bb5
|
@ -128,10 +128,13 @@ impl BanksServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_transaction(transaction: &Transaction) -> transaction::Result<()> {
|
fn verify_transaction(
|
||||||
|
transaction: &Transaction,
|
||||||
|
libsecp256k1_0_5_upgrade_enabled: bool,
|
||||||
|
) -> transaction::Result<()> {
|
||||||
if let Err(err) = transaction.verify() {
|
if let Err(err) = transaction.verify() {
|
||||||
Err(err)
|
Err(err)
|
||||||
} else if let Err(err) = transaction.verify_precompiles() {
|
} else if let Err(err) = transaction.verify_precompiles(libsecp256k1_0_5_upgrade_enabled) {
|
||||||
Err(err)
|
Err(err)
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -212,7 +215,10 @@ impl Banks for BanksServer {
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
commitment: CommitmentLevel,
|
commitment: CommitmentLevel,
|
||||||
) -> Option<transaction::Result<()>> {
|
) -> Option<transaction::Result<()>> {
|
||||||
if let Err(err) = verify_transaction(&transaction) {
|
if let Err(err) = verify_transaction(
|
||||||
|
&transaction,
|
||||||
|
self.bank(commitment).libsecp256k1_0_5_upgrade_enabled(),
|
||||||
|
) {
|
||||||
return Some(Err(err));
|
return Some(Err(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1059,7 +1059,7 @@ impl BankingStage {
|
||||||
fn transactions_from_packets(
|
fn transactions_from_packets(
|
||||||
msgs: &Packets,
|
msgs: &Packets,
|
||||||
transaction_indexes: &[usize],
|
transaction_indexes: &[usize],
|
||||||
secp256k1_program_enabled: bool,
|
libsecp256k1_0_5_upgrade_enabled: bool,
|
||||||
cost_tracker: &Arc<RwLock<CostTracker>>,
|
cost_tracker: &Arc<RwLock<CostTracker>>,
|
||||||
banking_stage_stats: &BankingStageStats,
|
banking_stage_stats: &BankingStageStats,
|
||||||
) -> (Vec<HashedTransaction<'static>>, Vec<usize>, Vec<usize>) {
|
) -> (Vec<HashedTransaction<'static>>, Vec<usize>, Vec<usize>) {
|
||||||
|
@ -1070,9 +1070,8 @@ impl BankingStage {
|
||||||
.filter_map(|tx_index| {
|
.filter_map(|tx_index| {
|
||||||
let p = &msgs.packets[*tx_index];
|
let p = &msgs.packets[*tx_index];
|
||||||
let tx: Transaction = limited_deserialize(&p.data[0..p.meta.size]).ok()?;
|
let tx: Transaction = limited_deserialize(&p.data[0..p.meta.size]).ok()?;
|
||||||
if secp256k1_program_enabled {
|
tx.verify_precompiles(libsecp256k1_0_5_upgrade_enabled)
|
||||||
tx.verify_precompiles().ok()?;
|
.ok()?;
|
||||||
}
|
|
||||||
Some((tx, *tx_index))
|
Some((tx, *tx_index))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -1180,7 +1179,7 @@ impl BankingStage {
|
||||||
Self::transactions_from_packets(
|
Self::transactions_from_packets(
|
||||||
msgs,
|
msgs,
|
||||||
&packet_indexes,
|
&packet_indexes,
|
||||||
bank.secp256k1_program_enabled(),
|
bank.libsecp256k1_0_5_upgrade_enabled(),
|
||||||
cost_tracker,
|
cost_tracker,
|
||||||
banking_stage_stats,
|
banking_stage_stats,
|
||||||
);
|
);
|
||||||
|
@ -1292,7 +1291,7 @@ impl BankingStage {
|
||||||
Self::transactions_from_packets(
|
Self::transactions_from_packets(
|
||||||
msgs,
|
msgs,
|
||||||
transaction_indexes,
|
transaction_indexes,
|
||||||
bank.secp256k1_program_enabled(),
|
bank.libsecp256k1_0_5_upgrade_enabled(),
|
||||||
cost_tracker,
|
cost_tracker,
|
||||||
banking_stage_stats,
|
banking_stage_stats,
|
||||||
);
|
);
|
||||||
|
|
|
@ -359,7 +359,7 @@ pub trait EntrySlice {
|
||||||
fn verify_and_hash_transactions(
|
fn verify_and_hash_transactions(
|
||||||
&self,
|
&self,
|
||||||
skip_verification: bool,
|
skip_verification: bool,
|
||||||
secp256k1_program_enabled: bool,
|
libsecp256k1_0_5_upgrade_enabled: bool,
|
||||||
verify_tx_signatures_len: bool,
|
verify_tx_signatures_len: bool,
|
||||||
) -> Option<Vec<EntryType<'_>>>;
|
) -> Option<Vec<EntryType<'_>>>;
|
||||||
}
|
}
|
||||||
|
@ -515,7 +515,7 @@ impl EntrySlice for [Entry] {
|
||||||
fn verify_and_hash_transactions<'a>(
|
fn verify_and_hash_transactions<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
skip_verification: bool,
|
skip_verification: bool,
|
||||||
secp256k1_program_enabled: bool,
|
libsecp256k1_0_5_upgrade_enabled: bool,
|
||||||
verify_tx_signatures_len: bool,
|
verify_tx_signatures_len: bool,
|
||||||
) -> Option<Vec<EntryType<'a>>> {
|
) -> Option<Vec<EntryType<'a>>> {
|
||||||
let verify_and_hash = |tx: &'a Transaction| -> Option<HashedTransaction<'a>> {
|
let verify_and_hash = |tx: &'a Transaction| -> Option<HashedTransaction<'a>> {
|
||||||
|
@ -524,10 +524,8 @@ impl EntrySlice for [Entry] {
|
||||||
if size > PACKET_DATA_SIZE as u64 {
|
if size > PACKET_DATA_SIZE as u64 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
if secp256k1_program_enabled {
|
tx.verify_precompiles(libsecp256k1_0_5_upgrade_enabled)
|
||||||
// Verify tx precompiles if secp256k1 program is enabled.
|
.ok()?;
|
||||||
tx.verify_precompiles().ok()?;
|
|
||||||
}
|
|
||||||
if verify_tx_signatures_len && !tx.verify_signatures_len() {
|
if verify_tx_signatures_len && !tx.verify_signatures_len() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2404,13 +2404,13 @@ fn main() {
|
||||||
let mut store_failed_count = 0;
|
let mut store_failed_count = 0;
|
||||||
if force_enabled_count >= 1 {
|
if force_enabled_count >= 1 {
|
||||||
if base_bank
|
if base_bank
|
||||||
.get_account(&feature_set::secp256k1_program_enabled::id())
|
.get_account(&feature_set::spl_token_v2_multisig_fix::id())
|
||||||
.is_some()
|
.is_some()
|
||||||
{
|
{
|
||||||
// steal some lamports from the pretty old feature not to affect
|
// steal some lamports from the pretty old feature not to affect
|
||||||
// capitalizaion, which doesn't affect inflation behavior!
|
// capitalizaion, which doesn't affect inflation behavior!
|
||||||
base_bank.store_account(
|
base_bank.store_account(
|
||||||
&feature_set::secp256k1_program_enabled::id(),
|
&feature_set::spl_token_v2_multisig_fix::id(),
|
||||||
&AccountSharedData::default(),
|
&AccountSharedData::default(),
|
||||||
);
|
);
|
||||||
force_enabled_count -= 1;
|
force_enabled_count -= 1;
|
||||||
|
|
|
@ -793,7 +793,7 @@ pub fn confirm_slot(
|
||||||
let check_start = Instant::now();
|
let check_start = Instant::now();
|
||||||
let check_result = entries.verify_and_hash_transactions(
|
let check_result = entries.verify_and_hash_transactions(
|
||||||
skip_verification,
|
skip_verification,
|
||||||
bank.secp256k1_program_enabled(),
|
bank.libsecp256k1_0_5_upgrade_enabled(),
|
||||||
bank.verify_tx_signatures_len_enabled(),
|
bank.verify_tx_signatures_len_enabled(),
|
||||||
);
|
);
|
||||||
if check_result.is_none() {
|
if check_result.is_none() {
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub mod test {
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(tx.verify_precompiles().is_ok());
|
assert!(tx.verify_precompiles(false).is_ok());
|
||||||
|
|
||||||
let index = thread_rng().gen_range(0, secp_instruction.data.len());
|
let index = thread_rng().gen_range(0, secp_instruction.data.len());
|
||||||
secp_instruction.data[index] = secp_instruction.data[index].wrapping_add(12);
|
secp_instruction.data[index] = secp_instruction.data[index].wrapping_add(12);
|
||||||
|
@ -54,6 +54,6 @@ pub mod test {
|
||||||
&[&mint_keypair],
|
&[&mint_keypair],
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
assert!(tx.verify_precompiles().is_err());
|
assert!(tx.verify_precompiles(false).is_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1899,12 +1899,15 @@ impl JsonRpcRequestProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_transaction(transaction: &Transaction) -> Result<()> {
|
fn verify_transaction(
|
||||||
|
transaction: &Transaction,
|
||||||
|
libsecp256k1_0_5_upgrade_enabled: bool,
|
||||||
|
) -> Result<()> {
|
||||||
if transaction.verify().is_err() {
|
if transaction.verify().is_err() {
|
||||||
return Err(RpcCustomError::TransactionSignatureVerificationFailure.into());
|
return Err(RpcCustomError::TransactionSignatureVerificationFailure.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = transaction.verify_precompiles() {
|
if let Err(e) = transaction.verify_precompiles(libsecp256k1_0_5_upgrade_enabled) {
|
||||||
return Err(RpcCustomError::TransactionPrecompileVerificationFailure(e).into());
|
return Err(RpcCustomError::TransactionPrecompileVerificationFailure(e).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3001,7 +3004,10 @@ pub mod rpc_full {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !config.skip_preflight {
|
if !config.skip_preflight {
|
||||||
if let Err(e) = verify_transaction(&transaction) {
|
if let Err(e) = verify_transaction(
|
||||||
|
&transaction,
|
||||||
|
preflight_bank.libsecp256k1_0_5_upgrade_enabled(),
|
||||||
|
) {
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3064,6 +3070,7 @@ pub mod rpc_full {
|
||||||
let encoding = config.encoding.unwrap_or(UiTransactionEncoding::Base58);
|
let encoding = config.encoding.unwrap_or(UiTransactionEncoding::Base58);
|
||||||
let (_, mut transaction) = deserialize_transaction(data, encoding)?;
|
let (_, mut transaction) = deserialize_transaction(data, encoding)?;
|
||||||
|
|
||||||
|
let bank = &*meta.bank(config.commitment);
|
||||||
if config.sig_verify {
|
if config.sig_verify {
|
||||||
if config.replace_recent_blockhash {
|
if config.replace_recent_blockhash {
|
||||||
return Err(Error::invalid_params(
|
return Err(Error::invalid_params(
|
||||||
|
@ -3071,11 +3078,12 @@ pub mod rpc_full {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = verify_transaction(&transaction) {
|
if let Err(e) =
|
||||||
|
verify_transaction(&transaction, bank.libsecp256k1_0_5_upgrade_enabled())
|
||||||
|
{
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let bank = &*meta.bank(config.commitment);
|
|
||||||
if config.replace_recent_blockhash {
|
if config.replace_recent_blockhash {
|
||||||
transaction.message.recent_blockhash = bank.last_blockhash();
|
transaction.message.recent_blockhash = bank.last_blockhash();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ use solana_sdk::{
|
||||||
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
||||||
clock::{BankId, Slot, INITIAL_RENT_EPOCH},
|
clock::{BankId, Slot, INITIAL_RENT_EPOCH},
|
||||||
feature_set::{self, FeatureSet},
|
feature_set::{self, FeatureSet},
|
||||||
fee_calculator::{FeeCalculator, FeeConfig},
|
fee_calculator::FeeCalculator,
|
||||||
genesis_config::ClusterType,
|
genesis_config::ClusterType,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
message::Message,
|
message::Message,
|
||||||
|
@ -424,10 +424,6 @@ impl Accounts {
|
||||||
rent_collector: &RentCollector,
|
rent_collector: &RentCollector,
|
||||||
feature_set: &FeatureSet,
|
feature_set: &FeatureSet,
|
||||||
) -> Vec<TransactionLoadResult> {
|
) -> Vec<TransactionLoadResult> {
|
||||||
let fee_config = FeeConfig {
|
|
||||||
secp256k1_program_enabled: feature_set
|
|
||||||
.is_active(&feature_set::secp256k1_program_enabled::id()),
|
|
||||||
};
|
|
||||||
txs.zip(lock_results)
|
txs.zip(lock_results)
|
||||||
.map(|etx| match etx {
|
.map(|etx| match etx {
|
||||||
(tx, (Ok(()), nonce_rollback)) => {
|
(tx, (Ok(()), nonce_rollback)) => {
|
||||||
|
@ -440,7 +436,7 @@ impl Accounts {
|
||||||
.cloned()
|
.cloned()
|
||||||
});
|
});
|
||||||
let fee = if let Some(fee_calculator) = fee_calculator {
|
let fee = if let Some(fee_calculator) = fee_calculator {
|
||||||
fee_calculator.calculate_fee_with_config(tx.message(), &fee_config)
|
fee_calculator.calculate_fee(tx.message())
|
||||||
} else {
|
} else {
|
||||||
return (Err(TransactionError::BlockhashNotFound), None);
|
return (Err(TransactionError::BlockhashNotFound), None);
|
||||||
};
|
};
|
||||||
|
|
|
@ -80,7 +80,7 @@ use solana_sdk::{
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
feature,
|
feature,
|
||||||
feature_set::{self, FeatureSet},
|
feature_set::{self, FeatureSet},
|
||||||
fee_calculator::{FeeCalculator, FeeConfig, FeeRateGovernor},
|
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
||||||
genesis_config::{ClusterType, GenesisConfig},
|
genesis_config::{ClusterType, GenesisConfig},
|
||||||
hard_forks::HardForks,
|
hard_forks::HardForks,
|
||||||
hash::{extend_and_hash, hashv, Hash},
|
hash::{extend_and_hash, hashv, Hash},
|
||||||
|
@ -3374,10 +3374,6 @@ impl Bank {
|
||||||
let hash_queue = self.blockhash_queue.read().unwrap();
|
let hash_queue = self.blockhash_queue.read().unwrap();
|
||||||
let mut fees = 0;
|
let mut fees = 0;
|
||||||
|
|
||||||
let fee_config = FeeConfig {
|
|
||||||
secp256k1_program_enabled: self.secp256k1_program_enabled(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let results = txs
|
let results = txs
|
||||||
.zip(executed)
|
.zip(executed)
|
||||||
.map(|(tx, (res, nonce_rollback))| {
|
.map(|(tx, (res, nonce_rollback))| {
|
||||||
|
@ -3395,7 +3391,7 @@ impl Bank {
|
||||||
});
|
});
|
||||||
let fee_calculator = fee_calculator.ok_or(TransactionError::BlockhashNotFound)?;
|
let fee_calculator = fee_calculator.ok_or(TransactionError::BlockhashNotFound)?;
|
||||||
|
|
||||||
let fee = fee_calculator.calculate_fee_with_config(tx.message(), &fee_config);
|
let fee = fee_calculator.calculate_fee(tx.message());
|
||||||
|
|
||||||
let message = tx.message();
|
let message = tx.message();
|
||||||
match *res {
|
match *res {
|
||||||
|
@ -5095,11 +5091,6 @@ impl Bank {
|
||||||
self.rc.accounts.accounts_db.shrink_candidate_slots()
|
self.rc.accounts.accounts_db.shrink_candidate_slots()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn secp256k1_program_enabled(&self) -> bool {
|
|
||||||
self.feature_set
|
|
||||||
.is_active(&feature_set::secp256k1_program_enabled::id())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn no_overflow_rent_distribution_enabled(&self) -> bool {
|
pub fn no_overflow_rent_distribution_enabled(&self) -> bool {
|
||||||
self.feature_set
|
self.feature_set
|
||||||
.is_active(&feature_set::no_overflow_rent_distribution::id())
|
.is_active(&feature_set::no_overflow_rent_distribution::id())
|
||||||
|
@ -5120,6 +5111,11 @@ impl Bank {
|
||||||
.is_active(&feature_set::verify_tx_signatures_len::id())
|
.is_active(&feature_set::verify_tx_signatures_len::id())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn libsecp256k1_0_5_upgrade_enabled(&self) -> bool {
|
||||||
|
self.feature_set
|
||||||
|
.is_active(&feature_set::libsecp256k1_0_5_upgrade_enabled::id())
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the wallclock time from bank creation to now has exceeded the allotted
|
// Check if the wallclock time from bank creation to now has exceeded the allotted
|
||||||
// time for transaction processing
|
// time for transaction processing
|
||||||
pub fn should_bank_still_be_processing_txs(
|
pub fn should_bank_still_be_processing_txs(
|
||||||
|
@ -5722,7 +5718,7 @@ pub(crate) mod tests {
|
||||||
cluster_type: ClusterType::MainnetBeta,
|
cluster_type: ClusterType::MainnetBeta,
|
||||||
..GenesisConfig::default()
|
..GenesisConfig::default()
|
||||||
}));
|
}));
|
||||||
let sysvar_and_native_proram_delta0 = 10;
|
let sysvar_and_native_proram_delta0 = 11;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank0.capitalization(),
|
bank0.capitalization(),
|
||||||
42 * 42 + sysvar_and_native_proram_delta0
|
42 * 42 + sysvar_and_native_proram_delta0
|
||||||
|
@ -7424,10 +7420,10 @@ pub(crate) mod tests {
|
||||||
// not being eagerly-collected for exact rewards calculation
|
// not being eagerly-collected for exact rewards calculation
|
||||||
bank0.restore_old_behavior_for_fragile_tests();
|
bank0.restore_old_behavior_for_fragile_tests();
|
||||||
|
|
||||||
let sysvar_and_native_proram_delta0 = 10;
|
let sysvar_and_native_program_delta0 = 11;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank0.capitalization(),
|
bank0.capitalization(),
|
||||||
42 * 1_000_000_000 + sysvar_and_native_proram_delta0
|
42 * 1_000_000_000 + sysvar_and_native_program_delta0
|
||||||
);
|
);
|
||||||
assert!(bank0.rewards.read().unwrap().is_empty());
|
assert!(bank0.rewards.read().unwrap().is_empty());
|
||||||
|
|
||||||
|
@ -7547,7 +7543,7 @@ pub(crate) mod tests {
|
||||||
// not being eagerly-collected for exact rewards calculation
|
// not being eagerly-collected for exact rewards calculation
|
||||||
bank.restore_old_behavior_for_fragile_tests();
|
bank.restore_old_behavior_for_fragile_tests();
|
||||||
|
|
||||||
let sysvar_and_native_proram_delta = 10;
|
let sysvar_and_native_proram_delta = 11;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.capitalization(),
|
bank.capitalization(),
|
||||||
42 * 1_000_000_000 + sysvar_and_native_proram_delta
|
42 * 1_000_000_000 + sysvar_and_native_proram_delta
|
||||||
|
@ -10783,25 +10779,25 @@ pub(crate) mod tests {
|
||||||
if bank.slot == 0 {
|
if bank.slot == 0 {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.hash().to_string(),
|
bank.hash().to_string(),
|
||||||
"Cn7Wmi7w1n9NbK7RGnTQ4LpbJ2LtoJoc1sufiTwb57Ya"
|
"BfvaoHkrQwrkQo7T1mW6jmJXveRy11rut8bva2H1Rt5H"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if bank.slot == 32 {
|
if bank.slot == 32 {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.hash().to_string(),
|
bank.hash().to_string(),
|
||||||
"BXupB8XsZukMTnDbKshJ8qPCydWnc8BKtSj7YTJ6gAH"
|
"JBGPApnSMPKZaYiR16v46XSSGcKxy8kCbVtN1CG1XDxW"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if bank.slot == 64 {
|
if bank.slot == 64 {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.hash().to_string(),
|
bank.hash().to_string(),
|
||||||
"EDkKefgSMSV1NhxnGnJP7R5AGZ2JZD6oxnoZtGuEGBCU"
|
"BDCt9cGPfxpgJXzp8Tq1nX1zSqpbs8xrkAFyRhmXKiuX"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if bank.slot == 128 {
|
if bank.slot == 128 {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.hash().to_string(),
|
bank.hash().to_string(),
|
||||||
"AtWu4tubU9zGFChfHtQghQx3RVWtMQu6Rj49rQymFc4z"
|
"4zUpK4VUhKLaPUgeMMSeDR2w827goriRL5NndJxGDVmz"
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -10951,7 +10947,7 @@ pub(crate) mod tests {
|
||||||
// No more slots should be shrunk
|
// No more slots should be shrunk
|
||||||
assert_eq!(bank2.shrink_candidate_slots(), 0);
|
assert_eq!(bank2.shrink_candidate_slots(), 0);
|
||||||
// alive_counts represents the count of alive accounts in the three slots 0,1,2
|
// alive_counts represents the count of alive accounts in the three slots 0,1,2
|
||||||
assert_eq!(alive_counts, vec![9, 1, 7]);
|
assert_eq!(alive_counts, vec![10, 1, 7]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -10999,7 +10995,7 @@ pub(crate) mod tests {
|
||||||
.map(|_| bank.process_stale_slot_with_budget(0, force_to_return_alive_account))
|
.map(|_| bank.process_stale_slot_with_budget(0, force_to_return_alive_account))
|
||||||
.sum();
|
.sum();
|
||||||
// consumed_budgets represents the count of alive accounts in the three slots 0,1,2
|
// consumed_budgets represents the count of alive accounts in the three slots 0,1,2
|
||||||
assert_eq!(consumed_budgets, 10);
|
assert_eq!(consumed_budgets, 11);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -3,7 +3,6 @@ use crate::{
|
||||||
system_instruction_processor,
|
system_instruction_processor,
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
feature_set,
|
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
process_instruction::{stable_log, InvokeContext, ProcessInstructionWithContext},
|
process_instruction::{stable_log, InvokeContext, ProcessInstructionWithContext},
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
|
@ -64,6 +63,11 @@ fn genesis_builtins() -> Vec<Builtin> {
|
||||||
solana_config_program::id(),
|
solana_config_program::id(),
|
||||||
with_program_logging!(solana_config_program::config_processor::process_instruction),
|
with_program_logging!(solana_config_program::config_processor::process_instruction),
|
||||||
),
|
),
|
||||||
|
Builtin::new(
|
||||||
|
"secp256k1_program",
|
||||||
|
solana_sdk::secp256k1_program::id(),
|
||||||
|
solana_secp256k1_program::process_instruction,
|
||||||
|
),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,15 +86,7 @@ pub enum ActivationType {
|
||||||
/// normal child Bank creation.
|
/// normal child Bank creation.
|
||||||
/// https://github.com/solana-labs/solana/blob/84b139cc94b5be7c9e0c18c2ad91743231b85a0d/runtime/src/bank.rs#L1723
|
/// https://github.com/solana-labs/solana/blob/84b139cc94b5be7c9e0c18c2ad91743231b85a0d/runtime/src/bank.rs#L1723
|
||||||
fn feature_builtins() -> Vec<(Builtin, Pubkey, ActivationType)> {
|
fn feature_builtins() -> Vec<(Builtin, Pubkey, ActivationType)> {
|
||||||
vec![(
|
vec![]
|
||||||
Builtin::new(
|
|
||||||
"secp256k1_program",
|
|
||||||
solana_sdk::secp256k1_program::id(),
|
|
||||||
solana_secp256k1_program::process_instruction,
|
|
||||||
),
|
|
||||||
feature_set::secp256k1_program_enabled::id(),
|
|
||||||
ActivationType::NewProgram,
|
|
||||||
)]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get() -> Builtins {
|
pub(crate) fn get() -> Builtins {
|
||||||
|
|
|
@ -273,7 +273,7 @@ mod tests {
|
||||||
..GenesisConfig::default()
|
..GenesisConfig::default()
|
||||||
};
|
};
|
||||||
let mut bank = Arc::new(Bank::new(&genesis_config));
|
let mut bank = Arc::new(Bank::new(&genesis_config));
|
||||||
let sysvar_and_native_program_delta = 10;
|
let sysvar_and_native_program_delta = 11;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.capitalization(),
|
bank.capitalization(),
|
||||||
(num_genesis_accounts + num_non_circulating_accounts + num_stake_accounts) * balance
|
(num_genesis_accounts + num_non_circulating_accounts + num_stake_accounts) * balance
|
||||||
|
|
|
@ -20,18 +20,6 @@ impl Default for FeeCalculator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FeeConfig {
|
|
||||||
pub secp256k1_program_enabled: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for FeeConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
secp256k1_program_enabled: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FeeCalculator {
|
impl FeeCalculator {
|
||||||
pub fn new(lamports_per_signature: u64) -> Self {
|
pub fn new(lamports_per_signature: u64) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -40,20 +28,14 @@ impl FeeCalculator {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn calculate_fee(&self, message: &Message) -> u64 {
|
pub fn calculate_fee(&self, message: &Message) -> u64 {
|
||||||
self.calculate_fee_with_config(message, &FeeConfig::default())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn calculate_fee_with_config(&self, message: &Message, fee_config: &FeeConfig) -> u64 {
|
|
||||||
let mut num_secp256k1_signatures: u64 = 0;
|
let mut num_secp256k1_signatures: u64 = 0;
|
||||||
if fee_config.secp256k1_program_enabled {
|
for instruction in &message.instructions {
|
||||||
for instruction in &message.instructions {
|
let program_index = instruction.program_id_index as usize;
|
||||||
let program_index = instruction.program_id_index as usize;
|
// Transaction may not be sanitized here
|
||||||
// Transaction may not be sanitized here
|
if program_index < message.account_keys.len() {
|
||||||
if program_index < message.account_keys.len() {
|
let id = message.account_keys[program_index];
|
||||||
let id = message.account_keys[program_index];
|
if secp256k1_program::check_id(&id) && !instruction.data.is_empty() {
|
||||||
if secp256k1_program::check_id(&id) && !instruction.data.is_empty() {
|
num_secp256k1_signatures += instruction.data[0] as u64;
|
||||||
num_secp256k1_signatures += instruction.data[0] as u64;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,15 +241,6 @@ mod tests {
|
||||||
Some(&pubkey0),
|
Some(&pubkey0),
|
||||||
);
|
);
|
||||||
assert_eq!(FeeCalculator::new(1).calculate_fee(&message), 2);
|
assert_eq!(FeeCalculator::new(1).calculate_fee(&message), 2);
|
||||||
assert_eq!(
|
|
||||||
FeeCalculator::new(1).calculate_fee_with_config(
|
|
||||||
&message,
|
|
||||||
&FeeConfig {
|
|
||||||
secp256k1_program_enabled: false
|
|
||||||
}
|
|
||||||
),
|
|
||||||
1
|
|
||||||
);
|
|
||||||
|
|
||||||
secp_instruction.data = vec![0];
|
secp_instruction.data = vec![0];
|
||||||
secp_instruction2.data = vec![10];
|
secp_instruction2.data = vec![10];
|
||||||
|
|
|
@ -10,10 +10,6 @@ pub mod instructions_sysvar_enabled {
|
||||||
solana_sdk::declare_id!("EnvhHCLvg55P7PDtbvR1NwuTuAeodqpusV3MR5QEK8gs");
|
solana_sdk::declare_id!("EnvhHCLvg55P7PDtbvR1NwuTuAeodqpusV3MR5QEK8gs");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod secp256k1_program_enabled {
|
|
||||||
solana_sdk::declare_id!("E3PHP7w8kB7np3CTQ1qQ2tW3KCtjRSXBQgW9vM2mWv2Y");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod consistent_recent_blockhashes_sysvar {
|
pub mod consistent_recent_blockhashes_sysvar {
|
||||||
solana_sdk::declare_id!("3h1BQWPDS5veRsq6mDBWruEpgPxRJkfwGexg5iiQ9mYg");
|
solana_sdk::declare_id!("3h1BQWPDS5veRsq6mDBWruEpgPxRJkfwGexg5iiQ9mYg");
|
||||||
}
|
}
|
||||||
|
@ -171,11 +167,14 @@ pub mod rent_for_sysvars {
|
||||||
solana_sdk::declare_id!("BKCPBQQBZqggVnFso5nQ8rQ4RwwogYwjuUt9biBjxwNF");
|
solana_sdk::declare_id!("BKCPBQQBZqggVnFso5nQ8rQ4RwwogYwjuUt9biBjxwNF");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod libsecp256k1_0_5_upgrade_enabled {
|
||||||
|
solana_sdk::declare_id!("DhsYfRjxfnh2g7HKJYSzT79r74Afa1wbHkAgHndrA1oy");
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
/// Map of feature identifiers to user-visible description
|
/// Map of feature identifiers to user-visible description
|
||||||
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
|
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
|
||||||
(instructions_sysvar_enabled::id(), "instructions sysvar"),
|
(instructions_sysvar_enabled::id(), "instructions sysvar"),
|
||||||
(secp256k1_program_enabled::id(), "secp256k1 program"),
|
|
||||||
(consistent_recent_blockhashes_sysvar::id(), "consistent recentblockhashes sysvar"),
|
(consistent_recent_blockhashes_sysvar::id(), "consistent recentblockhashes sysvar"),
|
||||||
(deprecate_rewards_sysvar::id(), "deprecate unused rewards sysvar"),
|
(deprecate_rewards_sysvar::id(), "deprecate unused rewards sysvar"),
|
||||||
(pico_inflation::id(), "pico inflation"),
|
(pico_inflation::id(), "pico inflation"),
|
||||||
|
@ -213,6 +212,7 @@ lazy_static! {
|
||||||
(updated_verify_policy::id(), "Update verify policy"),
|
(updated_verify_policy::id(), "Update verify policy"),
|
||||||
(neon_evm_compute_budget::id(), "bump neon_evm's compute budget"),
|
(neon_evm_compute_budget::id(), "bump neon_evm's compute budget"),
|
||||||
(rent_for_sysvars::id(), "collect rent from accounts owned by sysvars"),
|
(rent_for_sysvars::id(), "collect rent from accounts owned by sysvars"),
|
||||||
|
(libsecp256k1_0_5_upgrade_enabled::id(), "upgrade libsecp256k1 to v0.5.0"),
|
||||||
/*************** ADD NEW FEATURES HERE ***************/
|
/*************** ADD NEW FEATURES HERE ***************/
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -392,7 +392,7 @@ impl Transaction {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn verify_precompiles(&self) -> Result<()> {
|
pub fn verify_precompiles(&self, _libsecp256k1_0_5_upgrade_enabled: bool) -> Result<()> {
|
||||||
for instruction in &self.message().instructions {
|
for instruction in &self.message().instructions {
|
||||||
// The Transaction may not be sanitized at this point
|
// The Transaction may not be sanitized at this point
|
||||||
if instruction.program_id_index as usize >= self.message().account_keys.len() {
|
if instruction.program_id_index as usize >= self.message().account_keys.len() {
|
||||||
|
|
Loading…
Reference in New Issue