From 6dbf058ab5bb0aed2cba512b998083f964f4a532 Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Wed, 15 Jan 2025 08:53:46 -0600 Subject: [PATCH] secp256r1 signatures count towards fee - behind feature --- fee/src/lib.rs | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/fee/src/lib.rs b/fee/src/lib.rs index 91712e6062c262..241c1061d86bd8 100644 --- a/fee/src/lib.rs +++ b/fee/src/lib.rs @@ -1,5 +1,7 @@ use { - solana_feature_set::{remove_rounding_in_fee_calculation, FeatureSet}, + solana_feature_set::{ + enable_secp256r1_precompile, remove_rounding_in_fee_calculation, FeatureSet, + }, solana_fee_structure::FeeDetails, solana_svm_transaction::svm_message::SVMMessage, }; @@ -9,6 +11,7 @@ use { #[derive(Copy, Clone)] pub struct FeeFeatures { pub remove_rounding_in_fee_calculation: bool, + pub enable_secp256r1_precompile: bool, } impl From<&FeatureSet> for FeeFeatures { @@ -16,6 +19,7 @@ impl From<&FeatureSet> for FeeFeatures { Self { remove_rounding_in_fee_calculation: feature_set .is_active(&remove_rounding_in_fee_calculation::ID), + enable_secp256r1_precompile: feature_set.is_active(&enable_secp256r1_precompile::ID), } } } @@ -50,7 +54,11 @@ pub fn calculate_fee_details( } FeeDetails::new( - calculate_signature_fee(SignatureCounts::from(message), lamports_per_signature), + calculate_signature_fee( + SignatureCounts::from(message), + lamports_per_signature, + fee_features.enable_secp256r1_precompile, + ), prioritization_fee, fee_features.remove_rounding_in_fee_calculation, ) @@ -62,13 +70,17 @@ fn calculate_signature_fee( num_transaction_signatures, num_ed25519_signatures, num_secp256k1_signatures, + num_secp256r1_signatures, }: SignatureCounts, lamports_per_signature: u64, + enable_secp256r1_precompile: bool, ) -> u64 { let signature_count = num_transaction_signatures .saturating_add(num_ed25519_signatures) - .saturating_add(num_secp256k1_signatures); - + .saturating_add(num_secp256k1_signatures) + .saturating_add( + u64::from(enable_secp256r1_precompile).wrapping_mul(num_secp256r1_signatures), + ); signature_count.saturating_mul(lamports_per_signature) } @@ -76,6 +88,7 @@ struct SignatureCounts { pub num_transaction_signatures: u64, pub num_ed25519_signatures: u64, pub num_secp256k1_signatures: u64, + pub num_secp256r1_signatures: u64, } impl From<&Tx> for SignatureCounts { @@ -84,6 +97,7 @@ impl From<&Tx> for SignatureCounts { num_transaction_signatures: message.num_transaction_signatures(), num_ed25519_signatures: message.num_ed25519_signatures(), num_secp256k1_signatures: message.num_secp256k1_signatures(), + num_secp256r1_signatures: message.num_secp256r1_signatures(), } } } @@ -103,8 +117,10 @@ mod tests { num_transaction_signatures: 0, num_ed25519_signatures: 0, num_secp256k1_signatures: 0, + num_secp256r1_signatures: 0, }, LAMPORTS_PER_SIGNATURE, + true, ), 0 ); @@ -116,8 +132,10 @@ mod tests { num_transaction_signatures: 1, num_ed25519_signatures: 0, num_secp256k1_signatures: 0, + num_secp256r1_signatures: 0, }, LAMPORTS_PER_SIGNATURE, + true, ), LAMPORTS_PER_SIGNATURE ); @@ -129,8 +147,25 @@ mod tests { num_transaction_signatures: 1, num_ed25519_signatures: 2, num_secp256k1_signatures: 3, + num_secp256r1_signatures: 4, + }, + LAMPORTS_PER_SIGNATURE, + true, + ), + 10 * LAMPORTS_PER_SIGNATURE + ); + + // Pre-compile signatures (no secp256r1) + assert_eq!( + calculate_signature_fee( + SignatureCounts { + num_transaction_signatures: 1, + num_ed25519_signatures: 2, + num_secp256k1_signatures: 3, + num_secp256r1_signatures: 4, }, LAMPORTS_PER_SIGNATURE, + false, ), 6 * LAMPORTS_PER_SIGNATURE );