Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f4267c4
should have no_std support. but doesn't work yet
Sep 18, 2019
1dad3a8
changed to newer mesalock-style. not working
Sep 18, 2019
54394fe
improved std compilation, but sgx-tstd still sticks in deps
Sep 19, 2019
8615f10
using rstd works
Sep 19, 2019
5c3706d
adding substrate-primitives from 9b08e7ff938a45dbec7fcdb854063202e2b0…
Sep 19, 2019
b81b70c
forked substrate-primitives to include crypto in no_std. builds
Sep 20, 2019
490f067
added sr25519 to primitives (seems to support no_std now)
Sep 20, 2019
f2eddcd
added hash::Has to signature
Sep 20, 2019
cad26d4
fixing hash::Hash
Sep 20, 2019
2d4e177
fixing pub use Pair
Sep 20, 2019
76106bc
fixing ss58codec trait bound
Sep 20, 2019
f5d16b7
got rif of test-node-runtime dependency. contract example broken
Sep 21, 2019
6bf7a72
fix cargo tests
Sep 21, 2019
c661bab
exposing public for no_std
Sep 21, 2019
8e3d313
fixing no_std. blake and twox ok now. ed25519 and sr25519 bad.
Sep 21, 2019
34e853a
cleanup dependencies
Sep 22, 2019
b2838d0
some error handling and unit testing
Sep 25, 2019
68c1900
fixing handling of null
Sep 25, 2019
d59e220
adding set_balance function for convenience
Sep 25, 2019
af31e8e
more flexible conversion (nonce is u32)
Sep 25, 2019
fb2ca04
slight reformatting
Sep 26, 2019
14fe5a7
adding a hint on how to make example_contract work
Sep 27, 2019
e79f8b4
Merge branch 'master' into no_std_rstd
brenzi Sep 27, 2019
c3d4ec0
fix merge issues
Sep 27, 2019
089eeb9
fixing no_std after merge
Sep 27, 2019
6e30c74
adding no_std test crate. fixing pub extern crate issue
Sep 30, 2019
5e7524f
[test_no_std]: fixing linker issue
Sep 30, 2019
42f1e11
[extrinsic/mod] fix std build dependencies in macros
Sep 30, 2019
9b53214
[node_metadata] added parsing of events and simple prints
Sep 30, 2019
b519bd3
fixing external relative path for application crypto
Sep 30, 2019
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: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# will have compiled files and executables
**/target/


# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
**/Cargo.lock
Expand Down
52 changes: 34 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,25 @@ authors = ["Supercomputing Systems AG <[email protected]>"]
edition = "2018"

[dependencies]
env_logger = "0.6"
ws = "0.7"
hex = "0.3"
log = "0.4"
clap = { version = "2.33", features = ["yaml"] }
serde = "1.0"
regex = "1.1"
serde_json = "1.0"
hex-literal = "0.1"
serde_derive = "1.0"
env_logger = { version = "0.6", optional = true }
ws = { version = "0.7", optional = true }
hex = { version = "0.3", default-features=false, optional = true }
log = { version = "0.4", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }
serde_json = { version = "1.0", optional = true }
primitive-types = { version = "0.5", default-features = false, features = ["codec"] }
parity-codec-derive = { version = "3.3", default-features = false }

[dependencies.primitives]
git = 'https://github.com/paritytech/substrate'
rev = '9b08e7ff938a45dbec7fcdb854063202e2b0cb48'
path = "./primitives"
default-features=false
package = "substrate-primitives"

[dependencies.codec]
default-features = false
package = "parity-scale-codec"
features = ["derive"]
version = "1.0.0"
default-features = false

[dependencies.indices]
git = 'https://github.com/paritytech/substrate'
Expand Down Expand Up @@ -78,19 +73,25 @@ rev = '9b08e7ff938a45dbec7fcdb854063202e2b0cb48'
package = "srml-support"
default-features=false

