Skip to content

Commit

Permalink
linting: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
0xRigel committed Jan 4, 2024
1 parent f327432 commit 8c215c0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
1 change: 0 additions & 1 deletion sdk/program/src/secp256r1_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
//!
//! [np]:

crate::declare_id!("Secp256r1SigVerify1111111111111111111111111");
8 changes: 4 additions & 4 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ pub use solana_program::{
fee_calculator, impl_sysvar_get, incinerator, instruction, keccak, lamports,
loader_instruction, loader_upgradeable_instruction, loader_v4, loader_v4_instruction, message,
msg, native_token, nonce, poseidon, program, program_error, program_memory, program_option,
program_pack, rent, sanitize, sdk_ids, secp256k1_program, secp256k1_recover,secp256r1_program, serde_varint,
serialize_utils, short_vec, slot_hashes, slot_history, stable_layout, stake, stake_history,
syscalls, system_instruction, system_program, sysvar, unchecked_div_by_const, vote,
wasm_bindgen,
program_pack, rent, sanitize, sdk_ids, secp256k1_program, secp256k1_recover, secp256r1_program,
serde_varint, serialize_utils, short_vec, slot_hashes, slot_history, stable_layout, stake,
stake_history, syscalls, system_instruction, system_program, sysvar, unchecked_div_by_const,
vote, wasm_bindgen,
};

pub mod account;
Expand Down
32 changes: 18 additions & 14 deletions sdk/src/secp256r1_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ use {
crate::{feature_set::FeatureSet, instruction::Instruction, precompiles::PrecompileError},
bytemuck::{bytes_of, Pod, Zeroable},
p256::{
ecdsa::{SigningKey, Signature, VerifyingKey, signature::{Signer, Verifier}},
elliptic_curve::IsHigh
}
ecdsa::{
signature::{Signer, Verifier},
Signature, SigningKey, VerifyingKey,
},
elliptic_curve::IsHigh,
},
};

pub const COMPRESSED_PUBKEY_SERIALIZED_SIZE: usize = 33;
Expand All @@ -23,13 +26,13 @@ pub const DATA_START: usize = SIGNATURE_OFFSETS_SERIALIZED_SIZE + SIGNATURE_OFFS
#[derive(Default, Debug, Copy, Clone, Zeroable, Pod, Eq, PartialEq)]
#[repr(C)]
pub struct Secp256r1SignatureOffsets {
signature_offset: u16, // offset to compact secp256r1 signature of 64 bytes
signature_instruction_index: u16, // instruction index to find signature
public_key_offset: u16, // offset to compressed public key of 33 bytes
signature_offset: u16, // offset to compact secp256r1 signature of 64 bytes
signature_instruction_index: u16, // instruction index to find signature
public_key_offset: u16, // offset to compressed public key of 33 bytes
public_key_instruction_index: u16, // instruction index to find public key
message_data_offset: u16, // offset to start of message data
message_data_size: u16, // size of message data
message_instruction_index: u16, // index of instruction data to get message data
message_data_offset: u16, // offset to start of message data
message_data_size: u16, // size of message data
message_instruction_index: u16, // index of instruction data to get message data
}

pub fn new_secp256r1_instruction(signer: &SigningKey, message: &[u8]) -> Instruction {
Expand Down Expand Up @@ -130,7 +133,7 @@ pub fn verify(
instruction_datas,
offsets.public_key_instruction_index,
offsets.public_key_offset,
COMPRESSED_PUBKEY_SERIALIZED_SIZE
COMPRESSED_PUBKEY_SERIALIZED_SIZE,
)?;

// Parse out message
Expand All @@ -143,7 +146,7 @@ pub fn verify(
)?;

let signature =
Signature::try_from(signature).map_err(|_| PrecompileError::InvalidSignature)?;
Signature::try_from(signature).map_err(|_| PrecompileError::InvalidSignature)?;

// Enforce Low-S
if signature.s().is_high().into() {
Expand All @@ -153,7 +156,8 @@ pub fn verify(
let publickey = p256::ecdsa::VerifyingKey::from_sec1_bytes(pubkey)
.map_err(|_| PrecompileError::InvalidPublicKey)?;

publickey.verify(message, &signature)
publickey
.verify(message, &signature)
.map_err(|_| PrecompileError::InvalidSignature)?;
}
Ok(())
Expand Down Expand Up @@ -190,9 +194,9 @@ pub mod test {
use {
super::*,
crate::{
secp256r1_instruction::new_secp256r1_instruction,
feature_set::FeatureSet,
hash::Hash,
secp256r1_instruction::new_secp256r1_instruction,
signature::{Keypair, Signer},
transaction::Transaction,
},
Expand Down Expand Up @@ -385,4 +389,4 @@ pub mod test {
);
assert!(tx.verify_precompiles(&feature_set).is_err());
}
}
}

0 comments on commit 8c215c0

Please sign in to comment.