Upgrade parity-common deps to latest (#11620)

* Upgrade parity-crypto to 0.6

* More fixes

* Upgrade ethabi and ethabi-derive

* Fix lockfile

* Patch ethabi from master

* quickfix for ethash

* Update forkid

* Add secret store back

* Fetch ethabi from crates

* fetch secret-store from the right place

* update to keccak-hash 0.5.1

* ethash: upgrade keccak-hash

* ethash: sneaky spaces

* ethash: use overlapping bytes after all

* revert submodule update

Co-authored-by: Andronik Ordian <write@reusable.software>
This commit is contained in:
David
2020-04-11 13:16:37 +02:00
committed by GitHub
parent b8e4f142d1
commit 1b23af3fa9
73 changed files with 337 additions and 400 deletions

View File

@@ -7,8 +7,8 @@ authors = ["Parity Technologies <admin@parity.io>"]
[dependencies]
common-types = { path = "../ethcore/types" }
either = "1.0.0"
ethereum-types = "0.8.0"
keccak-hash = "0.4.0"
ethereum-types = "0.9.0"
keccak-hash = "0.5.0"
log = "0.4"
memmap = "0.6"
parking_lot = "0.10.0"

View File

@@ -301,17 +301,23 @@ impl AsRef<[Node]> for NodeCache {
// out. It counts as a read and causes all writes afterwards to be elided. Yes, really. I know, I
// want to refactor this to use less `unsafe` as much as the next rustacean.
unsafe fn initialize_memory(memory: *mut Node, num_nodes: usize, ident: &H256) {
let dst = memory as *mut u8;
// We use raw pointers here, see above
let dst = slice::from_raw_parts_mut(memory as *mut u8, NODE_BYTES);
debug_assert_eq!(ident.len(), 32);
keccak_512::unchecked(dst, NODE_BYTES, ident.as_ptr(), ident.len());
keccak_512::write(&ident[..], dst);
for i in 1..num_nodes {
// We use raw pointers here, see above
let dst = memory.offset(i as _) as *mut u8;
let src = memory.offset(i as isize - 1) as *mut u8;
keccak_512::unchecked(dst, NODE_BYTES, src, NODE_BYTES);
let dst = slice::from_raw_parts_mut(
memory.offset(i as _) as *mut u8,
NODE_BYTES,
);
let src = slice::from_raw_parts(
memory.offset(i as isize - 1) as *mut u8,
NODE_BYTES,
);
keccak_512::write(src, dst);
}
// Now this is initialized, we can treat it as a slice.

View File

@@ -139,13 +139,14 @@ pub fn quick_get_difficulty(header_hash: &H256, nonce: u64, mix_hash: &H256, pro
let hash_len = header_hash.len();
buf[..hash_len].copy_from_slice(header_hash);
buf[hash_len..hash_len + mem::size_of::<u64>()].copy_from_slice(&nonce.to_ne_bytes());
let end = hash_len + mem::size_of::<u64>();
buf[hash_len..end].copy_from_slice(&nonce.to_ne_bytes());
keccak_512::unchecked(buf.as_mut_ptr(), 64, buf.as_ptr(), 40);
keccak_512::inplace_range(&mut buf, 0..end);
buf[64..].copy_from_slice(mix_hash);
let mut hash = [0u8; 32];
keccak_256::unchecked(hash.as_mut_ptr(), hash.len(), buf.as_ptr(), buf.len());
keccak_256::write(&buf, &mut hash);
hash
}
@@ -197,21 +198,17 @@ fn hash_compute(light: &Light, full_size: usize, header_hash: &H256, nonce: u64)
// improvements, since I can't imagine that 3-5% of our runtime is taken up by catting two
// arrays together.
let mut buf: MixBuf = MixBuf {
half_mix: unsafe {
half_mix: {
// Pack `header_hash` and `nonce` together
let mut out = [0u8; NODE_BYTES];
let hash_len = header_hash.len();
out[..hash_len].copy_from_slice(header_hash);
out[hash_len..hash_len + mem::size_of::<u64>()].copy_from_slice(&nonce.to_ne_bytes());
let end = hash_len + mem::size_of::<u64>();
out[hash_len..end].copy_from_slice(&nonce.to_ne_bytes());
// compute keccak-512 hash and replicate across mix
keccak_512::unchecked(
out.as_mut_ptr(),
NODE_BYTES,
out.as_ptr(),
header_hash.len() + mem::size_of::<u64>(),
);
keccak_512::inplace_range(&mut out, 0..end);
Node { bytes: out }
},
@@ -285,21 +282,20 @@ fn hash_compute(light: &Light, full_size: usize, header_hash: &H256, nonce: u64)
let value: H256 = {
// We can interpret the buffer as an array of `u8`s, since it's `repr(C)`.
let read_ptr: *const u8 = &buf as *const MixBuf as *const u8;
// We overwrite the second half since `keccak_256` has an internal buffer and so allows
// overlapping arrays as input.
let write_ptr: *mut u8 = &mut buf.compress_bytes as *mut [u8; 32] as *mut u8;
unsafe {
keccak_256::unchecked(
write_ptr,
buf.compress_bytes.len(),
let buffer = unsafe {
core::slice::from_raw_parts(
read_ptr,
buf.half_mix.bytes.len() + buf.compress_bytes.len(),
);
}
)
};
// We overwrite the buf.compress_bytes since `keccak_256` has an internal buffer and so allows
// overlapping arrays as input.
keccak_256::write(buffer, &mut buf.compress_bytes);
buf.compress_bytes
};
ProofOfWork { mix_hash: mix_hash, value: value }
ProofOfWork { mix_hash, value }
}
pub fn calculate_dag_item(node_index: u32, cache: &[Node]) -> Node {

View File

@@ -21,36 +21,11 @@ pub type H256 = [u8; 32];
pub mod keccak_512 {
use super::hash;
pub use self::hash::keccak_512_unchecked as unchecked;
pub fn write(input: &[u8], output: &mut [u8]) {
hash::keccak_512(input, output);
}
pub fn inplace(input: &mut [u8]) {
// This is safe since `keccak_*` uses an internal buffer and copies the result to the output. This
// means that we can reuse the input buffer for both input and output.
unsafe {
hash::keccak_512_unchecked(input.as_mut_ptr(), input.len(), input.as_ptr(), input.len());
}
}
pub use self::hash::{keccak_512 as write, keccak512 as inplace, keccak512_range as inplace_range};
}
pub mod keccak_256 {
use super::hash;
pub use self::hash::keccak_256_unchecked as unchecked;
#[allow(dead_code)]
pub fn write(input: &[u8], output: &mut [u8]) {
hash::keccak_256(input, output);
}
pub fn inplace(input: &mut [u8]) {
// This is safe since `keccak_*` uses an internal buffer and copies the result to the output. This
// means that we can reuse the input buffer for both input and output.
unsafe {
hash::keccak_256_unchecked(input.as_mut_ptr(), input.len(), input.as_ptr(), input.len());
}
}
pub use self::hash::{keccak_256 as write, keccak256 as inplace, keccak256_range as inplace_range};
}