[dev-dependencies.rstd]
[dependencies.rstd]
git = 'https://github.com/paritytech/substrate'
rev = '9b08e7ff938a45dbec7fcdb854063202e2b0cb48'
package = "sr-std"
default-features = false

[dev-dependencies.node_runtime]
git = 'https://github.com/paritytech/substrate'
rev = '9b08e7ff938a45dbec7fcdb854063202e2b0cb48'
package = "node-runtime"

[dev-dependencies.test_node_runtime]
git = 'https://github.com/scs/substrate-test-nodes.git'
package = "test-node-runtime"
[dev-dependencies.node_primitives]
git = 'https://github.com/paritytech/substrate'
rev = '9b08e7ff938a45dbec7fcdb854063202e2b0cb48'
package = "node-primitives"

#[dev-dependencies.test_node_runtime]
#git = 'https://github.com/scs/substrate-test-nodes.git'
#package = "test-node-runtime"

[dev-dependencies.contracts]
git = 'https://github.com/paritytech/substrate'
Expand All @@ -105,6 +106,9 @@ git = 'https://github.com/paritytech/substrate'
rev = '9b08e7ff938a45dbec7fcdb854063202e2b0cb48'
package = "substrate-keyring"

[dev-dependencies.clap]
version = "2.33"
features = ["yaml"]

[features]
default = ["std"]
Expand All @@ -121,6 +125,12 @@ std = [
"runtime_io/std",
"indices/std",
"primitives/std",
"serde/std",
"serde_json",
"env_logger",
"log",
"ws",
"hex",
]

[[example]]
Expand Down Expand Up @@ -153,4 +163,10 @@ path = "src/examples/example_custom_storage_struct.rs"

[[example]]
name = "example_compose_extrinsic_offline"
path = "src/examples/example_compose_extrinsic_offline.rs"
path = "src/examples/example_compose_extrinsic_offline.rs"

[patch."https://github.com/paritytech/substrate"]
substrate-primitives = { package = "substrate-primitives", path = "./primitives", default-features=false }

[patch.crates-io]
ed25519-dalek = { git = "https://github.com/scs/ed25519-dalek.git", branch = "no_std_sgx"}
98 changes: 98 additions & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
[package]
name = "substrate-primitives"
version = "2.0.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
rustc-hex = { version = "2.0", default-features = false }
serde = { version = "1.0", optional = true, features = ["derive"] }
twox-hash = { version = "1.3.0", default-features = false }
byteorder = { version = "1.3.1", default-features = false }
primitive-types = { version = "0.5.0", default-features = false, features = ["codec"] }
impl-serde = { version = "0.1", optional = true }
log = { version = "0.4", optional = true }
wasmi = { version = "0.5.0", optional = true }
hash-db = { version = "0.15.2", default-features = false }
hash256-std-hasher = { version = "0.15.2", default-features = false }
base58 = { version = "0.1", optional = true }
rand = { version = "0.6", optional = true }
sha2 = { version = "0.8", optional = true }
substrate-bip39 = { version = "0.3.1", optional = true }
tiny-bip39 = { version = "0.6.1", optional = true }
hex = { version = "0.4", default-features = false }
regex = { version = "1.1", optional = true }
num-traits = { version = "0.2", default-features = false }
zeroize = { version = "0.9.2", default-features = false }
lazy_static = { version = "1.3", default-features = false }
parking_lot = { version = "0.9.0", optional = true }

[dependencies.rstd]
git = 'https://github.com/paritytech/substrate'
rev = '9b08e7ff938a45dbec7fcdb854063202e2b0cb48'
package = "sr-std"
default-features = false

[dependencies.blake2-rfc]
git = "https://github.com/cesarb/blake2-rfc"
package = "blake2-rfc"
version = "0.2.18"
default-features = false

[dependencies.ed25519-dalek]
version = "1.0.0-pre.1"
default-features = false
features = ["u64_backend"]

[dependencies.schnorrkel]
version = "0.8.5"
features = ["preaudit_deprecated"]
default-features = false

