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

remove byteorder dependency #807

Open
wants to merge 1 commit into
base: develop
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
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ serde_with = { version = "3.11.0", default-features = false, features = [
] }
rand = "0.8.5"
bytes = { version = "1.1", default-features = false }
byteorder = "1"
futures = "0.3"
tokio = { version = "1.15.0", features = ["full"] }
tokio-stream = { version = "0.1.8", features = ["sync", "time"] }
Expand Down
1 change: 0 additions & 1 deletion ergo-chain-generation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ edition.workspace = true
[dependencies]
base16 = { workspace = true }
blake2 = { workspace = true }
byteorder = { workspace = true }
ergo-lib = { workspace = true }
num-bigint = { workspace = true }
rand = { workspace = true }
Expand Down
16 changes: 4 additions & 12 deletions ergo-chain-generation/src/chain_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ fn prove_block(
let x = DlogProverInput::random();
let x_bigint = BigInt::from_bytes_be(Sign::Plus, &x.to_bytes());

use byteorder::{BigEndian, WriteBytesExt};
let mut height_bytes = Vec::with_capacity(4);
#[allow(clippy::unwrap_used)]
height_bytes.write_u32::<BigEndian>(header.height).unwrap();
let height_bytes = header.height.to_be_bytes().to_vec();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you remove to_vec here as well?

let popow_algos = ergo_nipopow::NipopowAlgos::default();
let big_n = popow_algos.pow_scheme.calc_big_n(version, height);

Expand All @@ -217,11 +214,7 @@ fn prove_block(
let p1 = sk.public_image_bytes().unwrap();
let p2 = x.public_image().h.sigma_serialize_bytes().unwrap();
for i in min_nonce..max_nonce {
let nonce = {
let mut bytes = vec![];
bytes.write_i64::<BigEndian>(i).unwrap();
bytes
};
let nonce = i.to_be_bytes();
let seed_hash = if version == 1 {
let mut seed = msg.clone();
seed.extend(&nonce);
Expand All @@ -238,8 +231,7 @@ fn prove_block(
.gen_indexes(&seed_hash, big_n)
.into_iter()
.map(|ix| {
let mut index_bytes = vec![];
index_bytes.write_u32::<BigEndian>(ix).unwrap();
let index_bytes = ix.to_be_bytes();
generate_element(version, &msg, &p1, &p2, &index_bytes, &height_bytes)
})
.fold(BigInt::from(0_u8), |acc, e| acc + e);
Expand All @@ -253,7 +245,7 @@ fn prove_block(
let autolykos_solution = AutolykosSolution {
miner_pk: sk.public_key().unwrap().public_key.into(),
pow_onetime_pk: Some(x.public_image().h),
nonce,
nonce: nonce.to_vec(),
pow_distance: Some(d),
};
// Compute header ID
Expand Down
1 change: 0 additions & 1 deletion ergo-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ ergo-merkle-tree = { workspace = true, features = ["arbitrary"] }
sigma-test-util = { workspace = true }
pretty_assertions = { workspace = true }
bs58 = { workspace = true }
byteorder = { workspace = true }
expect-test = { workspace = true }


Expand Down
1 change: 0 additions & 1 deletion ergo-nipopow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
base16 = { workspace = true }
bounded-integer = { workspace = true }
byteorder = { workspace = true }
thiserror = { workspace = true }
derive_more = { workspace = true }
ergotree-ir = { workspace = true, features = ["json"] }
Expand Down
18 changes: 3 additions & 15 deletions ergo-nipopow/src/autolykos_pow_scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ impl AutolykosPowScheme {
.cloned()
.ok_or(AutolykosPowSchemeError::MissingPowDistanceParameter)
} else {
use byteorder::{BigEndian, WriteBytesExt};
// hit for version 2
let msg = blake2b256_hash(&header.serialize_without_pow()?).to_vec();
let nonce = header.autolykos_solution.nonce.clone();
let mut height_bytes = Vec::with_capacity(4);
#[allow(clippy::unwrap_used)]
height_bytes.write_u32::<BigEndian>(header.height).unwrap();
let height_bytes = header.height.to_be_bytes();

let mut concat = msg.clone();
concat.extend(&nonce);
Expand All @@ -56,8 +53,7 @@ impl AutolykosPowScheme {
let f2 = indexes.into_iter().fold(BigInt::from(0u32), |acc, idx| {
// This is specific to autolykos v2.
let mut concat = vec![];
#[allow(clippy::unwrap_used)]
concat.write_u32::<BigEndian>(idx).unwrap();
concat.extend_from_slice(&idx.to_be_bytes());
concat.extend(&height_bytes);
concat.extend(&self.calc_big_m());
acc + BigInt::from_bytes_be(Sign::Plus, &blake2b256_hash(&concat)[1..])
Expand All @@ -72,15 +68,7 @@ impl AutolykosPowScheme {

/// Constant data to be added to hash function to increase its calculation time
pub fn calc_big_m(&self) -> Vec<u8> {
use byteorder::{BigEndian, WriteBytesExt};
(0u64..1024)
.flat_map(|x| {
let mut bytes = Vec::with_capacity(8);
#[allow(clippy::unwrap_used)]
bytes.write_u64::<BigEndian>(x).unwrap();
bytes
})
.collect()
(0u64..1024).flat_map(|x| x.to_be_bytes()).collect()
}

/// Computes `J` (denoted by `seed` in Ergo implementation) line 4, algorithm 1 of Autolykos v2
Expand Down
Loading