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

crypto: lazy_static removed, light parser for address URI added #2250

Merged
merged 32 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5b233fc
crypto: lazy_static removed, light parser added
michalkucharczyk Nov 9, 2023
3ab3733
fuzzer added
michalkucharczyk Nov 9, 2023
7e6bdb3
fix
michalkucharczyk Nov 9, 2023
f92f50f
cleanup
michalkucharczyk Nov 9, 2023
1a52c98
license added
michalkucharczyk Nov 9, 2023
b0167c3
std gate added
michalkucharczyk Nov 9, 2023
b6dbf0d
address uri moved to src/
michalkucharczyk Nov 9, 2023
eaf5de0
Apply suggestions from code review
michalkucharczyk Nov 13, 2023
047eb83
parsing error added
michalkucharczyk Nov 13, 2023
b33de54
fix
michalkucharczyk Nov 13, 2023
ee7f179
Merge remote-tracking branch 'origin/master' into mku-crypto-address-…
michalkucharczyk Nov 13, 2023
a3b9ded
Update substrate/primitives/core/src/address_uri.rs
michalkucharczyk Nov 13, 2023
3aad2c5
Update substrate/primitives/core/src/address_uri.rs
michalkucharczyk Nov 13, 2023
d556091
review suggestions
michalkucharczyk Nov 13, 2023
40486a6
fuzzer fixed
michalkucharczyk Nov 13, 2023
77ad7f1
review suggestion
michalkucharczyk Nov 13, 2023
93bc851
naming
michalkucharczyk Nov 13, 2023
33dd1f3
missed review suggesions + fixes
michalkucharczyk Nov 13, 2023
0476638
Update substrate/primitives/core/src/address_uri.rs
michalkucharczyk Nov 13, 2023
0dddd34
fix
michalkucharczyk Nov 13, 2023
2500fe0
Merge remote-tracking branch 'origin/master' into mku-crypto-address-…
michalkucharczyk Nov 13, 2023
52f8aa2
Merge branch 'master' into mku-crypto-address-uri-parser
michalkucharczyk Nov 13, 2023
abff740
".git/.scripts/commands/update-ui/update-ui.sh"
Nov 13, 2023
b2bb315
test-pallet-ui: trybuild-overwrite
michalkucharczyk Nov 13, 2023
13582d3
Merge branch 'master' into mku-crypto-address-uri-parser
michalkucharczyk Nov 13, 2023
9fa5ff8
better error communication
michalkucharczyk Nov 16, 2023
80532e7
fuzzer added to workspace
michalkucharczyk Nov 16, 2023
69d7c7f
fix
michalkucharczyk Nov 16, 2023
ad71461
fix
michalkucharczyk Nov 16, 2023
ab059c3
fix indexing to be 0-based
michalkucharczyk Nov 16, 2023
f6c7bfd
Merge branch 'master' into mku-crypto-address-uri-parser
michalkucharczyk Nov 16, 2023
06dd2fd
Merge branch 'master' into mku-crypto-address-uri-parser
michalkucharczyk Nov 17, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeDecode`:
Box<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Rc<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Arc<T>
= note: required for `Bar` to implement `Decode`
= note: required for `Bar` to implement `FullCodec`
Expand Down Expand Up @@ -44,8 +44,8 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
bytes::bytes::Bytes
Cow<'a, T>
parity_scale_codec::Ref<'a, T, U>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Rc<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Arc<T>
Vec<T>
and $N others
Expand Down Expand Up @@ -81,8 +81,8 @@ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeDecode`:
Box<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Rc<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Arc<T>
= note: required for `Bar` to implement `Decode`
= note: required for `Bar` to implement `FullCodec`
Expand Down Expand Up @@ -119,8 +119,8 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
bytes::bytes::Bytes
Cow<'a, T>
parity_scale_codec::Ref<'a, T, U>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Rc<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Arc<T>
Vec<T>
and $N others
Expand All @@ -137,8 +137,8 @@ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeDecode`:
Box<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Rc<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Arc<T>
= note: required for `Bar` to implement `Decode`
= note: required for `Bar` to implement `FullCodec`
Expand Down Expand Up @@ -177,8 +177,8 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
bytes::bytes::Bytes
Cow<'a, T>
parity_scale_codec::Ref<'a, T, U>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Rc<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Arc<T>
Vec<T>
and $N others
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeDecode`:
Box<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Rc<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Arc<T>
= note: required for `Bar` to implement `Decode`
= note: required for `Bar` to implement `FullCodec`
Expand Down Expand Up @@ -44,8 +44,8 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
bytes::bytes::Bytes
Cow<'a, T>
parity_scale_codec::Ref<'a, T, U>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Rc<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Arc<T>
Vec<T>
and $N others
Expand Down Expand Up @@ -81,8 +81,8 @@ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeDecode`:
Box<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Rc<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Arc<T>
= note: required for `Bar` to implement `Decode`
= note: required for `Bar` to implement `FullCodec`
Expand Down Expand Up @@ -119,8 +119,8 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
bytes::bytes::Bytes
Cow<'a, T>
parity_scale_codec::Ref<'a, T, U>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Rc<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Arc<T>
Vec<T>
and $N others
Expand All @@ -137,8 +137,8 @@ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeDecode`:
Box<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Rc<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Arc<T>
= note: required for `Bar` to implement `Decode`
= note: required for `Bar` to implement `FullCodec`
Expand Down Expand Up @@ -177,8 +177,8 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
bytes::bytes::Bytes
Cow<'a, T>
parity_scale_codec::Ref<'a, T, U>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Rc<T>
frame_support::sp_runtime::sp_application_crypto::sp_core::Bytes
Arc<T>
Vec<T>
and $N others
Expand Down
6 changes: 2 additions & 4 deletions substrate/primitives/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ bs58 = { version = "0.5.0", default-features = false, optional = true }
rand = { version = "0.8.5", features = ["small_rng"], optional = true }
substrate-bip39 = { version = "0.4.4", optional = true }
bip39 = { version = "2.0.0", default-features = false }
regex = { version = "1.6.0", optional = true }
zeroize = { version = "1.4.3", default-features = false }
secrecy = { version = "0.8.0", default-features = false }
lazy_static = { version = "1.4.0", default-features = false, optional = true }
parking_lot = { version = "0.12.1", optional = true }
ss58-registry = { version = "1.34.0", default-features = false }
sp-std = { path = "../std", default-features = false}
Expand Down Expand Up @@ -63,6 +61,8 @@ bandersnatch_vrfs = { git = "https://github.com/w3f/ring-vrf", rev = "cbc342e",
[dev-dependencies]
criterion = "0.4.0"
serde_json = "1.0.108"
lazy_static = "1.4.0"
regex = "1.6.0"
sp-core-hashing-proc-macro = { path = "hashing/proc-macro" }

[[bench]]
Expand Down Expand Up @@ -92,7 +92,6 @@ std = [
"hash256-std-hasher/std",
"impl-serde/std",
"itertools",
"lazy_static",
"libsecp256k1/std",
"log/std",
"merlin/std",
Expand All @@ -102,7 +101,6 @@ std = [
"primitive-types/serde",
"primitive-types/std",
"rand",
"regex",
"scale-info/std",
"schnorrkel/std",
"secp256k1/global-context",
Expand Down
27 changes: 27 additions & 0 deletions substrate/primitives/core/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "sp-core-fuzz"
version = "0.0.0"
publish = false

[package.metadata]
cargo-fuzz = true

[dependencies]
lazy_static = "1.4.0"
libfuzzer-sys = "0.4"
regex = "1.10.2"

sp-core = { path = ".." }

# Prevent this from interfering with workspaces
[workspace]
members = ["."]
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved

[profile.release]
debug = 1

[[bin]]
name = "fuzz_address_uri"
path = "fuzz_targets/fuzz_address_uri.rs"
test = false
doc = false
50 changes: 50 additions & 0 deletions substrate/primitives/core/fuzz/fuzz_targets/fuzz_address_uri.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// 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.

#![no_main]

extern crate libfuzzer_sys;
extern crate regex;
extern crate sp_core;

use libfuzzer_sys::fuzz_target;
use regex::Regex;
use sp_core::crypto::AddressUri;

lazy_static::lazy_static! {
static ref SECRET_PHRASE_REGEX: Regex = Regex::new(r"^(?P<phrase>[a-zA-Z0-9 ]+)?(?P<path>(//?[^/]+)*)(///(?P<password>.*))?$")
.expect("constructed from known-good static value; qed");
}

fuzz_target!(|input: &str| {
let regex_result = SECRET_PHRASE_REGEX.captures(input);
let manual_result = AddressUri::parse(input);
assert_eq!(regex_result.is_some(), manual_result.is_ok());
if let (Some(regex_result), Ok(manual_result)) = (regex_result, manual_result) {
assert_eq!(regex_result.name("phrase").map(|p| p.as_str()), manual_result.phrase);

let manual_paths = manual_result
.paths
.iter()
.map(|s| "/".to_string() + s)
.collect::<Vec<_>>()
.join("");

assert_eq!(regex_result.name("path").unwrap().as_str().to_string(), manual_paths);
assert_eq!(regex_result.name("password").map(|pass| pass.as_str()), manual_result.pass);
}
});
Loading