Skip to content

Commit

Permalink
Merge pull request #113 from hammeWang/develop
Browse files Browse the repository at this point in the history
complete ethereum-chainrelay ingredient
  • Loading branch information
hackfisher authored Nov 26, 2019
2 parents a447084 + 8ee5c86 commit 4b69cc9
Show file tree
Hide file tree
Showing 13 changed files with 1,526 additions and 453 deletions.
161 changes: 155 additions & 6 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,16 @@ members = [
"core/merkle-mountain-range",
"core/fly-client",
"core/sr-eth-primitives",
"core/sr-rlp",

# "darwinia-client",

"node/cli",
"node/executor",
"node/primitives",
"node/runtime",
"node/rpc-client",

"srml/support",

"srml/balances",
"srml/kton",
"srml/staking",

"srml/ethereum-bridge",
]

Expand Down
24 changes: 20 additions & 4 deletions core/sr-eth-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ sr-primitives = {git = "https://github.com/darwinia-network/substrate.git", bran
substrate-primitives = {git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop", default-features = false }
rlp = { version = "0.4.3", optional = true }
parity-crypto = { version = "0.4.2", features = ["publickey"] }
rlp_derive = { git = "https://github.com/paritytech/parity-ethereum.git" }
ethereum-types = "0.8.0"
rlp_derive = { git = "https://github.com/paritytech/parity-ethereum.git", default-features = false }
ethereum-types = { version = "0.8.0", default-feature = false, features = ["serialize"] }
keccak-hash = "0.4.0"
ethbloom = { version = "0.8", default-features = false, features = ["serialize"] }
impl-codec = { version = "0.4", default-features = false, optional = true }
fixed-hash = { version = "0.4", default-features = false}
impl-rlp = { version = "0.2", default-features = false, optional = true }


[dev-dependencies]
support = { package = "srml-support", git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop"}
rustc-hex = "2.0"
keccak-hasher = "0.1"
triehash-ethereum = { version = "0.2", git = "https://github.com/paritytech/parity-ethereum.git" }
hex-literal = "0.2.1"


[features]
default = ["std"]
Expand All @@ -31,9 +40,16 @@ std = [
"rstd/std",
"sr-primitives/std",
"substrate-primitives/std",
"rlp",
"rlp/std",
"keccak-hash/std",
"ethereum-types/std",
"parity-crypto/publickey"
"parity-crypto/publickey",
"ethereum-types/std",
"ethereum-types/serialize",
"ethbloom/std",
"ethbloom/serialize",
"impl-codec/std",
"fixed-hash/std",
"impl-rlp/std"
]

10 changes: 10 additions & 0 deletions core/sr-eth-primitives/src/encoded.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Header(Vec<u8>);
impl Header {
/// Create a new owning header view.
/// Expects the data to be an RLP-encoded header -- any other case will likely lead to
/// panics further down the line.
pub fn new(encoded: Vec<u8>) -> Self {
Header(encoded)
}
}
38 changes: 38 additions & 0 deletions core/sr-eth-primitives/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/// Define errors when verifying eth blocks
use super::*;
#[cfg(feature = "std")]
use std::error::Error;
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
/// Error indicating value found is outside of a valid range.
pub struct OutOfBounds<T> {
/// Minimum allowed value.
pub min: Option<T>,
/// Maximum allowed value.
pub max: Option<T>,
/// Value found.
pub found: T,
}

#[derive(PartialEq, Eq, Clone, Copy, Debug)]
/// Error indicating an expected value was not found.
pub struct Mismatch<T> {
/// Value expected.
pub expected: T,
/// Value found.
pub found: T,
}

#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub enum BlockError {
InvalidProofOfWork(OutOfBounds<U256>),
DifficultyOutOfBounds(OutOfBounds<U256>),
InvalidSealArity(Mismatch<usize>),
Rlp(&'static str),
}

//#[cfg(feature = "std")]
//impl Error for BlockError {
// fn description(&self) -> &str {
// "Block error"
// }
//}
56 changes: 56 additions & 0 deletions core/sr-eth-primitives/src/keccak.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.

// Parity Ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity Ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.

extern crate keccak_hash as hash;

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 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());
}
}
}
Loading

0 comments on commit 4b69cc9

Please sign in to comment.