Skip to content

Commit

Permalink
Add keccak-secp256k1 instruction (#11839)
Browse files Browse the repository at this point in the history
* Implement keccak-secp256k1 instruction

Verifies eth addreses with ecrecover function

* Move secp256k1 test

(cherry picked from commit 3930cb8)

# Conflicts:
#	Cargo.lock
#	runtime/Cargo.toml
  • Loading branch information
sakridge authored and mergify-bot committed Sep 21, 2020
1 parent 7db0464 commit 778c70b
Show file tree
Hide file tree
Showing 25 changed files with 756 additions and 52 deletions.
112 changes: 107 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ members = [
"net-shaper",
"notifier",
"poh-bench",
"programs/secp256k1",
"programs/bpf_loader",
"programs/budget",
"programs/config",
Expand Down
2 changes: 1 addition & 1 deletion cli/src/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn check_account_for_multiple_fees_with_commitment(
pub fn calculate_fee(fee_calculator: &FeeCalculator, messages: &[&Message]) -> u64 {
messages
.iter()
.map(|message| fee_calculator.calculate_fee(message))
.map(|message| fee_calculator.calculate_fee(message, None))
.sum()
}

Expand Down
42 changes: 36 additions & 6 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions core/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2977,7 +2977,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();
Expand Down Expand Up @@ -4074,7 +4074,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!(
Expand Down
5 changes: 4 additions & 1 deletion core/src/transaction_status_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,12 @@ pub fn confirm_slot(

let verifier = if !skip_verification {
datapoint_debug!("verify-batch-size", ("size", num_entries as i64, i64));
let entry_state = entries.start_verify(&progress.last_entry, recyclers.clone());
let entry_state = entries.start_verify(
&progress.last_entry,
recyclers.clone(),
bank.cluster_type(),
bank.epoch(),
);
if entry_state.status() == EntryVerificationStatus::Failure {
warn!("Ledger proof of history failed at slot: {}", slot);
return Err(BlockError::InvalidEntryHash.into());
Expand Down
Loading

0 comments on commit 778c70b

Please sign in to comment.