From 3f503c65ee54adfbb5d852a3787451f2e82a0733 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Tue, 3 Dec 2024 11:53:49 +0900 Subject: [PATCH 1/3] add secp256r1 to runtime-transaction signature details --- Cargo.lock | 3 +++ cost-model/src/transaction_cost.rs | 2 +- programs/sbf/Cargo.lock | 3 +++ runtime-transaction/Cargo.toml | 1 + .../src/runtime_transaction/sdk_transactions.rs | 1 + .../src/runtime_transaction/transaction_view.rs | 1 + runtime-transaction/src/signature_details.rs | 16 ++++++++++++++++ sdk/message/Cargo.toml | 1 + sdk/message/src/sanitized.rs | 16 ++++++++++++++++ svm/examples/Cargo.lock | 3 +++ transaction-view/Cargo.toml | 1 + .../src/resolved_transaction_view.rs | 7 +++++++ 12 files changed, 54 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index e317b6cc79ed6e..0361d4e38a8222 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -237,6 +237,7 @@ dependencies = [ "bincode", "criterion", "solana-sdk", + "solana-secp256r1-program", "solana-svm-transaction", ] @@ -7550,6 +7551,7 @@ dependencies = [ "solana-pubkey", "solana-sanitize", "solana-sdk-ids", + "solana-secp256r1-program", "solana-sha256-hasher", "solana-short-vec", "solana-system-interface", @@ -8462,6 +8464,7 @@ dependencies = [ "solana-program", "solana-pubkey", "solana-sdk", + "solana-secp256r1-program", "solana-svm-transaction", "thiserror 2.0.3", ] diff --git a/cost-model/src/transaction_cost.rs b/cost-model/src/transaction_cost.rs index 3df0f45e7b8067..b4e3287b0ebab6 100644 --- a/cost-model/src/transaction_cost.rs +++ b/cost-model/src/transaction_cost.rs @@ -244,7 +244,7 @@ impl solana_runtime_transaction::transaction_meta::StaticMeta for WritableKeysTr fn signature_details(&self) -> &solana_sdk::message::TransactionSignatureDetails { const DUMMY: solana_sdk::message::TransactionSignatureDetails = - solana_sdk::message::TransactionSignatureDetails::new(0, 0, 0); + solana_sdk::message::TransactionSignatureDetails::new(0, 0, 0, 0); &DUMMY } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index c23f52f0a6ef3d..b886e9eb895355 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -78,6 +78,7 @@ name = "agave-transaction-view" version = "2.2.0" dependencies = [ "solana-sdk", + "solana-secp256r1-program", "solana-svm-transaction", ] @@ -5962,6 +5963,7 @@ dependencies = [ "solana-pubkey", "solana-sanitize", "solana-sdk-ids", + "solana-secp256r1-program", "solana-short-vec", "solana-system-interface", "solana-transaction-error", @@ -6678,6 +6680,7 @@ dependencies = [ "solana-compute-budget", "solana-pubkey", "solana-sdk", + "solana-secp256r1-program", "solana-svm-transaction", "thiserror 2.0.3", ] diff --git a/runtime-transaction/Cargo.toml b/runtime-transaction/Cargo.toml index 489ff1d3f78285..74313966d5fbbd 100644 --- a/runtime-transaction/Cargo.toml +++ b/runtime-transaction/Cargo.toml @@ -16,6 +16,7 @@ solana-builtins-default-costs = { workspace = true } solana-compute-budget = { workspace = true } solana-pubkey = { workspace = true } solana-sdk = { workspace = true } +solana-secp256r1-program = { workspace = true, features = ["openssl-vendored"] } solana-svm-transaction = { workspace = true } thiserror = { workspace = true } diff --git a/runtime-transaction/src/runtime_transaction/sdk_transactions.rs b/runtime-transaction/src/runtime_transaction/sdk_transactions.rs index f60b741eca01a9..691469167387c9 100644 --- a/runtime-transaction/src/runtime_transaction/sdk_transactions.rs +++ b/runtime-transaction/src/runtime_transaction/sdk_transactions.rs @@ -47,6 +47,7 @@ impl RuntimeTransaction { ), precompile_signature_details.num_secp256k1_instruction_signatures, precompile_signature_details.num_ed25519_instruction_signatures, + precompile_signature_details.num_secp256r1_instruction_signatures, ); let compute_budget_instruction_details = ComputeBudgetInstructionDetails::try_from( sanitized_versioned_tx diff --git a/runtime-transaction/src/runtime_transaction/transaction_view.rs b/runtime-transaction/src/runtime_transaction/transaction_view.rs index a83036c276be81..7a7c38f0db306b 100644 --- a/runtime-transaction/src/runtime_transaction/transaction_view.rs +++ b/runtime-transaction/src/runtime_transaction/transaction_view.rs @@ -57,6 +57,7 @@ impl RuntimeTransaction> { u64::from(transaction.num_required_signatures()), precompile_signature_details.num_secp256k1_instruction_signatures, precompile_signature_details.num_ed25519_instruction_signatures, + precompile_signature_details.num_secp256r1_instruction_signatures, ); let compute_budget_instruction_details = ComputeBudgetInstructionDetails::try_from(transaction.program_instructions_iter())?; diff --git a/runtime-transaction/src/signature_details.rs b/runtime-transaction/src/signature_details.rs index 8972873116a236..5dea3c74b956cc 100644 --- a/runtime-transaction/src/signature_details.rs +++ b/runtime-transaction/src/signature_details.rs @@ -7,6 +7,7 @@ use { pub struct PrecompileSignatureDetails { pub num_secp256k1_instruction_signatures: u64, pub num_ed25519_instruction_signatures: u64, + pub num_secp256r1_instruction_signatures: u64, } /// Get transaction signature details. @@ -20,6 +21,7 @@ pub fn get_precompile_signature_details<'a>( // is low enough that the sum of all signatures will not overflow a u64. let mut num_secp256k1_instruction_signatures: u64 = 0; let mut num_ed25519_instruction_signatures: u64 = 0; + let mut num_secp256r1_instruction_signatures: u64 = 0; for (program_id, instruction) in instructions { let program_id_index = instruction.program_id_index; match filter.is_signature(program_id_index, program_id) { @@ -32,12 +34,17 @@ pub fn get_precompile_signature_details<'a>( num_ed25519_instruction_signatures = num_ed25519_instruction_signatures .wrapping_add(get_num_signatures_in_instruction(&instruction)); } + ProgramIdStatus::Secp256r1 => { + num_secp256r1_instruction_signatures = num_secp256r1_instruction_signatures + .wrapping_add(get_num_signatures_in_instruction(&instruction)); + } } } PrecompileSignatureDetails { num_secp256k1_instruction_signatures, num_ed25519_instruction_signatures, + num_secp256r1_instruction_signatures, } } @@ -51,6 +58,7 @@ enum ProgramIdStatus { NotSignature, Secp256k1, Ed25519, + Secp256r1, } struct SignatureDetailsFilter { @@ -86,6 +94,8 @@ impl SignatureDetailsFilter { ProgramIdStatus::Secp256k1 } else if program_id == &solana_sdk::ed25519_program::ID { ProgramIdStatus::Ed25519 + } else if program_id == &solana_secp256r1_program::ID { + ProgramIdStatus::Secp256r1 } else { ProgramIdStatus::NotSignature } @@ -140,19 +150,23 @@ mod tests { Pubkey::new_unique(), solana_sdk::secp256k1_program::ID, solana_sdk::ed25519_program::ID, + solana_secp256r1_program::ID, ]; let instructions = [ make_instruction(&program_ids, 1, &[5]), make_instruction(&program_ids, 2, &[3]), + make_instruction(&program_ids, 3, &[4]), make_instruction(&program_ids, 0, &[]), make_instruction(&program_ids, 2, &[2]), make_instruction(&program_ids, 1, &[1]), make_instruction(&program_ids, 0, &[]), + make_instruction(&program_ids, 3, &[3]), ]; let signature_details = get_precompile_signature_details(instructions.into_iter()); assert_eq!(signature_details.num_secp256k1_instruction_signatures, 6); assert_eq!(signature_details.num_ed25519_instruction_signatures, 5); + assert_eq!(signature_details.num_secp256r1_instruction_signatures, 7); } #[test] @@ -160,6 +174,7 @@ mod tests { let program_ids = [ solana_sdk::secp256k1_program::ID, solana_sdk::ed25519_program::ID, + solana_secp256r1_program::ID, ]; let instructions = [ make_instruction(&program_ids, 0, &[]), @@ -169,5 +184,6 @@ mod tests { let signature_details = get_precompile_signature_details(instructions.into_iter()); assert_eq!(signature_details.num_secp256k1_instruction_signatures, 0); assert_eq!(signature_details.num_ed25519_instruction_signatures, 0); + assert_eq!(signature_details.num_secp256r1_instruction_signatures, 0); } } diff --git a/sdk/message/Cargo.toml b/sdk/message/Cargo.toml index 20d8ab43dcef3a..286bb284a1da12 100644 --- a/sdk/message/Cargo.toml +++ b/sdk/message/Cargo.toml @@ -24,6 +24,7 @@ solana-logger = { workspace = true, optional = true } solana-pubkey = { workspace = true } solana-sanitize = { workspace = true } solana-sdk-ids = { workspace = true } +solana-secp256r1-program = { workspace = true, features = ["openssl-vendored"] } solana-short-vec = { workspace = true, optional = true } solana-system-interface = { workspace = true, optional = true, features = [ "bincode", diff --git a/sdk/message/src/sanitized.rs b/sdk/message/src/sanitized.rs index ac7f61b05010a6..f66e7d9aa4fccf 100644 --- a/sdk/message/src/sanitized.rs +++ b/sdk/message/src/sanitized.rs @@ -411,6 +411,13 @@ impl SanitizedMessage { .num_ed25519_instruction_signatures .saturating_add(u64::from(*num_verifies)); } + } else if solana_secp256r1_program::check_id(program_id) { + if let Some(num_verifies) = instruction.data.first() { + transaction_signature_details.num_secp256r1_instruction_signatures = + transaction_signature_details + .num_secp256r1_instruction_signatures + .saturating_add(u64::from(*num_verifies)); + } } } @@ -425,6 +432,7 @@ pub struct TransactionSignatureDetails { num_transaction_signatures: u64, num_secp256k1_instruction_signatures: u64, num_ed25519_instruction_signatures: u64, + num_secp256r1_instruction_signatures: u64, } impl TransactionSignatureDetails { @@ -432,11 +440,13 @@ impl TransactionSignatureDetails { num_transaction_signatures: u64, num_secp256k1_instruction_signatures: u64, num_ed25519_instruction_signatures: u64, + num_secp256r1_instruction_signatures: u64, ) -> Self { Self { num_transaction_signatures, num_secp256k1_instruction_signatures, num_ed25519_instruction_signatures, + num_secp256r1_instruction_signatures, } } @@ -445,6 +455,7 @@ impl TransactionSignatureDetails { self.num_transaction_signatures .saturating_add(self.num_secp256k1_instruction_signatures) .saturating_add(self.num_ed25519_instruction_signatures) + .saturating_add(self.num_secp256r1_instruction_signatures) } /// return the number of transaction signatures @@ -461,6 +472,11 @@ impl TransactionSignatureDetails { pub fn num_ed25519_instruction_signatures(&self) -> u64 { self.num_ed25519_instruction_signatures } + + /// return the number of secp256k1 instruction signatures + pub fn num_secp256r1_instruction_signatures(&self) -> u64 { + self.num_secp256r1_instruction_signatures + } } #[cfg(test)] diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index 58cd78515ad41d..f0af5bafe749fb 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -78,6 +78,7 @@ name = "agave-transaction-view" version = "2.2.0" dependencies = [ "solana-sdk", + "solana-secp256r1-program", "solana-svm-transaction", ] @@ -5782,6 +5783,7 @@ dependencies = [ "solana-pubkey", "solana-sanitize", "solana-sdk-ids", + "solana-secp256r1-program", "solana-short-vec", "solana-system-interface", "solana-transaction-error", @@ -6498,6 +6500,7 @@ dependencies = [ "solana-compute-budget", "solana-pubkey", "solana-sdk", + "solana-secp256r1-program", "solana-svm-transaction", "thiserror 2.0.3", ] diff --git a/transaction-view/Cargo.toml b/transaction-view/Cargo.toml index 44347099927442..15aff155aeebb0 100644 --- a/transaction-view/Cargo.toml +++ b/transaction-view/Cargo.toml @@ -11,6 +11,7 @@ edition = { workspace = true } [dependencies] solana-sdk = { workspace = true } +solana-secp256r1-program = { workspace = true } solana-svm-transaction = { workspace = true } [dev-dependencies] diff --git a/transaction-view/src/resolved_transaction_view.rs b/transaction-view/src/resolved_transaction_view.rs index 1bc8cd1ef8508b..9c52f41d2f6bba 100644 --- a/transaction-view/src/resolved_transaction_view.rs +++ b/transaction-view/src/resolved_transaction_view.rs @@ -165,6 +165,7 @@ impl ResolvedTransactionView { // counting the number of pre-processor operations separately let mut num_secp256k1_instruction_signatures: u64 = 0; let mut num_ed25519_instruction_signatures: u64 = 0; + let mut num_secp256r1_instruction_signatures: u64 = 0; for (program_id, instruction) in self.program_instructions_iter() { if secp256k1_program::check_id(program_id) { if let Some(num_verifies) = instruction.data.first() { @@ -176,6 +177,11 @@ impl ResolvedTransactionView { num_ed25519_instruction_signatures = num_ed25519_instruction_signatures.wrapping_add(u64::from(*num_verifies)); } + } else if solana_secp256r1_program::check_id(program_id) { + if let Some(num_verifies) = instruction.data.first() { + num_secp256r1_instruction_signatures = + num_secp256r1_instruction_signatures.wrapping_add(u64::from(*num_verifies)); + } } } @@ -183,6 +189,7 @@ impl ResolvedTransactionView { u64::from(self.view.num_required_signatures()), num_secp256k1_instruction_signatures, num_ed25519_instruction_signatures, + num_secp256r1_instruction_signatures, ) } } From c47cfe683a2ee4daa5c96b97d7b1c2669ac5a893 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Wed, 4 Dec 2024 08:26:51 +0900 Subject: [PATCH 2/3] add `solana-sdk-ids` dependency and remove `solana-secp256r1-program` dependency --- Cargo.lock | 5 ++--- runtime-transaction/Cargo.toml | 2 +- runtime-transaction/src/signature_details.rs | 6 +++--- sdk/message/Cargo.toml | 1 - sdk/message/src/sanitized.rs | 4 ++-- transaction-view/Cargo.toml | 2 +- transaction-view/src/resolved_transaction_view.rs | 3 ++- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0361d4e38a8222..559479c2af30f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -237,7 +237,7 @@ dependencies = [ "bincode", "criterion", "solana-sdk", - "solana-secp256r1-program", + "solana-sdk-ids", "solana-svm-transaction", ] @@ -7551,7 +7551,6 @@ dependencies = [ "solana-pubkey", "solana-sanitize", "solana-sdk-ids", - "solana-secp256r1-program", "solana-sha256-hasher", "solana-short-vec", "solana-system-interface", @@ -8464,7 +8463,7 @@ dependencies = [ "solana-program", "solana-pubkey", "solana-sdk", - "solana-secp256r1-program", + "solana-sdk-ids", "solana-svm-transaction", "thiserror 2.0.3", ] diff --git a/runtime-transaction/Cargo.toml b/runtime-transaction/Cargo.toml index 74313966d5fbbd..7f925bda81a7bb 100644 --- a/runtime-transaction/Cargo.toml +++ b/runtime-transaction/Cargo.toml @@ -16,7 +16,7 @@ solana-builtins-default-costs = { workspace = true } solana-compute-budget = { workspace = true } solana-pubkey = { workspace = true } solana-sdk = { workspace = true } -solana-secp256r1-program = { workspace = true, features = ["openssl-vendored"] } +solana-sdk-ids = { workspace = true } solana-svm-transaction = { workspace = true } thiserror = { workspace = true } diff --git a/runtime-transaction/src/signature_details.rs b/runtime-transaction/src/signature_details.rs index 5dea3c74b956cc..888376a960d7e6 100644 --- a/runtime-transaction/src/signature_details.rs +++ b/runtime-transaction/src/signature_details.rs @@ -94,7 +94,7 @@ impl SignatureDetailsFilter { ProgramIdStatus::Secp256k1 } else if program_id == &solana_sdk::ed25519_program::ID { ProgramIdStatus::Ed25519 - } else if program_id == &solana_secp256r1_program::ID { + } else if program_id == &solana_sdk_ids::secp256r1_program::ID { ProgramIdStatus::Secp256r1 } else { ProgramIdStatus::NotSignature @@ -150,7 +150,7 @@ mod tests { Pubkey::new_unique(), solana_sdk::secp256k1_program::ID, solana_sdk::ed25519_program::ID, - solana_secp256r1_program::ID, + solana_sdk_ids::secp256r1_program::ID, ]; let instructions = [ make_instruction(&program_ids, 1, &[5]), @@ -174,7 +174,7 @@ mod tests { let program_ids = [ solana_sdk::secp256k1_program::ID, solana_sdk::ed25519_program::ID, - solana_secp256r1_program::ID, + solana_sdk_ids::secp256r1_program::ID, ]; let instructions = [ make_instruction(&program_ids, 0, &[]), diff --git a/sdk/message/Cargo.toml b/sdk/message/Cargo.toml index 286bb284a1da12..20d8ab43dcef3a 100644 --- a/sdk/message/Cargo.toml +++ b/sdk/message/Cargo.toml @@ -24,7 +24,6 @@ solana-logger = { workspace = true, optional = true } solana-pubkey = { workspace = true } solana-sanitize = { workspace = true } solana-sdk-ids = { workspace = true } -solana-secp256r1-program = { workspace = true, features = ["openssl-vendored"] } solana-short-vec = { workspace = true, optional = true } solana-system-interface = { workspace = true, optional = true, features = [ "bincode", diff --git a/sdk/message/src/sanitized.rs b/sdk/message/src/sanitized.rs index f66e7d9aa4fccf..e4429ac243cadd 100644 --- a/sdk/message/src/sanitized.rs +++ b/sdk/message/src/sanitized.rs @@ -14,7 +14,7 @@ use { solana_instruction::{BorrowedAccountMeta, BorrowedInstruction}, solana_pubkey::Pubkey, solana_sanitize::Sanitize, - solana_sdk_ids::{ed25519_program, secp256k1_program}, + solana_sdk_ids::{ed25519_program, secp256k1_program, secp256r1_program}, std::{borrow::Cow, collections::HashSet, convert::TryFrom}, }; @@ -411,7 +411,7 @@ impl SanitizedMessage { .num_ed25519_instruction_signatures .saturating_add(u64::from(*num_verifies)); } - } else if solana_secp256r1_program::check_id(program_id) { + } else if secp256r1_program::check_id(program_id) { if let Some(num_verifies) = instruction.data.first() { transaction_signature_details.num_secp256r1_instruction_signatures = transaction_signature_details diff --git a/transaction-view/Cargo.toml b/transaction-view/Cargo.toml index 15aff155aeebb0..cb4a43aa7753bd 100644 --- a/transaction-view/Cargo.toml +++ b/transaction-view/Cargo.toml @@ -11,7 +11,7 @@ edition = { workspace = true } [dependencies] solana-sdk = { workspace = true } -solana-secp256r1-program = { workspace = true } +solana-sdk-ids = { workspace = true } solana-svm-transaction = { workspace = true } [dev-dependencies] diff --git a/transaction-view/src/resolved_transaction_view.rs b/transaction-view/src/resolved_transaction_view.rs index 9c52f41d2f6bba..3dbcb1273fd601 100644 --- a/transaction-view/src/resolved_transaction_view.rs +++ b/transaction-view/src/resolved_transaction_view.rs @@ -17,6 +17,7 @@ use { secp256k1_program, signature::Signature, }, + solana_sdk_ids::secp256r1_program, solana_svm_transaction::{ instruction::SVMInstruction, message_address_table_lookup::SVMMessageAddressTableLookup, svm_message::SVMMessage, svm_transaction::SVMTransaction, @@ -177,7 +178,7 @@ impl ResolvedTransactionView { num_ed25519_instruction_signatures = num_ed25519_instruction_signatures.wrapping_add(u64::from(*num_verifies)); } - } else if solana_secp256r1_program::check_id(program_id) { + } else if secp256r1_program::check_id(program_id) { if let Some(num_verifies) = instruction.data.first() { num_secp256r1_instruction_signatures = num_secp256r1_instruction_signatures.wrapping_add(u64::from(*num_verifies)); From d42c944a87b715281c41d0aa38eb2b807cee7ec8 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Wed, 4 Dec 2024 08:28:59 +0900 Subject: [PATCH 3/3] cargo lock --- programs/sbf/Cargo.lock | 5 ++--- svm/examples/Cargo.lock | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index b886e9eb895355..b1d696e94741a8 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -78,7 +78,7 @@ name = "agave-transaction-view" version = "2.2.0" dependencies = [ "solana-sdk", - "solana-secp256r1-program", + "solana-sdk-ids", "solana-svm-transaction", ] @@ -5963,7 +5963,6 @@ dependencies = [ "solana-pubkey", "solana-sanitize", "solana-sdk-ids", - "solana-secp256r1-program", "solana-short-vec", "solana-system-interface", "solana-transaction-error", @@ -6680,7 +6679,7 @@ dependencies = [ "solana-compute-budget", "solana-pubkey", "solana-sdk", - "solana-secp256r1-program", + "solana-sdk-ids", "solana-svm-transaction", "thiserror 2.0.3", ] diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index f0af5bafe749fb..7e8009a6e71004 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -78,7 +78,7 @@ name = "agave-transaction-view" version = "2.2.0" dependencies = [ "solana-sdk", - "solana-secp256r1-program", + "solana-sdk-ids", "solana-svm-transaction", ] @@ -5783,7 +5783,6 @@ dependencies = [ "solana-pubkey", "solana-sanitize", "solana-sdk-ids", - "solana-secp256r1-program", "solana-short-vec", "solana-system-interface", "solana-transaction-error", @@ -6500,7 +6499,7 @@ dependencies = [ "solana-compute-budget", "solana-pubkey", "solana-sdk", - "solana-secp256r1-program", + "solana-sdk-ids", "solana-svm-transaction", "thiserror 2.0.3", ]