From 9d9e2b43f29475aad3e4d29872d72c6610edef22 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 2 Jul 2019 15:06:27 +0800 Subject: [PATCH] ethcore does not use byteorder (#10829) --- Cargo.lock | 1 - ethcore/Cargo.toml | 1 - ethcore/src/builtin.rs | 5 +++-- ethcore/src/lib.rs | 1 - ethcore/src/state_db.rs | 17 +++++++++-------- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1a5bcda70..3bf2f113f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -867,7 +867,6 @@ dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "blooms-db 0.1.0", "bn 0.4.4 (git+https://github.com/paritytech/bn)", - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "common-types 0.1.0", "criterion 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 9296f10b1..9c315fffb 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -10,7 +10,6 @@ authors = ["Parity Technologies "] ansi_term = "0.11" blooms-db = { path = "../util/blooms-db", optional = true } bn = { git = "https://github.com/paritytech/bn", default-features = false } -byteorder = "1.0" common-types = { path = "types" } crossbeam = "0.4" derive_more = "0.14.0" diff --git a/ethcore/src/builtin.rs b/ethcore/src/builtin.rs index bae1c75da..6a52c9cdd 100644 --- a/ethcore/src/builtin.rs +++ b/ethcore/src/builtin.rs @@ -19,7 +19,6 @@ use std::cmp::{max, min}; use std::io::{self, Read}; -use byteorder::{ByteOrder, BigEndian}; use parity_crypto::digest; use num::{BigUint, Zero, One}; @@ -369,7 +368,9 @@ impl Impl for ModexpImpl { // but so would running out of addressable memory! let mut read_len = |reader: &mut io::Chain<&[u8], io::Repeat>| { reader.read_exact(&mut buf[..]).expect("reading from zero-extended memory cannot fail; qed"); - BigEndian::read_u64(&buf[24..]) as usize + let mut len_bytes = [0u8; 8]; + len_bytes.copy_from_slice(&buf[24..]); + u64::from_be_bytes(len_bytes) as usize }; let base_len = read_len(&mut reader); diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 254b6bed7..a0ee0c2d7 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -55,7 +55,6 @@ extern crate ansi_term; extern crate bn; -extern crate byteorder; extern crate common_types as types; extern crate crossbeam; extern crate ethabi; diff --git a/ethcore/src/state_db.rs b/ethcore/src/state_db.rs index 132677ab5..cb00d2132 100644 --- a/ethcore/src/state_db.rs +++ b/ethcore/src/state_db.rs @@ -21,7 +21,6 @@ use std::io; use std::sync::Arc; use bloom_journal::{Bloom, BloomJournal}; -use byteorder::{LittleEndian, ByteOrder}; use db::COL_ACCOUNT_BLOOM; use ethereum_types::{H256, Address}; use hash::keccak; @@ -169,11 +168,15 @@ impl StateDB { let hash_count = hash_count_bytes[0]; let mut bloom_parts = vec![0u64; ACCOUNT_BLOOM_SPACE / 8]; - let mut key = [0u8; 8]; for i in 0..ACCOUNT_BLOOM_SPACE / 8 { - LittleEndian::write_u64(&mut key, i as u64); + let key: [u8; 8] = (i as u64).to_le_bytes(); bloom_parts[i] = db.get(COL_ACCOUNT_BLOOM, &key).expect("low-level database error") - .and_then(|val| Some(LittleEndian::read_u64(&val[..]))) + .map(|val| { + assert!(val.len() == 8, "low-level database error"); + let mut buff = [0u8; 8]; + buff.copy_from_slice(&*val); + u64::from_le_bytes(buff) + }) .unwrap_or(0u64); } @@ -186,12 +189,10 @@ impl StateDB { pub fn commit_bloom(batch: &mut DBTransaction, journal: BloomJournal) -> io::Result<()> { assert!(journal.hash_functions <= 255); batch.put(COL_ACCOUNT_BLOOM, ACCOUNT_BLOOM_HASHCOUNT_KEY, &[journal.hash_functions as u8]); - let mut key = [0u8; 8]; - let mut val = [0u8; 8]; for (bloom_part_index, bloom_part_value) in journal.entries { - LittleEndian::write_u64(&mut key, bloom_part_index as u64); - LittleEndian::write_u64(&mut val, bloom_part_value); + let key: [u8; 8] = (bloom_part_index as u64).to_le_bytes(); + let val: [u8; 8] = bloom_part_value.to_le_bytes(); batch.put(COL_ACCOUNT_BLOOM, &key, &val); } Ok(())