Skip to content

Commit

Permalink
Use serde instead of unsafe rust
Browse files Browse the repository at this point in the history
We will add some more ergonomic code for conversion to jellyfish at some
point. This code can be used as a stop gap until then.
  • Loading branch information
sveitser committed Nov 27, 2024
1 parent c919dd1 commit 6b8d822
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ark-bn254 = { workspace = true }
ark-ec = { workspace = true }
ark-ed-on-bn254 = { workspace = true }
ark-serialize = { workspace = true }
ark-std = { workspace = true }
async-broadcast = { workspace = true }
async-trait = { workspace = true }
base64-bytes = { workspace = true }
Expand Down
18 changes: 10 additions & 8 deletions types/src/v0/v0_3/stake_table.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use crate::PubKey;
use ark_ec::{bn, short_weierstrass, twisted_edwards};
use ark_ec::{
bn,
short_weierstrass::{self, Projective},
twisted_edwards, AffineRepr,
};
use ark_ed_on_bn254::EdwardsConfig;
use ark_serialize::{CanonicalDeserialize as _, CanonicalSerialize};
use contract_bindings::permissioned_stake_table::{EdOnBN254Point, NodeInfo};
use derive_more::derive::From;
use hotshot_contract_adapter::stake_table::ParsedG1Point;
use hotshot_types::{light_client::StateVerKey, network::PeerConfigKeys};
use jf_utils::to_bytes;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, From)]
Expand All @@ -29,13 +35,9 @@ impl From<NodeInfo> for PermissionedPeerConfig {
y1: bls_vk.y_1,
};
let g2_affine = short_weierstrass::Affine::<ark_bn254::g2::Config>::from(g2);
// TODO: maybe this works until I find a better way
let g2_proj = bn::G2Projective::<ark_bn254::Config>::from(g2_affine);
unsafe {
std::mem::transmute::<short_weierstrass::Projective<ark_bn254::g2::Config>, PubKey>(
g2_proj,
)
}
// TODO: remove unwrap
let b = to_bytes!(&g2_affine.into_group()).unwrap();
PubKey::deserialize_compressed(&b[..]).unwrap()
};
let state_ver_key = {
let EdOnBN254Point { x, y } = schnorr_vk;
Expand Down

0 comments on commit 6b8d822

Please sign in to comment.