Skip to content

Commit

Permalink
Use anyhow::Context
Browse files Browse the repository at this point in the history
  • Loading branch information
moshababo committed Nov 2, 2023
1 parent e89656f commit 91b4f64
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bit-vec = "0.6"
blst = "0.3.10"
ark-bn254 = "0.4.0"
ark-ec = "0.4.2"
ark-serialize = "0.4.2"
ark-serialize = { version = "0.4.2", features = ["std"] }
num-traits = "0.2.17"
clap = { version = "4.3.3", features = ["derive"] }
ed25519-dalek = { version = "2.0.0", features = ["serde", "rand_core"] }
Expand Down
1 change: 0 additions & 1 deletion node/libs/crypto/src/bn254/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use ark_bn254::{G1Affine, G1Projective};
use ark_ec::AffineRepr as _;
use sha2::Digest as _;
use tracing::instrument;

/// Hashes an arbitrary message and maps it to an elliptic curve point in G1.
pub(crate) fn hash_to_g1(msg: &[u8]) -> G1Projective {
Expand Down
10 changes: 5 additions & 5 deletions node/libs/crypto/src/bn254/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! BLS signature scheme for the BN254 curve.
use crate::ByteFmt;
use anyhow::anyhow;
use anyhow::Context as _;
use ark_bn254::{Bn254, Fr, G1Projective as G1, G2Projective as G2};
use ark_ec::{
pairing::{Pairing as _, PairingOutput},
Expand Down Expand Up @@ -43,7 +43,7 @@ impl ByteFmt for SecretKey {
fn decode(bytes: &[u8]) -> anyhow::Result<Self> {
Fr::deserialize_compressed(bytes)
.map(Self)
.map_err(|e| anyhow!("failed to decode secret key: {e:?}"))
.context("failed to decode secret key")
}

fn encode(&self) -> Vec<u8> {
Expand All @@ -61,7 +61,7 @@ impl ByteFmt for PublicKey {
fn decode(bytes: &[u8]) -> anyhow::Result<Self> {
G2::deserialize_compressed(bytes)
.map(Self)
.map_err(|e| anyhow!("failed to decode public key: {e:?}"))
.context("failed to decode public key")
}

fn encode(&self) -> Vec<u8> {
Expand Down Expand Up @@ -110,7 +110,7 @@ impl ByteFmt for Signature {
fn decode(bytes: &[u8]) -> anyhow::Result<Self> {
G1::deserialize_compressed(bytes)
.map(Self)
.map_err(|e| anyhow!("failed to decode signature: {e:?}"))
.context("failed to decode signature")
}
fn encode(&self) -> Vec<u8> {
let mut buf = Vec::new();
Expand Down Expand Up @@ -184,7 +184,7 @@ impl ByteFmt for AggregateSignature {
fn decode(bytes: &[u8]) -> anyhow::Result<Self> {
G1::deserialize_compressed(bytes)
.map(Self)
.map_err(|e| anyhow!("failed to decode aggregate signature: {e:?}"))
.context("failed to decode aggregate signature")
}

fn encode(&self) -> Vec<u8> {
Expand Down
6 changes: 4 additions & 2 deletions node/libs/crypto/src/bn254/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::bn254::{AggregateSignature, PublicKey, SecretKey, Signature};
use rand::{rngs::StdRng, Rng, SeedableRng};
use std::iter::repeat_with;

use rand::{rngs::StdRng, Rng, SeedableRng};

use crate::bn254::{AggregateSignature, PublicKey, SecretKey, Signature};

#[test]
fn signature_smoke() {
let mut rng = StdRng::seed_from_u64(29483920);
Expand Down

0 comments on commit 91b4f64

Please sign in to comment.