Skip to content

Commit

Permalink
fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinheavey committed Apr 21, 2024
1 parent 3c1a8d0 commit 5ef9236
Show file tree
Hide file tree
Showing 23 changed files with 81 additions and 973 deletions.
23 changes: 12 additions & 11 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions curve25519/src/edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct PodEdwardsPoint(pub [u8; 32]);
mod target_arch {
use {
super::*,
crate::curve25519::{
crate::{
curve_syscall_traits::{GroupOperations, MultiScalarMultiplication, PointValidation},
errors::Curve25519Error,
scalar::PodScalar,
Expand Down Expand Up @@ -134,7 +134,7 @@ mod target_arch {
mod target_arch {
use {
super::*,
crate::curve25519::{
crate::{
curve_syscall_traits::{ADD, CURVE25519_EDWARDS, MUL, SUB},
scalar::PodScalar,
},
Expand Down Expand Up @@ -245,7 +245,7 @@ mod target_arch {
mod tests {
use {
super::*,
crate::curve25519::scalar::PodScalar,
crate::scalar::PodScalar,
curve25519_dalek::{
constants::ED25519_BASEPOINT_POINT as G, edwards::EdwardsPoint, traits::Identity,
},
Expand Down
18 changes: 18 additions & 0 deletions curve25519/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,21 @@ 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,
}
6 changes: 3 additions & 3 deletions curve25519/src/ristretto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct PodRistrettoPoint(pub [u8; 32]);
mod target_arch {
use {
super::*,
crate::curve25519::{
crate::{
curve_syscall_traits::{GroupOperations, MultiScalarMultiplication, PointValidation},
errors::Curve25519Error,
scalar::PodScalar,
Expand Down Expand Up @@ -135,7 +135,7 @@ mod target_arch {
mod target_arch {
use {
super::*,
crate::curve25519::{
crate::{
curve_syscall_traits::{ADD, CURVE25519_RISTRETTO, MUL, SUB},
scalar::PodScalar,
},
Expand Down Expand Up @@ -247,7 +247,7 @@ mod target_arch {
mod tests {
use {
super::*,
crate::curve25519::scalar::PodScalar,
crate::scalar::PodScalar,
curve25519_dalek::{
constants::RISTRETTO_BASEPOINT_POINT as G, ristretto::RistrettoPoint, traits::Identity,
},
Expand Down
16 changes: 15 additions & 1 deletion curve25519/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub struct PodScalar(pub [u8; 32]);

#[cfg(not(target_os = "solana"))]
mod target_arch {
use {super::*, crate::curve25519::errors::Curve25519Error, curve25519_dalek::scalar::Scalar};
use {super::*, crate::errors::{Curve25519Error, ElGamalError}, curve25519_dalek::scalar::Scalar};

impl From<&Scalar> for PodScalar {
fn from(scalar: &Scalar) -> Self {
Expand All @@ -21,4 +21,18 @@ mod target_arch {
Scalar::from_canonical_bytes(pod.0).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).ok_or(ElGamalError::CiphertextDeserialization)
}
}
}
18 changes: 9 additions & 9 deletions programs/bpf_loader/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ declare_builtin_function!(
_arg5: u64,
memory_mapping: &mut MemoryMapping,
) -> Result<u64, Error> {
use solana_zk_token_sdk::curve25519::{curve_syscall_traits::*, edwards, ristretto};
use solana_curve25519::{curve_syscall_traits::*, edwards, ristretto};
match curve_id {
CURVE25519_EDWARDS => {
let cost = invoke_context
Expand Down Expand Up @@ -935,7 +935,7 @@ declare_builtin_function!(
result_point_addr: u64,
memory_mapping: &mut MemoryMapping,
) -> Result<u64, Error> {
use solana_zk_token_sdk::curve25519::{
use solana_curve25519::{
curve_syscall_traits::*, edwards, ristretto, scalar,
};
match curve_id {
Expand Down Expand Up @@ -1136,7 +1136,7 @@ declare_builtin_function!(
result_point_addr: u64,
memory_mapping: &mut MemoryMapping,
) -> Result<u64, Error> {
use solana_zk_token_sdk::curve25519::{
use solana_curve25519::{
curve_syscall_traits::*, edwards, ristretto, scalar,
};

Expand Down Expand Up @@ -2621,7 +2621,7 @@ mod tests {

#[test]
fn test_syscall_edwards_curve_point_validation() {
use solana_zk_token_sdk::curve25519::curve_syscall_traits::CURVE25519_EDWARDS;
use solana_curve25519::curve_syscall_traits::CURVE25519_EDWARDS;

let config = Config::default();
prepare_mockup!(invoke_context, program_id, bpf_loader::id());
Expand Down Expand Up @@ -2694,7 +2694,7 @@ mod tests {

#[test]
fn test_syscall_ristretto_curve_point_validation() {
use solana_zk_token_sdk::curve25519::curve_syscall_traits::CURVE25519_RISTRETTO;
use solana_curve25519::curve_syscall_traits::CURVE25519_RISTRETTO;

let config = Config::default();
prepare_mockup!(invoke_context, program_id, bpf_loader::id());
Expand Down Expand Up @@ -2767,7 +2767,7 @@ mod tests {

#[test]
fn test_syscall_edwards_curve_group_ops() {
use solana_zk_token_sdk::curve25519::curve_syscall_traits::{
use solana_curve25519::curve_syscall_traits::{
ADD, CURVE25519_EDWARDS, MUL, SUB,
};

Expand Down Expand Up @@ -2924,7 +2924,7 @@ mod tests {

#[test]
fn test_syscall_ristretto_curve_group_ops() {
use solana_zk_token_sdk::curve25519::curve_syscall_traits::{
use solana_curve25519::curve_syscall_traits::{
ADD, CURVE25519_RISTRETTO, MUL, SUB,
};

Expand Down Expand Up @@ -3083,7 +3083,7 @@ mod tests {

#[test]
fn test_syscall_multiscalar_multiplication() {
use solana_zk_token_sdk::curve25519::curve_syscall_traits::{
use solana_curve25519::curve_syscall_traits::{
CURVE25519_EDWARDS, CURVE25519_RISTRETTO,
};

Expand Down Expand Up @@ -3191,7 +3191,7 @@ mod tests {

#[test]
fn test_syscall_multiscalar_multiplication_maximum_length_exceeded() {
use solana_zk_token_sdk::curve25519::curve_syscall_traits::{
use solana_curve25519::curve_syscall_traits::{
CURVE25519_EDWARDS, CURVE25519_RISTRETTO,
};

Expand Down
2 changes: 1 addition & 1 deletion programs/sbf/rust/curve25519/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
extern crate solana_program;
use {
solana_program::{custom_heap_default, custom_panic_default, msg},
solana_zk_token_sdk::curve25519::{edwards, ristretto, scalar},
solana_curve25519::{edwards, ristretto, scalar},
};

#[no_mangle]
Expand Down
1 change: 1 addition & 0 deletions zk-token-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ rand = { version = "0.7" }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
sha3 = "0.9"
solana-curve25519 = { workspace = true }
solana-sdk = { workspace = true }
subtle = { workspace = true }
zeroize = { workspace = true, features = ["zeroize_derive"] }
Expand Down
85 changes: 0 additions & 85 deletions zk-token-sdk/src/curve25519/curve_syscall_traits.rs

This file was deleted.

Loading

0 comments on commit 5ef9236

Please sign in to comment.