Add keccak-secp256k1 instruction (#11839)

* Implement keccak-secp256k1 instruction

Verifies eth addreses with ecrecover function

* Move secp256k1 test
This commit is contained in:
sakridge
2020-09-15 18:23:21 -07:00
committed by GitHub
parent 7237e7065f
commit 3930cb865a
25 changed files with 732 additions and 52 deletions

View File

@ -30,9 +30,10 @@ use solana_runtime::{
};
use solana_sdk::{
clock::{
Slot, DEFAULT_TICKS_PER_SLOT, MAX_PROCESSING_AGE, MAX_TRANSACTION_FORWARDING_DELAY,
Epoch, Slot, DEFAULT_TICKS_PER_SLOT, MAX_PROCESSING_AGE, MAX_TRANSACTION_FORWARDING_DELAY,
MAX_TRANSACTION_FORWARDING_DELAY_GPU,
},
genesis_config::ClusterType,
poh_config::PohConfig,
pubkey::Pubkey,
timing::{duration_as_ms, timestamp},
@ -724,6 +725,8 @@ impl BankingStage {
fn transactions_from_packets(
msgs: &Packets,
transaction_indexes: &[usize],
cluster_type: ClusterType,
epoch: Epoch,
) -> (Vec<Transaction>, Vec<usize>) {
let packets = Packets::new(
transaction_indexes
@ -733,8 +736,27 @@ impl BankingStage {
);
let transactions = Self::deserialize_transactions(&packets);
let maybe_secp_verified_transactions: Vec<_> =
if solana_sdk::secp256k1::is_enabled(cluster_type, epoch) {
transactions
.into_iter()
.map(|tx| {
if let Some(tx) = tx {
if tx.verify_precompiles().is_ok() {
Some(tx)
} else {
None
}
} else {
None
}
})
.collect()
} else {
transactions
};
Self::filter_transaction_indexes(transactions, &transaction_indexes)
Self::filter_transaction_indexes(maybe_secp_verified_transactions, &transaction_indexes)
}
/// This function filters pending packets that are still valid
@ -783,8 +805,12 @@ impl BankingStage {
transaction_status_sender: Option<TransactionStatusSender>,
gossip_vote_sender: &ReplayVoteSender,
) -> (usize, usize, Vec<usize>) {
let (transactions, transaction_to_packet_indexes) =
Self::transactions_from_packets(msgs, &packet_indexes);
let (transactions, transaction_to_packet_indexes) = Self::transactions_from_packets(
msgs,
&packet_indexes,
bank.cluster_type(),
bank.epoch(),
);
debug!(
"bank: {} filtered transactions {}",
bank.slot(),
@ -833,8 +859,12 @@ impl BankingStage {
}
}
let (transactions, transaction_to_packet_indexes) =
Self::transactions_from_packets(msgs, &transaction_indexes);
let (transactions, transaction_to_packet_indexes) = Self::transactions_from_packets(
msgs,
&transaction_indexes,
bank.cluster_type(),
bank.epoch(),
);
let tx_count = transaction_to_packet_indexes.len();

View File

@ -2968,7 +2968,7 @@ pub mod tests {
let largest_accounts: Vec<RpcAccountBalance> =
serde_json::from_value(json["result"]["value"].clone())
.expect("actual response deserialization");
assert_eq!(largest_accounts.len(), 19);
assert_eq!(largest_accounts.len(), 20);
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getLargestAccounts","params":[{"filter":"nonCirculating"}]}"#;
let res = io.handle_request_sync(&req, meta);
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
@ -4065,7 +4065,7 @@ pub mod tests {
);
// sendTransaction will fail due to insanity
bad_transaction.message.instructions[0].program_id_index = 255u8;
bad_transaction.message.instructions[0].program_id_index = 0u8;
let recent_blockhash = bank_forks.read().unwrap().root_bank().last_blockhash();
bad_transaction.sign(&[&mint_keypair], recent_blockhash);
let req = format!(

View File

@ -71,7 +71,10 @@ impl TransactionStatusService {
_ => bank.get_fee_calculator(&transaction.message().recent_blockhash),
}
.expect("FeeCalculator must exist");
let fee = fee_calculator.calculate_fee(transaction.message());
let fee = fee_calculator.calculate_fee(
transaction.message(),
solana_sdk::secp256k1::get_fee_config(bank.cluster_type(), bank.epoch()),
);
let (writable_keys, readonly_keys) =
transaction.message.get_account_keys_by_lock_type();
blockstore