Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace rust_secp256k1 with k256 #3407

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
40 changes: 27 additions & 13 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ rand = { version = "0.8.5", default-features = false }
rand_chacha = { version = "0.3.1", default-features = false }
rand_distr = { version = "0.4.3", default-features = false }
ruzstd = "0.7.1"
k256 = { version = "0.13.4", default-features = false, features = [
"ecdsa", "pem", "sha256", "serde", "arithmetic"
] }
k8s-openapi = { version = "0.21.1", features = ["v1_28"] }
pathdiff = "0.2.1"
kube = "0.88.1"
Expand All @@ -134,7 +137,6 @@ revm-interpreter = { version = "15.1.0", features = [ "serde" ] }
revm-precompile = "16.0.0"
revm-primitives = "15.1.0"
rocksdb = "0.21.0"
secp256k1 = { version = "0.30.0", default-features = false, features = [ "alloc", "rand", "serde" ] }
scylla = "0.15.1"
semver = "1.0.22"
serde = { version = "1.0.197", features = ["derive"] }
Expand Down
47 changes: 26 additions & 21 deletions examples/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 linera-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ futures.workspace = true
getrandom = { workspace = true, optional = true }
hex.workspace = true
is-terminal.workspace = true
k256.workspace = true
linera-witty = { workspace = true, features = ["macros"] }
prometheus = { workspace = true, optional = true }
proptest = { workspace = true, optional = true, features = ["alloc"] }
rand.workspace = true
reqwest = { workspace = true, optional = true }
secp256k1.workspace = true
serde.workspace = true
serde-name.workspace = true
serde_bytes.workspace = true
Expand Down
6 changes: 5 additions & 1 deletion linera-base/src/crypto/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ impl TryFrom<&[u8]> for Ed25519PublicKey {

fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
if value.len() != dalek::PUBLIC_KEY_LENGTH {
return Err(CryptoError::IncorrectPublicKeySize(value.len()));
return Err(CryptoError::IncorrectPublicKeySize {
scheme: "Ed25519".to_string(),
len: value.len(),
expected: dalek::PUBLIC_KEY_LENGTH,
});
}
let mut pubkey = [0u8; dalek::PUBLIC_KEY_LENGTH];
pubkey.copy_from_slice(value);
Expand Down
14 changes: 9 additions & 5 deletions linera-base/src/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ mod secp256k1;
use std::{io, num::ParseIntError};

use alloy_primitives::FixedBytes;
use ed25519_dalek::{self as dalek};
pub use hash::*;
use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -50,14 +49,19 @@ pub enum CryptoError {
)]
IncorrectHashSize(usize),
#[error(
"Byte slice has length {0} but a `PublicKey` requires exactly {expected} bytes",
expected = dalek::PUBLIC_KEY_LENGTH,
"Byte slice has length {len} but a {scheme} `PublicKey` requires exactly {expected} bytes"
)]
IncorrectPublicKeySize(usize),
IncorrectPublicKeySize {
scheme: String,
len: usize,
expected: usize,
},
#[error("Could not parse integer: {0}")]
ParseIntError(#[from] ParseIntError),
#[error("secp256k1 error: {0}")]
Secp256k1Error(::secp256k1::Error),
Secp256k1Error(k256::ecdsa::Error),
#[error("could not parse public key: {0}: key point at inifinity.")]
Secp256k1PointAtIfinity(String),
Comment on lines +62 to +64
Copy link
Contributor

@Twey Twey Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Secp256k1Error(k256::ecdsa::Error),
#[error("could not parse public key: {0}: key point at inifinity.")]
Secp256k1PointAtIfinity(String),
#[error("could not parse public key `{0}`: point at infinity")]
Secp256k1PointAtInfinity(String),

(re-commenting suggestion since it was partially applied, which breaks the accept feature)

}

#[cfg(with_getrandom)]
Expand Down
Loading