Skip to content

Commit

Permalink
secp256r1 signatures count towards fee - behind feature
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Jan 16, 2025
1 parent 36c2fdd commit e59bf5a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
43 changes: 39 additions & 4 deletions fee/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand All @@ -9,13 +11,15 @@ use {
#[derive(Copy, Clone)]
pub struct FeeFeatures {
pub remove_rounding_in_fee_calculation: bool,
pub enable_secp256r1_precompile: bool,
}

impl From<&FeatureSet> for FeeFeatures {
fn from(feature_set: &FeatureSet) -> Self {
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),
}
}
}
Expand Down Expand Up @@ -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,
)
Expand All @@ -62,20 +70,25 @@ 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)
}

struct SignatureCounts {
pub num_transaction_signatures: u64,
pub num_ed25519_signatures: u64,
pub num_secp256k1_signatures: u64,
pub num_secp256r1_signatures: u64,
}

impl<Tx: SVMMessage> From<&Tx> for SignatureCounts {
Expand All @@ -84,6 +97,7 @@ impl<Tx: SVMMessage> 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(),
}
}
}
Expand All @@ -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
);
Expand All @@ -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
);
Expand All @@ -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
);
Expand Down
1 change: 1 addition & 0 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10390,6 +10390,7 @@ fn calculate_test_fee(
fee_budget_limits.prioritization_fee,
FeeFeatures {
remove_rounding_in_fee_calculation: true,
enable_secp256r1_precompile: true,
},
)
}
Expand Down

0 comments on commit e59bf5a

Please sign in to comment.