Skip to content

Commit

Permalink
Merge branch 'tomas/k256' (#1958)
Browse files Browse the repository at this point in the history
* origin/tomas/k256:
  changelog: add #1958
  deps: switch to use libseck256k1 to k256
  • Loading branch information
Fraccaman committed Oct 23, 2023
2 parents dcc29fc + 7e4e922 commit d0756d6
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 381 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/miscellaneous/1958-k256.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Switched from using `libsecp256k1` to `k256` crate.
([\#1958](https://github.com/anoma/namada/pull/1958))
79 changes: 19 additions & 60 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 @@ -86,10 +86,10 @@ git2 = "0.13.25"
ics23 = "0.9.0"
index-set = {git = "https://github.com/heliaxdev/index-set", tag = "v0.7.1", features = ["serialize-borsh", "serialize-serde"]}
itertools = "0.10.0"
k256 = { version = "0.13.0", default-features = false, features = ["ecdsa", "pkcs8", "precomputed-tables", "serde", "std"]}
lazy_static = "1.4.0"
libc = "0.2.97"
libloading = "0.7.2"
libsecp256k1 = {git = "https://github.com/heliaxdev/libsecp256k1", rev = "bbb3bd44a49db361f21d9db80f9a087c194c0ae9", default-features = false, features = ["std", "static-context"]}
# branch = "murisi/namada-integration"
masp_primitives = { git = "https://github.com/anoma/masp", rev = "50acc5028fbcd52a05970fe7991c7850ab04358e" }
masp_proofs = { git = "https://github.com/anoma/masp", rev = "50acc5028fbcd52a05970fe7991c7850ab04358e", default-features = false, features = ["local-prover"] }
Expand Down
6 changes: 3 additions & 3 deletions apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1617,11 +1617,11 @@ mod test_utils {
ref sig,
ref recovery_id,
)) => {
let mut sig_bytes = sig.serialize();
let recovery_id_bytes = recovery_id.serialize();
let mut sig_bytes = sig.to_vec();
let recovery_id_bytes = recovery_id.to_byte();
sig_bytes[0] = sig_bytes[0].wrapping_add(1);
let bytes: [u8; 65] =
[sig_bytes.as_slice(), [recovery_id_bytes].as_slice()]
[sig_bytes.as_slice(), &[recovery_id_bytes]]
.concat()
.try_into()
.unwrap();
Expand Down
8 changes: 1 addition & 7 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ ferveo-tpke = [
wasm-runtime = [
"rayon",
]
# secp256k1 key signing, disabled in WASM build by default as it bloats the
# build a lot
secp256k1-sign = [
"libsecp256k1/hmac",
]

abciplus = [
"ibc",
Expand Down Expand Up @@ -78,7 +73,7 @@ ics23.workspace = true
impl-num-traits = "0.1.2"
index-set.workspace = true
itertools.workspace = true
libsecp256k1.workspace = true
k256.workspace = true
masp_primitives.workspace = true
num256.workspace = true
num-integer = "0.1.45"
Expand All @@ -104,7 +99,6 @@ zeroize.workspace = true

[dev-dependencies]
assert_matches.workspace = true
libsecp256k1 = {workspace = true, features = ["hmac"]}
pretty_assertions.workspace = true
proptest.workspace = true
rand.workspace = true
Expand Down
16 changes: 7 additions & 9 deletions core/src/types/key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,17 +692,15 @@ mod more_tests {
fn zeroize_keypair_secp256k1() {
use rand::thread_rng;

let mut sk = secp256k1::SigScheme::generate(&mut thread_rng());
let sk_scalar = sk.0.to_scalar_ref();
let len = sk_scalar.0.len();
let ptr = sk_scalar.0.as_ref().as_ptr();

let original_data = sk_scalar.0;

let sk = secp256k1::SigScheme::generate(&mut thread_rng());
let (ptr, original_data) = {
let sk_scalar = sk.0.as_scalar_primitive().as_ref();
(sk_scalar.as_ptr(), sk_scalar.to_owned())
};
drop(sk);

assert_ne!(&original_data, unsafe {
core::slice::from_raw_parts(ptr, len)
assert_ne!(original_data.as_slice(), unsafe {
core::slice::from_raw_parts(ptr, secp256k1::SECRET_KEY_SIZE)
});
}
}
Loading

0 comments on commit d0756d6

Please sign in to comment.