From 6fe7c6b97e71991daf95dceecfb55a0d5bc73841 Mon Sep 17 00:00:00 2001 From: Jack May Date: Thu, 14 Oct 2021 08:52:59 -0700 Subject: [PATCH] charge for ed25519 sig verifies (#20639) --- sdk/program/src/message/sanitized.rs | 41 +++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/sdk/program/src/message/sanitized.rs b/sdk/program/src/message/sanitized.rs index cfaf6218280e00..89764f00d32570 100644 --- a/sdk/program/src/message/sanitized.rs +++ b/sdk/program/src/message/sanitized.rs @@ -6,6 +6,7 @@ use { pubkey::Pubkey, sanitize::{Sanitize, SanitizeError}, secp256k1_program, + ed25519_program, serialize_utils::{append_slice, append_u16, append_u8}, }, bitflags::bitflags, @@ -294,7 +295,7 @@ impl SanitizedMessage { pub fn calculate_fee(&self, lamports_per_signature: u64) -> u64 { let mut num_signatures = u64::from(self.header().num_required_signatures); for (program_id, instruction) in self.program_instructions_iter() { - if secp256k1_program::check_id(program_id) { + if secp256k1_program::check_id(program_id) || ed25519_program::check_id(program_id) { if let Some(num_verifies) = instruction.data.get(0) { num_signatures = num_signatures.saturating_add(u64::from(*num_verifies)); @@ -598,4 +599,42 @@ mod tests { .unwrap(); assert_eq!(message.calculate_fee(1), 11); } + + #[test] + fn test_calculate_fee_ed25519() { + let key0 = Pubkey::new_unique(); + let key1 = Pubkey::new_unique(); + let ix0 = system_instruction::transfer(&key0, &key1, 1); + + let mut instruction1 = Instruction { + program_id: ed25519_program::id(), + accounts: vec![], + data: vec![], + }; + let mut instruction2 = Instruction { + program_id: ed25519_program::id(), + accounts: vec![], + data: vec![1], + }; + + let message = SanitizedMessage::try_from(Message::new( + &[ + ix0.clone(), + instruction1.clone(), + instruction2.clone(), + ], + Some(&key0), + )) + .unwrap(); + assert_eq!(message.calculate_fee(1), 2); + + instruction1.data = vec![0]; + instruction2.data = vec![10]; + let message = SanitizedMessage::try_from(Message::new( + &[ix0, instruction1, instruction2], + Some(&key0), + )) + .unwrap(); + assert_eq!(message.calculate_fee(1), 11); + } }