solana_secp256k1_program/
lib.rs1use safecoin_sdk::{
2 instruction::InstructionError, process_instruction::InvokeContext, pubkey::Pubkey,
3};
4
5pub fn process_instruction(
6 _program_id: &Pubkey,
7 _data: &[u8],
8 _invoke_context: &mut dyn InvokeContext,
9) -> Result<(), InstructionError> {
10 Ok(())
12}
13
14#[cfg(test)]
15pub mod test {
16 use {
17 rand::{thread_rng, Rng},
18 safecoin_sdk::{
19 feature_set,
20 hash::Hash,
21 secp256k1_instruction::{
22 new_secp256k1_instruction, SecpSignatureOffsets, SIGNATURE_OFFSETS_SERIALIZED_SIZE,
23 },
24 signature::{Keypair, Signer},
25 transaction::Transaction,
26 },
27 std::sync::Arc,
28 };
29
30 #[test]
31 fn test_secp256k1() {
32 solana_logger::setup();
33 let offsets = SecpSignatureOffsets::default();
34 assert_eq!(
35 bincode::serialized_size(&offsets).unwrap() as usize,
36 SIGNATURE_OFFSETS_SERIALIZED_SIZE
37 );
38
39 let secp_privkey = libsecp256k1::SecretKey::random(&mut thread_rng());
40 let message_arr = b"hello";
41 let mut secp_instruction = new_secp256k1_instruction(&secp_privkey, message_arr);
42 let mint_keypair = Keypair::new();
43 let mut feature_set = feature_set::FeatureSet::all_enabled();
44 feature_set
45 .active
46 .remove(&feature_set::libsecp256k1_0_5_upgrade_enabled::id());
47 feature_set
48 .inactive
49 .insert(feature_set::libsecp256k1_0_5_upgrade_enabled::id());
50 let feature_set = Arc::new(feature_set);
51
52 let tx = Transaction::new_signed_with_payer(
53 &[secp_instruction.clone()],
54 Some(&mint_keypair.pubkey()),
55 &[&mint_keypair],
56 Hash::default(),
57 );
58
59 assert!(tx.verify_precompiles(&feature_set).is_ok());
60
61 let index = thread_rng().gen_range(0, secp_instruction.data.len());
62 secp_instruction.data[index] = secp_instruction.data[index].wrapping_add(12);
63 let tx = Transaction::new_signed_with_payer(
64 &[secp_instruction],
65 Some(&mint_keypair.pubkey()),
66 &[&mint_keypair],
67 Hash::default(),
68 );
69 assert!(tx.verify_precompiles(&feature_set).is_err());
70 }
71}