Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .config/spellcheck.dic
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
33
34
19AM
CPI
Cofactorless
Expand All @@ -16,10 +16,10 @@ cofactor
cofactored
cofactorless
cryptographic
dalek
dalek's
dalek/M
de
deserializes
doublings
ed25519
encodings
entrypoint
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ serde = { version = "1.0.228", default-features = false }
serde_derive = "1.0.228"
solana-account = "3.4.0"
solana-curve25519 = "4.0.1"
solana-ed25519-verify = { path = "ed25519-verify", version = "4.0.0", default-features = false }
solana-ed25519-verify = { path = "ed25519-verify", version = "0.1.0", default-features = false }
solana-instruction = "3.3.0"
solana-program-error = "3.0.1"
solana-program-runtime = { version = "4.0.0", features = ["agave-unstable-api"] }
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ The program verifies a single signature. Instruction data is:
[96 ..] message
```

The `ed25519_verify_instruction` helper in `solana-ed25519-verify` builds this
layout.
The `verify` helper in `solana-ed25519-verify` builds this layout.

### Constraints

Expand Down
2 changes: 1 addition & 1 deletion ed25519-verify/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "solana-ed25519-verify"
version = "4.0.0"
version = "0.1.0"
edition = "2021"

[lib]
Expand Down
6 changes: 0 additions & 6 deletions ed25519-verify/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,3 @@ impl VerificationCriteria {
}
}
}

impl Default for VerificationCriteria {
fn default() -> Self {
Self::zip215()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate alloc;

use {
crate::{PUBKEY_SERIALIZED_SIZE, SIGNATURE_SERIALIZED_SIZE},
alloc::{vec, vec::Vec},
Expand All @@ -13,7 +11,7 @@ use {
/// verifies the signature under the [ZIP-215] criteria.
///
/// [ZIP-215]: crate::VerificationCriteria::zip215
pub fn ed25519_verify_instruction(
pub fn verify(
program_id: &Pubkey,
public_key: &[u8; PUBKEY_SERIALIZED_SIZE],
signature: &[u8; SIGNATURE_SERIALIZED_SIZE],
Expand Down
4 changes: 2 additions & 2 deletions ed25519-verify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ extern crate alloc;

mod config;
#[cfg(feature = "instruction")]
pub mod program;
pub mod instruction;
mod scalar;
mod verifier;

pub use config::VerificationCriteria;
#[cfg(feature = "instruction")]
pub use program::ed25519_verify_instruction;
pub use instruction::verify;
pub use verifier::Ed25519Verifier;

pub const PUBKEY_SERIALIZED_SIZE: usize = 32;
Expand Down
8 changes: 7 additions & 1 deletion ed25519-verify/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ const EDWARDS_IDENTITY_COMPRESSED: PodEdwardsPoint =
/// The verification behavior is selected by [`VerificationCriteria`]. A verifier
/// created with [`Ed25519Verifier::new`] uses the [`VerificationCriteria::zip215`]
/// preset, matching this crate's historical behavior.
#[derive(Debug, Clone, Copy, Default)]
#[derive(Debug, Clone, Copy)]
pub struct Ed25519Verifier {
criteria: VerificationCriteria,
}

impl Default for Ed25519Verifier {
fn default() -> Self {
Self::new()
}
}

impl Ed25519Verifier {
/// Initializes a verifier using the default [ZIP-215] criteria.
///
Expand Down
8 changes: 2 additions & 6 deletions ed25519-verify/tests/verify_instruction.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {
ed25519_dalek::{Signature, Signer, SigningKey, VerifyingKey},
solana_ed25519_verify::{
ed25519_verify_instruction, Ed25519Verifier, VerificationCriteria, PUBKEY_SERIALIZED_SIZE,
verify, Ed25519Verifier, VerificationCriteria, PUBKEY_SERIALIZED_SIZE,
SIGNATURE_SERIALIZED_SIZE,
},
solana_program_error::ProgramError,
Expand Down Expand Up @@ -58,7 +58,7 @@ fn constructs_program_instruction_with_direct_layout() {
let message = b"hello ed25519";
let (signature, public_key) = signed_payload(message);

let instruction = ed25519_verify_instruction(&program_id, &public_key, &signature, message);
let instruction = verify(&program_id, &public_key, &signature, message);

const PUBKEY_START: usize = 0;
const SIGNATURE_START: usize = PUBKEY_START + PUBKEY_SERIALIZED_SIZE;
Expand Down Expand Up @@ -214,10 +214,6 @@ fn new_uses_zip215_criteria() {
Ed25519Verifier::new().criteria(),
VerificationCriteria::zip215()
);
assert_eq!(
VerificationCriteria::default(),
VerificationCriteria::zip215()
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion program/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "solana-ed25519-program"
version = "4.0.0"
version = "0.1.0"
edition = "2021"

[lib]
Expand Down
9 changes: 4 additions & 5 deletions program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

//! Pinocchio SBF wrapper for [`solana_ed25519_verify`].

#[cfg(not(any(target_os = "solana", target_arch = "bpf")))]
extern crate std;

use {
pinocchio::{
entrypoint::InstructionContext, error::ProgramError, lazy_program_entrypoint, ProgramResult,
Expand Down Expand Up @@ -44,12 +41,14 @@ pub fn process_instruction(context: InstructionContext) -> ProgramResult {
return Err(ProgramError::InvalidInstructionData);
}

// Both ranges are fixed-size and in bounds after the length check above,
// so the conversions to fixed-size arrays cannot fail.
let public_key = instruction_data[PUBKEY_OFFSET..SIGNATURE_OFFSET]
.try_into()
.map_err(|_| ProgramError::InvalidInstructionData)?;
.unwrap();
let signature = instruction_data[SIGNATURE_OFFSET..MESSAGE_OFFSET]
.try_into()
.map_err(|_| ProgramError::InvalidInstructionData)?;
.unwrap();
let message = &instruction_data[MESSAGE_OFFSET..];

Ed25519Verifier::new().verify_signature(signature, public_key, message)
Expand Down
8 changes: 3 additions & 5 deletions program/tests/mollusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use {
ed25519_dalek::{Signer, SigningKey},
mollusk_svm::Mollusk,
solana_account::Account,
solana_ed25519_verify::{
ed25519_verify_instruction, PUBKEY_SERIALIZED_SIZE, SIGNATURE_SERIALIZED_SIZE,
},
solana_ed25519_verify::{verify, PUBKEY_SERIALIZED_SIZE, SIGNATURE_SERIALIZED_SIZE},
solana_instruction::{AccountMeta, Instruction},
solana_program_runtime::{
invoke_context::InvokeContext,
Expand Down Expand Up @@ -155,7 +153,7 @@ fn signed_instruction(program_id: Pubkey, message: &[u8]) -> Instruction {
let signature = signing_key.sign(message).to_bytes();
let public_key = signing_key.verifying_key().to_bytes();

ed25519_verify_instruction(&program_id, &public_key, &signature, message)
verify(&program_id, &public_key, &signature, message)
}

#[test]
Expand Down Expand Up @@ -186,7 +184,7 @@ fn accepts_zip215_small_order_public_key_vector_on_sbf() {
let message = b"zip215 low-order public key vector";
let mut signature = [0; SIGNATURE_SERIALIZED_SIZE];
signature[..EDWARDS_IDENTITY_COMPRESSED.len()].copy_from_slice(&EDWARDS_IDENTITY_COMPRESSED);
let ix = ed25519_verify_instruction(
let ix = verify(
&program_id,
&SMALL_ORDER_PUBLIC_KEY_COMPRESSED,
&signature,
Expand Down
Loading