forked from anza-xyz/agave
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract curve25519 crate from zk-token-sdk (anza-xyz#951)
* extract curve25519 crate * remove obsolete comment * fix Cargo.toml files * fix imports * update lock file * remove unused deps from zk-token-sdk * fmt * add solana-curve25519 patch * add missing override to programs/sbf/Cargo.toml * copy over an allow() * move new crate to curves dir * use workspace version * add back missing dev dep * add missing dependencies to programs/sbf * fmt * move dep to the correct dependency table * remove #[cfg(not(target_os = "solana"))] above errors mod
- Loading branch information
1 parent
7f91aec
commit 674b346
Showing
29 changed files
with
167 additions
and
144 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/farf/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "solana-curve25519" | ||
description = "Solana Curve25519 Syscalls" | ||
documentation = "https://docs.rs/solana-curve25519" | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
repository = { workspace = true } | ||
homepage = { workspace = true } | ||
license = { workspace = true } | ||
edition = { workspace = true } | ||
|
||
[dependencies] | ||
bytemuck = { workspace = true, features = ["derive"] } | ||
solana-program = { workspace = true } | ||
thiserror = { workspace = true } | ||
|
||
[target.'cfg(not(target_os = "solana"))'.dependencies] | ||
curve25519-dalek = { workspace = true, features = ["serde"] } |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Clone, Debug, Eq, PartialEq)] | ||
pub enum Curve25519Error { | ||
#[error("pod conversion failed")] | ||
PodConversion, | ||
} | ||
|
||
#[derive(Error, Clone, Debug, Eq, PartialEq)] | ||
pub enum ElGamalError { | ||
#[error("key derivation method not supported")] | ||
DerivationMethodNotSupported, | ||
#[error("seed length too short for derivation")] | ||
SeedLengthTooShort, | ||
#[error("seed length too long for derivation")] | ||
SeedLengthTooLong, | ||
#[error("failed to deserialize ciphertext")] | ||
CiphertextDeserialization, | ||
#[error("failed to deserialize public key")] | ||
PubkeyDeserialization, | ||
#[error("failed to deserialize keypair")] | ||
KeypairDeserialization, | ||
#[error("failed to deserialize secret key")] | ||
SecretKeyDeserialization, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![allow(clippy::arithmetic_side_effects, clippy::op_ref)] | ||
//! Syscall operations for curve25519 | ||
pub mod curve_syscall_traits; | ||
pub mod edwards; | ||
pub mod errors; | ||
pub mod ristretto; | ||
pub mod scalar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
pub use bytemuck::{Pod, Zeroable}; | ||
|
||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Pod, Zeroable)] | ||
#[repr(transparent)] | ||
pub struct PodScalar(pub [u8; 32]); | ||
|
||
#[cfg(not(target_os = "solana"))] | ||
mod target_arch { | ||
use { | ||
super::*, | ||
crate::errors::{Curve25519Error, ElGamalError}, | ||
curve25519_dalek::scalar::Scalar, | ||
}; | ||
|
||
impl From<&Scalar> for PodScalar { | ||
fn from(scalar: &Scalar) -> Self { | ||
Self(scalar.to_bytes()) | ||
} | ||
} | ||
|
||
impl TryFrom<&PodScalar> for Scalar { | ||
type Error = Curve25519Error; | ||
|
||
fn try_from(pod: &PodScalar) -> Result<Self, Self::Error> { | ||
Option::from(Scalar::from_canonical_bytes(pod.0)) | ||
.into_option() | ||
.ok_or(Curve25519Error::PodConversion) | ||
} | ||
} | ||
|
||
impl From<Scalar> for PodScalar { | ||
fn from(scalar: Scalar) -> Self { | ||
Self(scalar.to_bytes()) | ||
} | ||
} | ||
|
||
impl TryFrom<PodScalar> for Scalar { | ||
type Error = ElGamalError; | ||
|
||
fn try_from(pod: PodScalar) -> Result<Self, Self::Error> { | ||
Scalar::from_canonical_bytes(pod.0) | ||
.into_option() | ||
.ok_or(ElGamalError::CiphertextDeserialization) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.