[dev-dependencies]
##substrate-serializer = { path = "../serializer" }
#pretty_assertions = "0.6"
#hex-literal = "0.2"
#rand = "0.6"
#criterion = "0.2"

[[bench]]
name = "benches"
harness = false

[lib]
bench = false

[features]
default = ["std"]
std = [
"log",
"wasmi",
"primitive-types/std",
"primitive-types/serde",
"primitive-types/byteorder",
"primitive-types/rustc-hex",
"primitive-types/libc",
"impl-serde",
"codec/std",
"hash256-std-hasher/std",
"hash-db/std",
"rstd/std",
"serde",
"rustc-hex/std",
"twox-hash/std",
"blake2-rfc/std",
"ed25519-dalek/std",
"base58",
"substrate-bip39",
"tiny-bip39",
"serde",
"byteorder/std",
"rand",
"sha2",
"regex",
"parking_lot",
"num-traits/std",
"zeroize/std",
]
95 changes: 95 additions & 0 deletions primitives/benches/benches.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2019 Parity Technologies
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


#[macro_use]
extern crate criterion;

use substrate_primitives as primitives;
use criterion::{Criterion, black_box, Bencher, Fun};
use std::time::Duration;
use primitives::crypto::Pair as _;
use primitives::hashing::{twox_128, blake2_128};

const MAX_KEY_SIZE: u32 = 32;

fn get_key(key_size: u32) -> Vec<u8> {
use rand::SeedableRng;
use rand::Rng;

let rnd: [u8; 32] = rand::rngs::StdRng::seed_from_u64(12).gen();
let mut rnd = rnd.iter().cycle();

(0..key_size)
.map(|_| rnd.next().unwrap().clone())
.collect()
}

fn bench_blake2_128(b: &mut Bencher, key: &Vec<u8>) {
b.iter(|| {
let _a = blake2_128(black_box(key));
});
}

fn bench_twox_128(b: &mut Bencher, key: &Vec<u8>) {
b.iter(|| {
let _a = twox_128(black_box(key));
});
}

fn bench_hash_128_fix_size(c: &mut Criterion) {
let key = get_key(MAX_KEY_SIZE);
let blake_fn = Fun::new("blake2_128", bench_blake2_128);
let twox_fn = Fun::new("twox_128", bench_twox_128);
let fns = vec![blake_fn, twox_fn];

c.bench_functions("fixed size hashing", fns, key);
}

fn bench_hash_128_dyn_size(c: &mut Criterion) {
let mut keys = Vec::new();
for i in (2..MAX_KEY_SIZE).step_by(4) {
keys.push(get_key(i).clone())
}

c.bench_function_over_inputs("dyn size hashing - blake2", |b, key| bench_blake2_128(b, &key), keys.clone());
c.bench_function_over_inputs("dyn size hashing - twox", |b, key| bench_twox_128(b, &key), keys);
}

fn bench_ed25519(c: &mut Criterion) {
c.bench_function_over_inputs("signing - ed25519", |b, &msg_size| {
let msg = (0..msg_size)
.map(|_| rand::random::<u8>())
.collect::<Vec<_>>();
let key = primitives::ed25519::Pair::generate().0;
b.iter(|| key.sign(&msg))
}, vec![32, 1024, 1024 * 1024]);

c.bench_function_over_inputs("verifying - ed25519", |b, &msg_size| {
let msg = (0..msg_size)
.map(|_| rand::random::<u8>())
.collect::<Vec<_>>();
let key = primitives::ed25519::Pair::generate().0;
let sig = key.sign(&msg);
let public = key.public();
b.iter(|| primitives::ed25519::Pair::verify(&sig, &msg, &public))
}, vec![32, 1024, 1024 * 1024]);
}

criterion_group!{
name = benches;
config = Criterion::default().warm_up_time(Duration::from_millis(500)).without_plots();
targets = bench_hash_128_fix_size, bench_hash_128_dyn_size, bench_ed25519
}
criterion_main!(benches);
Loading