From a7e3fac5d6d373d04ee7269b4e9f5b6e4ed9750e Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 25 Oct 2019 12:48:26 +0200 Subject: [PATCH 01/15] add CONTRIBUTING guidelines and initial changelogs --- CONTRIBUTING.md | 46 ++++++++++++++++++++++++ contract-address/CHANGELOG.md | 7 ++++ ethbloom/CHANGELOG.md | 11 ++++++ ethereum-types/CHANGELOG.md | 9 +++++ fixed-hash/CHANGELOG.md | 11 ++++++ keccak-hash/CHANGELOG.md | 11 ++++++ kvdb-memorydb/CHANGELOG.md | 7 ++++ kvdb-rocksdb/CHANGELOG.md | 12 +++++++ kvdb-web/CHANGELOG.md | 11 ++++++ kvdb/CHANGELOG.md | 13 +++++++ parity-bytes/CHANGELOG.md | 13 +++++++ parity-crypto/CHANGELOG.md | 7 ++++ parity-path/CHANGELOG.md | 7 ++++ parity-util-mem/CHANGELOG.md | 11 ++++++ plain_hasher/CHANGELOG.md | 12 +++++++ primitive-types/CHANGELOG.md | 11 ++++++ primitive-types/impls/codec/CHANGELOG.md | 7 ++++ primitive-types/impls/rlp/CHANGELOG.md | 7 ++++ primitive-types/impls/serde/CHANGELOG.md | 7 ++++ rlp/CHANGELOG.md | 15 ++++++++ trace-time/CHANGELOG.md | 12 +++++++ transaction-pool/CHANGELOG.md | 12 +++++++ triehash/CHANGELOG.md | 12 +++++++ uint/CHANGELOG.md | 16 +++++++++ 24 files changed, 287 insertions(+) create mode 100644 CONTRIBUTING.md create mode 100644 contract-address/CHANGELOG.md create mode 100644 ethbloom/CHANGELOG.md create mode 100644 ethereum-types/CHANGELOG.md create mode 100644 fixed-hash/CHANGELOG.md create mode 100644 keccak-hash/CHANGELOG.md create mode 100644 kvdb-memorydb/CHANGELOG.md create mode 100644 kvdb-rocksdb/CHANGELOG.md create mode 100644 kvdb-web/CHANGELOG.md create mode 100644 kvdb/CHANGELOG.md create mode 100644 parity-bytes/CHANGELOG.md create mode 100644 parity-crypto/CHANGELOG.md create mode 100644 parity-path/CHANGELOG.md create mode 100644 parity-util-mem/CHANGELOG.md create mode 100644 plain_hasher/CHANGELOG.md create mode 100644 primitive-types/CHANGELOG.md create mode 100644 primitive-types/impls/codec/CHANGELOG.md create mode 100644 primitive-types/impls/rlp/CHANGELOG.md create mode 100644 primitive-types/impls/serde/CHANGELOG.md create mode 100644 rlp/CHANGELOG.md create mode 100644 trace-time/CHANGELOG.md create mode 100644 transaction-pool/CHANGELOG.md create mode 100644 triehash/CHANGELOG.md create mode 100644 uint/CHANGELOG.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..29e61c46b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,46 @@ +# Contributing to parity-common + +parity-common welcomes contribution from everyone in the form of suggestions, bug +reports, pull requests, and feedback. This document gives some guidance if you +are thinking of helping us. + +Please reach out here in a GitHub issue if we can do anything to help you contribute. + +## Submitting bug reports and feature requests + +When reporting a bug or asking for help, please include enough details so that +the people helping you can reproduce the behavior you are seeing. For some tips +on how to approach this, read about how to produce a [Minimal, Complete, and +Verifiable example]. + +[Minimal, Complete, and Verifiable example]: https://stackoverflow.com/help/mcve + +When making a feature request, please make it clear what problem you intend to +solve with the feature, any ideas for how parity-common could support solving that problem, any possible alternatives, and any disadvantages. + +## Versioning + +As many crates in the rust ecosystem, all crates in parity-common follow [semantic versioning]. This means bumping PATCH version on bug fixes that don't break backwards compatibility, MINOR version on new features and MAJOR version otherwise (MAJOR.MINOR.PATCH). Versions < 1.0 are considered to have the format 0.MAJOR.MINOR, which means bumping MINOR version for all non-breaking changes. + +If you bump a dependency that publicly exposed in crate's API (e.g. `pub use dependency;` or `pub field: dependency::Dependency`) and the version transition for dependency was semver-breaking, than it is considered to be a breaking change. To put it simply, if you change could cause a compilation error in user's code, it is a breaking change. + +## Releasing a new version + +When making a new release make sure to follow these steps: +* Add a git tag in format `-v`, e.g. `impl-serde-v0.2.2` +* List all major and breaking changes in the crate's changelog. +* `cargo publish` + +[semantic versioning]: https://semver.org/ + +## Conduct + +We follow [Substrate Code of Conduct]. + +[Substrate Code of Conduct]: https://github.com/paritytech/substrate/blob/master/CODE_OF_CONDUCT.adoc + +## Attribution + +This guideline is adapted from [Serde's CONTRIBUTING guide]. + +[Serde's CONTRIBUTING guide]: https://github.com/serde-rs/serde/blob/master/CONTRIBUTING.md diff --git a/contract-address/CHANGELOG.md b/contract-address/CHANGELOG.md new file mode 100644 index 000000000..927c9dc9c --- /dev/null +++ b/contract-address/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] diff --git a/ethbloom/CHANGELOG.md b/ethbloom/CHANGELOG.md new file mode 100644 index 000000000..f1da71a00 --- /dev/null +++ b/ethbloom/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.8.1] - 2019-10-24 +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) diff --git a/ethereum-types/CHANGELOG.md b/ethereum-types/CHANGELOG.md new file mode 100644 index 000000000..6fad76681 --- /dev/null +++ b/ethereum-types/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] +### Added +- uint error type is re-exported (https://github.com/paritytech/parity-common/pull/244) diff --git a/fixed-hash/CHANGELOG.md b/fixed-hash/CHANGELOG.md new file mode 100644 index 000000000..2d2170b42 --- /dev/null +++ b/fixed-hash/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.5.1] - 2019-10-24 +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) diff --git a/keccak-hash/CHANGELOG.md b/keccak-hash/CHANGELOG.md new file mode 100644 index 000000000..c1208e434 --- /dev/null +++ b/keccak-hash/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.4.1] - 2019-10-24 +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) diff --git a/kvdb-memorydb/CHANGELOG.md b/kvdb-memorydb/CHANGELOG.md new file mode 100644 index 000000000..927c9dc9c --- /dev/null +++ b/kvdb-memorydb/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] diff --git a/kvdb-rocksdb/CHANGELOG.md b/kvdb-rocksdb/CHANGELOG.md new file mode 100644 index 000000000..cc514b497 --- /dev/null +++ b/kvdb-rocksdb/CHANGELOG.md @@ -0,0 +1,12 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.1.6] - 2019-10-24 +- Updated to 2018 edition idioms (https://github.com/paritytech/parity-common/pull/237) +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) diff --git a/kvdb-web/CHANGELOG.md b/kvdb-web/CHANGELOG.md new file mode 100644 index 000000000..437f1ba3e --- /dev/null +++ b/kvdb-web/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.1.1] - 2019-10-24 +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) diff --git a/kvdb/CHANGELOG.md b/kvdb/CHANGELOG.md new file mode 100644 index 000000000..565fdccf3 --- /dev/null +++ b/kvdb/CHANGELOG.md @@ -0,0 +1,13 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.1.1] - 2019-10-24 +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +### Changed +- Migrated to 2018 edition (https://github.com/paritytech/parity-common/pull/205) diff --git a/parity-bytes/CHANGELOG.md b/parity-bytes/CHANGELOG.md new file mode 100644 index 000000000..cc79bd068 --- /dev/null +++ b/parity-bytes/CHANGELOG.md @@ -0,0 +1,13 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.1.1] - 2019-10-24 +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +### Added +- Added no-std support (https://github.com/paritytech/parity-common/pull/154) diff --git a/parity-crypto/CHANGELOG.md b/parity-crypto/CHANGELOG.md new file mode 100644 index 000000000..927c9dc9c --- /dev/null +++ b/parity-crypto/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] diff --git a/parity-path/CHANGELOG.md b/parity-path/CHANGELOG.md new file mode 100644 index 000000000..927c9dc9c --- /dev/null +++ b/parity-path/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] diff --git a/parity-util-mem/CHANGELOG.md b/parity-util-mem/CHANGELOG.md new file mode 100644 index 000000000..8f69530b7 --- /dev/null +++ b/parity-util-mem/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.2.1] - 2019-10-24 +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) diff --git a/plain_hasher/CHANGELOG.md b/plain_hasher/CHANGELOG.md new file mode 100644 index 000000000..a4bd19586 --- /dev/null +++ b/plain_hasher/CHANGELOG.md @@ -0,0 +1,12 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.2.2] - 2019-10-24 +- Migrated to 2018 edition (https://github.com/paritytech/parity-common/pull/213) +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) diff --git a/primitive-types/CHANGELOG.md b/primitive-types/CHANGELOG.md new file mode 100644 index 000000000..ed6699fde --- /dev/null +++ b/primitive-types/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.6.1] - 2019-10-24 +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) diff --git a/primitive-types/impls/codec/CHANGELOG.md b/primitive-types/impls/codec/CHANGELOG.md new file mode 100644 index 000000000..927c9dc9c --- /dev/null +++ b/primitive-types/impls/codec/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] diff --git a/primitive-types/impls/rlp/CHANGELOG.md b/primitive-types/impls/rlp/CHANGELOG.md new file mode 100644 index 000000000..927c9dc9c --- /dev/null +++ b/primitive-types/impls/rlp/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] diff --git a/primitive-types/impls/serde/CHANGELOG.md b/primitive-types/impls/serde/CHANGELOG.md new file mode 100644 index 000000000..927c9dc9c --- /dev/null +++ b/primitive-types/impls/serde/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] diff --git a/rlp/CHANGELOG.md b/rlp/CHANGELOG.md new file mode 100644 index 000000000..10d37b23d --- /dev/null +++ b/rlp/CHANGELOG.md @@ -0,0 +1,15 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.4.3] - 2019-10-24 +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +### Fixed +- Fixed nested unbounded lists (https://github.com/paritytech/parity-common/pull/203) +### Added +- Added no-std support (https://github.com/paritytech/parity-common/pull/206) diff --git a/trace-time/CHANGELOG.md b/trace-time/CHANGELOG.md new file mode 100644 index 000000000..0231c53a1 --- /dev/null +++ b/trace-time/CHANGELOG.md @@ -0,0 +1,12 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.1.2] - 2019-10-24 +- Migrated to 2018 edition (https://github.com/paritytech/parity-common/pull/232) +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) diff --git a/transaction-pool/CHANGELOG.md b/transaction-pool/CHANGELOG.md new file mode 100644 index 000000000..bcd99d5a9 --- /dev/null +++ b/transaction-pool/CHANGELOG.md @@ -0,0 +1,12 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [2.0.2] - 2019-10-24 +- Updated to 2018 edition idioms (https://github.com/paritytech/parity-common/pull/237) +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) diff --git a/triehash/CHANGELOG.md b/triehash/CHANGELOG.md new file mode 100644 index 000000000..67629508f --- /dev/null +++ b/triehash/CHANGELOG.md @@ -0,0 +1,12 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.8.1] - 2019-10-24 +- Migrated to 2018 edition (https://github.com/paritytech/parity-common/pull/214) +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) diff --git a/uint/CHANGELOG.md b/uint/CHANGELOG.md new file mode 100644 index 000000000..a4214eaf9 --- /dev/null +++ b/uint/CHANGELOG.md @@ -0,0 +1,16 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.8.2] - 2019-10-24 +### Fixed +- Fixed 2018 edition imports (https://github.com/paritytech/parity-common/pull/237) +- Removed `uninitialized` usage (https://github.com/paritytech/parity-common/pull/238) +### Dependencies +- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +### Changed +- Modified AsRef impl (https://github.com/paritytech/parity-common/pull/196) From 9d58f1dd5766596b6a1ed29713f8e2a8fa82aac0 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 25 Oct 2019 14:56:02 +0200 Subject: [PATCH 02/15] Update CONTRIBUTING.md Co-Authored-By: David --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 29e61c46b..0a173b70e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,7 +22,7 @@ solve with the feature, any ideas for how parity-common could support solving th As many crates in the rust ecosystem, all crates in parity-common follow [semantic versioning]. This means bumping PATCH version on bug fixes that don't break backwards compatibility, MINOR version on new features and MAJOR version otherwise (MAJOR.MINOR.PATCH). Versions < 1.0 are considered to have the format 0.MAJOR.MINOR, which means bumping MINOR version for all non-breaking changes. -If you bump a dependency that publicly exposed in crate's API (e.g. `pub use dependency;` or `pub field: dependency::Dependency`) and the version transition for dependency was semver-breaking, than it is considered to be a breaking change. To put it simply, if you change could cause a compilation error in user's code, it is a breaking change. +If you bump a dependency that is publicly exposed in a crate's API (e.g. `pub use dependency;` or `pub field: dependency::Dependency`) and the version transition for the dependency was semver-breaking, then it is considered to be a breaking change for the consuming crate as well. To put it simply, if your change could cause a compilation error in user's code, it is a breaking change. ## Releasing a new version From 5e304578e395135b324f91087398835d3ff36b90 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 25 Oct 2019 15:25:34 +0200 Subject: [PATCH 03/15] [CONTRIBUTING] address some of the review comments --- CONTRIBUTING.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0a173b70e..2727bb7a4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,14 +24,21 @@ As many crates in the rust ecosystem, all crates in parity-common follow [semant If you bump a dependency that is publicly exposed in a crate's API (e.g. `pub use dependency;` or `pub field: dependency::Dependency`) and the version transition for the dependency was semver-breaking, then it is considered to be a breaking change for the consuming crate as well. To put it simply, if your change could cause a compilation error in user's code, it is a breaking change. +Bumping versions should be done in a separate from regular code changes PR. + +[semantic versioning]: https://semver.org/ + ## Releasing a new version +This part of the guidelines is for parity-common maintainers. + When making a new release make sure to follow these steps: -* Add a git tag in format `-v`, e.g. `impl-serde-v0.2.2` -* List all major and breaking changes in the crate's changelog. -* `cargo publish` +* Submit a PR with a version bump and list all major and breaking changes in the crate's changelog -[semantic versioning]: https://semver.org/ +After the PR is merged into master: +* `cargo publish` on the latest master (try with `--dry-run` first) +* Add a git tag in format `-v`, +e.g. `git tag impl-serde-v0.2.2` and push it with `git push origin impl-serde-v0.2.2` ## Conduct From 69ff0e69a0027055c1bcccd4f7ee6db87a6aec04 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 25 Oct 2019 15:35:25 +0200 Subject: [PATCH 04/15] [CONTRIBUTING] mention our code style --- CONTRIBUTING.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2727bb7a4..c6cfaec09 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,6 +18,13 @@ Verifiable example]. When making a feature request, please make it clear what problem you intend to solve with the feature, any ideas for how parity-common could support solving that problem, any possible alternatives, and any disadvantages. +## Code style + +We don't use rustfmt in parity-common, but rather have [our own code style] and [editorconfig]. + +[our own code style]: https://wiki.parity.io/Substrate-Style-Guide +[editorconfig]: https://github.com/paritytech/parity-common/blob/master/.editorconfig + ## Versioning As many crates in the rust ecosystem, all crates in parity-common follow [semantic versioning]. This means bumping PATCH version on bug fixes that don't break backwards compatibility, MINOR version on new features and MAJOR version otherwise (MAJOR.MINOR.PATCH). Versions < 1.0 are considered to have the format 0.MAJOR.MINOR, which means bumping MINOR version for all non-breaking changes. From df9c8211e5e078f4c230d373c3bfadd4c8011569 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Mon, 28 Oct 2019 11:27:02 +0100 Subject: [PATCH 05/15] rustfmt (sorry not sorry) --- .travis.yml | 4 + CONTRIBUTING.md | 7 - contract-address/src/lib.rs | 160 ++--- ethbloom/benches/bloom.rs | 5 +- ethbloom/benches/unrolling.rs | 2 +- ethbloom/src/lib.rs | 28 +- ethereum-types/src/hash.rs | 129 +++- ethereum-types/src/lib.rs | 6 +- ethereum-types/src/uint.rs | 61 +- ethereum-types/tests/serde.rs | 128 +++- fixed-hash/src/hash.rs | 33 +- fixed-hash/src/lib.rs | 6 +- fixed-hash/src/tests.rs | 12 +- keccak-hash/benches/keccak_256.rs | 32 +- keccak-hash/src/lib.rs | 56 +- kvdb-memorydb/src/lib.rs | 51 +- kvdb-rocksdb/src/lib.rs | 322 ++++++--- kvdb-web/src/error.rs | 9 +- kvdb-web/src/indexed_db.rs | 88 ++- kvdb-web/src/lib.rs | 146 ++-- kvdb-web/tests/indexed_db.rs | 47 +- kvdb/src/lib.rs | 25 +- parity-bytes/src/lib.rs | 17 +- parity-crypto/benches/bench.rs | 34 +- parity-crypto/src/aes.rs | 147 ++-- parity-crypto/src/digest.rs | 36 +- parity-crypto/src/error.rs | 11 +- parity-crypto/src/hmac/mod.rs | 62 +- parity-crypto/src/hmac/test.rs | 131 ++-- parity-crypto/src/lib.rs | 22 +- parity-crypto/src/pbkdf2/test.rs | 11 +- parity-crypto/src/publickey/ec_math_utils.rs | 40 +- parity-crypto/src/publickey/ecdh.rs | 5 +- .../src/publickey/ecdsa_signature.rs | 77 ++- parity-crypto/src/publickey/ecies.rs | 13 +- parity-crypto/src/publickey/error.rs | 2 +- parity-crypto/src/publickey/extended_keys.rs | 233 +++++-- parity-crypto/src/publickey/keypair.rs | 21 +- .../src/publickey/keypair_generator.rs | 5 +- parity-crypto/src/publickey/mod.rs | 16 +- parity-crypto/src/publickey/secret_key.rs | 64 +- parity-crypto/src/scrypt.rs | 43 +- parity-path/src/lib.rs | 20 +- parity-util-mem/src/allocators.rs | 103 ++- parity-util-mem/src/impls.rs | 38 +- parity-util-mem/src/lib.rs | 18 +- parity-util-mem/src/malloc_size.rs | 636 +++++++++--------- parity-util-mem/src/sizeof.rs | 14 +- plain_hasher/benches/bench.rs | 32 +- primitive-types/impls/codec/src/lib.rs | 16 +- primitive-types/impls/rlp/src/lib.rs | 27 +- .../impls/serde/benches/impl_serde.rs | 40 +- primitive-types/impls/serde/benches/input.rs | 6 +- primitive-types/impls/serde/src/lib.rs | 28 +- primitive-types/impls/serde/src/serialize.rs | 70 +- rlp/benches/rlp.rs | 135 ++-- rlp/src/impls.rs | 74 +- rlp/src/lib.rs | 27 +- rlp/src/rlpin.rs | 114 +++- rlp/src/stream.rs | 41 +- rlp/tests/tests.rs | 254 ++++--- rustfmt.toml | 1 + transaction-pool/src/error.rs | 28 +- transaction-pool/src/lib.rs | 6 +- transaction-pool/src/listener.rs | 8 +- transaction-pool/src/pool.rs | 193 ++++-- transaction-pool/src/ready.rs | 8 +- transaction-pool/src/replace.rs | 50 +- transaction-pool/src/scoring.rs | 23 +- transaction-pool/src/tests/helpers.rs | 19 +- transaction-pool/src/tests/mod.rs | 454 ++++++++----- transaction-pool/src/tests/tx_builder.rs | 6 +- transaction-pool/src/transactions.rs | 140 ++-- triehash/benches/triehash.rs | 2 +- triehash/src/lib.rs | 65 +- uint/benches/bigint.rs | 153 ++++- uint/examples/modular.rs | 9 +- uint/src/lib.rs | 4 +- uint/src/uint.rs | 190 +++--- uint/tests/uint_tests.rs | 607 ++++++++++------- 80 files changed, 3639 insertions(+), 2367 deletions(-) create mode 100644 rustfmt.toml diff --git a/.travis.yml b/.travis.yml index 5bedd7f7d..2d48dc81b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,10 @@ matrix: include: - os: linux rust: stable + before_script: + - rustup component add rustfmt + after_script: + - cargo fmt -- --check - os: linux rust: beta - os: linux diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c6cfaec09..2727bb7a4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,13 +18,6 @@ Verifiable example]. When making a feature request, please make it clear what problem you intend to solve with the feature, any ideas for how parity-common could support solving that problem, any possible alternatives, and any disadvantages. -## Code style - -We don't use rustfmt in parity-common, but rather have [our own code style] and [editorconfig]. - -[our own code style]: https://wiki.parity.io/Substrate-Style-Guide -[editorconfig]: https://github.com/paritytech/parity-common/blob/master/.editorconfig - ## Versioning As many crates in the rust ecosystem, all crates in parity-common follow [semantic versioning]. This means bumping PATCH version on bug fixes that don't break backwards compatibility, MINOR version on new features and MAJOR version otherwise (MAJOR.MINOR.PATCH). Versions < 1.0 are considered to have the format 0.MAJOR.MINOR, which means bumping MINOR version for all non-breaking changes. diff --git a/contract-address/src/lib.rs b/contract-address/src/lib.rs index ea4050316..5c59e1a97 100644 --- a/contract-address/src/lib.rs +++ b/contract-address/src/lib.rs @@ -27,95 +27,95 @@ use std::ops::Deref; pub struct ContractAddress(Address); impl ContractAddress { - /// Computes the address of a contract from the sender's address and the transaction nonce - pub fn from_sender_and_nonce(sender: &Address, nonce: &U256) -> Self { - let mut stream = RlpStream::new_list(2); - stream.append(sender); - stream.append(nonce); - - ContractAddress(Address::from(keccak(stream.as_raw()))) - } - - /// Computes the address of a contract from the sender's address, the salt and code hash - /// - /// pWASM `create2` scheme and EIP-1014 CREATE2 scheme - pub fn from_sender_salt_and_code(sender: &Address, salt: H256, code_hash: H256) -> Self { - let mut buffer = [0u8; 1 + 20 + 32 + 32]; - buffer[0] = 0xff; - &mut buffer[1..(1 + 20)].copy_from_slice(&sender[..]); - &mut buffer[(1 + 20)..(1 + 20 + 32)].copy_from_slice(&salt[..]); - &mut buffer[(1 + 20 + 32)..].copy_from_slice(&code_hash[..]); - - ContractAddress(Address::from(keccak(&buffer[..]))) - } - - /// Computes the address of a contract from the sender's address and the code hash - /// - /// Used by pwasm create ext. - pub fn from_sender_and_code(sender: &Address, code_hash: H256) -> Self { - let mut buffer = [0u8; 20 + 32]; - &mut buffer[..20].copy_from_slice(&sender[..]); - &mut buffer[20..].copy_from_slice(&code_hash[..]); - - ContractAddress(Address::from(keccak(&buffer[..]))) - } + /// Computes the address of a contract from the sender's address and the transaction nonce + pub fn from_sender_and_nonce(sender: &Address, nonce: &U256) -> Self { + let mut stream = RlpStream::new_list(2); + stream.append(sender); + stream.append(nonce); + + ContractAddress(Address::from(keccak(stream.as_raw()))) + } + + /// Computes the address of a contract from the sender's address, the salt and code hash + /// + /// pWASM `create2` scheme and EIP-1014 CREATE2 scheme + pub fn from_sender_salt_and_code(sender: &Address, salt: H256, code_hash: H256) -> Self { + let mut buffer = [0u8; 1 + 20 + 32 + 32]; + buffer[0] = 0xff; + &mut buffer[1..(1 + 20)].copy_from_slice(&sender[..]); + &mut buffer[(1 + 20)..(1 + 20 + 32)].copy_from_slice(&salt[..]); + &mut buffer[(1 + 20 + 32)..].copy_from_slice(&code_hash[..]); + + ContractAddress(Address::from(keccak(&buffer[..]))) + } + + /// Computes the address of a contract from the sender's address and the code hash + /// + /// Used by pwasm create ext. + pub fn from_sender_and_code(sender: &Address, code_hash: H256) -> Self { + let mut buffer = [0u8; 20 + 32]; + &mut buffer[..20].copy_from_slice(&sender[..]); + &mut buffer[20..].copy_from_slice(&code_hash[..]); + + ContractAddress(Address::from(keccak(&buffer[..]))) + } } impl Deref for ContractAddress { - type Target = Address; + type Target = Address; - fn deref(&self) -> &Self::Target { - &self.0 - } + fn deref(&self) -> &Self::Target { + &self.0 + } } impl From for Address { - fn from(contract_address: ContractAddress) -> Self { - contract_address.0 - } + fn from(contract_address: ContractAddress) -> Self { + contract_address.0 + } } #[cfg(test)] mod tests { - use super::*; - use std::str::FromStr; - - #[test] - fn test_from_sender_and_nonce() { - let sender = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); - let expected = Address::from_str("3f09c73a5ed19289fb9bdc72f1742566df146f56").unwrap(); - - let actual = ContractAddress::from_sender_and_nonce(&sender, &U256::from(88)); - - assert_eq!(Address::from(actual), expected); - } - - #[test] - fn test_from_sender_salt_and_code_hash() { - let sender = Address::zero(); - let code_hash = - H256::from_str("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470") - .unwrap(); - let expected_address = - Address::from_str("e33c0c7f7df4809055c3eba6c09cfe4baf1bd9e0").unwrap(); - - let contract_address = - ContractAddress::from_sender_salt_and_code(&sender, H256::zero(), code_hash); - - assert_eq!(Address::from(contract_address), expected_address); - } - - #[test] - fn test_from_sender_and_code_hash() { - let sender = Address::from_str("0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d").unwrap(); - let code_hash = - H256::from_str("d98f2e8134922f73748703c8e7084d42f13d2fa1439936ef5a3abcf5646fe83f") - .unwrap(); - let expected_address = - Address::from_str("064417880f5680b141ed7fcac031aad40df080b0").unwrap(); - - let contract_address = ContractAddress::from_sender_and_code(&sender, code_hash); - - assert_eq!(Address::from(contract_address), expected_address); - } + use super::*; + use std::str::FromStr; + + #[test] + fn test_from_sender_and_nonce() { + let sender = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); + let expected = Address::from_str("3f09c73a5ed19289fb9bdc72f1742566df146f56").unwrap(); + + let actual = ContractAddress::from_sender_and_nonce(&sender, &U256::from(88)); + + assert_eq!(Address::from(actual), expected); + } + + #[test] + fn test_from_sender_salt_and_code_hash() { + let sender = Address::zero(); + let code_hash = + H256::from_str("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470") + .unwrap(); + let expected_address = + Address::from_str("e33c0c7f7df4809055c3eba6c09cfe4baf1bd9e0").unwrap(); + + let contract_address = + ContractAddress::from_sender_salt_and_code(&sender, H256::zero(), code_hash); + + assert_eq!(Address::from(contract_address), expected_address); + } + + #[test] + fn test_from_sender_and_code_hash() { + let sender = Address::from_str("0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d").unwrap(); + let code_hash = + H256::from_str("d98f2e8134922f73748703c8e7084d42f13d2fa1439936ef5a3abcf5646fe83f") + .unwrap(); + let expected_address = + Address::from_str("064417880f5680b141ed7fcac031aad40df080b0").unwrap(); + + let contract_address = ContractAddress::from_sender_and_code(&sender, code_hash); + + assert_eq!(Address::from(contract_address), expected_address); + } } diff --git a/ethbloom/benches/bloom.rs b/ethbloom/benches/bloom.rs index 2231832ed..07f11a92f 100644 --- a/ethbloom/benches/bloom.rs +++ b/ethbloom/benches/bloom.rs @@ -21,8 +21,9 @@ fn test_bloom() -> Bloom { 00000000000000000000000000000000\ 00000000000000000000000000000000\ 00000000000000000000000000000000\ - 00000000000000000000000000000000" - ).unwrap() + 00000000000000000000000000000000", + ) + .unwrap() } fn test_topic() -> Vec { diff --git a/ethbloom/benches/unrolling.rs b/ethbloom/benches/unrolling.rs index e35a33270..5fd6883ce 100644 --- a/ethbloom/benches/unrolling.rs +++ b/ethbloom/benches/unrolling.rs @@ -48,7 +48,7 @@ fn bench_backwards(c: &mut Criterion) { b.iter(|| { let other_data = random_data(); for i in 0..255 { - data[255-i] |= other_data[255-i]; + data[255 - i] |= other_data[255 - i]; } }); }); diff --git a/ethbloom/src/lib.rs b/ethbloom/src/lib.rs index 5cc5b8119..70f5db822 100644 --- a/ethbloom/src/lib.rs +++ b/ethbloom/src/lib.rs @@ -45,20 +45,20 @@ #![cfg_attr(not(feature = "std"), no_std)] -use core::{ops, mem}; +use core::{mem, ops}; use crunchy::unroll; use fixed_hash::*; +use impl_rlp::impl_fixed_hash_rlp; #[cfg(feature = "serialize")] use impl_serde::impl_fixed_hash_serde; -use impl_rlp::impl_fixed_hash_rlp; use tiny_keccak::keccak256; // 3 according to yellowpaper const BLOOM_BITS: u32 = 3; const BLOOM_SIZE: usize = 256; -construct_fixed_hash!{ +construct_fixed_hash! { /// Bloom hash type with 256 bytes (2048 bits) size. pub struct Bloom(BLOOM_SIZE); } @@ -139,7 +139,10 @@ impl Bloom { self.contains_bloom(&bloom) } - pub fn contains_bloom<'a, B>(&self, bloom: B) -> bool where BloomRef<'a>: From { + pub fn contains_bloom<'a, B>(&self, bloom: B) -> bool + where + BloomRef<'a>: From, + { let bloom_ref: BloomRef<'_> = bloom.into(); // workaround for https://github.com/rust-lang/rust/issues/43644 self.contains_bloom_ref(bloom_ref) @@ -182,7 +185,10 @@ impl Bloom { } } - pub fn accrue_bloom<'a, B>(&mut self, bloom: B) where BloomRef<'a>: From { + pub fn accrue_bloom<'a, B>(&mut self, bloom: B) + where + BloomRef<'a>: From, + { let bloom_ref: BloomRef<'_> = bloom.into(); assert_eq!(self.0.len(), BLOOM_SIZE); assert_eq!(bloom_ref.0.len(), BLOOM_SIZE); @@ -212,7 +218,10 @@ impl<'a> BloomRef<'a> { } #[allow(clippy::trivially_copy_pass_by_ref)] - pub fn contains_bloom<'b, B>(&self, bloom: B) -> bool where BloomRef<'b>: From { + pub fn contains_bloom<'b, B>(&self, bloom: B) -> bool + where + BloomRef<'b>: From, + { let bloom_ref: BloomRef<'_> = bloom.into(); assert_eq!(self.0.len(), BLOOM_SIZE); assert_eq!(bloom_ref.0.len(), BLOOM_SIZE); @@ -249,9 +258,9 @@ impl_fixed_hash_serde!(Bloom, BLOOM_SIZE); #[cfg(test)] mod tests { + use super::{Bloom, Input}; use core::str::FromStr; use hex_literal::hex; - use super::{Bloom, Input}; #[test] fn it_works() { @@ -271,8 +280,9 @@ mod tests { 00000000000000000000000000000000\ 00000000000000000000000000000000\ 00000000000000000000000000000000\ - 00000000000000000000000000000000" - ).unwrap(); + 00000000000000000000000000000000", + ) + .unwrap(); let address = hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106"); let topic = hex!("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc"); diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index 9c04ee576..23d00dd22 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -1,7 +1,7 @@ -use crate::{U64, U128, U256, U512}; +use crate::{U128, U256, U512, U64}; use fixed_hash::*; use impl_rlp::impl_fixed_hash_rlp; -#[cfg(feature="serialize")] +#[cfg(feature = "serialize")] use impl_serde::impl_fixed_hash_serde; pub trait BigEndianHash { @@ -11,30 +11,35 @@ pub trait BigEndianHash { fn into_uint(&self) -> Self::Uint; } -construct_fixed_hash!{ pub struct H32(4); } +construct_fixed_hash! { pub struct H32(4); } impl_fixed_hash_rlp!(H32, 4); -#[cfg(feature = "serialize")] impl_fixed_hash_serde!(H32, 4); +#[cfg(feature = "serialize")] +impl_fixed_hash_serde!(H32, 4); -construct_fixed_hash!{ pub struct H64(8); } +construct_fixed_hash! { pub struct H64(8); } impl_fixed_hash_rlp!(H64, 8); -#[cfg(feature = "serialize")] impl_fixed_hash_serde!(H64, 8); +#[cfg(feature = "serialize")] +impl_fixed_hash_serde!(H64, 8); -construct_fixed_hash!{ pub struct H128(16); } +construct_fixed_hash! { pub struct H128(16); } impl_fixed_hash_rlp!(H128, 16); -#[cfg(feature = "serialize")] impl_fixed_hash_serde!(H128, 16); +#[cfg(feature = "serialize")] +impl_fixed_hash_serde!(H128, 16); pub use primitive_types::H160; pub use primitive_types::H256; -construct_fixed_hash!{ pub struct H264(33); } +construct_fixed_hash! { pub struct H264(33); } impl_fixed_hash_rlp!(H264, 33); -#[cfg(feature = "serialize")] impl_fixed_hash_serde!(H264, 33); +#[cfg(feature = "serialize")] +impl_fixed_hash_serde!(H264, 33); pub use primitive_types::H512; -construct_fixed_hash!{ pub struct H520(65); } +construct_fixed_hash! { pub struct H520(65); } impl_fixed_hash_rlp!(H520, 65); -#[cfg(feature = "serialize")] impl_fixed_hash_serde!(H520, 65); +#[cfg(feature = "serialize")] +impl_fixed_hash_serde!(H520, 65); macro_rules! impl_uint_conversions { ($hash: ident, $uint: ident) => { @@ -51,7 +56,7 @@ macro_rules! impl_uint_conversions { $uint::from(self.as_ref() as &[u8]) } } - } + }; } impl_uint_conversions!(H64, U64); @@ -67,17 +72,41 @@ mod tests { #[test] fn test_serialize_h160() { let tests = vec![ - (H160::from_low_u64_be(0), "0x0000000000000000000000000000000000000000"), - (H160::from_low_u64_be(2), "0x0000000000000000000000000000000000000002"), - (H160::from_low_u64_be(15), "0x000000000000000000000000000000000000000f"), - (H160::from_low_u64_be(16), "0x0000000000000000000000000000000000000010"), - (H160::from_low_u64_be(1_000), "0x00000000000000000000000000000000000003e8"), - (H160::from_low_u64_be(100_000), "0x00000000000000000000000000000000000186a0"), - (H160::from_low_u64_be(u64::max_value()), "0x000000000000000000000000ffffffffffffffff"), + ( + H160::from_low_u64_be(0), + "0x0000000000000000000000000000000000000000", + ), + ( + H160::from_low_u64_be(2), + "0x0000000000000000000000000000000000000002", + ), + ( + H160::from_low_u64_be(15), + "0x000000000000000000000000000000000000000f", + ), + ( + H160::from_low_u64_be(16), + "0x0000000000000000000000000000000000000010", + ), + ( + H160::from_low_u64_be(1_000), + "0x00000000000000000000000000000000000003e8", + ), + ( + H160::from_low_u64_be(100_000), + "0x00000000000000000000000000000000000186a0", + ), + ( + H160::from_low_u64_be(u64::max_value()), + "0x000000000000000000000000ffffffffffffffff", + ), ]; for (number, expected) in tests { - assert_eq!(format!("{:?}", expected), ser::to_string_pretty(&number).unwrap()); + assert_eq!( + format!("{:?}", expected), + ser::to_string_pretty(&number).unwrap() + ); assert_eq!(number, ser::from_str(&format!("{:?}", expected)).unwrap()); } } @@ -85,26 +114,62 @@ mod tests { #[test] fn test_serialize_h256() { let tests = vec![ - (H256::from_low_u64_be(0), "0x0000000000000000000000000000000000000000000000000000000000000000"), - (H256::from_low_u64_be(2), "0x0000000000000000000000000000000000000000000000000000000000000002"), - (H256::from_low_u64_be(15), "0x000000000000000000000000000000000000000000000000000000000000000f"), - (H256::from_low_u64_be(16), "0x0000000000000000000000000000000000000000000000000000000000000010"), - (H256::from_low_u64_be(1_000), "0x00000000000000000000000000000000000000000000000000000000000003e8"), - (H256::from_low_u64_be(100_000), "0x00000000000000000000000000000000000000000000000000000000000186a0"), - (H256::from_low_u64_be(u64::max_value()), "0x000000000000000000000000000000000000000000000000ffffffffffffffff"), + ( + H256::from_low_u64_be(0), + "0x0000000000000000000000000000000000000000000000000000000000000000", + ), + ( + H256::from_low_u64_be(2), + "0x0000000000000000000000000000000000000000000000000000000000000002", + ), + ( + H256::from_low_u64_be(15), + "0x000000000000000000000000000000000000000000000000000000000000000f", + ), + ( + H256::from_low_u64_be(16), + "0x0000000000000000000000000000000000000000000000000000000000000010", + ), + ( + H256::from_low_u64_be(1_000), + "0x00000000000000000000000000000000000000000000000000000000000003e8", + ), + ( + H256::from_low_u64_be(100_000), + "0x00000000000000000000000000000000000000000000000000000000000186a0", + ), + ( + H256::from_low_u64_be(u64::max_value()), + "0x000000000000000000000000000000000000000000000000ffffffffffffffff", + ), ]; for (number, expected) in tests { - assert_eq!(format!("{:?}", expected), ser::to_string_pretty(&number).unwrap()); + assert_eq!( + format!("{:?}", expected), + ser::to_string_pretty(&number).unwrap() + ); assert_eq!(number, ser::from_str(&format!("{:?}", expected)).unwrap()); } } #[test] fn test_serialize_invalid() { - assert!(ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000\"").unwrap_err().is_data()); - assert!(ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000g\"").unwrap_err().is_data()); - assert!(ser::from_str::("\"0x00000000000000000000000000000000000000000000000000000000000000000\"").unwrap_err().is_data()); + assert!(ser::from_str::( + "\"0x000000000000000000000000000000000000000000000000000000000000000\"" + ) + .unwrap_err() + .is_data()); + assert!(ser::from_str::( + "\"0x000000000000000000000000000000000000000000000000000000000000000g\"" + ) + .unwrap_err() + .is_data()); + assert!(ser::from_str::( + "\"0x00000000000000000000000000000000000000000000000000000000000000000\"" + ) + .unwrap_err() + .is_data()); assert!(ser::from_str::("\"\"").unwrap_err().is_data()); assert!(ser::from_str::("\"0\"").unwrap_err().is_data()); assert!(ser::from_str::("\"10\"").unwrap_err().is_data()); diff --git a/ethereum-types/src/lib.rs b/ethereum-types/src/lib.rs index dbbb42ad0..9bc756ba0 100644 --- a/ethereum-types/src/lib.rs +++ b/ethereum-types/src/lib.rs @@ -1,13 +1,11 @@ #![cfg_attr(not(feature = "std"), no_std)] - - mod hash; mod uint; -pub use uint::{U64, U128, U256, U512, FromDecStrErr}; -pub use hash::{BigEndianHash, H32, H64, H128, H160, H256, H264, H512, H520}; pub use ethbloom::{Bloom, BloomRef, Input as BloomInput}; +pub use hash::{BigEndianHash, H128, H160, H256, H264, H32, H512, H520, H64}; +pub use uint::{FromDecStrErr, U128, U256, U512, U64}; pub type Address = H160; pub type Secret = H256; diff --git a/ethereum-types/src/uint.rs b/ethereum-types/src/uint.rs index 258c52f20..8d6a355f4 100644 --- a/ethereum-types/src/uint.rs +++ b/ethereum-types/src/uint.rs @@ -1,7 +1,7 @@ -use uint_crate::*; use impl_rlp::impl_uint_rlp; -#[cfg(feature="serialize")] +#[cfg(feature = "serialize")] use impl_serde::impl_uint_serde; +use uint_crate::*; pub use uint_crate::FromDecStrErr; @@ -10,16 +10,16 @@ construct_uint! { pub struct U64(1); } impl_uint_rlp!(U64, 1); -#[cfg(feature = "serialize")] impl_uint_serde!(U64, 1); +#[cfg(feature = "serialize")] +impl_uint_serde!(U64, 1); pub use primitive_types::{U128, U256, U512}; - #[cfg(test)] mod tests { use super::{U256, U512}; - use std::u64::MAX; use serde_json as ser; + use std::u64::MAX; macro_rules! test_serialize { ($name: ident, $test_name: ident) => { @@ -40,7 +40,10 @@ mod tests { ]; for (number, expected) in tests { - assert_eq!(format!("{:?}", expected), ser::to_string_pretty(&number).unwrap()); + assert_eq!( + format!("{:?}", expected), + ser::to_string_pretty(&number).unwrap() + ); assert_eq!(number, ser::from_str(&format!("{:?}", expected)).unwrap()); } @@ -51,7 +54,7 @@ mod tests { assert!(ser::from_str::<$name>("\"10\"").unwrap_err().is_data()); assert!(ser::from_str::<$name>("\"0\"").unwrap_err().is_data()); } - } + }; } test_serialize!(U256, test_u256); @@ -63,9 +66,11 @@ mod tests { ser::to_string_pretty(&!U256::zero()).unwrap(), "\"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"" ); - assert!( - ser::from_str::("\"0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"").unwrap_err().is_data() - ); + assert!(ser::from_str::( + "\"0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"" + ) + .unwrap_err() + .is_data()); } #[test] @@ -110,58 +115,58 @@ mod tests { assert_eq!(U512([0, 27, 0, 0, 0, 0, 0, 0]), result); let result = U256([MAX, 0, 0, 0]).full_mul(U256([MAX, 0, 0, 0])); - assert_eq!(U512([1, MAX-1, 0, 0, 0, 0, 0, 0]), result); + assert_eq!(U512([1, MAX - 1, 0, 0, 0, 0, 0, 0]), result); let result = U256([0, MAX, 0, 0]).full_mul(U256([MAX, 0, 0, 0])); - assert_eq!(U512([0, 1, MAX-1, 0, 0, 0, 0, 0]), result); + assert_eq!(U512([0, 1, MAX - 1, 0, 0, 0, 0, 0]), result); let result = U256([MAX, MAX, 0, 0]).full_mul(U256([MAX, 0, 0, 0])); - assert_eq!(U512([1, MAX, MAX-1, 0, 0, 0, 0, 0]), result); + assert_eq!(U512([1, MAX, MAX - 1, 0, 0, 0, 0, 0]), result); let result = U256([MAX, 0, 0, 0]).full_mul(U256([MAX, MAX, 0, 0])); - assert_eq!(U512([1, MAX, MAX-1, 0, 0, 0, 0, 0]), result); + assert_eq!(U512([1, MAX, MAX - 1, 0, 0, 0, 0, 0]), result); let result = U256([MAX, MAX, 0, 0]).full_mul(U256([MAX, MAX, 0, 0])); - assert_eq!(U512([1, 0, MAX-1, MAX, 0, 0, 0, 0]), result); + assert_eq!(U512([1, 0, MAX - 1, MAX, 0, 0, 0, 0]), result); let result = U256([MAX, 0, 0, 0]).full_mul(U256([MAX, MAX, MAX, 0])); - assert_eq!(U512([1, MAX, MAX, MAX-1, 0, 0, 0, 0]), result); + assert_eq!(U512([1, MAX, MAX, MAX - 1, 0, 0, 0, 0]), result); let result = U256([MAX, MAX, MAX, 0]).full_mul(U256([MAX, 0, 0, 0])); - assert_eq!(U512([1, MAX, MAX, MAX-1, 0, 0, 0, 0]), result); + assert_eq!(U512([1, MAX, MAX, MAX - 1, 0, 0, 0, 0]), result); let result = U256([MAX, 0, 0, 0]).full_mul(U256([MAX, MAX, MAX, MAX])); - assert_eq!(U512([1, MAX, MAX, MAX, MAX-1, 0, 0, 0]), result); + assert_eq!(U512([1, MAX, MAX, MAX, MAX - 1, 0, 0, 0]), result); let result = U256([MAX, MAX, MAX, MAX]).full_mul(U256([MAX, 0, 0, 0])); - assert_eq!(U512([1, MAX, MAX, MAX, MAX-1, 0, 0, 0]), result); + assert_eq!(U512([1, MAX, MAX, MAX, MAX - 1, 0, 0, 0]), result); let result = U256([MAX, MAX, MAX, 0]).full_mul(U256([MAX, MAX, 0, 0])); - assert_eq!(U512([1, 0, MAX, MAX-1, MAX, 0, 0, 0]), result); + assert_eq!(U512([1, 0, MAX, MAX - 1, MAX, 0, 0, 0]), result); let result = U256([MAX, MAX, 0, 0]).full_mul(U256([MAX, MAX, MAX, 0])); - assert_eq!(U512([1, 0, MAX, MAX-1, MAX, 0, 0, 0]), result); + assert_eq!(U512([1, 0, MAX, MAX - 1, MAX, 0, 0, 0]), result); let result = U256([MAX, MAX, MAX, MAX]).full_mul(U256([MAX, MAX, 0, 0])); - assert_eq!(U512([1, 0, MAX, MAX, MAX-1, MAX, 0, 0]), result); + assert_eq!(U512([1, 0, MAX, MAX, MAX - 1, MAX, 0, 0]), result); let result = U256([MAX, MAX, 0, 0]).full_mul(U256([MAX, MAX, MAX, MAX])); - assert_eq!(U512([1, 0, MAX, MAX, MAX-1, MAX, 0, 0]), result); + assert_eq!(U512([1, 0, MAX, MAX, MAX - 1, MAX, 0, 0]), result); let result = U256([MAX, MAX, MAX, 0]).full_mul(U256([MAX, MAX, MAX, 0])); - assert_eq!(U512([1, 0, 0, MAX-1, MAX, MAX, 0, 0]), result); + assert_eq!(U512([1, 0, 0, MAX - 1, MAX, MAX, 0, 0]), result); let result = U256([MAX, MAX, MAX, 0]).full_mul(U256([MAX, MAX, MAX, MAX])); - assert_eq!(U512([1, 0, 0, MAX, MAX-1, MAX, MAX, 0]), result); + assert_eq!(U512([1, 0, 0, MAX, MAX - 1, MAX, MAX, 0]), result); let result = U256([MAX, MAX, MAX, MAX]).full_mul(U256([MAX, MAX, MAX, 0])); - assert_eq!(U512([1, 0, 0, MAX, MAX-1, MAX, MAX, 0]), result); + assert_eq!(U512([1, 0, 0, MAX, MAX - 1, MAX, MAX, 0]), result); let result = U256([MAX, MAX, MAX, MAX]).full_mul(U256([MAX, MAX, MAX, MAX])); - assert_eq!(U512([1, 0, 0, 0, MAX-1, MAX, MAX, MAX]), result); + assert_eq!(U512([1, 0, 0, 0, MAX - 1, MAX, MAX, MAX]), result); let result = U256([0, 0, 0, MAX]).full_mul(U256([0, 0, 0, MAX])); - assert_eq!(U512([0, 0, 0, 0, 0, 0, 1, MAX-1]), result); + assert_eq!(U512([0, 0, 0, 0, 0, 0, 1, MAX - 1]), result); let result = U256([1, 0, 0, 0]).full_mul(U256([0, 0, 0, MAX])); assert_eq!(U512([0, 0, 0, MAX, 0, 0, 0, 0]), result); diff --git a/ethereum-types/tests/serde.rs b/ethereum-types/tests/serde.rs index 1cdbc4466..e24422323 100644 --- a/ethereum-types/tests/serde.rs +++ b/ethereum-types/tests/serde.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ethereum_types::{U256, U512, H160, H256}; +use ethereum_types::{H160, H256, U256, U512}; use serde_json as ser; macro_rules! test { @@ -24,11 +24,17 @@ macro_rules! test { ($name::from(1_000), "0x3e8"), ($name::from(100_000), "0x186a0"), ($name::from(u64::max_value()), "0xffffffffffffffff"), - ($name::from(u64::max_value()) + $name::from(1u64), "0x10000000000000000"), + ( + $name::from(u64::max_value()) + $name::from(1u64), + "0x10000000000000000", + ), ]; for (number, expected) in tests { - assert_eq!(format!("{:?}", expected), ser::to_string_pretty(&number).unwrap()); + assert_eq!( + format!("{:?}", expected), + ser::to_string_pretty(&number).unwrap() + ); assert_eq!(number, ser::from_str(&format!("{:?}", expected)).unwrap()); } @@ -39,7 +45,7 @@ macro_rules! test { assert!(ser::from_str::<$name>("\"10\"").unwrap_err().is_data()); assert!(ser::from_str::<$name>("\"0\"").unwrap_err().is_data()); } - } + }; } test!(U256, test_u256); @@ -51,25 +57,51 @@ fn test_large_values() { ser::to_string_pretty(&!U256::zero()).unwrap(), "\"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"" ); - assert!( - ser::from_str::("\"0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"").unwrap_err().is_data() - ); + assert!(ser::from_str::( + "\"0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"" + ) + .unwrap_err() + .is_data()); } #[test] fn test_h160() { let tests = vec![ - (H160::from_low_u64_be(0), "0x0000000000000000000000000000000000000000"), - (H160::from_low_u64_be(2), "0x0000000000000000000000000000000000000002"), - (H160::from_low_u64_be(15), "0x000000000000000000000000000000000000000f"), - (H160::from_low_u64_be(16), "0x0000000000000000000000000000000000000010"), - (H160::from_low_u64_be(1_000), "0x00000000000000000000000000000000000003e8"), - (H160::from_low_u64_be(100_000), "0x00000000000000000000000000000000000186a0"), - (H160::from_low_u64_be(u64::max_value()), "0x000000000000000000000000ffffffffffffffff"), + ( + H160::from_low_u64_be(0), + "0x0000000000000000000000000000000000000000", + ), + ( + H160::from_low_u64_be(2), + "0x0000000000000000000000000000000000000002", + ), + ( + H160::from_low_u64_be(15), + "0x000000000000000000000000000000000000000f", + ), + ( + H160::from_low_u64_be(16), + "0x0000000000000000000000000000000000000010", + ), + ( + H160::from_low_u64_be(1_000), + "0x00000000000000000000000000000000000003e8", + ), + ( + H160::from_low_u64_be(100_000), + "0x00000000000000000000000000000000000186a0", + ), + ( + H160::from_low_u64_be(u64::max_value()), + "0x000000000000000000000000ffffffffffffffff", + ), ]; for (number, expected) in tests { - assert_eq!(format!("{:?}", expected), ser::to_string_pretty(&number).unwrap()); + assert_eq!( + format!("{:?}", expected), + ser::to_string_pretty(&number).unwrap() + ); assert_eq!(number, ser::from_str(&format!("{:?}", expected)).unwrap()); } } @@ -77,26 +109,62 @@ fn test_h160() { #[test] fn test_h256() { let tests = vec![ - (H256::from_low_u64_be(0), "0x0000000000000000000000000000000000000000000000000000000000000000"), - (H256::from_low_u64_be(2), "0x0000000000000000000000000000000000000000000000000000000000000002"), - (H256::from_low_u64_be(15), "0x000000000000000000000000000000000000000000000000000000000000000f"), - (H256::from_low_u64_be(16), "0x0000000000000000000000000000000000000000000000000000000000000010"), - (H256::from_low_u64_be(1_000), "0x00000000000000000000000000000000000000000000000000000000000003e8"), - (H256::from_low_u64_be(100_000), "0x00000000000000000000000000000000000000000000000000000000000186a0"), - (H256::from_low_u64_be(u64::max_value()), "0x000000000000000000000000000000000000000000000000ffffffffffffffff"), + ( + H256::from_low_u64_be(0), + "0x0000000000000000000000000000000000000000000000000000000000000000", + ), + ( + H256::from_low_u64_be(2), + "0x0000000000000000000000000000000000000000000000000000000000000002", + ), + ( + H256::from_low_u64_be(15), + "0x000000000000000000000000000000000000000000000000000000000000000f", + ), + ( + H256::from_low_u64_be(16), + "0x0000000000000000000000000000000000000000000000000000000000000010", + ), + ( + H256::from_low_u64_be(1_000), + "0x00000000000000000000000000000000000000000000000000000000000003e8", + ), + ( + H256::from_low_u64_be(100_000), + "0x00000000000000000000000000000000000000000000000000000000000186a0", + ), + ( + H256::from_low_u64_be(u64::max_value()), + "0x000000000000000000000000000000000000000000000000ffffffffffffffff", + ), ]; for (number, expected) in tests { - assert_eq!(format!("{:?}", expected), ser::to_string_pretty(&number).unwrap()); + assert_eq!( + format!("{:?}", expected), + ser::to_string_pretty(&number).unwrap() + ); assert_eq!(number, ser::from_str(&format!("{:?}", expected)).unwrap()); } } #[test] fn test_invalid() { - assert!(ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000\"").unwrap_err().is_data()); - assert!(ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000g\"").unwrap_err().is_data()); - assert!(ser::from_str::("\"0x00000000000000000000000000000000000000000000000000000000000000000\"").unwrap_err().is_data()); + assert!(ser::from_str::( + "\"0x000000000000000000000000000000000000000000000000000000000000000\"" + ) + .unwrap_err() + .is_data()); + assert!(ser::from_str::( + "\"0x000000000000000000000000000000000000000000000000000000000000000g\"" + ) + .unwrap_err() + .is_data()); + assert!(ser::from_str::( + "\"0x00000000000000000000000000000000000000000000000000000000000000000\"" + ) + .unwrap_err() + .is_data()); assert!(ser::from_str::("\"\"").unwrap_err().is_data()); assert!(ser::from_str::("\"0\"").unwrap_err().is_data()); assert!(ser::from_str::("\"10\"").unwrap_err().is_data()); @@ -104,7 +172,11 @@ fn test_invalid() { #[test] fn test_invalid_char() { - const INVALID_STR: &str = "\"0x000000000000000000000000000000000000000000000000000000000000000g\""; + const INVALID_STR: &str = + "\"0x000000000000000000000000000000000000000000000000000000000000000g\""; const EXPECTED_MSG: &str = "invalid hex character: g, at 65 at line 1 column 68"; - assert_eq!(ser::from_str::(INVALID_STR).unwrap_err().to_string(), EXPECTED_MSG); + assert_eq!( + ser::from_str::(INVALID_STR).unwrap_err().to_string(), + EXPECTED_MSG + ); } diff --git a/fixed-hash/src/hash.rs b/fixed-hash/src/hash.rs index 393b4cc93..2004ffdf0 100644 --- a/fixed-hash/src/hash.rs +++ b/fixed-hash/src/hash.rs @@ -338,7 +338,7 @@ macro_rules! construct_fixed_hash { #[macro_export] #[doc(hidden)] macro_rules! impl_byteorder_for_fixed_hash { - ( $name:ident ) => {} + ( $name:ident ) => {}; } // Implementation for enabled byteorder crate support. @@ -368,7 +368,7 @@ macro_rules! impl_byteorder_for_fixed_hash { fn to_low_u64_with_byteorder(&self) -> u64 where - B: $crate::byteorder::ByteOrder + B: $crate::byteorder::ByteOrder, { let mut buf = [0x0; 8]; let capped = $crate::core_::cmp::min(Self::len_bytes(), 8); @@ -411,7 +411,7 @@ macro_rules! impl_byteorder_for_fixed_hash { fn from_low_u64_with_byteorder(val: u64) -> Self where - B: $crate::byteorder::ByteOrder + B: $crate::byteorder::ByteOrder, { let mut buf = [0x0; 8]; B::write_u64(&mut buf, val); @@ -457,7 +457,7 @@ macro_rules! impl_byteorder_for_fixed_hash { Self::from_low_u64_with_byteorder::<$crate::byteorder::NativeEndian>(val) } } - } + }; } // Implementation for disabled rand crate support. @@ -471,7 +471,7 @@ macro_rules! impl_byteorder_for_fixed_hash { #[macro_export] #[doc(hidden)] macro_rules! impl_rand_for_fixed_hash { - ( $name:ident ) => {} + ( $name:ident ) => {}; } // Implementation for enabled rand crate support. @@ -504,7 +504,7 @@ macro_rules! impl_rand_for_fixed_hash { /// given random number generator. pub fn randomize_using(&mut self, rng: &mut R) where - R: $crate::rand::Rng + ?Sized + R: $crate::rand::Rng + ?Sized, { use $crate::rand::distributions::Distribution; *self = $crate::rand::distributions::Standard.sample(rng); @@ -520,7 +520,7 @@ macro_rules! impl_rand_for_fixed_hash { /// given random number generator. pub fn random_using(rng: &mut R) -> Self where - R: $crate::rand::Rng + ?Sized + R: $crate::rand::Rng + ?Sized, { let mut ret = Self::zero(); ret.randomize_using(rng); @@ -534,7 +534,7 @@ macro_rules! impl_rand_for_fixed_hash { hash } } - } + }; } // Implementation for disabled libc crate support. @@ -562,7 +562,7 @@ macro_rules! impl_libc_for_fixed_hash { self.as_bytes().cmp(other.as_bytes()) } } - } + }; } // Implementation for enabled libc crate support. @@ -608,7 +608,7 @@ macro_rules! impl_libc_for_fixed_hash { $crate::core_::cmp::Ordering::Equal } } - } + }; } // Implementation for disabled rustc-hex crate support. @@ -622,7 +622,7 @@ macro_rules! impl_libc_for_fixed_hash { #[macro_export] #[doc(hidden)] macro_rules! impl_rustc_hex_for_fixed_hash { - ( $name:ident ) => {} + ( $name:ident ) => {}; } // Implementation for enabled rustc-hex crate support. @@ -663,7 +663,7 @@ macro_rules! impl_rustc_hex_for_fixed_hash { Ok($name::from_slice(&bytes)) } } - } + }; } // Implementation for disabled quickcheck crate support. @@ -677,7 +677,7 @@ macro_rules! impl_rustc_hex_for_fixed_hash { #[macro_export] #[doc(hidden)] macro_rules! impl_quickcheck_for_fixed_hash { - ( $name:ident ) => {} + ( $name:ident ) => {}; } // Implementation for enabled quickcheck crate support. @@ -699,7 +699,7 @@ macro_rules! impl_quickcheck_for_fixed_hash { Self::from(res) } } - } + }; } #[macro_export] @@ -812,9 +812,8 @@ macro_rules! impl_fixed_hash_conversions { ); let mut ret = $small_ty::zero(); - ret.as_bytes_mut().copy_from_slice( - &value[(large_ty_size - small_ty_size)..large_ty_size], - ); + ret.as_bytes_mut() + .copy_from_slice(&value[(large_ty_size - small_ty_size)..large_ty_size]); ret } } diff --git a/fixed-hash/src/lib.rs b/fixed-hash/src/lib.rs index 9c841f885..297490134 100644 --- a/fixed-hash/src/lib.rs +++ b/fixed-hash/src/lib.rs @@ -65,7 +65,7 @@ mod hash; mod tests; #[cfg(feature = "api-dummy")] -construct_fixed_hash!{ - /// Go here for an overview of the hash type API. - pub struct ApiDummy(32); +construct_fixed_hash! { + /// Go here for an overview of the hash type API. + pub struct ApiDummy(32); } diff --git a/fixed-hash/src/tests.rs b/fixed-hash/src/tests.rs index b1445f3e4..12f28ff25 100644 --- a/fixed-hash/src/tests.rs +++ b/fixed-hash/src/tests.rs @@ -1,8 +1,8 @@ -construct_fixed_hash!{ struct H32(4); } -construct_fixed_hash!{ struct H64(8); } -construct_fixed_hash!{ struct H128(16); } -construct_fixed_hash!{ struct H160(20); } -construct_fixed_hash!{ struct H256(32); } +construct_fixed_hash! { struct H32(4); } +construct_fixed_hash! { struct H64(8); } +construct_fixed_hash! { struct H128(16); } +construct_fixed_hash! { struct H160(20); } +construct_fixed_hash! { struct H256(32); } impl_fixed_hash_conversions!(H256, H160); @@ -250,7 +250,7 @@ mod from_low_u64 { #[cfg(feature = "rand")] mod rand { use super::*; - use ::rand::{SeedableRng, rngs::StdRng}; + use ::rand::{rngs::StdRng, SeedableRng}; #[test] fn random() { diff --git a/keccak-hash/benches/keccak_256.rs b/keccak-hash/benches/keccak_256.rs index e18de9fe6..5cf5f2526 100644 --- a/keccak-hash/benches/keccak_256.rs +++ b/keccak-hash/benches/keccak_256.rs @@ -23,28 +23,28 @@ use test::Bencher; #[bench] fn bench_keccak_256_with_empty_input(b: &mut Bencher) { - let empty = [0u8;0]; - b.bytes = empty.len() as u64; - b.iter(|| { - let _out = keccak(empty); - }) + let empty = [0u8; 0]; + b.bytes = empty.len() as u64; + b.iter(|| { + let _out = keccak(empty); + }) } #[bench] fn bench_keccak_256_with_typical_input(b: &mut Bencher) { - let data: Vec = From::from("some medum length string with important information"); - b.bytes = data.len() as u64; - b.iter(|| { - let _out = keccak(&data); - }) + let data: Vec = From::from("some medum length string with important information"); + b.bytes = data.len() as u64; + b.iter(|| { + let _out = keccak(&data); + }) } #[bench] fn bench_keccak_256_with_large_input(b: &mut Bencher) { - // 4096 chars - let data: Vec = From::from("IGxcKBr1Qp7tuqtpSVhAbvt7UgWLEi7mCA6Wa185seLSIJLFS8K1aAFO9AwtO9b3n9SM3Qg136JMmy9Mj9gZ84IaUm8XioPtloabFDU5ZR1wvauJT6jNTkvBVBpUigIsyU7C1u3s99vKP64LpXqvo1hwItZKtISxmUAgzzjv5q14V4G9bkKAnmc4M5xixgLsDGZmnj6HcOMY3XRkWtxN3RscSKwPA0bfpgtz27ZVHplbXwloYRgRLpjRhZJc7sqO8RFnTHKasVkxVRcUoDBvWNJK27TbLvQQcfxETI2Q1H6c2cBAchi8unSiuxqy5rIvVxcl9rsmmRY4IXLEG9qKntUGbiIRLjEffIP9ODoWog0GbWLmMtfvtf24hWVwXz6Ap5oUAR0kLgb7HYIYrOwKjvfV25iEF7GW8cjhl8yowXx1zcgW4t6NJNqJlGzRKx8MvRWQXvHz8h8JxcHl7S64i6PAkxI9eCLXLvs8cpbEQQHt05Zu6GKm6IInjc9mSh52WFuGhgjbno69XzfkBufJs6c9tZuBf6ErVPj4UxmT82ajCruDusk79Tlvb8oQMLjoplQc1alQaLQwSsMac9iVp9MiE3PeYnTTepJ1V10tp79fciDAnNPJgPcRfDYv0REcSFgR9Q7yWhbpPpyBjO7HwOykDQVGtV0ZbDFrFRygLAXagAIkOPc9HDfcBNID1Q2MGk8ijVWMyvmGz1wzbpNfFcQaSOm8olhwoLyHUGvkyXegh44iNsPBUvSicNxTTDowtMqO5azleuWEjzxCobYbASDopvl6JeJjRtEBBO5YCQJiHsYjlXh9QR5Q543GsqhzRLgcHNRSZYLMZqDmIABXZi8VRNJMZyWXDRKHOGDmcHWe55uZomW6FnyU0uSRKxxz66K0JWfxuFzzxAR0vR4ZZCTemgDRQuDwL1loC3KUMjDpU13jUgoPc4UJUVfwQ4f4BUY3X51Cfw9FLw4oX39KoFoiCP2Z6z27gZUY1IlE59WoXGLj4KjTp4C16ZihG080gfDIWlXnDEk3VwBuBFyKWARB63sGLrGnn27b1gHWMaop6sPvkQgWxkEKIqsxDIvXLZJg2s23V8Gqtt0FeA7R3RCvBysF4jNjQ7NiQTIQWQZ8G9gO4mEsftolSZv6FlSpNeBKIIwYWSO2R6vkgeiz06euE9bwwnenOjwPNGTGk8WHIOZBJ1hIP0ejVU2i2ca9ON0phSAnewqjo5W3PtZf2Q7mDvp9imuVWoy4t8XcZq8I2Un9jVjes9Xi0FLN2t71vLFWLWZmGDzwXxpqEgkARS1WjtJoYXCBmRnXEPj6jQfwMZWKPYSIrmOogxMVoWvA8wrof6utfJna9JezyTnrBJSCuGTSNmwwAXRLoFYxF1RITyN8mI2KmHSfvLXBrbE6kmAkjsm4XJb6kria7oUQQ1gzJuCyB7oNHjZTBFNhNa7VeQ1s1xLOwZXLOAjZ4MDTYKnF7giGJGyswb5KQxkOV9orbuAu6pJsjtql6h1UD3BcNUkG3oz8kJNepbuCN3vNCJcZOX1VrQi0PWkDwyvECrQ2E1CgbU6GpWatpg2sCTpo9W62pCcWBK2FKUFWqU3qo2T7T1Mk2ZtM6hE9I8op0M7xlGE91Mn7ea6aq93MWp7nvFlBvbaMIoeU4MpDx0BeOSkROY03ZBJ0x7K8nJrNUhAtvxp17c9oFk0VxLiuRbAAcwDUormOmpVXZNIcqnap4twEVYaSIowfcNojyUSrFL5nPc8ZG93WgNNl9rpUPZhssVml3DvXghI80A9SW3QauzohTQAX2bkWelFBHnuG2LKrsJ8en51N6CkjcS5b87y1DVMZELcZ1n5s8PCAA1wyn7OSZlgw00GRzch1YwMoHzBBgIUtMO9HrMyuhgqIPJP7KcKbQkKhtvBXKplX8SCfSlOwUkLwHNKm3HYVE0uVfJ91NAsUrGoCOjYiXYpoRT8bjAPWTm6fDlTq2sbPOyTMoc4xRasmiOJ7B0PT6UxPzCPImM4100sPFxp7Kofv4okKZWTPKTefeYiPefI3jRgfDtEIP9E6a35LZD75lBNMXYlAqL3qlnheUQD1WQimFTHiDsW6bmURptNvtkMjEXzXzpWbnyxBskUGTvP2YQjtSAhWliDXkv6t1x71cYav7TQbqvbIzMRQQsguSGYMbs8YIC4DC9ep5reWAfanlTxcxksbEhQ7FGzXOvcufeGnDl2C85gWfryVzwN7kOZiSEktFMOQ1ngRC23y1fCOiHQVQJ2nLnaW7GILb9wkN1mBTRuHsOefRJST0TnRxcn4bBq4MIibIitVyjPRy7G5XvPEcL4pFaW1HCPGm6pUOEEwTer32JObNGCyTFB1BI2cRLJu5BHPjgG3mmb0gGkGlIfh8D2b2amogpivqEn2r9Y1KOKQ8ufJvG2mYfkevco9DuEZ9Nmzkm6XkCTZaFMNHqbfQaKqsEYK7i2N1KfkBct1leW2H9MQ9QO7AHCqXHK47b1kWVIm6pSJA1yV4funzCqXnIJCEURQgHiKf38YpN7ylLhe1J4UvSG3KeesZNeFFIZOEP9HZUSFMpnN1MOrwejojK0D4qzwucYWtXrTQ8I7UP5QhlijIsCKckUa9C1Osjrq8cgSclYNGt19wpy0onUbX1rOQBUlAAUJs4CyXNU0wmVUjw7tG1LUC8my4s9KZDUj4R5UcPz3VaZRrx1RqYu6YxjroJW70I1LyG4WEiQbOkCoLmaiWo9WzbUS2cErlOo2RPymlkWHxbNnZawX2Bc872ivRHSWqNpRHyuR5QewXmcyghH3EhESBAxTel5E2xuQXfLCEVK0kEk0Mj22KPsckKKyH7sVYC1F4YItQh5hj9Titb7KflQb9vnXQ44UHxY3zBhTQT5PSYv1Kv8HxXCsnpmhZCiBru16iX9oEB33icBVB2KKcZZEEKnCGPVxJlM9RTlyNyQmjHf7z4GeTDuMAUrsMO31WvgZBnWcAOtn6ulBTUCAaqxJiWqzlMx2FSANAlyAjAxqzmQjzPLvQRjskUnBFN3woKB1m2bSo2c5thwA1fKiPvN5LW8tl1rnfNy3rJ0GJpK8nZjkzHMztYrKYAe56pX4SvplpTyibTIiRXLyEVsmuByTHCZhO3fvGoFsav3ZuRhe9eAAWeqAh13eKDTcA0ufME3ZnmJheXEZ3OwrxnFjSf3U0clkWYVont3neh77ODKHhYnX0bOmnJJlr4RqFoLBitskY0kcGMKcZlaej21SENjDcFgaka3CfHbAH5vIFqnoX1JZrZPkQ65PZqQWImP79U3gXWKvz96lElyJZAFqn0Mbltllqw4MhlI766AvHraOmMsJoNvjv1QR7pCSnC0iX6nbqW1eVPaUSZDuZRtRIxfLA8HC9VbxufT2KZV3qG0l7wrZna5Di2MNcBE9uthuVLZcqp8vCmEhINDhRRlipR7tC2iRBHecS5WtxBCpbEm1y1kgNG5o60UKgAswxxuJ3RQ9Y49mPIApBMmp4LFpuKRfcrZb4UJnCfR3pNbQ70nnZ6Be2M7tuJUCoFfHrhqHXNz5A0uWMgxUS50c60zLl6QAELxHaCGba4WCMOHIo5nSKcUuYtDyDoDlrezALW5mZR4PRPRxnjrXxbJI14qrpymRReC3QgFDJp6sT5TLwvSHaavPlEbt2Eu0Kh5SXklGHXP9YuF3glGuJzSob3NakW1RXF5786U1MHhtJby64LyGWvNn4QXie3VjeL3QQu4C9crEAxSSiOJOfnL3DYIVOY4ipUkKFlF7Rp2q6gZazDvcUCp1cbcr7T7B4s22rXzjN7mHYWOyWuZGwlImeorY3aVKi7BaXbhgOFw6BUmIc1HeGFELHIEnPE9MwOjZam3LOm0rhBHlvJJZkXvJKmDUJrGlyqC5GtC5lDWLfXewyDWDqq7PY0atVQily5GWqib6wub6u6LZ3HZDNP8gK64Nf4kC259AE4V2hCohDnSsXAIoOkehwXyp6CkDT42NJb6sXHUv2N6cm292MiKA22PKWrwUGsan599KI2V67YRDfcfiB4ZHRDiSe62MBE0fGLIgXLIWw1xTWYbPQ9YAj3xovBvmewbJ1De4k6uS"); - b.bytes = data.len() as u64; - b.iter(|| { - let _out = keccak(&data); - }) + // 4096 chars + let data: Vec = From::from("IGxcKBr1Qp7tuqtpSVhAbvt7UgWLEi7mCA6Wa185seLSIJLFS8K1aAFO9AwtO9b3n9SM3Qg136JMmy9Mj9gZ84IaUm8XioPtloabFDU5ZR1wvauJT6jNTkvBVBpUigIsyU7C1u3s99vKP64LpXqvo1hwItZKtISxmUAgzzjv5q14V4G9bkKAnmc4M5xixgLsDGZmnj6HcOMY3XRkWtxN3RscSKwPA0bfpgtz27ZVHplbXwloYRgRLpjRhZJc7sqO8RFnTHKasVkxVRcUoDBvWNJK27TbLvQQcfxETI2Q1H6c2cBAchi8unSiuxqy5rIvVxcl9rsmmRY4IXLEG9qKntUGbiIRLjEffIP9ODoWog0GbWLmMtfvtf24hWVwXz6Ap5oUAR0kLgb7HYIYrOwKjvfV25iEF7GW8cjhl8yowXx1zcgW4t6NJNqJlGzRKx8MvRWQXvHz8h8JxcHl7S64i6PAkxI9eCLXLvs8cpbEQQHt05Zu6GKm6IInjc9mSh52WFuGhgjbno69XzfkBufJs6c9tZuBf6ErVPj4UxmT82ajCruDusk79Tlvb8oQMLjoplQc1alQaLQwSsMac9iVp9MiE3PeYnTTepJ1V10tp79fciDAnNPJgPcRfDYv0REcSFgR9Q7yWhbpPpyBjO7HwOykDQVGtV0ZbDFrFRygLAXagAIkOPc9HDfcBNID1Q2MGk8ijVWMyvmGz1wzbpNfFcQaSOm8olhwoLyHUGvkyXegh44iNsPBUvSicNxTTDowtMqO5azleuWEjzxCobYbASDopvl6JeJjRtEBBO5YCQJiHsYjlXh9QR5Q543GsqhzRLgcHNRSZYLMZqDmIABXZi8VRNJMZyWXDRKHOGDmcHWe55uZomW6FnyU0uSRKxxz66K0JWfxuFzzxAR0vR4ZZCTemgDRQuDwL1loC3KUMjDpU13jUgoPc4UJUVfwQ4f4BUY3X51Cfw9FLw4oX39KoFoiCP2Z6z27gZUY1IlE59WoXGLj4KjTp4C16ZihG080gfDIWlXnDEk3VwBuBFyKWARB63sGLrGnn27b1gHWMaop6sPvkQgWxkEKIqsxDIvXLZJg2s23V8Gqtt0FeA7R3RCvBysF4jNjQ7NiQTIQWQZ8G9gO4mEsftolSZv6FlSpNeBKIIwYWSO2R6vkgeiz06euE9bwwnenOjwPNGTGk8WHIOZBJ1hIP0ejVU2i2ca9ON0phSAnewqjo5W3PtZf2Q7mDvp9imuVWoy4t8XcZq8I2Un9jVjes9Xi0FLN2t71vLFWLWZmGDzwXxpqEgkARS1WjtJoYXCBmRnXEPj6jQfwMZWKPYSIrmOogxMVoWvA8wrof6utfJna9JezyTnrBJSCuGTSNmwwAXRLoFYxF1RITyN8mI2KmHSfvLXBrbE6kmAkjsm4XJb6kria7oUQQ1gzJuCyB7oNHjZTBFNhNa7VeQ1s1xLOwZXLOAjZ4MDTYKnF7giGJGyswb5KQxkOV9orbuAu6pJsjtql6h1UD3BcNUkG3oz8kJNepbuCN3vNCJcZOX1VrQi0PWkDwyvECrQ2E1CgbU6GpWatpg2sCTpo9W62pCcWBK2FKUFWqU3qo2T7T1Mk2ZtM6hE9I8op0M7xlGE91Mn7ea6aq93MWp7nvFlBvbaMIoeU4MpDx0BeOSkROY03ZBJ0x7K8nJrNUhAtvxp17c9oFk0VxLiuRbAAcwDUormOmpVXZNIcqnap4twEVYaSIowfcNojyUSrFL5nPc8ZG93WgNNl9rpUPZhssVml3DvXghI80A9SW3QauzohTQAX2bkWelFBHnuG2LKrsJ8en51N6CkjcS5b87y1DVMZELcZ1n5s8PCAA1wyn7OSZlgw00GRzch1YwMoHzBBgIUtMO9HrMyuhgqIPJP7KcKbQkKhtvBXKplX8SCfSlOwUkLwHNKm3HYVE0uVfJ91NAsUrGoCOjYiXYpoRT8bjAPWTm6fDlTq2sbPOyTMoc4xRasmiOJ7B0PT6UxPzCPImM4100sPFxp7Kofv4okKZWTPKTefeYiPefI3jRgfDtEIP9E6a35LZD75lBNMXYlAqL3qlnheUQD1WQimFTHiDsW6bmURptNvtkMjEXzXzpWbnyxBskUGTvP2YQjtSAhWliDXkv6t1x71cYav7TQbqvbIzMRQQsguSGYMbs8YIC4DC9ep5reWAfanlTxcxksbEhQ7FGzXOvcufeGnDl2C85gWfryVzwN7kOZiSEktFMOQ1ngRC23y1fCOiHQVQJ2nLnaW7GILb9wkN1mBTRuHsOefRJST0TnRxcn4bBq4MIibIitVyjPRy7G5XvPEcL4pFaW1HCPGm6pUOEEwTer32JObNGCyTFB1BI2cRLJu5BHPjgG3mmb0gGkGlIfh8D2b2amogpivqEn2r9Y1KOKQ8ufJvG2mYfkevco9DuEZ9Nmzkm6XkCTZaFMNHqbfQaKqsEYK7i2N1KfkBct1leW2H9MQ9QO7AHCqXHK47b1kWVIm6pSJA1yV4funzCqXnIJCEURQgHiKf38YpN7ylLhe1J4UvSG3KeesZNeFFIZOEP9HZUSFMpnN1MOrwejojK0D4qzwucYWtXrTQ8I7UP5QhlijIsCKckUa9C1Osjrq8cgSclYNGt19wpy0onUbX1rOQBUlAAUJs4CyXNU0wmVUjw7tG1LUC8my4s9KZDUj4R5UcPz3VaZRrx1RqYu6YxjroJW70I1LyG4WEiQbOkCoLmaiWo9WzbUS2cErlOo2RPymlkWHxbNnZawX2Bc872ivRHSWqNpRHyuR5QewXmcyghH3EhESBAxTel5E2xuQXfLCEVK0kEk0Mj22KPsckKKyH7sVYC1F4YItQh5hj9Titb7KflQb9vnXQ44UHxY3zBhTQT5PSYv1Kv8HxXCsnpmhZCiBru16iX9oEB33icBVB2KKcZZEEKnCGPVxJlM9RTlyNyQmjHf7z4GeTDuMAUrsMO31WvgZBnWcAOtn6ulBTUCAaqxJiWqzlMx2FSANAlyAjAxqzmQjzPLvQRjskUnBFN3woKB1m2bSo2c5thwA1fKiPvN5LW8tl1rnfNy3rJ0GJpK8nZjkzHMztYrKYAe56pX4SvplpTyibTIiRXLyEVsmuByTHCZhO3fvGoFsav3ZuRhe9eAAWeqAh13eKDTcA0ufME3ZnmJheXEZ3OwrxnFjSf3U0clkWYVont3neh77ODKHhYnX0bOmnJJlr4RqFoLBitskY0kcGMKcZlaej21SENjDcFgaka3CfHbAH5vIFqnoX1JZrZPkQ65PZqQWImP79U3gXWKvz96lElyJZAFqn0Mbltllqw4MhlI766AvHraOmMsJoNvjv1QR7pCSnC0iX6nbqW1eVPaUSZDuZRtRIxfLA8HC9VbxufT2KZV3qG0l7wrZna5Di2MNcBE9uthuVLZcqp8vCmEhINDhRRlipR7tC2iRBHecS5WtxBCpbEm1y1kgNG5o60UKgAswxxuJ3RQ9Y49mPIApBMmp4LFpuKRfcrZb4UJnCfR3pNbQ70nnZ6Be2M7tuJUCoFfHrhqHXNz5A0uWMgxUS50c60zLl6QAELxHaCGba4WCMOHIo5nSKcUuYtDyDoDlrezALW5mZR4PRPRxnjrXxbJI14qrpymRReC3QgFDJp6sT5TLwvSHaavPlEbt2Eu0Kh5SXklGHXP9YuF3glGuJzSob3NakW1RXF5786U1MHhtJby64LyGWvNn4QXie3VjeL3QQu4C9crEAxSSiOJOfnL3DYIVOY4ipUkKFlF7Rp2q6gZazDvcUCp1cbcr7T7B4s22rXzjN7mHYWOyWuZGwlImeorY3aVKi7BaXbhgOFw6BUmIc1HeGFELHIEnPE9MwOjZam3LOm0rhBHlvJJZkXvJKmDUJrGlyqC5GtC5lDWLfXewyDWDqq7PY0atVQily5GWqib6wub6u6LZ3HZDNP8gK64Nf4kC259AE4V2hCohDnSsXAIoOkehwXyp6CkDT42NJb6sXHUv2N6cm292MiKA22PKWrwUGsan599KI2V67YRDfcfiB4ZHRDiSe62MBE0fGLIgXLIWw1xTWYbPQ9YAj3xovBvmewbJ1De4k6uS"); + b.bytes = data.len() as u64; + b.iter(|| { + let _out = keccak(&data); + }) } diff --git a/keccak-hash/src/lib.rs b/keccak-hash/src/lib.rs index 77a3767e0..65f719bb5 100644 --- a/keccak-hash/src/lib.rs +++ b/keccak-hash/src/lib.rs @@ -16,21 +16,30 @@ #![cfg_attr(not(feature = "std"), no_std)] +use core::slice; #[cfg(feature = "std")] use std::io; -use core::slice; pub use primitive_types::H256; use tiny_keccak::Keccak; /// Get the KECCAK (i.e. Keccak) hash of the empty bytes string. -pub const KECCAK_EMPTY: H256 = H256( [0xc5, 0xd2, 0x46, 0x01, 0x86, 0xf7, 0x23, 0x3c, 0x92, 0x7e, 0x7d, 0xb2, 0xdc, 0xc7, 0x03, 0xc0, 0xe5, 0x00, 0xb6, 0x53, 0xca, 0x82, 0x27, 0x3b, 0x7b, 0xfa, 0xd8, 0x04, 0x5d, 0x85, 0xa4, 0x70] ); +pub const KECCAK_EMPTY: H256 = H256([ + 0xc5, 0xd2, 0x46, 0x01, 0x86, 0xf7, 0x23, 0x3c, 0x92, 0x7e, 0x7d, 0xb2, 0xdc, 0xc7, 0x03, 0xc0, + 0xe5, 0x00, 0xb6, 0x53, 0xca, 0x82, 0x27, 0x3b, 0x7b, 0xfa, 0xd8, 0x04, 0x5d, 0x85, 0xa4, 0x70, +]); /// The KECCAK of the RLP encoding of empty data. -pub const KECCAK_NULL_RLP: H256 = H256( [0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e, 0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21] ); +pub const KECCAK_NULL_RLP: H256 = H256([ + 0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e, + 0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21, +]); /// The KECCAK of the RLP encoding of empty list. -pub const KECCAK_EMPTY_LIST_RLP: H256 = H256( [0x1d, 0xcc, 0x4d, 0xe8, 0xde, 0xc7, 0x5d, 0x7a, 0xab, 0x85, 0xb5, 0x67, 0xb6, 0xcc, 0xd4, 0x1a, 0xd3, 0x12, 0x45, 0x1b, 0x94, 0x8a, 0x74, 0x13, 0xf0, 0xa1, 0x42, 0xfd, 0x40, 0xd4, 0x93, 0x47] ); +pub const KECCAK_EMPTY_LIST_RLP: H256 = H256([ + 0x1d, 0xcc, 0x4d, 0xe8, 0xde, 0xc7, 0x5d, 0x7a, 0xab, 0x85, 0xb5, 0x67, 0xb6, 0xcc, 0xd4, 0x1a, + 0xd3, 0x12, 0x45, 0x1b, 0x94, 0x8a, 0x74, 0x13, 0xf0, 0xa1, 0x42, 0xfd, 0x40, 0xd4, 0x93, 0x47, +]); pub fn keccak>(s: T) -> H256 { let mut result = [0u8; 32]; @@ -43,7 +52,7 @@ pub unsafe fn keccak_256_unchecked(out: *mut u8, outlen: usize, input: *const u8 // means that we can reuse the input buffer for both input and output. Keccak::keccak256( slice::from_raw_parts(input, inputlen), - slice::from_raw_parts_mut(out, outlen) + slice::from_raw_parts_mut(out, outlen), ); } @@ -52,15 +61,21 @@ pub unsafe fn keccak_512_unchecked(out: *mut u8, outlen: usize, input: *const u8 // means that we can reuse the input buffer for both input and output. Keccak::keccak512( slice::from_raw_parts(input, inputlen), - slice::from_raw_parts_mut(out, outlen) + slice::from_raw_parts_mut(out, outlen), ); } -pub fn keccak_256(input: &[u8], mut output: &mut [u8]) { Keccak::keccak256(input, &mut output); } +pub fn keccak_256(input: &[u8], mut output: &mut [u8]) { + Keccak::keccak256(input, &mut output); +} -pub fn keccak_512(input: &[u8], mut output: &mut [u8]) { Keccak::keccak512(input, &mut output); } +pub fn keccak_512(input: &[u8], mut output: &mut [u8]) { + Keccak::keccak512(input, &mut output); +} -pub fn write_keccak>(s: T, dest: &mut [u8]) { Keccak::keccak256(s.as_ref(), dest); } +pub fn write_keccak>(s: T, dest: &mut [u8]) { + Keccak::keccak256(s.as_ref(), dest); +} #[cfg(feature = "std")] pub fn keccak_pipe(r: &mut dyn io::BufRead, w: &mut dyn io::Write) -> Result { @@ -106,10 +121,9 @@ mod tests { assert_eq!( keccak([0x41u8; 32]), H256([ - 0x59, 0xca, 0xd5, 0x94, 0x86, 0x73, 0x62, 0x2c, - 0x1d, 0x64, 0xe2, 0x32, 0x24, 0x88, 0xbf, 0x01, - 0x61, 0x9f, 0x7f, 0xf4, 0x57, 0x89, 0x74, 0x1b, - 0x15, 0xa9, 0xf7, 0x82, 0xce, 0x92, 0x90, 0xa8 + 0x59, 0xca, 0xd5, 0x94, 0x86, 0x73, 0x62, 0x2c, 0x1d, 0x64, 0xe2, 0x32, 0x24, 0x88, + 0xbf, 0x01, 0x61, 0x9f, 0x7f, 0xf4, 0x57, 0x89, 0x74, 0x1b, 0x15, 0xa9, 0xf7, 0x82, + 0xce, 0x92, 0x90, 0xa8 ]), ); } @@ -118,12 +132,11 @@ mod tests { fn write_keccak_with_content() { let data: Vec = From::from("hello world"); let expected = vec![ - 0x47, 0x17, 0x32, 0x85, 0xa8, 0xd7, 0x34, 0x1e, - 0x5e, 0x97, 0x2f, 0xc6, 0x77, 0x28, 0x63, 0x84, - 0xf8, 0x02, 0xf8, 0xef, 0x42, 0xa5, 0xec, 0x5f, - 0x03, 0xbb, 0xfa, 0x25, 0x4c, 0xb0, 0x1f, 0xad + 0x47, 0x17, 0x32, 0x85, 0xa8, 0xd7, 0x34, 0x1e, 0x5e, 0x97, 0x2f, 0xc6, 0x77, 0x28, + 0x63, 0x84, 0xf8, 0x02, 0xf8, 0xef, 0x42, 0xa5, 0xec, 0x5f, 0x03, 0xbb, 0xfa, 0x25, + 0x4c, 0xb0, 0x1f, 0xad, ]; - let mut dest = [0u8;32]; + let mut dest = [0u8; 32]; write_keccak(data, &mut dest); assert_eq!(dest, expected.as_ref()); @@ -133,7 +146,7 @@ mod tests { #[test] fn should_keccak_a_file() { use std::fs; - use std::io::{Write, BufReader}; + use std::io::{BufReader, Write}; // given let tmpdir = tempdir::TempDir::new("keccak").unwrap(); @@ -150,6 +163,9 @@ mod tests { let hash = keccak_buffer(&mut file).unwrap(); // then - assert_eq!(format!("{:x}", hash), "68371d7e884c168ae2022c82bd837d51837718a7f7dfb7aa3f753074a35e1d87"); + assert_eq!( + format!("{:x}", hash), + "68371d7e884c168ae2022c82bd837d51837718a7f7dfb7aa3f753074a35e1d87" + ); } } diff --git a/kvdb-memorydb/src/lib.rs b/kvdb-memorydb/src/lib.rs index 2762b6081..f46ff8bf9 100644 --- a/kvdb-memorydb/src/lib.rs +++ b/kvdb-memorydb/src/lib.rs @@ -14,9 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use std::{io, collections::{BTreeMap, HashMap}}; +use kvdb::{DBOp, DBTransaction, DBValue, KeyValueDB}; use parking_lot::RwLock; -use kvdb::{DBValue, DBTransaction, KeyValueDB, DBOp}; +use std::{ + collections::{BTreeMap, HashMap}, + io, +}; /// A key-value database fulfilling the `KeyValueDB` trait, living in memory. /// This is generally intended for tests and is not particularly optimized. @@ -36,7 +39,7 @@ pub fn create(num_cols: u32) -> InMemory { } InMemory { - columns: RwLock::new(cols) + columns: RwLock::new(cols), } } @@ -44,7 +47,10 @@ impl KeyValueDB for InMemory { fn get(&self, col: Option, key: &[u8]) -> io::Result> { let columns = self.columns.read(); match columns.get(&col) { - None => Err(io::Error::new(io::ErrorKind::Other, format!("No such column family: {:?}", col))), + None => Err(io::Error::new( + io::ErrorKind::Other, + format!("No such column family: {:?}", col), + )), Some(map) => Ok(map.get(key).cloned()), } } @@ -53,10 +59,10 @@ impl KeyValueDB for InMemory { let columns = self.columns.read(); match columns.get(&col) { None => None, - Some(map) => - map.iter() - .find(|&(ref k ,_)| k.starts_with(prefix)) - .map(|(_, v)| v.to_vec().into_boxed_slice()) + Some(map) => map + .iter() + .find(|&(ref k, _)| k.starts_with(prefix)) + .map(|(_, v)| v.to_vec().into_boxed_slice()), } } @@ -69,12 +75,12 @@ impl KeyValueDB for InMemory { if let Some(col) = columns.get_mut(&col) { col.insert(key.into_vec(), value); } - }, + } DBOp::Delete { col, key } => { if let Some(col) = columns.get_mut(&col) { col.remove(&*key); } - }, + } } } } @@ -83,32 +89,41 @@ impl KeyValueDB for InMemory { Ok(()) } - fn iter<'a>(&'a self, col: Option) -> Box, Box<[u8]>)> + 'a> { + fn iter<'a>( + &'a self, + col: Option, + ) -> Box, Box<[u8]>)> + 'a> { match self.columns.read().get(&col) { - Some(map) => Box::new( // TODO: worth optimizing at all? + Some(map) => Box::new( + // TODO: worth optimizing at all? map.clone() .into_iter() - .map(|(k, v)| (k.into_boxed_slice(), v.into_vec().into_boxed_slice())) + .map(|(k, v)| (k.into_boxed_slice(), v.into_vec().into_boxed_slice())), ), None => Box::new(None.into_iter()), } } - fn iter_from_prefix<'a>(&'a self, col: Option, prefix: &'a [u8]) - -> Box, Box<[u8]>)> + 'a> - { + fn iter_from_prefix<'a>( + &'a self, + col: Option, + prefix: &'a [u8], + ) -> Box, Box<[u8]>)> + 'a> { match self.columns.read().get(&col) { Some(map) => Box::new( map.clone() .into_iter() .skip_while(move |&(ref k, _)| !k.starts_with(prefix)) - .map(|(k, v)| (k.into_boxed_slice(), v.into_vec().into_boxed_slice())) + .map(|(k, v)| (k.into_boxed_slice(), v.into_vec().into_boxed_slice())), ), None => Box::new(None.into_iter()), } } fn restore(&self, _new_db: &str) -> io::Result<()> { - Err(io::Error::new(io::ErrorKind::Other, "Attempted to restore in-memory database")) + Err(io::Error::new( + io::ErrorKind::Other, + "Attempted to restore in-memory database", + )) } } diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index 7f137953c..ea15d200d 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -14,33 +14,33 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use std::{ - cmp, fs, io, mem, result, error, - collections::HashMap, marker::PhantomData, path::Path -}; +use std::{cmp, collections::HashMap, error, fs, io, marker::PhantomData, mem, path::Path, result}; -use parking_lot::{Mutex, MutexGuard, RwLock}; +use interleaved_ordered::{interleave_ordered, InterleaveOrdered}; use parity_rocksdb::{ - DB, Writable, WriteBatch, WriteOptions, IteratorMode, DBIterator, - Options, BlockBasedOptions, Direction, Cache, Column, ReadOptions + BlockBasedOptions, Cache, Column, DBIterator, Direction, IteratorMode, Options, ReadOptions, + Writable, WriteBatch, WriteOptions, DB, }; -use interleaved_ordered::{interleave_ordered, InterleaveOrdered}; +use parking_lot::{Mutex, MutexGuard, RwLock}; -use log::{debug, warn}; use elastic_array::ElasticArray32; use fs_swap::{swap, swap_nonatomic}; -use kvdb::{KeyValueDB, DBTransaction, DBValue, DBOp}; +use kvdb::{DBOp, DBTransaction, DBValue, KeyValueDB}; +use log::{debug, warn}; #[cfg(target_os = "linux")] use regex::Regex; #[cfg(target_os = "linux")] -use std::process::Command; -#[cfg(target_os = "linux")] use std::fs::File; #[cfg(target_os = "linux")] use std::path::PathBuf; +#[cfg(target_os = "linux")] +use std::process::Command; -fn other_io_err(e: E) -> io::Error where E: Into> { +fn other_io_err(e: E) -> io::Error +where + E: Into>, +{ io::Error::new(io::ErrorKind::Other, e) } @@ -78,10 +78,12 @@ pub fn rotational_from_df_output(df_out: Vec) -> Option { str::from_utf8(df_out.as_slice()) .ok() // Get the drive name. - .and_then(|df_str| Regex::new(r"/dev/(sd[:alpha:]{1,2})") - .ok() - .and_then(|re| re.captures(df_str)) - .and_then(|captures| captures.get(1))) + .and_then(|df_str| { + Regex::new(r"/dev/(sd[:alpha:]{1,2})") + .ok() + .and_then(|re| re.captures(df_str)) + .and_then(|captures| captures.get(1)) + }) // Generate path e.g. /sys/block/sda/queue/rotational .map(|drive_path| { let mut p = PathBuf::from("/sys/block"); @@ -110,9 +112,13 @@ impl CompactionProfile { let mut buffer = [0; 1]; if file.read_exact(&mut buffer).is_ok() { // 0 means not rotational. - if buffer == [48] { return Self::ssd(); } + if buffer == [48] { + return Self::ssd(); + } // 1 means rotational. - if buffer == [49] { return Self::hdd(); } + if buffer == [49] { + return Self::hdd(); + } } } } @@ -213,19 +219,22 @@ struct DBAndColumns { fn col_config(config: &DatabaseConfig, block_opts: &BlockBasedOptions) -> io::Result { let mut opts = Options::new(); - opts.set_parsed_options("level_compaction_dynamic_level_bytes=true").map_err(other_io_err)?; + opts.set_parsed_options("level_compaction_dynamic_level_bytes=true") + .map_err(other_io_err)?; opts.set_block_based_table_factory(block_opts); - opts.set_parsed_options( - &format!("block_based_table_factory={{{};{}}}", - "cache_index_and_filter_blocks=true", - "pin_l0_filter_and_index_blocks_in_cache=true")).map_err(other_io_err)?; + opts.set_parsed_options(&format!( + "block_based_table_factory={{{};{}}}", + "cache_index_and_filter_blocks=true", "pin_l0_filter_and_index_blocks_in_cache=true" + )) + .map_err(other_io_err)?; opts.optimize_level_style_compaction(config.memory_budget_per_col() as i32); opts.set_target_file_size_base(config.compaction.initial_file_size); - opts.set_parsed_options("compression_per_level=").map_err(other_io_err)?; + opts.set_parsed_options("compression_per_level=") + .map_err(other_io_err)?; Ok(opts) } @@ -248,10 +257,16 @@ pub struct Database { } #[inline] -fn check_for_corruption>(path: P, res: result::Result) -> io::Result { +fn check_for_corruption>( + path: P, + res: result::Result, +) -> io::Result { if let Err(ref s) = res { if s.starts_with("Corruption:") { - warn!("DB corrupted: {}. Repair will be triggered on next restart", s); + warn!( + "DB corrupted: {}. Repair will be triggered on next restart", + s + ); let _ = fs::File::create(path.as_ref().join(Database::CORRUPTION_FILE_NAME)); } } @@ -260,7 +275,8 @@ fn check_for_corruption>(path: P, res: result::Result bool { - s.starts_with("Corruption:") || s.starts_with("Invalid argument: You have to open all column families") + s.starts_with("Corruption:") + || s.starts_with("Invalid argument: You have to open all column families") } impl Database { @@ -276,13 +292,16 @@ impl Database { let mut opts = Options::new(); if let Some(rate_limit) = config.compaction.write_rate_limit { - opts.set_parsed_options(&format!("rate_limiter_bytes_per_sec={}", rate_limit)).map_err(other_io_err)?; + opts.set_parsed_options(&format!("rate_limiter_bytes_per_sec={}", rate_limit)) + .map_err(other_io_err)?; } opts.set_use_fsync(false); opts.create_if_missing(true); opts.set_max_open_files(config.max_open_files); - opts.set_parsed_options("keep_log_file_num=1").map_err(other_io_err)?; - opts.set_parsed_options("bytes_per_sync=1048576").map_err(other_io_err)?; + opts.set_parsed_options("keep_log_file_num=1") + .map_err(other_io_err)?; + opts.set_parsed_options("bytes_per_sync=1048576") + .map_err(other_io_err)?; opts.set_db_write_buffer_size(config.memory_budget_per_col() / 2); opts.increase_parallelism(cmp::max(1, ::num_cpus::get() as i32 / 2)); @@ -311,7 +330,7 @@ impl Database { let cfnames: Vec<_> = (0..columns).map(|c| format!("col{}", c)).collect(); let cfnames: Vec<&str> = cfnames.iter().map(|n| n as &str).collect(); - for _ in 0 .. config.columns.unwrap_or(0) { + for _ in 0..config.columns.unwrap_or(0) { cf_options.push(col_config(&config, &block_opts)?); } @@ -324,27 +343,33 @@ impl Database { Some(_) => { match DB::open_cf(&opts, path, &cfnames, &cf_options) { Ok(db) => { - cfs = cfnames.iter().map(|n| db.cf_handle(n) - .expect("rocksdb opens a cf_handle for each cfname; qed")).collect(); + cfs = cfnames + .iter() + .map(|n| { + db.cf_handle(n) + .expect("rocksdb opens a cf_handle for each cfname; qed") + }) + .collect(); Ok(db) } Err(_) => { // retry and create CFs match DB::open_cf(&opts, path, &[], &[]) { Ok(mut db) => { - cfs = cfnames.iter() + cfs = cfnames + .iter() .enumerate() .map(|(i, n)| db.create_cf(n, &cf_options[i])) .collect::<::std::result::Result<_, _>>() .map_err(other_io_err)?; Ok(db) - }, + } err => err, } } } - }, - None => DB::open(&opts, path) + } + None => DB::open(&opts, path), }; let db = match db { @@ -356,20 +381,24 @@ impl Database { match cfnames.is_empty() { true => DB::open(&opts, path).map_err(other_io_err)?, false => { - let db = DB::open_cf(&opts, path, &cfnames, &cf_options).map_err(other_io_err)?; - cfs = cfnames.iter().map(|n| db.cf_handle(n) - .expect("rocksdb opens a cf_handle for each cfname; qed")).collect(); + let db = DB::open_cf(&opts, path, &cfnames, &cf_options) + .map_err(other_io_err)?; + cfs = cfnames + .iter() + .map(|n| { + db.cf_handle(n) + .expect("rocksdb opens a cf_handle for each cfname; qed") + }) + .collect(); db - }, + } } - }, - Err(s) => { - return Err(other_io_err(s)) } + Err(s) => return Err(other_io_err(s)), }; let num_cols = cfs.len(); Ok(Database { - db: RwLock::new(Some(DBAndColumns{ db: db, cfs: cfs })), + db: RwLock::new(Some(DBAndColumns { db: db, cfs: cfs })), config: config.clone(), write_opts: write_opts, overlay: RwLock::new((0..(num_cols + 1)).map(|_| HashMap::new()).collect()), @@ -399,13 +428,13 @@ impl Database { DBOp::Insert { col, key, value } => { let c = Self::to_overlay_column(col); overlay[c].insert(key, KeyState::Insert(value)); - }, + } DBOp::Delete { col, key } => { let c = Self::to_overlay_column(col); overlay[c].insert(key, KeyState::Delete); - }, + } } - }; + } } /// Commit buffered changes to database. Must be called under `flush_lock` @@ -424,30 +453,30 @@ impl Database { } else { batch.delete(key).map_err(other_io_err)?; } - }, + } KeyState::Insert(ref value) => { if c > 0 { - batch.put_cf(cfs[c - 1], key, value).map_err(other_io_err)?; + batch + .put_cf(cfs[c - 1], key, value) + .map_err(other_io_err)?; } else { batch.put(key, value).map_err(other_io_err)?; } - }, + } } } } } - check_for_corruption( - &self.path, - db.write_opt(batch, &self.write_opts))?; + check_for_corruption(&self.path, db.write_opt(batch, &self.write_opts))?; for column in self.flushing.write().iter_mut() { column.clear(); column.shrink_to_fit(); } Ok(()) - }, - None => Err(other_io_err("Database is closed")) + } + None => Err(other_io_err("Database is closed")), } } @@ -458,7 +487,9 @@ impl Database { // The value inside the lock is used to detect that. if *lock { // This can only happen if another flushing thread is terminated unexpectedly. - return Err(other_io_err("Database write failure. Running low on memory perhaps?")) + return Err(other_io_err( + "Database write failure. Running low on memory perhaps?", + )); } *lock = true; let result = self.write_flushing_with_lock(&mut lock); @@ -479,17 +510,21 @@ impl Database { match op { DBOp::Insert { col, key, value } => match col { None => batch.put(&key, &value).map_err(other_io_err)?, - Some(c) => batch.put_cf(cfs[c as usize], &key, &value).map_err(other_io_err)?, + Some(c) => batch + .put_cf(cfs[c as usize], &key, &value) + .map_err(other_io_err)?, }, DBOp::Delete { col, key } => match col { None => batch.delete(&key).map_err(other_io_err)?, - Some(c) => batch.delete_cf(cfs[c as usize], &key).map_err(other_io_err)?, - } + Some(c) => batch + .delete_cf(cfs[c as usize], &key) + .map_err(other_io_err)?, + }, } } check_for_corruption(&self.path, db.write_opt(batch, &self.write_opts)) - }, + } None => Err(other_io_err("Database is closed")), } } @@ -507,16 +542,22 @@ impl Database { match flushing.get(key) { Some(&KeyState::Insert(ref value)) => Ok(Some(value.clone())), Some(&KeyState::Delete) => Ok(None), - None => { - col.map_or_else( - || db.get_opt(key, &self.read_opts).map(|r| r.map(|v| DBValue::from_slice(&v))), - |c| db.get_cf_opt(cfs[c as usize], key, &self.read_opts).map(|r| r.map(|v| DBValue::from_slice(&v)))) - .map_err(other_io_err) - }, + None => col + .map_or_else( + || { + db.get_opt(key, &self.read_opts) + .map(|r| r.map(|v| DBValue::from_slice(&v))) + }, + |c| { + db.get_cf_opt(cfs[c as usize], key, &self.read_opts) + .map(|r| r.map(|v| DBValue::from_slice(&v))) + }, + ) + .map_err(other_io_err), } - }, + } } - }, + } None => Ok(None), } } @@ -527,8 +568,14 @@ impl Database { self.iter_from_prefix(col, prefix).and_then(|mut iter| { match iter.next() { // TODO: use prefix_same_as_start read option (not available in C API currently) - Some((k, v)) => if k[0 .. prefix.len()] == prefix[..] { Some(v) } else { None }, - _ => None + Some((k, v)) => { + if k[0..prefix.len()] == prefix[..] { + Some(v) + } else { + None + } + } + _ => None, } }) } @@ -538,25 +585,31 @@ impl Database { match *self.db.read() { Some(DBAndColumns { ref db, ref cfs }) => { let overlay = &self.overlay.read()[Self::to_overlay_column(col)]; - let mut overlay_data = overlay.iter() + let mut overlay_data = overlay + .iter() .filter_map(|(k, v)| match *v { - KeyState::Insert(ref value) => - Some((k.clone().into_vec().into_boxed_slice(), value.clone().into_vec().into_boxed_slice())), + KeyState::Insert(ref value) => Some(( + k.clone().into_vec().into_boxed_slice(), + value.clone().into_vec().into_boxed_slice(), + )), KeyState::Delete => None, - }).collect::>(); + }) + .collect::>(); overlay_data.sort(); let iter = col.map_or_else( || db.iterator_opt(IteratorMode::Start, &self.read_opts), - |c| db.iterator_cf_opt(cfs[c as usize], IteratorMode::Start, &self.read_opts) - .expect("iterator params are valid; qed") + |c| { + db.iterator_cf_opt(cfs[c as usize], IteratorMode::Start, &self.read_opts) + .expect("iterator params are valid; qed") + }, ); Some(DatabaseIterator { iter: interleave_ordered(overlay_data, iter), _marker: PhantomData, }) - }, + } None => None, } } @@ -564,15 +617,28 @@ impl Database { fn iter_from_prefix(&self, col: Option, prefix: &[u8]) -> Option> { match *self.db.read() { Some(DBAndColumns { ref db, ref cfs }) => { - let iter = col.map_or_else(|| db.iterator_opt(IteratorMode::From(prefix, Direction::Forward), &self.read_opts), - |c| db.iterator_cf_opt(cfs[c as usize], IteratorMode::From(prefix, Direction::Forward), &self.read_opts) - .expect("iterator params are valid; qed")); + let iter = col.map_or_else( + || { + db.iterator_opt( + IteratorMode::From(prefix, Direction::Forward), + &self.read_opts, + ) + }, + |c| { + db.iterator_cf_opt( + cfs[c as usize], + IteratorMode::From(prefix, Direction::Forward), + &self.read_opts, + ) + .expect("iterator params are valid; qed") + }, + ); Some(DatabaseIterator { iter: interleave_ordered(Vec::new(), iter), _marker: PhantomData, }) - }, + } None => None, } } @@ -593,17 +659,20 @@ impl Database { Ok(_) => { // ignore errors let _ = fs::remove_dir_all(new_db); - }, + } Err(err) => { debug!("DB atomic swap failed: {}", err); match swap_nonatomic(new_db, &self.path) { Ok(_) => { // ignore errors let _ = fs::remove_dir_all(new_db); - }, + } Err(err) => { warn!("Failed to swap DB directories: {:?}", err); - return Err(io::Error::new(io::ErrorKind::Other, "DB restoration failed: could not swap DB directories")); + return Err(io::Error::new( + io::ErrorKind::Other, + "DB restoration failed: could not swap DB directories", + )); } } } @@ -619,8 +688,16 @@ impl Database { /// The number of non-default column families. pub fn num_columns(&self) -> u32 { - self.db.read().as_ref() - .and_then(|db| if db.cfs.is_empty() { None } else { Some(db.cfs.len()) } ) + self.db + .read() + .as_ref() + .and_then(|db| { + if db.cfs.is_empty() { + None + } else { + Some(db.cfs.len()) + } + }) .map(|n| n as u32) .unwrap_or(0) } @@ -628,14 +705,17 @@ impl Database { /// Drop a column family. pub fn drop_column(&self) -> io::Result<()> { match *self.db.write() { - Some(DBAndColumns { ref mut db, ref mut cfs }) => { + Some(DBAndColumns { + ref mut db, + ref mut cfs, + }) => { if let Some(col) = cfs.pop() { let name = format!("col{}", cfs.len()); drop(col); db.drop_cf(&name).map_err(other_io_err)?; } Ok(()) - }, + } None => Ok(()), } } @@ -643,12 +723,18 @@ impl Database { /// Add a column family. pub fn add_column(&self) -> io::Result<()> { match *self.db.write() { - Some(DBAndColumns { ref mut db, ref mut cfs }) => { + Some(DBAndColumns { + ref mut db, + ref mut cfs, + }) => { let col = cfs.len() as u32; let name = format!("col{}", col); - cfs.push(db.create_cf(&name, &col_config(&self.config, &self.block_opts)?).map_err(other_io_err)?); + cfs.push( + db.create_cf(&name, &col_config(&self.config, &self.block_opts)?) + .map_err(other_io_err)?, + ); Ok(()) - }, + } None => Ok(()), } } @@ -677,14 +763,19 @@ impl KeyValueDB for Database { Database::flush(self) } - fn iter<'a>(&'a self, col: Option) -> Box, Box<[u8]>)> + 'a> { + fn iter<'a>( + &'a self, + col: Option, + ) -> Box, Box<[u8]>)> + 'a> { let unboxed = Database::iter(self, col); Box::new(unboxed.into_iter().flat_map(|inner| inner)) } - fn iter_from_prefix<'a>(&'a self, col: Option, prefix: &'a [u8]) - -> Box, Box<[u8]>)> + 'a> - { + fn iter_from_prefix<'a>( + &'a self, + col: Option, + prefix: &'a [u8], + ) -> Box, Box<[u8]>)> + 'a> { let unboxed = Database::iter_from_prefix(self, col, prefix); Box::new(unboxed.into_iter().flat_map(|inner| inner)) } @@ -703,17 +794,23 @@ impl Drop for Database { #[cfg(test)] mod tests { + use super::*; + use ethereum_types::H256; use std::str::FromStr; use tempdir::TempDir; - use ethereum_types::H256; - use super::*; fn test_db(config: &DatabaseConfig) { let tempdir = TempDir::new("").unwrap(); let db = Database::open(config, tempdir.path().to_str().unwrap()).unwrap(); - let key1 = H256::from_str("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc").unwrap(); - let key2 = H256::from_str("03c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc").unwrap(); - let key3 = H256::from_str("01c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc").unwrap(); + let key1 = + H256::from_str("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc") + .unwrap(); + let key2 = + H256::from_str("03c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc") + .unwrap(); + let key3 = + H256::from_str("01c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc") + .unwrap(); let mut batch = db.transaction(); batch.put(None, key1.as_bytes(), b"cat"); @@ -744,9 +841,15 @@ mod tests { transaction.delete(None, key1.as_bytes()); db.write(transaction).unwrap(); assert!(db.get(None, key1.as_bytes()).unwrap().is_none()); - assert_eq!(&*db.get(None, key3.as_bytes()).unwrap().unwrap(), b"elephant"); - - assert_eq!(&*db.get_by_prefix(None, key3.as_bytes()).unwrap(), b"elephant"); + assert_eq!( + &*db.get(None, key3.as_bytes()).unwrap().unwrap(), + b"elephant" + ); + + assert_eq!( + &*db.get_by_prefix(None, key3.as_bytes()).unwrap(), + b"elephant" + ); assert_eq!(&*db.get_by_prefix(None, key2.as_bytes()).unwrap(), b"dog"); let mut transaction = db.transaction(); @@ -773,7 +876,14 @@ mod tests { fn df_to_rotational() { use std::path::PathBuf; // Example df output. - let example_df = vec![70, 105, 108, 101, 115, 121, 115, 116, 101, 109, 32, 32, 32, 32, 32, 49, 75, 45, 98, 108, 111, 99, 107, 115, 32, 32, 32, 32, 32, 85, 115, 101, 100, 32, 65, 118, 97, 105, 108, 97, 98, 108, 101, 32, 85, 115, 101, 37, 32, 77, 111, 117, 110, 116, 101, 100, 32, 111, 110, 10, 47, 100, 101, 118, 47, 115, 100, 97, 49, 32, 32, 32, 32, 32, 32, 32, 54, 49, 52, 48, 57, 51, 48, 48, 32, 51, 56, 56, 50, 50, 50, 51, 54, 32, 32, 49, 57, 52, 52, 52, 54, 49, 54, 32, 32, 54, 55, 37, 32, 47, 10]; + let example_df = vec![ + 70, 105, 108, 101, 115, 121, 115, 116, 101, 109, 32, 32, 32, 32, 32, 49, 75, 45, 98, + 108, 111, 99, 107, 115, 32, 32, 32, 32, 32, 85, 115, 101, 100, 32, 65, 118, 97, 105, + 108, 97, 98, 108, 101, 32, 85, 115, 101, 37, 32, 77, 111, 117, 110, 116, 101, 100, 32, + 111, 110, 10, 47, 100, 101, 118, 47, 115, 100, 97, 49, 32, 32, 32, 32, 32, 32, 32, 54, + 49, 52, 48, 57, 51, 48, 48, 32, 51, 56, 56, 50, 50, 50, 51, 54, 32, 32, 49, 57, 52, 52, + 52, 54, 49, 54, 32, 32, 54, 55, 37, 32, 47, 10, + ]; let expected_output = Some(PathBuf::from("/sys/block/sda/queue/rotational")); assert_eq!(rotational_from_df_output(example_df), expected_output); } diff --git a/kvdb-web/src/error.rs b/kvdb-web/src/error.rs index f45295dc9..5dff3ee63 100644 --- a/kvdb-web/src/error.rs +++ b/kvdb-web/src/error.rs @@ -18,7 +18,6 @@ use std::fmt; - /// An error that occurred when working with IndexedDB. #[derive(Clone, PartialEq, Debug)] pub enum Error { @@ -48,11 +47,9 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Error::WindowNotAvailable => write!(f, "Accessing a Window has failed"), - Error::NotSupported(ref err) => write!( - f, - "IndexedDB is not supported by your browser: {}", - err, - ), + Error::NotSupported(ref err) => { + write!(f, "IndexedDB is not supported by your browser: {}", err,) + } Error::__Nonexhaustive => unreachable!(), } } diff --git a/kvdb-web/src/indexed_db.rs b/kvdb-web/src/indexed_db.rs index 09664a267..4876327b5 100644 --- a/kvdb-web/src/indexed_db.rs +++ b/kvdb-web/src/indexed_db.rs @@ -16,24 +16,21 @@ //! Utility functions to interact with IndexedDB browser API. -use wasm_bindgen::{JsCast, JsValue, closure::Closure}; +use js_sys::{Array, ArrayBuffer, Uint8Array}; +use wasm_bindgen::{closure::Closure, JsCast, JsValue}; use web_sys::{ - IdbDatabase, IdbRequest, IdbOpenDbRequest, - Event, IdbCursorWithValue, - IdbTransactionMode, + Event, IdbCursorWithValue, IdbDatabase, IdbOpenDbRequest, IdbRequest, IdbTransactionMode, }; -use js_sys::{Array, Uint8Array, ArrayBuffer}; use futures::channel; use futures::prelude::*; use kvdb::{DBOp, DBTransaction}; -use std::ops::Deref; use log::{debug, warn}; +use std::ops::Deref; - -use crate::{Column, error::Error}; +use crate::{error::Error, Column}; pub struct IndexedDB { pub version: u32, @@ -43,7 +40,11 @@ pub struct IndexedDB { /// Opens the IndexedDB with the given name, version and the specified number of columns /// (including the default one). -pub fn open(name: &str, version: Option, columns: u32) -> impl Future> { +pub fn open( + name: &str, + version: Option, + columns: u32, +) -> impl Future> { let (tx, rx) = channel::oneshot::channel::(); let window = match web_sys::window() { @@ -54,13 +55,18 @@ pub fn open(name: &str, version: Option, columns: u32) -> impl Future idb_factory.expect("We can't get a null pointer back; qed"), - Err(err) => return future::Either::Right(future::err(Error::NotSupported(format!("{:?}", err)))), + Err(err) => { + return future::Either::Right(future::err(Error::NotSupported(format!("{:?}", err)))) + } }; let open_request = match version { - Some(version) => idb_factory.open_with_u32(name, version) + Some(version) => idb_factory + .open_with_u32(name, version) + .expect("TypeError is not possible with Rust; qed"), + None => idb_factory + .open(name) .expect("TypeError is not possible with Rust; qed"), - None => idb_factory.open(name).expect("TypeError is not possible with Rust; qed"), }; try_create_missing_stores(&open_request, columns, version); @@ -68,7 +74,9 @@ pub fn open(name: &str, version: Option, columns: u32) -> impl Future().expect("Event target is IdbRequest; qed"); + let req = target + .dyn_ref::() + .expect("Event target is IdbRequest; qed"); let result = req .result() @@ -90,9 +98,7 @@ pub fn open(name: &str, version: Option, columns: u32) -> impl Future String { @@ -103,7 +109,6 @@ fn column_to_number(column: Column) -> u32 { column.map(|c| c + 1).unwrap_or_default() } - // Returns js objects representing store names for each column fn store_names_js(columns: u32) -> Array { let column_names = (0..=columns).map(store_name); @@ -118,15 +123,24 @@ fn store_names_js(columns: u32) -> Array { fn try_create_missing_stores(req: &IdbOpenDbRequest, columns: u32, version: Option) { let on_upgradeneeded = Closure::once(move |event: &Event| { - debug!("Upgrading or creating the database to version {:?}, columns {}", version, columns); + debug!( + "Upgrading or creating the database to version {:?}, columns {}", + version, columns + ); // Extract database handle from the event let target = event.target().expect("Event should have a target; qed"); - let req = target.dyn_ref::().expect("Event target is IdbRequest; qed"); + let req = target + .dyn_ref::() + .expect("Event target is IdbRequest; qed"); let result = req.result().expect("IdbRequest should have a result; qed"); let db: &IdbDatabase = result.unchecked_ref(); let previous_columns = db.object_store_names().length(); - debug!("Previous version: {}, columns {}", db.version(), previous_columns); + debug!( + "Previous version: {}, columns {}", + db.version(), + previous_columns + ); for name in (previous_columns..=columns).map(store_name) { let res = db.create_object_store(name.as_str()); @@ -150,14 +164,18 @@ pub fn idb_commit_transaction( // Create a transaction let mode = IdbTransactionMode::Readwrite; - let idb_txn = idb.transaction_with_str_sequence_and_mode(&store_names_js, mode) + let idb_txn = idb + .transaction_with_str_sequence_and_mode(&store_names_js, mode) .expect("The provided mode and store names are valid; qed"); // Open object stores (columns) - let object_stores = (0..=columns).map(|n| { - idb_txn.object_store(store_name(n).as_str()) - .expect("Object stores were created in try_create_object_stores; qed") - }).collect::>(); + let object_stores = (0..=columns) + .map(|n| { + idb_txn + .object_store(store_name(n).as_str()) + .expect("Object stores were created in try_create_object_stores; qed") + }) + .collect::>(); for op in &txn.ops { match op { @@ -173,7 +191,7 @@ pub fn idb_commit_transaction( if let Err(err) = res { warn!("error inserting key/values into col_{}: {:?}", column, err); } - }, + } DBOp::Delete { col, key } => { let column = column_to_number(*col) as usize; @@ -185,7 +203,7 @@ pub fn idb_commit_transaction( if let Err(err) = res { warn!("error deleting key from col_{}: {:?}", column, err); } - }, + } } } @@ -206,24 +224,30 @@ pub fn idb_commit_transaction( rx.map(|_| ()) } - /// Returns a cursor to a database column with the given column number. pub fn idb_cursor(idb: &IdbDatabase, col: u32) -> impl Stream, Vec)> { // TODO: we could read all the columns in one db transaction let store_name = store_name(col); let store_name = store_name.as_str(); - let txn = idb.transaction_with_str(store_name) + let txn = idb + .transaction_with_str(store_name) .expect("The stores were created on open: {}; qed"); - let store = txn.object_store(store_name).expect("Opening a store shouldn't fail; qed"); - let cursor = store.open_cursor().expect("Opening a cursor shouldn't fail; qed"); + let store = txn + .object_store(store_name) + .expect("Opening a store shouldn't fail; qed"); + let cursor = store + .open_cursor() + .expect("Opening a cursor shouldn't fail; qed"); let (tx, rx) = channel::mpsc::unbounded(); let on_cursor = Closure::wrap(Box::new(move |event: &Event| { // Extract the cursor from the event let target = event.target().expect("on_cursor should have a target; qed"); - let req = target.dyn_ref::().expect("target should be IdbRequest; qed"); + let req = target + .dyn_ref::() + .expect("target should be IdbRequest; qed"); let result = req.result().expect("IdbRequest should have a result; qed"); let cursor: &IdbCursorWithValue = result.unchecked_ref(); diff --git a/kvdb-web/src/lib.rs b/kvdb-web/src/lib.rs index f966f69ce..571107c0e 100644 --- a/kvdb-web/src/lib.rs +++ b/kvdb-web/src/lib.rs @@ -24,12 +24,12 @@ mod error; mod indexed_db; +use kvdb::{DBTransaction, DBValue}; +use kvdb_memorydb::{self as in_memory, InMemory}; +use send_wrapper::SendWrapper; use std::io; use std::rc::Rc; use std::sync::Mutex; -use kvdb::{DBValue, DBTransaction}; -use kvdb_memorydb::{InMemory, self as in_memory}; -use send_wrapper::SendWrapper; pub use error::Error; pub use kvdb::KeyValueDB; @@ -54,66 +54,85 @@ fn number_to_column(col: u32) -> Column { col.checked_sub(1) } - impl Database { /// Opens the database with the given name, /// and the specified number of columns (not including the default one). - pub fn open(name: String, columns: u32) -> impl Future> { + pub fn open( + name: String, + columns: u32, + ) -> impl Future> { // let's try to open the latest version of the db first let open_request = indexed_db::open(name.as_str(), None, columns); let name_clone = name.clone(); - open_request.then(move |db| { - let db = match db { - Ok(db) => db, - Err(err) => return future::Either::Right(future::err(err)), - }; - - // If we need more column than the latest version has, - // then bump the version (+ 1 for the default column). - // In order to bump the version, we close the database - // and reopen it with a higher version than it was opened with previously. - // cf. https://github.com/paritytech/parity-common/pull/202#discussion_r321221751 - if columns + 1 > db.columns { - let next_version = db.version + 1; - drop(db); - future::Either::Left(indexed_db::open(name.as_str(), Some(next_version), columns).boxed()) - } else { - future::Either::Left(future::ok(db).boxed()) - } - // populate the in_memory db from the IndexedDB - }).then(move |db| { - let db = match db { - Ok(db) => db, - Err(err) => return future::Either::Right(future::err(err)), - }; - - let indexed_db::IndexedDB { version, inner, .. } = db; - let rc = Rc::new(inner.take()); - let weak = Rc::downgrade(&rc); - // read the columns from the IndexedDB - future::Either::Left(stream::iter(0..=columns).map(move |n| { - let db = weak.upgrade().expect("rc should live at least as long; qed"); - indexed_db::idb_cursor(&db, n).fold(DBTransaction::new(), move |mut txn, (key, value)| { - let column = number_to_column(n); - txn.put_vec(column, key.as_ref(), value); - future::ready(txn) - }) - // write each column into memory - }).fold(in_memory::create(columns), |m, txn| { - txn.then(|txn| { - m.write_buffered(txn); - future::ready(m) - }) - }).then(move |in_memory| future::ok(Database { - name: name_clone, - version, - columns, - in_memory, - indexed_db: Mutex::new(SendWrapper::new( - Rc::try_unwrap(rc).expect("should have only 1 ref at this point; qed") - )), - }))) - }) + open_request + .then(move |db| { + let db = match db { + Ok(db) => db, + Err(err) => return future::Either::Right(future::err(err)), + }; + + // If we need more column than the latest version has, + // then bump the version (+ 1 for the default column). + // In order to bump the version, we close the database + // and reopen it with a higher version than it was opened with previously. + // cf. https://github.com/paritytech/parity-common/pull/202#discussion_r321221751 + if columns + 1 > db.columns { + let next_version = db.version + 1; + drop(db); + future::Either::Left( + indexed_db::open(name.as_str(), Some(next_version), columns).boxed(), + ) + } else { + future::Either::Left(future::ok(db).boxed()) + } + // populate the in_memory db from the IndexedDB + }) + .then(move |db| { + let db = match db { + Ok(db) => db, + Err(err) => return future::Either::Right(future::err(err)), + }; + + let indexed_db::IndexedDB { version, inner, .. } = db; + let rc = Rc::new(inner.take()); + let weak = Rc::downgrade(&rc); + // read the columns from the IndexedDB + future::Either::Left( + stream::iter(0..=columns) + .map(move |n| { + let db = weak + .upgrade() + .expect("rc should live at least as long; qed"); + indexed_db::idb_cursor(&db, n).fold( + DBTransaction::new(), + move |mut txn, (key, value)| { + let column = number_to_column(n); + txn.put_vec(column, key.as_ref(), value); + future::ready(txn) + }, + ) + // write each column into memory + }) + .fold(in_memory::create(columns), |m, txn| { + txn.then(|txn| { + m.write_buffered(txn); + future::ready(m) + }) + }) + .then(move |in_memory| { + future::ok(Database { + name: name_clone, + version, + columns, + in_memory, + indexed_db: Mutex::new(SendWrapper::new( + Rc::try_unwrap(rc) + .expect("should have only 1 ref at this point; qed"), + )), + }) + }), + ) + }) } /// Get the database name. @@ -156,14 +175,19 @@ impl KeyValueDB for Database { } // NOTE: clones the whole db - fn iter<'a>(&'a self, col: Option) -> Box, Box<[u8]>)> + 'a> { + fn iter<'a>( + &'a self, + col: Option, + ) -> Box, Box<[u8]>)> + 'a> { self.in_memory.iter(col) } // NOTE: clones the whole db - fn iter_from_prefix<'a>(&'a self, col: Option, prefix: &'a [u8]) - -> Box, Box<[u8]>)> + 'a> - { + fn iter_from_prefix<'a>( + &'a self, + col: Option, + prefix: &'a [u8], + ) -> Box, Box<[u8]>)> + 'a> { self.in_memory.iter_from_prefix(col, prefix) } diff --git a/kvdb-web/tests/indexed_db.rs b/kvdb-web/tests/indexed_db.rs index 1286faf66..0824a5760 100644 --- a/kvdb-web/tests/indexed_db.rs +++ b/kvdb-web/tests/indexed_db.rs @@ -21,8 +21,8 @@ use futures::future::{self, FutureExt as _, TryFutureExt as _}; use kvdb_web::{Database, KeyValueDB as _}; -use wasm_bindgen_test::*; use wasm_bindgen::JsValue; +use wasm_bindgen_test::*; wasm_bindgen_test_configure!(run_in_browser); @@ -31,36 +31,37 @@ fn reopen_the_database_with_more_columns() -> impl futures01::Future impl future::Future { - Database::open("MyAsyncTest".into(), col) - .unwrap_or_else(|err| panic!("{}", err)) + Database::open("MyAsyncTest".into(), col).unwrap_or_else(|err| panic!("{}", err)) } - let fut = open_db(1).then(|db| { - // Write a value into the database - let mut batch = db.transaction(); - batch.put(None, b"hello", b"world"); - db.write_buffered(batch); + let fut = open_db(1) + .then(|db| { + // Write a value into the database + let mut batch = db.transaction(); + batch.put(None, b"hello", b"world"); + db.write_buffered(batch); - assert_eq!(db.get(None, b"hello").unwrap().unwrap().as_ref(), b"world"); + assert_eq!(db.get(None, b"hello").unwrap().unwrap().as_ref(), b"world"); - // Check the database version - assert_eq!(db.version(), 1); + // Check the database version + assert_eq!(db.version(), 1); - // Close the database - drop(db); + // Close the database + drop(db); - // Reopen it again with 3 columns - open_db(3) - }).map(|db| { - // The value should still be present - assert_eq!(db.get(None, b"hello").unwrap().unwrap().as_ref(), b"world"); - assert!(db.get(None, b"trash").unwrap().is_none()); + // Reopen it again with 3 columns + open_db(3) + }) + .map(|db| { + // The value should still be present + assert_eq!(db.get(None, b"hello").unwrap().unwrap().as_ref(), b"world"); + assert!(db.get(None, b"trash").unwrap().is_none()); - // The version should be bumped - assert_eq!(db.version(), 2); + // The version should be bumped + assert_eq!(db.version(), 2); - Ok(()) - }); + Ok(()) + }); compat::Compat::new(fut) } diff --git a/kvdb/src/lib.rs b/kvdb/src/lib.rs index 93a4902fd..dc5fbbb6f 100644 --- a/kvdb/src/lib.rs +++ b/kvdb/src/lib.rs @@ -16,11 +16,11 @@ //! Key-Value store abstraction with `RocksDB` backend. +use bytes::Bytes; +use elastic_array::{ElasticArray128, ElasticArray32}; use std::io; use std::path::Path; use std::sync::Arc; -use elastic_array::{ElasticArray128, ElasticArray32}; -use bytes::Bytes; /// Required length of prefixes. pub const PREFIX_LEN: usize = 12; @@ -46,7 +46,7 @@ pub enum DBOp { Delete { col: Option, key: ElasticArray32, - } + }, } impl DBOp { @@ -76,7 +76,7 @@ impl DBTransaction { /// Create new transaction with capacity. pub fn with_capacity(cap: usize) -> DBTransaction { DBTransaction { - ops: Vec::with_capacity(cap) + ops: Vec::with_capacity(cap), } } @@ -133,7 +133,9 @@ impl DBTransaction { /// implementation. pub trait KeyValueDB: Sync + Send { /// Helper to create a new transaction. - fn transaction(&self) -> DBTransaction { DBTransaction::new() } + fn transaction(&self) -> DBTransaction { + DBTransaction::new() + } /// Get a value by key. fn get(&self, col: Option, key: &[u8]) -> io::Result>; @@ -154,12 +156,17 @@ pub trait KeyValueDB: Sync + Send { fn flush(&self) -> io::Result<()>; /// Iterate over flushed data for a given column. - fn iter<'a>(&'a self, col: Option) - -> Box, Box<[u8]>)> + 'a>; + fn iter<'a>( + &'a self, + col: Option, + ) -> Box, Box<[u8]>)> + 'a>; /// Iterate over flushed data for a given column, starting from a given prefix. - fn iter_from_prefix<'a>(&'a self, col: Option, prefix: &'a [u8]) - -> Box, Box<[u8]>)> + 'a>; + fn iter_from_prefix<'a>( + &'a self, + col: Option, + prefix: &'a [u8], + ) -> Box, Box<[u8]>)> + 'a>; /// Attempt to replace this database with a new one located at the given path. fn restore(&self, new_db: &str) -> io::Result<()>; diff --git a/parity-bytes/src/lib.rs b/parity-bytes/src/lib.rs index 41bfd6134..648304670 100644 --- a/parity-bytes/src/lib.rs +++ b/parity-bytes/src/lib.rs @@ -75,7 +75,7 @@ pub enum BytesRef<'a> { /// This is a reference to a vector Flexible(&'a mut Bytes), /// This is a reference to a slice - Fixed(&'a mut [u8]) + Fixed(&'a mut [u8]), } impl<'a> BytesRef<'a> { @@ -86,18 +86,23 @@ impl<'a> BytesRef<'a> { match *self { BytesRef::Flexible(ref mut data) => { let data_len = data.len(); - let wrote = input.len() + if data_len > offset { 0 } else { offset - data_len }; + let wrote = input.len() + + if data_len > offset { + 0 + } else { + offset - data_len + }; data.resize(offset, 0); data.extend_from_slice(input); wrote - }, + } BytesRef::Fixed(ref mut data) if offset < data.len() => { let max = min(data.len() - offset, input.len()); data[offset..(max + offset)].copy_from_slice(&input[..max]); max - }, - _ => 0 + } + _ => 0, } } } @@ -127,9 +132,9 @@ pub type Bytes = Vec; #[cfg(test)] mod tests { + use super::BytesRef; #[cfg(not(feature = "std"))] use alloc::vec; - use super::BytesRef; #[test] fn should_write_bytes_to_fixed_bytesref() { diff --git a/parity-crypto/benches/bench.rs b/parity-crypto/benches/bench.rs index aa2e0fb78..370a37e94 100644 --- a/parity-crypto/benches/bench.rs +++ b/parity-crypto/benches/bench.rs @@ -17,44 +17,42 @@ #[macro_use] extern crate criterion; -use criterion::{Criterion, Bencher}; use crate::parity_crypto::publickey::Generator; +use criterion::{Bencher, Criterion}; -criterion_group!( - benches, - input_len, - ecdh_agree, -); +criterion_group!(benches, input_len, ecdh_agree,); criterion_main!(benches); /// general benches for multiple input size fn input_len(c: &mut Criterion) { - - c.bench_function_over_inputs("ripemd", + c.bench_function_over_inputs( + "ripemd", |b: &mut Bencher, size: &usize| { let data = vec![0u8; *size]; b.iter(|| parity_crypto::digest::ripemd160(&data[..])); }, - vec![100, 500, 1_000, 10_000, 100_000] + vec![100, 500, 1_000, 10_000, 100_000], ); - c.bench_function_over_inputs("aes_ctr", + c.bench_function_over_inputs( + "aes_ctr", |b: &mut Bencher, size: &usize| { let data = vec![0u8; *size]; let mut dest = vec![0; *size]; let k = [0; 16]; let iv = [0; 16]; - b.iter(||{ - parity_crypto::aes::encrypt_128_ctr(&k[..], &iv[..], &data[..], &mut dest[..]).unwrap(); + b.iter(|| { + parity_crypto::aes::encrypt_128_ctr(&k[..], &iv[..], &data[..], &mut dest[..]) + .unwrap(); // same as encrypt but add it just in case - parity_crypto::aes::decrypt_128_ctr(&k[..], &iv[..], &data[..], &mut dest[..]).unwrap(); + parity_crypto::aes::decrypt_128_ctr(&k[..], &iv[..], &data[..], &mut dest[..]) + .unwrap(); }); }, - vec![100, 500, 1_000, 10_000, 100_000] + vec![100, 500, 1_000, 10_000, 100_000], ); - } fn ecdh_agree(c: &mut Criterion) { @@ -62,5 +60,7 @@ fn ecdh_agree(c: &mut Criterion) { let public = keypair.public().clone(); let secret = keypair.secret().clone(); - c.bench_function("ecdh_agree", move |b| b.iter(|| parity_crypto::publickey::ecdh::agree(&secret, &public))); -} \ No newline at end of file + c.bench_function("ecdh_agree", move |b| { + b.iter(|| parity_crypto::publickey::ecdh::agree(&secret, &public)) + }); +} diff --git a/parity-crypto/src/aes.rs b/parity-crypto/src/aes.rs index e13300524..3a2eb3fa8 100644 --- a/parity-crypto/src/aes.rs +++ b/parity-crypto/src/aes.rs @@ -14,24 +14,20 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use aes::block_cipher_trait::generic_array::GenericArray; +use aes::{Aes128, Aes256}; +use aes_ctr::stream_cipher::{NewStreamCipher, SyncStreamCipher}; use block_modes::{ - BlockMode, - Cbc, - Ecb, - block_padding::{Pkcs7, ZeroPadding} + block_padding::{Pkcs7, ZeroPadding}, + BlockMode, Cbc, Ecb, }; -use aes_ctr::stream_cipher::{ NewStreamCipher, SyncStreamCipher }; -use aes::{ Aes128, Aes256 }; -use aes::block_cipher_trait::generic_array::GenericArray; use crate::error::SymmError; - /// One time encoder/decoder for Ecb mode Aes256 with zero padding pub struct AesEcb256(Ecb); impl AesEcb256 { - /// New encoder/decoder, no iv for ecb pub fn new(key: &[u8]) -> Result { Ok(AesEcb256(Ecb::new_var(key, &[])?)) @@ -40,7 +36,7 @@ impl AesEcb256 { /// Encrypt data in place without padding. The data length must be a multiple /// of the block size. pub fn encrypt(self, content: &mut [u8]) -> Result<(), SymmError> { - let len = content.len(); + let len = content.len(); self.0.encrypt(content, len)?; Ok(()) } @@ -53,29 +49,28 @@ impl AesEcb256 { } } - /// Reusable encoder/decoder for Aes256 in Ctr mode and no padding pub struct AesCtr256(aes_ctr::Aes256Ctr); impl AesCtr256 { - /// New encoder/decoder pub fn new(key: &[u8], iv: &[u8]) -> Result { - Ok(AesCtr256( - aes_ctr::Aes256Ctr::new(GenericArray::from_slice(key), GenericArray::from_slice(iv)) - )) + Ok(AesCtr256(aes_ctr::Aes256Ctr::new( + GenericArray::from_slice(key), + GenericArray::from_slice(iv), + ))) } /// In place encrypt a content without padding, the content length must be a multiple /// of the block size. - pub fn encrypt(&mut self, content: &mut[u8]) -> Result<(), SymmError> { + pub fn encrypt(&mut self, content: &mut [u8]) -> Result<(), SymmError> { self.0.try_apply_keystream(content)?; Ok(()) } /// In place decrypt a content without padding, the content length must be a multiple /// of the block size. - pub fn decrypt(&mut self, content: &mut[u8]) -> Result<(), SymmError> { + pub fn decrypt(&mut self, content: &mut [u8]) -> Result<(), SymmError> { self.0.try_apply_keystream(content)?; Ok(()) } @@ -86,15 +81,17 @@ impl AesCtr256 { /// Key (`k`) length and initialisation vector (`iv`) length have to be 16 bytes each. /// An error is returned if the input lengths are invalid. /// If possible prefer `inplace_encrypt_128_ctr` to avoid a slice copy. -pub fn encrypt_128_ctr(k: &[u8], iv: &[u8], plain: &[u8], dest: &mut [u8]) -> Result<(), SymmError> { - let mut encryptor = aes_ctr::Aes128Ctr::new( - GenericArray::from_slice(k), - GenericArray::from_slice(iv), - ); +pub fn encrypt_128_ctr( + k: &[u8], + iv: &[u8], + plain: &[u8], + dest: &mut [u8], +) -> Result<(), SymmError> { + let mut encryptor = + aes_ctr::Aes128Ctr::new(GenericArray::from_slice(k), GenericArray::from_slice(iv)); &mut dest[..plain.len()].copy_from_slice(plain); encryptor.try_apply_keystream(dest)?; Ok(()) - } /// Encrypt a message (CTR mode). @@ -102,13 +99,10 @@ pub fn encrypt_128_ctr(k: &[u8], iv: &[u8], plain: &[u8], dest: &mut [u8]) -> Re /// Key (`k`) length and initialisation vector (`iv`) length have to be 16 bytes each. /// An error is returned if the input lengths are invalid. pub fn inplace_encrypt_128_ctr(k: &[u8], iv: &[u8], data: &mut [u8]) -> Result<(), SymmError> { - let mut encryptor = aes_ctr::Aes128Ctr::new( - GenericArray::from_slice(k), - GenericArray::from_slice(iv), - ); + let mut encryptor = + aes_ctr::Aes128Ctr::new(GenericArray::from_slice(k), GenericArray::from_slice(iv)); encryptor.try_apply_keystream(data)?; Ok(()) - } /// Decrypt a message (CTR mode). @@ -116,11 +110,14 @@ pub fn inplace_encrypt_128_ctr(k: &[u8], iv: &[u8], data: &mut [u8]) -> Result<( /// Key (`k`) length and initialisation vector (`iv`) length have to be 16 bytes each. /// An error is returned if the input lengths are invalid. /// If possible prefer `inplace_decrypt_128_ctr` instead. -pub fn decrypt_128_ctr(k: &[u8], iv: &[u8], encrypted: &[u8], dest: &mut [u8]) -> Result<(), SymmError> { - let mut encryptor = aes_ctr::Aes128Ctr::new( - GenericArray::from_slice(k), - GenericArray::from_slice(iv), - ); +pub fn decrypt_128_ctr( + k: &[u8], + iv: &[u8], + encrypted: &[u8], + dest: &mut [u8], +) -> Result<(), SymmError> { + let mut encryptor = + aes_ctr::Aes128Ctr::new(GenericArray::from_slice(k), GenericArray::from_slice(iv)); &mut dest[..encrypted.len()].copy_from_slice(encrypted); encryptor.try_apply_keystream(dest)?; @@ -132,37 +129,41 @@ pub fn decrypt_128_ctr(k: &[u8], iv: &[u8], encrypted: &[u8], dest: &mut [u8]) - /// Key (`k`) length and initialisation vector (`iv`) length have to be 16 bytes each. /// An error is returned if the input lengths are invalid. pub fn inplace_decrypt_128_ctr(k: &[u8], iv: &[u8], data: &mut [u8]) -> Result<(), SymmError> { - let mut encryptor = aes_ctr::Aes128Ctr::new( - GenericArray::from_slice(k), - GenericArray::from_slice(iv), - ); + let mut encryptor = + aes_ctr::Aes128Ctr::new(GenericArray::from_slice(k), GenericArray::from_slice(iv)); encryptor.try_apply_keystream(data)?; Ok(()) } - /// Decrypt a message (CBC mode). /// /// Key (`k`) length and initialisation vector (`iv`) length have to be 16 bytes each. /// An error is returned if the input lengths are invalid. -pub fn decrypt_128_cbc(k: &[u8], iv: &[u8], encrypted: &[u8], dest: &mut [u8]) -> Result { +pub fn decrypt_128_cbc( + k: &[u8], + iv: &[u8], + encrypted: &[u8], + dest: &mut [u8], +) -> Result { let encryptor = Cbc::::new_var(k, iv)?; &mut dest[..encrypted.len()].copy_from_slice(encrypted); - let unpad_length = { - encryptor.decrypt(&mut dest[..encrypted.len()])?.len() - }; + let unpad_length = { encryptor.decrypt(&mut dest[..encrypted.len()])?.len() }; Ok(unpad_length) } - #[cfg(test)] mod tests { use super::*; // only use for test could be expose in the future - fn encrypt_128_cbc(k: &[u8], iv: &[u8], plain: &[u8], dest: &mut [u8]) -> Result<(), SymmError> { + fn encrypt_128_cbc( + k: &[u8], + iv: &[u8], + plain: &[u8], + dest: &mut [u8], + ) -> Result<(), SymmError> { let encryptor = Cbc::::new_var(k, iv)?; &mut dest[..plain.len()].copy_from_slice(plain); encryptor.encrypt(dest, plain.len())?; @@ -170,27 +171,43 @@ mod tests { } #[test] - pub fn test_aes_short() -> Result<(),SymmError> { - let key = [97, 110, 121, 99, 111, 110, 116, 101, 110, 116, 116, 111, 114, 101, 97, 99, 104, 49, 50, 56, 98, 105, 116, 115, 105, 122, 101, 10]; - let salt = [109, 121, 115, 97, 108, 116, 115, 104, 111, 117, 108, 100, 102, 105, 108, 108, 115, 111, 109, 109, 101, 98, 121, 116, 101, 108, 101, 110, 103, 116, 104, 10]; - let content = [83, 111, 109, 101, 32, 99, 111, 110, 116, 101, 110, 116, 32, 116, 111, 32, 116, 101, 115, 116, - 32, 97, 101, 115, 44, 10, 110, 111, 116, 32, 116, 111, 32, 109, 117, 99, 104, 32, 44, 32, 111, 110, 108, 121, - 32, 118, 101, 114, 121, 32, 98, 97, 115, 105, 99, 32, 116, 101, 115, 116, 32, 116, 111, 32, 97, 118, 111, 105, - 100, 32, 111, 98, 118, 105, 111, 117, 115, 32, 114, 101, 103, 114, 101, 115, 115, 105, 111, 110, 32, 119, 104, - 101, 110, 32, 115, 119, 105, 116, 99, 104, 105, 110, 103, 32, 108, 105, 98, 115, 46, 10]; - let ctr_enc = [65, 55, 246, 75, 24, 117, 30, 233, 218, 139, 91, 251, 251, 179, 171, 69, 60, 244, 249, 44, 238, 60, - 10, 66, 71, 10, 199, 111, 54, 24, 124, 223, 153, 250, 159, 154, 164, 109, 232, 82, 20, 199, 182, 40, 174, 104, 64, - 203, 236, 94, 222, 184, 117, 54, 234, 189, 253, 122, 135, 121, 100, 44, 227, 241, 123, 120, 110, 188, 109, 148, 112, - 160, 131, 205, 116, 104, 232, 8, 22, 170, 80, 231, 155, 246, 255, 115, 101, 5, 234, 104, 220, 199, 192, 166, 181, 156, - 113, 255, 187, 51, 38, 128, 75, 29, 237, 178, 205, 98, 101, 110]; - let cbc_enc = [167, 248, 5, 90, 11, 140, 215, 138, 165, 125, 137, 76, 47, 243, 191, 48, 183, 247, 109, 86, 24, 45, - 81, 215, 0, 51, 221, 185, 131, 97, 234, 189, 244, 255, 107, 210, 70, 60, 41, 221, 43, 137, 185, 166, 42, 65, 18, 200, - 151, 233, 255, 192, 109, 25, 105, 115, 161, 209, 126, 235, 99, 192, 241, 241, 19, 249, 87, 244, 28, 146, 186, 189, 108, - 9, 243, 132, 4, 105, 53, 162, 8, 235, 84, 107, 213, 59, 158, 113, 227, 120, 162, 50, 237, 123, 70, 187, 83, 73, 146, 13, - 44, 191, 53, 4, 125, 207, 176, 45, 8, 153, 175, 198]; - let mut dest = vec![0;110]; - let mut dest_padded = vec![0;112]; - let mut dest_padded2 = vec![0;128]; // TODO RustLib need an extra 16bytes in dest : looks extra buggy but function is not currently use (keep it private for now) + pub fn test_aes_short() -> Result<(), SymmError> { + let key = [ + 97, 110, 121, 99, 111, 110, 116, 101, 110, 116, 116, 111, 114, 101, 97, 99, 104, 49, + 50, 56, 98, 105, 116, 115, 105, 122, 101, 10, + ]; + let salt = [ + 109, 121, 115, 97, 108, 116, 115, 104, 111, 117, 108, 100, 102, 105, 108, 108, 115, + 111, 109, 109, 101, 98, 121, 116, 101, 108, 101, 110, 103, 116, 104, 10, + ]; + let content = [ + 83, 111, 109, 101, 32, 99, 111, 110, 116, 101, 110, 116, 32, 116, 111, 32, 116, 101, + 115, 116, 32, 97, 101, 115, 44, 10, 110, 111, 116, 32, 116, 111, 32, 109, 117, 99, 104, + 32, 44, 32, 111, 110, 108, 121, 32, 118, 101, 114, 121, 32, 98, 97, 115, 105, 99, 32, + 116, 101, 115, 116, 32, 116, 111, 32, 97, 118, 111, 105, 100, 32, 111, 98, 118, 105, + 111, 117, 115, 32, 114, 101, 103, 114, 101, 115, 115, 105, 111, 110, 32, 119, 104, 101, + 110, 32, 115, 119, 105, 116, 99, 104, 105, 110, 103, 32, 108, 105, 98, 115, 46, 10, + ]; + let ctr_enc = [ + 65, 55, 246, 75, 24, 117, 30, 233, 218, 139, 91, 251, 251, 179, 171, 69, 60, 244, 249, + 44, 238, 60, 10, 66, 71, 10, 199, 111, 54, 24, 124, 223, 153, 250, 159, 154, 164, 109, + 232, 82, 20, 199, 182, 40, 174, 104, 64, 203, 236, 94, 222, 184, 117, 54, 234, 189, + 253, 122, 135, 121, 100, 44, 227, 241, 123, 120, 110, 188, 109, 148, 112, 160, 131, + 205, 116, 104, 232, 8, 22, 170, 80, 231, 155, 246, 255, 115, 101, 5, 234, 104, 220, + 199, 192, 166, 181, 156, 113, 255, 187, 51, 38, 128, 75, 29, 237, 178, 205, 98, 101, + 110, + ]; + let cbc_enc = [ + 167, 248, 5, 90, 11, 140, 215, 138, 165, 125, 137, 76, 47, 243, 191, 48, 183, 247, 109, + 86, 24, 45, 81, 215, 0, 51, 221, 185, 131, 97, 234, 189, 244, 255, 107, 210, 70, 60, + 41, 221, 43, 137, 185, 166, 42, 65, 18, 200, 151, 233, 255, 192, 109, 25, 105, 115, + 161, 209, 126, 235, 99, 192, 241, 241, 19, 249, 87, 244, 28, 146, 186, 189, 108, 9, + 243, 132, 4, 105, 53, 162, 8, 235, 84, 107, 213, 59, 158, 113, 227, 120, 162, 50, 237, + 123, 70, 187, 83, 73, 146, 13, 44, 191, 53, 4, 125, 207, 176, 45, 8, 153, 175, 198, + ]; + let mut dest = vec![0; 110]; + let mut dest_padded = vec![0; 112]; + let mut dest_padded2 = vec![0; 128]; // TODO RustLib need an extra 16bytes in dest : looks extra buggy but function is not currently use (keep it private for now) encrypt_128_cbc(&key[..16], &salt[..16], &content, &mut dest_padded2)?; assert!(&dest_padded2[..112] == &cbc_enc[..]); encrypt_128_ctr(&key[..16], &salt[..16], &content, &mut dest)?; diff --git a/parity-crypto/src/digest.rs b/parity-crypto/src/digest.rs index 1851ac01d..e6fda3796 100644 --- a/parity-crypto/src/digest.rs +++ b/parity-crypto/src/digest.rs @@ -17,7 +17,10 @@ use std::marker::PhantomData; use std::ops::Deref; -use digest::generic_array::{GenericArray, typenum::{U20, U32, U64}}; +use digest::generic_array::{ + typenum::{U20, U32, U64}, + GenericArray, +}; use sha2::Digest as RDigest; /// The message digest. @@ -74,7 +77,7 @@ pub struct Hasher(Inner, PhantomData); enum Inner { Sha256(sha2::Sha256), Sha512(sha2::Sha512), - Ripemd160(ripemd160::Ripemd160) + Ripemd160(ripemd160::Ripemd160), } impl Hasher { @@ -91,36 +94,27 @@ impl Hasher { impl Hasher { pub fn ripemd160() -> Hasher { - Hasher(Inner::Ripemd160(ripemd160::Ripemd160::default()), PhantomData) + Hasher( + Inner::Ripemd160(ripemd160::Ripemd160::default()), + PhantomData, + ) } } impl Hasher { pub fn update(&mut self, data: &[u8]) { match self.0 { - Inner::Sha256(ref mut ctx) => { - ctx.input(data) - }, - Inner::Sha512(ref mut ctx) => { - ctx.input(data) - }, - Inner::Ripemd160(ref mut ctx) => { - ctx.input(data) - } + Inner::Sha256(ref mut ctx) => ctx.input(data), + Inner::Sha512(ref mut ctx) => ctx.input(data), + Inner::Ripemd160(ref mut ctx) => ctx.input(data), } } pub fn finish(self) -> Digest { match self.0 { - Inner::Sha256(ctx) => { - Digest(InnerDigest::Sha256(ctx.result()), PhantomData) - }, - Inner::Sha512(ctx) => { - Digest(InnerDigest::Sha512(ctx.result()), PhantomData) - }, - Inner::Ripemd160(ctx) => { - Digest(InnerDigest::Ripemd160(ctx.result()), PhantomData) - } + Inner::Sha256(ctx) => Digest(InnerDigest::Sha256(ctx.result()), PhantomData), + Inner::Sha512(ctx) => Digest(InnerDigest::Sha512(ctx.result()), PhantomData), + Inner::Ripemd160(ctx) => Digest(InnerDigest::Ripemd160(ctx.result()), PhantomData), } } } diff --git a/parity-crypto/src/error.rs b/parity-crypto/src/error.rs index 110c62cc5..ffcf5ca29 100644 --- a/parity-crypto/src/error.rs +++ b/parity-crypto/src/error.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use std::{fmt, result, error::Error as StdError}; +use std::{error::Error as StdError, fmt, result}; #[derive(Debug)] pub enum Error { @@ -74,7 +74,7 @@ impl StdError for SymmError { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> { match self { - Error::Scrypt(err)=> write!(f, "scrypt error: {}", err), + Error::Scrypt(err) => write!(f, "scrypt error: {}", err), Error::Symm(err) => write!(f, "symm error: {}", err), } } @@ -96,14 +96,16 @@ impl fmt::Display for SymmError { match self { SymmError(PrivSymmErr::BlockMode(err)) => write!(f, "block cipher error: {}", err), SymmError(PrivSymmErr::KeyStream(err)) => write!(f, "ctr key stream ended: {}", err), - SymmError(PrivSymmErr::InvalidKeyLength(err)) => write!(f, "block cipher key length: {}", err), + SymmError(PrivSymmErr::InvalidKeyLength(err)) => { + write!(f, "block cipher key length: {}", err) + } } } } impl Into for Error { fn into(self) -> std::io::Error { - std::io::Error::new(std::io::ErrorKind::Other, format!("Crypto error: {}",self)) + std::io::Error::new(std::io::ErrorKind::Other, format!("Crypto error: {}", self)) } } @@ -148,4 +150,3 @@ impl From for Error { Error::Symm(e) } } - diff --git a/parity-crypto/src/hmac/mod.rs b/parity-crypto/src/hmac/mod.rs index 571df7b59..95154bf08 100644 --- a/parity-crypto/src/hmac/mod.rs +++ b/parity-crypto/src/hmac/mod.rs @@ -17,7 +17,10 @@ use std::marker::PhantomData; use std::ops::Deref; -use digest::generic_array::{GenericArray, typenum::{U32, U64}}; +use digest::generic_array::{ + typenum::{U32, U64}, + GenericArray, +}; use hmac::{Hmac, Mac as _}; use zeroize::Zeroize; @@ -79,7 +82,7 @@ impl SigKey { pub fn sha256(key: &[u8]) -> SigKey { SigKey( KeyInner::Sha256(DisposableBox::from_slice(key)), - PhantomData + PhantomData, ) } } @@ -88,7 +91,7 @@ impl SigKey { pub fn sha512(key: &[u8]) -> SigKey { SigKey( KeyInner::Sha512(DisposableBox::from_slice(key)), - PhantomData + PhantomData, ) } } @@ -111,23 +114,18 @@ enum SignerInner { impl Signer { pub fn with(key: &SigKey) -> Signer { match &key.0 { - KeyInner::Sha256(key_bytes) => { - Signer( - SignerInner::Sha256( - Hmac::::new_varkey(&key_bytes.0) - .expect("always returns Ok; qed") - ), - PhantomData - ) - }, - KeyInner::Sha512(key_bytes) => { - Signer( - SignerInner::Sha512( - Hmac::::new_varkey(&key_bytes.0) - .expect("always returns Ok; qed") - ), PhantomData - ) - }, + KeyInner::Sha256(key_bytes) => Signer( + SignerInner::Sha256( + Hmac::::new_varkey(&key_bytes.0).expect("always returns Ok; qed"), + ), + PhantomData, + ), + KeyInner::Sha512(key_bytes) => Signer( + SignerInner::Sha512( + Hmac::::new_varkey(&key_bytes.0).expect("always returns Ok; qed"), + ), + PhantomData, + ), } } @@ -140,8 +138,12 @@ impl Signer { pub fn sign(self) -> Signature { match self.0 { - SignerInner::Sha256(hmac) => Signature(HashInner::Sha256(hmac.result().code()), PhantomData), - SignerInner::Sha512(hmac) => Signature(HashInner::Sha512(hmac.result().code()), PhantomData), + SignerInner::Sha256(hmac) => { + Signature(HashInner::Sha256(hmac.result().code()), PhantomData) + } + SignerInner::Sha512(hmac) => { + Signature(HashInner::Sha512(hmac.result().code()), PhantomData) + } } } } @@ -153,7 +155,7 @@ impl VerifyKey { pub fn sha256(key: &[u8]) -> VerifyKey { VerifyKey( KeyInner::Sha256(DisposableBox::from_slice(key)), - PhantomData + PhantomData, ) } } @@ -162,7 +164,7 @@ impl VerifyKey { pub fn sha512(key: &[u8]) -> VerifyKey { VerifyKey( KeyInner::Sha512(DisposableBox::from_slice(key)), - PhantomData + PhantomData, ) } } @@ -171,17 +173,17 @@ impl VerifyKey { pub fn verify(key: &VerifyKey, data: &[u8], sig: &[u8]) -> bool { match &key.0 { KeyInner::Sha256(key_bytes) => { - let mut ctx = Hmac::::new_varkey(&key_bytes.0) - .expect("always returns Ok; qed"); + let mut ctx = + Hmac::::new_varkey(&key_bytes.0).expect("always returns Ok; qed"); ctx.input(data); ctx.verify(sig).is_ok() - }, + } KeyInner::Sha512(key_bytes) => { - let mut ctx = Hmac::::new_varkey(&key_bytes.0) - .expect("always returns Ok; qed"); + let mut ctx = + Hmac::::new_varkey(&key_bytes.0).expect("always returns Ok; qed"); ctx.input(data); ctx.verify(sig).is_ok() - }, + } } } diff --git a/parity-crypto/src/hmac/test.rs b/parity-crypto/src/hmac/test.rs index 9e0c34e12..f9b91df5b 100644 --- a/parity-crypto/src/hmac/test.rs +++ b/parity-crypto/src/hmac/test.rs @@ -20,10 +20,10 @@ use hex_literal::hex; #[test] fn simple_mac_and_verify() { let input = b"Some bytes"; - let big_input = vec![7u8;2000]; + let big_input = vec![7u8; 2000]; - let key1 = vec![3u8;64]; - let key2 = vec![4u8;128]; + let key1 = vec![3u8; 64]; + let key2 = vec![4u8; 128]; let sig_key1 = SigKey::sha256(&key1[..]); let sig_key2 = SigKey::sha512(&key2[..]); @@ -32,14 +32,28 @@ fn simple_mac_and_verify() { let mut signer2 = Signer::with(&sig_key2); signer1.update(&input[..]); - for i in 0 .. big_input.len() / 33 { - signer2.update(&big_input[i*33..(i+1)*33]); + for i in 0..big_input.len() / 33 { + signer2.update(&big_input[i * 33..(i + 1) * 33]); } - signer2.update(&big_input[(big_input.len() / 33)*33..]); + signer2.update(&big_input[(big_input.len() / 33) * 33..]); let sig1 = signer1.sign(); - assert_eq!(&sig1[..], [223, 208, 90, 69, 144, 95, 145, 180, 56, 155, 78, 40, 86, 238, 205, 81, 160, 245, 88, 145, 164, 67, 254, 180, 202, 107, 93, 249, 64, 196, 86, 225]); + assert_eq!( + &sig1[..], + [ + 223, 208, 90, 69, 144, 95, 145, 180, 56, 155, 78, 40, 86, 238, 205, 81, 160, 245, 88, + 145, 164, 67, 254, 180, 202, 107, 93, 249, 64, 196, 86, 225 + ] + ); let sig2 = signer2.sign(); - assert_eq!(&sig2[..], &[29, 63, 46, 122, 27, 5, 241, 38, 86, 197, 91, 79, 33, 107, 152, 195, 118, 221, 117, 119, 84, 114, 46, 65, 243, 157, 105, 12, 147, 176, 190, 37, 210, 164, 152, 8, 58, 243, 59, 206, 80, 10, 230, 197, 255, 110, 191, 180, 93, 22, 255, 0, 99, 79, 237, 229, 209, 199, 125, 83, 15, 179, 134, 89][..]); + assert_eq!( + &sig2[..], + &[ + 29, 63, 46, 122, 27, 5, 241, 38, 86, 197, 91, 79, 33, 107, 152, 195, 118, 221, 117, + 119, 84, 114, 46, 65, 243, 157, 105, 12, 147, 176, 190, 37, 210, 164, 152, 8, 58, 243, + 59, 206, 80, 10, 230, 197, 255, 110, 191, 180, 93, 22, 255, 0, 99, 79, 237, 229, 209, + 199, 125, 83, 15, 179, 134, 89 + ][..] + ); assert_eq!(&sig1[..], &sign(&sig_key1, &input[..])[..]); assert_eq!(&sig2[..], &sign(&sig_key2, &big_input[..])[..]); let verif_key1 = VerifyKey::sha256(&key1[..]); @@ -48,12 +62,7 @@ fn simple_mac_and_verify() { assert!(verify(&verif_key2, &big_input[..], &sig2[..])); } -fn check_test_vector( - key: &[u8], - data: &[u8], - expected_256: &[u8], - expected_512: &[u8], -) { +fn check_test_vector(key: &[u8], data: &[u8], expected_256: &[u8], expected_512: &[u8]) { // Sha-256 let sig_key = SigKey::sha256(&key); let mut signer = Signer::with(&sig_key); @@ -62,7 +71,7 @@ fn check_test_vector( assert_eq!(&signature[..], expected_256); assert_eq!(&signature[..], &sign(&sig_key, data)[..]); let ver_key = VerifyKey::sha256(&key); - assert!(verify(&ver_key, data,&signature)); + assert!(verify(&ver_key, data, &signature)); // Sha-512 let sig_key = SigKey::sha512(&key); @@ -72,7 +81,7 @@ fn check_test_vector( assert_eq!(&signature[..], expected_512); assert_eq!(&signature[..], &sign(&sig_key, data)[..]); let ver_key = VerifyKey::sha512(&key); - assert!(verify(&ver_key, data,&signature)); + assert!(verify(&ver_key, data, &signature)); } #[test] @@ -83,28 +92,36 @@ fn ietf_test_vectors() { check_test_vector( &hex!("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"), &hex!("4869205468657265"), - &hex!(" + &hex!( + " b0344c61d8db38535ca8afceaf0bf12b - 881dc200c9833da726e9376c2e32cff7"), - &hex!(" + 881dc200c9833da726e9376c2e32cff7" + ), + &hex!( + " 87aa7cdea5ef619d4ff0b4241a1d6cb0 2379f4e2ce4ec2787ad0b30545e17cde daa833b7d6b8a702038b274eaea3f4e4 - be9d914eeb61f1702e696c203a126854") + be9d914eeb61f1702e696c203a126854" + ), ); // Test Case 2 check_test_vector( &hex!("4a656665"), &hex!("7768617420646f2079612077616e7420666f72206e6f7468696e673f"), - &hex!(" + &hex!( + " 5bdcc146bf60754e6a042426089575c7 - 5a003f089d2739839dec58b964ec3843"), - &hex!(" + 5a003f089d2739839dec58b964ec3843" + ), + &hex!( + " 164b7a7bfcf819e2e395fbe73b56e0a3 87bd64222e831fd610270cd7ea250554 9758bf75c05a994a6d034f65f8f0e6fd - caeab1a34d4a6b4b636e070a38bce737") + caeab1a34d4a6b4b636e070a38bce737" + ), ); // Test Case 3 check_test_vector( @@ -123,24 +140,31 @@ fn ietf_test_vectors() { // Test Case 4 check_test_vector( &hex!("0102030405060708090a0b0c0d0e0f10111213141516171819"), - &hex!(" + &hex!( + " cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd - cdcd"), - &hex!(" + cdcd" + ), + &hex!( + " 82558a389a443c0ea4cc819899f2083a - 85f0faa3e578f8077a2e3ff46729665b"), - &hex!(" + 85f0faa3e578f8077a2e3ff46729665b" + ), + &hex!( + " b0ba465637458c6990e5a8c5f61d4af7 e576d97ff94b872de76f8050361ee3db a91ca5c11aa25eb4d679275cc5788063 - a5f19741120c4f2de2adebeb10a298dd") + a5f19741120c4f2de2adebeb10a298dd" + ), ); // Test Case 6 check_test_vector( - &hex!(" + &hex!( + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa @@ -149,25 +173,33 @@ fn ietf_test_vectors() { aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaa"), - &hex!(" + aaaaaa" + ), + &hex!( + " 54657374205573696e67204c61726765 72205468616e20426c6f636b2d53697a 65204b6579202d2048617368204b6579 - 204669727374"), - &hex!(" + 204669727374" + ), + &hex!( + " 60e431591ee0b67f0d8a26aacbf5b77f - 8e0bc6213728c5140546040f0ee37f54"), - &hex!(" + 8e0bc6213728c5140546040f0ee37f54" + ), + &hex!( + " 80b24263c7c1a3ebb71493c1dd7be8b4 9b46d1f41b4aeec1121b013783f8f352 6b56d037e05f2598bd0fd2215d6a1e52 - 95e64f73f63f0aec8b915a985d786598") + 95e64f73f63f0aec8b915a985d786598" + ), ); // Test Case 7 check_test_vector( - &hex!(" + &hex!( + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa @@ -176,8 +208,10 @@ fn ietf_test_vectors() { aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaa"), - &hex!(" + aaaaaa" + ), + &hex!( + " 54686973206973206120746573742075 73696e672061206c6172676572207468 616e20626c6f636b2d73697a65206b65 @@ -187,15 +221,20 @@ fn ietf_test_vectors() { 647320746f2062652068617368656420 6265666f7265206265696e6720757365 642062792074686520484d414320616c - 676f726974686d2e"), - &hex!(" + 676f726974686d2e" + ), + &hex!( + " 9b09ffa71b942fcb27635fbcd5b0e944 - bfdc63644f0713938a7f51535c3a35e2"), - &hex!(" + bfdc63644f0713938a7f51535c3a35e2" + ), + &hex!( + " e37b6a775dc87dbaa4dfa9f96e5e3ffd debd71f8867289865df5a32d20cdc944 b6022cac3c4982b10d5eeb55c3e4de15 - 134676fb6de0446065c97440fa8c6a58") + 134676fb6de0446065c97440fa8c6a58" + ), ); } diff --git a/parity-crypto/src/lib.rs b/parity-crypto/src/lib.rs index 309c4c803..6e259a748 100644 --- a/parity-crypto/src/lib.rs +++ b/parity-crypto/src/lib.rs @@ -17,18 +17,18 @@ //! Crypto utils used by ethstore and network. pub mod aes; -pub mod error; -pub mod scrypt; pub mod digest; +pub mod error; pub mod hmac; pub mod pbkdf2; #[cfg(feature = "publickey")] pub mod publickey; +pub mod scrypt; pub use crate::error::Error; -use tiny_keccak::Keccak; use subtle::ConstantTimeEq; +use tiny_keccak::Keccak; pub const KEY_LENGTH: usize = 32; pub const KEY_ITERATIONS: usize = 10240; @@ -38,10 +38,15 @@ pub const KEY_LENGTH_AES: usize = KEY_LENGTH / 2; pub const DEFAULT_MAC: [u8; 2] = [0, 0]; pub trait Keccak256 { - fn keccak256(&self) -> T where T: Sized; + fn keccak256(&self) -> T + where + T: Sized; } -impl Keccak256<[u8; 32]> for T where T: AsRef<[u8]> { +impl Keccak256<[u8; 32]> for T +where + T: AsRef<[u8]>, +{ fn keccak256(&self) -> [u8; 32] { let mut keccak = Keccak::new_keccak256(); let mut result = [0u8; 32]; @@ -53,7 +58,12 @@ impl Keccak256<[u8; 32]> for T where T: AsRef<[u8]> { pub fn derive_key_iterations(password: &[u8], salt: &[u8], c: u32) -> (Vec, Vec) { let mut derived_key = [0u8; KEY_LENGTH]; - pbkdf2::sha256(c, pbkdf2::Salt(salt), pbkdf2::Secret(password), &mut derived_key); + pbkdf2::sha256( + c, + pbkdf2::Salt(salt), + pbkdf2::Secret(password), + &mut derived_key, + ); let derived_right_bits = &derived_key[0..KEY_LENGTH_AES]; let derived_left_bits = &derived_key[KEY_LENGTH_AES..KEY_LENGTH]; (derived_right_bits.to_vec(), derived_left_bits.to_vec()) diff --git a/parity-crypto/src/pbkdf2/test.rs b/parity-crypto/src/pbkdf2/test.rs index 0aca66967..1fbd493f8 100644 --- a/parity-crypto/src/pbkdf2/test.rs +++ b/parity-crypto/src/pbkdf2/test.rs @@ -18,10 +18,13 @@ use super::*; #[test] fn basic_test() { - let mut dest = [0;32]; - let salt = [5;32]; - let secret = [7;32]; + let mut dest = [0; 32]; + let salt = [5; 32]; + let secret = [7; 32]; sha256(3, Salt(&salt[..]), Secret(&secret[..]), &mut dest); - let res = [242, 33, 31, 124, 36, 223, 179, 185, 206, 175, 190, 253, 85, 33, 23, 126, 141, 29, 23, 97, 66, 63, 51, 196, 27, 255, 135, 206, 74, 137, 172, 87]; + let res = [ + 242, 33, 31, 124, 36, 223, 179, 185, 206, 175, 190, 253, 85, 33, 23, 126, 141, 29, 23, 97, + 66, 63, 51, 196, 27, 255, 135, 206, 74, 137, 172, 87, + ]; assert_eq!(res, dest); } diff --git a/parity-crypto/src/publickey/ec_math_utils.rs b/parity-crypto/src/publickey/ec_math_utils.rs index cbc2e3f81..966867b27 100644 --- a/parity-crypto/src/publickey/ec_math_utils.rs +++ b/parity-crypto/src/publickey/ec_math_utils.rs @@ -16,26 +16,21 @@ //! Multiple primitives for work with public and secret keys and with secp256k1 curve points -use super::{SECP256K1, Public, Secret, Error}; -use secp256k1::key; -use secp256k1::constants::{CURVE_ORDER as SECP256K1_CURVE_ORDER}; -use ethereum_types::{BigEndianHash as _, U256, H256}; +use super::{Error, Public, Secret, SECP256K1}; +use ethereum_types::{BigEndianHash as _, H256, U256}; use lazy_static::lazy_static; +use secp256k1::constants::CURVE_ORDER as SECP256K1_CURVE_ORDER; +use secp256k1::key; /// Generation point array combined from X and Y coordinates /// Equivalent to uncompressed form, see https://tools.ietf.org/id/draft-jivsov-ecc-compact-05.html#rfc.section.3 pub const BASE_POINT_BYTES: [u8; 65] = [ - 0x4, - // The X coordinate of the generator - 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, - 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, - 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, - 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, + 0x4, // The X coordinate of the generator + 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, + 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, // The Y coordinate of the generator - 0x48, 0x3a, 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, - 0x5d, 0xa4, 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, - 0xfd, 0x17, 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, - 0x9c, 0x47, 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8, + 0x48, 0x3a, 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, + 0xfd, 0x17, 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8, ]; lazy_static! { @@ -44,7 +39,8 @@ lazy_static! { /// Whether the public key is valid. pub fn public_is_valid(public: &Public) -> bool { - to_secp256k1_public(public).ok() + to_secp256k1_public(public) + .ok() .map_or(false, |p| p.is_valid()) } @@ -106,13 +102,17 @@ fn to_secp256k1_public(public: &Public) -> Result { fn set_public(public: &mut Public, key_public: &key::PublicKey) { let key_public_serialized = key_public.serialize_vec(&SECP256K1, false); - public.as_bytes_mut().copy_from_slice(&key_public_serialized[1..65]); + public + .as_bytes_mut() + .copy_from_slice(&key_public_serialized[1..65]); } #[cfg(test)] mod tests { - use super::super::{Random, Generator, Secret}; - use super::{public_add, public_sub, public_negate, public_is_valid, generation_point, public_mul_secret}; + use super::super::{Generator, Random, Secret}; + use super::{ + generation_point, public_add, public_is_valid, public_mul_secret, public_negate, public_sub, + }; use std::str::FromStr; #[test] @@ -166,7 +166,9 @@ mod tests { #[test] fn public_multiplication_verification() { - let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); + let secret = + Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") + .unwrap(); let mut public = generation_point(); public_mul_secret(&mut public, &secret).unwrap(); assert_eq!(format!("{:x}", public), "8ce0db0b0359ffc5866ba61903cc2518c3675ef2cf380a7e54bde7ea20e6fa1ab45b7617346cd11b7610001ee6ae5b0155c41cad9527cbcdff44ec67848943a4"); diff --git a/parity-crypto/src/publickey/ecdh.rs b/parity-crypto/src/publickey/ecdh.rs index 73d25491c..ab22c2a09 100644 --- a/parity-crypto/src/publickey/ecdh.rs +++ b/parity-crypto/src/publickey/ecdh.rs @@ -16,8 +16,8 @@ //! ECDH key agreement scheme implemented as a free function. +use super::{Error, Public, Secret, SECP256K1}; use secp256k1::{self, ecdh, key}; -use super::{Error, Secret, Public, SECP256K1}; /// Agree on a shared secret pub fn agree(secret: &Secret, public: &Public) -> Result { @@ -32,6 +32,5 @@ pub fn agree(secret: &Secret, public: &Public) -> Result { let sec = key::SecretKey::from_slice(context, secret.as_bytes())?; let shared = ecdh::SharedSecret::new_raw(context, &publ, &sec); - Secret::import_key(&shared[0..32]) - .map_err(|_| Error::Secp(secp256k1::Error::InvalidSecretKey)) + Secret::import_key(&shared[0..32]).map_err(|_| Error::Secp(secp256k1::Error::InvalidSecretKey)) } diff --git a/parity-crypto/src/publickey/ecdsa_signature.rs b/parity-crypto/src/publickey/ecdsa_signature.rs index 421fa9b61..1d51e88d9 100644 --- a/parity-crypto/src/publickey/ecdsa_signature.rs +++ b/parity-crypto/src/publickey/ecdsa_signature.rs @@ -16,16 +16,16 @@ //! Signature based on ECDSA, algorithm's description: https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm -use std::ops::{Deref, DerefMut}; +use super::{public_to_address, Address, Error, Message, Public, Secret, SECP256K1}; +use ethereum_types::{H256, H520}; +use rustc_hex::{FromHex, ToHex}; +use secp256k1::key::{PublicKey, SecretKey}; +use secp256k1::{Error as SecpError, Message as SecpMessage, RecoverableSignature, RecoveryId}; use std::cmp::PartialEq; use std::fmt; -use std::str::FromStr; use std::hash::{Hash, Hasher}; -use secp256k1::{Message as SecpMessage, RecoverableSignature, RecoveryId, Error as SecpError}; -use secp256k1::key::{SecretKey, PublicKey}; -use rustc_hex::{ToHex, FromHex}; -use ethereum_types::{H520, H256}; -use super::{Secret, Public, SECP256K1, Message, public_to_address, Address, Error}; +use std::ops::{Deref, DerefMut}; +use std::str::FromStr; /// Signature encoded as RSV components #[repr(C)] @@ -81,10 +81,9 @@ impl Signature { /// This condition may be required by some verification algorithms pub fn is_low_s(&self) -> bool { const LOW_SIG_THRESHOLD: H256 = H256([ - 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x5D, 0x57, 0x6E, 0x73, 0x57, 0xA4, 0x50, 0x1D, - 0xDF, 0xE9, 0x2F, 0x46, 0x68, 0x1B, 0x20, 0xA0, + 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x5D, 0x57, 0x6E, 0x73, 0x57, 0xA4, 0x50, 0x1D, 0xDF, 0xE9, 0x2F, 0x46, + 0x68, 0x1B, 0x20, 0xA0, ]); H256::from_slice(self.s()) <= LOW_SIG_THRESHOLD } @@ -97,22 +96,18 @@ impl Signature { /// used here as the upper bound for a valid (r, s, v) tuple pub fn is_valid(&self) -> bool { const UPPER_BOUND: H256 = H256([ - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, - 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, - 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, + 0xd0, 0x36, 0x41, 0x41, ]); const ONE: H256 = H256([ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, ]); let r = H256::from_slice(self.r()); let s = H256::from_slice(self.s()); - self.v() <= 1 && - r < UPPER_BOUND && r >= ONE && - s < UPPER_BOUND && s >= ONE + self.v() <= 1 && r < UPPER_BOUND && r >= ONE && s < UPPER_BOUND && s >= ONE } } @@ -125,7 +120,7 @@ impl PartialEq for Signature { } // manual implementation required in Rust 1.13+, see `std::cmp::AssertParamIsEq`. -impl Eq for Signature { } +impl Eq for Signature {} // also manual for the same reason, but the pretty printing might be useful. impl fmt::Debug for Signature { @@ -134,7 +129,7 @@ impl fmt::Debug for Signature { .field("r", &self.0[0..32].to_hex::()) .field("s", &self.0[32..64].to_hex::()) .field("v", &self.0[64..65].to_hex::()) - .finish() + .finish() } } @@ -153,8 +148,8 @@ impl FromStr for Signature { let mut data = [0; 65]; data.copy_from_slice(&hex[0..65]); Ok(Signature(data)) - }, - _ => Err(Error::InvalidSignature) + } + _ => Err(Error::InvalidSignature), } } } @@ -231,9 +226,17 @@ pub fn sign(secret: &Secret, message: &Message) -> Result { } /// Performs verification of the signature for the given message with corresponding public key -pub fn verify_public(public: &Public, signature: &Signature, message: &Message) -> Result { +pub fn verify_public( + public: &Public, + signature: &Signature, + message: &Message, +) -> Result { let context = &SECP256K1; - let rsig = RecoverableSignature::from_compact(context, &signature[0..64], RecoveryId::from_i32(signature[64] as i32)?)?; + let rsig = RecoverableSignature::from_compact( + context, + &signature[0..64], + RecoveryId::from_i32(signature[64] as i32)?, + )?; let sig = rsig.to_standard(context); let pdata: [u8; 65] = { @@ -246,12 +249,16 @@ pub fn verify_public(public: &Public, signature: &Signature, message: &Message) match context.verify(&SecpMessage::from_slice(&message[..])?, &sig, &publ) { Ok(_) => Ok(true), Err(SecpError::IncorrectSignature) => Ok(false), - Err(x) => Err(Error::from(x)) + Err(x) => Err(Error::from(x)), } } /// Checks if the address corresponds to the public key from the signature for the message -pub fn verify_address(address: &Address, signature: &Signature, message: &Message) -> Result { +pub fn verify_address( + address: &Address, + signature: &Signature, + message: &Message, +) -> Result { let public = recover(signature, message)?; let recovered_address = public_to_address(&public); Ok(address == &recovered_address) @@ -260,7 +267,11 @@ pub fn verify_address(address: &Address, signature: &Signature, message: &Messag /// Recovers the public key from the signature for the message pub fn recover(signature: &Signature, message: &Message) -> Result { let context = &SECP256K1; - let rsig = RecoverableSignature::from_compact(context, &signature[0..64], RecoveryId::from_i32(signature[64] as i32)?)?; + let rsig = RecoverableSignature::from_compact( + context, + &signature[0..64], + RecoveryId::from_i32(signature[64] as i32)?, + )?; let pubkey = context.recover(&SecpMessage::from_slice(&message[..])?, &rsig)?; let serialized = pubkey.serialize_vec(context, false); @@ -271,9 +282,9 @@ pub fn recover(signature: &Signature, message: &Message) -> Result> 24) as u8, (ctr >> 16) as u8, (ctr >> 8) as u8, ctr as u8]; + let ctrs = [ + (ctr >> 24) as u8, + (ctr >> 16) as u8, + (ctr >> 8) as u8, + ctr as u8, + ]; hasher.update(&ctrs); hasher.update(secret.as_bytes()); hasher.update(s1); @@ -118,7 +123,7 @@ fn kdf(secret: &Secret, s1: &[u8], dest: &mut [u8]) { #[cfg(test)] mod tests { - use super::super::{ecies, Random, Generator}; + use super::super::{ecies, Generator, Random}; #[test] fn ecies_shared() { diff --git a/parity-crypto/src/publickey/error.rs b/parity-crypto/src/publickey/error.rs index b8a568da7..322be394b 100644 --- a/parity-crypto/src/publickey/error.rs +++ b/parity-crypto/src/publickey/error.rs @@ -16,8 +16,8 @@ //! Module specific errors -use std::{fmt, result, error::Error as StdError}; use crate::error::SymmError; +use std::{error::Error as StdError, fmt, result}; /// Module specific errors #[derive(Debug)] diff --git a/parity-crypto/src/publickey/extended_keys.rs b/parity-crypto/src/publickey/extended_keys.rs index e585672e8..6ec293541 100644 --- a/parity-crypto/src/publickey/extended_keys.rs +++ b/parity-crypto/src/publickey/extended_keys.rs @@ -20,9 +20,9 @@ //! The hardened child keys use indices 2^31 through 2^32 - 1. //! See more details about derivation in https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki -use super::{Secret, Public}; -use ethereum_types::H256; pub use self::derivation::Error as DerivationError; +use super::{Public, Secret}; +use ethereum_types::H256; /// Represents label that can be stored as a part of key derivation pub trait Label { @@ -35,7 +35,9 @@ pub trait Label { } impl Label for u32 { - fn len() -> usize { 4 } + fn len() -> usize { + 4 + } fn store(&self, target: &mut [u8]) { let bytes = self.to_be_bytes(); @@ -57,15 +59,16 @@ impl From for Derivation { // See module's documentation for more details if index < (2 << 30) { Derivation::Soft(index) - } - else { + } else { Derivation::Hard(index) } } } impl Label for H256 { - fn len() -> usize { 32 } + fn len() -> usize { + 32 + } fn store(&self, target: &mut [u8]) { (&mut target[0..32]).copy_from_slice(self.as_bytes()); @@ -100,8 +103,12 @@ impl ExtendedSecret { } /// Derive new private key - pub fn derive(&self, index: Derivation) -> ExtendedSecret where T: Label { - let (derived_key, next_chain_code) = derivation::private(*self.secret, self.chain_code, index); + pub fn derive(&self, index: Derivation) -> ExtendedSecret + where + T: Label, + { + let (derived_key, next_chain_code) = + derivation::private(*self.secret, self.chain_code, index); let derived_secret = Secret::from(derived_key.0); @@ -123,23 +130,28 @@ pub struct ExtendedPublic { impl ExtendedPublic { /// New extended public key from known parent and chain code pub fn new(public: Public, chain_code: H256) -> Self { - ExtendedPublic { public: public, chain_code: chain_code } + ExtendedPublic { + public: public, + chain_code: chain_code, + } } /// Create new extended public key from known secret pub fn from_secret(secret: &ExtendedSecret) -> Result { - Ok( - ExtendedPublic::new( - derivation::point(**secret.as_raw())?, - secret.chain_code.clone(), - ) - ) + Ok(ExtendedPublic::new( + derivation::point(**secret.as_raw())?, + secret.chain_code.clone(), + )) } /// Derive new public key /// Operation is defined only for index belongs [0..2^31) - pub fn derive(&self, index: Derivation) -> Result where T: Label { - let (derived_key, next_chain_code) = derivation::public(self.public, self.chain_code, index)?; + pub fn derive(&self, index: Derivation) -> Result + where + T: Label, + { + let (derived_key, next_chain_code) = + derivation::public(self.public, self.chain_code, index)?; Ok(ExtendedPublic::new(derived_key, next_chain_code)) } @@ -197,7 +209,10 @@ impl ExtendedKeyPair { &self.public } - pub fn derive(&self, index: Derivation) -> Result where T: Label { + pub fn derive(&self, index: Derivation) -> Result + where + T: Label, + { let derived = self.secret.derive(index); Ok(ExtendedKeyPair { @@ -211,12 +226,12 @@ impl ExtendedKeyPair { // Work is based on BIP0032 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki mod derivation { - use crate::{hmac, Keccak256}; - use super::super::SECP256K1; - use ethereum_types::{BigEndianHash, U256, U512, H512, H256}; - use secp256k1::key::{SecretKey, PublicKey}; use super::super::ec_math_utils::CURVE_ORDER; - use super::{Label, Derivation}; + use super::super::SECP256K1; + use super::{Derivation, Label}; + use crate::{hmac, Keccak256}; + use ethereum_types::{BigEndianHash, H256, H512, U256, U512}; + use secp256k1::key::{PublicKey, SecretKey}; use std::convert::TryInto; #[derive(Debug)] @@ -233,7 +248,10 @@ mod derivation { // // Can panic if passed `private_key` is not a valid secp256k1 private key // (outside of (0..curve_order()]) field - pub fn private(private_key: H256, chain_code: H256, index: Derivation) -> (H256, H256) where T: Label { + pub fn private(private_key: H256, chain_code: H256, index: Derivation) -> (H256, H256) + where + T: Label, + { match index { Derivation::Soft(index) => private_soft(private_key, chain_code, index), Derivation::Hard(index) => private_hard(private_key, chain_code, index), @@ -258,7 +276,10 @@ mod derivation { // Can panic if passed `private_key` is not a valid secp256k1 private key // (outside of (0..curve_order()]) field - fn private_soft(private_key: H256, chain_code: H256, index: T) -> (H256, H256) where T: Label { + fn private_soft(private_key: H256, chain_code: H256, index: T) -> (H256, H256) + where + T: Label, + { let mut data = vec![0u8; 33 + T::len()]; let sec_private = SecretKey::from_slice(&SECP256K1, private_key.as_bytes()) @@ -278,7 +299,10 @@ mod derivation { // Deterministic derivation of the key using secp256k1 elliptic curve // This is hardened derivation and does not allow to associate // corresponding public keys of the original and derived private keys - fn private_hard(private_key: H256, chain_code: H256, index: T) -> (H256, H256) where T: Label { + fn private_hard(private_key: H256, chain_code: H256, index: T) -> (H256, H256) + where + T: Label, + { let mut data: Vec = vec![0u8; 33 + T::len()]; let private: U256 = private_key.into_uint(); @@ -298,19 +322,30 @@ mod derivation { // todo: surely can be optimized fn modulo(u1: U512, u2: U256) -> U256 { let m = u1 % U512::from(u2); - m.try_into().expect("U512 modulo U256 should fit into U256; qed") - } - - pub fn public(public_key: H512, chain_code: H256, derivation: Derivation) -> Result<(H512, H256), Error> where T: Label { + m.try_into() + .expect("U512 modulo U256 should fit into U256; qed") + } + + pub fn public( + public_key: H512, + chain_code: H256, + derivation: Derivation, + ) -> Result<(H512, H256), Error> + where + T: Label, + { let index = match derivation { Derivation::Soft(index) => index, - Derivation::Hard(_) => { return Err(Error::InvalidHardenedUse); } + Derivation::Hard(_) => { + return Err(Error::InvalidHardenedUse); + } }; let mut public_sec_raw = [0u8; 65]; public_sec_raw[0] = 4; public_sec_raw[1..65].copy_from_slice(public_key.as_bytes()); - let public_sec = PublicKey::from_slice(&SECP256K1, &public_sec_raw).map_err(|_| Error::InvalidPoint)?; + let public_sec = + PublicKey::from_slice(&SECP256K1, &public_sec_raw).map_err(|_| Error::InvalidPoint)?; let public_serialized = public_sec.serialize_vec(&SECP256K1, true); let mut data = vec![0u8; 33 + T::len()]; @@ -327,22 +362,22 @@ mod derivation { let new_chain_code = H256::from_slice(&i_512[32..64]); // Generated private key can (extremely rarely) be out of secp256k1 key field - if *CURVE_ORDER <= new_private.into_uint() { return Err(Error::MissingIndex); } + if *CURVE_ORDER <= new_private.into_uint() { + return Err(Error::MissingIndex); + } let new_private_sec = SecretKey::from_slice(&SECP256K1, new_private.as_bytes()) .expect("Private key belongs to the field [0..CURVE_ORDER) (checked above); So initializing can never fail; qed"); let mut new_public = PublicKey::from_secret_key(&SECP256K1, &new_private_sec) .expect("Valid private key produces valid public key"); // Adding two points on the elliptic curves (combining two public keys) - new_public.add_assign(&SECP256K1, &public_sec) + new_public + .add_assign(&SECP256K1, &public_sec) .expect("Addition of two valid points produce valid point"); let serialized = new_public.serialize_vec(&SECP256K1, false); - Ok(( - H512::from_slice(&serialized[1..65]), - new_chain_code, - )) + Ok((H512::from_slice(&serialized[1..65]), new_chain_code)) } fn sha3(slc: &[u8]) -> H256 { @@ -352,15 +387,17 @@ mod derivation { pub fn chain_code(secret: H256) -> H256 { // 10,000 rounds of sha3 let mut running_sha3 = sha3(secret.as_bytes()); - for _ in 0..99999 { running_sha3 = sha3(running_sha3.as_bytes()); } + for _ in 0..99999 { + running_sha3 = sha3(running_sha3.as_bytes()); + } running_sha3 } pub fn point(secret: H256) -> Result { let sec = SecretKey::from_slice(&SECP256K1, secret.as_bytes()) .map_err(|_| Error::InvalidPoint)?; - let public_sec = PublicKey::from_secret_key(&SECP256K1, &sec) - .map_err(|_| Error::InvalidPoint)?; + let public_sec = + PublicKey::from_secret_key(&SECP256K1, &sec).map_err(|_| Error::InvalidPoint)?; let serialized = public_sec.serialize_vec(&SECP256K1, false); Ok(H512::from_slice(&serialized[1..65])) } @@ -378,11 +415,11 @@ mod derivation { #[cfg(test)] mod tests { - use super::{ExtendedSecret, ExtendedPublic, ExtendedKeyPair}; use super::super::Secret; - use std::str::FromStr; - use ethereum_types::{H128, H256, H512}; use super::{derivation, Derivation}; + use super::{ExtendedKeyPair, ExtendedPublic, ExtendedSecret}; + use ethereum_types::{H128, H256, H512}; + use std::str::FromStr; fn master_chain_basic() -> (H256, H256) { let seed = H128::from_str("000102030405060708090a0b0c0d0e0f") @@ -393,7 +430,10 @@ mod tests { derivation::seed_pair(&*seed) } - fn test_extended(f: F, test_private: H256) where F: Fn(ExtendedSecret) -> ExtendedSecret { + fn test_extended(f: F, test_private: H256) + where + F: Fn(ExtendedSecret) -> ExtendedSecret, + { let (private_seed, chain_code) = master_chain_basic(); let extended_secret = ExtendedSecret::with_code(Secret::from(private_seed.0), chain_code); let derived = f(extended_secret); @@ -402,80 +442,126 @@ mod tests { #[test] fn smoky() { - let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); + let secret = + Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") + .unwrap(); let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::zero()); // hardened assert_eq!(&**extended_secret.as_raw(), &*secret); assert_eq!( **extended_secret.derive(2147483648.into()).as_raw(), - H256::from_str("0927453daed47839608e414a3738dfad10aed17c459bbd9ab53f89b026c834b6").unwrap(), + H256::from_str("0927453daed47839608e414a3738dfad10aed17c459bbd9ab53f89b026c834b6") + .unwrap(), ); assert_eq!( **extended_secret.derive(2147483649.into()).as_raw(), - H256::from_str("44238b6a29c6dcbe9b401364141ba11e2198c289a5fed243a1c11af35c19dc0f").unwrap(), + H256::from_str("44238b6a29c6dcbe9b401364141ba11e2198c289a5fed243a1c11af35c19dc0f") + .unwrap(), ); // normal - assert_eq!(**extended_secret.derive(0.into()).as_raw(), H256::from_str("bf6a74e3f7b36fc4c96a1e12f31abc817f9f5904f5a8fc27713163d1f0b713f6").unwrap()); - assert_eq!(**extended_secret.derive(1.into()).as_raw(), H256::from_str("bd4fca9eb1f9c201e9448c1eecd66e302d68d4d313ce895b8c134f512205c1bc").unwrap()); - assert_eq!(**extended_secret.derive(2.into()).as_raw(), H256::from_str("86932b542d6cab4d9c65490c7ef502d89ecc0e2a5f4852157649e3251e2a3268").unwrap()); + assert_eq!( + **extended_secret.derive(0.into()).as_raw(), + H256::from_str("bf6a74e3f7b36fc4c96a1e12f31abc817f9f5904f5a8fc27713163d1f0b713f6") + .unwrap() + ); + assert_eq!( + **extended_secret.derive(1.into()).as_raw(), + H256::from_str("bd4fca9eb1f9c201e9448c1eecd66e302d68d4d313ce895b8c134f512205c1bc") + .unwrap() + ); + assert_eq!( + **extended_secret.derive(2.into()).as_raw(), + H256::from_str("86932b542d6cab4d9c65490c7ef502d89ecc0e2a5f4852157649e3251e2a3268") + .unwrap() + ); - let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); - let derived_public = extended_public.derive(0.into()).expect("First derivation of public should succeed"); + let extended_public = ExtendedPublic::from_secret(&extended_secret) + .expect("Extended public should be created"); + let derived_public = extended_public + .derive(0.into()) + .expect("First derivation of public should succeed"); assert_eq!( *derived_public.public(), H512::from_str("f7b3244c96688f92372bfd4def26dc4151529747bab9f188a4ad34e141d47bd66522ff048bc6f19a0a4429b04318b1a8796c000265b4fa200dae5f6dda92dd94").unwrap(), ); let keypair = ExtendedKeyPair::with_secret( - Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(), + Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") + .unwrap(), H256::from_low_u64_be(64), ); assert_eq!( - **keypair.derive(2147483648u32.into()).expect("Derivation of keypair should succeed").secret().as_raw(), - H256::from_str("edef54414c03196557cf73774bc97a645c9a1df2164ed34f0c2a78d1375a930c").unwrap(), + **keypair + .derive(2147483648u32.into()) + .expect("Derivation of keypair should succeed") + .secret() + .as_raw(), + H256::from_str("edef54414c03196557cf73774bc97a645c9a1df2164ed34f0c2a78d1375a930c") + .unwrap(), ); } #[test] fn h256_soft_match() { - let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); - let derivation_secret = H256::from_str("51eaf04f9dbbc1417dc97e789edd0c37ecda88bac490434e367ea81b71b7b015").unwrap(); + let secret = + Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") + .unwrap(); + let derivation_secret = + H256::from_str("51eaf04f9dbbc1417dc97e789edd0c37ecda88bac490434e367ea81b71b7b015") + .unwrap(); let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::zero()); - let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); + let extended_public = ExtendedPublic::from_secret(&extended_secret) + .expect("Extended public should be created"); let derived_secret0 = extended_secret.derive(Derivation::Soft(derivation_secret)); - let derived_public0 = extended_public.derive(Derivation::Soft(derivation_secret)).expect("First derivation of public should succeed"); + let derived_public0 = extended_public + .derive(Derivation::Soft(derivation_secret)) + .expect("First derivation of public should succeed"); - let public_from_secret0 = ExtendedPublic::from_secret(&derived_secret0).expect("Extended public should be created"); + let public_from_secret0 = ExtendedPublic::from_secret(&derived_secret0) + .expect("Extended public should be created"); assert_eq!(public_from_secret0.public(), derived_public0.public()); } #[test] fn h256_hard() { - let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); - let derivation_secret = H256::from_str("51eaf04f9dbbc1417dc97e789edd0c37ecda88bac490434e367ea81b71b7b015").unwrap(); + let secret = + Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") + .unwrap(); + let derivation_secret = + H256::from_str("51eaf04f9dbbc1417dc97e789edd0c37ecda88bac490434e367ea81b71b7b015") + .unwrap(); let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::from_low_u64_be(1)); assert_eq!( - **extended_secret.derive(Derivation::Hard(derivation_secret)).as_raw(), - H256::from_str("2bc2d696fb744d77ff813b4a1ef0ad64e1e5188b622c54ba917acc5ebc7c5486").unwrap(), + **extended_secret + .derive(Derivation::Hard(derivation_secret)) + .as_raw(), + H256::from_str("2bc2d696fb744d77ff813b4a1ef0ad64e1e5188b622c54ba917acc5ebc7c5486") + .unwrap(), ); } #[test] fn match_() { - let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); + let secret = + Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") + .unwrap(); let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::from_low_u64_be(1)); - let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); + let extended_public = ExtendedPublic::from_secret(&extended_secret) + .expect("Extended public should be created"); let derived_secret0 = extended_secret.derive(0.into()); - let derived_public0 = extended_public.derive(0.into()).expect("First derivation of public should succeed"); + let derived_public0 = extended_public + .derive(0.into()) + .expect("First derivation of public should succeed"); - let public_from_secret0 = ExtendedPublic::from_secret(&derived_secret0).expect("Extended public should be created"); + let public_from_secret0 = ExtendedPublic::from_secret(&derived_secret0) + .expect("Extended public should be created"); assert_eq!(public_from_secret0.public(), derived_public0.public()); } @@ -489,8 +575,9 @@ mod tests { // private key from bitcoin test vector // xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs - let test_private = H256::from_str("e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35") - .expect("Private should be decoded ok"); + let test_private = + H256::from_str("e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35") + .expect("Private should be decoded ok"); let (private_seed, _) = derivation::seed_pair(&*seed); @@ -504,7 +591,7 @@ mod tests { test_extended( |secret| secret.derive(2147483648.into()), H256::from_str("edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea") - .expect("Private should be decoded ok") + .expect("Private should be decoded ok"), ); } @@ -515,7 +602,7 @@ mod tests { test_extended( |secret| secret.derive(2147483648.into()).derive(1.into()), H256::from_str("3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368") - .expect("Private should be decoded ok") + .expect("Private should be decoded ok"), ); } } diff --git a/parity-crypto/src/publickey/keypair.rs b/parity-crypto/src/publickey/keypair.rs index 04a9dbadd..94e414dce 100644 --- a/parity-crypto/src/publickey/keypair.rs +++ b/parity-crypto/src/publickey/keypair.rs @@ -16,10 +16,10 @@ //! Key pair (public + secrect) description -use std::fmt; -use secp256k1::key; -use super::{Secret, Public, Address, SECP256K1, Error}; +use super::{Address, Error, Public, Secret, SECP256K1}; use crate::Keccak256; +use secp256k1::key; +use std::fmt; /// Convert public key into the address pub fn public_to_address(public: &Public) -> Address { @@ -76,10 +76,7 @@ impl KeyPair { let mut public = Public::default(); public.as_bytes_mut().copy_from_slice(&serialized[1..65]); - KeyPair { - secret, - public, - } + KeyPair { secret, public } } /// Returns secret part of the keypair @@ -100,12 +97,14 @@ impl KeyPair { #[cfg(test)] mod tests { - use std::str::FromStr; use super::{KeyPair, Secret}; + use std::str::FromStr; #[test] fn from_secret() { - let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); + let secret = + Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") + .unwrap(); let _ = KeyPair::from_secret(secret).unwrap(); } @@ -115,7 +114,9 @@ mod tests { "secret: a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65 public: 8ce0db0b0359ffc5866ba61903cc2518c3675ef2cf380a7e54bde7ea20e6fa1ab45b7617346cd11b7610001ee6ae5b0155c41cad9527cbcdff44ec67848943a4 address: 5b073e9233944b5e729e46d618f0d8edf3d9c34a".to_owned(); - let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); + let secret = + Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") + .unwrap(); let kp = KeyPair::from_secret(secret).unwrap(); assert_eq!(format!("{}", kp), expected); } diff --git a/parity-crypto/src/publickey/keypair_generator.rs b/parity-crypto/src/publickey/keypair_generator.rs index e816bc6df..361d8a359 100644 --- a/parity-crypto/src/publickey/keypair_generator.rs +++ b/parity-crypto/src/publickey/keypair_generator.rs @@ -16,9 +16,9 @@ //! Random key pair generator. Relies on the secp256k1 C-library to generate random data. +use super::{Generator, KeyPair, SECP256K1}; use rand::rngs::OsRng; use std::convert::Infallible; -use super::{Generator, KeyPair, SECP256K1}; /// Randomly generates new keypair, instantiating the RNG each time. pub struct Random; @@ -38,7 +38,8 @@ impl Generator for OsRng { type Error = Infallible; fn generate(&mut self) -> Result { - let (sec, publ) = SECP256K1.generate_keypair(self) + let (sec, publ) = SECP256K1 + .generate_keypair(self) .expect("context always created with full capabilities; qed"); Ok(KeyPair::from_keypair(sec, publ)) diff --git a/parity-crypto/src/publickey/mod.rs b/parity-crypto/src/publickey/mod.rs index c983f0112..97679356b 100644 --- a/parity-crypto/src/publickey/mod.rs +++ b/parity-crypto/src/publickey/mod.rs @@ -17,24 +17,26 @@ //! Submodule of crypto utils for working with public key crypto primitives //! If you are looking for git history please refer to the `ethkey` crate in the `parity-ethereum` repository. +mod ecdsa_signature; +mod extended_keys; mod keypair; mod keypair_generator; -mod ecdsa_signature; mod secret_key; -mod extended_keys; +pub mod ec_math_utils; pub mod ecdh; pub mod ecies; -pub mod ec_math_utils; pub mod error; -pub use self::keypair::{KeyPair, public_to_address}; pub use self::ec_math_utils::public_is_valid; -pub use self::keypair_generator::Random; +pub use self::ecdsa_signature::{recover, sign, verify_address, verify_public, Signature}; pub use self::error::Error; -pub use self::ecdsa_signature::{sign, verify_public, verify_address, recover, Signature}; +pub use self::extended_keys::{ + Derivation, DerivationError, ExtendedKeyPair, ExtendedPublic, ExtendedSecret, +}; +pub use self::keypair::{public_to_address, KeyPair}; +pub use self::keypair_generator::Random; pub use self::secret_key::Secret; -pub use self::extended_keys::{ExtendedPublic, ExtendedSecret, ExtendedKeyPair, DerivationError, Derivation}; use ethereum_types::H256; use lazy_static::lazy_static; diff --git a/parity-crypto/src/publickey/secret_key.rs b/parity-crypto/src/publickey/secret_key.rs index ef8590c1d..9864ab6ef 100644 --- a/parity-crypto/src/publickey/secret_key.rs +++ b/parity-crypto/src/publickey/secret_key.rs @@ -16,15 +16,15 @@ //! Secret key implementation +use super::{Error, SECP256K1}; +use ethereum_types::H256; +use secp256k1::constants::SECRET_KEY_SIZE as SECP256K1_SECRET_KEY_SIZE; +use secp256k1::key; +use std::convert::TryFrom; use std::fmt; use std::ops::Deref; use std::str::FromStr; -use std::convert::TryFrom; -use secp256k1::constants::{SECRET_KEY_SIZE as SECP256K1_SECRET_KEY_SIZE}; -use secp256k1::key; -use ethereum_types::H256; use zeroize::Zeroize; -use super::{SECP256K1, Error}; /// Represents secret key #[derive(Clone, PartialEq, Eq)] @@ -52,7 +52,11 @@ impl fmt::Debug for Secret { impl fmt::Display for Secret { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - write!(fmt, "Secret: 0x{:x}{:x}..{:x}{:x}", self.inner[0], self.inner[1], self.inner[30], self.inner[31]) + write!( + fmt, + "Secret: 0x{:x}{:x}..{:x}{:x}", + self.inner[0], self.inner[1], self.inner[30], self.inner[31] + ) } } @@ -60,7 +64,7 @@ impl Secret { /// Creates a `Secret` from the given slice, returning `None` if the slice length != 32. pub fn copy_from_slice(key: &[u8]) -> Option { if key.len() != 32 { - return None + return None; } let mut h = H256::zero(); h.as_bytes_mut().copy_from_slice(&key[0..32]); @@ -69,7 +73,9 @@ impl Secret { /// Creates zero key, which is invalid for crypto operations, but valid for math operation. pub fn zero() -> Self { - Secret { inner: H256::zero() } + Secret { + inner: H256::zero(), + } } /// Imports and validates the key. @@ -95,7 +101,7 @@ impl Secret { (true, false) => { *self = other.clone(); Ok(()) - }, + } (false, false) => { let mut key_secret = self.to_secp256k1_secret()?; let other_secret = other.to_secp256k1_secret()?; @@ -103,7 +109,7 @@ impl Secret { *self = key_secret.into(); Ok(()) - }, + } } } @@ -114,7 +120,7 @@ impl Secret { (true, false) => { *self = other.clone(); self.neg() - }, + } (false, false) => { let mut key_secret = self.to_secp256k1_secret()?; let mut other_secret = other.to_secp256k1_secret()?; @@ -123,7 +129,7 @@ impl Secret { *self = key_secret.into(); Ok(()) - }, + } } } @@ -133,14 +139,14 @@ impl Secret { true => { *self = key::MINUS_ONE_KEY.into(); Ok(()) - }, + } false => { let mut key_secret = self.to_secp256k1_secret()?; key_secret.add_assign(&SECP256K1, &key::MINUS_ONE_KEY)?; *self = key_secret.into(); Ok(()) - }, + } } } @@ -151,7 +157,7 @@ impl Secret { (false, true) => { *self = Self::zero(); Ok(()) - }, + } (false, false) => { let mut key_secret = self.to_secp256k1_secret()?; let other_secret = other.to_secp256k1_secret()?; @@ -159,7 +165,7 @@ impl Secret { *self = key_secret.into(); Ok(()) - }, + } } } @@ -173,7 +179,7 @@ impl Secret { *self = key_secret.into(); Ok(()) - }, + } } } @@ -200,7 +206,7 @@ impl Secret { for _ in 1..pow { self.mul(&c)?; } - }, + } } Ok(()) @@ -215,7 +221,9 @@ impl Secret { impl FromStr for Secret { type Err = Error; fn from_str(s: &str) -> Result { - Ok(H256::from_str(s).map_err(|e| Error::Custom(format!("{:?}", e)))?.into()) + Ok(H256::from_str(s) + .map_err(|e| Error::Custom(format!("{:?}", e)))? + .into()) } } @@ -242,7 +250,7 @@ impl TryFrom<&str> for Secret { impl From for Secret { fn from(key: key::SecretKey) -> Self { let mut a = [0; SECP256K1_SECRET_KEY_SIZE]; - a.copy_from_slice(&key[0 .. SECP256K1_SECRET_KEY_SIZE]); + a.copy_from_slice(&key[0..SECP256K1_SECRET_KEY_SIZE]); a.into() } } @@ -257,9 +265,9 @@ impl Deref for Secret { #[cfg(test)] mod tests { - use std::str::FromStr; - use super::super::{Random, Generator}; + use super::super::{Generator, Random}; use super::Secret; + use std::str::FromStr; #[test] fn multiplicating_secret_inversion_with_secret_gives_one() { @@ -267,7 +275,11 @@ mod tests { let mut inversion = secret.clone(); inversion.inv().unwrap(); inversion.mul(&secret).unwrap(); - assert_eq!(inversion, Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap()); + assert_eq!( + inversion, + Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001") + .unwrap() + ); } #[test] @@ -285,7 +297,11 @@ mod tests { let mut pow0 = secret.clone(); pow0.pow(0).unwrap(); - assert_eq!(pow0, Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap()); + assert_eq!( + pow0, + Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001") + .unwrap() + ); let mut pow1 = secret.clone(); pow1.pow(1).unwrap(); diff --git a/parity-crypto/src/scrypt.rs b/parity-crypto/src/scrypt.rs index 9c8443146..a44464b52 100644 --- a/parity-crypto/src/scrypt.rs +++ b/parity-crypto/src/scrypt.rs @@ -14,21 +14,27 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use super::{KEY_LENGTH, KEY_LENGTH_AES}; use crate::error::ScryptError; -use super::{KEY_LENGTH_AES, KEY_LENGTH}; use scrypt::{scrypt, ScryptParams}; #[cfg(test)] use std::io::Error; -pub fn derive_key(pass: &[u8], salt: &[u8], n: u32, p: u32, r: u32) -> Result<(Vec, Vec), ScryptError> { +pub fn derive_key( + pass: &[u8], + salt: &[u8], + n: u32, + p: u32, + r: u32, +) -> Result<(Vec, Vec), ScryptError> { // sanity checks let log_n = (32 - n.leading_zeros() - 1) as u8; if log_n as u32 >= r * 16 { return Err(ScryptError::InvalidN); } - if p as u64 > ((u32::max_value() as u64 - 1) * 32)/(128 * (r as u64)) { + if p as u64 > ((u32::max_value() as u64 - 1) * 32) / (128 * (r as u64)) { return Err(ScryptError::InvalidP); } @@ -40,23 +46,32 @@ pub fn derive_key(pass: &[u8], salt: &[u8], n: u32, p: u32, r: u32) -> Result<(V Ok((derived_right_bits.to_vec(), derived_left_bits.to_vec())) } - // test is build from previous crypto lib behaviour, values may be incorrect // if previous crypto lib got a bug. #[test] -pub fn test_derive() -> Result<(),Error> { +pub fn test_derive() -> Result<(), Error> { let pass = [109, 121, 112, 97, 115, 115, 10]; - let salt = [109, 121, 115, 97, 108, 116, 115, 104, 111, 117, 108, 100, 102, 105, - 108, 108, 115, 111, 109, 109, 101, 98, 121, 116, 101, 108, 101, 110, 103, 116, 104, 10]; - let r1 = [93, 134, 79, 68, 223, 27, 44, 174, 236, 184, 179, 203, 74, 139, 73, 66]; - let r2 = [2, 24, 239, 131, 172, 164, 18, 171, 132, 207, 22, 217, 150, 20, 203, 37]; - let l1 = [6, 90, 119, 45, 67, 2, 99, 151, 81, 88, 166, 210, 244, 19, 123, 208]; - let l2 = [253, 123, 132, 12, 188, 89, 196, 2, 107, 224, 239, 231, 135, 177, 125, 62]; - - let (l,r) = derive_key(&pass[..],&salt, 262, 1, 8).unwrap(); + let salt = [ + 109, 121, 115, 97, 108, 116, 115, 104, 111, 117, 108, 100, 102, 105, 108, 108, 115, 111, + 109, 109, 101, 98, 121, 116, 101, 108, 101, 110, 103, 116, 104, 10, + ]; + let r1 = [ + 93, 134, 79, 68, 223, 27, 44, 174, 236, 184, 179, 203, 74, 139, 73, 66, + ]; + let r2 = [ + 2, 24, 239, 131, 172, 164, 18, 171, 132, 207, 22, 217, 150, 20, 203, 37, + ]; + let l1 = [ + 6, 90, 119, 45, 67, 2, 99, 151, 81, 88, 166, 210, 244, 19, 123, 208, + ]; + let l2 = [ + 253, 123, 132, 12, 188, 89, 196, 2, 107, 224, 239, 231, 135, 177, 125, 62, + ]; + + let (l, r) = derive_key(&pass[..], &salt, 262, 1, 8).unwrap(); assert!(l == r1); assert!(r == l1); - let (l,r) = derive_key(&pass[..],&salt, 144, 4, 4).unwrap(); + let (l, r) = derive_key(&pass[..], &salt, 144, 4, 4).unwrap(); assert!(l == r2); assert!(r == l2); Ok(()) diff --git a/parity-path/src/lib.rs b/parity-path/src/lib.rs index ffd4e9a0c..0fda82610 100644 --- a/parity-path/src/lib.rs +++ b/parity-path/src/lib.rs @@ -62,7 +62,9 @@ pub mod ethereum { use std::path::PathBuf; /// Default path for ethereum installation on Mac Os - pub fn default() -> PathBuf { super::config_path("Ethereum") } + pub fn default() -> PathBuf { + super::config_path("Ethereum") + } /// Default path for ethereum installation (testnet) pub fn test() -> PathBuf { @@ -89,14 +91,24 @@ pub mod ethereum { /// Restricts the permissions of given path only to the owner. #[cfg(unix)] -pub fn restrict_permissions_owner(file_path: &Path, write: bool, executable: bool) -> Result<(), String> { - let perms = ::std::os::unix::fs::PermissionsExt::from_mode(0o400 + write as u32 * 0o200 + executable as u32 * 0o100); +pub fn restrict_permissions_owner( + file_path: &Path, + write: bool, + executable: bool, +) -> Result<(), String> { + let perms = ::std::os::unix::fs::PermissionsExt::from_mode( + 0o400 + write as u32 * 0o200 + executable as u32 * 0o100, + ); ::std::fs::set_permissions(file_path, perms).map_err(|e| format!("{:?}", e)) } /// Restricts the permissions of given path only to the owner. #[cfg(not(unix))] -pub fn restrict_permissions_owner(_file_path: &Path, _write: bool, _executable: bool) -> Result<(), String> { +pub fn restrict_permissions_owner( + _file_path: &Path, + _write: bool, + _executable: bool, +) -> Result<(), String> { //TODO: implement me Ok(()) } diff --git a/parity-util-mem/src/allocators.rs b/parity-util-mem/src/allocators.rs index 9193dab9c..3919c4356 100644 --- a/parity-util-mem/src/allocators.rs +++ b/parity-util-mem/src/allocators.rs @@ -41,87 +41,86 @@ //! - jemalloc: compile error //! - mimalloc: compile error (until https://github.com/microsoft/mimalloc/pull/32 is merged) - -use crate::malloc_size::{MallocSizeOfOps, VoidPtrToSizeFn, MallocSizeOf}; #[cfg(feature = "std")] use crate::malloc_size::MallocUnconditionalSizeOf; -#[cfg(feature = "std")] -use std::os::raw::c_void; +use crate::malloc_size::{MallocSizeOf, MallocSizeOfOps, VoidPtrToSizeFn}; #[cfg(not(feature = "std"))] use core::ffi::c_void; +#[cfg(feature = "std")] +use std::os::raw::c_void; mod usable_size { use super::*; -cfg_if::cfg_if! { + cfg_if::cfg_if! { - if #[cfg(any( - target_arch = "wasm32", - feature = "estimate-heapsize", - feature = "weealloc-global", - feature = "dlmalloc-global", - ))] { + if #[cfg(any( + target_arch = "wasm32", + feature = "estimate-heapsize", + feature = "weealloc-global", + feature = "dlmalloc-global", + ))] { - // do not try system allocator + // do not try system allocator - /// Warning this is for compatibility only. - /// This function does panic: `estimate-heapsize` feature needs to be activated - /// to avoid this function call. - pub unsafe extern "C" fn malloc_usable_size(_ptr: *const c_void) -> usize { - unreachable!("estimate heapsize only") - } + /// Warning this is for compatibility only. + /// This function does panic: `estimate-heapsize` feature needs to be activated + /// to avoid this function call. + pub unsafe extern "C" fn malloc_usable_size(_ptr: *const c_void) -> usize { + unreachable!("estimate heapsize only") + } - } else if #[cfg(target_os = "windows")] { + } else if #[cfg(target_os = "windows")] { - use winapi::um::heapapi::{GetProcessHeap, HeapSize, HeapValidate}; + use winapi::um::heapapi::{GetProcessHeap, HeapSize, HeapValidate}; - /// Get the size of a heap block. - /// Call windows allocator through `winapi` crate - pub unsafe extern "C" fn malloc_usable_size(mut ptr: *const c_void) -> usize { + /// Get the size of a heap block. + /// Call windows allocator through `winapi` crate + pub unsafe extern "C" fn malloc_usable_size(mut ptr: *const c_void) -> usize { - let heap = GetProcessHeap(); + let heap = GetProcessHeap(); - if HeapValidate(heap, 0, ptr) == 0 { - ptr = *(ptr as *const *const c_void).offset(-1); + if HeapValidate(heap, 0, ptr) == 0 { + ptr = *(ptr as *const *const c_void).offset(-1); + } + + HeapSize(heap, 0, ptr) as usize } - HeapSize(heap, 0, ptr) as usize - } + } else if #[cfg(feature = "jemalloc-global")] { - } else if #[cfg(feature = "jemalloc-global")] { + /// Use of jemalloc usable size C function through jemallocator crate call. + pub unsafe extern "C" fn malloc_usable_size(ptr: *const c_void) -> usize { + jemallocator::usable_size(ptr) + } - /// Use of jemalloc usable size C function through jemallocator crate call. - pub unsafe extern "C" fn malloc_usable_size(ptr: *const c_void) -> usize { - jemallocator::usable_size(ptr) - } + } else if #[cfg(feature = "mimalloc-global")] { - } else if #[cfg(feature = "mimalloc-global")] { + /// Use of mimalloc usable size C function through mimalloc_sys crate call. + pub unsafe extern "C" fn malloc_usable_size(ptr: *const c_void) -> usize { + // mimalloc doesn't actually mutate the value ptr points to, + // but requires a mut pointer in the API + mimalloc_sys::mi_usable_size(ptr as *mut _) + } - /// Use of mimalloc usable size C function through mimalloc_sys crate call. - pub unsafe extern "C" fn malloc_usable_size(ptr: *const c_void) -> usize { - // mimalloc doesn't actually mutate the value ptr points to, - // but requires a mut pointer in the API - mimalloc_sys::mi_usable_size(ptr as *mut _) - } + } else if #[cfg(target_os = "linux")] { - } else if #[cfg(target_os = "linux")] { + /// Linux call system allocator (currently malloc). + extern "C" { + pub fn malloc_usable_size(ptr: *const c_void) -> usize; + } - /// Linux call system allocator (currently malloc). - extern "C" { - pub fn malloc_usable_size(ptr: *const c_void) -> usize; - } + } else { + // default allocator for non linux or windows system use estimate + pub unsafe extern "C" fn malloc_usable_size(_ptr: *const c_void) -> usize { + unreachable!("estimate heapsize or feature allocator needed") + } - } else { - // default allocator for non linux or windows system use estimate - pub unsafe extern "C" fn malloc_usable_size(_ptr: *const c_void) -> usize { - unreachable!("estimate heapsize or feature allocator needed") } } -} - /// No enclosing function defined. #[inline] pub fn new_enclosing_size_fn() -> Option { @@ -151,7 +150,7 @@ pub trait MallocSizeOfExt: MallocSizeOf { } } -impl MallocSizeOfExt for T { } +impl MallocSizeOfExt for T {} #[cfg(feature = "std")] impl MallocSizeOf for std::sync::Arc { diff --git a/parity-util-mem/src/impls.rs b/parity-util-mem/src/impls.rs index b6fd44d97..155f37aa4 100644 --- a/parity-util-mem/src/impls.rs +++ b/parity-util-mem/src/impls.rs @@ -19,27 +19,14 @@ //! - elastic_array arrays //! - parking_lot mutex structures -use ethereum_types::{ - U64, U128, U256, U512, H32, H64, - H128, H160, H256, H264, H512, H520, - Bloom -}; +use super::{MallocSizeOf, MallocSizeOfOps}; use elastic_array::{ - ElasticArray2, - ElasticArray4, - ElasticArray8, - ElasticArray16, - ElasticArray32, - ElasticArray36, - ElasticArray64, - ElasticArray128, - ElasticArray256, - ElasticArray512, - ElasticArray1024, - ElasticArray2048, + ElasticArray1024, ElasticArray128, ElasticArray16, ElasticArray2, ElasticArray2048, + ElasticArray256, ElasticArray32, ElasticArray36, ElasticArray4, ElasticArray512, + ElasticArray64, ElasticArray8, }; +use ethereum_types::{Bloom, H128, H160, H256, H264, H32, H512, H520, H64, U128, U256, U512, U64}; use parking_lot::{Mutex, RwLock}; -use super::{MallocSizeOf, MallocSizeOfOps}; #[cfg(not(feature = "std"))] use core as std; @@ -48,21 +35,19 @@ use core as std; malloc_size_of_is_0!(std::time::Instant); malloc_size_of_is_0!(std::time::Duration); -malloc_size_of_is_0!( - U64, U128, U256, U512, H32, H64, - H128, H160, H256, H264, H512, H520, - Bloom -); +malloc_size_of_is_0!(U64, U128, U256, U512, H32, H64, H128, H160, H256, H264, H512, H520, Bloom); macro_rules! impl_elastic_array { - ($name: ident, $dummy: ident, $size: expr) => ( + ($name: ident, $dummy: ident, $size: expr) => { impl MallocSizeOf for $name - where T: MallocSizeOf { + where + T: MallocSizeOf, + { fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { self[..].size_of(ops) } } - ) + }; } impl_elastic_array!(ElasticArray2, ElasticArray2Dummy, 2); @@ -78,7 +63,6 @@ impl_elastic_array!(ElasticArray512, ElasticArray512Dummy, 512); impl_elastic_array!(ElasticArray1024, ElasticArray1024Dummy, 1024); impl_elastic_array!(ElasticArray2048, ElasticArray2048Dummy, 2048); - impl MallocSizeOf for Mutex { fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { (*self.lock()).size_of(ops) diff --git a/parity-util-mem/src/lib.rs b/parity-util-mem/src/lib.rs index b55e5dc9e..e2198981e 100644 --- a/parity-util-mem/src/lib.rs +++ b/parity-util-mem/src/lib.rs @@ -25,7 +25,6 @@ extern crate alloc; use malloc_size_of_derive as malloc_size_derive; - cfg_if::cfg_if! { if #[cfg(all( feature = "jemalloc-global", @@ -58,10 +57,7 @@ cfg_if::cfg_if! { pub mod allocators; #[cfg(any( - all( - target_os = "macos", - not(feature = "jemalloc-global"), - ), + all(target_os = "macos", not(feature = "jemalloc-global"),), feature = "estimate-heapsize" ))] pub mod sizeof; @@ -71,23 +67,21 @@ pub mod sizeof; /// if at some point the trait become standard enough we could use the right way of doing it /// by implementing it in our type traits crates. At this time moving this trait to the primitive /// types level would impact too much of the dependencies to be easily manageable. -#[macro_use] mod malloc_size; +#[macro_use] +mod malloc_size; #[cfg(feature = "ethereum-impls")] pub mod impls; -pub use malloc_size_derive::*; -pub use malloc_size::{ - MallocSizeOfOps, - MallocSizeOf, -}; pub use allocators::MallocSizeOfExt; +pub use malloc_size::{MallocSizeOf, MallocSizeOfOps}; +pub use malloc_size_derive::*; #[cfg(feature = "std")] #[cfg(test)] mod test { - use std::sync::Arc; use super::MallocSizeOfExt; + use std::sync::Arc; #[test] fn test_arc() { diff --git a/parity-util-mem/src/malloc_size.rs b/parity-util-mem/src/malloc_size.rs index 8c2e06deb..eedf5fc2a 100644 --- a/parity-util-mem/src/malloc_size.rs +++ b/parity-util-mem/src/malloc_size.rs @@ -43,10 +43,8 @@ //! measured as well as the thing it points to. E.g. //! ` as MallocSizeOf>::size_of(field, ops)`. - // This file is patched at commit 5bdea7dc1c80790a852a3fb03edfb2b8fbd403dc DO NOT EDIT. - #[cfg(not(feature = "std"))] use alloc::vec::Vec; #[cfg(feature = "std")] @@ -55,7 +53,7 @@ mod rstd { } #[cfg(not(feature = "std"))] mod rstd { - pub use core::*; + pub use core::*; pub mod collections { pub use alloc::collections::*; pub use vec_deque::VecDeque; @@ -65,18 +63,18 @@ mod rstd { #[cfg(feature = "std")] use std::sync::Arc; -#[cfg(feature = "std")] -use std::hash::BuildHasher; +#[cfg(not(feature = "std"))] +pub use alloc::boxed::Box; +#[cfg(not(feature = "std"))] +use core::ffi::c_void; use rstd::hash::Hash; use rstd::mem::size_of; use rstd::ops::Range; use rstd::ops::{Deref, DerefMut}; #[cfg(feature = "std")] +use std::hash::BuildHasher; +#[cfg(feature = "std")] use std::os::raw::c_void; -#[cfg(not(feature = "std"))] -use core::ffi::c_void; -#[cfg(not(feature = "std"))] -pub use alloc::boxed::Box; /// A C function that takes a pointer to a heap allocation and returns its size. pub type VoidPtrToSizeFn = unsafe extern "C" fn(ptr: *const c_void) -> usize; @@ -86,428 +84,424 @@ pub type VoidPtrToBoolFnMut = dyn FnMut(*const c_void) -> bool; /// Operations used when measuring heap usage of data structures. pub struct MallocSizeOfOps { - /// A function that returns the size of a heap allocation. - size_of_op: VoidPtrToSizeFn, + /// A function that returns the size of a heap allocation. + size_of_op: VoidPtrToSizeFn, - /// Like `size_of_op`, but can take an interior pointer. Optional because - /// not all allocators support this operation. If it's not provided, some - /// memory measurements will actually be computed estimates rather than - /// real and accurate measurements. - enclosing_size_of_op: Option, + /// Like `size_of_op`, but can take an interior pointer. Optional because + /// not all allocators support this operation. If it's not provided, some + /// memory measurements will actually be computed estimates rather than + /// real and accurate measurements. + enclosing_size_of_op: Option, - /// Check if a pointer has been seen before, and remember it for next time. - /// Useful when measuring `Rc`s and `Arc`s. Optional, because many places - /// don't need it. - have_seen_ptr_op: Option>, + /// Check if a pointer has been seen before, and remember it for next time. + /// Useful when measuring `Rc`s and `Arc`s. Optional, because many places + /// don't need it. + have_seen_ptr_op: Option>, } impl MallocSizeOfOps { - pub fn new( - size_of: VoidPtrToSizeFn, - malloc_enclosing_size_of: Option, - have_seen_ptr: Option>, - ) -> Self { - MallocSizeOfOps { - size_of_op: size_of, - enclosing_size_of_op: malloc_enclosing_size_of, - have_seen_ptr_op: have_seen_ptr, - } - } - - /// Check if an allocation is empty. This relies on knowledge of how Rust - /// handles empty allocations, which may change in the future. - fn is_empty(ptr: *const T) -> bool { - // The correct condition is this: - // `ptr as usize <= ::std::mem::align_of::()` - // But we can't call align_of() on a ?Sized T. So we approximate it - // with the following. 256 is large enough that it should always be - // larger than the required alignment, but small enough that it is - // always in the first page of memory and therefore not a legitimate - // address. - return ptr as *const usize as usize <= 256; - } - - /// Call `size_of_op` on `ptr`, first checking that the allocation isn't - /// empty, because some types (such as `Vec`) utilize empty allocations. - pub unsafe fn malloc_size_of(&self, ptr: *const T) -> usize { - if MallocSizeOfOps::is_empty(ptr) { - 0 - } else { - (self.size_of_op)(ptr as *const c_void) - } - } - - /// Is an `enclosing_size_of_op` available? - pub fn has_malloc_enclosing_size_of(&self) -> bool { - self.enclosing_size_of_op.is_some() - } - - /// Call `enclosing_size_of_op`, which must be available, on `ptr`, which - /// must not be empty. - pub unsafe fn malloc_enclosing_size_of(&self, ptr: *const T) -> usize { - assert!(!MallocSizeOfOps::is_empty(ptr)); - (self.enclosing_size_of_op.unwrap())(ptr as *const c_void) - } - - /// Call `have_seen_ptr_op` on `ptr`. - pub fn have_seen_ptr(&mut self, ptr: *const T) -> bool { - let have_seen_ptr_op = self - .have_seen_ptr_op - .as_mut() - .expect("missing have_seen_ptr_op"); - have_seen_ptr_op(ptr as *const c_void) - } + pub fn new( + size_of: VoidPtrToSizeFn, + malloc_enclosing_size_of: Option, + have_seen_ptr: Option>, + ) -> Self { + MallocSizeOfOps { + size_of_op: size_of, + enclosing_size_of_op: malloc_enclosing_size_of, + have_seen_ptr_op: have_seen_ptr, + } + } + + /// Check if an allocation is empty. This relies on knowledge of how Rust + /// handles empty allocations, which may change in the future. + fn is_empty(ptr: *const T) -> bool { + // The correct condition is this: + // `ptr as usize <= ::std::mem::align_of::()` + // But we can't call align_of() on a ?Sized T. So we approximate it + // with the following. 256 is large enough that it should always be + // larger than the required alignment, but small enough that it is + // always in the first page of memory and therefore not a legitimate + // address. + return ptr as *const usize as usize <= 256; + } + + /// Call `size_of_op` on `ptr`, first checking that the allocation isn't + /// empty, because some types (such as `Vec`) utilize empty allocations. + pub unsafe fn malloc_size_of(&self, ptr: *const T) -> usize { + if MallocSizeOfOps::is_empty(ptr) { + 0 + } else { + (self.size_of_op)(ptr as *const c_void) + } + } + + /// Is an `enclosing_size_of_op` available? + pub fn has_malloc_enclosing_size_of(&self) -> bool { + self.enclosing_size_of_op.is_some() + } + + /// Call `enclosing_size_of_op`, which must be available, on `ptr`, which + /// must not be empty. + pub unsafe fn malloc_enclosing_size_of(&self, ptr: *const T) -> usize { + assert!(!MallocSizeOfOps::is_empty(ptr)); + (self.enclosing_size_of_op.unwrap())(ptr as *const c_void) + } + + /// Call `have_seen_ptr_op` on `ptr`. + pub fn have_seen_ptr(&mut self, ptr: *const T) -> bool { + let have_seen_ptr_op = self + .have_seen_ptr_op + .as_mut() + .expect("missing have_seen_ptr_op"); + have_seen_ptr_op(ptr as *const c_void) + } } /// Trait for measuring the "deep" heap usage of a data structure. This is the /// most commonly-used of the traits. pub trait MallocSizeOf { - /// Measure the heap usage of all descendant heap-allocated structures, but - /// not the space taken up by the value itself. - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize; + /// Measure the heap usage of all descendant heap-allocated structures, but + /// not the space taken up by the value itself. + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize; } /// Trait for measuring the "shallow" heap usage of a container. pub trait MallocShallowSizeOf { - /// Measure the heap usage of immediate heap-allocated descendant - /// structures, but not the space taken up by the value itself. Anything - /// beyond the immediate descendants must be measured separately, using - /// iteration. - fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize; + /// Measure the heap usage of immediate heap-allocated descendant + /// structures, but not the space taken up by the value itself. Anything + /// beyond the immediate descendants must be measured separately, using + /// iteration. + fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize; } /// Like `MallocSizeOf`, but with a different name so it cannot be used /// accidentally with derive(MallocSizeOf). For use with types like `Rc` and /// `Arc` when appropriate (e.g. when measuring a "primary" reference). pub trait MallocUnconditionalSizeOf { - /// Measure the heap usage of all heap-allocated descendant structures, but - /// not the space taken up by the value itself. - fn unconditional_size_of(&self, ops: &mut MallocSizeOfOps) -> usize; + /// Measure the heap usage of all heap-allocated descendant structures, but + /// not the space taken up by the value itself. + fn unconditional_size_of(&self, ops: &mut MallocSizeOfOps) -> usize; } /// `MallocUnconditionalSizeOf` combined with `MallocShallowSizeOf`. pub trait MallocUnconditionalShallowSizeOf { - /// `unconditional_size_of` combined with `shallow_size_of`. - fn unconditional_shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize; + /// `unconditional_size_of` combined with `shallow_size_of`. + fn unconditional_shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize; } /// Like `MallocSizeOf`, but only measures if the value hasn't already been /// measured. For use with types like `Rc` and `Arc` when appropriate (e.g. /// when there is no "primary" reference). pub trait MallocConditionalSizeOf { - /// Measure the heap usage of all heap-allocated descendant structures, but - /// not the space taken up by the value itself, and only if that heap usage - /// hasn't already been measured. - fn conditional_size_of(&self, ops: &mut MallocSizeOfOps) -> usize; + /// Measure the heap usage of all heap-allocated descendant structures, but + /// not the space taken up by the value itself, and only if that heap usage + /// hasn't already been measured. + fn conditional_size_of(&self, ops: &mut MallocSizeOfOps) -> usize; } /// `MallocConditionalSizeOf` combined with `MallocShallowSizeOf`. pub trait MallocConditionalShallowSizeOf { - /// `conditional_size_of` combined with `shallow_size_of`. - fn conditional_shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize; + /// `conditional_size_of` combined with `shallow_size_of`. + fn conditional_shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize; } #[cfg(not(any( - all( - target_os = "macos", - not(feature = "jemalloc-global"), - ), + all(target_os = "macos", not(feature = "jemalloc-global"),), feature = "estimate-heapsize" )))] pub mod inner_allocator_use { -use super::*; + use super::*; -#[cfg(not(feature = "std"))] -use alloc::string::String; + #[cfg(not(feature = "std"))] + use alloc::string::String; -impl MallocShallowSizeOf for Box { - fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - unsafe { ops.malloc_size_of(&**self) } - } -} - -impl MallocShallowSizeOf for Vec { - fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - unsafe { ops.malloc_size_of(self.as_ptr()) } - } -} + impl MallocShallowSizeOf for Box { + fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + unsafe { ops.malloc_size_of(&**self) } + } + } -// currently this seems only fine with jemalloc -#[cfg(feature = "std")] -#[cfg(all(feature = "jemalloc-global", not(target_os = "windows")))] -impl MallocUnconditionalShallowSizeOf for Arc { - fn unconditional_shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - unsafe { ops.malloc_size_of(arc_ptr(self)) } - } -} + impl MallocShallowSizeOf for Vec { + fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + unsafe { ops.malloc_size_of(self.as_ptr()) } + } + } -#[cfg(feature = "std")] -#[cfg(not(all(feature = "jemalloc-global", not(target_os = "windows"))))] -impl MallocUnconditionalShallowSizeOf for Arc { - fn unconditional_shallow_size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { - size_of::() - } -} + // currently this seems only fine with jemalloc + #[cfg(feature = "std")] + #[cfg(all(feature = "jemalloc-global", not(target_os = "windows")))] + impl MallocUnconditionalShallowSizeOf for Arc { + fn unconditional_shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + unsafe { ops.malloc_size_of(arc_ptr(self)) } + } + } -impl MallocSizeOf for String { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - unsafe { ops.malloc_size_of(self.as_ptr()) } - } -} + #[cfg(feature = "std")] + #[cfg(not(all(feature = "jemalloc-global", not(target_os = "windows"))))] + impl MallocUnconditionalShallowSizeOf for Arc { + fn unconditional_shallow_size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { + size_of::() + } + } + impl MallocSizeOf for String { + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + unsafe { ops.malloc_size_of(self.as_ptr()) } + } + } } impl<'a, T: ?Sized> MallocSizeOf for &'a T { - fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { - // Zero makes sense for a non-owning reference. - 0 - } + fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { + // Zero makes sense for a non-owning reference. + 0 + } } impl MallocSizeOf for Box { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - self.shallow_size_of(ops) + (**self).size_of(ops) - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + self.shallow_size_of(ops) + (**self).size_of(ops) + } } impl MallocSizeOf for () { - fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { - 0 - } + fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { + 0 + } } impl MallocSizeOf for (T1, T2) where - T1: MallocSizeOf, - T2: MallocSizeOf, + T1: MallocSizeOf, + T2: MallocSizeOf, { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - self.0.size_of(ops) + self.1.size_of(ops) - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + self.0.size_of(ops) + self.1.size_of(ops) + } } impl MallocSizeOf for (T1, T2, T3) where - T1: MallocSizeOf, - T2: MallocSizeOf, - T3: MallocSizeOf, + T1: MallocSizeOf, + T2: MallocSizeOf, + T3: MallocSizeOf, { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - self.0.size_of(ops) + self.1.size_of(ops) + self.2.size_of(ops) - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + self.0.size_of(ops) + self.1.size_of(ops) + self.2.size_of(ops) + } } impl MallocSizeOf for (T1, T2, T3, T4) where - T1: MallocSizeOf, - T2: MallocSizeOf, - T3: MallocSizeOf, - T4: MallocSizeOf, + T1: MallocSizeOf, + T2: MallocSizeOf, + T3: MallocSizeOf, + T4: MallocSizeOf, { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - self.0.size_of(ops) + self.1.size_of(ops) + self.2.size_of(ops) + self.3.size_of(ops) - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + self.0.size_of(ops) + self.1.size_of(ops) + self.2.size_of(ops) + self.3.size_of(ops) + } } impl MallocSizeOf for Option { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - if let Some(val) = self.as_ref() { - val.size_of(ops) - } else { - 0 - } - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + if let Some(val) = self.as_ref() { + val.size_of(ops) + } else { + 0 + } + } } impl MallocSizeOf for Result { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - match *self { - Ok(ref x) => x.size_of(ops), - Err(ref e) => e.size_of(ops), - } - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + match *self { + Ok(ref x) => x.size_of(ops), + Err(ref e) => e.size_of(ops), + } + } } impl MallocSizeOf for rstd::cell::Cell { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - self.get().size_of(ops) - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + self.get().size_of(ops) + } } impl MallocSizeOf for rstd::cell::RefCell { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - self.borrow().size_of(ops) - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + self.borrow().size_of(ops) + } } #[cfg(feature = "std")] impl<'a, B: ?Sized + ToOwned> MallocSizeOf for std::borrow::Cow<'a, B> where - B::Owned: MallocSizeOf, + B::Owned: MallocSizeOf, { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - match *self { - std::borrow::Cow::Borrowed(_) => 0, - std::borrow::Cow::Owned(ref b) => b.size_of(ops), - } - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + match *self { + std::borrow::Cow::Borrowed(_) => 0, + std::borrow::Cow::Owned(ref b) => b.size_of(ops), + } + } } impl MallocSizeOf for [T] { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - let mut n = 0; - for elem in self.iter() { - n += elem.size_of(ops); - } - n - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + let mut n = 0; + for elem in self.iter() { + n += elem.size_of(ops); + } + n + } } impl MallocSizeOf for Vec { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - let mut n = self.shallow_size_of(ops); - for elem in self.iter() { - n += elem.size_of(ops); - } - n - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + let mut n = self.shallow_size_of(ops); + for elem in self.iter() { + n += elem.size_of(ops); + } + n + } } impl MallocShallowSizeOf for rstd::collections::VecDeque { - fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - if ops.has_malloc_enclosing_size_of() { - if let Some(front) = self.front() { - // The front element is an interior pointer. - unsafe { ops.malloc_enclosing_size_of(&*front) } - } else { - // This assumes that no memory is allocated when the VecDeque is empty. - 0 - } - } else { - // An estimate. - self.capacity() * size_of::() - } - } + fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + if ops.has_malloc_enclosing_size_of() { + if let Some(front) = self.front() { + // The front element is an interior pointer. + unsafe { ops.malloc_enclosing_size_of(&*front) } + } else { + // This assumes that no memory is allocated when the VecDeque is empty. + 0 + } + } else { + // An estimate. + self.capacity() * size_of::() + } + } } impl MallocSizeOf for rstd::collections::VecDeque { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - let mut n = self.shallow_size_of(ops); - for elem in self.iter() { - n += elem.size_of(ops); - } - n - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + let mut n = self.shallow_size_of(ops); + for elem in self.iter() { + n += elem.size_of(ops); + } + n + } } #[cfg(feature = "std")] impl MallocShallowSizeOf for std::collections::HashSet where - T: Eq + Hash, - S: BuildHasher, + T: Eq + Hash, + S: BuildHasher, { - fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - if ops.has_malloc_enclosing_size_of() { - // The first value from the iterator gives us an interior pointer. - // `ops.malloc_enclosing_size_of()` then gives us the storage size. - // This assumes that the `HashSet`'s contents (values and hashes) - // are all stored in a single contiguous heap allocation. - self.iter() - .next() - .map_or(0, |t| unsafe { ops.malloc_enclosing_size_of(t) }) - } else { - // An estimate. - self.capacity() * (size_of::() + size_of::()) - } - } + fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + if ops.has_malloc_enclosing_size_of() { + // The first value from the iterator gives us an interior pointer. + // `ops.malloc_enclosing_size_of()` then gives us the storage size. + // This assumes that the `HashSet`'s contents (values and hashes) + // are all stored in a single contiguous heap allocation. + self.iter() + .next() + .map_or(0, |t| unsafe { ops.malloc_enclosing_size_of(t) }) + } else { + // An estimate. + self.capacity() * (size_of::() + size_of::()) + } + } } #[cfg(feature = "std")] impl MallocSizeOf for std::collections::HashSet where - T: Eq + Hash + MallocSizeOf, - S: BuildHasher, + T: Eq + Hash + MallocSizeOf, + S: BuildHasher, { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - let mut n = self.shallow_size_of(ops); - for t in self.iter() { - n += t.size_of(ops); - } - n - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + let mut n = self.shallow_size_of(ops); + for t in self.iter() { + n += t.size_of(ops); + } + n + } } #[cfg(feature = "std")] impl MallocShallowSizeOf for std::collections::HashMap where - K: Eq + Hash, - S: BuildHasher, + K: Eq + Hash, + S: BuildHasher, { - fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - // See the implementation for std::collections::HashSet for details. - if ops.has_malloc_enclosing_size_of() { - self.values() - .next() - .map_or(0, |v| unsafe { ops.malloc_enclosing_size_of(v) }) - } else { - self.capacity() * (size_of::() + size_of::() + size_of::()) - } - } + fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + // See the implementation for std::collections::HashSet for details. + if ops.has_malloc_enclosing_size_of() { + self.values() + .next() + .map_or(0, |v| unsafe { ops.malloc_enclosing_size_of(v) }) + } else { + self.capacity() * (size_of::() + size_of::() + size_of::()) + } + } } #[cfg(feature = "std")] impl MallocSizeOf for std::collections::HashMap where - K: Eq + Hash + MallocSizeOf, - V: MallocSizeOf, - S: BuildHasher, + K: Eq + Hash + MallocSizeOf, + V: MallocSizeOf, + S: BuildHasher, { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - let mut n = self.shallow_size_of(ops); - for (k, v) in self.iter() { - n += k.size_of(ops); - n += v.size_of(ops); - } - n - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + let mut n = self.shallow_size_of(ops); + for (k, v) in self.iter() { + n += k.size_of(ops); + n += v.size_of(ops); + } + n + } } impl MallocShallowSizeOf for rstd::collections::BTreeMap where - K: Eq + Hash, + K: Eq + Hash, { - fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - if ops.has_malloc_enclosing_size_of() { - self.values() - .next() - .map_or(0, |v| unsafe { ops.malloc_enclosing_size_of(v) }) - } else { - self.len() * (size_of::() + size_of::() + size_of::()) - } - } + fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + if ops.has_malloc_enclosing_size_of() { + self.values() + .next() + .map_or(0, |v| unsafe { ops.malloc_enclosing_size_of(v) }) + } else { + self.len() * (size_of::() + size_of::() + size_of::()) + } + } } impl MallocSizeOf for rstd::collections::BTreeMap where - K: Eq + Hash + MallocSizeOf, - V: MallocSizeOf, + K: Eq + Hash + MallocSizeOf, + V: MallocSizeOf, { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - let mut n = self.shallow_size_of(ops); - for (k, v) in self.iter() { - n += k.size_of(ops); - n += v.size_of(ops); - } - n - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + let mut n = self.shallow_size_of(ops); + for (k, v) in self.iter() { + n += k.size_of(ops); + n += v.size_of(ops); + } + n + } } // PhantomData is always 0. impl MallocSizeOf for rstd::marker::PhantomData { - fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { - 0 - } + fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { + 0 + } } // XXX: we don't want MallocSizeOf to be defined for Rc and Arc. If negative @@ -518,37 +512,37 @@ impl MallocSizeOf for rstd::marker::PhantomData { //impl !MallocShallowSizeOf for Arc { } #[cfg(feature = "std")] -fn arc_ptr(s: &Arc) -> * const T { - &(**s) as *const T +fn arc_ptr(s: &Arc) -> *const T { + &(**s) as *const T } #[cfg(feature = "std")] impl MallocUnconditionalSizeOf for Arc { - fn unconditional_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - self.unconditional_shallow_size_of(ops) + (**self).size_of(ops) - } + fn unconditional_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + self.unconditional_shallow_size_of(ops) + (**self).size_of(ops) + } } #[cfg(feature = "std")] impl MallocConditionalShallowSizeOf for Arc { - fn conditional_shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - if ops.have_seen_ptr(arc_ptr(self)) { - 0 - } else { - self.unconditional_shallow_size_of(ops) - } - } + fn conditional_shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + if ops.have_seen_ptr(arc_ptr(self)) { + 0 + } else { + self.unconditional_shallow_size_of(ops) + } + } } #[cfg(feature = "std")] impl MallocConditionalSizeOf for Arc { - fn conditional_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - if ops.have_seen_ptr(arc_ptr(self)) { - 0 - } else { - self.unconditional_size_of(ops) - } - } + fn conditional_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + if ops.have_seen_ptr(arc_ptr(self)) { + 0 + } else { + self.unconditional_size_of(ops) + } + } } /// If a mutex is stored directly as a member of a data type that is being measured, @@ -559,9 +553,9 @@ impl MallocConditionalSizeOf for Arc { /// contents. #[cfg(feature = "std")] impl MallocSizeOf for std::sync::Mutex { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - (*self.lock().unwrap()).size_of(ops) - } + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + (*self.lock().unwrap()).size_of(ops) + } } #[macro_export] @@ -607,15 +601,15 @@ malloc_size_of_is_0!(Range, Range); pub struct Measurable(pub T); impl Deref for Measurable { - type Target = T; + type Target = T; - fn deref(&self) -> &T { - &self.0 - } + fn deref(&self) -> &T { + &self.0 + } } impl DerefMut for Measurable { - fn deref_mut(&mut self) -> &mut T { - &mut self.0 - } + fn deref_mut(&mut self) -> &mut T { + &mut self.0 + } } diff --git a/parity-util-mem/src/sizeof.rs b/parity-util-mem/src/sizeof.rs index fb917b1b6..9a1ffec41 100644 --- a/parity-util-mem/src/sizeof.rs +++ b/parity-util-mem/src/sizeof.rs @@ -17,23 +17,19 @@ //! Estimation for heapsize calculation. Usable to replace call to allocator method (for some //! allocators or simply because we just need a deterministic cunsumption measurement). - use crate::malloc_size::{ - MallocSizeOf, - MallocShallowSizeOf, - MallocUnconditionalShallowSizeOf, - MallocSizeOfOps + MallocShallowSizeOf, MallocSizeOf, MallocSizeOfOps, MallocUnconditionalShallowSizeOf, }; #[cfg(not(feature = "std"))] use alloc::boxed::Box; #[cfg(not(feature = "std"))] -use alloc::vec::Vec; -#[cfg(not(feature = "std"))] use alloc::string::String; #[cfg(not(feature = "std"))] -use core::mem::{size_of, size_of_val}; -#[cfg(not(feature = "std"))] use alloc::sync::Arc; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; +#[cfg(not(feature = "std"))] +use core::mem::{size_of, size_of_val}; #[cfg(feature = "std")] use std::mem::{size_of, size_of_val}; diff --git a/plain_hasher/benches/bench.rs b/plain_hasher/benches/bench.rs index d5701ef87..4ba53bb1a 100644 --- a/plain_hasher/benches/bench.rs +++ b/plain_hasher/benches/bench.rs @@ -21,20 +21,24 @@ use criterion::{criterion_group, criterion_main, Criterion}; use plain_hasher::PlainHasher; fn bench_write_hasher(c: &mut Criterion) { - c.bench_function("write_plain_hasher", |b| b.iter(|| { - (0..100u8).fold(PlainHasher::default(), |mut old, new| { - let bb = [new; 32]; - old.write(&bb); - old - }); - })); - c.bench_function("write_default_hasher", |b| b.iter(|| { - (0..100u8).fold(DefaultHasher::default(), |mut old, new| { - let bb = [new; 32]; - old.write(&bb); - old - }); - })); + c.bench_function("write_plain_hasher", |b| { + b.iter(|| { + (0..100u8).fold(PlainHasher::default(), |mut old, new| { + let bb = [new; 32]; + old.write(&bb); + old + }); + }) + }); + c.bench_function("write_default_hasher", |b| { + b.iter(|| { + (0..100u8).fold(DefaultHasher::default(), |mut old, new| { + let bb = [new; 32]; + old.write(&bb); + old + }); + }) + }); } criterion_group!(benches, bench_write_hasher); diff --git a/primitive-types/impls/codec/src/lib.rs b/primitive-types/impls/codec/src/lib.rs index 961081793..ee01bbb13 100644 --- a/primitive-types/impls/codec/src/lib.rs +++ b/primitive-types/impls/codec/src/lib.rs @@ -28,14 +28,14 @@ macro_rules! impl_uint_codec { impl $crate::codec::EncodeLike for $name {} impl $crate::codec::Decode for $name { - fn decode(input: &mut I) - -> core::result::Result - { + fn decode( + input: &mut I, + ) -> core::result::Result { <[u8; $len * 8] as $crate::codec::Decode>::decode(input) .map(|b| $name::from_little_endian(&b)) } } - } + }; } /// Add Parity Codec serialization support to a fixed-sized hash type created by `construct_fixed_hash!`. @@ -51,11 +51,11 @@ macro_rules! impl_fixed_hash_codec { impl $crate::codec::EncodeLike for $name {} impl $crate::codec::Decode for $name { - fn decode(input: &mut I) - -> core::result::Result - { + fn decode( + input: &mut I, + ) -> core::result::Result { <[u8; $len] as $crate::codec::Decode>::decode(input).map($name) } } - } + }; } diff --git a/primitive-types/impls/rlp/src/lib.rs b/primitive-types/impls/rlp/src/lib.rs index dffbfe96b..9599e4eb0 100644 --- a/primitive-types/impls/rlp/src/lib.rs +++ b/primitive-types/impls/rlp/src/lib.rs @@ -42,7 +42,7 @@ macro_rules! impl_uint_rlp { }) } } - } + }; } /// Add RLP serialization support to a fixed-sized hash type created by `construct_fixed_hash!`. @@ -57,16 +57,21 @@ macro_rules! impl_fixed_hash_rlp { impl $crate::rlp::Decodable for $name { fn decode(rlp: &$crate::rlp::Rlp) -> Result { - rlp.decoder().decode_value(|bytes| match bytes.len().cmp(&$size) { - $crate::core_::cmp::Ordering::Less => Err($crate::rlp::DecoderError::RlpIsTooShort), - $crate::core_::cmp::Ordering::Greater => Err($crate::rlp::DecoderError::RlpIsTooBig), - $crate::core_::cmp::Ordering::Equal => { - let mut t = [0u8; $size]; - t.copy_from_slice(bytes); - Ok($name(t)) - } - }) + rlp.decoder() + .decode_value(|bytes| match bytes.len().cmp(&$size) { + $crate::core_::cmp::Ordering::Less => { + Err($crate::rlp::DecoderError::RlpIsTooShort) + } + $crate::core_::cmp::Ordering::Greater => { + Err($crate::rlp::DecoderError::RlpIsTooBig) + } + $crate::core_::cmp::Ordering::Equal => { + let mut t = [0u8; $size]; + t.copy_from_slice(bytes); + Ok($name(t)) + } + }) } } - } + }; } diff --git a/primitive-types/impls/serde/benches/impl_serde.rs b/primitive-types/impls/serde/benches/impl_serde.rs index 5e8935710..faf8596ae 100644 --- a/primitive-types/impls/serde/benches/impl_serde.rs +++ b/primitive-types/impls/serde/benches/impl_serde.rs @@ -12,11 +12,11 @@ //! cargo bench //! ``` -use criterion::{black_box, criterion_main, criterion_group, Criterion, ParameterizedBenchmark}; +use criterion::{black_box, criterion_group, criterion_main, Criterion, ParameterizedBenchmark}; use serde_derive::{Deserialize, Serialize}; // TODO(niklasad1): use `uint::construct_uint` when a new version of `uint` is released -use uint::*; use impl_serde::impl_uint_serde; +use uint::*; mod input; @@ -43,11 +43,7 @@ fn u256_to_hex(c: &mut Criterion) { "u256_to_hex", ParameterizedBenchmark::new( "", - |b, x| { - b.iter(|| { - black_box(serde_json::to_string(&x)) - }) - }, + |b, x| b.iter(|| black_box(serde_json::to_string(&x))), vec![ U256::from(0), U256::from(100), @@ -73,13 +69,9 @@ fn hex_to_u256(c: &mut Criterion) { "hex_to_u256", ParameterizedBenchmark::new( "", - |b, x| { - b.iter(|| { - black_box(serde_json::from_str::(&x)) - }) - }, - parameters - ) + |b, x| b.iter(|| black_box(serde_json::from_str::(&x))), + parameters, + ), ); } @@ -97,13 +89,9 @@ fn bytes_to_hex(c: &mut Criterion) { "bytes to hex", ParameterizedBenchmark::new( "", - |b, x| { - b.iter(|| { - black_box(serde_json::to_string(&x)) - }) - }, - parameters - ) + |b, x| b.iter(|| black_box(serde_json::to_string(&x))), + parameters, + ), ); } @@ -121,12 +109,8 @@ fn hex_to_bytes(c: &mut Criterion) { "hex to bytes", ParameterizedBenchmark::new( "", - |b, x| { - b.iter(|| { - black_box(serde_json::from_str::(&x)) - }) - }, - parameters - ) + |b, x| b.iter(|| black_box(serde_json::from_str::(&x))), + parameters, + ), ); } diff --git a/primitive-types/impls/serde/benches/input.rs b/primitive-types/impls/serde/benches/input.rs index 060b430d8..3fd3c297e 100644 --- a/primitive-types/impls/serde/benches/input.rs +++ b/primitive-types/impls/serde/benches/input.rs @@ -1,5 +1,6 @@ /// Hexdecimal string 64 chars (32 bytes) -pub const HEX_64_CHARS: &str = "\"0x6402541b4e3c2ab65306aec48fce5adedc60e3ac465c3d7036c731e0b2e49209\""; +pub const HEX_64_CHARS: &str = + "\"0x6402541b4e3c2ab65306aec48fce5adedc60e3ac465c3d7036c731e0b2e49209\""; /// Hexdecimal string 256 chars (128 bytes) pub const HEX_256_CHARS: &str = "\"0x2568f30caf43f5f11ec121695200e166f89b17149743da42fdff7dba5504c527b34c898ef20a61a45109b7a6e6a516994567932b31478cfa3a3bd4b058e36e88a51400403be492afb01039910c45376951d2bbec9a838666404b14850c6a8efe07b30b7cedc3e84f59b678b5d812feb4adc7e2c39d681366563ef45669a33a7604415e46a3df671968e38df6115c80eedb96dd326a273404a4b9b9957055d22e7091d3e663faa6c54a48888f29778db6f7c5199a2ccd2237c265d30ea67aed475cf459ca8039831971c2e04eb6b89951d4ba472ef8b196e60e2875e3ec2955a07956936d56162d6758eb0fe09d2b2b12e27217f26aa38f90f5def14ab7c215d3\""; @@ -14,5 +15,4 @@ pub const HEX_4096_CHARS: &str = "\"0x40966ce6355f1dbbfef6ea6f1e131dbc6425bccdf6 pub const HEX_16384_CHARS: &str = "\"0x163845494c2b0c18961062bab4aaca8139fc0d25421880bb44321d6632cf7f4c4504f62524f7a86ae4475cf99b5b4cda8737a27f14ddae73a8c7815a60603e6f732dad7b42a94ef4cc9674b7c73c93b6baace28b61879755ad8261917798e9b158219efacd1c25689e1d1c085cf314808e5c3c1e92ea386a1e0c8a5fb1ae88e2156052ecde6aad91a78cba4cda9632fa7c41d64845d48a51a1ec922567e530184cd9fab6d8c1b19612b350ebacd2daf44dc32a969496f0e0cfea47362fbc387bc8cfa7f8a9efd797bed8d1a317ca217226aaecb0f58cc29cc4c2f4d3c91f6367b2db2c4ffc44243486bd6e5ceae007bfd6d1bc44f784af00df58f88b1a999911c256038e04a56360655b2ba92841fac013ef8cf902720c23991292b6e540f95a7ac9b7d0dfd92dd7ab7e757a80cb170acf0466812f141bad1b8047b10ed98f51fe1a28851b8019a73721c0b29815b6642587a77d2711fb93238a6005ca3613a049546db4b6626ffcca2c8352b02a4bcd514e76bd2c9e4f0a6ac557deca69ccfa41caf16d276e06b272d6bf2c680828dead23c3b6d3111201f2ca98afd36ae03da4b8a620e48cb8ae05ecf8d37d21840052ff426543a141b7f25e27a7cf94240945b0fa69e9e4e566e2255f677789cb26fc129b7021221af3588711cf9402a750d89e4f9288eacadc2bb64a6782b9c3cefd3faa57c3796ab150a9126d9959853bf93039dbcf8a0965dec9e295d5fa7e7f8d63f115e14d9e9eb531eacbcdd392cfa8c6eb499f55a6660b1bd9c2d40ebcf31581a720b0b2576ef202f739ac809a7ba7c7fe87817b6e76f02f8613111621d615aa57c9fb914cc8587a6e7f1e91a82381174e8ab011d50e86b826cd945c41cfe3608b5785c6c496b2f6e4ec9f25059bda78a3af9899426076b07039e5072b464b94ec5b5544ab15151ee583a3645819caf2df574d81079cd7ada1baf296db81e5c046f4385aad4554903cd107c0f78759c5dfd327a022a3a986de84a96e03858c3cbd476e4fe25645c437dd4986c31cb7fe6fe82d80f83887de253a6601160ccf4ef82d5e556c5fccb983bd8da0556983520b866768505e73a5eb9ffefea262dfa6218ddb143eff7f9a9b2715c526d3bcc4f1d1dfdfcea8ab68a005d0192ccdf68d2da67cbb156ada92df641a5d9f18af4b76485aa84565e9deb41c6b29ddef705c53801dcf6540dd2c2ceaa7da6bade03ce40e1e44fafe7edab9fe2a89ef77c25a4efcfc456f472a6502020a196beb2c17c25977ef7c328a19c3636ef52ee8afa78f5d31002bda28f33156a3520b4e40a6740fca6bcc003b2fddfc33e7bff9c443350d4e2e571a0f7b465142c905c1d98c5ecdf887b494f1956a1f83d5952b4618748852937b900edaae2e9b8445eec1346a7b95b5ca36bafb9c45bdb7a895f1bf4852ec217886b7d67bfdf2711f73b56397c3b5f7138fbc91434d3ec3a1d8ca584d32691b82fc0e59f8ccc0ea9aef5ab92eb2f93fec2122142ba912832bb22a1fa594fe4b14de7f3a429bb6325fa6db1d1744f878fa2ccc630c02bf4a4a6c8a8fa42e22771dc2cd252f14c2cc6f0fc3a6fdd8c7ffd62adc26efee754b0fdfff4678eaf6dc2d8e59778b9cf1b691bedc4395b0680353be17acdc18d33101a8a2e6bcfe8878151b4480a677d47a536b41e974362d5d7e9dde2e6122b22d6f056b4e1aadbc6c776ce7c2d6248c66a3cecd2587e9595548661b86dd6bf356b2d28d1cee23813580b25cc863ef8da98cb8c59b120fb6c371474cde9bf971ed5366d51419da90edfec0b56127cb7d7d51d836cae2b1f83a3563f216bdc5bc69161d91af42441b22e76e80f91a51e8635296ed4e9ae26b627f298f973066eed623374d062ad3a67be902ac50a96634437b56db882a0f24d058213187c740260eff87ef41b5e987fd18c96acde50908eec87efd3e0ae75da18113f86f04b4dbbc197e6faee36121f2f03ddc995e07eab68a099931aa288ebc1c0889ffcd793a9d780b736b85d036bee14b5874c669e425540c7d2702e0c833a5ba8ff9b17b7f44b0612dcdd1321d8dc674a56c66abed9cf920c2b5c8eed06fadd784ebd0335e89c7916148b0f28e8a54e6881cdfc2a655246179a23ee328e436bc1890c821beefc4af0ca86923404ee9ba01cf42ceda8801e9a6507e4bca2528953dd9ddd6b4564ab7d18b9d40bb2f29e5f9a38bec25aeaf89f432ff295e496e2cf76ade09b5c9f65dc5807e1c1ac104d6f8593e9957504fea1cddd5add90506c277f0a2939955306d9fd9f5b83ca7c0a7e538de323aac21fddc9f181024c60c7ac17e593704345fd1d51bf336e96afc23fb7704f0fd78c17e5ea09633a1a4e81eb09f2c7cd8366181f8437aac37dcdd23136d38e311da09f3132a6caf29b6a2428c103d6a0de54e4f74deeb4da8142aa405653c634bc5fb288a62a310949aa03f8474b79cc4d578b14fa9ef9f970e28e747cd89d0f3dd0850f1a34056e70596e1ba5e5a3525d0fda0c1e1e7a40b0e65df62532f2c43c067126c050037c192d31808ca7deaa42eaeff832c9301751a949906d7ff030fcccc510fc3790c6984976bb8580169f0de5db4b21ca214916059fba0ce6e255d6624eda87adcd5424d24e5506d0100ee0aa8d0baf89c2535358a7c244496de98f6533f8c6a4c35890217876c4254dd3b98b707694b8b42c6705bedea7b125a5cee9eb280826b6a722eaf18e4180c5f7b30211d1e983a5055714defbbd2f225b1cc2219201dc1783aa8ef36d8bf5ee33ec0326a127d9a7fb7b50fda765e3a11092104d45e64e07ae4ce215bf5cb27ea333d1a37db8a105041805e1e2eba47135aff7abc33175aa373a1d3621756c82c186d62df1586d62281b93795adf3c3ae233ee701bae359589502b6b4b2fa6672cd2b4f3d064118a53e2beac5379d05a623cc95537fb14fa583bf0f03366a9651cd91e81f20aaf36098cbc0bc8c52c5073196ae40828e01a266e106c3da91ae60bb9571a610622715b1e5be5e0954bd948e441b1bca32823900324c4b8ad21ee701c4c0c6e4b3e9fb71683b9bf1a6e4cc2cb3a21bcfc5153f5835a309722e4567d7e66eebad6abd0d2e721e8513fc7f266c9d8230cced279e5f6615b25648e6ee5d71b9836fdb0cd27e99d9884f288cb3d64d7f6aba59ed5ca44b645c489a497363fe48e965a03c738771e2f3f180278ceeecb60d69c3391d445c0c2c2af8d9e72fe2973961a5c75cbcd1dd75ee3417900e70ebb4c6f625e5cce11e4a1e64644aa524156f5cc0966a1a07e0c82cca92a54f7549136f2858c66f5add0c90735ec9e8e8b89d99730242437cb565a79d3c850a43d50f4af8791bb68284e395e4d97ed183ee555fb81f871f6735dc5da96f8e9954335695f2f637fcb939250bd869374d5929ba298d8873c8f9687f22d4bd45184d96a0e26d178a1e413364d62e49f8381db668959f3b8676b8e5e08cb363f3a51b91d27738efd10fb897b1918895b75585174a272934ce2a8eca9d13019ea4b9abd86573fbebb45443ec9302a65d3594f6da39ded12ba4aad681cdc4e504ed7dc69d37a7f27836ee24bd1471884acc6e8194cb7d66e099e455ea72c211620f723ba7089be12fbcb93bdb9751d7718d2c63972afb3be135d83f413c1e1697fa3ee4a20177933973870b40e5bdb73ea8401e4846238306b904fd028dd7706c26909f96f1087fcbbe87aa053befab4b6ec8e07486dea54a4bc8c3c139b3d010fb6aed3563f2174f6eb46f8eea68109738ad14f381f519b39b45a50cfbc24fe84eef9ef99241ef53474561831faa89499dca951f662dadef973837ff6f72cd442563b801df3a5114aac4dd85403b0600698b09096d5c90daef2b1b84d7a1e9ccba1265d8893de06b1e8c642f95eb8dd26877fc21fb1c828aa8eff954553addbaf88f266b25b5ce2472c46a38eee97a52296bb6b66dde1823960da350e69f7672f8689b281266413f0932042b4fcf0b8a546292e492e45e2d94f8e4f0115130a9a464e2236b954875aecf6fe0925ecc1a010f490292bacb1f2bcb1790845c7dad561bed04a403340d1efe1cdb4d83e00bc688d5877b7b2ab52bb16d11d03bb1e1190e9531f8a7380aaf2447f1f9f6bf1d389b05c897705f52bf215d1e421983d2bcaadd2064908f84d344d66ea470580248c704417aa2488736cbd72a7c0a436fb7b9e6f8aa76f8c9dd780d222a4652674f624fdf9a4b375c9568db0369f37d0a636568980ef3a411b49720096ba31b3b5604fb8437e007b092faae0eeaea1549745c629a92fda7195c5a28ed014d3452b472851638a0d042ad5eeb447ceff57204ba469dc870c2c31f7e2f35319666ca6c296383360fd56df57bab17ea26c438ed0eac012a4bbbb4f7fc0b7a0126243b676f89e4108c88e0dde8799006a68540c294d244b7de1eae3217e0cc6b5769800db8aea252114ecb17ca31ee3520281a5aa6885fcacb5c33ac32a68dd2555d527e611cab46e54cb514ef43a6c0b7b087246efb89fc7afb1336970479a64cfafca89d09565b03b1b260ae09a950d5828e14fc6439576a60c3f348ade4857a151b024f32a1f67318c67dbe9532a4767882331ceb6ad429bcceae5eaa93867244b2ee38515099b674a90643625b6ef54f3ad687476ef973d1fb7f92e00fcc3f572b6b913de830dcf0af8b1567758e1fc5fe7b529783d72b656fe29bf7704976ec4aaddb3968f6b8410cb204b600ae552206c929a1d589f76de8f00fdee424a39de97a162c84c17890327a9b0ccd96cf5f2784a9053512294a4b2a88dea2dcdcd98eebb1f33a26465f531986d1515f5704eb782723a3c757ecd5c0d6cafb75d8444cbb825275754fe373c4575668cf8249c028347d4372e4cfb57a408b2e4ab268fd1d14c2d34afd8a8dfed7428bf9d5678038fa1dfc9f47ed9c974a959fcb3965c20bd8f288c5b29e9322977792d6079487dbcafef61deff4001f82c8e1e31e030ff920bd58d69d9d3d0e5b0f3c9b8477d15354329bc485dbf280f51379cf8d604736d4777e720ce6ce8df339661c3e89b10341f40935c82ea1f5e0c336d859aed5e9de49f916c409a31434fd18a17b06b157b2cf8fd4b1bd715498dd8f5c57eb7328814b58686ce09d77da69566a6562a6bbf319c2ababc45c9f8a01a4834daaaedc77698a1758638cf4083dcbf0ef3e60544824bedd389ffa4c5d75a97ee56eb1a6a88155228800295e079e4717014431d2820867e46b25287842a7083e2a6a8561c26d206612babfdc34b1df9ca4a32a4f19b0f9d98b07b9d7a0dcd82edde6b0454e063345b637750da75a239a9341558e1e3540f961f46d8efebe216293e24401801ac65f82bc1b702b38995a3c69399645ff242bca25efd4a2e85330ef9023c8d1b44d9264532e647f1190730cf24abb1dd3b0dd567d4d3c2ab707ee74dcb1aa7d0eb7488ac711d325a1eb3475526c41f74ff8f91bd0ee5507d50349496792a2461fab14cdedfc222165d0438deea93bacf5818a0af53cc2de188f28794a591b3a11289e2e0a201f54e30994aeee5b46ab5abda521777e8fb15a53472bf63dc526c8bd75d8514fba0c29da4a79e957a66ea77c37aeb7025f24b2eac7782356521827e60293d713cf6cad48cccc83bb9454dd22ba43fd23c87812e239701dff8c949d22d07209e94264b427688c9970d9bc9510a415ab58f08c86ac38d80ad0271635528757b07babb8c31cc0e1e9c99bf7a07d99d920835ce72e85ce5ed1602aacb778962e6aa93af14057efd051561f77996243b06c8da26fb46e696216620dcc9bae5abf202192d86a1b6d6c002225fceed3be9a4e2a9c611392245a6b15da0444a24f6f2a72210fa863ada30f7f27e98eedff1ac101c4f3b2d98bd09dc5947f51cc24039050ca52efcb2b5633a84bf1873733547f5b96106b74de88b88917be5faace63e906e3a6800bd41666be2c3ac79204286435fe7bf763de9ba28c966ca555e77e41ec831b1caa9cfae788a3cd7c05b7244349b22bd9424627352f8db369e2acf511907c88838a27b7fccd545623f5673f50dc794a6b7bdd4582198682a4f8bac58f5d3333d9cc205e447efd4630280c4083758e44a4a41bbf4c09deb7f48d3865b9138e51fa19a4423d1e40dbf7999e0883427b75e5fdc72e137d6d1a64938dcf1453559ce972c22a6e2f8fc4c8dca1c71cf25b6f442a0525613f6e3cc88068ca52b567dfc1e1ab19de44ec5562bbb47b4face30b46b1ec34c0370e0687a6aea111a887549c49227e9468309cf0330d68a72f7f2620eb0eac1380aaa277fbe86c516ff0c3731419cc103c535975b64114099769bef5e9fee5396a2063b11657a8968431b7831fe5161f8e006144d0a3a015367d0a9ae601cd52814efe1d8e3638a8a7c326017cef14c5bcbfddc1c96e7fa91d21a626ed1295ca149100219a6d5f7c3d1afa77fcb499bcc3223a5b32d2aafb367f467a0015380f00b1db790d0bc18beaa64cd409a0f94d7fc2fb02726ab95d4d61a4e0c940a835cc8ba7d25d466e399077c843fa033e1d600276034f0b61c31eb3a183784e112c89f2e8a64129ff5b4e09fc61d8d463d01b34557d45717db21e1d0ef85750abd487cc276c45a1f81ce06912896bf45fcc80345c27faaf0c63e303be7b44f001990ec3ab919cd8e7f78cc1cde691f4ce27a7632a983da200bc9d24e5870cb4712571e71f418bbafc40ea6555ce4da37eadf5efbeab4f6a280530b674346a5f0a0a90133e37072e5d94dc7d26642b152978b47685c7c973257045e3d0b6dd96cb5845d5be690794fc3b6f3f1867d1e646ce422e16c2da8258391314f51a91770600dd4faca5cf48ba1284c96ef164cde29e48ca17ede11561aceaf851ea2011586d27f93a00b020c9f91598cb6505e7697f2d114da19acd0d4078c2638cfc8a871fb6e5ea61eafe9b2b83f5b32c7bfbeb99e5bd598464507678089ba1965e9920e2594aead6366309ee4b2e1d597362017d1868463ef38281aff30835c255b50d34ccf87afb4bce0045b81a39ededcd77789e083052c8e03a68a507053eced7bde2b0d5fd35f3081ebbdd3df2120d16c1dc892c06b6f19cfd32e4bbfebb0a985329ee1013ee96c3817ea8514311041847fa45af7d4750e3e17b666b343b92aa5078f9f544d45ed312b6500d124d86388bb7f4c36de5439d9983cb216945e0fd389a76d7b467d4a14414ddca775f694374784ab251a35c26646c14db98d85c7d8e2b318f60d643d879d5830993636a579a333742c20ecbc6049e1c7c8bd58f5009200c26707eb7acf5a4ebadf88946d3260ed5011e4dae9b7efdebbc2251a69462805ec71bd3667e094f618124fdc68dd7e38863e3077b9e07428067d7dba602ab4fab22c691359164ba1bc9b9b0ffd1fa946cd0d28aab6bb46e424b476b836e5f8f01346a7aeb2ed7f999d4d75d206412e318423b541968c2ef2af0a275b97dac972d6c367b93deaa204339d28cef59752850b616c26be87d3d4592154164b8c0a950b9dcea06069dd2d480433b1783b2e048eef04137443c1b77d980cbc81818d97ef6f06de604691b29ae55f0d749ac65668a024423803eccd533e015537ead53d2c8fbbd11376fe3509fd3fd52aef61c45dfda36983de690278b65ff7af994465b7fc815a597f660ba443b8a5daae31b5ae35ea808fa77e3c115a7abe067e9745be0a21d23aa2e22c54459b477f1ca016fef63fb2f22e7a7a7deee5879417eb7dd0ad763246e64c8de5ebe501264d7b46f200a0734e8ba38cae4f7870777ad15e278cd0a031df412d220458aa2e4bab93424f447c6a5987d96553e1d357c9ae57461d6f7f4a8e694371673a04e1463b523998d435cdd863b7cc8971b00b4e08e7bc6bf4926c3cf4670cd613794287316536e33ec5eafb793cd05be39f5ef9a9dbdcfa26d0efb24eeba5d4befccc6c12e5a97012453c7bb42991f705cb773a6c8ae8b440b29eebd8fa770d57ed28f05e452cebd5785ac71594f5a5b8e5338d0ccfce3092dadf7b093615c7276b408305fca2edf355a08015e5db91a5a0182788b0fe007a99bd808c36d501e33ede3f6c06b82db8a52e20a66ade5f7ea162ceeedd5748266661b9afae3c115495039bb7a903cf9649a5a13d299631c8957d966c18fecef06d7e8f73ab61412fe9dcf7ec29468ecf84256e1940d0e9df74d38f75fe248692d8f012793f0989c447e0b5d9653a5f03952389393556bcd55d93e24870cfa874bc530a04678f64f674ad029d8d0a50f7467a193b0499e6b7a823199915216e428e33b9fc6f3d7db6a0e0ba5d7e2690bbf489abe48c0fb85cae65f2de835f71ff181f912bfe345518ec8f8251c47febac277bf8337d185df491dad9885076ccc9e5bdb1a69bf2c3163571bbbbacd994c051c551b4ae6074d911fa6a15dfa4429b4f23dd79ccf5ce290f5a1351b4dfaf7f12ae15b566989c00d34e255c9b05228f9ee6031fca417d71ac75996bba84438da99a9d1bbdabcb7cc0ee0c595dcb045c1b45115a8516c7eea6f7707d6bcadd18d0909f8d3956ce64a9028ff00458d2d415eb54276f63191b72ed2c023598255f962e3ab29bb5bca6636ac72502cbc1bce19237f0967395db40fc6e018301bbf3a5b9c3cc4d03c7d98aacf37d4e2ef6d8e5200598ce5a5b4725b169337318f2d036ecf4918a656d204efc2bae2db3073b4098bf7b2ddaafd87e2742063e63fe68da5b1a68655effa3e389e0387a3b658cef44e4c025d454d056d44bcfafffca0c5101213639324694db4ba7cd1fbb6adb983c714cec5b9a8c075dadea62def609f4eb500e676c2603ce356ffe2c816dd3a839c6e877f177d88559d077d3452591d25a5fa3946f2b0844a22d58027a3b0e7d0c275cab0638075ec17e8ce9e76e3789dba14c9905e21e3c0cf500bf913741785d3437167150e271a7d1b192bdafdb17d5324ace1fdd4a243614293172594ebc5765aa4efb42414adefbab07ea17b5decbc9cd8a35223ddcdf1254af01ec491f107e6302c17da3a570010b9ab49d7d803b8f533a17e32dfde8cbed1ecb2494e3ace8f19ab9eedf8e9fc2d9e600c8160024d9a53f4b2276cff3a43e6d9f53fc3212d95e90f2eb5e17a9b40be5bbb71b927577ae64ea796b5b4c7a52629065133bc179f100f9bcd61f74dcc3bc4673fa97b263af4a7ae0500856e832212a81a371055c27849cf658f765bbab2c7fdaa40cf1ff663318167b339e303832c48f7fe7b4833e8cdf75529a7815986cbd43c17f9214c89ff215564f69596061082838027157de5a4111ca21b92efa9bab7a692c4c0feac3bb7ff36d2603f4d501d09a3b1134b51b6257f164643490e4fbda1dff16bc9d20359dfd8ad59ae8a8d2d74495f0263092edbd8b9be2e5bc6ed913f2776a294025f0b1decf479376cc9662c5912102fd10705ffb8e40c92c9defc85d27e363b80f4eb90cc1fc65791e673f8e3230526e433cbaac95fc9a5a13e99180ee5dd3707f6970932bc6e0e224d94fe6b869ad86e495e235f2cbc860900b1dd031b9286208617756d0d1813e1daa66c2f3e733541820ac880058a99fa58f677eb626dfd3a8d4a504049a47c35e8ec14f1a737339cb710ce3a83cc001b84511baa9e1aae1b1df909839344dac908f4070e5f13b48e1fc1a5c045922a8f03b721d2368634890c137c1c16b837ba5c89ed8628dac3d6bb4d717eb26646a1c5f3d0d438add2b4a42a8d88ded1ddbfa6b5deed6e1a37e3b9209542de006e261a13f734c8e4aa2fa31ed167b8ddcd91227737c406b344dd44ab844f9823bba1eeaf58145c7d8a6392bb02480109f4c3dc9e86a84675dc2de6104c1bf9424a4ee13b5fef7e81062d56415a29d999c80802859d307e213c3bfc904502dbe89796f67d1e68c090bac68f2655c8c49788820ec1a9ee5299e49cd1fce1a8751fa11226bc3898417fea48d969f9b1e6b33a079be36c0f6ef08682e2901edaf9c9216d1c5778e17b70a7307c93509ba2efb6b1def5a84cad094d865d5757d55234cbdd87d45f9efe9548d54b641dc6eaae8671498452e6f5954eb1b0021d349eaf7dfc2652153a6a7dcf603a392dbe359d119342043172cff2fcaa22f41e5e4b26cc034398b1fc9e60c57b8659339b4718aac5b1d9f9d47103b4fb0fc3660e0e2044943dec1ac4f6b504127e5ae77275cf287367c324081ab7e3a4405966a372ae32a09bf978322a79d7d1ce45aa22b14eb6e66d47b8c702b80d5692e6a7d380866f61e6589a080fbe720e20d10a636feb1ebc0996fc1c0fb6e2f83ea9bab7a6ab3a19880a05061e11d3ac66bc0e10cd43bd304e956acc8bdeba60bdab0572359e26ec9dcfd77f3e5f4287f88fa77479a2053e15fbd2bc0cd8f9a8294cafc55ed4820661b3046cc2e71fc081945585b60958ea67a69d8b55cc18b39ced4e96453f00aceff758a4403d762d78c634777ae8780d11311885e41a5837511e53e2321ee46f33ea553353bd825c4c66776e1b4a99b2e649445327911e7adb6a5f3a8a402be0c6c42a8019ae0c75d6b1aceeaf35227e79685bf799f5eda354d68768c8c1b7403adbe65577be3b233afa8f8ae0740c41483698388995b84a04338e702ade301f70e0e137ff503779f85f30d2d83410f041bbb608f429de659640b9bf03b86bc4ca6bfe74d0b24aecd0021c1bc3b048d7a6aa72fa4a3116578cf910c96828e647dfab2e7b1a88ffb9fcebfe6e3f2ecb499e61feaa0a87cc8271d9ca0857c2803b5ada76dbe1c163fa9454331e3292d6582c5c399f9cb5794b43ded257ce812b96fdc4c01362d45a2c26a4a4cbc230355fcdd70ba502894c7ed7c93b07e227988deaabe0f594e581ec63f60a7102c81d96723130ab4960e641b6281b04c538f7d37bddb39949aac4646c17a1455a592bd564f3608303162c395e961e0249f6badbc74b19b883e77480361c7b26d51deb88698f91266f0fee2eb30f38b9dbdf9b34c2de5fefc0d441a7510ae4488a70faa929fc938ad1d3116ae9847a94727dd607340fb2786b12898c980f3c5a1a1ec3a140598cc5df65e8f2cee0e9847440898c28507e215e29d4032e425e3c9140bb67e9a017c089cfcdf2cfc1cf74d000e30a40acca9dcb0beccb2ac6935c152de31a2d27b63b7fa4744e19a6865ef72594e98930650d3174e58e3dca0c94dcf1ce33558f2d20eb6dc519431d823b4acbd22db19ef0ee8c99a9d3aa1799f25defe64a13661daa5b5a1d4be59a970ec87ac6533561be444d1492480067ef4b147bd535611b171a19cd6090ce73e248a9a1e34716466453278333e0493a840f89f81c27f0216ffab3cd5516a2da6dd97b7c2ba1ce83db582731fa703bf630116612562960a7c94322532abe9867ba4990138d207ad8b78f03ae49be80081b9e4489800817a4923d379f7ca03404d2ec75754ccb17e71fb6b9f507de00576f89274cc3ef0409ae012bf1f5018e17590db2542480a29f4e593913e1cb63b32787789751d1802b0cf6b2c5e9fa44223601e2b3fcb491ccea517bacf5236aa9ba871aef52af37c6963c39fd622dfa386e6ae0c36548395104a53b70\""; /// Hexadecimal string 65536 chars (32768 bytes) -pub const HEX_65536_CHARS: &str = "\"0x65536b37b273ac2f126b11185ef91c1cff07c9b5081fae332ef45c4e90dc0bad4868ee6713acc2eac2d7071fa5885f8b2a9988a07e01bc7de1ad0cb0f06a3467905a2e8723987bbc96c86ac4f1503479e1089d8d90cf4d836c4d12816a1a39dd8c379add349bc3f2f543a81051140483f61e81c3f18ff1c4049aee78e1c245846ec12f1b8392028c6a2e9e3fb110d20f0877110b2f266609a3d92f0cd8b59b7385cbd2e70417ee062ee356ca191f8c68aa68243f5ab62c5f4b237033c32ff7813405c8a4bea82f73380818dbd169cd1060f4f6791b96a402bc4dc83f6a6fde353e3a5de2e626706ae897b7da6b1e3522ed2f4b0f340378c70bfcaf10a7fc805d696822a76f4d8d2206a9a8aacc132dbe770ac870b9a406bde566ac665c942978e5edc1efada06bc13781315eea26f9977f58327a188a9051c6eaa00ca4e2e8e04f26f8dc2b589c399a6160c1345816f35e33b4a0db6d33322c3ccbf82cfc5c1b28be7da5d834d1720343c1bfd8b8964552bae373ed2a6b1b6f02766f679a2c9f1007610014cd71810e8117255b0a07e5e5e87711ac4713e13c6adc899350c4b35d9a22925bd46cf2cfe04fab2fee013e3560380de3b879b01a2e03347c784eba5b1f0367aa5a51cce5dd0cce8f983a1c0876887d679ca207faac11fff8e8a64c81ea02f0aa7ef2cbba80f75eb37a3975963b757f7fcc805adaf7611d729f1a47df9e85df5b2a2a8eed2b69d657a4513472ca6b6a44a1b695c8183dd178dcd621b2066ecccdc1fb88fea080735bb2edb104b88547ad6de9cea81a2afd04f245d1d15c92955648c248501a9b837ab549030860417f7ddff056eb73e90b1263923fd6e5ebba43ccd9f839817967df5c8a6b2b7fcdc62e4a55978c0baedb046059e4754aa043fc975d57c09ce6dcf56b1cdd24a85272faa1d821853f71b0bfbff2967f4b2dae326e4d990c3417f6c990559d25ff5b3d0b2573f49212bcf33d06fabd8a971f90060b396e178c6b52f55667958b1307460827b78884022187a85ea89cd2981f88365b5e2e66e0fb55926d7eed93edb19afdef4217f64a33d1c9318cc05cfe774e0f09428ec4a9dd38ac42a48751cefea3c9a8935ab04fdf7b24b834261def53839cb68a89cc61ebaab7047cca9d5727a86d79d5944737b0642e8770974cf2128c663d0133d9555cb4aa141e39dfc10c70e2fdfae954a7dfb39af8b7419909255d2d81fc069071fc29d1763c7579e729d87fd148a9bf26262a9332b2994a024adbb8f43ca76389fcead15a14ae24f005cfec16d4da950c8c1647b8e2357ab59be554f1faad237e492d6a5de11618817da26a611f122fe6c5f1ef9a826d3905ed4c8841f9f5e3431b994d1f4b62d10877c973aa1daf9614bbd55cdd865e36e25b9241c08e3b6627846113d6fdf4bdef35eacd48ca2d76959baa1484adb988262b38013926c388102bf0551c35616970f9d5fb1fded91a25e12f1f12afcce8295aea0ae7608163798af65025a84ef6e1f3d60a5d354d55e0fe408023894f68c2e523be63725b5cf33ace0828cf89a69ee428d073bca15014e7faa83014f1bbf6797ecb80bf75ae012fbd35b48f3d7e213d85c3ef991933021baaa7984e7c92073fcb720911ee736479e79eb55046d3ce4433b669c34e38c14b232402222788c3df8aeb42ee8b487c3cfe6eaece11d9b3aa681b143f9f360c7dc0f157d613c2b85ec407f6d85b1b1876c298c0ee50ecb9e0351738e6eac1e0e5749ab6a5f7aeb7fcb150af97b0c6b4b6df19dd0d06dd44764dfc10361e6217c8808b9b34b62311c5a93b4e6e0f7ef3ae52d4ca2689ffe94a04a4405442059bce9df2d919299f1bf75e74d5d51b963b19a0133e6904cc3c0310fb50a7c0c04c0e9a7d259c12c12cbf84dc72e3e460d74db9a2a3890d551b9451c84ec4a5e565c17692124a0ad25b47bad7cbf8c07ff8df7b40b3226309b783f939baeb02767c829bfe6bbf285b66b235b301372d8896521774d45d5c28ca6593b6f81f9aa9d1c74014fad0877f8134751210ecd6348555bb033d30a2d07a438b111c0ff0ebed28e22b81ddb4b9fc36cc4048afb3c876f62bba6f26b882cb2410d5f8e2895c35b90bd12010f424c64e53d33af47fe5657a2cd25e80b08e8a26274fdec89a6388dfe80bb6c48522115b6f0c78245e18b42a7f175ebf6816c4c45593a9f40dcbd881a1c9f8a9a010a886a319b6fe97e01347f6ebcb64d41687a08c869b0043c6cf684d11e75161c15f1037351c3b51f135c02935815fe9f5e382f4623a3e34ee42946e774c0717d6299a4c3720f26adcac65105771621ff851b47a1f2b96aa6a0d664021e398de908b83d64719da4dc9c6d20304d00c9fe89433f6a787abd9c282212a1c087781c40f5a615fa8a31affac834cd19e98e7b26c115e6f48f397f74e12d1b214ae427f13fad70b62e051d3fe4f90fafa426bd12321e17fa97bb0fd211401db77ebd2ad2bc5586f9a84ca02af969b1bc4c7229db28e02bd5ca60aa60d3ce159dac61bbfdc6dbe3b58cad672bb64a2cf8e30093d2be04b0f84be835aec191fdfa517d671b2bfadd7a76d45b0dc99ac383a53e324d734bee7738f093a6714437cb70a4d93af9dfe71b930158216a5e19e237276f9ba536b3cf0e063fe7101edffa5827b38b5cb74abbbbecc823ad1df97f8b638eba5a75ae875dbcb1077530c06e56ebd5df1956fb93f3a605b8c1b69fe0cdc42fc6ecdc0794057b1c6e756ad5f6f105727b21074ab582e430ce12fbc1b234b4fe9b5ded642378fea32006d6ca4c539e07163c7fec74848db5d164d4f4f2619aad89f246bba33e7cee1bb434c3c4baa73448226e4711e0a13b433dbea7b474248fea8fb3290c6ae92e42dc4a365e6562381bb1d7e903336c8cfef2863d383fbc0b45f015b0b831636724d6390efe15617333cdce3efb5d0c6c99a9b77ac6f6bce8008e85ad4c5cad08aa9232c312f5df1dd55bea468587a58b0a5d966e37f85acfe260b26016e2c2ff7a5f0fe8c296e3c9f21a69067fbb828dda563ae945ff5bcdcff950b53b1890c37add5ef49c3d77c51f046e7d39f1ce013ff1f95b1ea5c66b37e7a244605ac3e8a5d33c521d7286f6bc22b7fe4076d080d8e66f8921772887233e6c883c5705862d2e4894efe63f475460a10f66a19fe50ff82a2b3c03084515bbcd25aaaf506c9fd90c4eaa150a24fabd3331220d83a48961cf9c4e9da384959935f79d84a2218348d70d394b522ec0787e934aaa472633c75c98909d91576a322198980c06f0ea370573ff2c2e2daa3f71f0f8d92eaf202fdda79d56bcfbd5dcfa435f8300c25a179338bc0d85f9ac297d283aa763892fcfb96167ad6d803eedca540bf05d9980531c135e553bf5c27442e228c761863ff43950e66526a1805e0671afa5ff0eb021fdf175fff6a92841d639b7c88bf7195a8f32b43871a648048ec0fda674cf79239865eda8dfed6d74968400a53a647b66e5b00276d088d2dc91b57f20fafc5103ced1a56ec7f6bc8e56f8bbe42bbd034ed6aeeba802e3f8ae05426758bee5b0e583e34e4df9632b636b79b467c84618ce7aa026dcd7d1ecfc54a87e6bd6aa5c3d5159693fed90a6b59ed65e0bb6d4c4a2ba045fb539652e7df48386bc2ed72e5c29f8d7e8e45233992fd18c473a39cc04fc8cffe0d70cbc0f75fdc7daa1d9f4ed0434732051968cc6123a5ac63e49a8984aface0787dfd84dd5f16573034c95a6b10b980bca6868c903a8a6d4119acfd7c844c1bc5b6c86977e2de33440e4b31f472d6b7b58bf4394a079a529587d25f2ad0fa1bf22e196d859bb45b81788b5789384dad71b23d2a226d75e0679e1cfe9efb1c4d66463a42796877cfc9e5e2435b072d3f4453e23fdc6555d2cba5ebdcf4ad536b85d30286f3df49cb5972abad4019159adc68abfc34c04e46a5bdc182e622a08694db464760c5a4505021abe6b0dfe15c8eb5fa686fe0cf8a337dd14274884cafaffa3127ca9311de8cc04d19b0ac632ea8ba34c4308436cca4e25efe3796279f3e9da9f697448a9d4a0bcf4673f3e3e6a3d630d9ddae3b6a1ff95a545db4a5fad2f17bcc6c21be224b3a038e346d6e6db12ff12ccd6d573bba31807b31ae12056ad5b77cfc5047df67a48392389665ba2c1e28f9889b8448f0fb14c30ff2050ebca2546af586aeb5d83a785eaa54874521c5ac3daa5e9b365d620801e6384b6d72122dc72ede0ca03001af82d5650011abb62769a1a55ee09aed875fd706f14946248fb4b82d12548107db353b6f39a9da939acce756e7fb9c1866c2c00de1a79a82ee91b46122bb8f30d584619cb21a247cbffc8b7b9b09d76eb13bfa48c8f28ea335c9ba9230a030ae4a69fd7ec47a5eef8c5f9851bb1142092f173239dde5c059a728590f1741dc9f8aad1590501ba5616b7bc188d257009190356f968bbceacf77ff23f014f8310c9f0a89279d02c8d225754ce535000f79ec86455757319f65c4202df8831dad4c8e2b94a67c8949e46b733991f783d9368282bcc00475da4a1be720974d972544c810c5d789cba5e7b0935ed4f849e47207cf9d54342247a7702b8176a164bd7816fdb2bfd52f4c0d6e528b4080150d0eca5707dc5c1c220cb5c0508edc220d14e84b5386ba229b422558d49c9ed3dbe128058ca59aebdee15c9f040f10ef8d77345dcd95e2c500fa995330b6c0b2769c086d03049ef3efb98999265395a2c0ae3cec18c13d270bd91c1feb53588812942c9ad73f6d89eae4e84160abea950ad7da47e2c82dc9fb06d194642c2abf3af0b30e5d04ce6e028d0f522d4639cae0bfbcb2649d2e64a6a55f7437ffbbc65f8fd5992e59a98e98f0a1a83929ef10aceaf6319332d7ab660dd00e2c4b898fd25600161ccc24aee43a10eeaa62ccf5b95790deab87b88b49ec872f48c8713cd4597f6e55a556ab242ed843f866b64ac5b100916f0e4711a02bbfa9c42e47e5b4e72e84c28e27fbc7858d1d8791d600f29936680f470fc4badefbaf72f2ece3be6b85835b1bfddd8aa5c5b7a87f6e9c64ee9e76e836ee16efeaba2491865c24e9e0c5de706a567a54b77400bfaec3b2c9d6f43fedd6a13f713fea1474a6c3504ed17bd5a5e3ad57d807eec47d6e6ed65d8fcb4b9c0e7588680128b865677c38d7a2b8918cb76462bdace3efa22217c64b05cbcc8d29039f438e2687e521078677e1a44678a441e31752d86f6da8a46f91766a40a03526cdafda3e69e636093d8b27eb3d12f235525e21f98483db3f9735d76f2d5bd5f1b4a945a367ee471def08f2f5a5af864772436a0d2f8da323824489dbdd65da331c9ecf8eededb058c563ba0b1d378109df5186fc7e100c0beb4651e4ef8de0f33cd0e49ddfd7efb84be4ebd71f778f26ad273af8b47aac27f103620eab42694fde562a68312b551afc2c592c7f7efaec178625c51eac8f8028687c953bb26151305c6ba22d44d7c6c9a48bd1542e0211ef0633ffc8bb0ac98b3aebef98fe710b4af01303b1feeaadbbd3d631f3e133c646a0853887ad851130dd2924e84da97191494b93fd711639c4aa54eb60341b67cc5f39fe6b8844dee0c70d38f729d4aa44553a161e9af54c667b9ed083a65451286dff52d9503e3f679b5fa38ce7adf78ef8558176a0fefffd45e8a402105d075b9d50e6aea8fc00dbd5db0d3e0259e0207b07ccddb1cb54c0c7d07699a9bb817246c86bc7e76b4726d2648b266508dfcce13b7390eba8b3b5629ee150b540fc032ac6fcf6a7e20d8a5dea3dbba99b8470ee035a991f2e2a7cabba89431308d6e64a7cf4e931572e937069659f88d36afa4c6e98cbbf12fa624b17cfa15118151bca7912380d4d66220f7b58fb3bb71f3af7861f553066a356bb4333d18e9795fb5a209155f38c7d0141364ec4f0de11a38d5efec4f592f6fca3388f5772527d9e216aa09d8f3be8591d0e4efd9fd19dba829032b524eeb123f27ac8695600658b034b0c5eb4a1166e952667e8441004f4e8de0d0cc9c4cb79fb5579b9d6f2ccb390baea7c9719a55beb0cb87b82314a0c0c8a0e66aae85fb39224ff7cbcb4e9f252de601c7e452713f736039b7d4e90d6495806ea3f2b129ceec6ae7ac401da17a839d8eb394c0c89e7b39b59ed2f5994659ce9baeaf3c1adbfa943afdd952223457ebcef5a3f9f6d19858fca3e61a78a755ebfaf2e57cdb369a8742161ecbc2fc4c5ec29b9537992e4221e14a7b02e9e63b3e5a6da6587a7ad2a4e6963190421a11879350a39c22c9cc12b9ecf7a3f9132b53e07cfdeda0db6e29ce5a82b347db645377183a02cb852feaffb44a57da36c02945bb803d057a094df43dc1b4ec751f4dc3be45bb3b5490822d790d4d67cb82e23e418327be8732cd2db2f2479651a9130620ed92b6166bb729b0e5a9bceee3d1c7a98e0dee9ce57911b1d1a1f3da7d1370414c19b1454c8da246835158fae4de3f882240345aec8174fd5268f5b73b60c602442e7fcee71531b0120368abe2ad3bb5ac2da6f7ed1a14c168ccffd580261d367327ad4834c524ec554ebc0c248be39d8c6503e4ed2e8df7b36d59ed1b6b9f5d8ac455696102a9f795ca0aa75a7e9c86aa2f3f5bbe0dea2b09b9f0afc708ca38152decba96419ddc4890f74faa7358824328d036453ac16ae420fd5f86c0ed8e3ca44b095f6d4429b534d7f877ca07657704d0c35a5a1fffaf12e12a51bf210dc557353fe27406c36a185d3da3f8013438345e1c28cfa98038883bcfb957e0dfb57ff33f8caf5d5b9edc596d26629559ab6f035ba941fa665337ea16422549c918221fe0b5602180c3ba3fc7c18c7e0afd471c0dca54bb3732ac40b90f9dcd5aaf665b0ca63292ddd7235b67892df8e965fca21a8e77c1ec7d444b6d2ce05bd2253b9cdaadef964813a03b99695bfb5a8aec508e98adc14d35f7daef7d9f384776565152c354deb30b98d0c0543ef080fe48495899862fc553a2d48e1b39fd2c699c7891100c01a89aef6ce38871e04330c8164d6ffa27efc4a4c7f282b5341a8f6f92c87eefcf0facfc9a6417f93df635b600c8c218e185522009e0cc730d30dfbf3f3f2c6b2b582a6298ee855d0d7df41b0005033788c81830fc09cb97e4115ef9713ad8b6b74787db30427237a48fe83126cc2b8d3d431a3deafd22d532e9bb9ec2e74dc0f4901c060cb215b57d07e0c7cacb6d3baede035322fe9c32f212b28f8318a87f73f603c293d516b475cd96eceb1739bb4081a2d2d82fa6a6d0f33231ef184316041e357efc6bd400b7228943b93d2eef303c5ef7d7295ca959f10ead921d6e257dad7160743bdc3db3c8fd87d26b2aca6ed0bd945f41caa574d9ed61f65a45f8ad7ec50f6d7160d05ebd4516d0c3da1eb4efc88f88c5ea244ed90c07239f3d217983d93295926d6d0c8597c1d6985dd9a0df8cae5b0af9718820bb0ab425d4f8b6b5d1a8831b69c695258d2e268deb2e8743a1cba722078458fb7d5b5f4fc0f6f07207a25ed4608b7f8b8ab7ace1eaee32460e5ae00d299f78389bde8f7a64b58116387e5f0e98522c6743e808d63d7d4d3596a74d2812780ec35a9715c8fc440826d37ab29a909cc0c244099453c4a08fe541099cbffb04ead771a5c7c7004c55c44990856f2e02e790e9e4a3db5cf4db2873ad82a97159c86aa8347f8dd8ae846a4cc42f1448046cfa0e121fb9a7787136502f5cc5a21b4ff3da68a5ccdcc54e49f825dabc00a10d437d39a2a9c2e5deb72ab8b188520671eaf1b0091ab7a271a1b6ad840d089f2f79d1ac7ef5e317775eee5b2153c550ccd0038050eb7b7a6789aa6bfe68eebaac4851d93a22af4a08a14e37ec02fb0f89edbf0c1d15905a6dbf691f0f0f9e96539aeccad6267f52574aa4df31ec79dc9fd6f27b5a26fbb1945528180cad006e68745288c3868d611257541af28f036cff9b911172e38272cd5fa693ab89a11e02d795a0c7b4bda53203027994d2dda4129b474a2d94f708cf27840443597d9cc6149ff11d6c747bcc070b4adb4ce4bce847ccb7d7f899d1c4cfcb6db49b87c029b468c71e2a32771364c16c2ec2e6d10d1dedfb3379310e32b3e16153609723855caad0cc183c99c9143953e16a22b832acc833a8cd3b64d448b76134e6cf42b4b68e920c8682387c64bbb4700d8b131c45fe76d6217f96dec776fe6b49d4a770513d8228fb9e8f51f3b8d086e1cce2c5a3af3f4acfd76d985147d7067a3637984f15ce82560c5e1304f25bb1720ebce8407cde58560943896b8a3ecc59cebeb77131b1d33ddc1000dec496650992b25e3b7b13b5ada9ffb8ce961cbe53f43496e95f9f49d860cae0eed145b2c5ed2163a6a06acc60affd3536cbc328eef9dd2c3d778ed42deab72462cd808f2f1cb4ee11376ab3e4e2b1d3b9e4cd061aaeec1c616573ca29d6561f8e675af33805c2d57d2e539fd646851f4fdd9cd00a863bebb6ddca04cae87b5078c7349d6467f8c96fd93f881e76b89d506b5be38cf916094dbd6ba046995de1e38e5874e9582a7920afb47a220e7925f83adb6c14b70ecb6c85e0f14ffc1e99b11e8e8d45a0c4cb7459a758f55a5359776277548a3cb8e806bc1df0238664b35fa2173827781cde2fa9ce98853a86e3bd0bc8f38a53eba0fafa306b97e5657eaa4e5d2325ff5f39a5308126e0a4bc23696bf2d6233d3fb7a2c83f3096f82613ea80c5e4c3a5d5983d0b637c62bba0e18002e8bbec09608403107d1dca13fd22cf5f936829de8d614d8cb04bf969d3a3b7d2a7bd9a572b2ce3e05f62220548e0d8e93cba0c187464ce909cb440f4051a3d58f16ab95185579f37d1e2f890cd730fcdb99f7bad003c4c71bcfdd430eb9dfcba3140c30d9663e6b94df246aa73c5acbff26b7b6c373a0cdf64ac1229f17815be0134509bb63e066f9259d3e7bbc524e95a16907c335d78f830c4b63e461efc80a0d1dd31b63ee14124c23373c4f41f61b1923f4526cfabc5f3598db634ebf07cb70061ea71417f8efa32a2ccbd67fe4943633ef76184e38f3ef594f5ee8e1c148b30637358e32b5031b80db19e982291b383ccf5658cf2398594c5b570a2a284f45b44f343b33c76dbfed74c8919bb7fb09b46c854e0acc2fdcfcd6bb2434ae40f91413fca079183e087ec16be83cf854fa55d3b63fff2ac24877bb1b3205b77c407bb70c04d55023e99eb036fa7dfab98735234fd73a2b4b0962f31fb89e207f5fc8b9d4dbcfa00a184331970379dcf55e0b184fa79f32a9cd7a3b39b2bb9f3a44d628d85abb7453ce94e22ccb14a379e2f0c5caa0deb484e8f8c455e97a1e16f84685300b88211aee0d6ac18965571fab8166e5bb1548d6b556a4808b86494102a8f547f58cc47140d0b8f39718e1a5f35842b2ef476e50eb08ea1202d6db96fdf41c080e6b4609d9acf3114d4532076db372b4ec2c52f2b96a797896b2c1745b13012c3ce9e3e02eceaeb11a714539419b3ece70ffc777b3f633e406d56fd8f3d1feae707a1c9a64d527ece1d57fe78593df50b33227f35a3e31d8ef6777617569113460d7271aece80c344be8f5c139f567568a657d8b5bd5910c3e2f34e4fe5930d5dbf5eabe23ccd4c841a3cddfd39a287796844c95bbf6675567b1cc84feb5d3d4e514206dd4d4c2f90e296a04a8a30744618228efc696c40f7857d97e2ca25b868f236d04bcd20020b654a69180f67d43b5c34b626653abf25cbd364dd465dcb7d9dc1bb61bc3bff4afb9ff31f12ec68fa3e08a3fc91741edf8ec23f0a425482034b47022b74cd8ee32bdc1a4fe0a7e9e626315e1e6adc2686c6394a5520d7e918f5fff74e77a69295aaa00020b8337983e8af0cb58aebe4b486642cd5021c5998b5019cc64d93467c0daad184a7eaad2419755ef37c39de6c0d5905b8629ce6f31a1a447578248787af03d74350f25fa8f859750a98f94317d5915e4ad1b92ff45c440e809a1a612d962e2da2778677040884342e1a655559b1726be4ad5a6afe98ffedec7e4ffe0415b6578e3d4c206f9f9da50fad9d78eb94af03ecda8cc521db0cb49f9e334001e8d6dc7434d5cf0866a27e3c169004c2c722d0dc8843e29091d4c529c59c8d434eef4e967a52d38e86de94f27e61f9162ebee11e95f1cff57f31f943ad04c8e14870bee05454650be86aa4284abfc5fae87fface3d519be8a28571282ffe9869e16bf7eaa3fb491ce1f8e9a1a861a76cebe54283ae43f59d654319cf563ffb04663131c39adf1ca127c89d175880423f686823a9dc8f853912ae6acbf1d7ea0bd0af675760c7435eb4c99961cfe4d27b1d61752fe2d33ef19800c9966752b255693e692315f140a80f830be5d9f824d9136115284775106ed6a0c62bc59ddea4c1662fded15c5eda869f65f0c35f6d139ba8a8048379ea6a3c083e78f68f616d23b913100d71d5348d0b80d516288c9471100af56ce2b5eb5b310d7d8814fb0b7518377b8144ff5a84b5432dcbf931563aaca31d0239c321823fb3c28dd41a89354ce47d4ba95cd30d63dc673ebd03973eb03a7d85ea88d61a6f983e7fb4869591d26e2e818a1f77eef3bf277fa0cf386978ca5195001441a1c0579d78a49b1d5b007b7e2a4c80cc4a9721d6084dc91f6d21f6a10e775c07ca4ecf9a911015cbb63335484f7ef654818804d7474a4c8be35a899bc8a59847590606a07c7eb743244fe10948ff842c8cafa524aac50466b9a5f40461e7fd71950eb673306e477ec34aa9e0259885b128bb7d9c702b410d7d524dad6da5744054c8ca10fe8575375ebe645689dae51cb5142d3511e21a7b43840d0b42333bf558fd51a2870c4860982be9f53355d8cf99ee8bc6836d4692195b0e21fab6280a87e6243097ecee16e9d578012f67f7a377464f4a5f2f222163388a817d0f2460000734e882ce7ebd4276b7e1a6a22fbcef87d65a9ace315ddfbd8e3a02984cc509312fbaf7f4e47a074569ace19f14010aea632670957b2e9d5ec789bef90e32914d3d43c67a4571da14108c2ea8b80af4d332c831ff000d02a98e4ace3dd037ae843a8647163a4e80cdef62e2536c822bc144e643e0f70dc0cbf0a0b54ccf5d188733eb05e87f92add63cf7ea85f91c4fde4e2dac2cbdf2f656cd01db7777ca4190e32ed439d66c18502decd0c8cc1533b263d0d747986c4e6a4aff70e2a84badf0295e5df47c1e35ca13d6bfbcfe7c794cee421e96b219af6b694ad0f24d6f76afc88c387903aca32ab3573eb56dc593f33ee9a910dcc3ed709f9dd830a2029376172e63c7138b757ab345f1de0accb21c2fb6a06b656ac2399c7f1f0d5fb3447c89128448c35e61c2032b4ea4a840119826f69ea73409ababcfdb04356f66429b29499ca72a1037f7a08fb2e6f265b4e743e68035ae0311b2ccb61aed3fe17dd22c77ab38c49b09184107fe012d43ab385a11171ed09929cf462649449b68a2a10587d2f6948df8dc509e05a2bbb1f16563a0b6ca9c8b40528f55d1ba56d68b3d39456c2ea71acbd06db6cfea521f51314aeb39444080a9b05aa99bff9fd5f2feeed3d3b9ed33936c2b1bb0c80cfe0a2bf6fecebfd4f2ba88d6bec458dd065b852d56bf61cdf98651790cf3063d310453ef7efd57c63ae348ae3686433387dff0595622d44ea5917e645d312a1175571338f4ef78c7292ca625d81de1166cddd0005f0332b4c8741c281a8bf6bfa08520622f74e19a7a43a26a8c3cb806009d362d5119c0182b427f52652ecf4c346195aceab37c5aed0e9fcbda7d4d3a7dd59dc3b10c7c5fcfc98ffda7b357327812d2e08492efb7c8dc6fd6f7b3c22193dde3ca229c1a902e9fac48c06bd4ae72560b3420dc772b0ad7fdae4d48f2b286eb5f85a1ec12c77a21eeade57dfff2326e46fe7de05f5b0004fdddba3adf099a3bf1a6ff5cf1fd56cacb8bf08c531237d5d769a1d9cf676dce2ca1309745aece9b341dbdb960b84c40f3f45d72408f2bdf5fb32403c5826da8af71d6319a0e6e9f282b578536cba20c2ed267df4d4ca2f49628df45b836b993232981e0bc4f121b80295847ce60cb0db41f67851d6ac64f683f7cf6f986c5fb22095183645fa87717325496930017920dbd74b0be6899036293809aa863466c271158211f3e26dd86a62bf4c159cb17bb5e303f50650b8776c5644988a896fd7fa1c43fb6f142f1451c6b20250612c0af43ed0c2570fea925070ba9699a6b7ed67e7b83bc1db2e213a5a63c96a2ab691cb38e90a435a8c6f638baa9af40c2913fe0c1d516569acc2c27a57e13116a7ab0cd86152c9d972d332eac62f8c4ef9cff1de4c3e13cf03c3b9dc38c0e71069450443b5e07b51e7cce9b96dfe22b652f29541f0ebde8911fb56c2e6baf361ede39994d3679afb266734128094734dd29a0c2f90df70f30bcf45d0fcf461d1d22548d7fe807a571e690cf3bb71cceccdcd358bb66e42da73b8213770cbda83a50d1e4869545254cb4819f63da570b4b13c8545a095ee5d57bd74a84f70ab847d8d9478f232928a7335d8c36f5985514b81099ab32dbd5536f16c6074e2dc92b44e35aff65c9321e89f0f8b04864d595467c73c8dc618d747d01b3a62ebca9e7a4dd86ffd218e1cdf85ecc2ce300fd5787ee569367c97565a375c414ef65431ccff63866be5e47db305810c7df61727bd1c6b5dc37048656320eb71e3ba587d82b78a34ae20063e4f6598bf60b1d85c27d0fabcfaf9cc414013891e6f02d5953c42ca1c8b66dee0be7ea6a5e882a1d6d35ec67b6e6c0fdecdd7d5a418212ed30ee1cc9116fad5297cf60b1405b8943872197347a890766bd75b258c0cdb6c836dc62ed8581077f389e4f236093a2e530db8baac66a22ce78c5bc67ad6a928a5e666f59135ba35fdd6d8f96176eb7ea8d5d7e73cee10471ad348f89f8e17d1f7770b166253b986d9238e4014d6a1b2d7edb9c13c0779d4e0a11d09df3d2fc3facf27cf867189dc9c261bcecc301a51ac355dd08815807a171fa5d8a045b2fd37137b2f43dc630a4f426b53e01a59b88e3020160ca2c27c799d63b4591a8607cffd25ded698064761babb99103f2d8143192c5d9630cc62beb875e793778092f3046cd9f1b4bc83307a53cbbc36f9f1118053cbd5c06dca39edfd2512e7bfa16397cccd20fe4fb38c6f6ad66513d42be20a40e54cc0deb93feab18795e45bb5878663e0750ed3a4f2d6da17cfd85dda8943464efda1fff03205c84e9cb2a74bb26c938e6bbeeeb20ed2609cf795d6eab980a28c723a14eb809c553d9e5c5594aff1e96074649c1b8f4ea42f0d2dba40d0f07d251621297038119ae5a52c80cf001a332ce5f647d6c2d020ff621dbd5effa4a4be4b4cbd540a0313bec9acee45307429b582a5f71f71a6888bc4429f85beab1f6c11f3ddcf1561ad641e2571d17c77ff28ea33772d89aa6e8cd12c530168ac103a98421c299733ff4842ac944574ce3c9df87506daeac089eb8df22f45ceb8c1230be580bfab7d2a746071f28aba102e93c2e46e30760430ebb3e9883f2d09511f99331cadde5f96d18ec33f3fe2af12d46a3e4819ef95634241dbb23f0ada97759544579e0497f0f4e3077f1dd54a14ebae8b9d825a729e4b853f52b8d58832b6a20e56f27b85fcf38d39563f4afedfa6a5e7c58c47c417438e080463a8ea8db995297613db3be953e31fb570f54f9d90fe16c60fe2d75957701ba1940e98658616d5545d4deb230aab310daba86965131f7a6dc0f7d6c6e6a12cf2481f3095b822e52b54e2cde5e017081358ad1085acd94e434025b710ccf25f9f4423e6e4fc682ffe1479840d37466ff4771ce035855cda8a3e2907323fe7760dc4c39e317cea433c7a32fb587dd860683b08a9b8a568e95498b2107699f5e2192144fe52ba305240a70b8e9d60b56421d7e7edd141734706ff670abb57e1683b1c12b387df907f1982db60a0f206c5892b3b50d1daaf77194caecda12ec5fb1f89fafa5f749bbdacca43de4f7b6d418a9af0ad856e662a2ebb3fa6dc83a41609b1f7d5e90b53d9e8a77a73cf80f2984e3af010aa2bee35794712fd3502c9c58a81f7aaafab04f3265776d6bc82e79d0ec7e7da13fc57c79dc9e4f6ea29c2149fd57c6b878bbc3adb2aad4526dea40e8e30c76fd836d2bb825dbae2fbbe6ce6fb25c71a5cdadc37c0e1852a1b66d7451f90ea84b352c40a78cdddf18b637bfccfce077209c739ce802f85392568f0066f632e2cefc0f468aa965bce09c33713c25c4e0d5381157e7cd13f764cfaafffe0b47ec94b87b9146290719bb5156c44b97623754f59583d8b7f7450ec1b1d7efe8b8f5a09decbdaf790922805d7b06a29aab14cfbde149a79ab9890cb337087f0ab3f40b8abc1f2a5d3bf1aec8a7009a91c7b21548000d50ae6d2955bb9262787eda1fe5e0ec769a0c9a3bfec552fa05d6af6a10223fe4bcee0832475e5a3a38c823cbea745b87cc39d7d49defd664749e920843b801cfc14f558baad762f8796da716674e7ba1a4662b3392afeb24ec6e3a7e85f829d64bbeb812b021df0f8bc00b41660d106920b5ed28f3fffd8b59aff15f6cf514394d457d7ce7fb965b515004c8dcab97e3138b9daea3919f09af0ba2eb15fd37a75b29589f9e7456cab542d91268b8395fa90b8a2f5832f1f55cc4e0fe7c0051376cc1cd09b18b6a4674dff495bbef5869d148a967835c4adc996924e744e19a6e80456f06e30d0fe86a081f481e2aee593cbb63082d1110eae5267a5c6e8f38c766591f5de6ac8f58cba9aeec0be824b61a025bbb8efd53d1e59f6ea24a9408bebdef3b3cd5ebade03afc2dab103172f92ca4c9dae8759c44d67e0b442c00e4b81a50abba7d808c0b2f2bb9465318da6cd9bd89e3948d785b718d1d225c8ccac620bc9b31aa838e9272b4427ee3753dbacb7af3cc175063bb9e063a0570ece3c50fcb9468b7e9080feb5c64507ef91a79eaf0d70a0298f9e51d3a92b2591e3e6bf81b4c46aa5a64d620f1a8817d29d8d0deb2b373d094438a829d124aa966d8ce495dd5eb530989bbf7f4a2410928fd2687a5975bf9384c646d2480c92973f0e76cf8c126265371ea0612548cbb21a2772366d43aff01a3a0fafbc609889431eea924b2fbd0b03c1990f7480bf48e55bc897cff83e2748c8628fde910b643b211c951a01b4e1953853a7602f01ffc05b58f8a8a63f9b1a1573a23342154807940ad3080c77f95cc3fc714cf427845cb2a02a801be971f980f9e20ff0333c3b326c510615c2a266e3e4479f6bb9476b29e9aa9ba2d18e5a47f2c1dc8ca2a2f68d57410f5514c37499f7e8aa634567f1f5f43a1c858ad964d4ab4b3fda048e98c2bb369a3d7c9bbe6d202450bbe4e6874d01ad3ade3070cc6435223911150230529e67998d86740ce1cb35530e4510f08b968b78e319c904e2f92187af2ae70900ea7faff3830180a72ff9a55636e6ea0d6be5ea7c8a9dd2cb4e67afd3c4baf5a9506f75173e5c8c556b77db2eba2b25f98db84d64302ad1952936eeaf8296379e14cbcfe0546ba40750e3d14d29d884d1fcb0538d90fad43f53c20694e19239e24f5adcaa000718d0819be166a2827a04eafcf04fe4a2f8eea90335fce30090601f5dac609543ce74671cc0b735cfb447002a2edb9b182cce199a57a186f6bd2e5ea5216b93e13e88543de802becd8c0e7b0de5d08dff22903024da169dc45c8c44d4cafbdf8ac7e3d77010dcd94d4a95f1be9322c8b99449a9c737d2812f8a6fde48043d51058633a0db37a64ec4936ab4e80fbe7168b3d44bb92e50d964a9d98d254a72657755790ac9ea9fadf5a221d5c1bb6241bbe6e9682d9f74910f8f3a37d5f597ce1c8ffe000ee97434a452be176171dc2017530ba5314a9cfc90f3fdb1dfe8c9df810b3ea1303892a9df04337d1728d0257f85b921c9e1b2d954a090e0e74cd016114f9e7b829a6d311cfac64aeb2a3cdd10a96bd99ac77faf29ed4fbcf93e81fad1a37bc72f474c650eda34c4150dd67bf9d9c028b65748f99dff24595483a5a5aa8f09886b51cc538aa8666669923b1b39ddacbd201c11b6368b1e15f60bd0620efa37608a8b797f7b275cbc8ae396128243944fbf9dbe14e00817ce4e374ae3c04ce65b31636d53531326108d77012400faf0b6fe6f311e923692d9ac42af0792ec8d7b47303d875e5a95fc355a0a68dd690f29ba2aed1193635f6ac0e428f8b6494402ebf4440ff409bf80fdf4049d292178e18473701e97638ad7e6958a951a457a0df68a1f0e9869c77cc535ea6e8b35fb4b94a30dba24bd9d316f5dbfeaf50832a1573f6965959bc18149d6f7971f567f035d491c7a51825d5b4b5cb72dba919720e6a46f81aacb8e352e5fc15844a173609e89a21a462676c6501fc66c2f57b041e8a1c83917f4a0e7cb890e64b754c4f6731544349c1217343a4c8a7495082ce57e5137a1c80d3d479eb26af5f4ab7452ea86ae729abd2b6ea4c7f22c1aba4d71d47cfeec2344aaedfee4acabe07011807029a52aeb083436e4f4cb73320ef0d5196f6f1b2edea8fd93cae03e54997934e38e3a9b036b24d491f803799a0fece0cee98abced988ca5b32e179a3c8628269b18dbe3b2914d9710c4666cf28e11cf1bd296428875f25085e98ef1fadd60db3e3dba3cda144824723fbc449103634c5314954b5be07d0f2a3c3c45700c712bdf0142f317c2201e3a3670743f9bfe23f91f5b9e5fbebf6302a8faf6107eaa1820ee82584557da209796ab692d37f2bf7d2cbe192c25b2a2c2ff09648ba21bb3414ccc82a3b49f1fa945f51806b24ee50aa3e562ccdd374778f3ca98beb0459bb56f9359bff810aee72909db26fc5a25715ef07bced17999a010c78226b3f8bbbcade996bfa7f9eb312113b84cb1d65cd0a52746d2c7a89b109783202eb2aa14bc7a1a46fa225b69d1992838338c6f5e04f0858d026bc7968a632d3fb345f39c2dd850931554c7f8950246134b9cd5f4f252a0d22d958a072c61d25d5ec54cb9242259f444c5e7e536f0c32fb716993fa7965fc98e080970a36a08dc4eff9f85b77ebd468cdcd2e72d0a2a021b0a853bcc033ffc48bb68dff288828e46310dec368b860853a6c19069db8634486a6f545744ce83cbb1dd2c5f2d2868aae84f1ad0fda0aafe11f0fc0acddabe4877896d26c90d6542692b80c65395f69132f0d2fbf7cd0ead779a468ae9f617eaad77ba25db0acd78dfa2b2005aa8e8273a364cf2559e955efb36db928aef178a4d4184007d5ca5c7ec611016a355ba79fbefab86a123fb97f53b0eb32cfed5ace50a458f83644cf40b91066118343e605a1f6d3d5ba3efe9e0f2250d5bb5257ea2fe097a7a6a3f80fcc6702956e79474e6bb0ad3564e621fbc320437499ae7c72a2384664a44a01a06106bbf02d9c1953ca2d2d61c95a1d6038b11635bddde4ebbfc5b419e3058ba0b4b6d9b165becb17b64d4cc450b31ab20964d26ee2352085758f5851d41f754d8a8f8a920ea88631b61f69d60146a2167a704129a58fd8fa6165c162820611a8906d1688ace79bf9e66512cfd1484c096ce50388e602ed43cfdf67cc63847f3aa17dc2db6b7002ca597de8170c5c45011b43fcd529de06cc294bcbd8d73220c46770c5a9701628669d049a83e764855c5d32d40e646989d7dd84266a7d280eebaaa8d47e470634732d59e9ab4297eb3f07578b53f3531adc1391cb47dbfa75fdc02cdeffacc061deefbb7f0ec9f0f96e8ce0496e5abf5d87798a699e416175058bd093e97c1773b5616aaf56ff4ca5c26fb191c5ae41d4c2f361fa60b6d554b3480aec44c9fe477d2f0f7a45d7c6629344e67c93f33afe231625e5aebd5f81541f8218052a577b9ad7f6b72ac5723585e6de4ea90a2872b2b951df89ac3939cd87c91200b254d574c7f7cb55af7c9b278b4d6b201b12f0b94ae06cbb91007bef89368b73b0ae8020f955017c5d46c291f0fe20fbdba1739ea4a331803c6fe7bff876f89949cd5da5e2e7eee764b3c7c45e8ae0292753ca8ab2ae631fd8438d349a55beb9bdbe841e6bbe7882bcdb488470b0e55e6eecb0124ad3fd3db5a1376f11969b8287456d3d44f9a32dd474999da8f7ba73dabaeddbd2c810cc63006d8e5dd154a09b9e814997ea719de328d4e4eb6ce1ddf1bddd6e9d7caaf9b386955a8fe142d010e86532ecb06b3685c0a69161f2627a8333068c7ce52140eef125b42b36bf27f74070d192ba8936aa587b9d398446c2261fb965280bd6bc56309184181df312ff673c4335afb8a9e2140a1ed9832d14cb05c8f77ea84f3f39d7516707ff801d070e9f425c138f06929f5fe233ae282b20085c6cfd5458c7d08c24966692af215c5693f9e09861c01d9b0f860dd4b582c44b4a73459741a15e0edb6e3022391b79d5caccf5386b635829f3208a8158ad8b7a396f6890d0f4cbfbc61a2624c9ff55d45ebde3ac5c5f07c9c043d015c249bf7b40262997f5c4e93716f5e381b544e4cbf76729fb813e98333642f7d68cb6caee49668824a79f2d59cf73363b3aab88b4a6640547e9beb87cd78b6e056197ff9871fa1dc4f38d05f21a6d156011761b90a605015d45a834c13ff17854037e72af3a17de04b9deefc24c59768c8a615231b6f3a0ab37d69ad4a1ab4318803c69a3423f70ef6ebae7c80be230a4c64ff3b7ee3c29c6eec97370868294bd185ce576781e8dbbb69138f9569e4c638650301017285f5bcc2f606b39222130456ce7c2608366f51cbbdbe36eaf3448d841d4021c2bccf17c6de26fd1a2a36fe4477d9a966e34cf035b9f1490b7cd0161cfe4a8afc343dc85119e5ced8c7757206d6bfbe673677dd099007e05d031b53fac544405a942f3654502ae43cf1f882d7c562841daa43f96e062437eee30a993c488ec4d501ebe4ae0019344c8d9ba892d2e1ae84c07e24e9ac59852a15be0425881742c7c83caa026da718596830ed3ede80bea26565d24a529fc04ba53f5efbe355b36451ba4d33d7f7b12e1a09081838682308bf2c5a3b7597870268591f34fac0691ca37901fea0afd16dadd5cd3e2c28d2f265a4fc4f027289278184b6806e95fced0d23912b9ac4f76225b96bfff99aa953e779976043dbed61175db8b9373b21343de3b2e8a367e32197cc198a8cdba743210cc7a42971a10966a4c990088df071f1ecc96db33ec361bbe98c825ca3575b0f23a8294ea969cc8dbddab551a450655e488341c0541d8d189ad94b5fd67d052554cad0ffbc8d020a4110209bcde2e4bd6d461af522794470be1d268ff633f1317459eeeac3717e72bf9da0f4823dd4e2981c46655c5ae2dd213e329c5b151e9fa973396db3cf3d79e5362c6e63190c1fa936d95b98d81411aab1da95ecebae94d4c113fd49dc269eaf9033b6ec49c13201c14f7dcec4b29a146056800d4eff9a0c979f6a381de3f69f6aed2c5828cb82ded7db52ecd793b753205feec5a48f61b714c151aefb9944e254c43045a6c5e9c002c79f2bd42a17b713f23b5de9aa788f87e4266dc70ed569ef6e68ac621acfb6814f7869887fe266258bc82b29a70d391922a2713c31071bf73da0b4843b8e1f5a7f3f3f2aeaece946a819f00e34e0e2d98fc32580e79cc237647de6126a451102b1e8c5cc9bb2a3c01f0afdffa4005c60aa869011d4dd3eaa4a7bab937bfa7f82518150ae35fa9ce24bf829c197b792fc0994c7ebfb42a2f9a93f4c1892e4c25f662dd8248d67aa4ed9afa83ce9326dee5a20cfd879fafe9573b472817e74efc65e8ecf5f47199c9737332f634a05b3354cfe9340d12460f9846404e1b406c911db86c6678fb04a3317a645b1993e5e61bdcc0f822ee280bae9d84db191051a9958f22740cf0894555de3cf136f4cc8eb1c4ac44a8a9822f95a15fd6f80bd37252677a2cd10d703f9294855d169242679002d3b322656b4ab8eed68e404d79614fd4d91816c20a390341703e68e3ee241e41739418373d0fb9ba1fa6a0366b0cc0a2e9dbdd983188f8c0400dfb354b81f71817cd185526793fd68683952ca58763933e76fb7f1020df7f59bb35b63d41d14cd157a24fa3e4248b5cde6286519e8f437a086e9191b1faf82367faa4486978ba6f1810dbe877e5e33977dba474dbe70a3c4d4671b3f63e67e1db5281b1e0d0e0f1a66b1397e0e7726c4c374840a5fbbcbb98b6952fc211261def9275eec50e83729df2399756d6162cc2ca4e317ac25801e89b8f18974e47a6c3fdfc263181a689aab050f6866485b67fc445f037294f95592bd75c454a17df0a95a7e2a30c89a9bb2091102afe444d98002f36c65be3c1f79fb6665ae408e8744ebd1c399d0c95b20b21f06f7ec00f86554ccae8171ffc4698173464551795a77ce540ffe692450ed264e99b64dcd4deb6665c99d906b8b193ff1a1960d1fe4417660de1fe4f7df440b46effcc4ce95944bf2ab5ee1aa227d2cf5f513c191f6d5baa23d5f4f759e9404a0c1c86236e72d1bea4aed258bc652bd97ed8a226ad6e50a61918b3201406099938ba0d528d9bc6ceb36df2f7ba6c6538678a52db407d9272e32b13eadb152dd4b8ea3d384de54f57c33354c9123be7b8bc8a770ac5338c912c1539124449f627d105aba2102a4b0b67b0c65221cf18203e77f49027d0ab585b8bfc6861227b7752342921b1c00ee5a8742c089f201a190b19e41d3740e919a808e1ce8d3591a7beb851d81b8a55d61586651d229c1650f5ae4d2dca791c1b6d3cb2ba7059fcdb19dee84e1ad21ed8f12bf460be2dfd201a9fec9f0ba555af60262073d1910898bd32ff43a6cc844a9eceaf111208c959f48b03fd34393fa60ebcd35c973c9bc61a27bfc3f6e5c4b0ba005d1605542ce249fff70a03097330181444e4ce33c130517551acba9a693226e84a5edba5da80a3fb530bbc8bb5999739dee9c696a9ee1c7198f4cbe9635e007afe30cb77c1315a02429e226e3727146074c38e043c4770481cf4d7d321421ced4bc44cf359fab27bb5add0ebc1f02d1de646c157aa0a2fa053f76c5c17dc0e21271d3eca7ea2b4db478f23c052e106a734f93c5b3ca78de70c8c549dd411b5944ed9f18854b4b1ea1acf5a8780163a1fcf2104cb4c483fd17e8f759880a84c0e4cf5f8304d6e4389237afa8c93650b27e0319ac90f660782f92afab62e21fff102bb8d316eee157c2096ae69ea4cb3234c3894fbde89aa3e8cb18819f09ab8961d91d33901b0fb8234142d6692f6f38298534088a4c66b78760ac4cef690e6e67ef1c25bc8d010a0d12ce5af512bd2cf723bc65aa592ed8af781767b89cf66584553ea49cc8bca17efbf881a2bb424add154ff538c41bdccd485e625ea495c8ee50f6aca3a1bb285905295dcfe15b564a649af905cef87ab0c018facbcc04002f9903c8ee91de5e455eb4c35c1f0b1ebd65ed2c79fa3aa1a3ad8fdde6949c21bcb0489310021dd0ff77bd3a54e4e3b445547cec1ffd8883c38629b4493d0317093e90d51903c814885d75af75d2afd96792430eea0b65b981305cb684cbe871f4c5b5de566a86d2982b6ba8643116f50e988b228a460de65d9ac360736fb2b5052f51014142b0a9e2b01c36bd85182942ebf39943787b4b19f33effde6a4b78f137e41967cc89d4ee64e44d67ab1dc84dd30e65c51866217d0819ede95aeffafaa14642a6a8ce8ed24a8abdda1f5972db5f0bb9649440d298dc68e37ea3175044e099297e0bd5d62a9baa8be949ac6005a39105ab710042110c78a487ce7c87a2eb18341b7477b540fca6b0fbae9550aef51b759b9993e3485535e15799c473c5d71b1f42f1f460b9bf9467ac4548d5119444d721349a122314eb746e50915a4463efe65931bd505cd5883f0d6e4a2b4142da4c61326649baa5f679e8a4da39ead03b18235e148dc5bd8c6cd35c616bf1ae2f6f781baab1f4cf5f618ab074b774f2246830822a196c16053ff2a97bf9a1a04b83544abaa2c40cc2b3c3c578c00cad70dddd0ee284160987387de74bdc1198d083e814ceae60b4815bcc8677bc2999818615a872ebe40100a6c6bc0224c0195ff0b464e2c7ab6e828b977f5019e3cc6afd85cf39ad89fd1f73186d57d7b111e7ecba67edeec09dda5a22a968c9315df130d07863488ad7d72812f23a3d10a2d4295f6ed0e18a861c01bd621bf7090617e92b18e32cb91cf35741ecb3084b7f7b7bbaa2e358be52f2c197e1d6a8acc294c7c43f059178c1ac2ff2fc5ae567651350d4a87284f7fa8c7c31b9c2e8ce78d70205ffd1a869fc63c228d3d7973ff6f757abe1aa7c71f3e8624b8ed2c1dcd0643535eb15e73dea20e3ff98c8ddabdbe2fb6c346c4211849b993f27973dc6143a86228bfb2b5e2b94db481bc8d63c61b0e6115ec4b75799bb3fcc8bf5ffd7e0287a8221eb5388d05ec69fabee5ad152347ff9ddfc352838e139f791970773d32170afce03ba5d306042bc4e3a9c9d447ca0d93672bec897ff1b59f3a91e7f769f0cf7d1afe5af0266c48f486997722470555f59015a6e9b74a32019aab26bebe79b86bdf6511c434889ecf5d8766fd798f9ae4f10acdf4810add185d82345b0c469eed4f967a5ae662859127b22b1f0bad7a32196b6f941d3a2aba1641af14e074d19dae0e024b5defdf98064de910758b275eb0d39349a9aef6b2b9b9e9ca3d5a32d771872fa0c6ae9e43f39bbdfd36b9c017ac31be13f98bf47da6c367b92bfc8532bce28d6d9762fd56919c033378d0827ae8685a4ca04e3482fc1a3a023e103e2924cc4d5b897e23afcbb8f09ba3586ac455f95f4ffdb99e5fc93ce6aec0d673aa6b08de5926a19eb9a7de0ac787881bbe67a10690020006133c407293fb99695e491d26bd254354c22e08e3fdb9fc7b828f446c7538fd631d5ddc9992dde920bec9457ff2021bf0ca34f87beb6235f42e3606a48b183ea3c30dfa04ee94b11969a308ae876011826eac0a64ed655e84e136da48efd9d4682ca0e41dba225b19272b3212b98fd0dd1ee708aaf2c16202252fba04d8d9a960103d431b8e037b6d9b97aad6735fa563600edf95e8cee2bf5d0977538db048c7dc011582cbf4d7f94df5b39928f015538f76acd23db98b72cc785554523aea0af7eba88041df512957cea80ee6df20da80aaf0f76e850b4d5ad7fb780a37a34f695c8dbb96f1c03dc28cf6c07e803412d3c0cfea9e94e300334e8b6d94ecf53e0811238c0417399ba16309ab6fbfd99f7574c552911c05ab03dd301a47daed3fbe186bad39a262d8edbde91902aa96169eb53c5f7506cf14671e5faff0e6f3c33932c9374486e727858fe5c6a8bcfe80ac5672bf1f62cbb50ea9025a48cdeab0abfac0dc1edb00cd8fd3e92d19e042ab6e319561c26b1d5fae34b408a926941e4defc5655b193e1538db3e88e657d0e15f5475e51b039e85c7ef373b7a9fde3d9aa569fb5965986049fce25a73449b953ab590071979a479fbb6b8f44f03c8a9831e09efbf4138dad207e5ae666ac169682300115e04907e090e27deb33992f89cb3b4e460f7a7c577bbdf749f2707ba42a8263496a56922cb7fa2d97a72753a98db9165de7083ddca4af6f640d1fa6430e47ff43c22f87206247343bb0d365a77d459edd065ea228127ce1a1c56fb535e109fb0ef6562d04459b2ee1b7f8ac7666eb3a44ceb809419d0cbe0c4ecfc274d4a3ee511e1060b3b7948c86bd3c9effb965d5429c099df9b14c9e0db340c7090ec8ee9356c8bc8a6b8b4315b9092051d69b9ec86715edfe305eda73d1188b8426bdaa49329fcbf916eb555e23aea4b57b9c674ecc0f3107ed0b7c41008a61d0b77af5f5dffaa015ddd623e33ea020c0f8f5007d2bbf76fbd94ef312bc27b77d69b730e4eb5e4686e2e4950ce7a2084ca361d93c54e0b0b4ca9eed6710f1a2dde8875b877c226d2d10b828e7e346aa2bac738d1dda914d2a8089eb012a9ce5359ff74561150f7202ccbf5016fcecfa22f1489631524a022332806f7e9daf39fb8b774d4d3490107c2a4d27546d7cb2270b5804d01c3371aa06a3d180f0b4df11d23a6545157c1eeaf1edf0a02f492d45a639aa6e9d50246b966a2eec5053d40bde13b502a2f86f384ebd94d6e4f69cbba9ad9a126e2a0eb6dd84d129e9c5d2cd5763d05420e283170e73be17bfc612941e1b6b035f20d1ccf010faf6188ef76068b908fe5519c772bcefbbabcb7ef717e9b906a62a0b00ec56bbc0fcd72f08f3ae1a257dc847874f420a42d73bea2fac9900baa9dc87b3cfd979fd4b20d754b0ec92b8afd19523a2c46f913febd7489a156ad0c69c26a0472db960cb7f73a020e202294f29ea25eb51de2d4f72a2b9b7f9d1a379492e98c9514e77b5b516f32b974f67ea7a33398467e33e125db8994913ec7721c66a31407fdd147f6275f768bb61f1288e6318610f2a471ad84e88230363edf13c7173da724656392e8c08cc53729080ced477ff76cac77e2985d38272e06caa793d60d14d5df6d051699deb8a51b7749b20e0115e648a87c8b44c8b26d7b8f6447097b0566ce388a30087c1050fb2475d8540813a0c48e902419e37524d0744b92d3f14081fac0a101232565bf45b70cd90474fb38bdd6f48c9a46c523524a921c4eaba009e37655e3529a15a16dec68fa4baf62c51b6c670d39fd0a769f4714311d0e63ec0c5701fef71e22c29614b3ce509ed448bfdde4648cd32b98747e93e2cc668f83aece521ac4306960bd04241c2d5e9bfec9b8160603733f3d015e7fa2527ee300bf6de1c2c9fb0dcc3611941dddf5c8129b27f09801169b0fb1913bb7748e7193f87550479d6b7ead333d8da7e98feb892cf92b2ef450335bd4d2eb203c698b59d862ce9096c030eccc5885835f37fe2aef3184c3b75b2b9b3803b526bb32e0194d812eede8bfabb3abb84c66d8c6450b08e5009647749da4891b4e93e5dfc5de09b546cb2a80b9cf2701d1ca4d15bc5da86caeca4ab339b179d9e497db1450d4681d32da23c5f3b8c24a9f86ac1d0df434821823c47d8483ec86b011ef6a219cfa14b74c2064f029d636d8392494fe106979e179eb7ce234a4dba1551cf447309efa5ad1f70556ae08bc777714d586578effae2cca477e2ce61b227f5e2d5241e493d0b2379b621219faf8d8be44ea9ef4ebb8b6aad01440d0e9b10c964066e849128334566f5dc39724a8ca22d8d057cf32c7916ad2870c5eda332f87fb65e781b419a10fbe49630d47f1b115545309a5390e505702728ed43936c42d1885df2f9bb06cc834dd68d42175d9289a91879678ae06032bd324500e51f0ee40b14d1cf6d940a5e0850d3b202685963b8035e7ada7bcb80dc524d19188c2160f8539edf53d2fb0567ebd56a1a2f7c43bf7de5532a50b9afb27f43ea631ce59367a3274ab8607452f9811f4400dfde9cb049b2a475c8943f4f83e0600470b4f6ce177e2198c8fe569d2bae0a1d0b139211d741024b26f3a9916ea3c0b704b36c93275a4991dec8d91a541ce27b332183a4a1fc372dd34bd6b876cd1524e6600b7db242a799f20837376307110d7454e187b6c56d62a574e51e9e5f95e81e3ef5fa42c3518bb3c42ce4d49fb3395c42c2d44bd829594566f4a12e1ff8c4ecc5c34aad3f1a8721ce44d3b696863434948aa4770927401e4b213842605e41a3412a73158d51586e5311d5314de755737d4a0cafad4b8eba58b552ba767e4462ab4a3bf2b82d952bcbfb28cd2746b65ed92935abb4fafe2e7603317dadf8fdeeb6b46c97ee02e5727b8bb31ee910f86f45add2098d6a6b0fb2bcbc12e7b8ea5ea851984dacaad187134e5163013745e85e19947b2ef56735d9b461ed5ddda0e538b1239bde55ba16bed3b1dc453e4148d89fcc32288fbebd90b7e1daf6ad6ece865da477c8658075866b5c4994e8d0632391d8c6ebe0efe37f9c439582cb28824c2aad6548342eff83fda4d7d90cca7955c66b2ae0274ef207c2fa6fb7504ef4871a5df25bf001b8adf8dfb19dc19ab03fe960cbe6f44b93418ba8ab173c075405cc6d28000f22f6c7cfe4063e7aca85914e30ef32ceb78709e5134030fd91b142c2ad6f00ff43bd5e9804b6571aaa1d57777a059f080d47c6f38ecc9dd1d1f1a593107c91d9f24eb60f5e22b58ba06e7f032e4d66ba8fa89ae8eb539d0ed255409b0d4b0a3681f1dc4f5a519211c8efc83186a8847c9913756ab7d0614fc275320f1e8312e204e6043a11af78587f65a0cf95d55d7aa10bf3b7bec83fe9ffadfd9f6c0b7d5e01213bf5a01142a4c25bbbd865480da06eeb7b7db6943d40b60b731d5857561556d87a5288ed6b575d80b60db8c0ef59c1cb3bb43c62a35da0ca1a5fdacc0f1d5b2bd59ddeb3f4411df1e5d813f78a5ca0eabafee8c7e1a0b55b8067c9f784d9910b8d22d8224b90d89c0ce85dd2c5c2882c213d7b8a3d07c512e572c8a9696e0e8e028ea45572196fd2c8185f6ba4077e87051020fc197b21b69774d6be94b6e50d7ea64ee11515ab61fc64e6f7ec85446e7c1033fdacedf6a627e3b29d8136f45ee98f445df5680b953daffd7b625d98afafcf8b590b67aed14f8b7c50af82c8387790ea496c9ebf781ce6e31347b5b9970ee98ea734ba7f8a1a1638fee252cb38afcfd435c9acba935b15dbbac6f3197f09d4a470d9b36f3a6f27cb73d4b7e840cdc0593074bb3a07881806e614767145003acf8c8336d6827b082a23bd71fcb7665e4b4351b5b86fe7167d89fd4a93480c8807658796dcb6edf799939dad35645b23e73ace82096c83a1f92c985c85ee9c963a9b4f9e6659d3f426e00ac8bd31d9cb649f6da7a5553b2f4303697ad1bd765759aa0ed9111a7c92963d4b6f09dc60c2d71b830725b8f6c932e917a0e122372a2cb1673408a6c97ffad46e71fe989cb3f377bb9906ae8c2528a6a0bdc4bd4c2394a9b165a79b9796d769dda30a4e5e214ecac12b45912b38e367e571f2816b5be12554f19934c0e95b94532d854d8100f26d26cc4686b82e5663efda19d69c39f1f8df964f52139ddf90f5a3f1acec7f5419b1d7b5bed7601a37fa6b26d98058c60cb6da1aa740d496e08fe23222321dafc8b2ef5dafe7207a57cd2fe009eff2518b1d9dde687a687139d184723b03f6120c1ffc62fc96f243971418a10003242b9ff8c297ef036d5f014622d5e377d18eeab535043d37fda41d58656c370bcc862527040d79650060b8c54388bd4cd1b2928f1c5aef361671ed44aa181b5fc7810481d8eecdb4947c02b126fa260e3f0c65446427135c9b7d5902ed16093a750188a454d594180b968e26c21fef0984fc1be54ca52bc141d99d9f181d0691e0970dd5a28c2882085db6cf7bfd0c5573c978f938214eb2d52c499bdf9a89b8409247df73b903ce48de5f7cd945ab6be939d157cb7ca6939054940b5dfdb32248ad51323d1742e31dce87abd534bada2b7bdf2bc45927c1696eb8fa6594199014f5cd7b07b3f67c1025435518bc2aec0836925d0e94ec05ef11cd5cac5360b2ec6718f9ef989848f0578cbb0070daffd728b0ef14a95bda563173c988a81d03993b69823404ac4d56dceabf1bbbee8147675140897dc12213ce461b48218ea733f121a1322f58d0223acd6a90de5c67c10f329b5685d17d3a89c22b94f778df6d4c9ef6bac8232d22d3315e234d852ef2e610ab99fd4393da933e9cf51073b5f3d590b5ceb456b12096965598290a50749826a65e2f965cbccd3b7151e0e14489b8836cb3a5d389f42d5fb53e3677d14ac4b8bfa239f5d0412781adc3d0372c7a04aaa04b66bdc26315138da0306b387ae992e575d098e65bfb1e9939f9bd1599eb9f1f82a9e0152ae8d39c9231db5f1eec0e7eaa6816c96b0ad41fcc5c4ae38fd91fbc986fd9fbd489690e7a2bc5cb7ccb02da6bd99e6c4bc5dc5f40eb863eaae35ff9d9213c59e7885dcf6cfd59aabcede31ee3a5118747747387ba8eb269ee0e25b265a9bbc221a064b585ffcae30cf99f47f3db6b84d1aeec9c44692ceeacca71a272e55caf2be6a35f145ce28b5b3f9d210067fed63657d6a16d9f30aecc3cc5f3a9c87f5e30fa950b8b2f3a16e5103c90cdac1098c9774c89ac73d126a10aa36fca4943fcfcaa7de8733e414f4387818c27720107babbab2cfcb6c86ffb69dec906d96f52077a5f1973846206e50ffa7b1f6df1c5b5e05a8ce7db5e86171f8378a8e9bf06f240f0484720e268f08fb19a35b48481192d56cea354cdade638f090769410659706b660bd7d2831544d06f7ab99ba58e8301544426f345571c39366d420fde95da95210d4e1201ac76b987594253b8a026ca7983ec54ffa7fe1e28aceda66bae4c239cfebad4228802d6a445a1aae432b2c2cfc203d59ba2ac771a31c00c09e84f66b8b1ba4fef1780bbde37b9145d36b9e20c013a9ea0b1663cd9e27cf2298b0c97b024a5f456c500261e3fb73d72c5747cf0bfab168d0b86af86a554cff342966fa5246f810fd0301505b26cead8f37024e8c6fe6affabba731d4211afe60b6831f2ceeee91baf42a0a657358a98cf640f4eabdb3cdb38e37e45e6420086fc74e6a0b7c049c807f4050248f3cd11e2905119288950c2d5817c1677c8af8b015e1f351841f938bff6b7f702c8c391555b99dfacf06b19ef48c67f9d07a701f6a83ea0fcda3205235b0cfe8202f735266cfd4753bf0868b2fb77d29b640731fbe17f366b43f56cfa7cdf8c87d47dbdc9ff7154b9ab83618bfc80970b8f49a946c85688965923f7da71649d15176882ce3be480a20ed60960549c04fe806646b5eb7dfb9cf95742f7bdcf91bddaac1dcf48291fb62ecb5a15303dd6ce6c21ea72bef3f683df0df65ff43e0b5da22b0555fbb0e7093ac81df61b4d0c7de6f4f98dbdfadc2a82085e0e6dca0e3979bfb16e562d76e7616305b60d3dfdb70c14d9a1ff16a729cd7400846432279f68e97c7c7bfdd362cb901153e51dd56baa81ef7159738c19452ca6bed8546d9ab03cc12bc2ab252149eef44e3551c81be3f0a446e8a00d84d210cc31abc6b750172010c6b7af7d40ac2512c655285043a888e7115b46a0eb9c4913d75e86cfa17e617272107598da589b774036cac697192c6f9e54fe53ecd1c4ed1c3d3348ecccb0340582ece994cfa7544e5cbaa41051ee4ccb5d6d762e812b7d5cf8b7e76d6300ba211c48265521fdab33cd858dabc97167a0bdb78f26637740407398b7fcb78b9d435bcafb3b379fe3e5411036f48703ec672e34b8e85ea1e163f8fdeb146610cd93620ccfbfc85ae4bfdfd1ecdddc5f3c8e0fc5630ec43bfbf6708028696dfa94200db11cbdfae810e3d55ca1f855a1d9b98377b54aeaed3156391614ff1415146cae45c3f4c0e3f377f90d7e60c28c34e958c66ac091a66494a9cb1dcedfa5cb6eaa38f062664f113c3491e28606088d11e446a8cc41070298927be4c68a85cae340ee34af8e008bd1e2516534aaa3883a6f986ca290ce83bd717eaddf95888e66455619cdacc38912ffd9a44b0b072709705ff5c70ddc556f31d9e6c2b99e59bfe0272a336ec7914da06f957f27c378a6c563acf94ef5a91fa747893f2383b1ab848778abce8dc0a2b42172a7fb91d3cd8312aa98d155b5d9f13be2e5545b3d9bb3050c2447aa007575ff9aec56517c977752a13b199d82e299b253e708a21c1dd27d6659c7d1a724642b142c013122f6dde657cec6db586553b72935463668fad9ae186996ef38fdf6fde5aa8c4a7f073521f3cc2bbd9e33c4928a6a4726ce3a560659a41293701dc275c39eec03d57a359ea48ebede800e9208f4dbfb377293efad76fd92a7e6dedf8a530149879a8e50627059046c0c90e886e1790d5354e48fd8dc621596c55063784bb35c34ad25eaa8cb23a361091d4971ef7bad1cd83e23d9e40ffeb5a70bd0eeab408b4a427f6304b2ce806fdb8ed7b7e8c2102f66bda076abba771cdba1d0f5d7d456779ce8bef20929972e7417e6579a74d50245e5cbed2f04bfc519ec77c6234fb8c257515e29d1edb96ba6e551487d36a0cded60da9fa7a843f62599a1f6114afbe43b72ded08043b37e4dcef5a7802de1596ab457049a003aec15d0fa943aa0578db81492775c046217a204204ade6b158bc7c4b7bc33e771e49b9ceb385f3b6d11acd8d1c209d4b571b90174231bdbf9e4aff370b46a1e80398d19fb0399980852005063035090e408d1296d28e85dc58e90c7b68196b54faed1a22c5cc356e99822825049239b3002b946218e67841c61cb008e59c891481218da34708d17d6896fce941b7b3084a481c226827fdfe19e4c7455a6a2cedf205affaa821833b63855eb5964b074d4b475196abf9c592d54bd98cbff0d925fb36333b5e7d4fc87ba654cee389c47ac9cdf1673898e71ec8b23520386b0b0f6f9b807204d85d772383ab5d24526d6c57c87c5e2d566b58fc8f8058b38064153ab6c3a50f5f06ea4764ab9d606f6377e7a2c7412efecb71a4cb634cce3a63bf5359e8814ed77ddc6b4a40fc204d9af66876d06ecd2e40f9366c1185eaf88108b40b6f0f57f5ae175f5d46beb5036134f474cafbe8f4ef2260df5ba2da17bacd1acbbcd64ddc03746ba3e928cd0afcfa2939a8d6f11924528922d9f10ef8a312f69d8dabd8cc20de9b7fe58aaea75af2de6dc862940564c61c19754187341caa90ec381760e1c4810d8e771335ea5cb1a5c5e8e558af3069660d79e1ad66e30ac224cfab91a1bad9a4e9ea244b7aa1544ab11d44a25787bf9532f5c319e6e34f803929fa09cac811af9740548b28ed6dc4cdfac9616072f317cb0dbe1118488ab770d8576f090e58f5dfb6288f42afdfda46ed59277f7e06823e5ea03e2d414a79f454d86db3e322e1350ea893dec7099b1ecf696a4a3fb89d359fe29ab620529dc6a7dc5d632b696de9f333f506f84bca9fd7f66c936398123c12073a51e335ef3a0bf6b80055a551bd036177b7838aa07680e7f92556853232ef151caad7d7b09b9c7dc04925a835e1a4683cac902eeea199831cc929753e8c3f00114ed86bfa35e9ee4371be2bf58d159b93fbb24933a7815bb02712340282141d259a2deb9a1788ddfe75b85568bebf1452dbc3ee892c8d824cf01005c143a6cea5ccdd9a8c70e9e1b8e832bde53a109fd498af345eebeea6e5334e304cb584370ae3417a4a465ef262bbd64c2e5f6696a59991b4e9bb50a7381be46d0adc35e67276e1bcf3d34b781f788bdc0e3f6f5f21c246246eeeb28ffe8e57dd2fd09088bb2771e9c39b56726b036ee0f8fad7fa03ab203db69d4cc332b60d74e967f245f20b3d53774b795ce491603ef7af90021219ab199480c9edcafce4ff364a1e88f97350299bca866791bf4a61fa014d7d2dee73f62d8a4dd890abc2b6e781f946316a65aaa83dd774b942ff8badc448d7cfa5e9bbcd6d30af77496d69fb684e6c5a06e8e90815da8943277b2b9c05d112e3b70393cb8e0980edbfe6bd772feadb2ad553ac867b595959b3f078d0e89183854b41b4770db8a79649c5e4340bb205fb32822d4115434459be3101fb6ca248d6254149a414e482b6f602931c9e3a8ad09bd5db8def3c766799423d12e9d3af353b1861f9dccc899694c256e7eb2403edcd4c3b1dbac2a5677b44ce17dcd2995d8223608a7b6ea41bade82b2b195675775f2610ebce08eb81bc4ea253467a9f76e2701555266147b79f031ac9418b8b60433299bb850f4e463b446136b33fb58fc684de519142b477e32d11c3a41041edba421c1620f43a6813020d1d33cda7df23d2a8c24b7bd7772149b8bcb3fb28e53c0195696a648c0a7272ccdc2c78b3b0bd52b61dace9f79755df413efcfbb1ff1d5491b5010dd2dc6241c7c9b541ad5cb251b0e8e0c432de389aed2db2d339a84afc67594e460dda83c019fee3e1eb85591d0f036a09addb34b852a7bf79c21e5592fe0cdf1c2420e73293a2832b2ac6e734834cdfaada0265071f96aee6b10662747f79a4f96f51c8a6049afcc43da5b766dea3c42378dd4994817ad9ba561fbea39dc16f8f2766bc8f4532ceef2fb54e879c403e6083b757a6c6055a22c035cdb49ecba97c448263dcc33f509c5c0cbc2e65430b8f32779ba737bd292d77fb5797989090b7e126f67c321f23d671d5b80911e32ca2cdb23bc79596c9b33e5c2941eeb7b7931687f94a159b72a93142774147ddbc71f6ae38ff359bacfebd6aa33676c46703790243089ffc240a7649d4e36216948e3e9ddbb71541b022b640f90253064f0f27276cb93193b54466fe1df047752677dc29364f4bd97793a6735752f97750206c10f60316b3f8d9b9466412e997247ce9d9bc0e8754ef754110736052404af720c7f1fdd7017150160b35b6a2640b906d58475de9060c4b7bc314722e967369ac9a34cda947e542d7921a81a8d5083934e92af91841256e9b82930ca87ee8640c7ae66c5a3c3fdab86dcda30e079976d22a3cf56f9c156559828b8f7334bab35b654f018f331dca72dbbde50541b951d543284d49d3b96f1f2da217632c5e3660283d27904a56e4c83b4cac7675134b8745cdefa91c16905e16d958b0dcb29b5d52020ed7de8cab9dd8ddbe2cc6c44ed652193041e66b8ad5b86c6de0b905daaf17ff243ef2b21991da5b8a18c47f5835c405b13017d9a23fbf126c53bb2777a6d6681715da504698dbdb9d35500a9a11a4d1a41e1890c5aa928f33268c21d8f46a51abdc740aa3923f6b6e1b689af06a5cd1b983ab6111d9f89197e96accd56b7923fdcabc93f044a05902afbe293e4e17bceea5769574fc49020f2ada228b29f86e86439101eec7d551a882c8260d2798a5464341fc08b03f2a1e8d1420b00aeb0629742061b9f53ca9aafe67f06fd0e596b2f47f6197de46646ab70adbd7b200b375934a19280eb3be89c573b2b44ec0c4239f54bb158f23c06b65dd3c5c5d16754e0bc66e647409c38bad393e301cb6c511d3d4194c815b6ee562e0b3e5b1eb54782aa91a9b5957e61c9bbf37f51605e858549b4f1858455860c5ebf685d8f1c864f881e4b7e4b73cf866beeff7232c6d5c08c9b89ec81a9b0337545f8115c4fe44dd6f6147e6cb7788f7e3c1feba373da09f42d731522c32785653d33ff195bfd89f0c06892919b3a90b2ba324d0cadae87dc7d2f795e9a33abd500cdb3ed36975add5b149376a0888e6995023bb5fa7fcbfe83556309b452a436aee6e7d7da5242f03c43630c3bff362adec8ec4974e330567e81311d2732d20ec8e01c497b5fc6ac43f50208e9e11094e2b44a07dbb975e43f0eb0dcf8e9ae67391d3770db07f06166c585915d12f618a50f2c952ca38edf636caa511bdc0e70cf567fd7ab6d1280e5650f6dd4fb2e9951a012d5e2fa22a90e7e0d29637d00a0226cb13c1a90c6a7989063d314c91a4da4c65ac011231320ad2fc335fe7b728c139e58682a8aa4d296c0257234e89a8e6890ef8d982c244fb8f7b391167fa3bd52cd13704de96aab9589f7ce03532fa1b23618fd29d5d96a7ec7c43f2db64562ec1213e364f50a021c954c24f64b84332b38aff3d5bf23a2be97d23f7740a072d0e248993143a9d28afb08a577eabced00f638d953ddecd6bc8c54deae66d5d9d61f3ba20c15961270ac5e331437306200e89a2c1ba8b4748280d8092488258e7a006d2e5c47a83e02b71655ad8dc8ce9d7ae0302ca9ce3ad281fc83f71efb0f38afc85f9a02c024ea521b09aa7cb9fa6ec18b352d069adb122513b6a5c976004fa08ac546aaacad730c128bb2233b504640eb977697238304a8867e07ad5452827ce5c57f688d69f8b637231bbba36b435b4c2eb54122e20a256b316fe0b9f09ba49c6e890f1c125b3b0a54055fadf566b4116bda77d1c1f54f6179470dbc0f18a750471e97b4df70e1f7c8d65ddc7724ecde9cd8d540ecec35ea698f3234ae9cf110fbbcd70ae1e8c085abea9b8eecc97783ea2e645e696d4d62c47a714fea6c527ce28b679ab060070899611feea7a2dbea36a5e5cb0db1cc0d1954377b0b1a80063c510ef3435f8ab3c0611712212a0d3dc09efef11a5c9b2b6427913b993a6429e5dfa64530c7a064292300ac582663714d24541cbafa772c2ecfd224650ec4149d7f095af599fb9abe4ed606a3c9a01fd6fdfb8a39152dad05d896a3aa98b9b6be9484de85057d8f0a9fd38382f0a1b18ab6fe8e5feb15248b2852d4bcc5381d228f3fb833720ba581518d3ed51b7a7cbe1f1c883de8c0deaa92f34c54c14dccb5a333f84fb444fd93d9219be03045ea966a61a6fa74690c9dedfeea1ae26cc89c1e2352f9af665672f5c7ed01f12b6ae5a71563b2416fc1498d604aa8bfbefd0210eb2fa619d365dc507c15ff8a80e63e106902633f6625cb7f3a16aae1f77c8aa40d1dbe2f239219e19b2e238754b267c5c32b410592fd969ec8638dcc6c878f681999709a177ebfc6380a1edb6d88b18a8aad25cf4c1afca087d2c7297af4135394ebefb8d48785f045e894039845f0403969c4de08195ba4a280e664caa381bd709d7c9eec0f1bfe41f1569f31c57f98e3a51a1edc09c08334f181dfb582cb2c3abbf497508112620ec29490991316dce02458f3721ae0d09ac121586d5f3a83432bfd77c5487cc4cd6879f7de8737f10ca55ad7660dc66cb1060500cf5e9c0af985918520d774c51dbf55b310928707cde6b80ed4c2d5280ce9427bc3ce0778bf9286567bc07b784fe362188192180b0c726f73981741cae69be102d6fa51ded9d1d07d8f1c6ccf34e1e8041d3285d7a2e1ffab2fd909b96cad746c8c9583cbd611f00e4ed72c2d9b11db8c8f8a185b507299d124f35e17047e759729e284ca3f5c0706c7a4aea95cb944c0279106b33fb36c559a9cebb9011ec6532821684fcca72e59f709d986f69a8bce0c1567e8a2c3c239bd6f4688babbb14301ba31653cc4665540195d04a7b97adb80a8301807a2f71f3b296586ed84259dbecb51543e2d47814a6163f25c4250694560c0f6bd13a0d14137949bd3942aabee89af46cd1b044fae3eb930a1bfce61e7c0612211d38ec068089a90c4e8409c4a0ec5aad74c259357d9f6da5777d6d210cdf9fb64ab98f6efaeace77f23a73a5c5a333680c69e87460f55b1bec27fbc0173c3a491c1b82fa62a90399d7154a4540e96a7054dc34e6413ceb9e294344f2acefc9107306f49da2204f3ea2d3a38f8e9ff0a88eb2807a00c2c0b9e01cd1a95bcc825572be38f33c77fc2e9b82af06e15c3b5fbc0c4c343e50dafd03180f1975357ed2d1eedf46a947a2a4209051ed388a54477abcb3a4a36808e4e3aa725822689f861e2deba71abdcabc30af4fe2e644b11f8eb3dba80cf7b3fbf9eb7f5d378c42397cde37b33f4029548b6dbe0e9c0c87dc3bf8d516fd20b510be907bd560ba1e60f4e36a8ac3d5b34218ceac208dd732706030a712d38de4857358e94ea547688de11de94de4247fc9e50018e1d93f53e29b360673089e92c250453f0ff13e6e117ce94250076ca5e4efcb5c9f30a6fc123f470ece1f640ba2bd4cebdc6856e6e9d0a2a4d51c48f12fafef263ea83dd64fd575692ce6caf6536120393b349436cf782839950db0366b2f935f509e45ced95961f6537c461daed9f8c1d1ccfca06965ce7b578a8fca69166d700e7c5b8646b9f6cd92d88856ecb9bc70559e86dce5f8d1db1707d3cfcbff2bb7b49b189aea939f994061ae816d5016989eb581451798fb22dce881832df99e472ed1b22339b5c4d3a2f7e904702d03ac3685ab7a8d354610e846c07074af671040f9aa72f533f064a27118cb01a46817dc3997988c4a18ae0e0ead047ad1e32825f0e6393951bab272e41d94bbc47f4657b8fb65c1bed5c6cf73cbf3479c0bfcc5196af8bc3b99fb18dfdde33f2c438cf00c29e0a3481010f7348aee0894d1cd0223956ad0ad94fc70469af646c66ad124f1f7f8f98e7d49fb16df47c538e2c08e1264f4e404edddfa5cbdd5efb24b8f39164bdee556930951e1ae491608eeec5dd8a644cab8f60cb51a3ba144d1189b2a4778da5a7890888ff7d67f41195feb8ac09071403687776963000a253b3d29adfc97ab7ba383fff162b0e612b4e2c8f29e9249b7da9aa24c45a051ad1a860a7b440a0e32e579920d68c4220f7415caf8171043b87390baf3faba39fdd606567b6be277d6d2225ead573ac7b662d8f8350d2accd5efaedf0a3892379e9c33752a908c4e8353c83350c3e9901fe74bfa688d776ff6022a5212451fc40883182f03a97ffc776fff4cd9255837c86e90fbf58070b77c5ef94c8c7be4d610722aaca275ee4b9d099f2516706dd3d2e4dd1b790c35a703909fabb2c0d4e405bfee8d795e0a4cc7e64f5adc7a63d5164b195dd2eb96f64dc501916dfb83db3c7cc6583e4ba71e1c042a9fd7e749279c282ed1667f93de0921052cbb7f540f0b3cebba625084b8fafb1cbe43a377efa6e9d423dfe1ec135b5989ce33b5a35454a337e3ab1a2894f531ffd41b758fa33ed4d81da600084666b7d308928d39d57a4fc5f19959928e2b03473eca7f85e8ac4813ae0084067d9777a015715f5bd52a5e6bdeb47d89c194a01037ecbfd749c81dc6f3882b2b146770fc2c6f4696bd3367de7a344d6b2cff7087159176bf8daf3f19b39304b7e1158eb406b05bc032a3102ca08ef31b0c76c7537b60e8617ecfe1cca51127c3000d092bb871f520f027cf9e3ecc7c309bec05243c83566866b8463eaba69ee315c97011a1faad7fe85634d8a02e98c60148e0290cbc5f129bf4a4fb125ee7f73c0a1543d799cf9b78f507d0a2d243b40c574dad05cbb562a5265c7e9b222c49a66619b736447f0804bacdd141456051e51d00752c417a1e43e963b81632b0d2f55d63814f441cb13f7b4de940618773c8e8793a46ad675042bf70a1a855826f35c3ca70b87f294b21b0f7f8fe518ff659654cd88a644ba0122bb7310da8292d7e248a5b6333f2bf518e185230d8c0eb552c0863c912cecd8c0b09e5dd12755956d655dca984ff8f58f27a09abfe2dbd04228149e4bb651dcb3e5c20995177c4e041db0e5987f05cf5373241f8589357630789f4beecf54990c575ee19e44d102cbe196e9b216598534bcbba914e5b9a9db58746d31183641842e627e632ae64b68ea00bf1028b28c72692b0080e7bfdf75ebe1ad250d982afb13e0eff041ae6dea39bd81c73dff596ae04e29ab13e510524e722e32a372b94b160c62ec1874dbc6f6b78dc6060c3ee2f621c8bbfedea0307578eb17529944596d52dc9cf3ce36a23489f1f6ac8e9f875640c87277067d226467554a246446ecc26839c062f167504a18f84bc277aa36c614456cd8e0f3ae3950793b9d0338b756b275b999be099882319d49996d670bccab251c316d07a258291731841c8d4934f5e24f518e625872d38a50f60de3cf9208164a18666c6446c01e07109a3b0c069a260c15fe25c92ac258f35cce04beadd571084fe6cd7b69ff6e3060a69543e3c3487b3624989bdcfafd05946e9358c2e1ed74ecee9559bdc96999ef308348d3d30b3b4bed56618d2ab85265575fbf57cf04e9727ebd4047b619e820f7392f794cbae73820f1a4dddb39beef22cfaa43e0bea8b69edeacac9f1ec94963f97e847037729dc41087632b491a497abf2cce87d3c8bfc1e1839ed3ca39aa07c38bdd0a716082ed14b4215107785393c572f2681b960944a5bd236976dd64033ef413be6096e44535e5f80f82388353d12094201cafafa91b5376c85949a3887b43b3230f11019f070f5ac8721f5ee403a431d2335d61303392077d836519df7e9ef24f934e1cb280f3317024d29086fe92be30717e9efba8d6eb07c41fd3a6dea96187de1d2ffdb63b04d48f67772b11a6cb34481ef41f990599e1e86752375526784a3c1f4d97b331c1fe66e325978ac95fcadee4000884a771d48dc3ce951a2c9e2f40eee6419948a0941d2743a3c5fb951c0a6770d012693dda2aa872fb47f22567cae362b4828dba8a8347fdcaf136574553e7c3b6794d13d19d2244139fb9732c6ddced4d823e4cf055d3d8c1f73915e837a6e0149255ca89dfbc9ba0e2bd03714a494b0877276524de61b26bac8cd51f55880bcce5289638aa7ec1bf01ff981c5a02bf6268aae8de093187c876595bdddbe1d85efae6bf8f0d6bdb8f1ca6a04489516d637c497ff04eb10b98231b11ae7b841709efb0c84fcfb9b45b50f9090bf4330d72adac441dcbeba3a05922cfa9661cda0c0213044a8f76f71e401800d733fc496316faa2ed4300e38e5d06aba03c22a60e319e59433fc794cf41555549896b7375cfed93906240286b97a608db0049c46d159d1af37c8bcde7f21d3595ad168f9e0e1a4808d3594d66b7abc82f1a6b26a1020d41c3c514e0f74c90e6e8f90923f97b1d1c68e2d5014b4c39e1f141481afe00ef0d661d9e7b7b406a05b27cf1c199b21cc989ecc0f11283d59dbefa13b3b3e42f316cb65b9fe685b3990a502e998c208bcda8bb6e2b005bb3f41b0fdc981949b0333280dd8154f4a58055e287ce4692ce17f75fe4e4363a687768368ff79d60856a1426546d91d501cb68528ad4bdba7c444cdd66926da18092a8eb2ab989029a03e8294bd288b07716737a010385f3788777be8fcc15a8a003f27eb855f7807b78948ee62546c22e2a9d9e986e011e942969c9561c6d3bed28b5f1ea2ed708af3a4b9d8442527d683f2af2ff0f19f5cdddd23702dac08cd3604ce8850c24134eaa883cb39a9d6f3eb2e0975201c806f7c8b237abad30f6261704960b0c859ad26d696e5ea9ec129890ae7b90110902c4ed91aa29563ee9b07e73534f2a48e1a48881cef1bf1a597006b778cb1861f364749880806355d95898cf1a622e5d323452b576741db3cd4ea3c3502fab211755a686cac6ed4479c67636b331c81e84072f6c510e9f42cd50bdf80c1bcb5fbe3a7bb1715afbf89443c08bbb2680588ae67a442e16d4677e345b0509a61d30e5f93414f4b535ecf4797f4ac1b9f2c66d13963eb36bd789c6fc90e79c9021e057df0b6a28c2febef82ca6247a6fac2ef981f2cb13e4ebd5273ff0155a173c85b7525a0401d00a5294f11e295b9d9230c20aee4cc8e17135e5a6484eb43a9a2dff0e9a776ca3bbc0116b24a1230e20a21ad442c2c0e9cf23227d9c74a87485e223d01bcebb5584eccd173f572f00c03187bf0b3a6f01da929040165ddf2da37cc04baab1ab65dea89e4ec45d18c78f6feecb33be606e3c724d914ebb81d9b2e4b21657a0c2d80e0ce3d66f9b5e2a090804a17c487107aac548c011379e2c14fa63c08dc42f95d673da6fbb601f56764bc54741ae4c99a753df9e472768ddac6e05de8de89a6450eacfd96b1f86658e733f5f9c3fb0a48babc6a474b17d518101cacc59e42dd0d22eb29fb9c9f281861dc9e38d2162b2ddad5af5a4b0882f7fb78bc431ad08eece35fa3d6fdb82b01630edd437613fd7200ffd262fa3c30daa5d9eb6746d421cf00b4633a3d869f33794a0144f0dd84a1dff5c0622ca345b0a2938040e70be33ed44c4f43c4addbe087942343fb326450946880b253a96e9691cc2dc6f1d67164887f36be09464cf65b571c123880b400fb6992b533e1f54f939da2f00d4ef68da75ad8f13d4b132e72ecf97752d3a6a46dfe7a1a17e533c0554fbd4296fed20664789062779a328ac65173ec7ded581d4710fda8d2aaf6e8a4a3f302722859caeeccf30f93218352641c32ba67dffd90838e36a735fe319b9b3237a9d3a1aaa332131db6ebc98e051d02d9593e1fd831a457465f2f01c7ff18f0f4819a6527c270fb83a6bcb0478e1bf2287dc1c43c61cf8bc241afd41841373e564d81f1c4ba420a6e71b068bfa6c501ed4d9e9d2be32e6821248821afb7a41a9f9152254ecb53c15cb2b453db2624ea39c534318f8d82227046c4c221d8c3c72ef47928ac3574f1df75d8b9e706df6d71208cb1f1e2b02daf03b5c40d0bcecaedd01961f1c529c76e87eda4361f14790ab7394804094ffe72a12f43514761fb8626b6efa2038d208beae9b3741e2f7f89199ce19521beaf5dfab65cd1a996d9235cb0c2d1a317270c3066a5a7e10c5c07a8517de954dad4dd801eda0c56201bdb05d5dd2ab9d5c714dd2c681ad80cde51ce503056defda8916a91b6223312fce40a2efdfa673af7153d26dd00d0f8f9548d864718e37ae77792f0b2f1ebd15536e2eab78611f5731947debe7f2865bbc12ed2df4c6b979a6eec953cafded230dcee32757228e93b7464ff4d70ce26dbe9f36f063584a5bfe611eac3aada03446a496d66353b62da3732b94e999699e123f04cdc52e7435e27f531422ecac8f975e050e04e402a8b044d5c138d43bdbc529c2bd33cc5d289dec0267a15834e25f8186fff7ff7b28b666d89a9c147e91ff11954bd7ad58dd0a9b64d8d62cef3b1338c793fefef81864607cefbf42345e1929170aecf64d76429d8b9c5d46d4f810b44177c9b49ce51084118516150c6eee2313f668ddaa7bc95ce7427cb7876282ad0e5dd8c7ea32272866dace65fbfd784964de578b9ad3a4cfad36202f0c4a9e21a20817764b4f8d51716c1a53da492be3eeec89308c0f282c9dda08d451b0bec08925414d7de85baf1a25b2df1e064841b8e3b1a54bbbbd28ac2a472ca53b3a562de916208b2e5fd4e266b4e5c871303538ded890008d06eadbb72eee48acd9202c8d842c6b8058f2869182b352f1eda0744a70a84206643f81f3a3ff88cd8fa20c673f2d556cb5bc4c2f8b73cab62f5e95b1c86115eafb0798ec26b69b9143556c28d601d3df060a7f66d7a04f86d643bcb5b2203461b45468c410d0d8ac00a4dfb7f152fe19b7249e96f7e95f26b3171de6dcbd60f948ecb02940eaf5ef7b0f174a4c9c6369aa5acddbdcfcfc7d10dbbd2bb2a37ec89f0a3678f0e13afbba2e93d6ca70262c61be1984cddba702a9b03249ba78f10e42238147473d46c4d83f6267e3b9465feb61709cceafd55b2e40d0f7f6dec8872bc3ce5d76bd95c74bca04acd83553fd8ef3de43c7ab75c563b92b4d1d4574ff1bfc30ca7cff34990827a415544dc3aee8dd4fa829fdc73a90e417be10d0f3b4940dfeaa1b63e342124a549632774e1f8b4ea8551ca0c5db23af8f9d4904b1c856fb1af5b1765e6e10c50f501cec51251ba43065460c4c28c62c6e78c608020d05908569069e923f62f4df9968c5e8cc85ddd1a24b3dfa5bcfda1c63f5c6a5586bcb442edb8477aed80beb98f41199bbbc651faf831da597952b2dcf9827fdcfd7ab73501c12d48290cfa42d54a9feeec882aac8be93cefb68b7df376f08ca181245c161f80f20aa18ed333545a7112d80bd13f7288117ba293e2dbdb89af2a360e95bf9104cf752a5ac0332af003fe04c415958454fd420ae8af4a590a891295c916a1b5ca1575fc907f8ab95b1f3475dbc483f4c4633817c248f7faf20f3e0179497d771d10f982113a7384c0da912e5208c14b3b1b747a43db2bc08f902eb9f0e8ac70ff416041e8f34b463ba0d63ae6e80d7835f3befc3e70f9df6c5384c82313ea953d482c3dc26e75f8e73f6b993b44f20b829b8a60cba964175088d874e762dee989a97e071d36bd3fe1054644594db29ad2dad2daf6cc9e98ce72f6b777246fbff8423431322d63dcc6746b32230ddab0e24699c3e729e81f630689f5683f987144eeba2c4767b615dd1027faa69ec220499be0218e66f0c7b9c97fc10716c60c47ddf165d4dee1157e93dd49568d1f930b9a86d02f7b30ef4fc98ae9fdcf2b0e38a40b6f10741c5ec1303c6d324e178b4d502328f6b4702413f29466fc7774d3a64a0770b39caec7e594e37a6a10f925e3a000c50da50d4fd56b24327b2ad8d9ba29aeb4cc5ada1cac2850c0cfbae38774dc3ba2e27f2ed71abc582da19b0bc57a6281241a548895f81ed1180a2b24499a02b67bea809269ac68b0830db4fb8be4bfcc87e278142f189c71069a48e3924e8ab44e32d2f8eef816b59591175c426a1ef5c7959bc219f895a80640512324fb81b8732cdcdde03ff0a6af260ea81f5379f7badac712b9822bd66f749473fd7b863f3cf1f04d8bb9607e471c0751eac01fc8c93bfeb3325c38b5dd370977fa1633fcc790722693b779ca576136e7423e4e5979bfd8e14905f9b5357af7693cc4d8c5a84bc0649ee9241f3814513b77f950bd3728d2377e543349a1a90d78e282350b331bf9de827780a6d63674993168a8d8a1fa759cda1e6c0afe0be05e14cda543f5256fae8c1dbedfddd1e5ad8662a35f9baaf8858965084f64d6fde2d48008c0d949c02a1e01bfac4ef2d96d83e45c4e72dc00ee043db90d055f918a1c0dae749391fd432e898f19629229829e56380ccdc208b49bcdb6606383ba481bc4be2187af221d0f8579148dd66dd68041bf92e3ff078df9c5df6164129ac31e21238169b163410e2a98163a1523cf3cc1cecfbd5ca7684ab88025e11abc05fe8c52ff68441efff3714e54d9e0417a1425c5f4f1d0e0dfa1868863ca918fec1f5a8e0b21f0ae749fb9295f85c25a4e289d8c0ac32d291f36e0e40ac6d92a227b2b70b8435fecb064531b84263e9dcbf45cdef9cb147f8a87608772e51b4ba2d86978e4102291c858de0eb0a51068d2dbf2ec3298bb593906f83b36484a9ef0019b156abc13a7cf84f7b36199315d609bbca4820beacbf30395b560809ea6acb24e546da890080cee950df19042d6f58acf0d3d0bfb51f02a8e54f76205ff34e670aa75199fc8b4e9765864d8f5601b51f3dc06c9734b322ac4bb5fc4f7059f3ed147169201209b4ea02cf358b5b0ddd6c9890096325e581a5db36dc3225a00ca4be484d58efbb25e3fe537e96e916f0cfca18b8b48bb3f6d9e9243bde52698027d1ae1c050722cca64043a77b68a9b0221b1e02a1eae592186e858d433861679045e6db6f68d3c3dac81a0eb4cf1033329bfb294e4d0d823857c6bc88770f11fb0d1004a410fcd26a5411acb8d85a0c3c188d3ed77c13f7c65c0afb93429da02d6b082c766a46165b91b8a44573e68cd4617bbe673528cd09399890af88c50ff54bfebdcfeda611a7cc5f48f0a67a66ffa9e812e8d9c110309ee9c8a11c9694317b00abb81279ec2f5dd5f52c0f17ea50b92253da2d62318daac6fce4f183302fd9241c03c4cf599d8689bc6afa7257b6e445ed97879daf3ea4fc54cbe441b39838a4449747d1f6c1b5263aa19e4288007888b795549a9f8f68def34ec583a3f88e1c0b9a9b5204a6caab1af4e0207024276fbc31a015e9c86d723dd032d5a57f4064823ab5afedc2e461fb8bbd78402ad3b9d9cbc01afb755b63aa9b0685fc540a24d669d3279fed66609863606aa934fbf0ff767a5586dcbf9e5c0f947ca68d524e36989ed2fd504ad21a3164b7a61bb64a2e761cd81d3524fa7c41915d1620cfa5f9c583be3e1ac14c0c82635c755b954e9ab017a25d35d275b8848051fa154620b5e9db540a9baf6f034b0eed0d88a423a41da50d769467bff952541dcddf5d8fa8b4b4f97fa4634fa1118712eae5c2fcbd9d6762ad60f909f087e4ecf7a97a1d2e885e720ca8bbecb04500277ce1ae37882d034de86b3e6870377889b4a82e83b29b05438b6b2a3811403da177744347832ed885bdb25cbe37ee9d092a2fd0df58e064fb42969ff20c39e915fb4af981a28d032350d3c23f8259a5d7bcdb7544f7d6a815bb0f822e720cf6087d0dc5627b4d2f01d074ef50d6fb5f17794bfd07c446bfa367376aa44b801eb7e30bc5107fccc546c16c52b06e76c4830ab2f8daba95bb0f3a6a5991c267608b0e37a66099e2dc6f24f75b9fb4b3edb65d3a4d9850d487323da40e7cf87da2a7580f0b7da764eb92b9a3053e7e55f0d6f45ceb0333e8050ea6f8b7954bc22075fd3b619a6b09594a0be2aa94da2fadc9cf8e86bd4845a1ae32e571d589e4f59b3edcbcb106dadd32c21c8c476261b7396c924317ed821f4b414d83777a4a5d0db38fdafe99febdf68376631289ba334bf7da9d19ad3999e41348da8bc95b294beaef0e933914029e5e7b8f1ec3086f0dd1f8303f8f6620bbd6c5bae29356e61a1b2b8c8f368547373f4205c3c989baa78e1191da15c4e48c5e98b0d94164613c248516aad49b172d6d0e7afe12d81358cfc0359719e12fb76f36c9629419071511329e0fb9fe544cbec302eb6b7f73fa226f7fd7c662cd248e8cc46a3bd640b9c9677a77947f545cc44a054192a1f7641729f9eed9e9188abe61fabc1e8aa984dfd779d6b0b93f78a089d8187634315aaffabb80e19a1cb8cd15d160937ec91c1097ebf119a296b07485eaf9885760f5deb6a389f534b2679322156b7444a4e8bb34f4ec203156495336766009bec24c2b26acae5894f30025b7a9d28d344f23e274e36071e125121471b585dd1bf65f6b19acec147a948be300cc42b07460aa6bb1a29233fd085fdfe7e15a442c1e6f1af8c9739c54709b70683649e7363fd6bd9d00bbe7846c948ea9eb072eee4fac07a2efee6d7392062ed28643e6c56ee1d021277f08921fe59ee61e07ccf28e5d87a7a6aa514a69196669e600fddc0d51f6da190ecb56a2387fc21b7cfddaa01d4f4f9b0cbb3bcba19fc57439af6aa4bfe9cd2da0fe1d6287f7558ba05adfcb2896e877daaa1635b56cff8e3071da2ce3adf307226a7e2c88f33cf485a9eecbf27b4e986ddfa67418534a8f116a93682f414dff1c458c4f1ba3f342a9228549bfd603078d07061da145dde4ee6021d76bd6df943e5c8ac0a761803387b46a5c166277d4e5a67698608a76045bf4cb81c821f9133a511efc687362d32435f0f2ea6e5cfb24dd2aa201439c7c5cf30782e1b5e16260679ef77bd7abd4b78f153ec69d2e054c520c5d5031809c781e1799705561ace4679dcf33875c334f8a62a9ea0a379c83dbc0dd8359174403e241f19d70abf4b7381810f63462d779543b8f37cb344bd28906139395e8d568fc3cc2a12c77caca902c0aa0a07fd001042182f0332b3812d65ceaeddcbe3f41cade320cc6f15fc245895c5c4f820372155a785f488e54f8d0453d1094448d61540bb8c629a5295156095b036b61c9d6f631fb65293ec16e46d69eec2b025b82b4daecaaef5999df5c99849f07537e31d2bf1d4b70dda3b7cd651b04a0c334e3f05b02dbf6a6868f26d6e9ce254c583653932a3979e58c023582e976cd8185e491d10a2a57d6504204ea005dd8599f3427fde2b688c9d06f6de7e9425b8976b21e9de305f600807b0c1b09148277741a9ab9b96618d03a1d457af7dd7bcfb1afbe8f0b4716a660c8e3b8b33332ddf043857b594fa841dcecd3ebb3bbc9ca310c541ed583bb94ee37875d405b12bd0453546cf0601569238791ec898521e3ef8de5b4156aef5502fddfba88b723561b5b791e024ce65dd3a888b6abaf6550e579a73a5f88537d6966ad4232f9606412c863239ca8f0a070df60b32739dde141fe1f14ac9fd402e0d1702fb1796712c54803fa4f979b12afd0b63bd8bef38813c0c651e0503f058d2a8120249337ba7b09e89e736d3b2ef11b87c117def03a1ce67709a756426e5afe91fec17929e4e8905a058a6131ee3ae14e58f63a81d6f18d54cf9aaf0028eda6c065ebbfe0eeea5b2b8d88da14046847a58c9f4825f82c9af4893184726824c867e0aba615b6344529319e11c3396a42d97705dd31555af7e05b40637c033025ae1d82230f3edda382c482c9adb4a91e42d7196dd463b48fbeecc895a6fe6429bd12002716aa10424645adebe512c6314cecef677cfe6c62d8c2d106d7ed5ce92dcd55e80a3c766f32d1b9b288a63cfdf868cb632914a464646252839312772694e9220bcd748f033830f82a25bc2f3b0e9d86fd78bf37b7beab07f55d0b425b0a9b9842b08de52828a3cbfca156f44c14e9fb6a45be40145b1d76c48ec1bef40d022d7875e76ea550376b8ab110f1d4c460a005ab40b49484cbc985aeb9e6418bbb67bf4b4c39e882ba91084de9662c2ded559e4ecd5126bacd38afe57c017f70ae984432ad57481ef9940e79950051c9bcf9691703fb67a984538563a820783eb0b51a95ebedca9893132a8268935ace2cc95380f02b8c155874007c2182b4a48b18cd622b998bb371e181f37d16b4ee5437ecd419c865900b549a14b9b3ae03399b324458ddd96a1e9d163c8532e19f64e778ac71d8c8ac6072396c5a5d9337704fd15ffb8407cb22b914033fe85382d04f9899b2d13091e03cc4cab0bf1e84f6767c0e29ecaea8f5e9d0cf07be7fc715eb8b1e44754edaa0ccc51c5cebbd29d1349658869b160eaa225f56af4f30f0e\"" - +pub const HEX_65536_CHARS: &str = "\"0x65536b37b273ac2f126b11185ef91c1cff07c9b5081fae332ef45c4e90dc0bad4868ee6713acc2eac2d7071fa5885f8b2a9988a07e01bc7de1ad0cb0f06a3467905a2e8723987bbc96c86ac4f1503479e1089d8d90cf4d836c4d12816a1a39dd8c379add349bc3f2f543a81051140483f61e81c3f18ff1c4049aee78e1c245846ec12f1b8392028c6a2e9e3fb110d20f0877110b2f266609a3d92f0cd8b59b7385cbd2e70417ee062ee356ca191f8c68aa68243f5ab62c5f4b237033c32ff7813405c8a4bea82f73380818dbd169cd1060f4f6791b96a402bc4dc83f6a6fde353e3a5de2e626706ae897b7da6b1e3522ed2f4b0f340378c70bfcaf10a7fc805d696822a76f4d8d2206a9a8aacc132dbe770ac870b9a406bde566ac665c942978e5edc1efada06bc13781315eea26f9977f58327a188a9051c6eaa00ca4e2e8e04f26f8dc2b589c399a6160c1345816f35e33b4a0db6d33322c3ccbf82cfc5c1b28be7da5d834d1720343c1bfd8b8964552bae373ed2a6b1b6f02766f679a2c9f1007610014cd71810e8117255b0a07e5e5e87711ac4713e13c6adc899350c4b35d9a22925bd46cf2cfe04fab2fee013e3560380de3b879b01a2e03347c784eba5b1f0367aa5a51cce5dd0cce8f983a1c0876887d679ca207faac11fff8e8a64c81ea02f0aa7ef2cbba80f75eb37a3975963b757f7fcc805adaf7611d729f1a47df9e85df5b2a2a8eed2b69d657a4513472ca6b6a44a1b695c8183dd178dcd621b2066ecccdc1fb88fea080735bb2edb104b88547ad6de9cea81a2afd04f245d1d15c92955648c248501a9b837ab549030860417f7ddff056eb73e90b1263923fd6e5ebba43ccd9f839817967df5c8a6b2b7fcdc62e4a55978c0baedb046059e4754aa043fc975d57c09ce6dcf56b1cdd24a85272faa1d821853f71b0bfbff2967f4b2dae326e4d990c3417f6c990559d25ff5b3d0b2573f49212bcf33d06fabd8a971f90060b396e178c6b52f55667958b1307460827b78884022187a85ea89cd2981f88365b5e2e66e0fb55926d7eed93edb19afdef4217f64a33d1c9318cc05cfe774e0f09428ec4a9dd38ac42a48751cefea3c9a8935ab04fdf7b24b834261def53839cb68a89cc61ebaab7047cca9d5727a86d79d5944737b0642e8770974cf2128c663d0133d9555cb4aa141e39dfc10c70e2fdfae954a7dfb39af8b7419909255d2d81fc069071fc29d1763c7579e729d87fd148a9bf26262a9332b2994a024adbb8f43ca76389fcead15a14ae24f005cfec16d4da950c8c1647b8e2357ab59be554f1faad237e492d6a5de11618817da26a611f122fe6c5f1ef9a826d3905ed4c8841f9f5e3431b994d1f4b62d10877c973aa1daf9614bbd55cdd865e36e25b9241c08e3b6627846113d6fdf4bdef35eacd48ca2d76959baa1484adb988262b38013926c388102bf0551c35616970f9d5fb1fded91a25e12f1f12afcce8295aea0ae7608163798af65025a84ef6e1f3d60a5d354d55e0fe408023894f68c2e523be63725b5cf33ace0828cf89a69ee428d073bca15014e7faa83014f1bbf6797ecb80bf75ae012fbd35b48f3d7e213d85c3ef991933021baaa7984e7c92073fcb720911ee736479e79eb55046d3ce4433b669c34e38c14b232402222788c3df8aeb42ee8b487c3cfe6eaece11d9b3aa681b143f9f360c7dc0f157d613c2b85ec407f6d85b1b1876c298c0ee50ecb9e0351738e6eac1e0e5749ab6a5f7aeb7fcb150af97b0c6b4b6df19dd0d06dd44764dfc10361e6217c8808b9b34b62311c5a93b4e6e0f7ef3ae52d4ca2689ffe94a04a4405442059bce9df2d919299f1bf75e74d5d51b963b19a0133e6904cc3c0310fb50a7c0c04c0e9a7d259c12c12cbf84dc72e3e460d74db9a2a3890d551b9451c84ec4a5e565c17692124a0ad25b47bad7cbf8c07ff8df7b40b3226309b783f939baeb02767c829bfe6bbf285b66b235b301372d8896521774d45d5c28ca6593b6f81f9aa9d1c74014fad0877f8134751210ecd6348555bb033d30a2d07a438b111c0ff0ebed28e22b81ddb4b9fc36cc4048afb3c876f62bba6f26b882cb2410d5f8e2895c35b90bd12010f424c64e53d33af47fe5657a2cd25e80b08e8a26274fdec89a6388dfe80bb6c48522115b6f0c78245e18b42a7f175ebf6816c4c45593a9f40dcbd881a1c9f8a9a010a886a319b6fe97e01347f6ebcb64d41687a08c869b0043c6cf684d11e75161c15f1037351c3b51f135c02935815fe9f5e382f4623a3e34ee42946e774c0717d6299a4c3720f26adcac65105771621ff851b47a1f2b96aa6a0d664021e398de908b83d64719da4dc9c6d20304d00c9fe89433f6a787abd9c282212a1c087781c40f5a615fa8a31affac834cd19e98e7b26c115e6f48f397f74e12d1b214ae427f13fad70b62e051d3fe4f90fafa426bd12321e17fa97bb0fd211401db77ebd2ad2bc5586f9a84ca02af969b1bc4c7229db28e02bd5ca60aa60d3ce159dac61bbfdc6dbe3b58cad672bb64a2cf8e30093d2be04b0f84be835aec191fdfa517d671b2bfadd7a76d45b0dc99ac383a53e324d734bee7738f093a6714437cb70a4d93af9dfe71b930158216a5e19e237276f9ba536b3cf0e063fe7101edffa5827b38b5cb74abbbbecc823ad1df97f8b638eba5a75ae875dbcb1077530c06e56ebd5df1956fb93f3a605b8c1b69fe0cdc42fc6ecdc0794057b1c6e756ad5f6f105727b21074ab582e430ce12fbc1b234b4fe9b5ded642378fea32006d6ca4c539e07163c7fec74848db5d164d4f4f2619aad89f246bba33e7cee1bb434c3c4baa73448226e4711e0a13b433dbea7b474248fea8fb3290c6ae92e42dc4a365e6562381bb1d7e903336c8cfef2863d383fbc0b45f015b0b831636724d6390efe15617333cdce3efb5d0c6c99a9b77ac6f6bce8008e85ad4c5cad08aa9232c312f5df1dd55bea468587a58b0a5d966e37f85acfe260b26016e2c2ff7a5f0fe8c296e3c9f21a69067fbb828dda563ae945ff5bcdcff950b53b1890c37add5ef49c3d77c51f046e7d39f1ce013ff1f95b1ea5c66b37e7a244605ac3e8a5d33c521d7286f6bc22b7fe4076d080d8e66f8921772887233e6c883c5705862d2e4894efe63f475460a10f66a19fe50ff82a2b3c03084515bbcd25aaaf506c9fd90c4eaa150a24fabd3331220d83a48961cf9c4e9da384959935f79d84a2218348d70d394b522ec0787e934aaa472633c75c98909d91576a322198980c06f0ea370573ff2c2e2daa3f71f0f8d92eaf202fdda79d56bcfbd5dcfa435f8300c25a179338bc0d85f9ac297d283aa763892fcfb96167ad6d803eedca540bf05d9980531c135e553bf5c27442e228c761863ff43950e66526a1805e0671afa5ff0eb021fdf175fff6a92841d639b7c88bf7195a8f32b43871a648048ec0fda674cf79239865eda8dfed6d74968400a53a647b66e5b00276d088d2dc91b57f20fafc5103ced1a56ec7f6bc8e56f8bbe42bbd034ed6aeeba802e3f8ae05426758bee5b0e583e34e4df9632b636b79b467c84618ce7aa026dcd7d1ecfc54a87e6bd6aa5c3d5159693fed90a6b59ed65e0bb6d4c4a2ba045fb539652e7df48386bc2ed72e5c29f8d7e8e45233992fd18c473a39cc04fc8cffe0d70cbc0f75fdc7daa1d9f4ed0434732051968cc6123a5ac63e49a8984aface0787dfd84dd5f16573034c95a6b10b980bca6868c903a8a6d4119acfd7c844c1bc5b6c86977e2de33440e4b31f472d6b7b58bf4394a079a529587d25f2ad0fa1bf22e196d859bb45b81788b5789384dad71b23d2a226d75e0679e1cfe9efb1c4d66463a42796877cfc9e5e2435b072d3f4453e23fdc6555d2cba5ebdcf4ad536b85d30286f3df49cb5972abad4019159adc68abfc34c04e46a5bdc182e622a08694db464760c5a4505021abe6b0dfe15c8eb5fa686fe0cf8a337dd14274884cafaffa3127ca9311de8cc04d19b0ac632ea8ba34c4308436cca4e25efe3796279f3e9da9f697448a9d4a0bcf4673f3e3e6a3d630d9ddae3b6a1ff95a545db4a5fad2f17bcc6c21be224b3a038e346d6e6db12ff12ccd6d573bba31807b31ae12056ad5b77cfc5047df67a48392389665ba2c1e28f9889b8448f0fb14c30ff2050ebca2546af586aeb5d83a785eaa54874521c5ac3daa5e9b365d620801e6384b6d72122dc72ede0ca03001af82d5650011abb62769a1a55ee09aed875fd706f14946248fb4b82d12548107db353b6f39a9da939acce756e7fb9c1866c2c00de1a79a82ee91b46122bb8f30d584619cb21a247cbffc8b7b9b09d76eb13bfa48c8f28ea335c9ba9230a030ae4a69fd7ec47a5eef8c5f9851bb1142092f173239dde5c059a728590f1741dc9f8aad1590501ba5616b7bc188d257009190356f968bbceacf77ff23f014f8310c9f0a89279d02c8d225754ce535000f79ec86455757319f65c4202df8831dad4c8e2b94a67c8949e46b733991f783d9368282bcc00475da4a1be720974d972544c810c5d789cba5e7b0935ed4f849e47207cf9d54342247a7702b8176a164bd7816fdb2bfd52f4c0d6e528b4080150d0eca5707dc5c1c220cb5c0508edc220d14e84b5386ba229b422558d49c9ed3dbe128058ca59aebdee15c9f040f10ef8d77345dcd95e2c500fa995330b6c0b2769c086d03049ef3efb98999265395a2c0ae3cec18c13d270bd91c1feb53588812942c9ad73f6d89eae4e84160abea950ad7da47e2c82dc9fb06d194642c2abf3af0b30e5d04ce6e028d0f522d4639cae0bfbcb2649d2e64a6a55f7437ffbbc65f8fd5992e59a98e98f0a1a83929ef10aceaf6319332d7ab660dd00e2c4b898fd25600161ccc24aee43a10eeaa62ccf5b95790deab87b88b49ec872f48c8713cd4597f6e55a556ab242ed843f866b64ac5b100916f0e4711a02bbfa9c42e47e5b4e72e84c28e27fbc7858d1d8791d600f29936680f470fc4badefbaf72f2ece3be6b85835b1bfddd8aa5c5b7a87f6e9c64ee9e76e836ee16efeaba2491865c24e9e0c5de706a567a54b77400bfaec3b2c9d6f43fedd6a13f713fea1474a6c3504ed17bd5a5e3ad57d807eec47d6e6ed65d8fcb4b9c0e7588680128b865677c38d7a2b8918cb76462bdace3efa22217c64b05cbcc8d29039f438e2687e521078677e1a44678a441e31752d86f6da8a46f91766a40a03526cdafda3e69e636093d8b27eb3d12f235525e21f98483db3f9735d76f2d5bd5f1b4a945a367ee471def08f2f5a5af864772436a0d2f8da323824489dbdd65da331c9ecf8eededb058c563ba0b1d378109df5186fc7e100c0beb4651e4ef8de0f33cd0e49ddfd7efb84be4ebd71f778f26ad273af8b47aac27f103620eab42694fde562a68312b551afc2c592c7f7efaec178625c51eac8f8028687c953bb26151305c6ba22d44d7c6c9a48bd1542e0211ef0633ffc8bb0ac98b3aebef98fe710b4af01303b1feeaadbbd3d631f3e133c646a0853887ad851130dd2924e84da97191494b93fd711639c4aa54eb60341b67cc5f39fe6b8844dee0c70d38f729d4aa44553a161e9af54c667b9ed083a65451286dff52d9503e3f679b5fa38ce7adf78ef8558176a0fefffd45e8a402105d075b9d50e6aea8fc00dbd5db0d3e0259e0207b07ccddb1cb54c0c7d07699a9bb817246c86bc7e76b4726d2648b266508dfcce13b7390eba8b3b5629ee150b540fc032ac6fcf6a7e20d8a5dea3dbba99b8470ee035a991f2e2a7cabba89431308d6e64a7cf4e931572e937069659f88d36afa4c6e98cbbf12fa624b17cfa15118151bca7912380d4d66220f7b58fb3bb71f3af7861f553066a356bb4333d18e9795fb5a209155f38c7d0141364ec4f0de11a38d5efec4f592f6fca3388f5772527d9e216aa09d8f3be8591d0e4efd9fd19dba829032b524eeb123f27ac8695600658b034b0c5eb4a1166e952667e8441004f4e8de0d0cc9c4cb79fb5579b9d6f2ccb390baea7c9719a55beb0cb87b82314a0c0c8a0e66aae85fb39224ff7cbcb4e9f252de601c7e452713f736039b7d4e90d6495806ea3f2b129ceec6ae7ac401da17a839d8eb394c0c89e7b39b59ed2f5994659ce9baeaf3c1adbfa943afdd952223457ebcef5a3f9f6d19858fca3e61a78a755ebfaf2e57cdb369a8742161ecbc2fc4c5ec29b9537992e4221e14a7b02e9e63b3e5a6da6587a7ad2a4e6963190421a11879350a39c22c9cc12b9ecf7a3f9132b53e07cfdeda0db6e29ce5a82b347db645377183a02cb852feaffb44a57da36c02945bb803d057a094df43dc1b4ec751f4dc3be45bb3b5490822d790d4d67cb82e23e418327be8732cd2db2f2479651a9130620ed92b6166bb729b0e5a9bceee3d1c7a98e0dee9ce57911b1d1a1f3da7d1370414c19b1454c8da246835158fae4de3f882240345aec8174fd5268f5b73b60c602442e7fcee71531b0120368abe2ad3bb5ac2da6f7ed1a14c168ccffd580261d367327ad4834c524ec554ebc0c248be39d8c6503e4ed2e8df7b36d59ed1b6b9f5d8ac455696102a9f795ca0aa75a7e9c86aa2f3f5bbe0dea2b09b9f0afc708ca38152decba96419ddc4890f74faa7358824328d036453ac16ae420fd5f86c0ed8e3ca44b095f6d4429b534d7f877ca07657704d0c35a5a1fffaf12e12a51bf210dc557353fe27406c36a185d3da3f8013438345e1c28cfa98038883bcfb957e0dfb57ff33f8caf5d5b9edc596d26629559ab6f035ba941fa665337ea16422549c918221fe0b5602180c3ba3fc7c18c7e0afd471c0dca54bb3732ac40b90f9dcd5aaf665b0ca63292ddd7235b67892df8e965fca21a8e77c1ec7d444b6d2ce05bd2253b9cdaadef964813a03b99695bfb5a8aec508e98adc14d35f7daef7d9f384776565152c354deb30b98d0c0543ef080fe48495899862fc553a2d48e1b39fd2c699c7891100c01a89aef6ce38871e04330c8164d6ffa27efc4a4c7f282b5341a8f6f92c87eefcf0facfc9a6417f93df635b600c8c218e185522009e0cc730d30dfbf3f3f2c6b2b582a6298ee855d0d7df41b0005033788c81830fc09cb97e4115ef9713ad8b6b74787db30427237a48fe83126cc2b8d3d431a3deafd22d532e9bb9ec2e74dc0f4901c060cb215b57d07e0c7cacb6d3baede035322fe9c32f212b28f8318a87f73f603c293d516b475cd96eceb1739bb4081a2d2d82fa6a6d0f33231ef184316041e357efc6bd400b7228943b93d2eef303c5ef7d7295ca959f10ead921d6e257dad7160743bdc3db3c8fd87d26b2aca6ed0bd945f41caa574d9ed61f65a45f8ad7ec50f6d7160d05ebd4516d0c3da1eb4efc88f88c5ea244ed90c07239f3d217983d93295926d6d0c8597c1d6985dd9a0df8cae5b0af9718820bb0ab425d4f8b6b5d1a8831b69c695258d2e268deb2e8743a1cba722078458fb7d5b5f4fc0f6f07207a25ed4608b7f8b8ab7ace1eaee32460e5ae00d299f78389bde8f7a64b58116387e5f0e98522c6743e808d63d7d4d3596a74d2812780ec35a9715c8fc440826d37ab29a909cc0c244099453c4a08fe541099cbffb04ead771a5c7c7004c55c44990856f2e02e790e9e4a3db5cf4db2873ad82a97159c86aa8347f8dd8ae846a4cc42f1448046cfa0e121fb9a7787136502f5cc5a21b4ff3da68a5ccdcc54e49f825dabc00a10d437d39a2a9c2e5deb72ab8b188520671eaf1b0091ab7a271a1b6ad840d089f2f79d1ac7ef5e317775eee5b2153c550ccd0038050eb7b7a6789aa6bfe68eebaac4851d93a22af4a08a14e37ec02fb0f89edbf0c1d15905a6dbf691f0f0f9e96539aeccad6267f52574aa4df31ec79dc9fd6f27b5a26fbb1945528180cad006e68745288c3868d611257541af28f036cff9b911172e38272cd5fa693ab89a11e02d795a0c7b4bda53203027994d2dda4129b474a2d94f708cf27840443597d9cc6149ff11d6c747bcc070b4adb4ce4bce847ccb7d7f899d1c4cfcb6db49b87c029b468c71e2a32771364c16c2ec2e6d10d1dedfb3379310e32b3e16153609723855caad0cc183c99c9143953e16a22b832acc833a8cd3b64d448b76134e6cf42b4b68e920c8682387c64bbb4700d8b131c45fe76d6217f96dec776fe6b49d4a770513d8228fb9e8f51f3b8d086e1cce2c5a3af3f4acfd76d985147d7067a3637984f15ce82560c5e1304f25bb1720ebce8407cde58560943896b8a3ecc59cebeb77131b1d33ddc1000dec496650992b25e3b7b13b5ada9ffb8ce961cbe53f43496e95f9f49d860cae0eed145b2c5ed2163a6a06acc60affd3536cbc328eef9dd2c3d778ed42deab72462cd808f2f1cb4ee11376ab3e4e2b1d3b9e4cd061aaeec1c616573ca29d6561f8e675af33805c2d57d2e539fd646851f4fdd9cd00a863bebb6ddca04cae87b5078c7349d6467f8c96fd93f881e76b89d506b5be38cf916094dbd6ba046995de1e38e5874e9582a7920afb47a220e7925f83adb6c14b70ecb6c85e0f14ffc1e99b11e8e8d45a0c4cb7459a758f55a5359776277548a3cb8e806bc1df0238664b35fa2173827781cde2fa9ce98853a86e3bd0bc8f38a53eba0fafa306b97e5657eaa4e5d2325ff5f39a5308126e0a4bc23696bf2d6233d3fb7a2c83f3096f82613ea80c5e4c3a5d5983d0b637c62bba0e18002e8bbec09608403107d1dca13fd22cf5f936829de8d614d8cb04bf969d3a3b7d2a7bd9a572b2ce3e05f62220548e0d8e93cba0c187464ce909cb440f4051a3d58f16ab95185579f37d1e2f890cd730fcdb99f7bad003c4c71bcfdd430eb9dfcba3140c30d9663e6b94df246aa73c5acbff26b7b6c373a0cdf64ac1229f17815be0134509bb63e066f9259d3e7bbc524e95a16907c335d78f830c4b63e461efc80a0d1dd31b63ee14124c23373c4f41f61b1923f4526cfabc5f3598db634ebf07cb70061ea71417f8efa32a2ccbd67fe4943633ef76184e38f3ef594f5ee8e1c148b30637358e32b5031b80db19e982291b383ccf5658cf2398594c5b570a2a284f45b44f343b33c76dbfed74c8919bb7fb09b46c854e0acc2fdcfcd6bb2434ae40f91413fca079183e087ec16be83cf854fa55d3b63fff2ac24877bb1b3205b77c407bb70c04d55023e99eb036fa7dfab98735234fd73a2b4b0962f31fb89e207f5fc8b9d4dbcfa00a184331970379dcf55e0b184fa79f32a9cd7a3b39b2bb9f3a44d628d85abb7453ce94e22ccb14a379e2f0c5caa0deb484e8f8c455e97a1e16f84685300b88211aee0d6ac18965571fab8166e5bb1548d6b556a4808b86494102a8f547f58cc47140d0b8f39718e1a5f35842b2ef476e50eb08ea1202d6db96fdf41c080e6b4609d9acf3114d4532076db372b4ec2c52f2b96a797896b2c1745b13012c3ce9e3e02eceaeb11a714539419b3ece70ffc777b3f633e406d56fd8f3d1feae707a1c9a64d527ece1d57fe78593df50b33227f35a3e31d8ef6777617569113460d7271aece80c344be8f5c139f567568a657d8b5bd5910c3e2f34e4fe5930d5dbf5eabe23ccd4c841a3cddfd39a287796844c95bbf6675567b1cc84feb5d3d4e514206dd4d4c2f90e296a04a8a30744618228efc696c40f7857d97e2ca25b868f236d04bcd20020b654a69180f67d43b5c34b626653abf25cbd364dd465dcb7d9dc1bb61bc3bff4afb9ff31f12ec68fa3e08a3fc91741edf8ec23f0a425482034b47022b74cd8ee32bdc1a4fe0a7e9e626315e1e6adc2686c6394a5520d7e918f5fff74e77a69295aaa00020b8337983e8af0cb58aebe4b486642cd5021c5998b5019cc64d93467c0daad184a7eaad2419755ef37c39de6c0d5905b8629ce6f31a1a447578248787af03d74350f25fa8f859750a98f94317d5915e4ad1b92ff45c440e809a1a612d962e2da2778677040884342e1a655559b1726be4ad5a6afe98ffedec7e4ffe0415b6578e3d4c206f9f9da50fad9d78eb94af03ecda8cc521db0cb49f9e334001e8d6dc7434d5cf0866a27e3c169004c2c722d0dc8843e29091d4c529c59c8d434eef4e967a52d38e86de94f27e61f9162ebee11e95f1cff57f31f943ad04c8e14870bee05454650be86aa4284abfc5fae87fface3d519be8a28571282ffe9869e16bf7eaa3fb491ce1f8e9a1a861a76cebe54283ae43f59d654319cf563ffb04663131c39adf1ca127c89d175880423f686823a9dc8f853912ae6acbf1d7ea0bd0af675760c7435eb4c99961cfe4d27b1d61752fe2d33ef19800c9966752b255693e692315f140a80f830be5d9f824d9136115284775106ed6a0c62bc59ddea4c1662fded15c5eda869f65f0c35f6d139ba8a8048379ea6a3c083e78f68f616d23b913100d71d5348d0b80d516288c9471100af56ce2b5eb5b310d7d8814fb0b7518377b8144ff5a84b5432dcbf931563aaca31d0239c321823fb3c28dd41a89354ce47d4ba95cd30d63dc673ebd03973eb03a7d85ea88d61a6f983e7fb4869591d26e2e818a1f77eef3bf277fa0cf386978ca5195001441a1c0579d78a49b1d5b007b7e2a4c80cc4a9721d6084dc91f6d21f6a10e775c07ca4ecf9a911015cbb63335484f7ef654818804d7474a4c8be35a899bc8a59847590606a07c7eb743244fe10948ff842c8cafa524aac50466b9a5f40461e7fd71950eb673306e477ec34aa9e0259885b128bb7d9c702b410d7d524dad6da5744054c8ca10fe8575375ebe645689dae51cb5142d3511e21a7b43840d0b42333bf558fd51a2870c4860982be9f53355d8cf99ee8bc6836d4692195b0e21fab6280a87e6243097ecee16e9d578012f67f7a377464f4a5f2f222163388a817d0f2460000734e882ce7ebd4276b7e1a6a22fbcef87d65a9ace315ddfbd8e3a02984cc509312fbaf7f4e47a074569ace19f14010aea632670957b2e9d5ec789bef90e32914d3d43c67a4571da14108c2ea8b80af4d332c831ff000d02a98e4ace3dd037ae843a8647163a4e80cdef62e2536c822bc144e643e0f70dc0cbf0a0b54ccf5d188733eb05e87f92add63cf7ea85f91c4fde4e2dac2cbdf2f656cd01db7777ca4190e32ed439d66c18502decd0c8cc1533b263d0d747986c4e6a4aff70e2a84badf0295e5df47c1e35ca13d6bfbcfe7c794cee421e96b219af6b694ad0f24d6f76afc88c387903aca32ab3573eb56dc593f33ee9a910dcc3ed709f9dd830a2029376172e63c7138b757ab345f1de0accb21c2fb6a06b656ac2399c7f1f0d5fb3447c89128448c35e61c2032b4ea4a840119826f69ea73409ababcfdb04356f66429b29499ca72a1037f7a08fb2e6f265b4e743e68035ae0311b2ccb61aed3fe17dd22c77ab38c49b09184107fe012d43ab385a11171ed09929cf462649449b68a2a10587d2f6948df8dc509e05a2bbb1f16563a0b6ca9c8b40528f55d1ba56d68b3d39456c2ea71acbd06db6cfea521f51314aeb39444080a9b05aa99bff9fd5f2feeed3d3b9ed33936c2b1bb0c80cfe0a2bf6fecebfd4f2ba88d6bec458dd065b852d56bf61cdf98651790cf3063d310453ef7efd57c63ae348ae3686433387dff0595622d44ea5917e645d312a1175571338f4ef78c7292ca625d81de1166cddd0005f0332b4c8741c281a8bf6bfa08520622f74e19a7a43a26a8c3cb806009d362d5119c0182b427f52652ecf4c346195aceab37c5aed0e9fcbda7d4d3a7dd59dc3b10c7c5fcfc98ffda7b357327812d2e08492efb7c8dc6fd6f7b3c22193dde3ca229c1a902e9fac48c06bd4ae72560b3420dc772b0ad7fdae4d48f2b286eb5f85a1ec12c77a21eeade57dfff2326e46fe7de05f5b0004fdddba3adf099a3bf1a6ff5cf1fd56cacb8bf08c531237d5d769a1d9cf676dce2ca1309745aece9b341dbdb960b84c40f3f45d72408f2bdf5fb32403c5826da8af71d6319a0e6e9f282b578536cba20c2ed267df4d4ca2f49628df45b836b993232981e0bc4f121b80295847ce60cb0db41f67851d6ac64f683f7cf6f986c5fb22095183645fa87717325496930017920dbd74b0be6899036293809aa863466c271158211f3e26dd86a62bf4c159cb17bb5e303f50650b8776c5644988a896fd7fa1c43fb6f142f1451c6b20250612c0af43ed0c2570fea925070ba9699a6b7ed67e7b83bc1db2e213a5a63c96a2ab691cb38e90a435a8c6f638baa9af40c2913fe0c1d516569acc2c27a57e13116a7ab0cd86152c9d972d332eac62f8c4ef9cff1de4c3e13cf03c3b9dc38c0e71069450443b5e07b51e7cce9b96dfe22b652f29541f0ebde8911fb56c2e6baf361ede39994d3679afb266734128094734dd29a0c2f90df70f30bcf45d0fcf461d1d22548d7fe807a571e690cf3bb71cceccdcd358bb66e42da73b8213770cbda83a50d1e4869545254cb4819f63da570b4b13c8545a095ee5d57bd74a84f70ab847d8d9478f232928a7335d8c36f5985514b81099ab32dbd5536f16c6074e2dc92b44e35aff65c9321e89f0f8b04864d595467c73c8dc618d747d01b3a62ebca9e7a4dd86ffd218e1cdf85ecc2ce300fd5787ee569367c97565a375c414ef65431ccff63866be5e47db305810c7df61727bd1c6b5dc37048656320eb71e3ba587d82b78a34ae20063e4f6598bf60b1d85c27d0fabcfaf9cc414013891e6f02d5953c42ca1c8b66dee0be7ea6a5e882a1d6d35ec67b6e6c0fdecdd7d5a418212ed30ee1cc9116fad5297cf60b1405b8943872197347a890766bd75b258c0cdb6c836dc62ed8581077f389e4f236093a2e530db8baac66a22ce78c5bc67ad6a928a5e666f59135ba35fdd6d8f96176eb7ea8d5d7e73cee10471ad348f89f8e17d1f7770b166253b986d9238e4014d6a1b2d7edb9c13c0779d4e0a11d09df3d2fc3facf27cf867189dc9c261bcecc301a51ac355dd08815807a171fa5d8a045b2fd37137b2f43dc630a4f426b53e01a59b88e3020160ca2c27c799d63b4591a8607cffd25ded698064761babb99103f2d8143192c5d9630cc62beb875e793778092f3046cd9f1b4bc83307a53cbbc36f9f1118053cbd5c06dca39edfd2512e7bfa16397cccd20fe4fb38c6f6ad66513d42be20a40e54cc0deb93feab18795e45bb5878663e0750ed3a4f2d6da17cfd85dda8943464efda1fff03205c84e9cb2a74bb26c938e6bbeeeb20ed2609cf795d6eab980a28c723a14eb809c553d9e5c5594aff1e96074649c1b8f4ea42f0d2dba40d0f07d251621297038119ae5a52c80cf001a332ce5f647d6c2d020ff621dbd5effa4a4be4b4cbd540a0313bec9acee45307429b582a5f71f71a6888bc4429f85beab1f6c11f3ddcf1561ad641e2571d17c77ff28ea33772d89aa6e8cd12c530168ac103a98421c299733ff4842ac944574ce3c9df87506daeac089eb8df22f45ceb8c1230be580bfab7d2a746071f28aba102e93c2e46e30760430ebb3e9883f2d09511f99331cadde5f96d18ec33f3fe2af12d46a3e4819ef95634241dbb23f0ada97759544579e0497f0f4e3077f1dd54a14ebae8b9d825a729e4b853f52b8d58832b6a20e56f27b85fcf38d39563f4afedfa6a5e7c58c47c417438e080463a8ea8db995297613db3be953e31fb570f54f9d90fe16c60fe2d75957701ba1940e98658616d5545d4deb230aab310daba86965131f7a6dc0f7d6c6e6a12cf2481f3095b822e52b54e2cde5e017081358ad1085acd94e434025b710ccf25f9f4423e6e4fc682ffe1479840d37466ff4771ce035855cda8a3e2907323fe7760dc4c39e317cea433c7a32fb587dd860683b08a9b8a568e95498b2107699f5e2192144fe52ba305240a70b8e9d60b56421d7e7edd141734706ff670abb57e1683b1c12b387df907f1982db60a0f206c5892b3b50d1daaf77194caecda12ec5fb1f89fafa5f749bbdacca43de4f7b6d418a9af0ad856e662a2ebb3fa6dc83a41609b1f7d5e90b53d9e8a77a73cf80f2984e3af010aa2bee35794712fd3502c9c58a81f7aaafab04f3265776d6bc82e79d0ec7e7da13fc57c79dc9e4f6ea29c2149fd57c6b878bbc3adb2aad4526dea40e8e30c76fd836d2bb825dbae2fbbe6ce6fb25c71a5cdadc37c0e1852a1b66d7451f90ea84b352c40a78cdddf18b637bfccfce077209c739ce802f85392568f0066f632e2cefc0f468aa965bce09c33713c25c4e0d5381157e7cd13f764cfaafffe0b47ec94b87b9146290719bb5156c44b97623754f59583d8b7f7450ec1b1d7efe8b8f5a09decbdaf790922805d7b06a29aab14cfbde149a79ab9890cb337087f0ab3f40b8abc1f2a5d3bf1aec8a7009a91c7b21548000d50ae6d2955bb9262787eda1fe5e0ec769a0c9a3bfec552fa05d6af6a10223fe4bcee0832475e5a3a38c823cbea745b87cc39d7d49defd664749e920843b801cfc14f558baad762f8796da716674e7ba1a4662b3392afeb24ec6e3a7e85f829d64bbeb812b021df0f8bc00b41660d106920b5ed28f3fffd8b59aff15f6cf514394d457d7ce7fb965b515004c8dcab97e3138b9daea3919f09af0ba2eb15fd37a75b29589f9e7456cab542d91268b8395fa90b8a2f5832f1f55cc4e0fe7c0051376cc1cd09b18b6a4674dff495bbef5869d148a967835c4adc996924e744e19a6e80456f06e30d0fe86a081f481e2aee593cbb63082d1110eae5267a5c6e8f38c766591f5de6ac8f58cba9aeec0be824b61a025bbb8efd53d1e59f6ea24a9408bebdef3b3cd5ebade03afc2dab103172f92ca4c9dae8759c44d67e0b442c00e4b81a50abba7d808c0b2f2bb9465318da6cd9bd89e3948d785b718d1d225c8ccac620bc9b31aa838e9272b4427ee3753dbacb7af3cc175063bb9e063a0570ece3c50fcb9468b7e9080feb5c64507ef91a79eaf0d70a0298f9e51d3a92b2591e3e6bf81b4c46aa5a64d620f1a8817d29d8d0deb2b373d094438a829d124aa966d8ce495dd5eb530989bbf7f4a2410928fd2687a5975bf9384c646d2480c92973f0e76cf8c126265371ea0612548cbb21a2772366d43aff01a3a0fafbc609889431eea924b2fbd0b03c1990f7480bf48e55bc897cff83e2748c8628fde910b643b211c951a01b4e1953853a7602f01ffc05b58f8a8a63f9b1a1573a23342154807940ad3080c77f95cc3fc714cf427845cb2a02a801be971f980f9e20ff0333c3b326c510615c2a266e3e4479f6bb9476b29e9aa9ba2d18e5a47f2c1dc8ca2a2f68d57410f5514c37499f7e8aa634567f1f5f43a1c858ad964d4ab4b3fda048e98c2bb369a3d7c9bbe6d202450bbe4e6874d01ad3ade3070cc6435223911150230529e67998d86740ce1cb35530e4510f08b968b78e319c904e2f92187af2ae70900ea7faff3830180a72ff9a55636e6ea0d6be5ea7c8a9dd2cb4e67afd3c4baf5a9506f75173e5c8c556b77db2eba2b25f98db84d64302ad1952936eeaf8296379e14cbcfe0546ba40750e3d14d29d884d1fcb0538d90fad43f53c20694e19239e24f5adcaa000718d0819be166a2827a04eafcf04fe4a2f8eea90335fce30090601f5dac609543ce74671cc0b735cfb447002a2edb9b182cce199a57a186f6bd2e5ea5216b93e13e88543de802becd8c0e7b0de5d08dff22903024da169dc45c8c44d4cafbdf8ac7e3d77010dcd94d4a95f1be9322c8b99449a9c737d2812f8a6fde48043d51058633a0db37a64ec4936ab4e80fbe7168b3d44bb92e50d964a9d98d254a72657755790ac9ea9fadf5a221d5c1bb6241bbe6e9682d9f74910f8f3a37d5f597ce1c8ffe000ee97434a452be176171dc2017530ba5314a9cfc90f3fdb1dfe8c9df810b3ea1303892a9df04337d1728d0257f85b921c9e1b2d954a090e0e74cd016114f9e7b829a6d311cfac64aeb2a3cdd10a96bd99ac77faf29ed4fbcf93e81fad1a37bc72f474c650eda34c4150dd67bf9d9c028b65748f99dff24595483a5a5aa8f09886b51cc538aa8666669923b1b39ddacbd201c11b6368b1e15f60bd0620efa37608a8b797f7b275cbc8ae396128243944fbf9dbe14e00817ce4e374ae3c04ce65b31636d53531326108d77012400faf0b6fe6f311e923692d9ac42af0792ec8d7b47303d875e5a95fc355a0a68dd690f29ba2aed1193635f6ac0e428f8b6494402ebf4440ff409bf80fdf4049d292178e18473701e97638ad7e6958a951a457a0df68a1f0e9869c77cc535ea6e8b35fb4b94a30dba24bd9d316f5dbfeaf50832a1573f6965959bc18149d6f7971f567f035d491c7a51825d5b4b5cb72dba919720e6a46f81aacb8e352e5fc15844a173609e89a21a462676c6501fc66c2f57b041e8a1c83917f4a0e7cb890e64b754c4f6731544349c1217343a4c8a7495082ce57e5137a1c80d3d479eb26af5f4ab7452ea86ae729abd2b6ea4c7f22c1aba4d71d47cfeec2344aaedfee4acabe07011807029a52aeb083436e4f4cb73320ef0d5196f6f1b2edea8fd93cae03e54997934e38e3a9b036b24d491f803799a0fece0cee98abced988ca5b32e179a3c8628269b18dbe3b2914d9710c4666cf28e11cf1bd296428875f25085e98ef1fadd60db3e3dba3cda144824723fbc449103634c5314954b5be07d0f2a3c3c45700c712bdf0142f317c2201e3a3670743f9bfe23f91f5b9e5fbebf6302a8faf6107eaa1820ee82584557da209796ab692d37f2bf7d2cbe192c25b2a2c2ff09648ba21bb3414ccc82a3b49f1fa945f51806b24ee50aa3e562ccdd374778f3ca98beb0459bb56f9359bff810aee72909db26fc5a25715ef07bced17999a010c78226b3f8bbbcade996bfa7f9eb312113b84cb1d65cd0a52746d2c7a89b109783202eb2aa14bc7a1a46fa225b69d1992838338c6f5e04f0858d026bc7968a632d3fb345f39c2dd850931554c7f8950246134b9cd5f4f252a0d22d958a072c61d25d5ec54cb9242259f444c5e7e536f0c32fb716993fa7965fc98e080970a36a08dc4eff9f85b77ebd468cdcd2e72d0a2a021b0a853bcc033ffc48bb68dff288828e46310dec368b860853a6c19069db8634486a6f545744ce83cbb1dd2c5f2d2868aae84f1ad0fda0aafe11f0fc0acddabe4877896d26c90d6542692b80c65395f69132f0d2fbf7cd0ead779a468ae9f617eaad77ba25db0acd78dfa2b2005aa8e8273a364cf2559e955efb36db928aef178a4d4184007d5ca5c7ec611016a355ba79fbefab86a123fb97f53b0eb32cfed5ace50a458f83644cf40b91066118343e605a1f6d3d5ba3efe9e0f2250d5bb5257ea2fe097a7a6a3f80fcc6702956e79474e6bb0ad3564e621fbc320437499ae7c72a2384664a44a01a06106bbf02d9c1953ca2d2d61c95a1d6038b11635bddde4ebbfc5b419e3058ba0b4b6d9b165becb17b64d4cc450b31ab20964d26ee2352085758f5851d41f754d8a8f8a920ea88631b61f69d60146a2167a704129a58fd8fa6165c162820611a8906d1688ace79bf9e66512cfd1484c096ce50388e602ed43cfdf67cc63847f3aa17dc2db6b7002ca597de8170c5c45011b43fcd529de06cc294bcbd8d73220c46770c5a9701628669d049a83e764855c5d32d40e646989d7dd84266a7d280eebaaa8d47e470634732d59e9ab4297eb3f07578b53f3531adc1391cb47dbfa75fdc02cdeffacc061deefbb7f0ec9f0f96e8ce0496e5abf5d87798a699e416175058bd093e97c1773b5616aaf56ff4ca5c26fb191c5ae41d4c2f361fa60b6d554b3480aec44c9fe477d2f0f7a45d7c6629344e67c93f33afe231625e5aebd5f81541f8218052a577b9ad7f6b72ac5723585e6de4ea90a2872b2b951df89ac3939cd87c91200b254d574c7f7cb55af7c9b278b4d6b201b12f0b94ae06cbb91007bef89368b73b0ae8020f955017c5d46c291f0fe20fbdba1739ea4a331803c6fe7bff876f89949cd5da5e2e7eee764b3c7c45e8ae0292753ca8ab2ae631fd8438d349a55beb9bdbe841e6bbe7882bcdb488470b0e55e6eecb0124ad3fd3db5a1376f11969b8287456d3d44f9a32dd474999da8f7ba73dabaeddbd2c810cc63006d8e5dd154a09b9e814997ea719de328d4e4eb6ce1ddf1bddd6e9d7caaf9b386955a8fe142d010e86532ecb06b3685c0a69161f2627a8333068c7ce52140eef125b42b36bf27f74070d192ba8936aa587b9d398446c2261fb965280bd6bc56309184181df312ff673c4335afb8a9e2140a1ed9832d14cb05c8f77ea84f3f39d7516707ff801d070e9f425c138f06929f5fe233ae282b20085c6cfd5458c7d08c24966692af215c5693f9e09861c01d9b0f860dd4b582c44b4a73459741a15e0edb6e3022391b79d5caccf5386b635829f3208a8158ad8b7a396f6890d0f4cbfbc61a2624c9ff55d45ebde3ac5c5f07c9c043d015c249bf7b40262997f5c4e93716f5e381b544e4cbf76729fb813e98333642f7d68cb6caee49668824a79f2d59cf73363b3aab88b4a6640547e9beb87cd78b6e056197ff9871fa1dc4f38d05f21a6d156011761b90a605015d45a834c13ff17854037e72af3a17de04b9deefc24c59768c8a615231b6f3a0ab37d69ad4a1ab4318803c69a3423f70ef6ebae7c80be230a4c64ff3b7ee3c29c6eec97370868294bd185ce576781e8dbbb69138f9569e4c638650301017285f5bcc2f606b39222130456ce7c2608366f51cbbdbe36eaf3448d841d4021c2bccf17c6de26fd1a2a36fe4477d9a966e34cf035b9f1490b7cd0161cfe4a8afc343dc85119e5ced8c7757206d6bfbe673677dd099007e05d031b53fac544405a942f3654502ae43cf1f882d7c562841daa43f96e062437eee30a993c488ec4d501ebe4ae0019344c8d9ba892d2e1ae84c07e24e9ac59852a15be0425881742c7c83caa026da718596830ed3ede80bea26565d24a529fc04ba53f5efbe355b36451ba4d33d7f7b12e1a09081838682308bf2c5a3b7597870268591f34fac0691ca37901fea0afd16dadd5cd3e2c28d2f265a4fc4f027289278184b6806e95fced0d23912b9ac4f76225b96bfff99aa953e779976043dbed61175db8b9373b21343de3b2e8a367e32197cc198a8cdba743210cc7a42971a10966a4c990088df071f1ecc96db33ec361bbe98c825ca3575b0f23a8294ea969cc8dbddab551a450655e488341c0541d8d189ad94b5fd67d052554cad0ffbc8d020a4110209bcde2e4bd6d461af522794470be1d268ff633f1317459eeeac3717e72bf9da0f4823dd4e2981c46655c5ae2dd213e329c5b151e9fa973396db3cf3d79e5362c6e63190c1fa936d95b98d81411aab1da95ecebae94d4c113fd49dc269eaf9033b6ec49c13201c14f7dcec4b29a146056800d4eff9a0c979f6a381de3f69f6aed2c5828cb82ded7db52ecd793b753205feec5a48f61b714c151aefb9944e254c43045a6c5e9c002c79f2bd42a17b713f23b5de9aa788f87e4266dc70ed569ef6e68ac621acfb6814f7869887fe266258bc82b29a70d391922a2713c31071bf73da0b4843b8e1f5a7f3f3f2aeaece946a819f00e34e0e2d98fc32580e79cc237647de6126a451102b1e8c5cc9bb2a3c01f0afdffa4005c60aa869011d4dd3eaa4a7bab937bfa7f82518150ae35fa9ce24bf829c197b792fc0994c7ebfb42a2f9a93f4c1892e4c25f662dd8248d67aa4ed9afa83ce9326dee5a20cfd879fafe9573b472817e74efc65e8ecf5f47199c9737332f634a05b3354cfe9340d12460f9846404e1b406c911db86c6678fb04a3317a645b1993e5e61bdcc0f822ee280bae9d84db191051a9958f22740cf0894555de3cf136f4cc8eb1c4ac44a8a9822f95a15fd6f80bd37252677a2cd10d703f9294855d169242679002d3b322656b4ab8eed68e404d79614fd4d91816c20a390341703e68e3ee241e41739418373d0fb9ba1fa6a0366b0cc0a2e9dbdd983188f8c0400dfb354b81f71817cd185526793fd68683952ca58763933e76fb7f1020df7f59bb35b63d41d14cd157a24fa3e4248b5cde6286519e8f437a086e9191b1faf82367faa4486978ba6f1810dbe877e5e33977dba474dbe70a3c4d4671b3f63e67e1db5281b1e0d0e0f1a66b1397e0e7726c4c374840a5fbbcbb98b6952fc211261def9275eec50e83729df2399756d6162cc2ca4e317ac25801e89b8f18974e47a6c3fdfc263181a689aab050f6866485b67fc445f037294f95592bd75c454a17df0a95a7e2a30c89a9bb2091102afe444d98002f36c65be3c1f79fb6665ae408e8744ebd1c399d0c95b20b21f06f7ec00f86554ccae8171ffc4698173464551795a77ce540ffe692450ed264e99b64dcd4deb6665c99d906b8b193ff1a1960d1fe4417660de1fe4f7df440b46effcc4ce95944bf2ab5ee1aa227d2cf5f513c191f6d5baa23d5f4f759e9404a0c1c86236e72d1bea4aed258bc652bd97ed8a226ad6e50a61918b3201406099938ba0d528d9bc6ceb36df2f7ba6c6538678a52db407d9272e32b13eadb152dd4b8ea3d384de54f57c33354c9123be7b8bc8a770ac5338c912c1539124449f627d105aba2102a4b0b67b0c65221cf18203e77f49027d0ab585b8bfc6861227b7752342921b1c00ee5a8742c089f201a190b19e41d3740e919a808e1ce8d3591a7beb851d81b8a55d61586651d229c1650f5ae4d2dca791c1b6d3cb2ba7059fcdb19dee84e1ad21ed8f12bf460be2dfd201a9fec9f0ba555af60262073d1910898bd32ff43a6cc844a9eceaf111208c959f48b03fd34393fa60ebcd35c973c9bc61a27bfc3f6e5c4b0ba005d1605542ce249fff70a03097330181444e4ce33c130517551acba9a693226e84a5edba5da80a3fb530bbc8bb5999739dee9c696a9ee1c7198f4cbe9635e007afe30cb77c1315a02429e226e3727146074c38e043c4770481cf4d7d321421ced4bc44cf359fab27bb5add0ebc1f02d1de646c157aa0a2fa053f76c5c17dc0e21271d3eca7ea2b4db478f23c052e106a734f93c5b3ca78de70c8c549dd411b5944ed9f18854b4b1ea1acf5a8780163a1fcf2104cb4c483fd17e8f759880a84c0e4cf5f8304d6e4389237afa8c93650b27e0319ac90f660782f92afab62e21fff102bb8d316eee157c2096ae69ea4cb3234c3894fbde89aa3e8cb18819f09ab8961d91d33901b0fb8234142d6692f6f38298534088a4c66b78760ac4cef690e6e67ef1c25bc8d010a0d12ce5af512bd2cf723bc65aa592ed8af781767b89cf66584553ea49cc8bca17efbf881a2bb424add154ff538c41bdccd485e625ea495c8ee50f6aca3a1bb285905295dcfe15b564a649af905cef87ab0c018facbcc04002f9903c8ee91de5e455eb4c35c1f0b1ebd65ed2c79fa3aa1a3ad8fdde6949c21bcb0489310021dd0ff77bd3a54e4e3b445547cec1ffd8883c38629b4493d0317093e90d51903c814885d75af75d2afd96792430eea0b65b981305cb684cbe871f4c5b5de566a86d2982b6ba8643116f50e988b228a460de65d9ac360736fb2b5052f51014142b0a9e2b01c36bd85182942ebf39943787b4b19f33effde6a4b78f137e41967cc89d4ee64e44d67ab1dc84dd30e65c51866217d0819ede95aeffafaa14642a6a8ce8ed24a8abdda1f5972db5f0bb9649440d298dc68e37ea3175044e099297e0bd5d62a9baa8be949ac6005a39105ab710042110c78a487ce7c87a2eb18341b7477b540fca6b0fbae9550aef51b759b9993e3485535e15799c473c5d71b1f42f1f460b9bf9467ac4548d5119444d721349a122314eb746e50915a4463efe65931bd505cd5883f0d6e4a2b4142da4c61326649baa5f679e8a4da39ead03b18235e148dc5bd8c6cd35c616bf1ae2f6f781baab1f4cf5f618ab074b774f2246830822a196c16053ff2a97bf9a1a04b83544abaa2c40cc2b3c3c578c00cad70dddd0ee284160987387de74bdc1198d083e814ceae60b4815bcc8677bc2999818615a872ebe40100a6c6bc0224c0195ff0b464e2c7ab6e828b977f5019e3cc6afd85cf39ad89fd1f73186d57d7b111e7ecba67edeec09dda5a22a968c9315df130d07863488ad7d72812f23a3d10a2d4295f6ed0e18a861c01bd621bf7090617e92b18e32cb91cf35741ecb3084b7f7b7bbaa2e358be52f2c197e1d6a8acc294c7c43f059178c1ac2ff2fc5ae567651350d4a87284f7fa8c7c31b9c2e8ce78d70205ffd1a869fc63c228d3d7973ff6f757abe1aa7c71f3e8624b8ed2c1dcd0643535eb15e73dea20e3ff98c8ddabdbe2fb6c346c4211849b993f27973dc6143a86228bfb2b5e2b94db481bc8d63c61b0e6115ec4b75799bb3fcc8bf5ffd7e0287a8221eb5388d05ec69fabee5ad152347ff9ddfc352838e139f791970773d32170afce03ba5d306042bc4e3a9c9d447ca0d93672bec897ff1b59f3a91e7f769f0cf7d1afe5af0266c48f486997722470555f59015a6e9b74a32019aab26bebe79b86bdf6511c434889ecf5d8766fd798f9ae4f10acdf4810add185d82345b0c469eed4f967a5ae662859127b22b1f0bad7a32196b6f941d3a2aba1641af14e074d19dae0e024b5defdf98064de910758b275eb0d39349a9aef6b2b9b9e9ca3d5a32d771872fa0c6ae9e43f39bbdfd36b9c017ac31be13f98bf47da6c367b92bfc8532bce28d6d9762fd56919c033378d0827ae8685a4ca04e3482fc1a3a023e103e2924cc4d5b897e23afcbb8f09ba3586ac455f95f4ffdb99e5fc93ce6aec0d673aa6b08de5926a19eb9a7de0ac787881bbe67a10690020006133c407293fb99695e491d26bd254354c22e08e3fdb9fc7b828f446c7538fd631d5ddc9992dde920bec9457ff2021bf0ca34f87beb6235f42e3606a48b183ea3c30dfa04ee94b11969a308ae876011826eac0a64ed655e84e136da48efd9d4682ca0e41dba225b19272b3212b98fd0dd1ee708aaf2c16202252fba04d8d9a960103d431b8e037b6d9b97aad6735fa563600edf95e8cee2bf5d0977538db048c7dc011582cbf4d7f94df5b39928f015538f76acd23db98b72cc785554523aea0af7eba88041df512957cea80ee6df20da80aaf0f76e850b4d5ad7fb780a37a34f695c8dbb96f1c03dc28cf6c07e803412d3c0cfea9e94e300334e8b6d94ecf53e0811238c0417399ba16309ab6fbfd99f7574c552911c05ab03dd301a47daed3fbe186bad39a262d8edbde91902aa96169eb53c5f7506cf14671e5faff0e6f3c33932c9374486e727858fe5c6a8bcfe80ac5672bf1f62cbb50ea9025a48cdeab0abfac0dc1edb00cd8fd3e92d19e042ab6e319561c26b1d5fae34b408a926941e4defc5655b193e1538db3e88e657d0e15f5475e51b039e85c7ef373b7a9fde3d9aa569fb5965986049fce25a73449b953ab590071979a479fbb6b8f44f03c8a9831e09efbf4138dad207e5ae666ac169682300115e04907e090e27deb33992f89cb3b4e460f7a7c577bbdf749f2707ba42a8263496a56922cb7fa2d97a72753a98db9165de7083ddca4af6f640d1fa6430e47ff43c22f87206247343bb0d365a77d459edd065ea228127ce1a1c56fb535e109fb0ef6562d04459b2ee1b7f8ac7666eb3a44ceb809419d0cbe0c4ecfc274d4a3ee511e1060b3b7948c86bd3c9effb965d5429c099df9b14c9e0db340c7090ec8ee9356c8bc8a6b8b4315b9092051d69b9ec86715edfe305eda73d1188b8426bdaa49329fcbf916eb555e23aea4b57b9c674ecc0f3107ed0b7c41008a61d0b77af5f5dffaa015ddd623e33ea020c0f8f5007d2bbf76fbd94ef312bc27b77d69b730e4eb5e4686e2e4950ce7a2084ca361d93c54e0b0b4ca9eed6710f1a2dde8875b877c226d2d10b828e7e346aa2bac738d1dda914d2a8089eb012a9ce5359ff74561150f7202ccbf5016fcecfa22f1489631524a022332806f7e9daf39fb8b774d4d3490107c2a4d27546d7cb2270b5804d01c3371aa06a3d180f0b4df11d23a6545157c1eeaf1edf0a02f492d45a639aa6e9d50246b966a2eec5053d40bde13b502a2f86f384ebd94d6e4f69cbba9ad9a126e2a0eb6dd84d129e9c5d2cd5763d05420e283170e73be17bfc612941e1b6b035f20d1ccf010faf6188ef76068b908fe5519c772bcefbbabcb7ef717e9b906a62a0b00ec56bbc0fcd72f08f3ae1a257dc847874f420a42d73bea2fac9900baa9dc87b3cfd979fd4b20d754b0ec92b8afd19523a2c46f913febd7489a156ad0c69c26a0472db960cb7f73a020e202294f29ea25eb51de2d4f72a2b9b7f9d1a379492e98c9514e77b5b516f32b974f67ea7a33398467e33e125db8994913ec7721c66a31407fdd147f6275f768bb61f1288e6318610f2a471ad84e88230363edf13c7173da724656392e8c08cc53729080ced477ff76cac77e2985d38272e06caa793d60d14d5df6d051699deb8a51b7749b20e0115e648a87c8b44c8b26d7b8f6447097b0566ce388a30087c1050fb2475d8540813a0c48e902419e37524d0744b92d3f14081fac0a101232565bf45b70cd90474fb38bdd6f48c9a46c523524a921c4eaba009e37655e3529a15a16dec68fa4baf62c51b6c670d39fd0a769f4714311d0e63ec0c5701fef71e22c29614b3ce509ed448bfdde4648cd32b98747e93e2cc668f83aece521ac4306960bd04241c2d5e9bfec9b8160603733f3d015e7fa2527ee300bf6de1c2c9fb0dcc3611941dddf5c8129b27f09801169b0fb1913bb7748e7193f87550479d6b7ead333d8da7e98feb892cf92b2ef450335bd4d2eb203c698b59d862ce9096c030eccc5885835f37fe2aef3184c3b75b2b9b3803b526bb32e0194d812eede8bfabb3abb84c66d8c6450b08e5009647749da4891b4e93e5dfc5de09b546cb2a80b9cf2701d1ca4d15bc5da86caeca4ab339b179d9e497db1450d4681d32da23c5f3b8c24a9f86ac1d0df434821823c47d8483ec86b011ef6a219cfa14b74c2064f029d636d8392494fe106979e179eb7ce234a4dba1551cf447309efa5ad1f70556ae08bc777714d586578effae2cca477e2ce61b227f5e2d5241e493d0b2379b621219faf8d8be44ea9ef4ebb8b6aad01440d0e9b10c964066e849128334566f5dc39724a8ca22d8d057cf32c7916ad2870c5eda332f87fb65e781b419a10fbe49630d47f1b115545309a5390e505702728ed43936c42d1885df2f9bb06cc834dd68d42175d9289a91879678ae06032bd324500e51f0ee40b14d1cf6d940a5e0850d3b202685963b8035e7ada7bcb80dc524d19188c2160f8539edf53d2fb0567ebd56a1a2f7c43bf7de5532a50b9afb27f43ea631ce59367a3274ab8607452f9811f4400dfde9cb049b2a475c8943f4f83e0600470b4f6ce177e2198c8fe569d2bae0a1d0b139211d741024b26f3a9916ea3c0b704b36c93275a4991dec8d91a541ce27b332183a4a1fc372dd34bd6b876cd1524e6600b7db242a799f20837376307110d7454e187b6c56d62a574e51e9e5f95e81e3ef5fa42c3518bb3c42ce4d49fb3395c42c2d44bd829594566f4a12e1ff8c4ecc5c34aad3f1a8721ce44d3b696863434948aa4770927401e4b213842605e41a3412a73158d51586e5311d5314de755737d4a0cafad4b8eba58b552ba767e4462ab4a3bf2b82d952bcbfb28cd2746b65ed92935abb4fafe2e7603317dadf8fdeeb6b46c97ee02e5727b8bb31ee910f86f45add2098d6a6b0fb2bcbc12e7b8ea5ea851984dacaad187134e5163013745e85e19947b2ef56735d9b461ed5ddda0e538b1239bde55ba16bed3b1dc453e4148d89fcc32288fbebd90b7e1daf6ad6ece865da477c8658075866b5c4994e8d0632391d8c6ebe0efe37f9c439582cb28824c2aad6548342eff83fda4d7d90cca7955c66b2ae0274ef207c2fa6fb7504ef4871a5df25bf001b8adf8dfb19dc19ab03fe960cbe6f44b93418ba8ab173c075405cc6d28000f22f6c7cfe4063e7aca85914e30ef32ceb78709e5134030fd91b142c2ad6f00ff43bd5e9804b6571aaa1d57777a059f080d47c6f38ecc9dd1d1f1a593107c91d9f24eb60f5e22b58ba06e7f032e4d66ba8fa89ae8eb539d0ed255409b0d4b0a3681f1dc4f5a519211c8efc83186a8847c9913756ab7d0614fc275320f1e8312e204e6043a11af78587f65a0cf95d55d7aa10bf3b7bec83fe9ffadfd9f6c0b7d5e01213bf5a01142a4c25bbbd865480da06eeb7b7db6943d40b60b731d5857561556d87a5288ed6b575d80b60db8c0ef59c1cb3bb43c62a35da0ca1a5fdacc0f1d5b2bd59ddeb3f4411df1e5d813f78a5ca0eabafee8c7e1a0b55b8067c9f784d9910b8d22d8224b90d89c0ce85dd2c5c2882c213d7b8a3d07c512e572c8a9696e0e8e028ea45572196fd2c8185f6ba4077e87051020fc197b21b69774d6be94b6e50d7ea64ee11515ab61fc64e6f7ec85446e7c1033fdacedf6a627e3b29d8136f45ee98f445df5680b953daffd7b625d98afafcf8b590b67aed14f8b7c50af82c8387790ea496c9ebf781ce6e31347b5b9970ee98ea734ba7f8a1a1638fee252cb38afcfd435c9acba935b15dbbac6f3197f09d4a470d9b36f3a6f27cb73d4b7e840cdc0593074bb3a07881806e614767145003acf8c8336d6827b082a23bd71fcb7665e4b4351b5b86fe7167d89fd4a93480c8807658796dcb6edf799939dad35645b23e73ace82096c83a1f92c985c85ee9c963a9b4f9e6659d3f426e00ac8bd31d9cb649f6da7a5553b2f4303697ad1bd765759aa0ed9111a7c92963d4b6f09dc60c2d71b830725b8f6c932e917a0e122372a2cb1673408a6c97ffad46e71fe989cb3f377bb9906ae8c2528a6a0bdc4bd4c2394a9b165a79b9796d769dda30a4e5e214ecac12b45912b38e367e571f2816b5be12554f19934c0e95b94532d854d8100f26d26cc4686b82e5663efda19d69c39f1f8df964f52139ddf90f5a3f1acec7f5419b1d7b5bed7601a37fa6b26d98058c60cb6da1aa740d496e08fe23222321dafc8b2ef5dafe7207a57cd2fe009eff2518b1d9dde687a687139d184723b03f6120c1ffc62fc96f243971418a10003242b9ff8c297ef036d5f014622d5e377d18eeab535043d37fda41d58656c370bcc862527040d79650060b8c54388bd4cd1b2928f1c5aef361671ed44aa181b5fc7810481d8eecdb4947c02b126fa260e3f0c65446427135c9b7d5902ed16093a750188a454d594180b968e26c21fef0984fc1be54ca52bc141d99d9f181d0691e0970dd5a28c2882085db6cf7bfd0c5573c978f938214eb2d52c499bdf9a89b8409247df73b903ce48de5f7cd945ab6be939d157cb7ca6939054940b5dfdb32248ad51323d1742e31dce87abd534bada2b7bdf2bc45927c1696eb8fa6594199014f5cd7b07b3f67c1025435518bc2aec0836925d0e94ec05ef11cd5cac5360b2ec6718f9ef989848f0578cbb0070daffd728b0ef14a95bda563173c988a81d03993b69823404ac4d56dceabf1bbbee8147675140897dc12213ce461b48218ea733f121a1322f58d0223acd6a90de5c67c10f329b5685d17d3a89c22b94f778df6d4c9ef6bac8232d22d3315e234d852ef2e610ab99fd4393da933e9cf51073b5f3d590b5ceb456b12096965598290a50749826a65e2f965cbccd3b7151e0e14489b8836cb3a5d389f42d5fb53e3677d14ac4b8bfa239f5d0412781adc3d0372c7a04aaa04b66bdc26315138da0306b387ae992e575d098e65bfb1e9939f9bd1599eb9f1f82a9e0152ae8d39c9231db5f1eec0e7eaa6816c96b0ad41fcc5c4ae38fd91fbc986fd9fbd489690e7a2bc5cb7ccb02da6bd99e6c4bc5dc5f40eb863eaae35ff9d9213c59e7885dcf6cfd59aabcede31ee3a5118747747387ba8eb269ee0e25b265a9bbc221a064b585ffcae30cf99f47f3db6b84d1aeec9c44692ceeacca71a272e55caf2be6a35f145ce28b5b3f9d210067fed63657d6a16d9f30aecc3cc5f3a9c87f5e30fa950b8b2f3a16e5103c90cdac1098c9774c89ac73d126a10aa36fca4943fcfcaa7de8733e414f4387818c27720107babbab2cfcb6c86ffb69dec906d96f52077a5f1973846206e50ffa7b1f6df1c5b5e05a8ce7db5e86171f8378a8e9bf06f240f0484720e268f08fb19a35b48481192d56cea354cdade638f090769410659706b660bd7d2831544d06f7ab99ba58e8301544426f345571c39366d420fde95da95210d4e1201ac76b987594253b8a026ca7983ec54ffa7fe1e28aceda66bae4c239cfebad4228802d6a445a1aae432b2c2cfc203d59ba2ac771a31c00c09e84f66b8b1ba4fef1780bbde37b9145d36b9e20c013a9ea0b1663cd9e27cf2298b0c97b024a5f456c500261e3fb73d72c5747cf0bfab168d0b86af86a554cff342966fa5246f810fd0301505b26cead8f37024e8c6fe6affabba731d4211afe60b6831f2ceeee91baf42a0a657358a98cf640f4eabdb3cdb38e37e45e6420086fc74e6a0b7c049c807f4050248f3cd11e2905119288950c2d5817c1677c8af8b015e1f351841f938bff6b7f702c8c391555b99dfacf06b19ef48c67f9d07a701f6a83ea0fcda3205235b0cfe8202f735266cfd4753bf0868b2fb77d29b640731fbe17f366b43f56cfa7cdf8c87d47dbdc9ff7154b9ab83618bfc80970b8f49a946c85688965923f7da71649d15176882ce3be480a20ed60960549c04fe806646b5eb7dfb9cf95742f7bdcf91bddaac1dcf48291fb62ecb5a15303dd6ce6c21ea72bef3f683df0df65ff43e0b5da22b0555fbb0e7093ac81df61b4d0c7de6f4f98dbdfadc2a82085e0e6dca0e3979bfb16e562d76e7616305b60d3dfdb70c14d9a1ff16a729cd7400846432279f68e97c7c7bfdd362cb901153e51dd56baa81ef7159738c19452ca6bed8546d9ab03cc12bc2ab252149eef44e3551c81be3f0a446e8a00d84d210cc31abc6b750172010c6b7af7d40ac2512c655285043a888e7115b46a0eb9c4913d75e86cfa17e617272107598da589b774036cac697192c6f9e54fe53ecd1c4ed1c3d3348ecccb0340582ece994cfa7544e5cbaa41051ee4ccb5d6d762e812b7d5cf8b7e76d6300ba211c48265521fdab33cd858dabc97167a0bdb78f26637740407398b7fcb78b9d435bcafb3b379fe3e5411036f48703ec672e34b8e85ea1e163f8fdeb146610cd93620ccfbfc85ae4bfdfd1ecdddc5f3c8e0fc5630ec43bfbf6708028696dfa94200db11cbdfae810e3d55ca1f855a1d9b98377b54aeaed3156391614ff1415146cae45c3f4c0e3f377f90d7e60c28c34e958c66ac091a66494a9cb1dcedfa5cb6eaa38f062664f113c3491e28606088d11e446a8cc41070298927be4c68a85cae340ee34af8e008bd1e2516534aaa3883a6f986ca290ce83bd717eaddf95888e66455619cdacc38912ffd9a44b0b072709705ff5c70ddc556f31d9e6c2b99e59bfe0272a336ec7914da06f957f27c378a6c563acf94ef5a91fa747893f2383b1ab848778abce8dc0a2b42172a7fb91d3cd8312aa98d155b5d9f13be2e5545b3d9bb3050c2447aa007575ff9aec56517c977752a13b199d82e299b253e708a21c1dd27d6659c7d1a724642b142c013122f6dde657cec6db586553b72935463668fad9ae186996ef38fdf6fde5aa8c4a7f073521f3cc2bbd9e33c4928a6a4726ce3a560659a41293701dc275c39eec03d57a359ea48ebede800e9208f4dbfb377293efad76fd92a7e6dedf8a530149879a8e50627059046c0c90e886e1790d5354e48fd8dc621596c55063784bb35c34ad25eaa8cb23a361091d4971ef7bad1cd83e23d9e40ffeb5a70bd0eeab408b4a427f6304b2ce806fdb8ed7b7e8c2102f66bda076abba771cdba1d0f5d7d456779ce8bef20929972e7417e6579a74d50245e5cbed2f04bfc519ec77c6234fb8c257515e29d1edb96ba6e551487d36a0cded60da9fa7a843f62599a1f6114afbe43b72ded08043b37e4dcef5a7802de1596ab457049a003aec15d0fa943aa0578db81492775c046217a204204ade6b158bc7c4b7bc33e771e49b9ceb385f3b6d11acd8d1c209d4b571b90174231bdbf9e4aff370b46a1e80398d19fb0399980852005063035090e408d1296d28e85dc58e90c7b68196b54faed1a22c5cc356e99822825049239b3002b946218e67841c61cb008e59c891481218da34708d17d6896fce941b7b3084a481c226827fdfe19e4c7455a6a2cedf205affaa821833b63855eb5964b074d4b475196abf9c592d54bd98cbff0d925fb36333b5e7d4fc87ba654cee389c47ac9cdf1673898e71ec8b23520386b0b0f6f9b807204d85d772383ab5d24526d6c57c87c5e2d566b58fc8f8058b38064153ab6c3a50f5f06ea4764ab9d606f6377e7a2c7412efecb71a4cb634cce3a63bf5359e8814ed77ddc6b4a40fc204d9af66876d06ecd2e40f9366c1185eaf88108b40b6f0f57f5ae175f5d46beb5036134f474cafbe8f4ef2260df5ba2da17bacd1acbbcd64ddc03746ba3e928cd0afcfa2939a8d6f11924528922d9f10ef8a312f69d8dabd8cc20de9b7fe58aaea75af2de6dc862940564c61c19754187341caa90ec381760e1c4810d8e771335ea5cb1a5c5e8e558af3069660d79e1ad66e30ac224cfab91a1bad9a4e9ea244b7aa1544ab11d44a25787bf9532f5c319e6e34f803929fa09cac811af9740548b28ed6dc4cdfac9616072f317cb0dbe1118488ab770d8576f090e58f5dfb6288f42afdfda46ed59277f7e06823e5ea03e2d414a79f454d86db3e322e1350ea893dec7099b1ecf696a4a3fb89d359fe29ab620529dc6a7dc5d632b696de9f333f506f84bca9fd7f66c936398123c12073a51e335ef3a0bf6b80055a551bd036177b7838aa07680e7f92556853232ef151caad7d7b09b9c7dc04925a835e1a4683cac902eeea199831cc929753e8c3f00114ed86bfa35e9ee4371be2bf58d159b93fbb24933a7815bb02712340282141d259a2deb9a1788ddfe75b85568bebf1452dbc3ee892c8d824cf01005c143a6cea5ccdd9a8c70e9e1b8e832bde53a109fd498af345eebeea6e5334e304cb584370ae3417a4a465ef262bbd64c2e5f6696a59991b4e9bb50a7381be46d0adc35e67276e1bcf3d34b781f788bdc0e3f6f5f21c246246eeeb28ffe8e57dd2fd09088bb2771e9c39b56726b036ee0f8fad7fa03ab203db69d4cc332b60d74e967f245f20b3d53774b795ce491603ef7af90021219ab199480c9edcafce4ff364a1e88f97350299bca866791bf4a61fa014d7d2dee73f62d8a4dd890abc2b6e781f946316a65aaa83dd774b942ff8badc448d7cfa5e9bbcd6d30af77496d69fb684e6c5a06e8e90815da8943277b2b9c05d112e3b70393cb8e0980edbfe6bd772feadb2ad553ac867b595959b3f078d0e89183854b41b4770db8a79649c5e4340bb205fb32822d4115434459be3101fb6ca248d6254149a414e482b6f602931c9e3a8ad09bd5db8def3c766799423d12e9d3af353b1861f9dccc899694c256e7eb2403edcd4c3b1dbac2a5677b44ce17dcd2995d8223608a7b6ea41bade82b2b195675775f2610ebce08eb81bc4ea253467a9f76e2701555266147b79f031ac9418b8b60433299bb850f4e463b446136b33fb58fc684de519142b477e32d11c3a41041edba421c1620f43a6813020d1d33cda7df23d2a8c24b7bd7772149b8bcb3fb28e53c0195696a648c0a7272ccdc2c78b3b0bd52b61dace9f79755df413efcfbb1ff1d5491b5010dd2dc6241c7c9b541ad5cb251b0e8e0c432de389aed2db2d339a84afc67594e460dda83c019fee3e1eb85591d0f036a09addb34b852a7bf79c21e5592fe0cdf1c2420e73293a2832b2ac6e734834cdfaada0265071f96aee6b10662747f79a4f96f51c8a6049afcc43da5b766dea3c42378dd4994817ad9ba561fbea39dc16f8f2766bc8f4532ceef2fb54e879c403e6083b757a6c6055a22c035cdb49ecba97c448263dcc33f509c5c0cbc2e65430b8f32779ba737bd292d77fb5797989090b7e126f67c321f23d671d5b80911e32ca2cdb23bc79596c9b33e5c2941eeb7b7931687f94a159b72a93142774147ddbc71f6ae38ff359bacfebd6aa33676c46703790243089ffc240a7649d4e36216948e3e9ddbb71541b022b640f90253064f0f27276cb93193b54466fe1df047752677dc29364f4bd97793a6735752f97750206c10f60316b3f8d9b9466412e997247ce9d9bc0e8754ef754110736052404af720c7f1fdd7017150160b35b6a2640b906d58475de9060c4b7bc314722e967369ac9a34cda947e542d7921a81a8d5083934e92af91841256e9b82930ca87ee8640c7ae66c5a3c3fdab86dcda30e079976d22a3cf56f9c156559828b8f7334bab35b654f018f331dca72dbbde50541b951d543284d49d3b96f1f2da217632c5e3660283d27904a56e4c83b4cac7675134b8745cdefa91c16905e16d958b0dcb29b5d52020ed7de8cab9dd8ddbe2cc6c44ed652193041e66b8ad5b86c6de0b905daaf17ff243ef2b21991da5b8a18c47f5835c405b13017d9a23fbf126c53bb2777a6d6681715da504698dbdb9d35500a9a11a4d1a41e1890c5aa928f33268c21d8f46a51abdc740aa3923f6b6e1b689af06a5cd1b983ab6111d9f89197e96accd56b7923fdcabc93f044a05902afbe293e4e17bceea5769574fc49020f2ada228b29f86e86439101eec7d551a882c8260d2798a5464341fc08b03f2a1e8d1420b00aeb0629742061b9f53ca9aafe67f06fd0e596b2f47f6197de46646ab70adbd7b200b375934a19280eb3be89c573b2b44ec0c4239f54bb158f23c06b65dd3c5c5d16754e0bc66e647409c38bad393e301cb6c511d3d4194c815b6ee562e0b3e5b1eb54782aa91a9b5957e61c9bbf37f51605e858549b4f1858455860c5ebf685d8f1c864f881e4b7e4b73cf866beeff7232c6d5c08c9b89ec81a9b0337545f8115c4fe44dd6f6147e6cb7788f7e3c1feba373da09f42d731522c32785653d33ff195bfd89f0c06892919b3a90b2ba324d0cadae87dc7d2f795e9a33abd500cdb3ed36975add5b149376a0888e6995023bb5fa7fcbfe83556309b452a436aee6e7d7da5242f03c43630c3bff362adec8ec4974e330567e81311d2732d20ec8e01c497b5fc6ac43f50208e9e11094e2b44a07dbb975e43f0eb0dcf8e9ae67391d3770db07f06166c585915d12f618a50f2c952ca38edf636caa511bdc0e70cf567fd7ab6d1280e5650f6dd4fb2e9951a012d5e2fa22a90e7e0d29637d00a0226cb13c1a90c6a7989063d314c91a4da4c65ac011231320ad2fc335fe7b728c139e58682a8aa4d296c0257234e89a8e6890ef8d982c244fb8f7b391167fa3bd52cd13704de96aab9589f7ce03532fa1b23618fd29d5d96a7ec7c43f2db64562ec1213e364f50a021c954c24f64b84332b38aff3d5bf23a2be97d23f7740a072d0e248993143a9d28afb08a577eabced00f638d953ddecd6bc8c54deae66d5d9d61f3ba20c15961270ac5e331437306200e89a2c1ba8b4748280d8092488258e7a006d2e5c47a83e02b71655ad8dc8ce9d7ae0302ca9ce3ad281fc83f71efb0f38afc85f9a02c024ea521b09aa7cb9fa6ec18b352d069adb122513b6a5c976004fa08ac546aaacad730c128bb2233b504640eb977697238304a8867e07ad5452827ce5c57f688d69f8b637231bbba36b435b4c2eb54122e20a256b316fe0b9f09ba49c6e890f1c125b3b0a54055fadf566b4116bda77d1c1f54f6179470dbc0f18a750471e97b4df70e1f7c8d65ddc7724ecde9cd8d540ecec35ea698f3234ae9cf110fbbcd70ae1e8c085abea9b8eecc97783ea2e645e696d4d62c47a714fea6c527ce28b679ab060070899611feea7a2dbea36a5e5cb0db1cc0d1954377b0b1a80063c510ef3435f8ab3c0611712212a0d3dc09efef11a5c9b2b6427913b993a6429e5dfa64530c7a064292300ac582663714d24541cbafa772c2ecfd224650ec4149d7f095af599fb9abe4ed606a3c9a01fd6fdfb8a39152dad05d896a3aa98b9b6be9484de85057d8f0a9fd38382f0a1b18ab6fe8e5feb15248b2852d4bcc5381d228f3fb833720ba581518d3ed51b7a7cbe1f1c883de8c0deaa92f34c54c14dccb5a333f84fb444fd93d9219be03045ea966a61a6fa74690c9dedfeea1ae26cc89c1e2352f9af665672f5c7ed01f12b6ae5a71563b2416fc1498d604aa8bfbefd0210eb2fa619d365dc507c15ff8a80e63e106902633f6625cb7f3a16aae1f77c8aa40d1dbe2f239219e19b2e238754b267c5c32b410592fd969ec8638dcc6c878f681999709a177ebfc6380a1edb6d88b18a8aad25cf4c1afca087d2c7297af4135394ebefb8d48785f045e894039845f0403969c4de08195ba4a280e664caa381bd709d7c9eec0f1bfe41f1569f31c57f98e3a51a1edc09c08334f181dfb582cb2c3abbf497508112620ec29490991316dce02458f3721ae0d09ac121586d5f3a83432bfd77c5487cc4cd6879f7de8737f10ca55ad7660dc66cb1060500cf5e9c0af985918520d774c51dbf55b310928707cde6b80ed4c2d5280ce9427bc3ce0778bf9286567bc07b784fe362188192180b0c726f73981741cae69be102d6fa51ded9d1d07d8f1c6ccf34e1e8041d3285d7a2e1ffab2fd909b96cad746c8c9583cbd611f00e4ed72c2d9b11db8c8f8a185b507299d124f35e17047e759729e284ca3f5c0706c7a4aea95cb944c0279106b33fb36c559a9cebb9011ec6532821684fcca72e59f709d986f69a8bce0c1567e8a2c3c239bd6f4688babbb14301ba31653cc4665540195d04a7b97adb80a8301807a2f71f3b296586ed84259dbecb51543e2d47814a6163f25c4250694560c0f6bd13a0d14137949bd3942aabee89af46cd1b044fae3eb930a1bfce61e7c0612211d38ec068089a90c4e8409c4a0ec5aad74c259357d9f6da5777d6d210cdf9fb64ab98f6efaeace77f23a73a5c5a333680c69e87460f55b1bec27fbc0173c3a491c1b82fa62a90399d7154a4540e96a7054dc34e6413ceb9e294344f2acefc9107306f49da2204f3ea2d3a38f8e9ff0a88eb2807a00c2c0b9e01cd1a95bcc825572be38f33c77fc2e9b82af06e15c3b5fbc0c4c343e50dafd03180f1975357ed2d1eedf46a947a2a4209051ed388a54477abcb3a4a36808e4e3aa725822689f861e2deba71abdcabc30af4fe2e644b11f8eb3dba80cf7b3fbf9eb7f5d378c42397cde37b33f4029548b6dbe0e9c0c87dc3bf8d516fd20b510be907bd560ba1e60f4e36a8ac3d5b34218ceac208dd732706030a712d38de4857358e94ea547688de11de94de4247fc9e50018e1d93f53e29b360673089e92c250453f0ff13e6e117ce94250076ca5e4efcb5c9f30a6fc123f470ece1f640ba2bd4cebdc6856e6e9d0a2a4d51c48f12fafef263ea83dd64fd575692ce6caf6536120393b349436cf782839950db0366b2f935f509e45ced95961f6537c461daed9f8c1d1ccfca06965ce7b578a8fca69166d700e7c5b8646b9f6cd92d88856ecb9bc70559e86dce5f8d1db1707d3cfcbff2bb7b49b189aea939f994061ae816d5016989eb581451798fb22dce881832df99e472ed1b22339b5c4d3a2f7e904702d03ac3685ab7a8d354610e846c07074af671040f9aa72f533f064a27118cb01a46817dc3997988c4a18ae0e0ead047ad1e32825f0e6393951bab272e41d94bbc47f4657b8fb65c1bed5c6cf73cbf3479c0bfcc5196af8bc3b99fb18dfdde33f2c438cf00c29e0a3481010f7348aee0894d1cd0223956ad0ad94fc70469af646c66ad124f1f7f8f98e7d49fb16df47c538e2c08e1264f4e404edddfa5cbdd5efb24b8f39164bdee556930951e1ae491608eeec5dd8a644cab8f60cb51a3ba144d1189b2a4778da5a7890888ff7d67f41195feb8ac09071403687776963000a253b3d29adfc97ab7ba383fff162b0e612b4e2c8f29e9249b7da9aa24c45a051ad1a860a7b440a0e32e579920d68c4220f7415caf8171043b87390baf3faba39fdd606567b6be277d6d2225ead573ac7b662d8f8350d2accd5efaedf0a3892379e9c33752a908c4e8353c83350c3e9901fe74bfa688d776ff6022a5212451fc40883182f03a97ffc776fff4cd9255837c86e90fbf58070b77c5ef94c8c7be4d610722aaca275ee4b9d099f2516706dd3d2e4dd1b790c35a703909fabb2c0d4e405bfee8d795e0a4cc7e64f5adc7a63d5164b195dd2eb96f64dc501916dfb83db3c7cc6583e4ba71e1c042a9fd7e749279c282ed1667f93de0921052cbb7f540f0b3cebba625084b8fafb1cbe43a377efa6e9d423dfe1ec135b5989ce33b5a35454a337e3ab1a2894f531ffd41b758fa33ed4d81da600084666b7d308928d39d57a4fc5f19959928e2b03473eca7f85e8ac4813ae0084067d9777a015715f5bd52a5e6bdeb47d89c194a01037ecbfd749c81dc6f3882b2b146770fc2c6f4696bd3367de7a344d6b2cff7087159176bf8daf3f19b39304b7e1158eb406b05bc032a3102ca08ef31b0c76c7537b60e8617ecfe1cca51127c3000d092bb871f520f027cf9e3ecc7c309bec05243c83566866b8463eaba69ee315c97011a1faad7fe85634d8a02e98c60148e0290cbc5f129bf4a4fb125ee7f73c0a1543d799cf9b78f507d0a2d243b40c574dad05cbb562a5265c7e9b222c49a66619b736447f0804bacdd141456051e51d00752c417a1e43e963b81632b0d2f55d63814f441cb13f7b4de940618773c8e8793a46ad675042bf70a1a855826f35c3ca70b87f294b21b0f7f8fe518ff659654cd88a644ba0122bb7310da8292d7e248a5b6333f2bf518e185230d8c0eb552c0863c912cecd8c0b09e5dd12755956d655dca984ff8f58f27a09abfe2dbd04228149e4bb651dcb3e5c20995177c4e041db0e5987f05cf5373241f8589357630789f4beecf54990c575ee19e44d102cbe196e9b216598534bcbba914e5b9a9db58746d31183641842e627e632ae64b68ea00bf1028b28c72692b0080e7bfdf75ebe1ad250d982afb13e0eff041ae6dea39bd81c73dff596ae04e29ab13e510524e722e32a372b94b160c62ec1874dbc6f6b78dc6060c3ee2f621c8bbfedea0307578eb17529944596d52dc9cf3ce36a23489f1f6ac8e9f875640c87277067d226467554a246446ecc26839c062f167504a18f84bc277aa36c614456cd8e0f3ae3950793b9d0338b756b275b999be099882319d49996d670bccab251c316d07a258291731841c8d4934f5e24f518e625872d38a50f60de3cf9208164a18666c6446c01e07109a3b0c069a260c15fe25c92ac258f35cce04beadd571084fe6cd7b69ff6e3060a69543e3c3487b3624989bdcfafd05946e9358c2e1ed74ecee9559bdc96999ef308348d3d30b3b4bed56618d2ab85265575fbf57cf04e9727ebd4047b619e820f7392f794cbae73820f1a4dddb39beef22cfaa43e0bea8b69edeacac9f1ec94963f97e847037729dc41087632b491a497abf2cce87d3c8bfc1e1839ed3ca39aa07c38bdd0a716082ed14b4215107785393c572f2681b960944a5bd236976dd64033ef413be6096e44535e5f80f82388353d12094201cafafa91b5376c85949a3887b43b3230f11019f070f5ac8721f5ee403a431d2335d61303392077d836519df7e9ef24f934e1cb280f3317024d29086fe92be30717e9efba8d6eb07c41fd3a6dea96187de1d2ffdb63b04d48f67772b11a6cb34481ef41f990599e1e86752375526784a3c1f4d97b331c1fe66e325978ac95fcadee4000884a771d48dc3ce951a2c9e2f40eee6419948a0941d2743a3c5fb951c0a6770d012693dda2aa872fb47f22567cae362b4828dba8a8347fdcaf136574553e7c3b6794d13d19d2244139fb9732c6ddced4d823e4cf055d3d8c1f73915e837a6e0149255ca89dfbc9ba0e2bd03714a494b0877276524de61b26bac8cd51f55880bcce5289638aa7ec1bf01ff981c5a02bf6268aae8de093187c876595bdddbe1d85efae6bf8f0d6bdb8f1ca6a04489516d637c497ff04eb10b98231b11ae7b841709efb0c84fcfb9b45b50f9090bf4330d72adac441dcbeba3a05922cfa9661cda0c0213044a8f76f71e401800d733fc496316faa2ed4300e38e5d06aba03c22a60e319e59433fc794cf41555549896b7375cfed93906240286b97a608db0049c46d159d1af37c8bcde7f21d3595ad168f9e0e1a4808d3594d66b7abc82f1a6b26a1020d41c3c514e0f74c90e6e8f90923f97b1d1c68e2d5014b4c39e1f141481afe00ef0d661d9e7b7b406a05b27cf1c199b21cc989ecc0f11283d59dbefa13b3b3e42f316cb65b9fe685b3990a502e998c208bcda8bb6e2b005bb3f41b0fdc981949b0333280dd8154f4a58055e287ce4692ce17f75fe4e4363a687768368ff79d60856a1426546d91d501cb68528ad4bdba7c444cdd66926da18092a8eb2ab989029a03e8294bd288b07716737a010385f3788777be8fcc15a8a003f27eb855f7807b78948ee62546c22e2a9d9e986e011e942969c9561c6d3bed28b5f1ea2ed708af3a4b9d8442527d683f2af2ff0f19f5cdddd23702dac08cd3604ce8850c24134eaa883cb39a9d6f3eb2e0975201c806f7c8b237abad30f6261704960b0c859ad26d696e5ea9ec129890ae7b90110902c4ed91aa29563ee9b07e73534f2a48e1a48881cef1bf1a597006b778cb1861f364749880806355d95898cf1a622e5d323452b576741db3cd4ea3c3502fab211755a686cac6ed4479c67636b331c81e84072f6c510e9f42cd50bdf80c1bcb5fbe3a7bb1715afbf89443c08bbb2680588ae67a442e16d4677e345b0509a61d30e5f93414f4b535ecf4797f4ac1b9f2c66d13963eb36bd789c6fc90e79c9021e057df0b6a28c2febef82ca6247a6fac2ef981f2cb13e4ebd5273ff0155a173c85b7525a0401d00a5294f11e295b9d9230c20aee4cc8e17135e5a6484eb43a9a2dff0e9a776ca3bbc0116b24a1230e20a21ad442c2c0e9cf23227d9c74a87485e223d01bcebb5584eccd173f572f00c03187bf0b3a6f01da929040165ddf2da37cc04baab1ab65dea89e4ec45d18c78f6feecb33be606e3c724d914ebb81d9b2e4b21657a0c2d80e0ce3d66f9b5e2a090804a17c487107aac548c011379e2c14fa63c08dc42f95d673da6fbb601f56764bc54741ae4c99a753df9e472768ddac6e05de8de89a6450eacfd96b1f86658e733f5f9c3fb0a48babc6a474b17d518101cacc59e42dd0d22eb29fb9c9f281861dc9e38d2162b2ddad5af5a4b0882f7fb78bc431ad08eece35fa3d6fdb82b01630edd437613fd7200ffd262fa3c30daa5d9eb6746d421cf00b4633a3d869f33794a0144f0dd84a1dff5c0622ca345b0a2938040e70be33ed44c4f43c4addbe087942343fb326450946880b253a96e9691cc2dc6f1d67164887f36be09464cf65b571c123880b400fb6992b533e1f54f939da2f00d4ef68da75ad8f13d4b132e72ecf97752d3a6a46dfe7a1a17e533c0554fbd4296fed20664789062779a328ac65173ec7ded581d4710fda8d2aaf6e8a4a3f302722859caeeccf30f93218352641c32ba67dffd90838e36a735fe319b9b3237a9d3a1aaa332131db6ebc98e051d02d9593e1fd831a457465f2f01c7ff18f0f4819a6527c270fb83a6bcb0478e1bf2287dc1c43c61cf8bc241afd41841373e564d81f1c4ba420a6e71b068bfa6c501ed4d9e9d2be32e6821248821afb7a41a9f9152254ecb53c15cb2b453db2624ea39c534318f8d82227046c4c221d8c3c72ef47928ac3574f1df75d8b9e706df6d71208cb1f1e2b02daf03b5c40d0bcecaedd01961f1c529c76e87eda4361f14790ab7394804094ffe72a12f43514761fb8626b6efa2038d208beae9b3741e2f7f89199ce19521beaf5dfab65cd1a996d9235cb0c2d1a317270c3066a5a7e10c5c07a8517de954dad4dd801eda0c56201bdb05d5dd2ab9d5c714dd2c681ad80cde51ce503056defda8916a91b6223312fce40a2efdfa673af7153d26dd00d0f8f9548d864718e37ae77792f0b2f1ebd15536e2eab78611f5731947debe7f2865bbc12ed2df4c6b979a6eec953cafded230dcee32757228e93b7464ff4d70ce26dbe9f36f063584a5bfe611eac3aada03446a496d66353b62da3732b94e999699e123f04cdc52e7435e27f531422ecac8f975e050e04e402a8b044d5c138d43bdbc529c2bd33cc5d289dec0267a15834e25f8186fff7ff7b28b666d89a9c147e91ff11954bd7ad58dd0a9b64d8d62cef3b1338c793fefef81864607cefbf42345e1929170aecf64d76429d8b9c5d46d4f810b44177c9b49ce51084118516150c6eee2313f668ddaa7bc95ce7427cb7876282ad0e5dd8c7ea32272866dace65fbfd784964de578b9ad3a4cfad36202f0c4a9e21a20817764b4f8d51716c1a53da492be3eeec89308c0f282c9dda08d451b0bec08925414d7de85baf1a25b2df1e064841b8e3b1a54bbbbd28ac2a472ca53b3a562de916208b2e5fd4e266b4e5c871303538ded890008d06eadbb72eee48acd9202c8d842c6b8058f2869182b352f1eda0744a70a84206643f81f3a3ff88cd8fa20c673f2d556cb5bc4c2f8b73cab62f5e95b1c86115eafb0798ec26b69b9143556c28d601d3df060a7f66d7a04f86d643bcb5b2203461b45468c410d0d8ac00a4dfb7f152fe19b7249e96f7e95f26b3171de6dcbd60f948ecb02940eaf5ef7b0f174a4c9c6369aa5acddbdcfcfc7d10dbbd2bb2a37ec89f0a3678f0e13afbba2e93d6ca70262c61be1984cddba702a9b03249ba78f10e42238147473d46c4d83f6267e3b9465feb61709cceafd55b2e40d0f7f6dec8872bc3ce5d76bd95c74bca04acd83553fd8ef3de43c7ab75c563b92b4d1d4574ff1bfc30ca7cff34990827a415544dc3aee8dd4fa829fdc73a90e417be10d0f3b4940dfeaa1b63e342124a549632774e1f8b4ea8551ca0c5db23af8f9d4904b1c856fb1af5b1765e6e10c50f501cec51251ba43065460c4c28c62c6e78c608020d05908569069e923f62f4df9968c5e8cc85ddd1a24b3dfa5bcfda1c63f5c6a5586bcb442edb8477aed80beb98f41199bbbc651faf831da597952b2dcf9827fdcfd7ab73501c12d48290cfa42d54a9feeec882aac8be93cefb68b7df376f08ca181245c161f80f20aa18ed333545a7112d80bd13f7288117ba293e2dbdb89af2a360e95bf9104cf752a5ac0332af003fe04c415958454fd420ae8af4a590a891295c916a1b5ca1575fc907f8ab95b1f3475dbc483f4c4633817c248f7faf20f3e0179497d771d10f982113a7384c0da912e5208c14b3b1b747a43db2bc08f902eb9f0e8ac70ff416041e8f34b463ba0d63ae6e80d7835f3befc3e70f9df6c5384c82313ea953d482c3dc26e75f8e73f6b993b44f20b829b8a60cba964175088d874e762dee989a97e071d36bd3fe1054644594db29ad2dad2daf6cc9e98ce72f6b777246fbff8423431322d63dcc6746b32230ddab0e24699c3e729e81f630689f5683f987144eeba2c4767b615dd1027faa69ec220499be0218e66f0c7b9c97fc10716c60c47ddf165d4dee1157e93dd49568d1f930b9a86d02f7b30ef4fc98ae9fdcf2b0e38a40b6f10741c5ec1303c6d324e178b4d502328f6b4702413f29466fc7774d3a64a0770b39caec7e594e37a6a10f925e3a000c50da50d4fd56b24327b2ad8d9ba29aeb4cc5ada1cac2850c0cfbae38774dc3ba2e27f2ed71abc582da19b0bc57a6281241a548895f81ed1180a2b24499a02b67bea809269ac68b0830db4fb8be4bfcc87e278142f189c71069a48e3924e8ab44e32d2f8eef816b59591175c426a1ef5c7959bc219f895a80640512324fb81b8732cdcdde03ff0a6af260ea81f5379f7badac712b9822bd66f749473fd7b863f3cf1f04d8bb9607e471c0751eac01fc8c93bfeb3325c38b5dd370977fa1633fcc790722693b779ca576136e7423e4e5979bfd8e14905f9b5357af7693cc4d8c5a84bc0649ee9241f3814513b77f950bd3728d2377e543349a1a90d78e282350b331bf9de827780a6d63674993168a8d8a1fa759cda1e6c0afe0be05e14cda543f5256fae8c1dbedfddd1e5ad8662a35f9baaf8858965084f64d6fde2d48008c0d949c02a1e01bfac4ef2d96d83e45c4e72dc00ee043db90d055f918a1c0dae749391fd432e898f19629229829e56380ccdc208b49bcdb6606383ba481bc4be2187af221d0f8579148dd66dd68041bf92e3ff078df9c5df6164129ac31e21238169b163410e2a98163a1523cf3cc1cecfbd5ca7684ab88025e11abc05fe8c52ff68441efff3714e54d9e0417a1425c5f4f1d0e0dfa1868863ca918fec1f5a8e0b21f0ae749fb9295f85c25a4e289d8c0ac32d291f36e0e40ac6d92a227b2b70b8435fecb064531b84263e9dcbf45cdef9cb147f8a87608772e51b4ba2d86978e4102291c858de0eb0a51068d2dbf2ec3298bb593906f83b36484a9ef0019b156abc13a7cf84f7b36199315d609bbca4820beacbf30395b560809ea6acb24e546da890080cee950df19042d6f58acf0d3d0bfb51f02a8e54f76205ff34e670aa75199fc8b4e9765864d8f5601b51f3dc06c9734b322ac4bb5fc4f7059f3ed147169201209b4ea02cf358b5b0ddd6c9890096325e581a5db36dc3225a00ca4be484d58efbb25e3fe537e96e916f0cfca18b8b48bb3f6d9e9243bde52698027d1ae1c050722cca64043a77b68a9b0221b1e02a1eae592186e858d433861679045e6db6f68d3c3dac81a0eb4cf1033329bfb294e4d0d823857c6bc88770f11fb0d1004a410fcd26a5411acb8d85a0c3c188d3ed77c13f7c65c0afb93429da02d6b082c766a46165b91b8a44573e68cd4617bbe673528cd09399890af88c50ff54bfebdcfeda611a7cc5f48f0a67a66ffa9e812e8d9c110309ee9c8a11c9694317b00abb81279ec2f5dd5f52c0f17ea50b92253da2d62318daac6fce4f183302fd9241c03c4cf599d8689bc6afa7257b6e445ed97879daf3ea4fc54cbe441b39838a4449747d1f6c1b5263aa19e4288007888b795549a9f8f68def34ec583a3f88e1c0b9a9b5204a6caab1af4e0207024276fbc31a015e9c86d723dd032d5a57f4064823ab5afedc2e461fb8bbd78402ad3b9d9cbc01afb755b63aa9b0685fc540a24d669d3279fed66609863606aa934fbf0ff767a5586dcbf9e5c0f947ca68d524e36989ed2fd504ad21a3164b7a61bb64a2e761cd81d3524fa7c41915d1620cfa5f9c583be3e1ac14c0c82635c755b954e9ab017a25d35d275b8848051fa154620b5e9db540a9baf6f034b0eed0d88a423a41da50d769467bff952541dcddf5d8fa8b4b4f97fa4634fa1118712eae5c2fcbd9d6762ad60f909f087e4ecf7a97a1d2e885e720ca8bbecb04500277ce1ae37882d034de86b3e6870377889b4a82e83b29b05438b6b2a3811403da177744347832ed885bdb25cbe37ee9d092a2fd0df58e064fb42969ff20c39e915fb4af981a28d032350d3c23f8259a5d7bcdb7544f7d6a815bb0f822e720cf6087d0dc5627b4d2f01d074ef50d6fb5f17794bfd07c446bfa367376aa44b801eb7e30bc5107fccc546c16c52b06e76c4830ab2f8daba95bb0f3a6a5991c267608b0e37a66099e2dc6f24f75b9fb4b3edb65d3a4d9850d487323da40e7cf87da2a7580f0b7da764eb92b9a3053e7e55f0d6f45ceb0333e8050ea6f8b7954bc22075fd3b619a6b09594a0be2aa94da2fadc9cf8e86bd4845a1ae32e571d589e4f59b3edcbcb106dadd32c21c8c476261b7396c924317ed821f4b414d83777a4a5d0db38fdafe99febdf68376631289ba334bf7da9d19ad3999e41348da8bc95b294beaef0e933914029e5e7b8f1ec3086f0dd1f8303f8f6620bbd6c5bae29356e61a1b2b8c8f368547373f4205c3c989baa78e1191da15c4e48c5e98b0d94164613c248516aad49b172d6d0e7afe12d81358cfc0359719e12fb76f36c9629419071511329e0fb9fe544cbec302eb6b7f73fa226f7fd7c662cd248e8cc46a3bd640b9c9677a77947f545cc44a054192a1f7641729f9eed9e9188abe61fabc1e8aa984dfd779d6b0b93f78a089d8187634315aaffabb80e19a1cb8cd15d160937ec91c1097ebf119a296b07485eaf9885760f5deb6a389f534b2679322156b7444a4e8bb34f4ec203156495336766009bec24c2b26acae5894f30025b7a9d28d344f23e274e36071e125121471b585dd1bf65f6b19acec147a948be300cc42b07460aa6bb1a29233fd085fdfe7e15a442c1e6f1af8c9739c54709b70683649e7363fd6bd9d00bbe7846c948ea9eb072eee4fac07a2efee6d7392062ed28643e6c56ee1d021277f08921fe59ee61e07ccf28e5d87a7a6aa514a69196669e600fddc0d51f6da190ecb56a2387fc21b7cfddaa01d4f4f9b0cbb3bcba19fc57439af6aa4bfe9cd2da0fe1d6287f7558ba05adfcb2896e877daaa1635b56cff8e3071da2ce3adf307226a7e2c88f33cf485a9eecbf27b4e986ddfa67418534a8f116a93682f414dff1c458c4f1ba3f342a9228549bfd603078d07061da145dde4ee6021d76bd6df943e5c8ac0a761803387b46a5c166277d4e5a67698608a76045bf4cb81c821f9133a511efc687362d32435f0f2ea6e5cfb24dd2aa201439c7c5cf30782e1b5e16260679ef77bd7abd4b78f153ec69d2e054c520c5d5031809c781e1799705561ace4679dcf33875c334f8a62a9ea0a379c83dbc0dd8359174403e241f19d70abf4b7381810f63462d779543b8f37cb344bd28906139395e8d568fc3cc2a12c77caca902c0aa0a07fd001042182f0332b3812d65ceaeddcbe3f41cade320cc6f15fc245895c5c4f820372155a785f488e54f8d0453d1094448d61540bb8c629a5295156095b036b61c9d6f631fb65293ec16e46d69eec2b025b82b4daecaaef5999df5c99849f07537e31d2bf1d4b70dda3b7cd651b04a0c334e3f05b02dbf6a6868f26d6e9ce254c583653932a3979e58c023582e976cd8185e491d10a2a57d6504204ea005dd8599f3427fde2b688c9d06f6de7e9425b8976b21e9de305f600807b0c1b09148277741a9ab9b96618d03a1d457af7dd7bcfb1afbe8f0b4716a660c8e3b8b33332ddf043857b594fa841dcecd3ebb3bbc9ca310c541ed583bb94ee37875d405b12bd0453546cf0601569238791ec898521e3ef8de5b4156aef5502fddfba88b723561b5b791e024ce65dd3a888b6abaf6550e579a73a5f88537d6966ad4232f9606412c863239ca8f0a070df60b32739dde141fe1f14ac9fd402e0d1702fb1796712c54803fa4f979b12afd0b63bd8bef38813c0c651e0503f058d2a8120249337ba7b09e89e736d3b2ef11b87c117def03a1ce67709a756426e5afe91fec17929e4e8905a058a6131ee3ae14e58f63a81d6f18d54cf9aaf0028eda6c065ebbfe0eeea5b2b8d88da14046847a58c9f4825f82c9af4893184726824c867e0aba615b6344529319e11c3396a42d97705dd31555af7e05b40637c033025ae1d82230f3edda382c482c9adb4a91e42d7196dd463b48fbeecc895a6fe6429bd12002716aa10424645adebe512c6314cecef677cfe6c62d8c2d106d7ed5ce92dcd55e80a3c766f32d1b9b288a63cfdf868cb632914a464646252839312772694e9220bcd748f033830f82a25bc2f3b0e9d86fd78bf37b7beab07f55d0b425b0a9b9842b08de52828a3cbfca156f44c14e9fb6a45be40145b1d76c48ec1bef40d022d7875e76ea550376b8ab110f1d4c460a005ab40b49484cbc985aeb9e6418bbb67bf4b4c39e882ba91084de9662c2ded559e4ecd5126bacd38afe57c017f70ae984432ad57481ef9940e79950051c9bcf9691703fb67a984538563a820783eb0b51a95ebedca9893132a8268935ace2cc95380f02b8c155874007c2182b4a48b18cd622b998bb371e181f37d16b4ee5437ecd419c865900b549a14b9b3ae03399b324458ddd96a1e9d163c8532e19f64e778ac71d8c8ac6072396c5a5d9337704fd15ffb8407cb22b914033fe85382d04f9899b2d13091e03cc4cab0bf1e84f6767c0e29ecaea8f5e9d0cf07be7fc715eb8b1e44754edaa0ccc51c5cebbd29d1349658869b160eaa225f56af4f30f0e\""; diff --git a/primitive-types/impls/serde/src/lib.rs b/primitive-types/impls/serde/src/lib.rs index 22a17114c..661ff7c0e 100644 --- a/primitive-types/impls/serde/src/lib.rs +++ b/primitive-types/impls/serde/src/lib.rs @@ -19,7 +19,10 @@ pub mod serialize; macro_rules! impl_uint_serde { ($name: ident, $len: expr) => { impl $crate::serde::Serialize for $name { - fn serialize(&self, serializer: S) -> Result where S: $crate::serde::Serializer { + fn serialize(&self, serializer: S) -> Result + where + S: $crate::serde::Serializer, + { let mut slice = [0u8; 2 + 2 * $len * 8]; let mut bytes = [0u8; $len * 8]; self.to_big_endian(&mut bytes); @@ -28,16 +31,19 @@ macro_rules! impl_uint_serde { } impl<'de> $crate::serde::Deserialize<'de> for $name { - fn deserialize(deserializer: D) -> Result where D: $crate::serde::Deserializer<'de> { + fn deserialize(deserializer: D) -> Result + where + D: $crate::serde::Deserializer<'de>, + { let mut bytes = [0u8; $len * 8]; let wrote = $crate::serialize::deserialize_check_len( deserializer, - $crate::serialize::ExpectedLen::Between(0, &mut bytes) + $crate::serialize::ExpectedLen::Between(0, &mut bytes), )?; Ok(bytes[0..wrote].into()) } } - } + }; } /// Add Serde serialization support to a fixed-sized hash type created by `construct_fixed_hash!`. @@ -45,21 +51,27 @@ macro_rules! impl_uint_serde { macro_rules! impl_fixed_hash_serde { ($name: ident, $len: expr) => { impl $crate::serde::Serialize for $name { - fn serialize(&self, serializer: S) -> Result where S: $crate::serde::Serializer { + fn serialize(&self, serializer: S) -> Result + where + S: $crate::serde::Serializer, + { let mut slice = [0u8; 2 + 2 * $len]; $crate::serialize::serialize_raw(&mut slice, &self.0, serializer) } } impl<'de> $crate::serde::Deserialize<'de> for $name { - fn deserialize(deserializer: D) -> Result where D: $crate::serde::Deserializer<'de> { + fn deserialize(deserializer: D) -> Result + where + D: $crate::serde::Deserializer<'de>, + { let mut bytes = [0u8; $len]; $crate::serialize::deserialize_check_len( deserializer, - $crate::serialize::ExpectedLen::Exact(&mut bytes) + $crate::serialize::ExpectedLen::Exact(&mut bytes), )?; Ok($name(bytes)) } } - } + }; } diff --git a/primitive-types/impls/serde/src/serialize.rs b/primitive-types/impls/serde/src/serialize.rs index cc8da52bb..1dc627927 100644 --- a/primitive-types/impls/serde/src/serialize.rs +++ b/primitive-types/impls/serde/src/serialize.rs @@ -6,8 +6,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use serde::{de, Deserializer, Serializer}; use std::fmt; -use serde::{de, Serializer, Deserializer}; static CHARS: &[u8] = b"0123456789abcdef"; @@ -37,14 +37,16 @@ fn to_hex<'a>(v: &'a mut [u8], bytes: &[u8], skip_leading_zero: bool) -> &'a str } /// Serializes a slice of bytes. -pub fn serialize_raw(slice: &mut [u8], bytes: &[u8], serializer: S) -> Result where +pub fn serialize_raw(slice: &mut [u8], bytes: &[u8], serializer: S) -> Result +where S: Serializer, { serializer.serialize_str(to_hex(slice, bytes, false)) } /// Serializes a slice of bytes. -pub fn serialize(bytes: &[u8], serializer: S) -> Result where +pub fn serialize(bytes: &[u8], serializer: S) -> Result +where S: Serializer, { let mut slice = vec![0u8; (bytes.len() + 1) * 2]; @@ -54,7 +56,8 @@ pub fn serialize(bytes: &[u8], serializer: S) -> Result wher /// Serialize a slice of bytes as uint. /// /// The representation will have all leading zeros trimmed. -pub fn serialize_uint(slice: &mut [u8], bytes: &[u8], serializer: S) -> Result where +pub fn serialize_uint(slice: &mut [u8], bytes: &[u8], serializer: S) -> Result +where S: Serializer, { let non_zero = bytes.iter().take_while(|b| **b == 0).count(); @@ -79,14 +82,17 @@ impl<'a> fmt::Display for ExpectedLen<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match *self { ExpectedLen::Exact(ref v) => write!(fmt, "length of {}", v.len() * 2), - ExpectedLen::Between(min, ref v) => write!(fmt, "length between ({}; {}]", min * 2, v.len() * 2), + ExpectedLen::Between(min, ref v) => { + write!(fmt, "length between ({}; {}]", min * 2, v.len() * 2) + } } } } /// Deserialize into vector of bytes. This will allocate an O(n) intermediate /// string. -pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> where +pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> +where D: Deserializer<'de>, { struct Visitor; @@ -100,7 +106,7 @@ pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> where fn visit_str(self, v: &str) -> Result { if !v.starts_with("0x") { - return Err(E::custom("prefix is missing")) + return Err(E::custom("prefix is missing")); } let bytes_len = v.len() - 2; @@ -115,13 +121,16 @@ pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> where b'A'..=b'F' => buf |= byte - b'A' + 10, b'a'..=b'f' => buf |= byte - b'a' + 10, b'0'..=b'9' => buf |= byte - b'0', - b' '|b'\r'|b'\n'|b'\t' => { + b' ' | b'\r' | b'\n' | b'\t' => { buf >>= 4; - continue + continue; } b => { let ch = char::from(b); - return Err(E::custom(&format!("invalid hex character: {}, at {}", ch, idx))) + return Err(E::custom(&format!( + "invalid hex character: {}, at {}", + ch, idx + ))); } } @@ -146,7 +155,11 @@ pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> where /// Deserialize into vector of bytes with additional size check. /// Returns number of bytes written. -pub fn deserialize_check_len<'a, 'de, D>(deserializer: D, len: ExpectedLen<'a>) -> Result where +pub fn deserialize_check_len<'a, 'de, D>( + deserializer: D, + len: ExpectedLen<'a>, +) -> Result +where D: Deserializer<'de>, { struct Visitor<'a> { @@ -162,16 +175,18 @@ pub fn deserialize_check_len<'a, 'de, D>(deserializer: D, len: ExpectedLen<'a>) fn visit_str(self, v: &str) -> Result { if !v.starts_with("0x") { - return Err(E::custom("prefix is missing")) + return Err(E::custom("prefix is missing")); } let is_len_valid = match self.len { ExpectedLen::Exact(ref slice) => v.len() == 2 * slice.len() + 2, - ExpectedLen::Between(min, ref slice) => v.len() <= 2 * slice.len() + 2 && v.len() > 2 * min + 2, + ExpectedLen::Between(min, ref slice) => { + v.len() <= 2 * slice.len() + 2 && v.len() > 2 * min + 2 + } }; if !is_len_valid { - return Err(E::invalid_length(v.len() - 2, &self)) + return Err(E::invalid_length(v.len() - 2, &self)); } let bytes = match self.len { @@ -189,13 +204,16 @@ pub fn deserialize_check_len<'a, 'de, D>(deserializer: D, len: ExpectedLen<'a>) b'A'..=b'F' => buf |= byte - b'A' + 10, b'a'..=b'f' => buf |= byte - b'a' + 10, b'0'..=b'9' => buf |= byte - b'0', - b' '|b'\r'|b'\n'|b'\t' => { + b' ' | b'\r' | b'\n' | b'\t' => { buf >>= 4; - continue + continue; } b => { let ch = char::from(b); - return Err(E::custom(&format!("invalid hex character: {}, at {}", ch, idx))) + return Err(E::custom(&format!( + "invalid hex character: {}, at {}", + ch, idx + ))); } } @@ -225,7 +243,7 @@ mod tests { use self::serde_derive::Deserialize; #[derive(Deserialize)] - struct Bytes(#[serde(with="super")] Vec); + struct Bytes(#[serde(with = "super")] Vec); #[test] fn should_not_fail_on_short_string() { @@ -244,12 +262,20 @@ mod tests { assert_eq!(f.0, vec![0x1, 0x23, 0x45]); } - #[test] fn should_not_fail_on_other_strings() { - let a: Bytes = serde_json::from_str("\"0x7f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587\"").unwrap(); - let b: Bytes = serde_json::from_str("\"0x7f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587b\"").unwrap(); - let c: Bytes = serde_json::from_str("\"0x7f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587b4\"").unwrap(); + let a: Bytes = serde_json::from_str( + "\"0x7f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587\"", + ) + .unwrap(); + let b: Bytes = serde_json::from_str( + "\"0x7f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587b\"", + ) + .unwrap(); + let c: Bytes = serde_json::from_str( + "\"0x7f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587b4\"", + ) + .unwrap(); assert_eq!(a.0.len(), 31); assert_eq!(b.0.len(), 32); diff --git a/rlp/benches/rlp.rs b/rlp/benches/rlp.rs index e874cb0da..6f6402a99 100644 --- a/rlp/benches/rlp.rs +++ b/rlp/benches/rlp.rs @@ -11,62 +11,81 @@ use criterion::{criterion_group, criterion_main, Criterion}; fn bench_encode(c: &mut Criterion) { - c.bench_function("encode_u64", |b| b.iter(|| { - let mut stream = rlp::RlpStream::new(); - stream.append(&0x1023_4567_89ab_cdefu64); - let _ = stream.out(); - })); - c.bench_function("encode_u256", |b| b.iter(|| { - let mut stream = rlp::RlpStream::new(); - let uint: primitive_types::U256 = "8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0".into(); - stream.append(&uint); - let _ = stream.out(); - })); - c.bench_function("encode_1000_u64", |b| b.iter(|| { - let mut stream = rlp::RlpStream::new_list(1000); - for i in 0..1000u64 { - stream.append(&i); - } - let _ = stream.out(); - })); - c.bench_function("encode_nested_empty_lists", |b| b.iter(|| { - // [ [], [[]], [ [], [[]] ] ] - let mut stream = rlp::RlpStream::new_list(3); - stream.begin_list(0); - stream.begin_list(1).begin_list(0); - stream.begin_list(2).begin_list(0).begin_list(1).begin_list(0); - let _ = stream.out(); - })); - c.bench_function("encode_1000_empty_lists", |b| b.iter(|| { - let mut stream = rlp::RlpStream::new_list(1000); - for _ in 0..1000 { + c.bench_function("encode_u64", |b| { + b.iter(|| { + let mut stream = rlp::RlpStream::new(); + stream.append(&0x1023_4567_89ab_cdefu64); + let _ = stream.out(); + }) + }); + c.bench_function("encode_u256", |b| { + b.iter(|| { + let mut stream = rlp::RlpStream::new(); + let uint: primitive_types::U256 = + "8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0".into(); + stream.append(&uint); + let _ = stream.out(); + }) + }); + c.bench_function("encode_1000_u64", |b| { + b.iter(|| { + let mut stream = rlp::RlpStream::new_list(1000); + for i in 0..1000u64 { + stream.append(&i); + } + let _ = stream.out(); + }) + }); + c.bench_function("encode_nested_empty_lists", |b| { + b.iter(|| { + // [ [], [[]], [ [], [[]] ] ] + let mut stream = rlp::RlpStream::new_list(3); stream.begin_list(0); - } - let _ = stream.out(); - })); + stream.begin_list(1).begin_list(0); + stream + .begin_list(2) + .begin_list(0) + .begin_list(1) + .begin_list(0); + let _ = stream.out(); + }) + }); + c.bench_function("encode_1000_empty_lists", |b| { + b.iter(|| { + let mut stream = rlp::RlpStream::new_list(1000); + for _ in 0..1000 { + stream.begin_list(0); + } + let _ = stream.out(); + }) + }); } fn bench_decode(c: &mut Criterion) { - c.bench_function("decode_u64", |b| b.iter(|| { - let data = vec![0x88, 0x10, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]; - let rlp = rlp::Rlp::new(&data); - let _: u64 = rlp.as_val().unwrap(); - })); - c.bench_function("decode_u256", |b| b.iter(|| { - let data = vec![ - 0xa0, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x09, 0x10, 0x20, - 0x30, 0x40, 0x50, 0x60, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xf0 - ]; - let rlp = rlp::Rlp::new(&data); - let _ : primitive_types::U256 = rlp.as_val().unwrap(); - })); + c.bench_function("decode_u64", |b| { + b.iter(|| { + let data = vec![0x88, 0x10, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]; + let rlp = rlp::Rlp::new(&data); + let _: u64 = rlp.as_val().unwrap(); + }) + }); + c.bench_function("decode_u256", |b| { + b.iter(|| { + let data = vec![ + 0xa0, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x09, 0x10, 0x20, 0x30, 0x40, + 0x50, 0x60, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x12, 0xf0, + ]; + let rlp = rlp::Rlp::new(&data); + let _: primitive_types::U256 = rlp.as_val().unwrap(); + }) + }); c.bench_function("decode_1000_u64", |b| { let mut stream = rlp::RlpStream::new_list(1000); for i in 0..1000u64 { stream.append(&i); } - let data= stream.out(); + let data = stream.out(); b.iter(|| { let rlp = rlp::Rlp::new(&data); for i in 0..1000 { @@ -74,16 +93,18 @@ fn bench_decode(c: &mut Criterion) { } }); }); - c.bench_function("decode_nested_empty_lists", |b| b.iter(|| { - // [ [], [[]], [ [], [[]] ] ] - let data = vec![0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0]; - let rlp = rlp::Rlp::new(&data); - let _v0: Vec = rlp.at(0).unwrap().as_list().unwrap(); - let _v1: Vec = rlp.at(1).unwrap().at(0).unwrap().as_list().unwrap(); - let nested_rlp = rlp.at(2).unwrap(); - let _v2a: Vec = nested_rlp.at(0).unwrap().as_list().unwrap(); - let _v2b: Vec = nested_rlp.at(1).unwrap().at(0).unwrap().as_list().unwrap(); - })); + c.bench_function("decode_nested_empty_lists", |b| { + b.iter(|| { + // [ [], [[]], [ [], [[]] ] ] + let data = vec![0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0]; + let rlp = rlp::Rlp::new(&data); + let _v0: Vec = rlp.at(0).unwrap().as_list().unwrap(); + let _v1: Vec = rlp.at(1).unwrap().at(0).unwrap().as_list().unwrap(); + let nested_rlp = rlp.at(2).unwrap(); + let _v2a: Vec = nested_rlp.at(0).unwrap().as_list().unwrap(); + let _v2b: Vec = nested_rlp.at(1).unwrap().at(0).unwrap().as_list().unwrap(); + }) + }); c.bench_function("decode_1000_empty_lists", |b| { let mut stream = rlp::RlpStream::new_list(1000); for _ in 0..1000 { diff --git a/rlp/src/impls.rs b/rlp/src/impls.rs index 3fbf3cf20..4f30b8a59 100644 --- a/rlp/src/impls.rs +++ b/rlp/src/impls.rs @@ -7,14 +7,14 @@ // except according to those terms. #[cfg(not(feature = "std"))] -use alloc::{borrow::ToOwned, vec::Vec, string::String}; +use alloc::{borrow::ToOwned, string::String, vec::Vec}; +use core::iter::{empty, once}; use core::{mem, str}; -use core::iter::{once, empty}; use crate::error::DecoderError; use crate::rlpin::Rlp; use crate::stream::RlpStream; -use crate::traits::{Encodable, Decodable}; +use crate::traits::{Decodable, Encodable}; pub fn decode_usize(bytes: &[u8]) -> Result { match bytes.len() { @@ -41,12 +41,10 @@ impl Encodable for bool { impl Decodable for bool { fn decode(rlp: &Rlp) -> Result { - rlp.decoder().decode_value(|bytes| { - match bytes.len() { - 0 => Ok(false), - 1 => Ok(bytes[0] != 0), - _ => Err(DecoderError::RlpIsTooBig), - } + rlp.decoder().decode_value(|bytes| match bytes.len() { + 0 => Ok(false), + 1 => Ok(bytes[0] != 0), + _ => Err(DecoderError::RlpIsTooBig), }) } } @@ -65,18 +63,19 @@ impl Encodable for Vec { impl Decodable for Vec { fn decode(rlp: &Rlp) -> Result { - rlp.decoder().decode_value(|bytes| { - Ok(bytes.to_vec()) - }) + rlp.decoder().decode_value(|bytes| Ok(bytes.to_vec())) } } -impl Encodable for Option where T: Encodable { +impl Encodable for Option +where + T: Encodable, +{ fn rlp_append(&self, s: &mut RlpStream) { match *self { None => { s.begin_list(0); - }, + } Some(ref value) => { s.begin_list(1); s.append(value); @@ -85,7 +84,10 @@ impl Encodable for Option where T: Encodable { } } -impl Decodable for Option where T: Decodable { +impl Decodable for Option +where + T: Decodable, +{ fn decode(rlp: &Rlp) -> Result { let items = rlp.item_count()?; match items { @@ -108,13 +110,11 @@ impl Encodable for u8 { impl Decodable for u8 { fn decode(rlp: &Rlp) -> Result { - rlp.decoder().decode_value(|bytes| { - match bytes.len() { - 1 if bytes[0] != 0 => Ok(bytes[0]), - 0 => Ok(0), - 1 => Err(DecoderError::RlpInvalidIndirection), - _ => Err(DecoderError::RlpIsTooBig), - } + rlp.decoder().decode_value(|bytes| match bytes.len() { + 1 if bytes[0] != 0 => Ok(bytes[0]), + 0 => Ok(0), + 1 => Err(DecoderError::RlpInvalidIndirection), + _ => Err(DecoderError::RlpIsTooBig), }) } } @@ -128,33 +128,31 @@ macro_rules! impl_encodable_for_u { s.encoder().encode_value(&buffer[leading_empty_bytes..]); } } - } + }; } macro_rules! impl_decodable_for_u { ($name: ident) => { impl Decodable for $name { fn decode(rlp: &Rlp) -> Result { - rlp.decoder().decode_value(|bytes| { - match bytes.len() { - 0 | 1 => u8::decode(rlp).map(|v| v as $name), - l if l <= mem::size_of::<$name>() => { - if bytes[0] == 0 { - return Err(DecoderError::RlpInvalidIndirection); - } - let mut res = 0 as $name; - for (i, byte) in bytes.iter().enumerate().take(l) { - let shift = (l - 1 - i) * 8; - res += (*byte as $name) << shift; - } - Ok(res) + rlp.decoder().decode_value(|bytes| match bytes.len() { + 0 | 1 => u8::decode(rlp).map(|v| v as $name), + l if l <= mem::size_of::<$name>() => { + if bytes[0] == 0 { + return Err(DecoderError::RlpInvalidIndirection); } - _ => Err(DecoderError::RlpIsTooBig), + let mut res = 0 as $name; + for (i, byte) in bytes.iter().enumerate().take(l) { + let shift = (l - 1 - i) * 8; + res += (*byte as $name) << shift; + } + Ok(res) } + _ => Err(DecoderError::RlpIsTooBig), }) } } - } + }; } impl_encodable_for_u!(u16); diff --git a/rlp/src/lib.rs b/rlp/src/lib.rs index 1baa52c2f..ab386e689 100644 --- a/rlp/src/lib.rs +++ b/rlp/src/lib.rs @@ -37,18 +37,18 @@ #[cfg(not(feature = "std"))] extern crate alloc; -mod traits; mod error; +mod impls; mod rlpin; mod stream; -mod impls; +mod traits; #[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::borrow::Borrow; pub use self::error::DecoderError; -pub use self::rlpin::{Rlp, RlpIterator, PayloadInfo, Prototype}; +pub use self::rlpin::{PayloadInfo, Prototype, Rlp, RlpIterator}; pub use self::stream::RlpStream; pub use self::traits::{Decodable, Encodable}; @@ -68,12 +68,18 @@ pub const EMPTY_LIST_RLP: [u8; 1] = [0xC0; 1]; /// assert_eq!(animal, "cat".to_owned()); /// } /// ``` -pub fn decode(bytes: &[u8]) -> Result where T: Decodable { +pub fn decode(bytes: &[u8]) -> Result +where + T: Decodable, +{ let rlp = Rlp::new(bytes); rlp.as_val() } -pub fn decode_list(bytes: &[u8]) -> Vec where T: Decodable { +pub fn decode_list(bytes: &[u8]) -> Vec +where + T: Decodable, +{ let rlp = Rlp::new(bytes); rlp.as_list().expect("trusted rlp should be valid") } @@ -89,13 +95,20 @@ pub fn decode_list(bytes: &[u8]) -> Vec where T: Decodable { /// assert_eq!(out, vec![0x83, b'c', b'a', b't']); /// } /// ``` -pub fn encode(object: &E) -> Vec where E: Encodable { +pub fn encode(object: &E) -> Vec +where + E: Encodable, +{ let mut stream = RlpStream::new(); stream.append(object); stream.drain() } -pub fn encode_list(object: &[K]) -> Vec where E: Encodable, K: Borrow { +pub fn encode_list(object: &[K]) -> Vec +where + E: Encodable, + K: Borrow, +{ let mut stream = RlpStream::new(); stream.append_list(object); stream.drain() diff --git a/rlp/src/rlpin.rs b/rlp/src/rlpin.rs index 0d8c9ad2a..91d6be3b2 100644 --- a/rlp/src/rlpin.rs +++ b/rlp/src/rlpin.rs @@ -50,7 +50,10 @@ pub struct PayloadInfo { pub value_len: usize, } -fn calculate_payload_info(header_bytes: &[u8], len_of_len: usize) -> Result { +fn calculate_payload_info( + header_bytes: &[u8], + len_of_len: usize, +) -> Result { let header_len = 1 + len_of_len; match header_bytes.get(1) { Some(&0) => return Err(DecoderError::RlpDataLenWithZeroPrefix), @@ -69,15 +72,22 @@ fn calculate_payload_info(header_bytes: &[u8], len_of_len: usize) -> Result PayloadInfo { - PayloadInfo { header_len, value_len } + PayloadInfo { + header_len, + value_len, + } } /// Total size of the RLP. - pub fn total(&self) -> usize { self.header_len + self.value_len } + pub fn total(&self) -> usize { + self.header_len + self.value_len + } /// Create a new object from the given bytes RLP. The bytes pub fn from(header_bytes: &[u8]) -> Result { - let l = *header_bytes.first().ok_or_else(|| DecoderError::RlpIsTooShort)?; + let l = *header_bytes + .first() + .ok_or_else(|| DecoderError::RlpIsTooShort)?; if l <= 0x7f { Ok(PayloadInfo::new(0, 1)) } else if l <= 0xb7 { @@ -111,16 +121,18 @@ impl<'a> fmt::Display for Rlp<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { match self.prototype() { Ok(Prototype::Null) => write!(f, "null"), - Ok(Prototype::Data(_)) => write!(f, "\"0x{}\"", self.data().unwrap().to_hex::()), + Ok(Prototype::Data(_)) => { + write!(f, "\"0x{}\"", self.data().unwrap().to_hex::()) + } Ok(Prototype::List(len)) => { write!(f, "[")?; - for i in 0..len-1 { + for i in 0..len - 1 { write!(f, "{}, ", self.at(i).unwrap())?; } write!(f, "{}", self.at(len - 1).unwrap())?; write!(f, "]") - }, - Err(err) => write!(f, "{:?}", err) + } + Err(err) => write!(f, "{:?}", err), } } } @@ -130,11 +142,14 @@ impl<'a> Rlp<'a> { Rlp { bytes, offset_cache: Cell::new(None), - count_cache: Cell::new(None) + count_cache: Cell::new(None), } } - pub fn as_raw<'view>(&'view self) -> &'a [u8] where 'a: 'view { + pub fn as_raw<'view>(&'view self) -> &'a [u8] + where + 'a: 'view, + { self.bytes } @@ -153,7 +168,10 @@ impl<'a> Rlp<'a> { BasicDecoder::payload_info(self.bytes) } - pub fn data<'view>(&'view self) -> Result<&'a [u8], DecoderError> where 'a: 'view { + pub fn data<'view>(&'view self) -> Result<&'a [u8], DecoderError> + where + 'a: 'view, + { let pi = BasicDecoder::payload_info(self.bytes)?; Ok(&self.bytes[pi.header_len..(pi.header_len + pi.value_len)]) } @@ -169,20 +187,25 @@ impl<'a> Rlp<'a> { } } } else { - Err(DecoderError::RlpExpectedToBeList) + Err(DecoderError::RlpExpectedToBeList) } } pub fn size(&self) -> usize { if self.is_data() { // TODO: No panic on malformed data, but ideally would Err on no PayloadInfo. - BasicDecoder::payload_info(self.bytes).map(|b| b.value_len).unwrap_or(0) + BasicDecoder::payload_info(self.bytes) + .map(|b| b.value_len) + .unwrap_or(0) } else { 0 } } - pub fn at<'view>(&'view self, index: usize) -> Result, DecoderError> where 'a: 'view { + pub fn at<'view>(&'view self, index: usize) -> Result, DecoderError> + where + 'a: 'view, + { if !self.is_list() { return Err(DecoderError::RlpExpectedToBeList); } @@ -192,7 +215,9 @@ impl<'a> Rlp<'a> { let cache = self.offset_cache.get(); let (bytes, indexes_to_skip, bytes_consumed) = match cache { Some(ref cache) if cache.index <= index => ( - Rlp::consume(self.bytes, cache.offset)?, index - cache.index, cache.offset + Rlp::consume(self.bytes, cache.offset)?, + index - cache.index, + cache.offset, ), _ => { let (bytes, consumed) = self.consume_list_payload()?; @@ -204,7 +229,8 @@ impl<'a> Rlp<'a> { let (bytes, consumed) = Rlp::consume_items(bytes, indexes_to_skip)?; // update the cache - self.offset_cache.set(Some(OffsetCache::new(index, bytes_consumed + consumed))); + self.offset_cache + .set(Some(OffsetCache::new(index, bytes_consumed + consumed))); // construct new rlp let found = BasicDecoder::payload_info(bytes)?; @@ -238,28 +264,43 @@ impl<'a> Rlp<'a> { b @ 0xb8..=0xbf => { let payload_idx = 1 + b as usize - 0xb7; payload_idx < self.bytes.len() && self.bytes[payload_idx] != 0 - }, - _ => false + } + _ => false, } } - pub fn iter<'view>(&'view self) -> RlpIterator<'a, 'view> where 'a: 'view { + pub fn iter<'view>(&'view self) -> RlpIterator<'a, 'view> + where + 'a: 'view, + { self.into_iter() } - pub fn as_val(&self) -> Result where T: Decodable { + pub fn as_val(&self) -> Result + where + T: Decodable, + { T::decode(self) } - pub fn as_list(&self) -> Result, DecoderError> where T: Decodable { + pub fn as_list(&self) -> Result, DecoderError> + where + T: Decodable, + { self.iter().map(|rlp| rlp.as_val()).collect() } - pub fn val_at(&self, index: usize) -> Result where T: Decodable { + pub fn val_at(&self, index: usize) -> Result + where + T: Decodable, + { self.at(index)?.as_val() } - pub fn list_at(&self, index: usize) -> Result, DecoderError> where T: Decodable { + pub fn list_at(&self, index: usize) -> Result, DecoderError> + where + T: Decodable, + { self.at(index)?.as_list() } @@ -273,7 +314,10 @@ impl<'a> Rlp<'a> { if self.bytes.len() < (item.header_len + item.value_len) { return Err(DecoderError::RlpIsTooShort); } - Ok((&self.bytes[item.header_len..item.header_len + item.value_len], item.header_len)) + Ok(( + &self.bytes[item.header_len..item.header_len + item.value_len], + item.header_len, + )) } /// consumes fixed number of items @@ -300,12 +344,18 @@ impl<'a> Rlp<'a> { } /// Iterator over rlp-slice list elements. -pub struct RlpIterator<'a, 'view> where 'a: 'view { +pub struct RlpIterator<'a, 'view> +where + 'a: 'view, +{ rlp: &'view Rlp<'a>, index: usize, } -impl<'a, 'view> IntoIterator for &'view Rlp<'a> where 'a: 'view { +impl<'a, 'view> IntoIterator for &'view Rlp<'a> +where + 'a: 'view, +{ type Item = Rlp<'a>; type IntoIter = RlpIterator<'a, 'view>; @@ -334,9 +384,7 @@ pub struct BasicDecoder<'a> { impl<'a> BasicDecoder<'a> { pub fn new(rlp: &'a [u8]) -> BasicDecoder<'a> { - BasicDecoder { - rlp, - } + BasicDecoder { rlp } } /// Return first item info. @@ -349,8 +397,9 @@ impl<'a> BasicDecoder<'a> { } pub fn decode_value(&self, f: F) -> Result - where F: Fn(&[u8]) -> Result { - + where + F: Fn(&[u8]) -> Result, + { let bytes = self.rlp; let l = *bytes.first().ok_or_else(|| DecoderError::RlpIsTooShort)?; @@ -375,7 +424,8 @@ impl<'a> BasicDecoder<'a> { } let len = decode_usize(&bytes[1..begin_of_value])?; - let last_index_of_value = begin_of_value.checked_add(len) + let last_index_of_value = begin_of_value + .checked_add(len) .ok_or(DecoderError::RlpInvalidLength)?; if bytes.len() < last_index_of_value { return Err(DecoderError::RlpInconsistentLengthAndData); diff --git a/rlp/src/stream.rs b/rlp/src/stream.rs index 1a4fb0d66..a23e3a6cc 100644 --- a/rlp/src/stream.rs +++ b/rlp/src/stream.rs @@ -113,7 +113,10 @@ impl RlpStream { /// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); /// } /// ``` - pub fn append(&mut self, value: &E) -> &mut Self where E: Encodable { + pub fn append(&mut self, value: &E) -> &mut Self + where + E: Encodable, + { self.finished_list = false; value.rlp_append(self); if !self.finished_list { @@ -136,7 +139,8 @@ impl RlpStream { /// } /// ``` pub fn append_iter(&mut self, value: I) -> &mut Self - where I: IntoIterator, + where + I: IntoIterator, { self.finished_list = false; self.encoder().encode_iter(value); @@ -147,7 +151,11 @@ impl RlpStream { } /// Appends list of values to the end of stream, chainable. - pub fn append_list(&mut self, values: &[K]) -> &mut Self where E: Encodable, K: Borrow { + pub fn append_list(&mut self, values: &[K]) -> &mut Self + where + E: Encodable, + K: Borrow, + { self.begin_list(values.len()); for value in values { self.append(value.borrow()); @@ -157,7 +165,10 @@ impl RlpStream { /// Appends value to the end of stream, but do not count it as an appended item. /// It's useful for wrapper types - pub fn append_internal(&mut self, value: &E) -> &mut Self where E: Encodable { + pub fn append_internal(&mut self, value: &E) -> &mut Self + where + E: Encodable, + { value.rlp_append(self); self } @@ -184,15 +195,16 @@ impl RlpStream { self.buffer.push(0xc0u8); self.note_appended(1); self.finished_list = true; - }, + } _ => { // payload is longer than 1 byte only for lists > 55 bytes // by pushing always this 1 byte we may avoid unnecessary shift of data self.buffer.push(0); let position = self.buffer.len(); - self.unfinished_lists.push(ListInfo::new(position, Some(len))); - }, + self.unfinished_lists + .push(ListInfo::new(position, Some(len))); + } } // return chainable self @@ -314,7 +326,9 @@ impl RlpStream { Some(ref mut x) => { x.current += inserted_items; match x.max { - Some(ref max) if x.current > *max => panic!("You cannot append more items then you expect!"), + Some(ref max) if x.current > *max => { + panic!("You cannot append more items then you expect!") + } Some(ref max) => x.current == *max, _ => false, } @@ -350,7 +364,6 @@ impl RlpStream { pub fn complete_unbounded_list(&mut self) { self.finalize_unbounded_list(); } - } pub struct BasicEncoder<'a> { @@ -360,7 +373,7 @@ pub struct BasicEncoder<'a> { impl<'a> BasicEncoder<'a> { fn new(stream: &'a mut RlpStream) -> Self { BasicEncoder { - buffer: &mut stream.buffer + buffer: &mut stream.buffer, } } @@ -371,7 +384,8 @@ impl<'a> BasicEncoder<'a> { let buffer: [u8; 4] = size.to_be_bytes(); assert!(position <= self.buffer.len()); - self.buffer.extend_from_slice(&buffer[leading_empty_bytes..]); + self.buffer + .extend_from_slice(&buffer[leading_empty_bytes..]); self.buffer[position..].rotate_right(size_bytes as usize); size_bytes as u8 } @@ -382,7 +396,7 @@ impl<'a> BasicEncoder<'a> { match len { 0..=55 => { self.buffer[pos - 1] = 0xc0u8 + len as u8; - }, + } _ => { let inserted_bytes = self.insert_size(len, pos); self.buffer[pos - 1] = 0xf7u8 + inserted_bytes; @@ -396,7 +410,8 @@ impl<'a> BasicEncoder<'a> { /// Pushes encoded value to the end of buffer pub fn encode_iter(&mut self, value: I) - where I: IntoIterator, + where + I: IntoIterator, { let mut value = value.into_iter(); let len = match value.size_hint() { diff --git a/rlp/tests/tests.rs b/rlp/tests/tests.rs index 5d0310553..1e0fae34d 100644 --- a/rlp/tests/tests.rs +++ b/rlp/tests/tests.rs @@ -6,11 +6,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::{fmt, cmp}; +use core::{cmp, fmt}; use hex_literal::hex; use primitive_types::{H160, U256}; -use rlp::{Encodable, Decodable, Rlp, RlpStream, DecoderError}; +use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream}; #[test] fn test_rlp_display() { @@ -21,7 +21,9 @@ fn test_rlp_display() { #[test] fn length_overflow() { - let bs = [0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe5]; + let bs = [ + 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe5, + ]; let rlp = Rlp::new(&bs); let res: Result = rlp.as_val(); assert_eq!(Err(DecoderError::RlpInvalidLength), res); @@ -92,10 +94,13 @@ fn rlp_iter() { } } -struct ETestPair(T, Vec) where T: Encodable; +struct ETestPair(T, Vec) +where + T: Encodable; fn run_encode_tests(tests: Vec>) - where T: Encodable +where + T: Encodable, { for t in &tests { let res = rlp::encode(&t.0); @@ -103,10 +108,13 @@ fn run_encode_tests(tests: Vec>) } } -struct VETestPair(Vec, Vec) where T: Encodable; +struct VETestPair(Vec, Vec) +where + T: Encodable; fn run_encode_tests_list(tests: Vec>) - where T: Encodable +where + T: Encodable, { for t in &tests { let res = rlp::encode_list(&t.0); @@ -146,44 +154,60 @@ fn encode_u64() { #[test] fn encode_u256() { - let tests = vec![ETestPair(U256::from(0u64), vec![0x80u8]), - ETestPair(U256::from(0x0100_0000u64), vec![0x84, 0x01, 0x00, 0x00, 0x00]), - ETestPair(U256::from(0xffff_ffffu64), - vec![0x84, 0xff, 0xff, 0xff, 0xff]), - ETestPair(("8090a0b0c0d0e0f00910203040506077000000000000\ - 000100000000000012f0").into(), - vec![0xa0, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, - 0x09, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x77, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x12, 0xf0])]; + let tests = vec![ + ETestPair(U256::from(0u64), vec![0x80u8]), + ETestPair( + U256::from(0x0100_0000u64), + vec![0x84, 0x01, 0x00, 0x00, 0x00], + ), + ETestPair( + U256::from(0xffff_ffffu64), + vec![0x84, 0xff, 0xff, 0xff, 0xff], + ), + ETestPair( + ("8090a0b0c0d0e0f00910203040506077000000000000\ + 000100000000000012f0") + .into(), + vec![ + 0xa0, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x09, 0x10, 0x20, 0x30, 0x40, + 0x50, 0x60, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x12, 0xf0, + ], + ), + ]; run_encode_tests(tests); } #[test] fn encode_str() { - let tests = vec![ETestPair("cat", vec![0x83, b'c', b'a', b't']), - ETestPair("dog", vec![0x83, b'd', b'o', b'g']), - ETestPair("Marek", vec![0x85, b'M', b'a', b'r', b'e', b'k']), - ETestPair("", vec![0x80]), - ETestPair("Lorem ipsum dolor sit amet, consectetur adipisicing elit", - vec![0xb8, 0x38, b'L', b'o', b'r', b'e', b'm', b' ', b'i', - b'p', b's', b'u', b'm', b' ', b'd', b'o', b'l', b'o', - b'r', b' ', b's', b'i', b't', b' ', b'a', b'm', b'e', - b't', b',', b' ', b'c', b'o', b'n', b's', b'e', b'c', - b't', b'e', b't', b'u', b'r', b' ', b'a', b'd', b'i', - b'p', b'i', b's', b'i', b'c', b'i', b'n', b'g', b' ', - b'e', b'l', b'i', b't'])]; + let tests = vec![ + ETestPair("cat", vec![0x83, b'c', b'a', b't']), + ETestPair("dog", vec![0x83, b'd', b'o', b'g']), + ETestPair("Marek", vec![0x85, b'M', b'a', b'r', b'e', b'k']), + ETestPair("", vec![0x80]), + ETestPair( + "Lorem ipsum dolor sit amet, consectetur adipisicing elit", + vec![ + 0xb8, 0x38, b'L', b'o', b'r', b'e', b'm', b' ', b'i', b'p', b's', b'u', b'm', b' ', + b'd', b'o', b'l', b'o', b'r', b' ', b's', b'i', b't', b' ', b'a', b'm', b'e', b't', + b',', b' ', b'c', b'o', b'n', b's', b'e', b'c', b't', b'e', b't', b'u', b'r', b' ', + b'a', b'd', b'i', b'p', b'i', b's', b'i', b'c', b'i', b'n', b'g', b' ', b'e', b'l', + b'i', b't', + ], + ), + ]; run_encode_tests(tests); } #[test] fn encode_address() { - let tests = vec![ - ETestPair(H160::from(hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106")), - vec![0x94, 0xef, 0x2d, 0x6d, 0x19, 0x40, 0x84, 0xc2, 0xde, - 0x36, 0xe0, 0xda, 0xbf, 0xce, 0x45, 0xd0, 0x46, - 0xb3, 0x7d, 0x11, 0x06]) - ]; + let tests = vec![ETestPair( + H160::from(hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106")), + vec![ + 0x94, 0xef, 0x2d, 0x6d, 0x19, 0x40, 0x84, 0xc2, 0xde, 0x36, 0xe0, 0xda, 0xbf, 0xce, + 0x45, 0xd0, 0x46, 0xb3, 0x7d, 0x11, 0x06, + ], + )]; run_encode_tests(tests); } @@ -205,32 +229,47 @@ fn encode_vector_u64() { VETestPair(vec![], vec![0xc0]), VETestPair(vec![15u64], vec![0xc1, 0x0f]), VETestPair(vec![1, 2, 3, 7, 0xff], vec![0xc6, 1, 2, 3, 7, 0x81, 0xff]), - VETestPair(vec![0xffff_ffff, 1, 2, 3, 7, 0xff], vec![0xcb, 0x84, 0xff, 0xff, 0xff, 0xff, 1, 2, 3, 7, 0x81, 0xff]), + VETestPair( + vec![0xffff_ffff, 1, 2, 3, 7, 0xff], + vec![0xcb, 0x84, 0xff, 0xff, 0xff, 0xff, 1, 2, 3, 7, 0x81, 0xff], + ), ]; run_encode_tests_list(tests); } #[test] fn encode_vector_str() { - let tests = vec![VETestPair(vec!["cat", "dog"], - vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'])]; + let tests = vec![VETestPair( + vec!["cat", "dog"], + vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'], + )]; run_encode_tests_list(tests); } -struct DTestPair(T, Vec) where T: Decodable + fmt::Debug + cmp::Eq; +struct DTestPair(T, Vec) +where + T: Decodable + fmt::Debug + cmp::Eq; -struct VDTestPair(Vec, Vec) where T: Decodable + fmt::Debug + cmp::Eq; +struct VDTestPair(Vec, Vec) +where + T: Decodable + fmt::Debug + cmp::Eq; -fn run_decode_tests(tests: Vec>) where T: Decodable + fmt::Debug + cmp::Eq { +fn run_decode_tests(tests: Vec>) +where + T: Decodable + fmt::Debug + cmp::Eq, +{ for t in &tests { - let res : Result = rlp::decode(&t.1); + let res: Result = rlp::decode(&t.1); assert!(res.is_ok()); let res = res.unwrap(); assert_eq!(&res, &t.0); } } -fn run_decode_tests_list(tests: Vec>) where T: Decodable + fmt::Debug + cmp::Eq { +fn run_decode_tests_list(tests: Vec>) +where + T: Decodable + fmt::Debug + cmp::Eq, +{ for t in &tests { let res: Vec = rlp::decode_list(&t.1); assert_eq!(res, t.0); @@ -288,46 +327,60 @@ fn decode_untrusted_u64() { #[test] fn decode_untrusted_u256() { - let tests = vec![DTestPair(U256::from(0u64), vec![0x80u8]), - DTestPair(U256::from(0x0100_0000u64), vec![0x84, 0x01, 0x00, 0x00, 0x00]), - DTestPair(U256::from(0xffff_ffffu64), - vec![0x84, 0xff, 0xff, 0xff, 0xff]), - DTestPair(("8090a0b0c0d0e0f00910203040506077000000000000\ - 000100000000000012f0").into(), - vec![0xa0, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, - 0x09, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x77, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x12, 0xf0])]; + let tests = vec![ + DTestPair(U256::from(0u64), vec![0x80u8]), + DTestPair( + U256::from(0x0100_0000u64), + vec![0x84, 0x01, 0x00, 0x00, 0x00], + ), + DTestPair( + U256::from(0xffff_ffffu64), + vec![0x84, 0xff, 0xff, 0xff, 0xff], + ), + DTestPair( + ("8090a0b0c0d0e0f00910203040506077000000000000\ + 000100000000000012f0") + .into(), + vec![ + 0xa0, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x09, 0x10, 0x20, 0x30, 0x40, + 0x50, 0x60, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x12, 0xf0, + ], + ), + ]; run_decode_tests(tests); } #[test] fn decode_untrusted_str() { - let tests = vec![DTestPair("cat".to_owned(), vec![0x83, b'c', b'a', b't']), - DTestPair("dog".to_owned(), vec![0x83, b'd', b'o', b'g']), - DTestPair("Marek".to_owned(), - vec![0x85, b'M', b'a', b'r', b'e', b'k']), - DTestPair("".to_owned(), vec![0x80]), - DTestPair("Lorem ipsum dolor sit amet, consectetur adipisicing elit" - .to_owned(), - vec![0xb8, 0x38, b'L', b'o', b'r', b'e', b'm', b' ', b'i', - b'p', b's', b'u', b'm', b' ', b'd', b'o', b'l', b'o', - b'r', b' ', b's', b'i', b't', b' ', b'a', b'm', b'e', - b't', b',', b' ', b'c', b'o', b'n', b's', b'e', b'c', - b't', b'e', b't', b'u', b'r', b' ', b'a', b'd', b'i', - b'p', b'i', b's', b'i', b'c', b'i', b'n', b'g', b' ', - b'e', b'l', b'i', b't'])]; + let tests = vec![ + DTestPair("cat".to_owned(), vec![0x83, b'c', b'a', b't']), + DTestPair("dog".to_owned(), vec![0x83, b'd', b'o', b'g']), + DTestPair("Marek".to_owned(), vec![0x85, b'M', b'a', b'r', b'e', b'k']), + DTestPair("".to_owned(), vec![0x80]), + DTestPair( + "Lorem ipsum dolor sit amet, consectetur adipisicing elit".to_owned(), + vec![ + 0xb8, 0x38, b'L', b'o', b'r', b'e', b'm', b' ', b'i', b'p', b's', b'u', b'm', b' ', + b'd', b'o', b'l', b'o', b'r', b' ', b's', b'i', b't', b' ', b'a', b'm', b'e', b't', + b',', b' ', b'c', b'o', b'n', b's', b'e', b'c', b't', b'e', b't', b'u', b'r', b' ', + b'a', b'd', b'i', b'p', b'i', b's', b'i', b'c', b'i', b'n', b'g', b' ', b'e', b'l', + b'i', b't', + ], + ), + ]; run_decode_tests(tests); } #[test] fn decode_untrusted_address() { - let tests = vec![ - DTestPair(H160::from(hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106")), - vec![0x94, 0xef, 0x2d, 0x6d, 0x19, 0x40, 0x84, 0xc2, 0xde, - 0x36, 0xe0, 0xda, 0xbf, 0xce, 0x45, 0xd0, 0x46, - 0xb3, 0x7d, 0x11, 0x06]) - ]; + let tests = vec![DTestPair( + H160::from(hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106")), + vec![ + 0x94, 0xef, 0x2d, 0x6d, 0x19, 0x40, 0x84, 0xc2, 0xde, 0x36, 0xe0, 0xda, 0xbf, 0xce, + 0x45, 0xd0, 0x46, 0xb3, 0x7d, 0x11, 0x06, + ], + )]; run_decode_tests(tests); } @@ -337,21 +390,25 @@ fn decode_untrusted_vector_u64() { VDTestPair(vec![], vec![0xc0]), VDTestPair(vec![15u64], vec![0xc1, 0x0f]), VDTestPair(vec![1, 2, 3, 7, 0xff], vec![0xc6, 1, 2, 3, 7, 0x81, 0xff]), - VDTestPair(vec![0xffff_ffff, 1, 2, 3, 7, 0xff], vec![0xcb, 0x84, 0xff, 0xff, 0xff, 0xff, 1, 2, 3, 7, 0x81, 0xff]), + VDTestPair( + vec![0xffff_ffff, 1, 2, 3, 7, 0xff], + vec![0xcb, 0x84, 0xff, 0xff, 0xff, 0xff, 1, 2, 3, 7, 0x81, 0xff], + ), ]; run_decode_tests_list(tests); } #[test] fn decode_untrusted_vector_str() { - let tests = vec![VDTestPair(vec!["cat".to_owned(), "dog".to_owned()], - vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'])]; + let tests = vec![VDTestPair( + vec!["cat".to_owned(), "dog".to_owned()], + vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'], + )]; run_decode_tests_list(tests); } #[test] -fn test_rlp_data_length_check() -{ +fn test_rlp_data_length_check() { let data = vec![0x84, b'c', b'a', b't']; let rlp = Rlp::new(&data); @@ -360,8 +417,7 @@ fn test_rlp_data_length_check() } #[test] -fn test_rlp_long_data_length_check() -{ +fn test_rlp_long_data_length_check() { let mut data: Vec = vec![0xb8, 255]; for _ in 0..253 { data.push(b'c'); @@ -374,8 +430,7 @@ fn test_rlp_long_data_length_check() } #[test] -fn test_the_exact_long_string() -{ +fn test_the_exact_long_string() { let mut data: Vec = vec![0xb8, 255]; for _ in 0..255 { data.push(b'c'); @@ -388,8 +443,7 @@ fn test_the_exact_long_string() } #[test] -fn test_rlp_2bytes_data_length_check() -{ +fn test_rlp_2bytes_data_length_check() { let mut data: Vec = vec![0xb9, 2, 255]; // 512+255 for _ in 0..700 { data.push(b'c'); @@ -411,7 +465,9 @@ fn test_rlp_nested_empty_list_encode() { #[test] fn test_rlp_list_length_overflow() { - let data: Vec = vec![0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00]; + let data: Vec = vec![ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + ]; let rlp = Rlp::new(&data); let as_val: Result = rlp.val_at(0); assert_eq!(Err(DecoderError::RlpIsTooShort), as_val); @@ -419,7 +475,7 @@ fn test_rlp_list_length_overflow() { #[test] fn test_rlp_stream_size_limit() { - for limit in 40 .. 270 { + for limit in 40..270 { let item = [0u8; 1]; let mut stream = RlpStream::new(); while stream.append_raw_checked(&item, 1, limit) {} @@ -484,11 +540,26 @@ fn test_canonical_list_encoding() { // https://github.com/paritytech/parity-common/issues/48 #[test] fn test_inner_length_capping_for_short_lists() { - assert_eq!(Rlp::new(&[0xc0, 0x82, b'a', b'b']).val_at::(0), Err(DecoderError::RlpIsTooShort)); - assert_eq!(Rlp::new(&[0xc0 + 1, 0x82, b'a', b'b']).val_at::(0), Err(DecoderError::RlpIsTooShort)); - assert_eq!(Rlp::new(&[0xc0 + 2, 0x82, b'a', b'b']).val_at::(0), Err(DecoderError::RlpIsTooShort)); - assert_eq!(Rlp::new(&[0xc0 + 3, 0x82, b'a', b'b']).val_at::(0), Ok("ab".to_owned())); - assert_eq!(Rlp::new(&[0xc0 + 4, 0x82, b'a', b'b']).val_at::(0), Err(DecoderError::RlpIsTooShort)); + assert_eq!( + Rlp::new(&[0xc0, 0x82, b'a', b'b']).val_at::(0), + Err(DecoderError::RlpIsTooShort) + ); + assert_eq!( + Rlp::new(&[0xc0 + 1, 0x82, b'a', b'b']).val_at::(0), + Err(DecoderError::RlpIsTooShort) + ); + assert_eq!( + Rlp::new(&[0xc0 + 2, 0x82, b'a', b'b']).val_at::(0), + Err(DecoderError::RlpIsTooShort) + ); + assert_eq!( + Rlp::new(&[0xc0 + 3, 0x82, b'a', b'b']).val_at::(0), + Ok("ab".to_owned()) + ); + assert_eq!( + Rlp::new(&[0xc0 + 4, 0x82, b'a', b'b']).val_at::(0), + Err(DecoderError::RlpIsTooShort) + ); } // test described in @@ -531,7 +602,6 @@ fn test_nested_list_roundtrip() { } } - let items = (0..4).map(|i| Inner(i, i + 1)).collect(); let nest = Nest(items); diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 000000000..218e20321 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +hard_tabs = true diff --git a/transaction-pool/src/error.rs b/transaction-pool/src/error.rs index 74ce76652..fb1e89e4b 100644 --- a/transaction-pool/src/error.rs +++ b/transaction-pool/src/error.rs @@ -33,12 +33,15 @@ pub type Result = result::Result>; impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Error::AlreadyImported(h) => - write!(f, "[{:?}] already imported", h), - Error::TooCheapToEnter(hash, min_score) => - write!(f, "[{:x}] too cheap to enter the pool. Min score: {}", hash, min_score), - Error::TooCheapToReplace(old_hash, hash) => - write!(f, "[{:x}] too cheap to replace: {:x}", hash, old_hash), + Error::AlreadyImported(h) => write!(f, "[{:?}] already imported", h), + Error::TooCheapToEnter(hash, min_score) => write!( + f, + "[{:x}] too cheap to enter the pool. Min score: {}", + hash, min_score + ), + Error::TooCheapToReplace(old_hash, hash) => { + write!(f, "[{:x}] too cheap to replace: {:x}", hash, old_hash) + } } } } @@ -46,14 +49,21 @@ impl fmt::Display for Error { impl error::Error for Error {} #[cfg(test)] -impl PartialEq for Error where H: PartialEq { +impl PartialEq for Error +where + H: PartialEq, +{ fn eq(&self, other: &Self) -> bool { use self::Error::*; match (self, other) { (&AlreadyImported(ref h1), &AlreadyImported(ref h2)) => h1 == h2, - (&TooCheapToEnter(ref h1, ref s1), &TooCheapToEnter(ref h2, ref s2)) => h1 == h2 && s1 == s2, - (&TooCheapToReplace(ref old1, ref new1), &TooCheapToReplace(ref old2, ref new2)) => old1 == old2 && new1 == new2, + (&TooCheapToEnter(ref h1, ref s1), &TooCheapToEnter(ref h2, ref s2)) => { + h1 == h2 && s1 == s2 + } + (&TooCheapToReplace(ref old1, ref new1), &TooCheapToReplace(ref old2, ref new2)) => { + old1 == old2 && new1 == new2 + } _ => false, } } diff --git a/transaction-pool/src/lib.rs b/transaction-pool/src/lib.rs index 669441829..66e93fffe 100644 --- a/transaction-pool/src/lib.rs +++ b/transaction-pool/src/lib.rs @@ -86,9 +86,9 @@ pub mod scoring; pub use self::error::Error; pub use self::listener::{Listener, NoopListener}; pub use self::options::Options; -pub use self::pool::{Pool, PendingIterator, UnorderedIterator, Transaction}; -pub use self::ready::{Ready, Readiness}; -pub use self::replace::{ShouldReplace, ReplaceTransaction}; +pub use self::pool::{PendingIterator, Pool, Transaction, UnorderedIterator}; +pub use self::ready::{Readiness, Ready}; +pub use self::replace::{ReplaceTransaction, ShouldReplace}; pub use self::scoring::Scoring; pub use self::status::{LightStatus, Status}; pub use self::verifier::Verifier; diff --git a/transaction-pool/src/listener.rs b/transaction-pool/src/listener.rs index a599c8763..566b318ee 100644 --- a/transaction-pool/src/listener.rs +++ b/transaction-pool/src/listener.rs @@ -14,8 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use std::{fmt::{Debug, LowerHex}, sync::Arc}; use crate::error::Error; +use std::{ + fmt::{Debug, LowerHex}, + sync::Arc, +}; /// Transaction pool listener. /// @@ -49,7 +52,8 @@ pub trait Listener { pub struct NoopListener; impl Listener for NoopListener {} -impl Listener for (A, B) where +impl Listener for (A, B) +where A: Listener, B: Listener, { diff --git a/transaction-pool/src/pool.rs b/transaction-pool/src/pool.rs index 539e7dded..262aee1b6 100644 --- a/transaction-pool/src/pool.rs +++ b/transaction-pool/src/pool.rs @@ -14,18 +14,18 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use std::sync::Arc; -use std::slice; -use std::collections::{hash_map, HashMap, BTreeSet}; use log::{trace, warn}; +use std::collections::{hash_map, BTreeSet, HashMap}; +use std::slice; +use std::sync::Arc; use crate::{ error, listener::{Listener, NoopListener}, options::Options, - ready::{Ready, Readiness}, - replace::{ShouldReplace, ReplaceTransaction}, - scoring::{self, Scoring, ScoreWithRef}, + ready::{Readiness, Ready}, + replace::{ReplaceTransaction, ShouldReplace}, + scoring::{self, ScoreWithRef, Scoring}, status::{LightStatus, Status}, transactions::{AddResult, Transactions}, VerifiedTransaction, @@ -101,7 +101,8 @@ impl> Pool { const INITIAL_NUMBER_OF_SENDERS: usize = 16; -impl Pool where +impl Pool +where T: VerifiedTransaction, S: Scoring, L: Listener, @@ -122,7 +123,6 @@ impl Pool where worst_transactions: Default::default(), insertion_id: 0, } - } /// Attempts to import new transaction to the pool, returns a `Arc` or an `Error`. @@ -138,11 +138,15 @@ impl Pool where /// new transaction via the supplied `ShouldReplace` implementation and may be evicted. /// /// The `Listener` will be informed on any drops or rejections. - pub fn import(&mut self, transaction: T, replace: &dyn ShouldReplace) -> error::Result, T::Hash> { + pub fn import( + &mut self, + transaction: T, + replace: &dyn ShouldReplace, + ) -> error::Result, T::Hash> { let mem_usage = transaction.mem_usage(); if self.by_hash.contains_key(transaction.hash()) { - return Err(error::Error::AlreadyImported(transaction.hash().clone())) + return Err(error::Error::AlreadyImported(transaction.hash().clone())); } self.insertion_id += 1; @@ -154,30 +158,37 @@ impl Pool where // TODO [ToDr] Most likely move this after the transaction is inserted. // Avoid using should_replace, but rather use scoring for that. { - let remove_worst = |s: &mut Self, transaction| { - match s.remove_worst(transaction, replace) { + let remove_worst = + |s: &mut Self, transaction| match s.remove_worst(transaction, replace) { Err(err) => { s.listener.rejected(transaction, &err); Err(err) - }, + } Ok(None) => Ok(false), Ok(Some(removed)) => { s.listener.dropped(&removed, Some(transaction)); s.finalize_remove(removed.hash()); Ok(true) - }, - } - }; + } + }; while self.by_hash.len() + 1 > self.options.max_count { - trace!("Count limit reached: {} > {}", self.by_hash.len() + 1, self.options.max_count); + trace!( + "Count limit reached: {} > {}", + self.by_hash.len() + 1, + self.options.max_count + ); if !remove_worst(self, &transaction)? { break; } } while self.mem_usage + mem_usage > self.options.max_mem_usage { - trace!("Mem limit reached: {} > {}", self.mem_usage + mem_usage, self.options.max_mem_usage); + trace!( + "Mem limit reached: {} > {}", + self.mem_usage + mem_usage, + self.options.max_mem_usage + ); if !remove_worst(self, &transaction)? { break; } @@ -185,7 +196,10 @@ impl Pool where } let (result, prev_state, current_state) = { - let transactions = self.transactions.entry(transaction.sender().clone()).or_insert_with(Transactions::default); + let transactions = self + .transactions + .entry(transaction.sender().clone()) + .or_insert_with(Transactions::default); // get worst and best transactions for comparison let prev = transactions.worst_and_best(); let result = transactions.add(transaction, &self.scoring, self.options.max_per_sender); @@ -201,22 +215,22 @@ impl Pool where self.listener.added(&tx, None); self.finalize_insert(&tx, None); Ok(tx.transaction) - }, - AddResult::PushedOut { new, old } | - AddResult::Replaced { new, old } => { + } + AddResult::PushedOut { new, old } | AddResult::Replaced { new, old } => { self.listener.added(&new, Some(&old)); self.finalize_insert(&new, Some(&old)); Ok(new.transaction) - }, + } AddResult::TooCheap { new, old } => { let error = error::Error::TooCheapToReplace(old.hash().clone(), new.hash().clone()); self.listener.rejected(&new, &error); - return Err(error) - }, + return Err(error); + } AddResult::TooCheapToEnter(new, score) => { - let error = error::Error::TooCheapToEnter(new.hash().clone(), format!("{:#x}", score)); + let error = + error::Error::TooCheapToEnter(new.hash().clone(), format!("{:#x}", score)); self.listener.rejected(&new, &error); - return Err(error) + return Err(error); } } } @@ -252,24 +266,26 @@ impl Pool where a.0 == b.0 && a.1.hash() == b.1.hash() }; - let update = |collection: &mut BTreeSet<_>, (score, tx), remove| if remove { - collection.remove(&ScoreWithRef::new(score, tx)); - } else { - collection.insert(ScoreWithRef::new(score, tx)); + let update = |collection: &mut BTreeSet<_>, (score, tx), remove| { + if remove { + collection.remove(&ScoreWithRef::new(score, tx)); + } else { + collection.insert(ScoreWithRef::new(score, tx)); + } }; match (previous, current) { (None, Some((worst, best))) => { update(worst_collection, worst, false); update(best_collection, best, false); - }, + } (Some((worst, best)), None) => { // all transactions from that sender has been removed. // We can clear a hashmap entry. self.transactions.remove(worst.1.sender()); update(worst_collection, worst, true); update(best_collection, best, true); - }, + } (Some((w1, b1)), Some((w2, b2))) => { if !is_same(&w1, &w2) { update(worst_collection, w1, true); @@ -279,8 +295,8 @@ impl Pool where update(best_collection, b1, true); update(best_collection, b2, false); } - }, - (None, None) => {}, + } + (None, None) => {} } } @@ -288,17 +304,26 @@ impl Pool where /// /// Returns `None` in case we couldn't decide if the transaction should replace the worst transaction or not. /// In such case we will accept the transaction even though it is going to exceed the limit. - fn remove_worst(&mut self, transaction: &Transaction, replace: &dyn ShouldReplace) -> error::Result>, T::Hash> { + fn remove_worst( + &mut self, + transaction: &Transaction, + replace: &dyn ShouldReplace, + ) -> error::Result>, T::Hash> { let to_remove = match self.worst_transactions.iter().next_back() { // No elements to remove? and the pool is still full? None => { warn!("The pool is full but there are no transactions to remove."); - return Err(error::Error::TooCheapToEnter(transaction.hash().clone(), "unknown".into())) - }, + return Err(error::Error::TooCheapToEnter( + transaction.hash().clone(), + "unknown".into(), + )); + } Some(old) => { let txs = &self.transactions; let get_replace_tx = |tx| { - let sender_txs = txs.get(transaction.sender()).map(|txs| txs.iter().as_slice()); + let sender_txs = txs + .get(transaction.sender()) + .map(|txs| txs.iter().as_slice()); ReplaceTransaction::new(tx, sender_txs) }; let old_replace = get_replace_tx(&old.transaction); @@ -311,10 +336,13 @@ impl Pool where scoring::Choice::ReplaceOld => Some(old.clone()), // otherwise fail scoring::Choice::RejectNew => { - return Err(error::Error::TooCheapToEnter(transaction.hash().clone(), format!("{:#x}", old.score))) - }, + return Err(error::Error::TooCheapToEnter( + transaction.hash().clone(), + format!("{:#x}", old.score), + )) + } } - }, + } }; if let Some(to_remove) = to_remove { @@ -330,7 +358,11 @@ impl Pool where } /// Removes transaction from sender's transaction `HashMap`. - fn remove_from_set, &S) -> R>(&mut self, sender: &T::Sender, f: F) -> Option { + fn remove_from_set, &S) -> R>( + &mut self, + sender: &T::Sender, + f: F, + ) -> Option { let (prev, next, result) = if let Some(set) = self.transactions.get_mut(sender) { let prev = set.worst_and_best(); let result = f(set, &self.scoring); @@ -362,9 +394,7 @@ impl Pool where /// will either get a `cancelled` or `invalid` notification. pub fn remove(&mut self, hash: &T::Hash, is_invalid: bool) -> Option> { if let Some(tx) = self.finalize_remove(hash) { - self.remove_from_set(tx.sender(), |set, scoring| { - set.remove(&tx, scoring) - }); + self.remove_from_set(tx.sender(), |set, scoring| set.remove(&tx, scoring)); if is_invalid { self.listener.invalid(&tx); } else { @@ -390,7 +420,7 @@ impl Pool where self.listener.culled(&tx); } len - }, + } None => 0, } } @@ -403,13 +433,13 @@ impl Pool where for sender in senders { removed += self.remove_stalled(sender, &mut ready); } - }, + } None => { let senders = self.transactions.keys().cloned().collect::>(); for sender in senders { removed += self.remove_stalled(&sender, &mut ready); } - }, + } } removed @@ -422,18 +452,22 @@ impl Pool where /// Returns worst transaction in the queue (if any). pub fn worst_transaction(&self) -> Option> { - self.worst_transactions.iter().next_back().map(|x| x.transaction.transaction.clone()) + self.worst_transactions + .iter() + .next_back() + .map(|x| x.transaction.transaction.clone()) } /// Returns true if the pool is at it's capacity. pub fn is_full(&self) -> bool { - self.by_hash.len() >= self.options.max_count - || self.mem_usage >= self.options.max_mem_usage + self.by_hash.len() >= self.options.max_count || self.mem_usage >= self.options.max_mem_usage } /// Returns senders ordered by priority of their transactions. - pub fn senders(&self) -> impl Iterator { - self.best_transactions.iter().map(|tx| tx.transaction.sender()) + pub fn senders(&self) -> impl Iterator { + self.best_transactions + .iter() + .map(|tx| tx.transaction.sender()) } /// Returns an iterator of pending (ready) transactions. @@ -446,8 +480,14 @@ impl Pool where } /// Returns pending (ready) transactions from given sender. - pub fn pending_from_sender>(&self, ready: R, sender: &T::Sender) -> PendingIterator<'_, T, R, S, L> { - let best_transactions = self.transactions.get(sender) + pub fn pending_from_sender>( + &self, + ready: R, + sender: &T::Sender, + ) -> PendingIterator<'_, T, R, S, L> { + let best_transactions = self + .transactions + .get(sender) .and_then(|transactions| transactions.worst_and_best()) .map(|(_, best)| ScoreWithRef::new(best.0, best.1)) .map(|s| { @@ -547,7 +587,8 @@ impl Pool where /// /// NOTE: the transactions are not removed from the queue. /// You might remove them later by calling `cull`. -pub struct UnorderedIterator<'a, T, R, S> where +pub struct UnorderedIterator<'a, T, R, S> +where T: VerifiedTransaction + 'a, S: Scoring + 'a, { @@ -556,7 +597,8 @@ pub struct UnorderedIterator<'a, T, R, S> where transactions: Option>>, } -impl<'a, T, R, S> Iterator for UnorderedIterator<'a, T, R, S> where +impl<'a, T, R, S> Iterator for UnorderedIterator<'a, T, R, S> +where T: VerifiedTransaction, R: Ready, S: Scoring, @@ -570,7 +612,7 @@ impl<'a, T, R, S> Iterator for UnorderedIterator<'a, T, R, S> where match self.ready.is_ready(&tx) { Readiness::Ready => { return Some(tx.transaction.clone()); - }, + } state => trace!("[{:?}] Ignoring {:?} transaction.", tx.hash(), state), } } @@ -583,11 +625,11 @@ impl<'a, T, R, S> Iterator for UnorderedIterator<'a, T, R, S> where } } - /// An iterator over all pending (ready) transactions. /// NOTE: the transactions are not removed from the queue. /// You might remove them later by calling `cull`. -pub struct PendingIterator<'a, T, R, S, L> where +pub struct PendingIterator<'a, T, R, S, L> +where T: VerifiedTransaction + 'a, S: Scoring + 'a, L: 'a, @@ -597,7 +639,8 @@ pub struct PendingIterator<'a, T, R, S, L> where pool: &'a Pool, } -impl<'a, T, R, S, L> Iterator for PendingIterator<'a, T, R, S, L> where +impl<'a, T, R, S, L> Iterator for PendingIterator<'a, T, R, S, L> +where T: VerifiedTransaction, R: Ready, S: Scoring, @@ -607,8 +650,15 @@ impl<'a, T, R, S, L> Iterator for PendingIterator<'a, T, R, S, L> where fn next(&mut self) -> Option { while !self.best_transactions.is_empty() { let best = { - let best = self.best_transactions.iter().next().expect("current_best is not empty; qed").clone(); - self.best_transactions.take(&best).expect("Just taken from iterator; qed") + let best = self + .best_transactions + .iter() + .next() + .expect("current_best is not empty; qed") + .clone(); + self.best_transactions + .take(&best) + .expect("Just taken from iterator; qed") }; let tx_state = self.ready.is_ready(&best.transaction); @@ -616,24 +666,29 @@ impl<'a, T, R, S, L> Iterator for PendingIterator<'a, T, R, S, L> where match tx_state { Readiness::Ready | Readiness::Stale => { // retrieve next one from the same sender. - let next = self.pool.transactions + let next = self + .pool + .transactions .get(best.transaction.sender()) .and_then(|s| s.find_next(&best.transaction, &self.pool.scoring)); if let Some((score, tx)) = next { self.best_transactions.insert(ScoreWithRef::new(score, tx)); } - }, + } _ => (), } if tx_state == Readiness::Ready { - return Some(best.transaction.transaction) + return Some(best.transaction.transaction); } - trace!("[{:?}] Ignoring {:?} transaction.", best.transaction.hash(), tx_state); + trace!( + "[{:?}] Ignoring {:?} transaction.", + best.transaction.hash(), + tx_state + ); } None } } - diff --git a/transaction-pool/src/ready.rs b/transaction-pool/src/ready.rs index 0bee5188d..45e85ca29 100644 --- a/transaction-pool/src/ready.rs +++ b/transaction-pool/src/ready.rs @@ -35,13 +35,17 @@ pub trait Ready { fn is_ready(&mut self, tx: &T) -> Readiness; } -impl Ready for F where F: FnMut(&T) -> Readiness { +impl Ready for F +where + F: FnMut(&T) -> Readiness, +{ fn is_ready(&mut self, tx: &T) -> Readiness { (*self)(tx) } } -impl Ready for (A, B) where +impl Ready for (A, B) +where A: Ready, B: Ready, { diff --git a/transaction-pool/src/replace.rs b/transaction-pool/src/replace.rs index bc44e8d90..56ea719ce 100644 --- a/transaction-pool/src/replace.rs +++ b/transaction-pool/src/replace.rs @@ -16,40 +16,44 @@ //! When queue limits are reached, decide whether to replace an existing transaction from the pool -use crate::{ - pool::Transaction, - scoring::Choice, -}; +use crate::{pool::Transaction, scoring::Choice}; /// Encapsulates a transaction to be compared, along with pooled transactions from the same sender pub struct ReplaceTransaction<'a, T> { - /// The transaction to be compared for replacement - pub transaction: &'a Transaction, - /// Other transactions currently in the pool for the same sender - pub pooled_by_sender: Option<&'a [Transaction]>, + /// The transaction to be compared for replacement + pub transaction: &'a Transaction, + /// Other transactions currently in the pool for the same sender + pub pooled_by_sender: Option<&'a [Transaction]>, } impl<'a, T> ReplaceTransaction<'a, T> { - /// Creates a new `ReplaceTransaction` - pub fn new(transaction: &'a Transaction, pooled_by_sender: Option<&'a [Transaction]>) -> Self { - ReplaceTransaction { - transaction, - pooled_by_sender, - } - } + /// Creates a new `ReplaceTransaction` + pub fn new( + transaction: &'a Transaction, + pooled_by_sender: Option<&'a [Transaction]>, + ) -> Self { + ReplaceTransaction { + transaction, + pooled_by_sender, + } + } } impl<'a, T> ::std::ops::Deref for ReplaceTransaction<'a, T> { - type Target = Transaction; - fn deref(&self) -> &Self::Target { - &self.transaction - } + type Target = Transaction; + fn deref(&self) -> &Self::Target { + &self.transaction + } } /// Chooses whether a new transaction should replace an existing transaction if the pool is full. pub trait ShouldReplace { - /// Decides if `new` should push out `old` transaction from the pool. - /// - /// NOTE returning `InsertNew` here can lead to some transactions being accepted above pool limits. - fn should_replace(&self, old: &ReplaceTransaction<'_, T>, new: &ReplaceTransaction<'_, T>) -> Choice; + /// Decides if `new` should push out `old` transaction from the pool. + /// + /// NOTE returning `InsertNew` here can lead to some transactions being accepted above pool limits. + fn should_replace( + &self, + old: &ReplaceTransaction<'_, T>, + new: &ReplaceTransaction<'_, T>, + ) -> Choice; } diff --git a/transaction-pool/src/scoring.rs b/transaction-pool/src/scoring.rs index c3edbb1ac..94908c7d5 100644 --- a/transaction-pool/src/scoring.rs +++ b/transaction-pool/src/scoring.rs @@ -16,8 +16,8 @@ //! A transactions ordering abstraction. -use std::{cmp, fmt}; use crate::pool::Transaction; +use std::{cmp, fmt}; /// Represents a decision what to do with /// a new transaction that tries to enter the pool. @@ -94,13 +94,20 @@ pub trait Scoring: fmt::Debug { /// Updates the transaction scores given a list of transactions and a change to previous scoring. /// NOTE: you can safely assume that both slices have the same length. /// (i.e. score at index `i` represents transaction at the same index) - fn update_scores(&self, txs: &[Transaction], scores: &mut [Self::Score], change: Change); + fn update_scores( + &self, + txs: &[Transaction], + scores: &mut [Self::Score], + change: Change, + ); /// Decides if the transaction should ignore per-sender limit in the pool. /// /// If you return `true` for given transaction it's going to be accepted even though /// the per-sender limit is exceeded. - fn should_ignore_sender_limit(&self, _new: &T) -> bool { false } + fn should_ignore_sender_limit(&self, _new: &T) -> bool { + false + } } /// A score with a reference to the transaction. @@ -130,8 +137,11 @@ impl Clone for ScoreWithRef { impl Ord for ScoreWithRef { fn cmp(&self, other: &Self) -> cmp::Ordering { - other.score.cmp(&self.score) - .then(self.transaction.insertion_id.cmp(&other.transaction.insertion_id)) + other.score.cmp(&self.score).then( + self.transaction + .insertion_id + .cmp(&other.transaction.insertion_id), + ) } } @@ -141,7 +151,7 @@ impl PartialOrd for ScoreWithRef { } } -impl PartialEq for ScoreWithRef { +impl PartialEq for ScoreWithRef { fn eq(&self, other: &Self) -> bool { self.score == other.score && self.transaction.insertion_id == other.transaction.insertion_id } @@ -149,7 +159,6 @@ impl PartialEq for ScoreWithRef { impl Eq for ScoreWithRef {} - #[cfg(test)] mod tests { use super::*; diff --git a/transaction-pool/src/tests/helpers.rs b/transaction-pool/src/tests/helpers.rs index 73d11f9e5..eed525671 100644 --- a/transaction-pool/src/tests/helpers.rs +++ b/transaction-pool/src/tests/helpers.rs @@ -17,9 +17,9 @@ use std::cmp; use std::collections::HashMap; -use ethereum_types::{H160 as Sender, U256}; -use crate::{pool, scoring, Scoring, ShouldReplace, ReplaceTransaction, Ready, Readiness}; use super::Transaction; +use crate::{pool, scoring, Readiness, Ready, ReplaceTransaction, Scoring, ShouldReplace}; +use ethereum_types::{H160 as Sender, U256}; #[derive(Debug, Default)] pub struct DummyScoring { @@ -54,7 +54,12 @@ impl Scoring for DummyScoring { } } - fn update_scores(&self, txs: &[pool::Transaction], scores: &mut [Self::Score], change: scoring::Change) { + fn update_scores( + &self, + txs: &[pool::Transaction], + scores: &mut [Self::Score], + change: scoring::Change, + ) { if let scoring::Change::Event(_) = change { // In case of event reset all scores to 0 for i in 0..txs.len() { @@ -74,7 +79,11 @@ impl Scoring for DummyScoring { } impl ShouldReplace for DummyScoring { - fn should_replace(&self, old: &ReplaceTransaction<'_, Transaction>, new: &ReplaceTransaction<'_, Transaction>) -> scoring::Choice { + fn should_replace( + &self, + old: &ReplaceTransaction<'_, Transaction>, + new: &ReplaceTransaction<'_, Transaction>, + ) -> scoring::Choice { if self.always_insert { scoring::Choice::InsertNew } else if new.gas_price > old.gas_price { @@ -105,7 +114,7 @@ impl Ready for NonceReady { cmp::Ordering::Equal => { *nonce += 1.into(); Readiness::Ready - }, + } cmp::Ordering::Less => Readiness::Stale, } } diff --git a/transaction-pool/src/tests/mod.rs b/transaction-pool/src/tests/mod.rs index 7cc7c5553..c52287b18 100644 --- a/transaction-pool/src/tests/mod.rs +++ b/transaction-pool/src/tests/mod.rs @@ -22,8 +22,8 @@ use self::tx_builder::TransactionBuilder; use std::sync::Arc; -use ethereum_types::{H256, U256, Address}; use super::*; +use ethereum_types::{Address, H256, U256}; #[derive(Debug, PartialEq)] pub struct Transaction { @@ -39,9 +39,15 @@ impl VerifiedTransaction for Transaction { type Hash = H256; type Sender = Address; - fn hash(&self) -> &H256 { &self.hash } - fn mem_usage(&self) -> usize { self.mem_usage } - fn sender(&self) -> &Address { &self.sender } + fn hash(&self) -> &H256 { + &self.hash + } + fn mem_usage(&self) -> usize { + self.mem_usage + } + fn sender(&self) -> &Address { + &self.sender + } } pub type SharedTransaction = Arc; @@ -57,8 +63,10 @@ impl TestPool { } } -fn import, L: Listener>(txq: &mut Pool, tx: Transaction) - -> Result, Error<::Hash>> { +fn import, L: Listener>( + txq: &mut Pool, + tx: Transaction, +) -> Result, Error<::Hash>> { txq.import(tx, &mut DummyScoring::default()) } @@ -67,32 +75,41 @@ fn should_clear_queue() { // given let b = TransactionBuilder::default(); let mut txq = TestPool::default(); - assert_eq!(txq.light_status(), LightStatus { - mem_usage: 0, - transaction_count: 0, - senders: 0, - }); + assert_eq!( + txq.light_status(), + LightStatus { + mem_usage: 0, + transaction_count: 0, + senders: 0, + } + ); let tx1 = b.tx().nonce(0).new(); let tx2 = b.tx().nonce(1).mem_usage(1).new(); // add import(&mut txq, tx1).unwrap(); import(&mut txq, tx2).unwrap(); - assert_eq!(txq.light_status(), LightStatus { - mem_usage: 1, - transaction_count: 2, - senders: 1, - }); + assert_eq!( + txq.light_status(), + LightStatus { + mem_usage: 1, + transaction_count: 2, + senders: 1, + } + ); // when txq.clear(); // then - assert_eq!(txq.light_status(), LightStatus { - mem_usage: 0, - transaction_count: 0, - senders: 0, - }); + assert_eq!( + txq.light_status(), + LightStatus { + mem_usage: 0, + transaction_count: 0, + senders: 0, + } + ); } #[test] @@ -140,7 +157,10 @@ fn should_reject_if_above_count() { let tx2 = b.tx().nonce(1).new(); let hash = tx2.hash.clone(); import(&mut txq, tx1).unwrap(); - assert_eq!(import(&mut txq, tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into())); + assert_eq!( + import(&mut txq, tx2).unwrap_err(), + error::Error::TooCheapToEnter(hash, "0x0".into()) + ); assert_eq!(txq.light_status().transaction_count, 1); txq.clear(); @@ -166,7 +186,10 @@ fn should_reject_if_above_mem_usage() { let tx2 = b.tx().nonce(2).mem_usage(2).new(); let hash = tx2.hash.clone(); import(&mut txq, tx1).unwrap(); - assert_eq!(import(&mut txq, tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into())); + assert_eq!( + import(&mut txq, tx2).unwrap_err(), + error::Error::TooCheapToEnter(hash, "0x0".into()) + ); assert_eq!(txq.light_status().transaction_count, 1); txq.clear(); @@ -192,7 +215,10 @@ fn should_reject_if_above_sender_count() { let tx2 = b.tx().nonce(2).new(); let hash = tx2.hash.clone(); import(&mut txq, tx1).unwrap(); - assert_eq!(import(&mut txq, tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into())); + assert_eq!( + import(&mut txq, tx2).unwrap_err(), + error::Error::TooCheapToEnter(hash, "0x0".into()) + ); assert_eq!(txq.light_status().transaction_count, 1); txq.clear(); @@ -203,7 +229,10 @@ fn should_reject_if_above_sender_count() { let hash = tx2.hash.clone(); import(&mut txq, tx1).unwrap(); // This results in error because we also compare nonces - assert_eq!(import(&mut txq, tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into())); + assert_eq!( + import(&mut txq, tx2).unwrap_err(), + error::Error::TooCheapToEnter(hash, "0x0".into()) + ); assert_eq!(txq.light_status().transaction_count, 1); } @@ -234,16 +263,22 @@ fn should_construct_pending() { import(&mut txq, b.tx().sender(1).nonce(5).new()).unwrap(); assert_eq!(txq.light_status().transaction_count, 11); - assert_eq!(txq.status(NonceReady::default()), Status { - stalled: 0, - pending: 9, - future: 2, - }); - assert_eq!(txq.status(NonceReady::new(1)), Status { - stalled: 3, - pending: 6, - future: 2, - }); + assert_eq!( + txq.status(NonceReady::default()), + Status { + stalled: 0, + pending: 9, + future: 2, + } + ); + assert_eq!( + txq.status(NonceReady::new(1)), + Status { + stalled: 3, + pending: 6, + future: 2, + } + ); // when let mut current_gas = U256::zero(); @@ -306,16 +341,22 @@ fn should_return_unordered_iterator() { let tx9 = import(&mut txq, b.tx().sender(2).nonce(0).new()).unwrap(); assert_eq!(txq.light_status().transaction_count, 11); - assert_eq!(txq.status(NonceReady::default()), Status { - stalled: 0, - pending: 9, - future: 2, - }); - assert_eq!(txq.status(NonceReady::new(1)), Status { - stalled: 3, - pending: 6, - future: 2, - }); + assert_eq!( + txq.status(NonceReady::default()), + Status { + stalled: 0, + pending: 9, + future: 2, + } + ); + assert_eq!( + txq.status(NonceReady::new(1)), + Status { + stalled: 3, + pending: 6, + future: 2, + } + ); // when let all: Vec<_> = txq.unordered_pending(NonceReady::default()).collect(); @@ -333,7 +374,9 @@ fn should_return_unordered_iterator() { vec![chain3.clone(), chain2.clone(), chain1.clone()], vec![chain3.clone(), chain1.clone(), chain2.clone()], vec![chain1.clone(), chain3.clone(), chain2.clone()], - ].into_iter().map(|mut v| { + ] + .into_iter() + .map(|mut v| { let mut first = v.pop().unwrap(); for mut x in v { first.append(&mut x); @@ -370,16 +413,22 @@ fn should_update_scoring_correctly() { import(&mut txq, b.tx().sender(1).nonce(5).new()).unwrap(); assert_eq!(txq.light_status().transaction_count, 11); - assert_eq!(txq.status(NonceReady::default()), Status { - stalled: 0, - pending: 9, - future: 2, - }); - assert_eq!(txq.status(NonceReady::new(1)), Status { - stalled: 3, - pending: 6, - future: 2, - }); + assert_eq!( + txq.status(NonceReady::default()), + Status { + stalled: 0, + pending: 9, + future: 2, + } + ); + assert_eq!( + txq.status(NonceReady::new(1)), + Status { + stalled: 3, + pending: 6, + future: 2, + } + ); txq.update_scores(&Address::zero(), ()); @@ -441,26 +490,35 @@ fn should_cull_stalled_transactions() { import(&mut txq, b.tx().sender(1).nonce(1).new()).unwrap(); import(&mut txq, b.tx().sender(1).nonce(5).new()).unwrap(); - assert_eq!(txq.status(NonceReady::new(1)), Status { - stalled: 2, - pending: 2, - future: 2, - }); + assert_eq!( + txq.status(NonceReady::new(1)), + Status { + stalled: 2, + pending: 2, + future: 2, + } + ); // when assert_eq!(txq.cull(None, NonceReady::new(1)), 2); // then - assert_eq!(txq.status(NonceReady::new(1)), Status { - stalled: 0, - pending: 2, - future: 2, - }); - assert_eq!(txq.light_status(), LightStatus { - transaction_count: 4, - senders: 2, - mem_usage: 0, - }); + assert_eq!( + txq.status(NonceReady::new(1)), + Status { + stalled: 0, + pending: 2, + future: 2, + } + ); + assert_eq!( + txq.light_status(), + LightStatus { + transaction_count: 4, + senders: 2, + mem_usage: 0, + } + ); } #[test] @@ -476,27 +534,36 @@ fn should_cull_stalled_transactions_from_a_sender() { import(&mut txq, b.tx().sender(1).nonce(1).new()).unwrap(); import(&mut txq, b.tx().sender(1).nonce(2).new()).unwrap(); - assert_eq!(txq.status(NonceReady::new(2)), Status { - stalled: 4, - pending: 1, - future: 0, - }); + assert_eq!( + txq.status(NonceReady::new(2)), + Status { + stalled: 4, + pending: 1, + future: 0, + } + ); // when let sender = Address::zero(); assert_eq!(txq.cull(Some(&[sender]), NonceReady::new(2)), 2); // then - assert_eq!(txq.status(NonceReady::new(2)), Status { - stalled: 2, - pending: 1, - future: 0, - }); - assert_eq!(txq.light_status(), LightStatus { - transaction_count: 3, - senders: 1, - mem_usage: 0, - }); + assert_eq!( + txq.status(NonceReady::new(2)), + Status { + stalled: 2, + pending: 1, + future: 0, + } + ); + assert_eq!( + txq.light_status(), + LightStatus { + transaction_count: 3, + senders: 1, + mem_usage: 0, + } + ); } #[test] @@ -509,27 +576,36 @@ fn should_re_insert_after_cull() { import(&mut txq, b.tx().nonce(1).new()).unwrap(); import(&mut txq, b.tx().sender(1).nonce(0).new()).unwrap(); import(&mut txq, b.tx().sender(1).nonce(1).new()).unwrap(); - assert_eq!(txq.status(NonceReady::new(1)), Status { - stalled: 2, - pending: 2, - future: 0, - }); + assert_eq!( + txq.status(NonceReady::new(1)), + Status { + stalled: 2, + pending: 2, + future: 0, + } + ); // when assert_eq!(txq.cull(None, NonceReady::new(1)), 2); - assert_eq!(txq.status(NonceReady::new(1)), Status { - stalled: 0, - pending: 2, - future: 0, - }); + assert_eq!( + txq.status(NonceReady::new(1)), + Status { + stalled: 0, + pending: 2, + future: 0, + } + ); import(&mut txq, b.tx().nonce(0).gas_price(5).new()).unwrap(); import(&mut txq, b.tx().sender(1).nonce(0).new()).unwrap(); - assert_eq!(txq.status(NonceReady::new(1)), Status { - stalled: 2, - pending: 2, - future: 0, - }); + assert_eq!( + txq.status(NonceReady::new(1)), + Status { + stalled: 2, + pending: 2, + future: 0, + } + ); } #[test] @@ -568,26 +644,43 @@ fn should_return_is_full() { fn should_import_even_if_limit_is_reached_and_should_replace_returns_insert_new() { // given let b = TransactionBuilder::default(); - let mut txq = TestPool::with_scoring(DummyScoring::always_insert(), Options { - max_count: 1, - ..Default::default() - }); - txq.import(b.tx().nonce(0).gas_price(5).new(), &mut DummyScoring::always_insert()).unwrap(); - assert_eq!(txq.light_status(), LightStatus { - transaction_count: 1, - senders: 1, - mem_usage: 0, - }); + let mut txq = TestPool::with_scoring( + DummyScoring::always_insert(), + Options { + max_count: 1, + ..Default::default() + }, + ); + txq.import( + b.tx().nonce(0).gas_price(5).new(), + &mut DummyScoring::always_insert(), + ) + .unwrap(); + assert_eq!( + txq.light_status(), + LightStatus { + transaction_count: 1, + senders: 1, + mem_usage: 0, + } + ); // when - txq.import(b.tx().nonce(1).gas_price(5).new(), &mut DummyScoring::always_insert()).unwrap(); + txq.import( + b.tx().nonce(1).gas_price(5).new(), + &mut DummyScoring::always_insert(), + ) + .unwrap(); // then - assert_eq!(txq.light_status(), LightStatus { - transaction_count: 2, - senders: 1, - mem_usage: 0, - }); + assert_eq!( + txq.light_status(), + LightStatus { + transaction_count: 2, + senders: 1, + mem_usage: 0, + } + ); } #[test] @@ -596,16 +689,22 @@ fn should_not_import_even_if_limit_is_reached_and_should_replace_returns_false() // given let b = TransactionBuilder::default(); - let mut txq = TestPool::with_scoring(DummyScoring::default(), Options { - max_count: 1, - ..Default::default() - }); + let mut txq = TestPool::with_scoring( + DummyScoring::default(), + Options { + max_count: 1, + ..Default::default() + }, + ); import(&mut txq, b.tx().nonce(0).gas_price(5).new()).unwrap(); - assert_eq!(txq.light_status(), LightStatus { - transaction_count: 1, - senders: 1, - mem_usage: 0, - }); + assert_eq!( + txq.light_status(), + LightStatus { + transaction_count: 1, + senders: 1, + mem_usage: 0, + } + ); // when let err = import(&mut txq, b.tx().nonce(1).gas_price(5).new()).unwrap_err(); @@ -614,48 +713,69 @@ fn should_not_import_even_if_limit_is_reached_and_should_replace_returns_false() assert_eq!( err, error::Error::TooCheapToEnter( - H256::from_str("00000000000000000000000000000000000000000000000000000000000001f5").unwrap(), + H256::from_str("00000000000000000000000000000000000000000000000000000000000001f5") + .unwrap(), "0x5".into() ) ); - assert_eq!(txq.light_status(), LightStatus { - transaction_count: 1, - senders: 1, - mem_usage: 0, - }); + assert_eq!( + txq.light_status(), + LightStatus { + transaction_count: 1, + senders: 1, + mem_usage: 0, + } + ); } #[test] fn should_import_even_if_sender_limit_is_reached() { // given let b = TransactionBuilder::default(); - let mut txq = TestPool::with_scoring(DummyScoring::always_insert(), Options { - max_count: 1, - max_per_sender: 1, - ..Default::default() - }); - txq.import(b.tx().nonce(0).gas_price(5).new(), &mut DummyScoring::always_insert()).unwrap(); - assert_eq!(txq.light_status(), LightStatus { - transaction_count: 1, - senders: 1, - mem_usage: 0, - }); + let mut txq = TestPool::with_scoring( + DummyScoring::always_insert(), + Options { + max_count: 1, + max_per_sender: 1, + ..Default::default() + }, + ); + txq.import( + b.tx().nonce(0).gas_price(5).new(), + &mut DummyScoring::always_insert(), + ) + .unwrap(); + assert_eq!( + txq.light_status(), + LightStatus { + transaction_count: 1, + senders: 1, + mem_usage: 0, + } + ); // when - txq.import(b.tx().nonce(1).gas_price(5).new(), &mut DummyScoring::always_insert()).unwrap(); + txq.import( + b.tx().nonce(1).gas_price(5).new(), + &mut DummyScoring::always_insert(), + ) + .unwrap(); // then - assert_eq!(txq.light_status(), LightStatus { - transaction_count: 2, - senders: 1, - mem_usage: 0, - }); + assert_eq!( + txq.light_status(), + LightStatus { + transaction_count: 2, + senders: 1, + mem_usage: 0, + } + ); } mod listener { use std::cell::RefCell; - use std::rc::Rc; use std::fmt; + use std::rc::Rc; use super::*; @@ -664,10 +784,16 @@ mod listener { impl Listener for MyListener { fn added(&mut self, _tx: &SharedTransaction, old: Option<&SharedTransaction>) { - self.0.borrow_mut().push(if old.is_some() { "replaced" } else { "added" }); + self.0 + .borrow_mut() + .push(if old.is_some() { "replaced" } else { "added" }); } - fn rejected(&mut self, _tx: &SharedTransaction, _reason: &error::Error) { + fn rejected( + &mut self, + _tx: &SharedTransaction, + _reason: &error::Error, + ) { self.0.borrow_mut().push("rejected".into()); } @@ -693,11 +819,15 @@ mod listener { let b = TransactionBuilder::default(); let listener = MyListener::default(); let results = listener.0.clone(); - let mut txq = Pool::new(listener, DummyScoring::default(), Options { - max_per_sender: 1, - max_count: 2, - ..Default::default() - }); + let mut txq = Pool::new( + listener, + DummyScoring::default(), + Options { + max_per_sender: 1, + max_count: 2, + ..Default::default() + }, + ); assert!(results.borrow().is_empty()); // Regular import @@ -721,7 +851,10 @@ mod listener { assert_eq!(*results.borrow(), &["added", "dropped", "added"]); // Reject (too cheap) import(&mut txq, b.tx().sender(2).nonce(1).gas_price(2).new()).unwrap_err(); - assert_eq!(*results.borrow(), &["added", "dropped", "added", "rejected"]); + assert_eq!( + *results.borrow(), + &["added", "dropped", "added", "rejected"] + ); assert_eq!(txq.light_status().transaction_count, 2); } @@ -741,7 +874,10 @@ mod listener { txq.remove(&tx1.hash(), false); assert_eq!(*results.borrow(), &["added", "added", "canceled"]); txq.remove(&tx2.hash(), true); - assert_eq!(*results.borrow(), &["added", "added", "canceled", "invalid"]); + assert_eq!( + *results.borrow(), + &["added", "added", "canceled", "invalid"] + ); assert_eq!(txq.light_status().transaction_count, 0); } diff --git a/transaction-pool/src/tests/tx_builder.rs b/transaction-pool/src/tests/tx_builder.rs index dae2bb248..83f7b13a0 100644 --- a/transaction-pool/src/tests/tx_builder.rs +++ b/transaction-pool/src/tests/tx_builder.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use super::{Transaction, U256, H256, Address}; +use super::{Address, Transaction, H256, U256}; use ethereum_types::BigEndianHash; #[derive(Debug, Default, Clone)] @@ -52,7 +52,9 @@ impl TransactionBuilder { } pub fn new(self) -> Transaction { - let hash: U256 = self.nonce ^ (U256::from(100) * self.gas_price) ^ (U256::from(100_000) * U256::from(self.sender.to_low_u64_be())); + let hash: U256 = self.nonce + ^ (U256::from(100) * self.gas_price) + ^ (U256::from(100_000) * U256::from(self.sender.to_low_u64_be())); Transaction { hash: H256::from_uint(&hash), nonce: self.nonce, diff --git a/transaction-pool/src/transactions.rs b/transaction-pool/src/transactions.rs index 8256bf33a..b21bad038 100644 --- a/transaction-pool/src/transactions.rs +++ b/transaction-pool/src/transactions.rs @@ -16,31 +16,22 @@ use std::{fmt, mem}; -use smallvec::SmallVec; use log::warn; +use smallvec::SmallVec; use crate::{ - ready::{Ready, Readiness}, - scoring::{self, Scoring}, pool::Transaction, + ready::{Readiness, Ready}, + scoring::{self, Scoring}, }; #[derive(Debug)] pub enum AddResult { Ok(T), TooCheapToEnter(T, S), - TooCheap { - old: T, - new: T, - }, - Replaced { - old: T, - new: T, - }, - PushedOut { - old: T, - new: T, - }, + TooCheap { old: T, new: T }, + Replaced { old: T, new: T }, + PushedOut { old: T, new: T }, } /// Represents all transactions from a particular sender ordered by nonce. @@ -74,7 +65,9 @@ impl> Transactions { self.transactions.iter() } - pub fn worst_and_best(&self) -> Option<((S::Score, Transaction), (S::Score, Transaction))> { + pub fn worst_and_best( + &self, + ) -> Option<((S::Score, Transaction), (S::Score, Transaction))> { let len = self.scores.len(); self.scores.get(0).cloned().map(|best| { let worst = self.scores[len - 1].clone(); @@ -86,17 +79,25 @@ impl> Transactions { } pub fn find_next(&self, tx: &T, scoring: &S) -> Option<(S::Score, Transaction)> { - self.transactions.binary_search_by(|old| scoring.compare(old, &tx)).ok().and_then(|index| { - let index = index + 1; - if index < self.scores.len() { - Some((self.scores[index].clone(), self.transactions[index].clone())) - } else { - None - } - }) + self.transactions + .binary_search_by(|old| scoring.compare(old, &tx)) + .ok() + .and_then(|index| { + let index = index + 1; + if index < self.scores.len() { + Some((self.scores[index].clone(), self.transactions[index].clone())) + } else { + None + } + }) } - fn push_cheapest_transaction(&mut self, tx: Transaction, scoring: &S, max_count: usize) -> AddResult, S::Score> { + fn push_cheapest_transaction( + &mut self, + tx: Transaction, + scoring: &S, + max_count: usize, + ) -> AddResult, S::Score> { let index = self.transactions.len(); if index == max_count && !scoring.should_ignore_sender_limit(&tx) { let min_score = self.scores[index - 1].clone(); @@ -104,25 +105,41 @@ impl> Transactions { } else { self.transactions.push(tx.clone()); self.scores.push(Default::default()); - scoring.update_scores(&self.transactions, &mut self.scores, scoring::Change::InsertedAt(index)); + scoring.update_scores( + &self.transactions, + &mut self.scores, + scoring::Change::InsertedAt(index), + ); AddResult::Ok(tx) } } pub fn update_scores(&mut self, scoring: &S, event: S::Event) { - scoring.update_scores(&self.transactions, &mut self.scores, scoring::Change::Event(event)); + scoring.update_scores( + &self.transactions, + &mut self.scores, + scoring::Change::Event(event), + ); } - pub fn add(&mut self, new: Transaction, scoring: &S, max_count: usize) -> AddResult, S::Score> { - let index = match self.transactions.binary_search_by(|old| scoring.compare(old, &new)) { + pub fn add( + &mut self, + new: Transaction, + scoring: &S, + max_count: usize, + ) -> AddResult, S::Score> { + let index = match self + .transactions + .binary_search_by(|old| scoring.compare(old, &new)) + { Ok(index) => index, Err(index) => index, }; // Insert at the end. if index == self.transactions.len() { - return self.push_cheapest_transaction(new, scoring, max_count) + return self.push_cheapest_transaction(new, scoring, max_count); } // Decide if the transaction should replace some other. @@ -136,51 +153,68 @@ impl> Transactions { scoring::Choice::InsertNew => { self.transactions.insert(index, new.clone()); self.scores.insert(index, Default::default()); - scoring.update_scores(&self.transactions, &mut self.scores, scoring::Change::InsertedAt(index)); + scoring.update_scores( + &self.transactions, + &mut self.scores, + scoring::Change::InsertedAt(index), + ); if self.transactions.len() > max_count { let old = self.transactions.pop().expect("len is non-zero"); self.scores.pop(); - scoring.update_scores(&self.transactions, &mut self.scores, scoring::Change::RemovedAt(self.transactions.len())); + scoring.update_scores( + &self.transactions, + &mut self.scores, + scoring::Change::RemovedAt(self.transactions.len()), + ); - AddResult::PushedOut { - old, - new, - } + AddResult::PushedOut { old, new } } else { AddResult::Ok(new) } - }, + } // New transaction is replacing some other transaction already in the queue. scoring::Choice::ReplaceOld => { let old = mem::replace(&mut self.transactions[index], new.clone()); - scoring.update_scores(&self.transactions, &mut self.scores, scoring::Change::ReplacedAt(index)); + scoring.update_scores( + &self.transactions, + &mut self.scores, + scoring::Change::ReplacedAt(index), + ); - AddResult::Replaced { - old, - new, - } - }, + AddResult::Replaced { old, new } + } } } pub fn remove(&mut self, tx: &T, scoring: &S) -> bool { - let index = match self.transactions.binary_search_by(|old| scoring.compare(old, tx)) { + let index = match self + .transactions + .binary_search_by(|old| scoring.compare(old, tx)) + { Ok(index) => index, Err(_) => { warn!("Attempting to remove non-existent transaction {:?}", tx); return false; - }, + } }; self.transactions.remove(index); self.scores.remove(index); // Update scoring - scoring.update_scores(&self.transactions, &mut self.scores, scoring::Change::RemovedAt(index)); + scoring.update_scores( + &self.transactions, + &mut self.scores, + scoring::Change::RemovedAt(index), + ); return true; } - pub fn cull>(&mut self, ready: &mut R, scoring: &S) -> SmallVec<[Transaction; PER_SENDER]> { + pub fn cull>( + &mut self, + ready: &mut R, + scoring: &S, + ) -> SmallVec<[Transaction; PER_SENDER]> { let mut result = SmallVec::new(); if self.is_empty() { return result; @@ -191,7 +225,7 @@ impl> Transactions { match ready.is_ready(tx) { Readiness::Stale => { first_non_stalled += 1; - }, + } Readiness::Ready | Readiness::Future => break, } } @@ -207,7 +241,9 @@ impl> Transactions { for _ in 0..first_non_stalled { self.scores.pop(); result.push( - self.transactions.pop().expect("first_non_stalled is never greater than transactions.len(); qed") + self.transactions + .pop() + .expect("first_non_stalled is never greater than transactions.len(); qed"), ); } @@ -215,7 +251,11 @@ impl> Transactions { self.scores.reverse(); // update scoring - scoring.update_scores(&self.transactions, &mut self.scores, scoring::Change::Culled(result.len())); + scoring.update_scores( + &self.transactions, + &mut self.scores, + scoring::Change::Culled(result.len()), + ); // reverse the result to maintain correct order. result.reverse(); diff --git a/triehash/benches/triehash.rs b/triehash/benches/triehash.rs index 8930f473e..fea116a46 100644 --- a/triehash/benches/triehash.rs +++ b/triehash/benches/triehash.rs @@ -42,7 +42,7 @@ fn random_bytes(min_count: usize, diff_count: usize, seed: &mut H256) -> Vec fn random_value(seed: &mut H256) -> Vec { *seed = H256(keccak256(seed.as_bytes())); match seed[0] % 2 { - 1 => vec![seed[31];1], + 1 => vec![seed[31]; 1], _ => seed.as_bytes().to_vec(), } } diff --git a/triehash/src/lib.rs b/triehash/src/lib.rs index 94bcbfaed..cbbaa0f81 100644 --- a/triehash/src/lib.rs +++ b/triehash/src/lib.rs @@ -26,7 +26,8 @@ use hash_db::Hasher; use rlp::RlpStream; fn shared_prefix_len(first: &[T], second: &[T]) -> usize { - first.iter() + first + .iter() .zip(second.iter()) .position(|(f, s)| f != s) .unwrap_or_else(|| cmp::min(first.len(), second.len())) @@ -56,7 +57,12 @@ where H: Hasher, ::Out: cmp::Ord, { - trie_root::(input.into_iter().enumerate().map(|(i, v)| (rlp::encode(&i), v))) + trie_root::( + input + .into_iter() + .enumerate() + .map(|(i, v)| (rlp::encode(&i), v)), + ) } /// Generates a trie root hash for a vector of key-value tuples @@ -90,9 +96,7 @@ where ::Out: cmp::Ord, { // first put elements into btree to sort them and to remove duplicates - let input = input - .into_iter() - .collect::>(); + let input = input.into_iter().collect::>(); let mut nibbles = Vec::with_capacity(input.keys().map(|k| k.as_ref().len()).sum::() * 2); let mut lens = Vec::with_capacity(input.len() + 1); @@ -106,7 +110,9 @@ where } // then move them to a vector - let input = input.into_iter().zip(lens.windows(2)) + let input = input + .into_iter() + .zip(lens.windows(2)) .map(|((_, v), w)| (&nibbles[w[0]..w[1]], v)) .collect::>(); @@ -178,7 +184,11 @@ fn hex_prefix_encode<'a>(nibbles: &'a [u8], leaf: bool) -> impl Iterator(input: &[(A, B)], pre_len: usize, stream: &mut RlpStream) @@ -209,11 +219,12 @@ where } // get length of the longest shared prefix in slice keys - let shared_prefix = input.iter() + let shared_prefix = input + .iter() // skip first tuple .skip(1) // get minimum number of shared nibbles between first and each successive - .fold(key.len(), | acc, &(ref k, _) | { + .fold(key.len(), |acc, &(ref k, _)| { cmp::min(shared_prefix_len(key, k.as_ref()), acc) }); @@ -246,8 +257,10 @@ where // if at least 1 successive element has the same nibble // append their suffixes match len { - 0 => { stream.append_empty_data(); }, - _ => hash256aux::(&input[begin..(begin + len)], pre_len + 1, stream) + 0 => { + stream.append_empty_data(); + } + _ => hash256aux::(&input[begin..(begin + len)], pre_len + 1, stream), } begin += len; } @@ -271,16 +284,16 @@ where let out = s.out(); match out.len() { 0..=31 => stream.append_raw(&out, 1), - _ => stream.append(&H::hash(&out).as_ref()) + _ => stream.append(&H::hash(&out).as_ref()), }; } #[cfg(test)] mod tests { - use super::{trie_root, shared_prefix_len, hex_prefix_encode}; - use keccak_hasher::KeccakHasher; + use super::{hex_prefix_encode, shared_prefix_len, trie_root}; use ethereum_types::H256; use hex_literal::hex; + use keccak_hasher::KeccakHasher; #[test] fn test_hex_prefix_encode() { @@ -318,10 +331,14 @@ mod tests { #[test] fn simple_test() { assert_eq!( - trie_root::(vec![ - (b"A", b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" as &[u8]) - ]), - H256::from(hex!("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab")).as_ref(), + trie_root::(vec![( + b"A", + b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" as &[u8] + )]), + H256::from(hex!( + "d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab" + )) + .as_ref(), ); } @@ -343,22 +360,22 @@ mod tests { #[test] fn test_shared_prefix() { - let a = vec![1,2,3,4,5,6]; - let b = vec![4,2,3,4,5,6]; + let a = vec![1, 2, 3, 4, 5, 6]; + let b = vec![4, 2, 3, 4, 5, 6]; assert_eq!(shared_prefix_len(&a, &b), 0); } #[test] fn test_shared_prefix2() { - let a = vec![1,2,3,3,5]; - let b = vec![1,2,3]; + let a = vec![1, 2, 3, 3, 5]; + let b = vec![1, 2, 3]; assert_eq!(shared_prefix_len(&a, &b), 3); } #[test] fn test_shared_prefix3() { - let a = vec![1,2,3,4,5,6]; - let b = vec![1,2,3,4,5,6]; + let a = vec![1, 2, 3, 4, 5, 6]; + let b = vec![1, 2, 3, 4, 5, 6]; assert_eq!(shared_prefix_len(&a, &b), 6); } } diff --git a/uint/benches/bigint.rs b/uint/benches/bigint.rs index 61f24e93d..ee0591a97 100644 --- a/uint/benches/bigint.rs +++ b/uint/benches/bigint.rs @@ -12,7 +12,6 @@ //! rustup run cargo bench //! ``` - use criterion::{criterion_group, criterion_main}; use uint::{construct_uint, uint_full_mul_reg}; @@ -107,7 +106,11 @@ fn u128_div(c: &mut Criterion) { black_box(x / u128::from(*z)) }) }, - vec![(0u64, u64::max_value(), 100u64), (u64::max_value(), u64::max_value(), 99), (42, 42, 100500)], + vec![ + (0u64, u64::max_value(), 100u64), + (u64::max_value(), u64::max_value(), 99), + (42, 42, 100500), + ], ), ); } @@ -160,7 +163,10 @@ fn u256_mul(c: &mut Criterion) { (U256::max_value(), 1u64), (U256::from(3), u64::max_value()), ( - U256::from_dec_str("21674844646682989462120101885968193938394323990565507610662749").unwrap(), + U256::from_dec_str( + "21674844646682989462120101885968193938394323990565507610662749", + ) + .unwrap(), 173, ), ], @@ -220,7 +226,12 @@ fn u256_mul_full(c: &mut Criterion) { b.iter(|| { let y = *y; let U512(ref u512words) = x.full_mul(U256([y, y, y, y])); - black_box(U256([u512words[0], u512words[2], u512words[2], u512words[3]])) + black_box(U256([ + u512words[0], + u512words[2], + u512words[2], + u512words[3], + ])) }) }, vec![(U256::from(42), 1u64), (U256::from(3), u64::max_value())], @@ -229,8 +240,18 @@ fn u256_mul_full(c: &mut Criterion) { } fn u256_div(c: &mut Criterion) { - let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); - let two = U256([2096410819092764509, 8483673822214032535, 36306297304129857, 3453]); + let one = U256([ + 12767554894655550452, + 16333049135534778834, + 140317443000293558, + 598963, + ]); + let two = U256([ + 2096410819092764509, + 8483673822214032535, + 36306297304129857, + 3453, + ]); c.bench_function("u256_div", move |b| b.iter(|| black_box(one / two))); } @@ -242,10 +263,23 @@ fn u256_rem(c: &mut Criterion) { |b, (x, y)| b.iter(|| black_box(x % y)), vec![ (U256::max_value(), U256::from(1u64)), - (U256::from(u64::max_value()), U256::from(u64::from(u32::max_value()) + 1)), ( - U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]), - U256([2096410819092764509, 8483673822214032535, 36306297304129857, 3453]), + U256::from(u64::max_value()), + U256::from(u64::from(u32::max_value()) + 1), + ), + ( + U256([ + 12767554894655550452, + 16333049135534778834, + 140317443000293558, + 598963, + ]), + U256([ + 2096410819092764509, + 8483673822214032535, + 36306297304129857, + 3453, + ]), ), ( U256::from_str( @@ -265,7 +299,10 @@ fn u256_rem(c: &mut Criterion) { fn u512_pairs() -> Vec<(U512, U512)> { vec![ (U512::from(1u64), U512::from(0u64)), - (U512::from(u64::max_value()), U512::from(u64::from(u32::max_value()) + 1)), + ( + U512::from(u64::max_value()), + U512::from(u64::from(u32::max_value()) + 1), + ), ( U512([ 12767554894655550452, @@ -277,7 +314,16 @@ fn u512_pairs() -> Vec<(U512, U512)> { 0, 0, ]), - U512([0, 0, 0, 0, 2096410819092764509, 8483673822214032535, 36306297304129857, 3453]), + U512([ + 0, + 0, + 0, + 0, + 2096410819092764509, + 8483673822214032535, + 36306297304129857, + 3453, + ]), ), ( U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") @@ -407,17 +453,13 @@ fn u512_mul_u32_vs_u64(c: &mut Criterion) { fn bench_u512_mul_u32(b: &mut Bencher, i: u32) { let x = U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); - b.iter(|| { - black_box(x * i) - }); + b.iter(|| black_box(x * i)); } fn bench_u512_mul_u64(b: &mut Bencher, i: u64) { let x = U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); - b.iter(|| { - black_box(x * i) - }); + b.iter(|| black_box(x * i)); } fn mulmod_u512_vs_biguint_vs_gmp(c: &mut Criterion) { @@ -478,8 +520,18 @@ fn u128_mul(c: &mut Criterion) { } fn u256_bit_and(c: &mut Criterion) { - let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); - let two = U256([2096410819092764509, 8483673822214032535, 36306297304129857, 3453]); + let one = U256([ + 12767554894655550452, + 16333049135534778834, + 140317443000293558, + 598963, + ]); + let two = U256([ + 2096410819092764509, + 8483673822214032535, + 36306297304129857, + 3453, + ]); c.bench_function("u256_bit_and", move |b| b.iter(|| black_box(one & two))); } @@ -508,8 +560,18 @@ fn u512_bit_and(c: &mut Criterion) { } fn u256_bit_xor(c: &mut Criterion) { - let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); - let two = U256([2096410819092764509, 8483673822214032535, 36306297304129857, 3453]); + let one = U256([ + 12767554894655550452, + 16333049135534778834, + 140317443000293558, + 598963, + ]); + let two = U256([ + 2096410819092764509, + 8483673822214032535, + 36306297304129857, + 3453, + ]); c.bench_function("u256_bit_xor", move |b| b.iter(|| black_box(one ^ two))); } @@ -538,8 +600,18 @@ fn u512_bit_xor(c: &mut Criterion) { } fn u256_bit_or(c: &mut Criterion) { - let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); - let two = U256([2096410819092764509, 8483673822214032535, 36306297304129857, 3453]); + let one = U256([ + 12767554894655550452, + 16333049135534778834, + 140317443000293558, + 598963, + ]); + let two = U256([ + 2096410819092764509, + 8483673822214032535, + 36306297304129857, + 3453, + ]); c.bench_function("u256_bit_or", move |b| b.iter(|| black_box(one | two))); } @@ -568,7 +640,12 @@ fn u512_bit_or(c: &mut Criterion) { } fn u256_not(c: &mut Criterion) { - let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); + let one = U256([ + 12767554894655550452, + 16333049135534778834, + 140317443000293558, + 598963, + ]); c.bench_function("u256_not", move |b| b.iter(|| black_box(!one))); } @@ -587,7 +664,12 @@ fn u512_not(c: &mut Criterion) { } fn u256_shl(c: &mut Criterion) { - let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); + let one = U256([ + 12767554894655550452, + 16333049135534778834, + 140317443000293558, + 598963, + ]); c.bench_function("u256_shl", move |b| b.iter(|| black_box(one << 128))); } @@ -606,7 +688,12 @@ fn u512_shl(c: &mut Criterion) { } fn u256_shr(c: &mut Criterion) { - let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); + let one = U256([ + 12767554894655550452, + 16333049135534778834, + 140317443000293558, + 598963, + ]); c.bench_function("u256_shr", move |b| b.iter(|| black_box(one >> 128))); } @@ -625,8 +712,18 @@ fn u512_shr(c: &mut Criterion) { } fn u256_ord(c: &mut Criterion) { - let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); - let two = U256([2096410819092764509, 8483673822214032535, 36306297304129857, 3453]); + let one = U256([ + 12767554894655550452, + 16333049135534778834, + 140317443000293558, + 598963, + ]); + let two = U256([ + 2096410819092764509, + 8483673822214032535, + 36306297304129857, + 3453, + ]); c.bench_function("u256_ord", move |b| b.iter(|| black_box(one < two))); } diff --git a/uint/examples/modular.rs b/uint/examples/modular.rs index 1364bd766..1c0e3fb2d 100644 --- a/uint/examples/modular.rs +++ b/uint/examples/modular.rs @@ -6,8 +6,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - #[macro_use] extern crate uint; @@ -22,8 +20,9 @@ fn main() { // where the p is defined below // (it's a prime!) let p = U256::from_dec_str( - "38873241744847760218045702002058062581688990428170398542849190507947196700873" - ).expect("p to be a good number in the example"); + "38873241744847760218045702002058062581688990428170398542849190507947196700873", + ) + .expect("p to be a good number in the example"); // then, on this field, // (p-1) + (p+1) = 0 @@ -50,7 +49,7 @@ fn main() { let multiplicator = 3; let mul = { let mut result = p_minus_1; - for _ in 0..multiplicator-1 { + for _ in 0..multiplicator - 1 { result = (p_minus_1 + result) % p; } result diff --git a/uint/src/lib.rs b/uint/src/lib.rs index e72c32d5f..519028a9d 100644 --- a/uint/src/lib.rs +++ b/uint/src/lib.rs @@ -21,11 +21,11 @@ pub use core as core_; #[doc(hidden)] pub use rustc_hex; -#[cfg(feature="quickcheck")] +#[cfg(feature = "quickcheck")] #[doc(hidden)] pub use qc; -#[cfg(feature="quickcheck")] +#[cfg(feature = "quickcheck")] #[doc(hidden)] pub use rand; diff --git a/uint/src/uint.rs b/uint/src/uint.rs index 274cc529c..2cfdf7caf 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -47,7 +47,7 @@ macro_rules! impl_map_from { From::from(value as $to) } } - } + }; } #[macro_export] @@ -61,63 +61,69 @@ macro_rules! impl_try_from_for_primitive { fn try_from(u: $from) -> $crate::core_::result::Result<$to, &'static str> { let $from(arr) = u; if !u.fits_word() || arr[0] > <$to>::max_value() as u64 { - Err(concat!("integer overflow when casting to ", stringify!($to))) + Err(concat!( + "integer overflow when casting to ", + stringify!($to) + )) } else { Ok(arr[0] as $to) } } } - } + }; } #[macro_export] #[doc(hidden)] macro_rules! uint_overflowing_binop { - ($name:ident, $n_words: tt, $self_expr: expr, $other: expr, $fn:expr) => ({ - use $crate::{core_ as core}; + ($name:ident, $n_words: tt, $self_expr: expr, $other: expr, $fn:expr) => {{ + use $crate::core_ as core; let $name(ref me) = $self_expr; let $name(ref you) = $other; let mut ret = [0u64; $n_words]; let ret_ptr = &mut ret as *mut [u64; $n_words] as *mut u64; let mut carry = 0u64; - $crate::static_assertions::const_assert!(core::isize::MAX as usize / core::mem::size_of::() > $n_words); + $crate::static_assertions::const_assert!( + core::isize::MAX as usize / core::mem::size_of::() > $n_words + ); // `unroll!` is recursive, but doesn’t use `$crate::unroll`, so we need to ensure that it // is in scope unqualified. use $crate::unroll; unroll! { - for i in 0..$n_words { - use core::ptr; + for i in 0..$n_words { + use core::ptr; - if carry != 0 { - let (res1, overflow1) = ($fn)(me[i], you[i]); - let (res2, overflow2) = ($fn)(res1, carry); + if carry != 0 { + let (res1, overflow1) = ($fn)(me[i], you[i]); + let (res2, overflow2) = ($fn)(res1, carry); - unsafe { - // SAFETY: `i` is within bounds and `i * size_of::() < isize::MAX` - *ret_ptr.offset(i as _) = res2 - } - carry = (overflow1 as u8 + overflow2 as u8) as u64; - } else { - let (res, overflow) = ($fn)(me[i], you[i]); + unsafe { + // SAFETY: `i` is within bounds and `i * size_of::() < isize::MAX` + *ret_ptr.offset(i as _) = res2 + } + carry = (overflow1 as u8 + overflow2 as u8) as u64; + } else { + let (res, overflow) = ($fn)(me[i], you[i]); - unsafe { - // SAFETY: `i` is within bounds and `i * size_of::() < isize::MAX` - *ret_ptr.offset(i as _) = res - } + unsafe { + // SAFETY: `i` is within bounds and `i * size_of::() < isize::MAX` + *ret_ptr.offset(i as _) = res + } - carry = overflow as u64; + carry = overflow as u64; + } + } } - } - } ($name(ret), carry > 0) - }) + }}; } #[macro_export] #[doc(hidden)] +#[rustfmt::skip] macro_rules! uint_full_mul_reg { ($name:ident, 8, $self_expr:expr, $other:expr) => { $crate::uint_full_mul_reg!($name, 8, $self_expr, $other, |a, b| a != 0 || b != 0); @@ -125,57 +131,60 @@ macro_rules! uint_full_mul_reg { ($name:ident, $n_words:tt, $self_expr:expr, $other:expr) => { $crate::uint_full_mul_reg!($name, $n_words, $self_expr, $other, |_, _| true); }; - ($name:ident, $n_words:tt, $self_expr:expr, $other:expr, $check:expr) => ({{ - #![allow(unused_assignments)] + ($name:ident, $n_words:tt, $self_expr:expr, $other:expr, $check:expr) => {{ + { + #![allow(unused_assignments)] - let $name(ref me) = $self_expr; - let $name(ref you) = $other; - let mut ret = [0u64; $n_words * 2]; + let $name(ref me) = $self_expr; + let $name(ref you) = $other; + let mut ret = [0u64; $n_words * 2]; - use $crate::unroll; - unroll! { - for i in 0..$n_words { - let mut carry = 0u64; - let b = you[i]; - - unroll! { - for j in 0..$n_words { - if $check(me[j], carry) { - let a = me[j]; - - let (hi, low) = Self::split_u128(a as u128 * b as u128); - - let overflow = { - let existing_low = &mut ret[i + j]; - let (low, o) = low.overflowing_add(*existing_low); - *existing_low = low; - o - }; - - carry = { - let existing_hi = &mut ret[i + j + 1]; - let hi = hi + overflow as u64; - let (hi, o0) = hi.overflowing_add(carry); - let (hi, o1) = hi.overflowing_add(*existing_hi); - *existing_hi = hi; - - (o0 | o1) as u64 + use $crate::unroll; + unroll! { + for i in 0..$n_words { + let mut carry = 0u64; + let b = you[i]; + + unroll! { + for j in 0..$n_words { + if $check(me[j], carry) { + let a = me[j]; + + let (hi, low) = Self::split_u128(a as u128 * b as u128); + + let overflow = { + let existing_low = &mut ret[i + j]; + let (low, o) = low.overflowing_add(*existing_low); + *existing_low = low; + o + }; + + carry = { + let existing_hi = &mut ret[i + j + 1]; + let hi = hi + overflow as u64; + let (hi, o0) = hi.overflowing_add(carry); + let (hi, o1) = hi.overflowing_add(*existing_hi); + *existing_hi = hi; + + (o0 | o1) as u64 + } } } } } } - } - ret - }}); + ret + } + }}; } #[macro_export] #[doc(hidden)] macro_rules! uint_overflowing_mul { - ($name:ident, $n_words: tt, $self_expr: expr, $other: expr) => ({ - let ret: [u64; $n_words * 2] = $crate::uint_full_mul_reg!($name, $n_words, $self_expr, $other); + ($name:ident, $n_words: tt, $self_expr: expr, $other: expr) => {{ + let ret: [u64; $n_words * 2] = + $crate::uint_full_mul_reg!($name, $n_words, $self_expr, $other); // The safety of this is enforced by the compiler let ret: [[u64; $n_words]; 2] = unsafe { $crate::core_::mem::transmute(ret) }; @@ -185,36 +194,32 @@ macro_rules! uint_overflowing_mul { fn any_nonzero(arr: &[u64; $n_words]) -> bool { use $crate::unroll; unroll! { - for i in 0..$n_words { - if arr[i] != 0 { - return true; - } + for i in 0..$n_words { + if arr[i] != 0 { + return true; + } + } } - } false - } + } ($name(ret[0]), any_nonzero(&ret[1])) - }) + }}; } #[macro_export] #[doc(hidden)] macro_rules! overflowing { - ($op: expr, $overflow: expr) => ( - { - let (overflow_x, overflow_overflow) = $op; - $overflow |= overflow_overflow; - overflow_x - } - ); - ($op: expr) => ( - { - let (overflow_x, _overflow_overflow) = $op; - overflow_x - } - ); + ($op: expr, $overflow: expr) => {{ + let (overflow_x, overflow_overflow) = $op; + $overflow |= overflow_overflow; + overflow_x + }}; + ($op: expr) => {{ + let (overflow_x, _overflow_overflow) = $op; + overflow_x + }}; } #[macro_export] @@ -223,8 +228,8 @@ macro_rules! panic_on_overflow { ($name: expr) => { if $name { panic!("arithmetic operation overflow") - } - } + } + }; } #[macro_export] @@ -281,7 +286,7 @@ macro_rules! impl_mul_from { *self = result } } - } + }; } #[macro_export] @@ -334,7 +339,7 @@ macro_rules! impl_mul_for_primitive { *self = result } } - } + }; } #[macro_export] @@ -1561,19 +1566,20 @@ macro_rules! impl_std_for_uint { s.parse().unwrap() } } - } + }; } #[cfg(not(feature = "std"))] #[macro_export] #[doc(hidden)] macro_rules! impl_std_for_uint { - ($name: ident, $n_words: tt) => {} + ($name: ident, $n_words: tt) => {}; } #[cfg(feature = "quickcheck")] #[macro_export] #[doc(hidden)] +#[rustfmt::skip] macro_rules! impl_quickcheck_arbitrary_for_uint { ($uint: ty, $n_bytes: tt) => { impl $crate::qc::Arbitrary for $uint { @@ -1602,12 +1608,12 @@ macro_rules! impl_quickcheck_arbitrary_for_uint { res.as_ref().into() } } - } + }; } #[cfg(not(feature = "quickcheck"))] #[macro_export] #[doc(hidden)] macro_rules! impl_quickcheck_arbitrary_for_uint { - ($uint: ty, $n_bytes: tt) => {} + ($uint: ty, $n_bytes: tt) => {}; } diff --git a/uint/tests/uint_tests.rs b/uint/tests/uint_tests.rs index 0dedc0723..d36e4b27d 100644 --- a/uint/tests/uint_tests.rs +++ b/uint/tests/uint_tests.rs @@ -6,11 +6,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::u64::MAX; -use core::str::FromStr; use core::convert::TryInto; -use uint::{FromDecStrErr, construct_uint, overflowing}; +use core::str::FromStr; +use core::u64::MAX; use crunchy::unroll; +use uint::{construct_uint, overflowing, FromDecStrErr}; construct_uint! { pub struct U256(4); @@ -77,22 +77,26 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from(&[0x10u8, 0x10][..])); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from(&[0x12u8, 0xf0][..])); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from(&[0, 0x12u8, 0xf0][..])); - assert_eq!(U256([0x12f0, 0 , 0, 0]), U256::from(&[0, 0, 0, 0, 0, 0, 0, 0x12u8, 0xf0][..])); - assert_eq!(U256([0x12f0, 1 , 0, 0]), U256::from(&[1, 0, 0, 0, 0, 0, 0, 0x12u8, 0xf0][..])); - assert_eq!( - U256([0x12f0, 1 , 0x0910203040506077, 0x8090a0b0c0d0e0f0]), - U256::from(& - [ - 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, - 0x09, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x77, - 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0x12u8, 0xf0 + assert_eq!( + U256([0x12f0, 0, 0, 0]), + U256::from(&[0, 0, 0, 0, 0, 0, 0, 0x12u8, 0xf0][..]) + ); + assert_eq!( + U256([0x12f0, 1, 0, 0]), + U256::from(&[1, 0, 0, 0, 0, 0, 0, 0x12u8, 0xf0][..]) + ); + assert_eq!( + U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), + U256::from( + &[ + 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x09, 0x10, 0x20, 0x30, 0x40, 0x50, + 0x60, 0x77, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x12u8, 0xf0 ][..] ) ); assert_eq!( U256([0x00192437100019fa, 0x243710, 0, 0]), - U256::from(&[0x24u8, 0x37, 0x10,0, 0x19, 0x24, 0x37, 0x10, 0, 0x19, 0xfa][..]) + U256::from(&[0x24u8, 0x37, 0x10, 0, 0x19, 0x24, 0x37, 0x10, 0, 0x19, 0xfa][..]) ); // test initializtion from string @@ -101,10 +105,16 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!(U256([0x12f0, 0 , 0, 0]), U256::from_str("0000000012f0").unwrap()); - assert_eq!(U256([0x12f0, 1 , 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( - U256([0x12f0, 1 , 0x0910203040506077, 0x8090a0b0c0d0e0f0]), + U256([0x12f0, 0, 0, 0]), + U256::from_str("0000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0, 0]), + U256::from_str("0100000000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() ); let sa = U256::from_str("0a").unwrap(); @@ -112,10 +122,16 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!(U256([0x12f0, 0 , 0, 0]), U256::from_str("0000000012f0").unwrap()); - assert_eq!(U256([0x12f0, 1 , 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( - U256([0x12f0, 1 , 0x0910203040506077, 0x8090a0b0c0d0e0f0]), + U256([0x12f0, 0, 0, 0]), + U256::from_str("0000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0, 0]), + U256::from_str("0100000000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() ); let sa = U256::from_str("0a").unwrap(); @@ -123,10 +139,16 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!(U256([0x12f0, 0 , 0, 0]), U256::from_str("0000000012f0").unwrap()); - assert_eq!(U256([0x12f0, 1 , 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( - U256([0x12f0, 1 , 0x0910203040506077, 0x8090a0b0c0d0e0f0]), + U256([0x12f0, 0, 0, 0]), + U256::from_str("0000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0, 0]), + U256::from_str("0100000000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() ); let sa = U256::from_str("0a").unwrap(); @@ -134,10 +156,16 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!(U256([0x12f0, 0 , 0, 0]), U256::from_str("0000000012f0").unwrap()); - assert_eq!(U256([0x12f0, 1 , 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( - U256([0x12f0, 1 , 0x0910203040506077, 0x8090a0b0c0d0e0f0]), + U256([0x12f0, 0, 0, 0]), + U256::from_str("0000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0, 0]), + U256::from_str("0100000000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() ); let sa = U256::from_str("0a").unwrap(); @@ -145,10 +173,16 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!(U256([0x12f0, 0 , 0, 0]), U256::from_str("0000000012f0").unwrap()); - assert_eq!(U256([0x12f0, 1 , 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( - U256([0x12f0, 1 , 0x0910203040506077, 0x8090a0b0c0d0e0f0]), + U256([0x12f0, 0, 0, 0]), + U256::from_str("0000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0, 0]), + U256::from_str("0100000000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() ); let sa = U256::from_str("0a").unwrap(); @@ -156,10 +190,16 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!(U256([0x12f0, 0 , 0, 0]), U256::from_str("0000000012f0").unwrap()); - assert_eq!(U256([0x12f0, 1 , 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( - U256([0x12f0, 1 , 0x0910203040506077, 0x8090a0b0c0d0e0f0]), + U256([0x12f0, 0, 0, 0]), + U256::from_str("0000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0, 0]), + U256::from_str("0100000000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() ); let sa = U256::from_str("0a").unwrap(); @@ -167,10 +207,16 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!(U256([0x12f0, 0 , 0, 0]), U256::from_str("0000000012f0").unwrap()); - assert_eq!(U256([0x12f0, 1 , 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( - U256([0x12f0, 1 , 0x0910203040506077, 0x8090a0b0c0d0e0f0]), + U256([0x12f0, 0, 0, 0]), + U256::from_str("0000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0, 0]), + U256::from_str("0100000000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() ); let sa = U256::from_str("0a").unwrap(); @@ -178,10 +224,16 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!(U256([0x12f0, 0 , 0, 0]), U256::from_str("0000000012f0").unwrap()); - assert_eq!(U256([0x12f0, 1 , 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( - U256([0x12f0, 1 , 0x0910203040506077, 0x8090a0b0c0d0e0f0]), + U256([0x12f0, 0, 0, 0]), + U256::from_str("0000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0, 0]), + U256::from_str("0100000000000012f0").unwrap() + ); + assert_eq!( + U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() ); } @@ -190,8 +242,11 @@ fn uint256_from() { fn uint256_try_into_primitives() { macro_rules! try_into_uint_primitive_ok { ($primitive: ty) => { - assert_eq!(U256::from(10).try_into() as Result<$primitive, _>, Ok(<$primitive>::from(10u8))); - } + assert_eq!( + U256::from(10).try_into() as Result<$primitive, _>, + Ok(<$primitive>::from(10u8)) + ); + }; } try_into_uint_primitive_ok!(u8); try_into_uint_primitive_ok!(u16); @@ -202,8 +257,11 @@ fn uint256_try_into_primitives() { macro_rules! try_into_iint_primitive_ok { ($primitive: ty) => { - assert_eq!(U256::from(10).try_into() as Result<$primitive, _>, Ok(<$primitive>::from(10i8))); - } + assert_eq!( + U256::from(10).try_into() as Result<$primitive, _>, + Ok(<$primitive>::from(10i8)) + ); + }; } try_into_iint_primitive_ok!(i8); try_into_iint_primitive_ok!(i16); @@ -216,23 +274,32 @@ fn uint256_try_into_primitives() { ($small: ty, $big: ty) => { assert_eq!( U256::from(<$small>::max_value() as $big + 1).try_into() as Result<$small, _>, - Err(concat!("integer overflow when casting to ", stringify!($small))) + Err(concat!( + "integer overflow when casting to ", + stringify!($small) + )) ); - } + }; } try_into_primitive_err!(u8, u16); try_into_primitive_err!(u16, u32); try_into_primitive_err!(u32, u64); try_into_primitive_err!(usize, u128); try_into_primitive_err!(u64, u128); - assert_eq!(U256([0, 0, 1, 0]).try_into() as Result, Err("integer overflow when casting to u128")); + assert_eq!( + U256([0, 0, 1, 0]).try_into() as Result, + Err("integer overflow when casting to u128") + ); try_into_primitive_err!(i8, i16); try_into_primitive_err!(i16, i32); try_into_primitive_err!(i32, i64); try_into_primitive_err!(isize, i128); try_into_primitive_err!(i64, i128); try_into_primitive_err!(i128, u128); - assert_eq!(U256([0, 0, 1, 0]).try_into() as Result, Err("integer overflow when casting to i128")); + assert_eq!( + U256([0, 0, 1, 0]).try_into() as Result, + Err("integer overflow when casting to i128") + ); } #[test] @@ -279,11 +346,14 @@ fn uint256_bits_test() { assert_eq!(U256::from(0x01ffu64).byte(1), 0x1); assert_eq!(U256([0u64, 0xfc, 0, 0]).byte(8), 0xfc); assert_eq!(U256([0u64, 0, 0, u64::max_value()]).byte(31), 0xff); - assert_eq!(U256([0u64, 0, 0, (u64::max_value() >> 8) + 1]).byte(31), 0x01); + assert_eq!( + U256([0u64, 0, 0, (u64::max_value() >> 8) + 1]).byte(31), + 0x01 + ); } #[test] -#[cfg_attr(feature="dev", allow(eq_op))] +#[cfg_attr(feature = "dev", allow(eq_op))] fn uint256_comp_test() { let small = U256([10u64, 0, 0, 0]); let big = U256([0x8C8C3EE70C644118u64, 0x0209E7378231E632, 0, 0]); @@ -314,20 +384,28 @@ fn uint256_arithmetic_test() { assert_eq!(shr, U256([0x7DDE000000000000u64, 0x0001BD5B7DDFBD5B, 0, 0])); // Increment let incr = shr + U256::from(1u64); - assert_eq!(incr, U256([0x7DDE000000000001u64, 0x0001BD5B7DDFBD5B, 0, 0])); + assert_eq!( + incr, + U256([0x7DDE000000000001u64, 0x0001BD5B7DDFBD5B, 0, 0]) + ); // Subtraction let sub = overflowing!(incr.overflowing_sub(init)); assert_eq!(sub, U256([0x9F30411021524112u64, 0x0001BD5B7DDFBD5A, 0, 0])); // Multiplication let mult = sub * 300u32; - assert_eq!(mult, U256([0x8C8C3EE70C644118u64, 0x0209E7378231E632, 0, 0])); + assert_eq!( + mult, + U256([0x8C8C3EE70C644118u64, 0x0209E7378231E632, 0, 0]) + ); // Division assert_eq!(U256::from(105u8) / U256::from(5u8), U256::from(21u8)); let div = mult / U256::from(300u16); assert_eq!(div, U256([0x9F30411021524112u64, 0x0001BD5B7DDFBD5A, 0, 0])); - let a = U256::from_str("ff000000000000000000000000000000000000000000000000000000000000d1").unwrap(); - let b = U256::from_str("00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2e").unwrap(); + let a = + U256::from_str("ff000000000000000000000000000000000000000000000000000000000000d1").unwrap(); + let b = + U256::from_str("00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2e").unwrap(); println!("{:x}", a); println!("{:x}", b); assert_eq!(!a, b); @@ -355,10 +433,19 @@ fn uint256_extreme_bitshift_test() { assert_eq!(init << 64, U256([0, 0xDEADBEEFDEADBEEF, 0, 0])); let add = (init << 64) + init; assert_eq!(add, U256([0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF, 0, 0])); - assert_eq!(add >> 0, U256([0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF, 0, 0])); - assert_eq!(add << 0, U256([0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF, 0, 0])); + assert_eq!( + add >> 0, + U256([0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF, 0, 0]) + ); + assert_eq!( + add << 0, + U256([0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF, 0, 0]) + ); assert_eq!(add >> 64, U256([0xDEADBEEFDEADBEEF, 0, 0, 0])); - assert_eq!(add << 64, U256([0, 0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF, 0])); + assert_eq!( + add << 64, + U256([0, 0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF, 0]) + ); } #[test] @@ -435,7 +522,11 @@ pub fn display_u512() { fn uint256_overflowing_pow() { assert_eq!( U256::from(2).overflowing_pow(U256::from(0xff)), - (U256::from_str("8000000000000000000000000000000000000000000000000000000000000000").unwrap(), false) + ( + U256::from_str("8000000000000000000000000000000000000000000000000000000000000000") + .unwrap(), + false + ) ); assert_eq!( U256::from(2).overflowing_pow(U256::from(0x100)), @@ -453,15 +544,19 @@ fn uint256_mul2() { let a = U512::from_str("10000000000000000fffffffffffffffe").unwrap(); let b = U512::from_str("ffffffffffffffffffffffffffffffff").unwrap(); - assert_eq!(a * b, U512::from_str("10000000000000000fffffffffffffffcffffffffffffffff0000000000000002").unwrap()); + assert_eq!( + a * b, + U512::from_str("10000000000000000fffffffffffffffcffffffffffffffff0000000000000002") + .unwrap() + ); } #[test] fn uint256_overflowing_mul() { assert_eq!( - U256::from_str("100000000000000000000000000000000").unwrap().overflowing_mul( - U256::from_str("100000000000000000000000000000000").unwrap() - ), + U256::from_str("100000000000000000000000000000000") + .unwrap() + .overflowing_mul(U256::from_str("100000000000000000000000000000000").unwrap()), (U256::zero(), true) ); } @@ -479,10 +574,12 @@ fn uint512_mul() { #[test] fn uint256_mul_overflow() { assert_eq!( - U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() - .overflowing_mul( - U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() - ), + U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + .unwrap() + .overflowing_mul( + U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + .unwrap() + ), (U256::from_str("1").unwrap(), true) ); } @@ -492,35 +589,36 @@ fn uint256_mul_overflow() { #[allow(unused_must_use)] fn uint256_mul_overflow_panic() { U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() - * - U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap(); + * U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + .unwrap(); } #[test] fn uint256_sub_overflow() { assert_eq!( - U256::from_str("0").unwrap() - .overflowing_sub( - U256::from_str("1").unwrap() - ), - (U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap(), true) - ); + U256::from_str("0") + .unwrap() + .overflowing_sub(U256::from_str("1").unwrap()), + ( + U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + .unwrap(), + true + ) + ); } #[test] #[should_panic] #[allow(unused_must_use)] fn uint256_sub_overflow_panic() { - U256::from_str("0").unwrap() - - - U256::from_str("1").unwrap(); + U256::from_str("0").unwrap() - U256::from_str("1").unwrap(); } #[test] fn uint256_shl() { assert_eq!( U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() - << 4, + << 4, U256::from_str("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0").unwrap() ); } @@ -529,12 +627,12 @@ fn uint256_shl() { fn uint256_shl_words() { assert_eq!( U256::from_str("0000000000000001ffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() - << 64, + << 64, U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000").unwrap() ); assert_eq!( U256::from_str("0000000000000000ffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() - << 64, + << 64, U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000").unwrap() ); } @@ -543,17 +641,16 @@ fn uint256_shl_words() { fn uint256_mul() { assert_eq!( U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() - * - U256::from_str("2").unwrap(), + * U256::from_str("2").unwrap(), U256::from_str("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe").unwrap() - ); + ); } #[test] fn uint256_div() { - assert_eq!(U256::from(10u64) / U256::from(1u64), U256::from(10u64)); - assert_eq!(U256::from(10u64) / U256::from(2u64), U256::from(5u64)); - assert_eq!(U256::from(10u64) / U256::from(3u64), U256::from(3u64)); + assert_eq!(U256::from(10u64) / U256::from(1u64), U256::from(10u64)); + assert_eq!(U256::from(10u64) / U256::from(2u64), U256::from(5u64)); + assert_eq!(U256::from(10u64) / U256::from(3u64), U256::from(3u64)); } #[test] @@ -566,8 +663,16 @@ fn uint256_rem() { fn uint256_from_dec_str() { assert_eq!(U256::from_dec_str("10").unwrap(), U256::from(10u64)); assert_eq!(U256::from_dec_str("1024").unwrap(), U256::from(1024u64)); - assert_eq!(U256::from_dec_str("115792089237316195423570985008687907853269984665640564039457584007913129639936"), Err(FromDecStrErr::InvalidLength)); - assert_eq!(U256::from_dec_str("0x11"), Err(FromDecStrErr::InvalidCharacter)); + assert_eq!( + U256::from_dec_str( + "115792089237316195423570985008687907853269984665640564039457584007913129639936" + ), + Err(FromDecStrErr::InvalidLength) + ); + assert_eq!( + U256::from_dec_str("0x11"), + Err(FromDecStrErr::InvalidCharacter) + ); } #[test] @@ -583,34 +688,40 @@ fn display_uint_zero() { #[test] fn u512_multi_adds() { - let (result, _) = U512([0, 0, 0, 0, 0, 0, 0, 0]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, 0])); + let (result, _) = + U512([0, 0, 0, 0, 0, 0, 0, 0]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, 0])); assert_eq!(result, U512([0, 0, 0, 0, 0, 0, 0, 0])); - let (result, _) = U512([1, 0, 0, 0, 0, 0, 0, 1]).overflowing_add(U512([1, 0, 0, 0, 0, 0, 0, 1])); + let (result, _) = + U512([1, 0, 0, 0, 0, 0, 0, 1]).overflowing_add(U512([1, 0, 0, 0, 0, 0, 0, 1])); assert_eq!(result, U512([2, 0, 0, 0, 0, 0, 0, 2])); - let (result, _) = U512([0, 0, 0, 0, 0, 0, 0, 1]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, 1])); + let (result, _) = + U512([0, 0, 0, 0, 0, 0, 0, 1]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, 1])); assert_eq!(result, U512([0, 0, 0, 0, 0, 0, 0, 2])); - let (result, _) = U512([0, 0, 0, 0, 0, 0, 2, 1]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 3, 1])); + let (result, _) = + U512([0, 0, 0, 0, 0, 0, 2, 1]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 3, 1])); assert_eq!(result, U512([0, 0, 0, 0, 0, 0, 5, 2])); - let (result, _) = U512([1, 2, 3, 4, 5, 6, 7, 8]).overflowing_add(U512([9, 10, 11, 12, 13, 14, 15, 16])); + let (result, _) = + U512([1, 2, 3, 4, 5, 6, 7, 8]).overflowing_add(U512([9, 10, 11, 12, 13, 14, 15, 16])); assert_eq!(result, U512([10, 12, 14, 16, 18, 20, 22, 24])); - let (_, overflow) = U512([0, 0, 0, 0, 0, 0, 2, 1]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 3, 1])); + let (_, overflow) = + U512([0, 0, 0, 0, 0, 0, 2, 1]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 3, 1])); assert!(!overflow); let (_, overflow) = U512([MAX, MAX, MAX, MAX, MAX, MAX, MAX, MAX]) .overflowing_add(U512([MAX, MAX, MAX, MAX, MAX, MAX, MAX, MAX])); assert!(overflow); - let (_, overflow) = U512([0, 0, 0, 0, 0, 0, 0, MAX]) - .overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, MAX])); + let (_, overflow) = + U512([0, 0, 0, 0, 0, 0, 0, MAX]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, MAX])); assert!(overflow); - let (_, overflow) = U512([0, 0, 0, 0, 0, 0, 0, MAX]) - .overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, 0])); + let (_, overflow) = + U512([0, 0, 0, 0, 0, 0, 0, MAX]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, 0])); assert!(!overflow); } @@ -626,8 +737,7 @@ fn u256_multi_adds() { assert_eq!(result, U256([0, 0, 5, 2])); assert!(!overflow); - let (_, overflow) = U256([MAX, MAX, MAX, MAX]) - .overflowing_add(U256([MAX, MAX, MAX, MAX])); + let (_, overflow) = U256([MAX, MAX, MAX, MAX]).overflowing_add(U256([MAX, MAX, MAX, MAX])); assert!(overflow); let (_, overflow) = U256([0, 0, 0, MAX]).overflowing_add(U256([0, 0, 0, MAX])); @@ -646,11 +756,13 @@ fn u256_multi_subs() { assert!(overflow); let (result, overflow) = - U256([MAX, MAX, MAX, MAX]) - .overflowing_sub(U256([MAX/2, MAX/2, MAX/2, MAX/2])); + U256([MAX, MAX, MAX, MAX]).overflowing_sub(U256([MAX / 2, MAX / 2, MAX / 2, MAX / 2])); assert!(!overflow); - assert_eq!(U256([MAX/2+1, MAX/2+1, MAX/2+1, MAX/2+1]), result); + assert_eq!( + U256([MAX / 2 + 1, MAX / 2 + 1, MAX / 2 + 1, MAX / 2 + 1]), + result + ); let (result, overflow) = U256([0, 0, 0, 1]).overflowing_sub(U256([0, 0, 1, 0])); assert!(!overflow); @@ -663,77 +775,71 @@ fn u256_multi_subs() { #[test] fn u512_multi_subs() { - let (result, _) = U512([0, 0, 0, 0, 0, 0, 0, 0]).overflowing_sub(U512([0, 0, 0, 0, 0, 0, 0, 0])); + let (result, _) = + U512([0, 0, 0, 0, 0, 0, 0, 0]).overflowing_sub(U512([0, 0, 0, 0, 0, 0, 0, 0])); assert_eq!(result, U512([0, 0, 0, 0, 0, 0, 0, 0])); - let (result, _) = U512([10, 9, 8, 7, 6, 5, 4, 3]).overflowing_sub(U512([9, 8, 7, 6, 5, 4, 3, 2])); + let (result, _) = + U512([10, 9, 8, 7, 6, 5, 4, 3]).overflowing_sub(U512([9, 8, 7, 6, 5, 4, 3, 2])); assert_eq!(result, U512([1, 1, 1, 1, 1, 1, 1, 1])); - let (_, overflow) = U512([10, 9, 8, 7, 6, 5, 4, 3]).overflowing_sub(U512([9, 8, 7, 6, 5, 4, 3, 2])); + let (_, overflow) = + U512([10, 9, 8, 7, 6, 5, 4, 3]).overflowing_sub(U512([9, 8, 7, 6, 5, 4, 3, 2])); assert!(!overflow); - let (_, overflow) = U512([9, 8, 7, 6, 5, 4, 3, 2]).overflowing_sub(U512([10, 9, 8, 7, 6, 5, 4, 3])); + let (_, overflow) = + U512([9, 8, 7, 6, 5, 4, 3, 2]).overflowing_sub(U512([10, 9, 8, 7, 6, 5, 4, 3])); assert!(overflow); } #[test] fn u256_multi_carry_all() { let (result, _) = U256([MAX, 0, 0, 0]).overflowing_mul(U256([MAX, 0, 0, 0])); - assert_eq!(U256([1, MAX-1, 0, 0]), result); + assert_eq!(U256([1, MAX - 1, 0, 0]), result); let (result, _) = U256([0, MAX, 0, 0]).overflowing_mul(U256([MAX, 0, 0, 0])); - assert_eq!(U256([0, 1, MAX-1, 0]), result); + assert_eq!(U256([0, 1, MAX - 1, 0]), result); let (result, _) = U256([MAX, MAX, 0, 0]).overflowing_mul(U256([MAX, 0, 0, 0])); - assert_eq!(U256([1, MAX, MAX-1, 0]), result); + assert_eq!(U256([1, MAX, MAX - 1, 0]), result); let (result, _) = U256([MAX, 0, 0, 0]).overflowing_mul(U256([MAX, MAX, 0, 0])); - assert_eq!(U256([1, MAX, MAX-1, 0]), result); + assert_eq!(U256([1, MAX, MAX - 1, 0]), result); - let (result, _) = U256([MAX, MAX, 0, 0]) - .overflowing_mul(U256([MAX, MAX, 0, 0])); - assert_eq!(U256([1, 0, MAX-1, MAX]), result); + let (result, _) = U256([MAX, MAX, 0, 0]).overflowing_mul(U256([MAX, MAX, 0, 0])); + assert_eq!(U256([1, 0, MAX - 1, MAX]), result); let (result, _) = U256([MAX, 0, 0, 0]).overflowing_mul(U256([MAX, MAX, MAX, 0])); - assert_eq!(U256([1, MAX, MAX, MAX-1]), result); + assert_eq!(U256([1, MAX, MAX, MAX - 1]), result); let (result, _) = U256([MAX, MAX, MAX, 0]).overflowing_mul(U256([MAX, 0, 0, 0])); - assert_eq!(U256([1, MAX, MAX, MAX-1]), result); + assert_eq!(U256([1, MAX, MAX, MAX - 1]), result); - let (result, _) = U256([MAX, 0, 0, 0]).overflowing_mul( - U256([MAX, MAX, MAX, MAX])); + let (result, _) = U256([MAX, 0, 0, 0]).overflowing_mul(U256([MAX, MAX, MAX, MAX])); assert_eq!(U256([1, MAX, MAX, MAX]), result); - let (result, _) = U256([MAX, MAX, MAX, MAX]) - .overflowing_mul(U256([MAX, 0, 0, 0])); + let (result, _) = U256([MAX, MAX, MAX, MAX]).overflowing_mul(U256([MAX, 0, 0, 0])); assert_eq!(U256([1, MAX, MAX, MAX]), result); - let (result, _) = U256([MAX, MAX, MAX, 0]) - .overflowing_mul(U256([MAX, MAX, 0, 0])); - assert_eq!(U256([1, 0, MAX, MAX-1]), result); + let (result, _) = U256([MAX, MAX, MAX, 0]).overflowing_mul(U256([MAX, MAX, 0, 0])); + assert_eq!(U256([1, 0, MAX, MAX - 1]), result); - let (result, _) = U256([MAX, MAX, 0, 0]) - .overflowing_mul(U256([MAX, MAX, MAX, 0])); - assert_eq!(U256([1, 0, MAX, MAX-1]), result); + let (result, _) = U256([MAX, MAX, 0, 0]).overflowing_mul(U256([MAX, MAX, MAX, 0])); + assert_eq!(U256([1, 0, MAX, MAX - 1]), result); - let (result, _) = U256([MAX, MAX, MAX, MAX]) - .overflowing_mul(U256([MAX, MAX, 0, 0])); + let (result, _) = U256([MAX, MAX, MAX, MAX]).overflowing_mul(U256([MAX, MAX, 0, 0])); assert_eq!(U256([1, 0, MAX, MAX]), result); - let (result, _) = U256([MAX, MAX, 0, 0]) - .overflowing_mul(U256([MAX, MAX, MAX, MAX])); + let (result, _) = U256([MAX, MAX, 0, 0]).overflowing_mul(U256([MAX, MAX, MAX, MAX])); assert_eq!(U256([1, 0, MAX, MAX]), result); - let (result, _) = U256([MAX, MAX, MAX, 0]) - .overflowing_mul(U256([MAX, MAX, MAX, 0])); - assert_eq!(U256([1, 0, 0, MAX-1]), result); + let (result, _) = U256([MAX, MAX, MAX, 0]).overflowing_mul(U256([MAX, MAX, MAX, 0])); + assert_eq!(U256([1, 0, 0, MAX - 1]), result); - let (result, _) = U256([MAX, MAX, MAX, 0]) - .overflowing_mul(U256([MAX, MAX, MAX, MAX])); + let (result, _) = U256([MAX, MAX, MAX, 0]).overflowing_mul(U256([MAX, MAX, MAX, MAX])); assert_eq!(U256([1, 0, 0, MAX]), result); - let (result, _) = U256([MAX, MAX, MAX, MAX]) - .overflowing_mul(U256([MAX, MAX, MAX, 0])); + let (result, _) = U256([MAX, MAX, MAX, MAX]).overflowing_mul(U256([MAX, MAX, MAX, 0])); assert_eq!(U256([1, 0, 0, MAX]), result); let (result, _) = U256([0, 0, 0, MAX]).overflowing_mul(U256([0, 0, 0, MAX])); @@ -742,8 +848,7 @@ fn u256_multi_carry_all() { let (result, _) = U256([1, 0, 0, 0]).overflowing_mul(U256([0, 0, 0, MAX])); assert_eq!(U256([0, 0, 0, MAX]), result); - let (result, _) = U256([MAX, MAX, MAX, MAX]) - .overflowing_mul(U256([MAX, MAX, MAX, MAX])); + let (result, _) = U256([MAX, MAX, MAX, MAX]).overflowing_mul(U256([MAX, MAX, MAX, MAX])); assert_eq!(U256([1, 0, 0, 0]), result); } @@ -812,7 +917,16 @@ fn u256_multi_muls_overflow() { #[test] fn u512_div() { - let fuzz_data = [0x38,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff,0xff,0x7,0x0,0x0,0x0,0x0,0xc1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xfe,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0]; + let fuzz_data = [ + 0x38, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0x7, 0x0, + 0x0, 0x0, 0x0, 0xc1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0xfe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, + ]; let a = U512::from_little_endian(&fuzz_data[..64]); let b = U512::from_little_endian(&fuzz_data[64..]); let (x, y) = (a / b, a % b); @@ -829,39 +943,52 @@ fn big_endian() { source.to_big_endian(&mut target); assert_eq!( - vec![0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, - 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8], - target); + vec![ + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8 + ], + target + ); let source = U256([512, 0, 0, 0]); let mut target = vec![0u8; 32]; source.to_big_endian(&mut target); assert_eq!( - vec![0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, - 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8], - target); + vec![ + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8 + ], + target + ); let source = U256([0, 512, 0, 0]); let mut target = vec![0u8; 32]; source.to_big_endian(&mut target); assert_eq!( - vec![0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, - 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8], - target); + vec![ + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8 + ], + target + ); - let source = U256::from_str("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20").unwrap(); + let source = + U256::from_str("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20").unwrap(); source.to_big_endian(&mut target); assert_eq!( - vec![0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, - 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20], - target); + vec![ + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, + 0x1d, 0x1e, 0x1f, 0x20 + ], + target + ); } #[test] fn u256_multi_muls2() { - let (result, _) = U256([0, 0, 0, 0]).overflowing_mul(U256([0, 0, 0, 0])); assert_eq!(U256([0, 0, 0, 0]), result); @@ -893,46 +1020,51 @@ fn u256_multi_muls2() { assert_eq!(U256([0, 0, 0, u64::max_value()]), result); let x1: U256 = "0000000000000000000000000000000000000000000000000000012365124623".into(); - let x2sqr_right: U256 = "000000000000000000000000000000000000000000014baeef72e0378e2328c9".into(); + let x2sqr_right: U256 = + "000000000000000000000000000000000000000000014baeef72e0378e2328c9".into(); let x1sqr = x1 * x1; assert_eq!(x2sqr_right, x1sqr); let x1cube = x1sqr * x1; - let x1cube_right: U256 = "0000000000000000000000000000000001798acde139361466f712813717897b".into(); + let x1cube_right: U256 = + "0000000000000000000000000000000001798acde139361466f712813717897b".into(); assert_eq!(x1cube_right, x1cube); let x1quad = x1cube * x1; - let x1quad_right: U256 = "000000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1".into(); + let x1quad_right: U256 = + "000000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1".into(); assert_eq!(x1quad_right, x1quad); let x1penta = x1quad * x1; - let x1penta_right: U256 = "00000000000001e92875ac24be246e1c57e0507e8c46cc8d233b77f6f4c72993".into(); + let x1penta_right: U256 = + "00000000000001e92875ac24be246e1c57e0507e8c46cc8d233b77f6f4c72993".into(); assert_eq!(x1penta_right, x1penta); let x1septima = x1penta * x1; - let x1septima_right: U256 = "00022cca1da3f6e5722b7d3cc5bbfb486465ebc5a708dd293042f932d7eee119".into(); + let x1septima_right: U256 = + "00022cca1da3f6e5722b7d3cc5bbfb486465ebc5a708dd293042f932d7eee119".into(); assert_eq!(x1septima_right, x1septima); } #[test] fn example() { let mut val: U256 = 1023.into(); - for _ in 0..200 { val = val * U256::from(2) } - assert_eq!(&format!("{}", val), "1643897619276947051879427220465009342380213662639797070513307648"); + for _ in 0..200 { + val = val * U256::from(2) + } + assert_eq!( + &format!("{}", val), + "1643897619276947051879427220465009342380213662639797070513307648" + ); } #[test] fn little_endian() { let number: U256 = "00022cca1da3f6e5722b7d3cc5bbfb486465ebc5a708dd293042f932d7eee119".into(); let expected = [ - 0x19, 0xe1, 0xee, 0xd7, - 0x32, 0xf9, 0x42, 0x30, - 0x29, 0xdd, 0x08, 0xa7, - 0xc5, 0xeb, 0x65, 0x64, - 0x48, 0xfb, 0xbb, 0xc5, - 0x3c, 0x7d, 0x2b, 0x72, - 0xe5, 0xf6, 0xa3, 0x1d, - 0xca, 0x2c, 0x02, 0x00 + 0x19, 0xe1, 0xee, 0xd7, 0x32, 0xf9, 0x42, 0x30, 0x29, 0xdd, 0x08, 0xa7, 0xc5, 0xeb, 0x65, + 0x64, 0x48, 0xfb, 0xbb, 0xc5, 0x3c, 0x7d, 0x2b, 0x72, 0xe5, 0xf6, 0xa3, 0x1d, 0xca, 0x2c, + 0x02, 0x00, ]; let mut result = [0u8; 32]; number.to_little_endian(&mut result); @@ -942,10 +1074,8 @@ fn little_endian() { #[test] fn slice_roundtrip() { let raw = [ - 1u8, 2, 3, 5, 7, 11, 13, 17, - 19, 23, 29, 31, 37, 41, 43, 47, - 53, 59, 61, 67, 71, 73, 79, 83, - 89, 97, 101, 103, 107, 109, 113, 127 + 1u8, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, + 83, 89, 97, 101, 103, 107, 109, 113, 127, ]; let u256: U256 = (&raw[..]).into(); @@ -960,10 +1090,8 @@ fn slice_roundtrip() { #[test] fn slice_roundtrip_le() { let raw = [ - 1u8, 2, 3, 5, 7, 11, 13, 17, - 19, 23, 29, 31, 37, 41, 43, 47, - 53, 59, 61, 67, 71, 73, 79, 83, - 89, 97, 101, 103, 107, 109, 113, 127 + 1u8, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, + 83, 89, 97, 101, 103, 107, 109, 113, 127, ]; let u256 = U256::from_little_endian(&raw[..]); @@ -978,10 +1106,8 @@ fn slice_roundtrip_le() { #[test] fn slice_roundtrip_le2() { let raw = [ - 2, 3, 5, 7, 11, 13, 17, - 19, 23, 29, 31, 37, 41, 43, 47, - 53, 59, 61, 67, 71, 73, 79, 83, - 89, 97, 101, 103, 107, 109, 113, 127 + 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, + 97, 101, 103, 107, 109, 113, 127, ]; let u256 = U256::from_little_endian(&raw[..]); @@ -996,10 +1122,8 @@ fn slice_roundtrip_le2() { #[test] fn from_little_endian() { let source: [u8; 32] = [ - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, ]; let number = U256::from_little_endian(&source[..]); @@ -1010,10 +1134,8 @@ fn from_little_endian() { #[test] fn from_big_endian() { let source: [u8; 32] = [ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, ]; let number = U256::from_big_endian(&source[..]); @@ -1024,79 +1146,108 @@ fn from_big_endian() { #[test] fn into_fixed_array() { let expected: [u8; 32] = [ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, ]; - let ary : [u8; 32] = U256::from(1).into(); + let ary: [u8; 32] = U256::from(1).into(); assert_eq!(ary, expected); } #[test] fn test_u256_from_fixed_array() { let ary = [ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 123, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, + 0, 123, ]; - let num : U256 = ary.into(); - assert_eq!( num, U256::from(std::u64::MAX) + 1 + 123); + let num: U256 = ary.into(); + assert_eq!(num, U256::from(std::u64::MAX) + 1 + 123); - let a_ref : &U256 = &ary.into(); - assert_eq!( a_ref, &(U256::from(std::u64::MAX) + 1 + 123)); + let a_ref: &U256 = &ary.into(); + assert_eq!(a_ref, &(U256::from(std::u64::MAX) + 1 + 123)); } #[test] fn test_from_ref_to_fixed_array() { - let ary : &[u8; 32] = &[ - 1,0,1,2,1,0,1,2, - 3,0,3,4,3,0,3,4, - 5,0,5,6,5,0,5,6, - 7,0,7,8,7,0,7,8 + let ary: &[u8; 32] = &[ + 1, 0, 1, 2, 1, 0, 1, 2, 3, 0, 3, 4, 3, 0, 3, 4, 5, 0, 5, 6, 5, 0, 5, 6, 7, 0, 7, 8, 7, 0, + 7, 8, ]; - let big : U256 = ary.into(); + let big: U256 = ary.into(); // the numbers are each row of 8 bytes reversed and cast to u64 - assert_eq!(big, U256([504410889324070664, 360293493601469702, 216176097878868740, 72058702156267778u64])); + assert_eq!( + big, + U256([ + 504410889324070664, + 360293493601469702, + 216176097878868740, + 72058702156267778u64 + ]) + ); } #[test] fn test_u512_from_fixed_array() { let ary = [ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 123 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 123, ]; - let num : U512 = ary.into(); - assert_eq!( num, U512::from(123) ); + let num: U512 = ary.into(); + assert_eq!(num, U512::from(123)); - let a_ref : &U512 = &ary.into(); - assert_eq!( a_ref, &U512::from(123) ); + let a_ref: &U512 = &ary.into(); + assert_eq!(a_ref, &U512::from(123)); } #[test] fn leading_zeros() { - assert_eq!(U256::from("000000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1").leading_zeros(), 95); - assert_eq!(U256::from("f00000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1").leading_zeros(), 0); - assert_eq!(U256::from("0000000000000000000000000000000000000000000000000000000000000001").leading_zeros(), 255); - assert_eq!(U256::from("0000000000000000000000000000000000000000000000000000000000000000").leading_zeros(), 256); + assert_eq!( + U256::from("000000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1") + .leading_zeros(), + 95 + ); + assert_eq!( + U256::from("f00000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1") + .leading_zeros(), + 0 + ); + assert_eq!( + U256::from("0000000000000000000000000000000000000000000000000000000000000001") + .leading_zeros(), + 255 + ); + assert_eq!( + U256::from("0000000000000000000000000000000000000000000000000000000000000000") + .leading_zeros(), + 256 + ); } #[test] fn trailing_zeros() { - assert_eq!(U256::from("1adbdd6bd6ff027485484b97f8a6a4c7129756dd100000000000000000000000").trailing_zeros(), 92); - assert_eq!(U256::from("1adbdd6bd6ff027485484b97f8a6a4c7129756dd10000000000000000000000f").trailing_zeros(), 0); - assert_eq!(U256::from("8000000000000000000000000000000000000000000000000000000000000000").trailing_zeros(), 255); - assert_eq!(U256::from("0000000000000000000000000000000000000000000000000000000000000000").trailing_zeros(), 256); + assert_eq!( + U256::from("1adbdd6bd6ff027485484b97f8a6a4c7129756dd100000000000000000000000") + .trailing_zeros(), + 92 + ); + assert_eq!( + U256::from("1adbdd6bd6ff027485484b97f8a6a4c7129756dd10000000000000000000000f") + .trailing_zeros(), + 0 + ); + assert_eq!( + U256::from("8000000000000000000000000000000000000000000000000000000000000000") + .trailing_zeros(), + 255 + ); + assert_eq!( + U256::from("0000000000000000000000000000000000000000000000000000000000000000") + .trailing_zeros(), + 256 + ); } -#[cfg(feature="quickcheck")] +#[cfg(feature = "quickcheck")] pub mod laws { use super::construct_uint; macro_rules! uint_laws { From eae6a3b8601650ed884d9709de9149b95a84fd5c Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Mon, 28 Oct 2019 11:56:02 +0100 Subject: [PATCH 06/15] unscrew uint macros fmt --- uint/src/uint.rs | 62 ++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/uint/src/uint.rs b/uint/src/uint.rs index 2cfdf7caf..034636e73 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -29,6 +29,8 @@ //! implementations for even more speed, hidden behind the `x64_arithmetic` //! feature flag. +#![rustfmt::skip] + /// Conversion from decimal string error #[derive(Debug, PartialEq)] pub enum FromDecStrErr { @@ -86,36 +88,36 @@ macro_rules! uint_overflowing_binop { let mut carry = 0u64; $crate::static_assertions::const_assert!( core::isize::MAX as usize / core::mem::size_of::() > $n_words - ); + ); // `unroll!` is recursive, but doesn’t use `$crate::unroll`, so we need to ensure that it // is in scope unqualified. use $crate::unroll; unroll! { - for i in 0..$n_words { - use core::ptr; + for i in 0..$n_words { + use core::ptr; - if carry != 0 { - let (res1, overflow1) = ($fn)(me[i], you[i]); - let (res2, overflow2) = ($fn)(res1, carry); + if carry != 0 { + let (res1, overflow1) = ($fn)(me[i], you[i]); + let (res2, overflow2) = ($fn)(res1, carry); - unsafe { - // SAFETY: `i` is within bounds and `i * size_of::() < isize::MAX` - *ret_ptr.offset(i as _) = res2 - } - carry = (overflow1 as u8 + overflow2 as u8) as u64; - } else { - let (res, overflow) = ($fn)(me[i], you[i]); + unsafe { + // SAFETY: `i` is within bounds and `i * size_of::() < isize::MAX` + *ret_ptr.offset(i as _) = res2 + } + carry = (overflow1 as u8 + overflow2 as u8) as u64; + } else { + let (res, overflow) = ($fn)(me[i], you[i]); - unsafe { - // SAFETY: `i` is within bounds and `i * size_of::() < isize::MAX` - *ret_ptr.offset(i as _) = res - } + unsafe { + // SAFETY: `i` is within bounds and `i * size_of::() < isize::MAX` + *ret_ptr.offset(i as _) = res + } - carry = overflow as u64; - } - } + carry = overflow as u64; } + } + } ($name(ret), carry > 0) }}; @@ -123,7 +125,6 @@ macro_rules! uint_overflowing_binop { #[macro_export] #[doc(hidden)] -#[rustfmt::skip] macro_rules! uint_full_mul_reg { ($name:ident, 8, $self_expr:expr, $other:expr) => { $crate::uint_full_mul_reg!($name, 8, $self_expr, $other, |a, b| a != 0 || b != 0); @@ -194,18 +195,18 @@ macro_rules! uint_overflowing_mul { fn any_nonzero(arr: &[u64; $n_words]) -> bool { use $crate::unroll; unroll! { - for i in 0..$n_words { - if arr[i] != 0 { - return true; - } - } + for i in 0..$n_words { + if arr[i] != 0 { + return true; + } } + } false - } + } ($name(ret[0]), any_nonzero(&ret[1])) - }}; + }}; } #[macro_export] @@ -215,11 +216,11 @@ macro_rules! overflowing { let (overflow_x, overflow_overflow) = $op; $overflow |= overflow_overflow; overflow_x - }}; + }}; ($op: expr) => {{ let (overflow_x, _overflow_overflow) = $op; overflow_x - }}; + }}; } #[macro_export] @@ -1579,7 +1580,6 @@ macro_rules! impl_std_for_uint { #[cfg(feature = "quickcheck")] #[macro_export] #[doc(hidden)] -#[rustfmt::skip] macro_rules! impl_quickcheck_arbitrary_for_uint { ($uint: ty, $n_bytes: tt) => { impl $crate::qc::Arbitrary for $uint { From 50ed3552287cf4b4c52fd4de93ecd3b0947f6f78 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Mon, 28 Oct 2019 11:58:35 +0100 Subject: [PATCH 07/15] rustfmt: max width 120 --- contract-address/src/lib.rs | 17 +- ethereum-types/src/hash.rs | 60 ++-- ethereum-types/src/uint.rs | 15 +- ethereum-types/tests/serde.rs | 78 ++--- fixed-hash/src/hash.rs | 19 +- fixed-hash/src/tests.rs | 19 +- keccak-hash/src/lib.rs | 22 +- kvdb-memorydb/src/lib.rs | 5 +- kvdb-rocksdb/src/lib.rs | 104 ++---- kvdb-web/src/error.rs | 4 +- kvdb-web/src/indexed_db.rs | 38 +-- kvdb-web/src/lib.rs | 34 +- kvdb/src/lib.rs | 10 +- parity-bytes/src/lib.rs | 7 +- parity-crypto/benches/bench.rs | 6 +- parity-crypto/src/aes.rs | 82 ++--- parity-crypto/src/digest.rs | 5 +- parity-crypto/src/error.rs | 4 +- parity-crypto/src/hmac/mod.rs | 42 +-- parity-crypto/src/hmac/test.rs | 23 +- parity-crypto/src/lib.rs | 7 +- parity-crypto/src/pbkdf2/test.rs | 4 +- parity-crypto/src/publickey/ec_math_utils.rs | 28 +- .../src/publickey/ecdsa_signature.rs | 41 +-- parity-crypto/src/publickey/ecies.rs | 7 +- parity-crypto/src/publickey/extended_keys.rs | 117 +++---- parity-crypto/src/publickey/keypair.rs | 8 +- parity-crypto/src/publickey/mod.rs | 4 +- parity-crypto/src/publickey/secret_key.rs | 14 +- parity-crypto/src/scrypt.rs | 24 +- parity-path/src/lib.rs | 17 +- parity-util-mem/src/impls.rs | 5 +- parity-util-mem/src/malloc_size.rs | 5 +- parity-util-mem/src/sizeof.rs | 4 +- primitive-types/impls/codec/src/lib.rs | 11 +- primitive-types/impls/rlp/src/lib.rs | 23 +- .../impls/serde/benches/impl_serde.rs | 14 +- primitive-types/impls/serde/benches/input.rs | 3 +- primitive-types/impls/serde/src/serialize.rs | 41 +-- rlp/benches/rlp.rs | 14 +- rlp/src/rlpin.rs | 31 +- rlp/src/stream.rs | 10 +- rlp/tests/tests.rs | 64 ++-- rustfmt.toml | 1 + transaction-pool/src/error.rs | 14 +- transaction-pool/src/pool.rs | 63 ++-- transaction-pool/src/replace.rs | 11 +- transaction-pool/src/scoring.rs | 16 +- transaction-pool/src/tests/helpers.rs | 4 +- transaction-pool/src/tests/mod.rs | 47 +-- transaction-pool/src/transactions.rs | 57 +--- triehash/src/lib.rs | 18 +- uint/benches/bigint.rs | 173 ++-------- uint/examples/modular.rs | 6 +- uint/tests/uint_tests.rs | 321 ++++++------------ 55 files changed, 530 insertions(+), 1291 deletions(-) diff --git a/contract-address/src/lib.rs b/contract-address/src/lib.rs index 5c59e1a97..1d4068d7d 100644 --- a/contract-address/src/lib.rs +++ b/contract-address/src/lib.rs @@ -93,14 +93,10 @@ mod tests { #[test] fn test_from_sender_salt_and_code_hash() { let sender = Address::zero(); - let code_hash = - H256::from_str("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470") - .unwrap(); - let expected_address = - Address::from_str("e33c0c7f7df4809055c3eba6c09cfe4baf1bd9e0").unwrap(); + let code_hash = H256::from_str("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").unwrap(); + let expected_address = Address::from_str("e33c0c7f7df4809055c3eba6c09cfe4baf1bd9e0").unwrap(); - let contract_address = - ContractAddress::from_sender_salt_and_code(&sender, H256::zero(), code_hash); + let contract_address = ContractAddress::from_sender_salt_and_code(&sender, H256::zero(), code_hash); assert_eq!(Address::from(contract_address), expected_address); } @@ -108,11 +104,8 @@ mod tests { #[test] fn test_from_sender_and_code_hash() { let sender = Address::from_str("0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d").unwrap(); - let code_hash = - H256::from_str("d98f2e8134922f73748703c8e7084d42f13d2fa1439936ef5a3abcf5646fe83f") - .unwrap(); - let expected_address = - Address::from_str("064417880f5680b141ed7fcac031aad40df080b0").unwrap(); + let code_hash = H256::from_str("d98f2e8134922f73748703c8e7084d42f13d2fa1439936ef5a3abcf5646fe83f").unwrap(); + let expected_address = Address::from_str("064417880f5680b141ed7fcac031aad40df080b0").unwrap(); let contract_address = ContractAddress::from_sender_and_code(&sender, code_hash); diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index 23d00dd22..0de3d2625 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -72,22 +72,10 @@ mod tests { #[test] fn test_serialize_h160() { let tests = vec![ - ( - H160::from_low_u64_be(0), - "0x0000000000000000000000000000000000000000", - ), - ( - H160::from_low_u64_be(2), - "0x0000000000000000000000000000000000000002", - ), - ( - H160::from_low_u64_be(15), - "0x000000000000000000000000000000000000000f", - ), - ( - H160::from_low_u64_be(16), - "0x0000000000000000000000000000000000000010", - ), + (H160::from_low_u64_be(0), "0x0000000000000000000000000000000000000000"), + (H160::from_low_u64_be(2), "0x0000000000000000000000000000000000000002"), + (H160::from_low_u64_be(15), "0x000000000000000000000000000000000000000f"), + (H160::from_low_u64_be(16), "0x0000000000000000000000000000000000000010"), ( H160::from_low_u64_be(1_000), "0x00000000000000000000000000000000000003e8", @@ -103,10 +91,7 @@ mod tests { ]; for (number, expected) in tests { - assert_eq!( - format!("{:?}", expected), - ser::to_string_pretty(&number).unwrap() - ); + assert_eq!(format!("{:?}", expected), ser::to_string_pretty(&number).unwrap()); assert_eq!(number, ser::from_str(&format!("{:?}", expected)).unwrap()); } } @@ -145,31 +130,28 @@ mod tests { ]; for (number, expected) in tests { - assert_eq!( - format!("{:?}", expected), - ser::to_string_pretty(&number).unwrap() - ); + assert_eq!(format!("{:?}", expected), ser::to_string_pretty(&number).unwrap()); assert_eq!(number, ser::from_str(&format!("{:?}", expected)).unwrap()); } } #[test] fn test_serialize_invalid() { - assert!(ser::from_str::( - "\"0x000000000000000000000000000000000000000000000000000000000000000\"" - ) - .unwrap_err() - .is_data()); - assert!(ser::from_str::( - "\"0x000000000000000000000000000000000000000000000000000000000000000g\"" - ) - .unwrap_err() - .is_data()); - assert!(ser::from_str::( - "\"0x00000000000000000000000000000000000000000000000000000000000000000\"" - ) - .unwrap_err() - .is_data()); + assert!( + ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000\"") + .unwrap_err() + .is_data() + ); + assert!( + ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000g\"") + .unwrap_err() + .is_data() + ); + assert!( + ser::from_str::("\"0x00000000000000000000000000000000000000000000000000000000000000000\"") + .unwrap_err() + .is_data() + ); assert!(ser::from_str::("\"\"").unwrap_err().is_data()); assert!(ser::from_str::("\"0\"").unwrap_err().is_data()); assert!(ser::from_str::("\"10\"").unwrap_err().is_data()); diff --git a/ethereum-types/src/uint.rs b/ethereum-types/src/uint.rs index 8d6a355f4..c7cef887b 100644 --- a/ethereum-types/src/uint.rs +++ b/ethereum-types/src/uint.rs @@ -40,10 +40,7 @@ mod tests { ]; for (number, expected) in tests { - assert_eq!( - format!("{:?}", expected), - ser::to_string_pretty(&number).unwrap() - ); + assert_eq!(format!("{:?}", expected), ser::to_string_pretty(&number).unwrap()); assert_eq!(number, ser::from_str(&format!("{:?}", expected)).unwrap()); } @@ -66,11 +63,11 @@ mod tests { ser::to_string_pretty(&!U256::zero()).unwrap(), "\"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"" ); - assert!(ser::from_str::( - "\"0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"" - ) - .unwrap_err() - .is_data()); + assert!( + ser::from_str::("\"0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"") + .unwrap_err() + .is_data() + ); } #[test] diff --git a/ethereum-types/tests/serde.rs b/ethereum-types/tests/serde.rs index e24422323..e7da96322 100644 --- a/ethereum-types/tests/serde.rs +++ b/ethereum-types/tests/serde.rs @@ -31,10 +31,7 @@ macro_rules! test { ]; for (number, expected) in tests { - assert_eq!( - format!("{:?}", expected), - ser::to_string_pretty(&number).unwrap() - ); + assert_eq!(format!("{:?}", expected), ser::to_string_pretty(&number).unwrap()); assert_eq!(number, ser::from_str(&format!("{:?}", expected)).unwrap()); } @@ -57,32 +54,20 @@ fn test_large_values() { ser::to_string_pretty(&!U256::zero()).unwrap(), "\"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"" ); - assert!(ser::from_str::( - "\"0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"" - ) - .unwrap_err() - .is_data()); + assert!( + ser::from_str::("\"0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"") + .unwrap_err() + .is_data() + ); } #[test] fn test_h160() { let tests = vec![ - ( - H160::from_low_u64_be(0), - "0x0000000000000000000000000000000000000000", - ), - ( - H160::from_low_u64_be(2), - "0x0000000000000000000000000000000000000002", - ), - ( - H160::from_low_u64_be(15), - "0x000000000000000000000000000000000000000f", - ), - ( - H160::from_low_u64_be(16), - "0x0000000000000000000000000000000000000010", - ), + (H160::from_low_u64_be(0), "0x0000000000000000000000000000000000000000"), + (H160::from_low_u64_be(2), "0x0000000000000000000000000000000000000002"), + (H160::from_low_u64_be(15), "0x000000000000000000000000000000000000000f"), + (H160::from_low_u64_be(16), "0x0000000000000000000000000000000000000010"), ( H160::from_low_u64_be(1_000), "0x00000000000000000000000000000000000003e8", @@ -98,10 +83,7 @@ fn test_h160() { ]; for (number, expected) in tests { - assert_eq!( - format!("{:?}", expected), - ser::to_string_pretty(&number).unwrap() - ); + assert_eq!(format!("{:?}", expected), ser::to_string_pretty(&number).unwrap()); assert_eq!(number, ser::from_str(&format!("{:?}", expected)).unwrap()); } } @@ -140,31 +122,28 @@ fn test_h256() { ]; for (number, expected) in tests { - assert_eq!( - format!("{:?}", expected), - ser::to_string_pretty(&number).unwrap() - ); + assert_eq!(format!("{:?}", expected), ser::to_string_pretty(&number).unwrap()); assert_eq!(number, ser::from_str(&format!("{:?}", expected)).unwrap()); } } #[test] fn test_invalid() { - assert!(ser::from_str::( - "\"0x000000000000000000000000000000000000000000000000000000000000000\"" - ) - .unwrap_err() - .is_data()); - assert!(ser::from_str::( - "\"0x000000000000000000000000000000000000000000000000000000000000000g\"" - ) - .unwrap_err() - .is_data()); - assert!(ser::from_str::( - "\"0x00000000000000000000000000000000000000000000000000000000000000000\"" - ) - .unwrap_err() - .is_data()); + assert!( + ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000\"") + .unwrap_err() + .is_data() + ); + assert!( + ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000g\"") + .unwrap_err() + .is_data() + ); + assert!( + ser::from_str::("\"0x00000000000000000000000000000000000000000000000000000000000000000\"") + .unwrap_err() + .is_data() + ); assert!(ser::from_str::("\"\"").unwrap_err().is_data()); assert!(ser::from_str::("\"0\"").unwrap_err().is_data()); assert!(ser::from_str::("\"10\"").unwrap_err().is_data()); @@ -172,8 +151,7 @@ fn test_invalid() { #[test] fn test_invalid_char() { - const INVALID_STR: &str = - "\"0x000000000000000000000000000000000000000000000000000000000000000g\""; + const INVALID_STR: &str = "\"0x000000000000000000000000000000000000000000000000000000000000000g\""; const EXPECTED_MSG: &str = "invalid hex character: g, at 65 at line 1 column 68"; assert_eq!( ser::from_str::(INVALID_STR).unwrap_err().to_string(), diff --git a/fixed-hash/src/hash.rs b/fixed-hash/src/hash.rs index 2004ffdf0..778f234c0 100644 --- a/fixed-hash/src/hash.rs +++ b/fixed-hash/src/hash.rs @@ -486,9 +486,7 @@ macro_rules! impl_rand_for_fixed_hash { #[doc(hidden)] macro_rules! impl_rand_for_fixed_hash { ( $name:ident ) => { - impl $crate::rand::distributions::Distribution<$name> - for $crate::rand::distributions::Standard - { + impl $crate::rand::distributions::Distribution<$name> for $crate::rand::distributions::Standard { fn sample(&self, rng: &mut R) -> $name { let mut ret = $name::zero(); for byte in ret.as_bytes_mut().iter_mut() { @@ -650,9 +648,7 @@ macro_rules! impl_rustc_hex_for_fixed_hash { /// /// - When encountering invalid non hex-digits /// - Upon empty string input or invalid input length in general - fn from_str( - input: &str, - ) -> $crate::core_::result::Result<$name, $crate::rustc_hex::FromHexError> { + fn from_str(input: &str) -> $crate::core_::result::Result<$name, $crate::rustc_hex::FromHexError> { #[cfg(not(feature = "std"))] use $crate::alloc_::vec::Vec; use $crate::rustc_hex::FromHex; @@ -788,14 +784,11 @@ macro_rules! impl_fixed_hash_conversions { let small_ty_size = $small_ty::len_bytes(); $crate::core_::debug_assert!( - large_ty_size > small_ty_size - && large_ty_size % 2 == 0 - && small_ty_size % 2 == 0 + large_ty_size > small_ty_size && large_ty_size % 2 == 0 && small_ty_size % 2 == 0 ); let mut ret = $large_ty::zero(); - ret.as_bytes_mut()[(large_ty_size - small_ty_size)..large_ty_size] - .copy_from_slice(value.as_bytes()); + ret.as_bytes_mut()[(large_ty_size - small_ty_size)..large_ty_size].copy_from_slice(value.as_bytes()); ret } } @@ -806,9 +799,7 @@ macro_rules! impl_fixed_hash_conversions { let small_ty_size = $small_ty::len_bytes(); $crate::core_::debug_assert!( - large_ty_size > small_ty_size - && large_ty_size % 2 == 0 - && small_ty_size % 2 == 0 + large_ty_size > small_ty_size && large_ty_size % 2 == 0 && small_ty_size % 2 == 0 ); let mut ret = $small_ty::zero(); diff --git a/fixed-hash/src/tests.rs b/fixed-hash/src/tests.rs index 12f28ff25..734d59de2 100644 --- a/fixed-hash/src/tests.rs +++ b/fixed-hash/src/tests.rs @@ -153,10 +153,7 @@ mod to_low_u64 { #[test] fn smaller_size() { - assert_eq!( - H32::from([0x01, 0x23, 0x45, 0x67]).to_low_u64_be(), - 0x0123_4567 - ); + assert_eq!(H32::from([0x01, 0x23, 0x45, 0x67]).to_low_u64_be(), 0x0123_4567); assert_eq!( H32::from([0x01, 0x23, 0x45, 0x67]).to_low_u64_le(), 0x6745_2301_0000_0000 @@ -256,10 +253,7 @@ mod rand { fn random() { let default_seed = ::Seed::default(); let mut rng = StdRng::from_seed(default_seed); - assert_eq!( - H32::random_using(&mut rng), - H32::from([0x76, 0xa0, 0x40, 0x53]) - ); + assert_eq!(H32::random_using(&mut rng), H32::from([0x76, 0xa0, 0x40, 0x53])); } #[test] @@ -313,14 +307,13 @@ mod from_str { #[test] fn from_h160_to_h256() { let h160 = H160::from([ - 0xEF, 0x2D, 0x6D, 0x19, 0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, - 0x46, 0xB3, 0x7D, 0x11, 0x06, + 0xEF, 0x2D, 0x6D, 0x19, 0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, + 0x11, 0x06, ]); let h256 = H256::from(h160); let expected = H256::from([ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, - 0x19, 0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, - 0x11, 0x06, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19, 0x40, 0x84, + 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06, ]); assert_eq!(h256, expected); } diff --git a/keccak-hash/src/lib.rs b/keccak-hash/src/lib.rs index 65f719bb5..adfe26114 100644 --- a/keccak-hash/src/lib.rs +++ b/keccak-hash/src/lib.rs @@ -25,20 +25,20 @@ use tiny_keccak::Keccak; /// Get the KECCAK (i.e. Keccak) hash of the empty bytes string. pub const KECCAK_EMPTY: H256 = H256([ - 0xc5, 0xd2, 0x46, 0x01, 0x86, 0xf7, 0x23, 0x3c, 0x92, 0x7e, 0x7d, 0xb2, 0xdc, 0xc7, 0x03, 0xc0, - 0xe5, 0x00, 0xb6, 0x53, 0xca, 0x82, 0x27, 0x3b, 0x7b, 0xfa, 0xd8, 0x04, 0x5d, 0x85, 0xa4, 0x70, + 0xc5, 0xd2, 0x46, 0x01, 0x86, 0xf7, 0x23, 0x3c, 0x92, 0x7e, 0x7d, 0xb2, 0xdc, 0xc7, 0x03, 0xc0, 0xe5, 0x00, 0xb6, + 0x53, 0xca, 0x82, 0x27, 0x3b, 0x7b, 0xfa, 0xd8, 0x04, 0x5d, 0x85, 0xa4, 0x70, ]); /// The KECCAK of the RLP encoding of empty data. pub const KECCAK_NULL_RLP: H256 = H256([ - 0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e, - 0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21, + 0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e, 0x5b, 0x48, 0xe0, + 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21, ]); /// The KECCAK of the RLP encoding of empty list. pub const KECCAK_EMPTY_LIST_RLP: H256 = H256([ - 0x1d, 0xcc, 0x4d, 0xe8, 0xde, 0xc7, 0x5d, 0x7a, 0xab, 0x85, 0xb5, 0x67, 0xb6, 0xcc, 0xd4, 0x1a, - 0xd3, 0x12, 0x45, 0x1b, 0x94, 0x8a, 0x74, 0x13, 0xf0, 0xa1, 0x42, 0xfd, 0x40, 0xd4, 0x93, 0x47, + 0x1d, 0xcc, 0x4d, 0xe8, 0xde, 0xc7, 0x5d, 0x7a, 0xab, 0x85, 0xb5, 0x67, 0xb6, 0xcc, 0xd4, 0x1a, 0xd3, 0x12, 0x45, + 0x1b, 0x94, 0x8a, 0x74, 0x13, 0xf0, 0xa1, 0x42, 0xfd, 0x40, 0xd4, 0x93, 0x47, ]); pub fn keccak>(s: T) -> H256 { @@ -121,9 +121,8 @@ mod tests { assert_eq!( keccak([0x41u8; 32]), H256([ - 0x59, 0xca, 0xd5, 0x94, 0x86, 0x73, 0x62, 0x2c, 0x1d, 0x64, 0xe2, 0x32, 0x24, 0x88, - 0xbf, 0x01, 0x61, 0x9f, 0x7f, 0xf4, 0x57, 0x89, 0x74, 0x1b, 0x15, 0xa9, 0xf7, 0x82, - 0xce, 0x92, 0x90, 0xa8 + 0x59, 0xca, 0xd5, 0x94, 0x86, 0x73, 0x62, 0x2c, 0x1d, 0x64, 0xe2, 0x32, 0x24, 0x88, 0xbf, 0x01, 0x61, + 0x9f, 0x7f, 0xf4, 0x57, 0x89, 0x74, 0x1b, 0x15, 0xa9, 0xf7, 0x82, 0xce, 0x92, 0x90, 0xa8 ]), ); } @@ -132,9 +131,8 @@ mod tests { fn write_keccak_with_content() { let data: Vec = From::from("hello world"); let expected = vec![ - 0x47, 0x17, 0x32, 0x85, 0xa8, 0xd7, 0x34, 0x1e, 0x5e, 0x97, 0x2f, 0xc6, 0x77, 0x28, - 0x63, 0x84, 0xf8, 0x02, 0xf8, 0xef, 0x42, 0xa5, 0xec, 0x5f, 0x03, 0xbb, 0xfa, 0x25, - 0x4c, 0xb0, 0x1f, 0xad, + 0x47, 0x17, 0x32, 0x85, 0xa8, 0xd7, 0x34, 0x1e, 0x5e, 0x97, 0x2f, 0xc6, 0x77, 0x28, 0x63, 0x84, 0xf8, 0x02, + 0xf8, 0xef, 0x42, 0xa5, 0xec, 0x5f, 0x03, 0xbb, 0xfa, 0x25, 0x4c, 0xb0, 0x1f, 0xad, ]; let mut dest = [0u8; 32]; write_keccak(data, &mut dest); diff --git a/kvdb-memorydb/src/lib.rs b/kvdb-memorydb/src/lib.rs index f46ff8bf9..ca10a9d33 100644 --- a/kvdb-memorydb/src/lib.rs +++ b/kvdb-memorydb/src/lib.rs @@ -89,10 +89,7 @@ impl KeyValueDB for InMemory { Ok(()) } - fn iter<'a>( - &'a self, - col: Option, - ) -> Box, Box<[u8]>)> + 'a> { + fn iter<'a>(&'a self, col: Option) -> Box, Box<[u8]>)> + 'a> { match self.columns.read().get(&col) { Some(map) => Box::new( // TODO: worth optimizing at all? diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index ea15d200d..97d2602bc 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -18,8 +18,8 @@ use std::{cmp, collections::HashMap, error, fs, io, marker::PhantomData, mem, pa use interleaved_ordered::{interleave_ordered, InterleaveOrdered}; use parity_rocksdb::{ - BlockBasedOptions, Cache, Column, DBIterator, Direction, IteratorMode, Options, ReadOptions, - Writable, WriteBatch, WriteOptions, DB, + BlockBasedOptions, Cache, Column, DBIterator, Direction, IteratorMode, Options, ReadOptions, Writable, WriteBatch, + WriteOptions, DB, }; use parking_lot::{Mutex, MutexGuard, RwLock}; @@ -257,16 +257,10 @@ pub struct Database { } #[inline] -fn check_for_corruption>( - path: P, - res: result::Result, -) -> io::Result { +fn check_for_corruption>(path: P, res: result::Result) -> io::Result { if let Err(ref s) = res { if s.starts_with("Corruption:") { - warn!( - "DB corrupted: {}. Repair will be triggered on next restart", - s - ); + warn!("DB corrupted: {}. Repair will be triggered on next restart", s); let _ = fs::File::create(path.as_ref().join(Database::CORRUPTION_FILE_NAME)); } } @@ -275,8 +269,7 @@ fn check_for_corruption>( } fn is_corrupted(s: &str) -> bool { - s.starts_with("Corruption:") - || s.starts_with("Invalid argument: You have to open all column families") + s.starts_with("Corruption:") || s.starts_with("Invalid argument: You have to open all column families") } impl Database { @@ -298,8 +291,7 @@ impl Database { opts.set_use_fsync(false); opts.create_if_missing(true); opts.set_max_open_files(config.max_open_files); - opts.set_parsed_options("keep_log_file_num=1") - .map_err(other_io_err)?; + opts.set_parsed_options("keep_log_file_num=1").map_err(other_io_err)?; opts.set_parsed_options("bytes_per_sync=1048576") .map_err(other_io_err)?; opts.set_db_write_buffer_size(config.memory_budget_per_col() / 2); @@ -345,10 +337,7 @@ impl Database { Ok(db) => { cfs = cfnames .iter() - .map(|n| { - db.cf_handle(n) - .expect("rocksdb opens a cf_handle for each cfname; qed") - }) + .map(|n| db.cf_handle(n).expect("rocksdb opens a cf_handle for each cfname; qed")) .collect(); Ok(db) } @@ -381,14 +370,10 @@ impl Database { match cfnames.is_empty() { true => DB::open(&opts, path).map_err(other_io_err)?, false => { - let db = DB::open_cf(&opts, path, &cfnames, &cf_options) - .map_err(other_io_err)?; + let db = DB::open_cf(&opts, path, &cfnames, &cf_options).map_err(other_io_err)?; cfs = cfnames .iter() - .map(|n| { - db.cf_handle(n) - .expect("rocksdb opens a cf_handle for each cfname; qed") - }) + .map(|n| db.cf_handle(n).expect("rocksdb opens a cf_handle for each cfname; qed")) .collect(); db } @@ -456,9 +441,7 @@ impl Database { } KeyState::Insert(ref value) => { if c > 0 { - batch - .put_cf(cfs[c - 1], key, value) - .map_err(other_io_err)?; + batch.put_cf(cfs[c - 1], key, value).map_err(other_io_err)?; } else { batch.put(key, value).map_err(other_io_err)?; } @@ -487,9 +470,7 @@ impl Database { // The value inside the lock is used to detect that. if *lock { // This can only happen if another flushing thread is terminated unexpectedly. - return Err(other_io_err( - "Database write failure. Running low on memory perhaps?", - )); + return Err(other_io_err("Database write failure. Running low on memory perhaps?")); } *lock = true; let result = self.write_flushing_with_lock(&mut lock); @@ -510,15 +491,11 @@ impl Database { match op { DBOp::Insert { col, key, value } => match col { None => batch.put(&key, &value).map_err(other_io_err)?, - Some(c) => batch - .put_cf(cfs[c as usize], &key, &value) - .map_err(other_io_err)?, + Some(c) => batch.put_cf(cfs[c as usize], &key, &value).map_err(other_io_err)?, }, DBOp::Delete { col, key } => match col { None => batch.delete(&key).map_err(other_io_err)?, - Some(c) => batch - .delete_cf(cfs[c as usize], &key) - .map_err(other_io_err)?, + Some(c) => batch.delete_cf(cfs[c as usize], &key).map_err(other_io_err)?, }, } } @@ -618,12 +595,7 @@ impl Database { match *self.db.read() { Some(DBAndColumns { ref db, ref cfs }) => { let iter = col.map_or_else( - || { - db.iterator_opt( - IteratorMode::From(prefix, Direction::Forward), - &self.read_opts, - ) - }, + || db.iterator_opt(IteratorMode::From(prefix, Direction::Forward), &self.read_opts), |c| { db.iterator_cf_opt( cfs[c as usize], @@ -691,13 +663,7 @@ impl Database { self.db .read() .as_ref() - .and_then(|db| { - if db.cfs.is_empty() { - None - } else { - Some(db.cfs.len()) - } - }) + .and_then(|db| if db.cfs.is_empty() { None } else { Some(db.cfs.len()) }) .map(|n| n as u32) .unwrap_or(0) } @@ -763,10 +729,7 @@ impl KeyValueDB for Database { Database::flush(self) } - fn iter<'a>( - &'a self, - col: Option, - ) -> Box, Box<[u8]>)> + 'a> { + fn iter<'a>(&'a self, col: Option) -> Box, Box<[u8]>)> + 'a> { let unboxed = Database::iter(self, col); Box::new(unboxed.into_iter().flat_map(|inner| inner)) } @@ -802,15 +765,9 @@ mod tests { fn test_db(config: &DatabaseConfig) { let tempdir = TempDir::new("").unwrap(); let db = Database::open(config, tempdir.path().to_str().unwrap()).unwrap(); - let key1 = - H256::from_str("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc") - .unwrap(); - let key2 = - H256::from_str("03c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc") - .unwrap(); - let key3 = - H256::from_str("01c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc") - .unwrap(); + let key1 = H256::from_str("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc").unwrap(); + let key2 = H256::from_str("03c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc").unwrap(); + let key3 = H256::from_str("01c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc").unwrap(); let mut batch = db.transaction(); batch.put(None, key1.as_bytes(), b"cat"); @@ -841,15 +798,9 @@ mod tests { transaction.delete(None, key1.as_bytes()); db.write(transaction).unwrap(); assert!(db.get(None, key1.as_bytes()).unwrap().is_none()); - assert_eq!( - &*db.get(None, key3.as_bytes()).unwrap().unwrap(), - b"elephant" - ); - - assert_eq!( - &*db.get_by_prefix(None, key3.as_bytes()).unwrap(), - b"elephant" - ); + assert_eq!(&*db.get(None, key3.as_bytes()).unwrap().unwrap(), b"elephant"); + + assert_eq!(&*db.get_by_prefix(None, key3.as_bytes()).unwrap(), b"elephant"); assert_eq!(&*db.get_by_prefix(None, key2.as_bytes()).unwrap(), b"dog"); let mut transaction = db.transaction(); @@ -877,12 +828,11 @@ mod tests { use std::path::PathBuf; // Example df output. let example_df = vec![ - 70, 105, 108, 101, 115, 121, 115, 116, 101, 109, 32, 32, 32, 32, 32, 49, 75, 45, 98, - 108, 111, 99, 107, 115, 32, 32, 32, 32, 32, 85, 115, 101, 100, 32, 65, 118, 97, 105, - 108, 97, 98, 108, 101, 32, 85, 115, 101, 37, 32, 77, 111, 117, 110, 116, 101, 100, 32, - 111, 110, 10, 47, 100, 101, 118, 47, 115, 100, 97, 49, 32, 32, 32, 32, 32, 32, 32, 54, - 49, 52, 48, 57, 51, 48, 48, 32, 51, 56, 56, 50, 50, 50, 51, 54, 32, 32, 49, 57, 52, 52, - 52, 54, 49, 54, 32, 32, 54, 55, 37, 32, 47, 10, + 70, 105, 108, 101, 115, 121, 115, 116, 101, 109, 32, 32, 32, 32, 32, 49, 75, 45, 98, 108, 111, 99, 107, + 115, 32, 32, 32, 32, 32, 85, 115, 101, 100, 32, 65, 118, 97, 105, 108, 97, 98, 108, 101, 32, 85, 115, 101, + 37, 32, 77, 111, 117, 110, 116, 101, 100, 32, 111, 110, 10, 47, 100, 101, 118, 47, 115, 100, 97, 49, 32, + 32, 32, 32, 32, 32, 32, 54, 49, 52, 48, 57, 51, 48, 48, 32, 51, 56, 56, 50, 50, 50, 51, 54, 32, 32, 49, 57, + 52, 52, 52, 54, 49, 54, 32, 32, 54, 55, 37, 32, 47, 10, ]; let expected_output = Some(PathBuf::from("/sys/block/sda/queue/rotational")); assert_eq!(rotational_from_df_output(example_df), expected_output); diff --git a/kvdb-web/src/error.rs b/kvdb-web/src/error.rs index 5dff3ee63..cd3916174 100644 --- a/kvdb-web/src/error.rs +++ b/kvdb-web/src/error.rs @@ -47,9 +47,7 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Error::WindowNotAvailable => write!(f, "Accessing a Window has failed"), - Error::NotSupported(ref err) => { - write!(f, "IndexedDB is not supported by your browser: {}", err,) - } + Error::NotSupported(ref err) => write!(f, "IndexedDB is not supported by your browser: {}", err,), Error::__Nonexhaustive => unreachable!(), } } diff --git a/kvdb-web/src/indexed_db.rs b/kvdb-web/src/indexed_db.rs index 4876327b5..9074c7d90 100644 --- a/kvdb-web/src/indexed_db.rs +++ b/kvdb-web/src/indexed_db.rs @@ -18,9 +18,7 @@ use js_sys::{Array, ArrayBuffer, Uint8Array}; use wasm_bindgen::{closure::Closure, JsCast, JsValue}; -use web_sys::{ - Event, IdbCursorWithValue, IdbDatabase, IdbOpenDbRequest, IdbRequest, IdbTransactionMode, -}; +use web_sys::{Event, IdbCursorWithValue, IdbDatabase, IdbOpenDbRequest, IdbRequest, IdbTransactionMode}; use futures::channel; use futures::prelude::*; @@ -40,11 +38,7 @@ pub struct IndexedDB { /// Opens the IndexedDB with the given name, version and the specified number of columns /// (including the default one). -pub fn open( - name: &str, - version: Option, - columns: u32, -) -> impl Future> { +pub fn open(name: &str, version: Option, columns: u32) -> impl Future> { let (tx, rx) = channel::oneshot::channel::(); let window = match web_sys::window() { @@ -55,9 +49,7 @@ pub fn open( let idb_factory = match idb_factory { Ok(idb_factory) => idb_factory.expect("We can't get a null pointer back; qed"), - Err(err) => { - return future::Either::Right(future::err(Error::NotSupported(format!("{:?}", err)))) - } + Err(err) => return future::Either::Right(future::err(Error::NotSupported(format!("{:?}", err)))), }; let open_request = match version { @@ -74,9 +66,7 @@ pub fn open( let on_success = Closure::once(move |event: &Event| { // Extract database handle from the event let target = event.target().expect("Event should have a target; qed"); - let req = target - .dyn_ref::() - .expect("Event target is IdbRequest; qed"); + let req = target.dyn_ref::().expect("Event target is IdbRequest; qed"); let result = req .result() @@ -129,18 +119,12 @@ fn try_create_missing_stores(req: &IdbOpenDbRequest, columns: u32, version: Opti ); // Extract database handle from the event let target = event.target().expect("Event should have a target; qed"); - let req = target - .dyn_ref::() - .expect("Event target is IdbRequest; qed"); + let req = target.dyn_ref::().expect("Event target is IdbRequest; qed"); let result = req.result().expect("IdbRequest should have a result; qed"); let db: &IdbDatabase = result.unchecked_ref(); let previous_columns = db.object_store_names().length(); - debug!( - "Previous version: {}, columns {}", - db.version(), - previous_columns - ); + debug!("Previous version: {}, columns {}", db.version(), previous_columns); for name in (previous_columns..=columns).map(store_name) { let res = db.create_object_store(name.as_str()); @@ -155,11 +139,7 @@ fn try_create_missing_stores(req: &IdbOpenDbRequest, columns: u32, version: Opti } /// Commit a transaction to the IndexedDB. -pub fn idb_commit_transaction( - idb: &IdbDatabase, - txn: &DBTransaction, - columns: u32, -) -> impl Future { +pub fn idb_commit_transaction(idb: &IdbDatabase, txn: &DBTransaction, columns: u32) -> impl Future { let store_names_js = store_names_js(columns); // Create a transaction @@ -236,9 +216,7 @@ pub fn idb_cursor(idb: &IdbDatabase, col: u32) -> impl Stream, V let store = txn .object_store(store_name) .expect("Opening a store shouldn't fail; qed"); - let cursor = store - .open_cursor() - .expect("Opening a cursor shouldn't fail; qed"); + let cursor = store.open_cursor().expect("Opening a cursor shouldn't fail; qed"); let (tx, rx) = channel::mpsc::unbounded(); diff --git a/kvdb-web/src/lib.rs b/kvdb-web/src/lib.rs index 571107c0e..bc9687ed4 100644 --- a/kvdb-web/src/lib.rs +++ b/kvdb-web/src/lib.rs @@ -57,10 +57,7 @@ fn number_to_column(col: u32) -> Column { impl Database { /// Opens the database with the given name, /// and the specified number of columns (not including the default one). - pub fn open( - name: String, - columns: u32, - ) -> impl Future> { + pub fn open(name: String, columns: u32) -> impl Future> { // let's try to open the latest version of the db first let open_request = indexed_db::open(name.as_str(), None, columns); let name_clone = name.clone(); @@ -79,9 +76,7 @@ impl Database { if columns + 1 > db.columns { let next_version = db.version + 1; drop(db); - future::Either::Left( - indexed_db::open(name.as_str(), Some(next_version), columns).boxed(), - ) + future::Either::Left(indexed_db::open(name.as_str(), Some(next_version), columns).boxed()) } else { future::Either::Left(future::ok(db).boxed()) } @@ -100,17 +95,12 @@ impl Database { future::Either::Left( stream::iter(0..=columns) .map(move |n| { - let db = weak - .upgrade() - .expect("rc should live at least as long; qed"); - indexed_db::idb_cursor(&db, n).fold( - DBTransaction::new(), - move |mut txn, (key, value)| { - let column = number_to_column(n); - txn.put_vec(column, key.as_ref(), value); - future::ready(txn) - }, - ) + let db = weak.upgrade().expect("rc should live at least as long; qed"); + indexed_db::idb_cursor(&db, n).fold(DBTransaction::new(), move |mut txn, (key, value)| { + let column = number_to_column(n); + txn.put_vec(column, key.as_ref(), value); + future::ready(txn) + }) // write each column into memory }) .fold(in_memory::create(columns), |m, txn| { @@ -126,8 +116,7 @@ impl Database { columns, in_memory, indexed_db: Mutex::new(SendWrapper::new( - Rc::try_unwrap(rc) - .expect("should have only 1 ref at this point; qed"), + Rc::try_unwrap(rc).expect("should have only 1 ref at this point; qed"), )), }) }), @@ -175,10 +164,7 @@ impl KeyValueDB for Database { } // NOTE: clones the whole db - fn iter<'a>( - &'a self, - col: Option, - ) -> Box, Box<[u8]>)> + 'a> { + fn iter<'a>(&'a self, col: Option) -> Box, Box<[u8]>)> + 'a> { self.in_memory.iter(col) } diff --git a/kvdb/src/lib.rs b/kvdb/src/lib.rs index dc5fbbb6f..0f2230864 100644 --- a/kvdb/src/lib.rs +++ b/kvdb/src/lib.rs @@ -106,10 +106,7 @@ impl DBTransaction { pub fn delete(&mut self, col: Option, key: &[u8]) { let mut ekey = ElasticArray32::new(); ekey.append_slice(key); - self.ops.push(DBOp::Delete { - col: col, - key: ekey, - }); + self.ops.push(DBOp::Delete { col: col, key: ekey }); } } @@ -156,10 +153,7 @@ pub trait KeyValueDB: Sync + Send { fn flush(&self) -> io::Result<()>; /// Iterate over flushed data for a given column. - fn iter<'a>( - &'a self, - col: Option, - ) -> Box, Box<[u8]>)> + 'a>; + fn iter<'a>(&'a self, col: Option) -> Box, Box<[u8]>)> + 'a>; /// Iterate over flushed data for a given column, starting from a given prefix. fn iter_from_prefix<'a>( diff --git a/parity-bytes/src/lib.rs b/parity-bytes/src/lib.rs index 648304670..292a6e160 100644 --- a/parity-bytes/src/lib.rs +++ b/parity-bytes/src/lib.rs @@ -86,12 +86,7 @@ impl<'a> BytesRef<'a> { match *self { BytesRef::Flexible(ref mut data) => { let data_len = data.len(); - let wrote = input.len() - + if data_len > offset { - 0 - } else { - offset - data_len - }; + let wrote = input.len() + if data_len > offset { 0 } else { offset - data_len }; data.resize(offset, 0); data.extend_from_slice(input); diff --git a/parity-crypto/benches/bench.rs b/parity-crypto/benches/bench.rs index 370a37e94..c33ba9bbf 100644 --- a/parity-crypto/benches/bench.rs +++ b/parity-crypto/benches/bench.rs @@ -44,11 +44,9 @@ fn input_len(c: &mut Criterion) { let iv = [0; 16]; b.iter(|| { - parity_crypto::aes::encrypt_128_ctr(&k[..], &iv[..], &data[..], &mut dest[..]) - .unwrap(); + parity_crypto::aes::encrypt_128_ctr(&k[..], &iv[..], &data[..], &mut dest[..]).unwrap(); // same as encrypt but add it just in case - parity_crypto::aes::decrypt_128_ctr(&k[..], &iv[..], &data[..], &mut dest[..]) - .unwrap(); + parity_crypto::aes::decrypt_128_ctr(&k[..], &iv[..], &data[..], &mut dest[..]).unwrap(); }); }, vec![100, 500, 1_000, 10_000, 100_000], diff --git a/parity-crypto/src/aes.rs b/parity-crypto/src/aes.rs index 3a2eb3fa8..bef5ef832 100644 --- a/parity-crypto/src/aes.rs +++ b/parity-crypto/src/aes.rs @@ -81,14 +81,8 @@ impl AesCtr256 { /// Key (`k`) length and initialisation vector (`iv`) length have to be 16 bytes each. /// An error is returned if the input lengths are invalid. /// If possible prefer `inplace_encrypt_128_ctr` to avoid a slice copy. -pub fn encrypt_128_ctr( - k: &[u8], - iv: &[u8], - plain: &[u8], - dest: &mut [u8], -) -> Result<(), SymmError> { - let mut encryptor = - aes_ctr::Aes128Ctr::new(GenericArray::from_slice(k), GenericArray::from_slice(iv)); +pub fn encrypt_128_ctr(k: &[u8], iv: &[u8], plain: &[u8], dest: &mut [u8]) -> Result<(), SymmError> { + let mut encryptor = aes_ctr::Aes128Ctr::new(GenericArray::from_slice(k), GenericArray::from_slice(iv)); &mut dest[..plain.len()].copy_from_slice(plain); encryptor.try_apply_keystream(dest)?; Ok(()) @@ -99,8 +93,7 @@ pub fn encrypt_128_ctr( /// Key (`k`) length and initialisation vector (`iv`) length have to be 16 bytes each. /// An error is returned if the input lengths are invalid. pub fn inplace_encrypt_128_ctr(k: &[u8], iv: &[u8], data: &mut [u8]) -> Result<(), SymmError> { - let mut encryptor = - aes_ctr::Aes128Ctr::new(GenericArray::from_slice(k), GenericArray::from_slice(iv)); + let mut encryptor = aes_ctr::Aes128Ctr::new(GenericArray::from_slice(k), GenericArray::from_slice(iv)); encryptor.try_apply_keystream(data)?; Ok(()) } @@ -110,14 +103,8 @@ pub fn inplace_encrypt_128_ctr(k: &[u8], iv: &[u8], data: &mut [u8]) -> Result<( /// Key (`k`) length and initialisation vector (`iv`) length have to be 16 bytes each. /// An error is returned if the input lengths are invalid. /// If possible prefer `inplace_decrypt_128_ctr` instead. -pub fn decrypt_128_ctr( - k: &[u8], - iv: &[u8], - encrypted: &[u8], - dest: &mut [u8], -) -> Result<(), SymmError> { - let mut encryptor = - aes_ctr::Aes128Ctr::new(GenericArray::from_slice(k), GenericArray::from_slice(iv)); +pub fn decrypt_128_ctr(k: &[u8], iv: &[u8], encrypted: &[u8], dest: &mut [u8]) -> Result<(), SymmError> { + let mut encryptor = aes_ctr::Aes128Ctr::new(GenericArray::from_slice(k), GenericArray::from_slice(iv)); &mut dest[..encrypted.len()].copy_from_slice(encrypted); encryptor.try_apply_keystream(dest)?; @@ -129,8 +116,7 @@ pub fn decrypt_128_ctr( /// Key (`k`) length and initialisation vector (`iv`) length have to be 16 bytes each. /// An error is returned if the input lengths are invalid. pub fn inplace_decrypt_128_ctr(k: &[u8], iv: &[u8], data: &mut [u8]) -> Result<(), SymmError> { - let mut encryptor = - aes_ctr::Aes128Ctr::new(GenericArray::from_slice(k), GenericArray::from_slice(iv)); + let mut encryptor = aes_ctr::Aes128Ctr::new(GenericArray::from_slice(k), GenericArray::from_slice(iv)); encryptor.try_apply_keystream(data)?; Ok(()) @@ -140,12 +126,7 @@ pub fn inplace_decrypt_128_ctr(k: &[u8], iv: &[u8], data: &mut [u8]) -> Result<( /// /// Key (`k`) length and initialisation vector (`iv`) length have to be 16 bytes each. /// An error is returned if the input lengths are invalid. -pub fn decrypt_128_cbc( - k: &[u8], - iv: &[u8], - encrypted: &[u8], - dest: &mut [u8], -) -> Result { +pub fn decrypt_128_cbc(k: &[u8], iv: &[u8], encrypted: &[u8], dest: &mut [u8]) -> Result { let encryptor = Cbc::::new_var(k, iv)?; &mut dest[..encrypted.len()].copy_from_slice(encrypted); let unpad_length = { encryptor.decrypt(&mut dest[..encrypted.len()])?.len() }; @@ -158,12 +139,7 @@ mod tests { use super::*; // only use for test could be expose in the future - fn encrypt_128_cbc( - k: &[u8], - iv: &[u8], - plain: &[u8], - dest: &mut [u8], - ) -> Result<(), SymmError> { + fn encrypt_128_cbc(k: &[u8], iv: &[u8], plain: &[u8], dest: &mut [u8]) -> Result<(), SymmError> { let encryptor = Cbc::::new_var(k, iv)?; &mut dest[..plain.len()].copy_from_slice(plain); encryptor.encrypt(dest, plain.len())?; @@ -173,37 +149,33 @@ mod tests { #[test] pub fn test_aes_short() -> Result<(), SymmError> { let key = [ - 97, 110, 121, 99, 111, 110, 116, 101, 110, 116, 116, 111, 114, 101, 97, 99, 104, 49, - 50, 56, 98, 105, 116, 115, 105, 122, 101, 10, + 97, 110, 121, 99, 111, 110, 116, 101, 110, 116, 116, 111, 114, 101, 97, 99, 104, 49, 50, 56, 98, 105, 116, + 115, 105, 122, 101, 10, ]; let salt = [ - 109, 121, 115, 97, 108, 116, 115, 104, 111, 117, 108, 100, 102, 105, 108, 108, 115, - 111, 109, 109, 101, 98, 121, 116, 101, 108, 101, 110, 103, 116, 104, 10, + 109, 121, 115, 97, 108, 116, 115, 104, 111, 117, 108, 100, 102, 105, 108, 108, 115, 111, 109, 109, 101, 98, + 121, 116, 101, 108, 101, 110, 103, 116, 104, 10, ]; let content = [ - 83, 111, 109, 101, 32, 99, 111, 110, 116, 101, 110, 116, 32, 116, 111, 32, 116, 101, - 115, 116, 32, 97, 101, 115, 44, 10, 110, 111, 116, 32, 116, 111, 32, 109, 117, 99, 104, - 32, 44, 32, 111, 110, 108, 121, 32, 118, 101, 114, 121, 32, 98, 97, 115, 105, 99, 32, - 116, 101, 115, 116, 32, 116, 111, 32, 97, 118, 111, 105, 100, 32, 111, 98, 118, 105, - 111, 117, 115, 32, 114, 101, 103, 114, 101, 115, 115, 105, 111, 110, 32, 119, 104, 101, - 110, 32, 115, 119, 105, 116, 99, 104, 105, 110, 103, 32, 108, 105, 98, 115, 46, 10, + 83, 111, 109, 101, 32, 99, 111, 110, 116, 101, 110, 116, 32, 116, 111, 32, 116, 101, 115, 116, 32, 97, 101, + 115, 44, 10, 110, 111, 116, 32, 116, 111, 32, 109, 117, 99, 104, 32, 44, 32, 111, 110, 108, 121, 32, 118, + 101, 114, 121, 32, 98, 97, 115, 105, 99, 32, 116, 101, 115, 116, 32, 116, 111, 32, 97, 118, 111, 105, 100, + 32, 111, 98, 118, 105, 111, 117, 115, 32, 114, 101, 103, 114, 101, 115, 115, 105, 111, 110, 32, 119, 104, + 101, 110, 32, 115, 119, 105, 116, 99, 104, 105, 110, 103, 32, 108, 105, 98, 115, 46, 10, ]; let ctr_enc = [ - 65, 55, 246, 75, 24, 117, 30, 233, 218, 139, 91, 251, 251, 179, 171, 69, 60, 244, 249, - 44, 238, 60, 10, 66, 71, 10, 199, 111, 54, 24, 124, 223, 153, 250, 159, 154, 164, 109, - 232, 82, 20, 199, 182, 40, 174, 104, 64, 203, 236, 94, 222, 184, 117, 54, 234, 189, - 253, 122, 135, 121, 100, 44, 227, 241, 123, 120, 110, 188, 109, 148, 112, 160, 131, - 205, 116, 104, 232, 8, 22, 170, 80, 231, 155, 246, 255, 115, 101, 5, 234, 104, 220, - 199, 192, 166, 181, 156, 113, 255, 187, 51, 38, 128, 75, 29, 237, 178, 205, 98, 101, - 110, + 65, 55, 246, 75, 24, 117, 30, 233, 218, 139, 91, 251, 251, 179, 171, 69, 60, 244, 249, 44, 238, 60, 10, 66, + 71, 10, 199, 111, 54, 24, 124, 223, 153, 250, 159, 154, 164, 109, 232, 82, 20, 199, 182, 40, 174, 104, 64, + 203, 236, 94, 222, 184, 117, 54, 234, 189, 253, 122, 135, 121, 100, 44, 227, 241, 123, 120, 110, 188, 109, + 148, 112, 160, 131, 205, 116, 104, 232, 8, 22, 170, 80, 231, 155, 246, 255, 115, 101, 5, 234, 104, 220, + 199, 192, 166, 181, 156, 113, 255, 187, 51, 38, 128, 75, 29, 237, 178, 205, 98, 101, 110, ]; let cbc_enc = [ - 167, 248, 5, 90, 11, 140, 215, 138, 165, 125, 137, 76, 47, 243, 191, 48, 183, 247, 109, - 86, 24, 45, 81, 215, 0, 51, 221, 185, 131, 97, 234, 189, 244, 255, 107, 210, 70, 60, - 41, 221, 43, 137, 185, 166, 42, 65, 18, 200, 151, 233, 255, 192, 109, 25, 105, 115, - 161, 209, 126, 235, 99, 192, 241, 241, 19, 249, 87, 244, 28, 146, 186, 189, 108, 9, - 243, 132, 4, 105, 53, 162, 8, 235, 84, 107, 213, 59, 158, 113, 227, 120, 162, 50, 237, - 123, 70, 187, 83, 73, 146, 13, 44, 191, 53, 4, 125, 207, 176, 45, 8, 153, 175, 198, + 167, 248, 5, 90, 11, 140, 215, 138, 165, 125, 137, 76, 47, 243, 191, 48, 183, 247, 109, 86, 24, 45, 81, + 215, 0, 51, 221, 185, 131, 97, 234, 189, 244, 255, 107, 210, 70, 60, 41, 221, 43, 137, 185, 166, 42, 65, + 18, 200, 151, 233, 255, 192, 109, 25, 105, 115, 161, 209, 126, 235, 99, 192, 241, 241, 19, 249, 87, 244, + 28, 146, 186, 189, 108, 9, 243, 132, 4, 105, 53, 162, 8, 235, 84, 107, 213, 59, 158, 113, 227, 120, 162, + 50, 237, 123, 70, 187, 83, 73, 146, 13, 44, 191, 53, 4, 125, 207, 176, 45, 8, 153, 175, 198, ]; let mut dest = vec![0; 110]; let mut dest_padded = vec![0; 112]; diff --git a/parity-crypto/src/digest.rs b/parity-crypto/src/digest.rs index e6fda3796..caf57dd0c 100644 --- a/parity-crypto/src/digest.rs +++ b/parity-crypto/src/digest.rs @@ -94,10 +94,7 @@ impl Hasher { impl Hasher { pub fn ripemd160() -> Hasher { - Hasher( - Inner::Ripemd160(ripemd160::Ripemd160::default()), - PhantomData, - ) + Hasher(Inner::Ripemd160(ripemd160::Ripemd160::default()), PhantomData) } } diff --git a/parity-crypto/src/error.rs b/parity-crypto/src/error.rs index ffcf5ca29..16d67f504 100644 --- a/parity-crypto/src/error.rs +++ b/parity-crypto/src/error.rs @@ -96,9 +96,7 @@ impl fmt::Display for SymmError { match self { SymmError(PrivSymmErr::BlockMode(err)) => write!(f, "block cipher error: {}", err), SymmError(PrivSymmErr::KeyStream(err)) => write!(f, "ctr key stream ended: {}", err), - SymmError(PrivSymmErr::InvalidKeyLength(err)) => { - write!(f, "block cipher key length: {}", err) - } + SymmError(PrivSymmErr::InvalidKeyLength(err)) => write!(f, "block cipher key length: {}", err), } } } diff --git a/parity-crypto/src/hmac/mod.rs b/parity-crypto/src/hmac/mod.rs index 95154bf08..2b082dd45 100644 --- a/parity-crypto/src/hmac/mod.rs +++ b/parity-crypto/src/hmac/mod.rs @@ -80,19 +80,13 @@ enum KeyInner { impl SigKey { pub fn sha256(key: &[u8]) -> SigKey { - SigKey( - KeyInner::Sha256(DisposableBox::from_slice(key)), - PhantomData, - ) + SigKey(KeyInner::Sha256(DisposableBox::from_slice(key)), PhantomData) } } impl SigKey { pub fn sha512(key: &[u8]) -> SigKey { - SigKey( - KeyInner::Sha512(DisposableBox::from_slice(key)), - PhantomData, - ) + SigKey(KeyInner::Sha512(DisposableBox::from_slice(key)), PhantomData) } } @@ -115,15 +109,11 @@ impl Signer { pub fn with(key: &SigKey) -> Signer { match &key.0 { KeyInner::Sha256(key_bytes) => Signer( - SignerInner::Sha256( - Hmac::::new_varkey(&key_bytes.0).expect("always returns Ok; qed"), - ), + SignerInner::Sha256(Hmac::::new_varkey(&key_bytes.0).expect("always returns Ok; qed")), PhantomData, ), KeyInner::Sha512(key_bytes) => Signer( - SignerInner::Sha512( - Hmac::::new_varkey(&key_bytes.0).expect("always returns Ok; qed"), - ), + SignerInner::Sha512(Hmac::::new_varkey(&key_bytes.0).expect("always returns Ok; qed")), PhantomData, ), } @@ -138,12 +128,8 @@ impl Signer { pub fn sign(self) -> Signature { match self.0 { - SignerInner::Sha256(hmac) => { - Signature(HashInner::Sha256(hmac.result().code()), PhantomData) - } - SignerInner::Sha512(hmac) => { - Signature(HashInner::Sha512(hmac.result().code()), PhantomData) - } + SignerInner::Sha256(hmac) => Signature(HashInner::Sha256(hmac.result().code()), PhantomData), + SignerInner::Sha512(hmac) => Signature(HashInner::Sha512(hmac.result().code()), PhantomData), } } } @@ -153,19 +139,13 @@ pub struct VerifyKey(KeyInner, PhantomData); impl VerifyKey { pub fn sha256(key: &[u8]) -> VerifyKey { - VerifyKey( - KeyInner::Sha256(DisposableBox::from_slice(key)), - PhantomData, - ) + VerifyKey(KeyInner::Sha256(DisposableBox::from_slice(key)), PhantomData) } } impl VerifyKey { pub fn sha512(key: &[u8]) -> VerifyKey { - VerifyKey( - KeyInner::Sha512(DisposableBox::from_slice(key)), - PhantomData, - ) + VerifyKey(KeyInner::Sha512(DisposableBox::from_slice(key)), PhantomData) } } @@ -173,14 +153,12 @@ impl VerifyKey { pub fn verify(key: &VerifyKey, data: &[u8], sig: &[u8]) -> bool { match &key.0 { KeyInner::Sha256(key_bytes) => { - let mut ctx = - Hmac::::new_varkey(&key_bytes.0).expect("always returns Ok; qed"); + let mut ctx = Hmac::::new_varkey(&key_bytes.0).expect("always returns Ok; qed"); ctx.input(data); ctx.verify(sig).is_ok() } KeyInner::Sha512(key_bytes) => { - let mut ctx = - Hmac::::new_varkey(&key_bytes.0).expect("always returns Ok; qed"); + let mut ctx = Hmac::::new_varkey(&key_bytes.0).expect("always returns Ok; qed"); ctx.input(data); ctx.verify(sig).is_ok() } diff --git a/parity-crypto/src/hmac/test.rs b/parity-crypto/src/hmac/test.rs index f9b91df5b..1633cf37c 100644 --- a/parity-crypto/src/hmac/test.rs +++ b/parity-crypto/src/hmac/test.rs @@ -40,18 +40,17 @@ fn simple_mac_and_verify() { assert_eq!( &sig1[..], [ - 223, 208, 90, 69, 144, 95, 145, 180, 56, 155, 78, 40, 86, 238, 205, 81, 160, 245, 88, - 145, 164, 67, 254, 180, 202, 107, 93, 249, 64, 196, 86, 225 + 223, 208, 90, 69, 144, 95, 145, 180, 56, 155, 78, 40, 86, 238, 205, 81, 160, 245, 88, 145, 164, 67, 254, + 180, 202, 107, 93, 249, 64, 196, 86, 225 ] ); let sig2 = signer2.sign(); assert_eq!( &sig2[..], &[ - 29, 63, 46, 122, 27, 5, 241, 38, 86, 197, 91, 79, 33, 107, 152, 195, 118, 221, 117, - 119, 84, 114, 46, 65, 243, 157, 105, 12, 147, 176, 190, 37, 210, 164, 152, 8, 58, 243, - 59, 206, 80, 10, 230, 197, 255, 110, 191, 180, 93, 22, 255, 0, 99, 79, 237, 229, 209, - 199, 125, 83, 15, 179, 134, 89 + 29, 63, 46, 122, 27, 5, 241, 38, 86, 197, 91, 79, 33, 107, 152, 195, 118, 221, 117, 119, 84, 114, 46, 65, + 243, 157, 105, 12, 147, 176, 190, 37, 210, 164, 152, 8, 58, 243, 59, 206, 80, 10, 230, 197, 255, 110, 191, + 180, 93, 22, 255, 0, 99, 79, 237, 229, 209, 199, 125, 83, 15, 179, 134, 89 ][..] ); assert_eq!(&sig1[..], &sign(&sig_key1, &input[..])[..]); @@ -127,14 +126,18 @@ fn ietf_test_vectors() { check_test_vector( &hex!("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), &hex!("dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"), - &hex!(" + &hex!( + " 773ea91e36800e46854db8ebd09181a7 - 2959098b3ef8c122d9635514ced565fe"), - &hex!(" + 2959098b3ef8c122d9635514ced565fe" + ), + &hex!( + " fa73b0089d56a284efb0f0756c890be9 b1b5dbdd8ee81a3655f83e33b2279d39 bf3e848279a722c806b485a47e67c807 - b946a337bee8942674278859e13292fb") + b946a337bee8942674278859e13292fb" + ), ); // Test Case 4 diff --git a/parity-crypto/src/lib.rs b/parity-crypto/src/lib.rs index 6e259a748..d1d146355 100644 --- a/parity-crypto/src/lib.rs +++ b/parity-crypto/src/lib.rs @@ -58,12 +58,7 @@ where pub fn derive_key_iterations(password: &[u8], salt: &[u8], c: u32) -> (Vec, Vec) { let mut derived_key = [0u8; KEY_LENGTH]; - pbkdf2::sha256( - c, - pbkdf2::Salt(salt), - pbkdf2::Secret(password), - &mut derived_key, - ); + pbkdf2::sha256(c, pbkdf2::Salt(salt), pbkdf2::Secret(password), &mut derived_key); let derived_right_bits = &derived_key[0..KEY_LENGTH_AES]; let derived_left_bits = &derived_key[KEY_LENGTH_AES..KEY_LENGTH]; (derived_right_bits.to_vec(), derived_left_bits.to_vec()) diff --git a/parity-crypto/src/pbkdf2/test.rs b/parity-crypto/src/pbkdf2/test.rs index 1fbd493f8..ff8cc685c 100644 --- a/parity-crypto/src/pbkdf2/test.rs +++ b/parity-crypto/src/pbkdf2/test.rs @@ -23,8 +23,8 @@ fn basic_test() { let secret = [7; 32]; sha256(3, Salt(&salt[..]), Secret(&secret[..]), &mut dest); let res = [ - 242, 33, 31, 124, 36, 223, 179, 185, 206, 175, 190, 253, 85, 33, 23, 126, 141, 29, 23, 97, - 66, 63, 51, 196, 27, 255, 135, 206, 74, 137, 172, 87, + 242, 33, 31, 124, 36, 223, 179, 185, 206, 175, 190, 253, 85, 33, 23, 126, 141, 29, 23, 97, 66, 63, 51, 196, 27, + 255, 135, 206, 74, 137, 172, 87, ]; assert_eq!(res, dest); } diff --git a/parity-crypto/src/publickey/ec_math_utils.rs b/parity-crypto/src/publickey/ec_math_utils.rs index 966867b27..1aa55db7e 100644 --- a/parity-crypto/src/publickey/ec_math_utils.rs +++ b/parity-crypto/src/publickey/ec_math_utils.rs @@ -26,11 +26,11 @@ use secp256k1::key; /// Equivalent to uncompressed form, see https://tools.ietf.org/id/draft-jivsov-ecc-compact-05.html#rfc.section.3 pub const BASE_POINT_BYTES: [u8; 65] = [ 0x4, // The X coordinate of the generator - 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, - 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, + 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b, 0xfc, + 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, // The Y coordinate of the generator - 0x48, 0x3a, 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, - 0xfd, 0x17, 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8, + 0x48, 0x3a, 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17, 0xb4, + 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8, ]; lazy_static! { @@ -39,9 +39,7 @@ lazy_static! { /// Whether the public key is valid. pub fn public_is_valid(public: &Public) -> bool { - to_secp256k1_public(public) - .ok() - .map_or(false, |p| p.is_valid()) + to_secp256k1_public(public).ok().map_or(false, |p| p.is_valid()) } /// In-place multiply public key by secret key (EC point * scalar) @@ -83,8 +81,8 @@ pub fn public_negate(public: &mut Public) -> Result<(), Error> { /// Return the generation point (aka base point) of secp256k1 pub fn generation_point() -> Public { - let public_key = key::PublicKey::from_slice(&SECP256K1, &BASE_POINT_BYTES) - .expect("constructed using constants; qed"); + let public_key = + key::PublicKey::from_slice(&SECP256K1, &BASE_POINT_BYTES).expect("constructed using constants; qed"); let mut public = Public::default(); set_public(&mut public, &public_key); public @@ -102,17 +100,13 @@ fn to_secp256k1_public(public: &Public) -> Result { fn set_public(public: &mut Public, key_public: &key::PublicKey) { let key_public_serialized = key_public.serialize_vec(&SECP256K1, false); - public - .as_bytes_mut() - .copy_from_slice(&key_public_serialized[1..65]); + public.as_bytes_mut().copy_from_slice(&key_public_serialized[1..65]); } #[cfg(test)] mod tests { use super::super::{Generator, Random, Secret}; - use super::{ - generation_point, public_add, public_is_valid, public_mul_secret, public_negate, public_sub, - }; + use super::{generation_point, public_add, public_is_valid, public_mul_secret, public_negate, public_sub}; use std::str::FromStr; #[test] @@ -166,9 +160,7 @@ mod tests { #[test] fn public_multiplication_verification() { - let secret = - Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") - .unwrap(); + let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); let mut public = generation_point(); public_mul_secret(&mut public, &secret).unwrap(); assert_eq!(format!("{:x}", public), "8ce0db0b0359ffc5866ba61903cc2518c3675ef2cf380a7e54bde7ea20e6fa1ab45b7617346cd11b7610001ee6ae5b0155c41cad9527cbcdff44ec67848943a4"); diff --git a/parity-crypto/src/publickey/ecdsa_signature.rs b/parity-crypto/src/publickey/ecdsa_signature.rs index 1d51e88d9..6801adf10 100644 --- a/parity-crypto/src/publickey/ecdsa_signature.rs +++ b/parity-crypto/src/publickey/ecdsa_signature.rs @@ -81,9 +81,8 @@ impl Signature { /// This condition may be required by some verification algorithms pub fn is_low_s(&self) -> bool { const LOW_SIG_THRESHOLD: H256 = H256([ - 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0x5D, 0x57, 0x6E, 0x73, 0x57, 0xA4, 0x50, 0x1D, 0xDF, 0xE9, 0x2F, 0x46, - 0x68, 0x1B, 0x20, 0xA0, + 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x5D, 0x57, + 0x6E, 0x73, 0x57, 0xA4, 0x50, 0x1D, 0xDF, 0xE9, 0x2F, 0x46, 0x68, 0x1B, 0x20, 0xA0, ]); H256::from_slice(self.s()) <= LOW_SIG_THRESHOLD } @@ -96,14 +95,12 @@ impl Signature { /// used here as the upper bound for a valid (r, s, v) tuple pub fn is_valid(&self) -> bool { const UPPER_BOUND: H256 = H256([ - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, - 0xd0, 0x36, 0x41, 0x41, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, + 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41, ]); const ONE: H256 = H256([ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, ]); let r = H256::from_slice(self.r()); let s = H256::from_slice(self.s()); @@ -226,17 +223,10 @@ pub fn sign(secret: &Secret, message: &Message) -> Result { } /// Performs verification of the signature for the given message with corresponding public key -pub fn verify_public( - public: &Public, - signature: &Signature, - message: &Message, -) -> Result { +pub fn verify_public(public: &Public, signature: &Signature, message: &Message) -> Result { let context = &SECP256K1; - let rsig = RecoverableSignature::from_compact( - context, - &signature[0..64], - RecoveryId::from_i32(signature[64] as i32)?, - )?; + let rsig = + RecoverableSignature::from_compact(context, &signature[0..64], RecoveryId::from_i32(signature[64] as i32)?)?; let sig = rsig.to_standard(context); let pdata: [u8; 65] = { @@ -254,11 +244,7 @@ pub fn verify_public( } /// Checks if the address corresponds to the public key from the signature for the message -pub fn verify_address( - address: &Address, - signature: &Signature, - message: &Message, -) -> Result { +pub fn verify_address(address: &Address, signature: &Signature, message: &Message) -> Result { let public = recover(signature, message)?; let recovered_address = public_to_address(&public); Ok(address == &recovered_address) @@ -267,11 +253,8 @@ pub fn verify_address( /// Recovers the public key from the signature for the message pub fn recover(signature: &Signature, message: &Message) -> Result { let context = &SECP256K1; - let rsig = RecoverableSignature::from_compact( - context, - &signature[0..64], - RecoveryId::from_i32(signature[64] as i32)?, - )?; + let rsig = + RecoverableSignature::from_compact(context, &signature[0..64], RecoveryId::from_i32(signature[64] as i32)?)?; let pubkey = context.recover(&SecpMessage::from_slice(&message[..])?, &rsig)?; let serialized = pubkey.serialize_vec(context, false); diff --git a/parity-crypto/src/publickey/ecies.rs b/parity-crypto/src/publickey/ecies.rs index 2725e9f72..7b963c138 100644 --- a/parity-crypto/src/publickey/ecies.rs +++ b/parity-crypto/src/publickey/ecies.rs @@ -105,12 +105,7 @@ fn kdf(secret: &Secret, s1: &[u8], dest: &mut [u8]) { let mut written = 0usize; while written < dest.len() { let mut hasher = digest::Hasher::sha256(); - let ctrs = [ - (ctr >> 24) as u8, - (ctr >> 16) as u8, - (ctr >> 8) as u8, - ctr as u8, - ]; + let ctrs = [(ctr >> 24) as u8, (ctr >> 16) as u8, (ctr >> 8) as u8, ctr as u8]; hasher.update(&ctrs); hasher.update(secret.as_bytes()); hasher.update(s1); diff --git a/parity-crypto/src/publickey/extended_keys.rs b/parity-crypto/src/publickey/extended_keys.rs index 6ec293541..e0e31d847 100644 --- a/parity-crypto/src/publickey/extended_keys.rs +++ b/parity-crypto/src/publickey/extended_keys.rs @@ -107,8 +107,7 @@ impl ExtendedSecret { where T: Label, { - let (derived_key, next_chain_code) = - derivation::private(*self.secret, self.chain_code, index); + let (derived_key, next_chain_code) = derivation::private(*self.secret, self.chain_code, index); let derived_secret = Secret::from(derived_key.0); @@ -150,8 +149,7 @@ impl ExtendedPublic { where T: Label, { - let (derived_key, next_chain_code) = - derivation::public(self.public, self.chain_code, index)?; + let (derived_key, next_chain_code) = derivation::public(self.public, self.chain_code, index)?; Ok(ExtendedPublic::new(derived_key, next_chain_code)) } @@ -168,8 +166,8 @@ pub struct ExtendedKeyPair { impl ExtendedKeyPair { pub fn new(secret: Secret) -> Self { let extended_secret = ExtendedSecret::new(secret); - let extended_public = ExtendedPublic::from_secret(&extended_secret) - .expect("Valid `Secret` always produces valid public; qed"); + let extended_public = + ExtendedPublic::from_secret(&extended_secret).expect("Valid `Secret` always produces valid public; qed"); ExtendedKeyPair { secret: extended_secret, public: extended_public, @@ -185,8 +183,8 @@ impl ExtendedKeyPair { pub fn with_secret(secret: Secret, chain_code: H256) -> Self { let extended_secret = ExtendedSecret::with_code(secret, chain_code); - let extended_public = ExtendedPublic::from_secret(&extended_secret) - .expect("Valid `Secret` always produces valid public; qed"); + let extended_public = + ExtendedPublic::from_secret(&extended_secret).expect("Valid `Secret` always produces valid public; qed"); ExtendedKeyPair { secret: extended_secret, public: extended_public, @@ -282,10 +280,10 @@ mod derivation { { let mut data = vec![0u8; 33 + T::len()]; - let sec_private = SecretKey::from_slice(&SECP256K1, private_key.as_bytes()) - .expect("Caller should provide valid private key"); - let sec_public = PublicKey::from_secret_key(&SECP256K1, &sec_private) - .expect("Caller should provide valid private key"); + let sec_private = + SecretKey::from_slice(&SECP256K1, private_key.as_bytes()).expect("Caller should provide valid private key"); + let sec_public = + PublicKey::from_secret_key(&SECP256K1, &sec_private).expect("Caller should provide valid private key"); let public_serialized = sec_public.serialize_vec(&SECP256K1, true); // curve point (compressed public key) -- index @@ -322,15 +320,10 @@ mod derivation { // todo: surely can be optimized fn modulo(u1: U512, u2: U256) -> U256 { let m = u1 % U512::from(u2); - m.try_into() - .expect("U512 modulo U256 should fit into U256; qed") + m.try_into().expect("U512 modulo U256 should fit into U256; qed") } - pub fn public( - public_key: H512, - chain_code: H256, - derivation: Derivation, - ) -> Result<(H512, H256), Error> + pub fn public(public_key: H512, chain_code: H256, derivation: Derivation) -> Result<(H512, H256), Error> where T: Label, { @@ -344,8 +337,7 @@ mod derivation { let mut public_sec_raw = [0u8; 65]; public_sec_raw[0] = 4; public_sec_raw[1..65].copy_from_slice(public_key.as_bytes()); - let public_sec = - PublicKey::from_slice(&SECP256K1, &public_sec_raw).map_err(|_| Error::InvalidPoint)?; + let public_sec = PublicKey::from_slice(&SECP256K1, &public_sec_raw).map_err(|_| Error::InvalidPoint)?; let public_serialized = public_sec.serialize_vec(&SECP256K1, true); let mut data = vec![0u8; 33 + T::len()]; @@ -365,8 +357,9 @@ mod derivation { if *CURVE_ORDER <= new_private.into_uint() { return Err(Error::MissingIndex); } - let new_private_sec = SecretKey::from_slice(&SECP256K1, new_private.as_bytes()) - .expect("Private key belongs to the field [0..CURVE_ORDER) (checked above); So initializing can never fail; qed"); + let new_private_sec = SecretKey::from_slice(&SECP256K1, new_private.as_bytes()).expect( + "Private key belongs to the field [0..CURVE_ORDER) (checked above); So initializing can never fail; qed", + ); let mut new_public = PublicKey::from_secret_key(&SECP256K1, &new_private_sec) .expect("Valid private key produces valid public key"); @@ -394,10 +387,8 @@ mod derivation { } pub fn point(secret: H256) -> Result { - let sec = SecretKey::from_slice(&SECP256K1, secret.as_bytes()) - .map_err(|_| Error::InvalidPoint)?; - let public_sec = - PublicKey::from_secret_key(&SECP256K1, &sec).map_err(|_| Error::InvalidPoint)?; + let sec = SecretKey::from_slice(&SECP256K1, secret.as_bytes()).map_err(|_| Error::InvalidPoint)?; + let public_sec = PublicKey::from_secret_key(&SECP256K1, &sec).map_err(|_| Error::InvalidPoint)?; let serialized = public_sec.serialize_vec(&SECP256K1, false); Ok(H512::from_slice(&serialized[1..65])) } @@ -442,43 +433,35 @@ mod tests { #[test] fn smoky() { - let secret = - Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") - .unwrap(); + let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::zero()); // hardened assert_eq!(&**extended_secret.as_raw(), &*secret); assert_eq!( **extended_secret.derive(2147483648.into()).as_raw(), - H256::from_str("0927453daed47839608e414a3738dfad10aed17c459bbd9ab53f89b026c834b6") - .unwrap(), + H256::from_str("0927453daed47839608e414a3738dfad10aed17c459bbd9ab53f89b026c834b6").unwrap(), ); assert_eq!( **extended_secret.derive(2147483649.into()).as_raw(), - H256::from_str("44238b6a29c6dcbe9b401364141ba11e2198c289a5fed243a1c11af35c19dc0f") - .unwrap(), + H256::from_str("44238b6a29c6dcbe9b401364141ba11e2198c289a5fed243a1c11af35c19dc0f").unwrap(), ); // normal assert_eq!( **extended_secret.derive(0.into()).as_raw(), - H256::from_str("bf6a74e3f7b36fc4c96a1e12f31abc817f9f5904f5a8fc27713163d1f0b713f6") - .unwrap() + H256::from_str("bf6a74e3f7b36fc4c96a1e12f31abc817f9f5904f5a8fc27713163d1f0b713f6").unwrap() ); assert_eq!( **extended_secret.derive(1.into()).as_raw(), - H256::from_str("bd4fca9eb1f9c201e9448c1eecd66e302d68d4d313ce895b8c134f512205c1bc") - .unwrap() + H256::from_str("bd4fca9eb1f9c201e9448c1eecd66e302d68d4d313ce895b8c134f512205c1bc").unwrap() ); assert_eq!( **extended_secret.derive(2.into()).as_raw(), - H256::from_str("86932b542d6cab4d9c65490c7ef502d89ecc0e2a5f4852157649e3251e2a3268") - .unwrap() + H256::from_str("86932b542d6cab4d9c65490c7ef502d89ecc0e2a5f4852157649e3251e2a3268").unwrap() ); - let extended_public = ExtendedPublic::from_secret(&extended_secret) - .expect("Extended public should be created"); + let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); let derived_public = extended_public .derive(0.into()) .expect("First derivation of public should succeed"); @@ -488,8 +471,7 @@ mod tests { ); let keypair = ExtendedKeyPair::with_secret( - Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") - .unwrap(), + Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(), H256::from_low_u64_be(64), ); assert_eq!( @@ -498,70 +480,56 @@ mod tests { .expect("Derivation of keypair should succeed") .secret() .as_raw(), - H256::from_str("edef54414c03196557cf73774bc97a645c9a1df2164ed34f0c2a78d1375a930c") - .unwrap(), + H256::from_str("edef54414c03196557cf73774bc97a645c9a1df2164ed34f0c2a78d1375a930c").unwrap(), ); } #[test] fn h256_soft_match() { - let secret = - Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") - .unwrap(); + let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); let derivation_secret = - H256::from_str("51eaf04f9dbbc1417dc97e789edd0c37ecda88bac490434e367ea81b71b7b015") - .unwrap(); + H256::from_str("51eaf04f9dbbc1417dc97e789edd0c37ecda88bac490434e367ea81b71b7b015").unwrap(); let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::zero()); - let extended_public = ExtendedPublic::from_secret(&extended_secret) - .expect("Extended public should be created"); + let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); let derived_secret0 = extended_secret.derive(Derivation::Soft(derivation_secret)); let derived_public0 = extended_public .derive(Derivation::Soft(derivation_secret)) .expect("First derivation of public should succeed"); - let public_from_secret0 = ExtendedPublic::from_secret(&derived_secret0) - .expect("Extended public should be created"); + let public_from_secret0 = + ExtendedPublic::from_secret(&derived_secret0).expect("Extended public should be created"); assert_eq!(public_from_secret0.public(), derived_public0.public()); } #[test] fn h256_hard() { - let secret = - Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") - .unwrap(); + let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); let derivation_secret = - H256::from_str("51eaf04f9dbbc1417dc97e789edd0c37ecda88bac490434e367ea81b71b7b015") - .unwrap(); + H256::from_str("51eaf04f9dbbc1417dc97e789edd0c37ecda88bac490434e367ea81b71b7b015").unwrap(); let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::from_low_u64_be(1)); assert_eq!( - **extended_secret - .derive(Derivation::Hard(derivation_secret)) - .as_raw(), - H256::from_str("2bc2d696fb744d77ff813b4a1ef0ad64e1e5188b622c54ba917acc5ebc7c5486") - .unwrap(), + **extended_secret.derive(Derivation::Hard(derivation_secret)).as_raw(), + H256::from_str("2bc2d696fb744d77ff813b4a1ef0ad64e1e5188b622c54ba917acc5ebc7c5486").unwrap(), ); } #[test] fn match_() { - let secret = - Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") - .unwrap(); + let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::from_low_u64_be(1)); - let extended_public = ExtendedPublic::from_secret(&extended_secret) - .expect("Extended public should be created"); + let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); let derived_secret0 = extended_secret.derive(0.into()); let derived_public0 = extended_public .derive(0.into()) .expect("First derivation of public should succeed"); - let public_from_secret0 = ExtendedPublic::from_secret(&derived_secret0) - .expect("Extended public should be created"); + let public_from_secret0 = + ExtendedPublic::from_secret(&derived_secret0).expect("Extended public should be created"); assert_eq!(public_from_secret0.public(), derived_public0.public()); } @@ -575,9 +543,8 @@ mod tests { // private key from bitcoin test vector // xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs - let test_private = - H256::from_str("e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35") - .expect("Private should be decoded ok"); + let test_private = H256::from_str("e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35") + .expect("Private should be decoded ok"); let (private_seed, _) = derivation::seed_pair(&*seed); diff --git a/parity-crypto/src/publickey/keypair.rs b/parity-crypto/src/publickey/keypair.rs index 94e414dce..c0403aa39 100644 --- a/parity-crypto/src/publickey/keypair.rs +++ b/parity-crypto/src/publickey/keypair.rs @@ -102,9 +102,7 @@ mod tests { #[test] fn from_secret() { - let secret = - Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") - .unwrap(); + let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); let _ = KeyPair::from_secret(secret).unwrap(); } @@ -114,9 +112,7 @@ mod tests { "secret: a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65 public: 8ce0db0b0359ffc5866ba61903cc2518c3675ef2cf380a7e54bde7ea20e6fa1ab45b7617346cd11b7610001ee6ae5b0155c41cad9527cbcdff44ec67848943a4 address: 5b073e9233944b5e729e46d618f0d8edf3d9c34a".to_owned(); - let secret = - Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65") - .unwrap(); + let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); let kp = KeyPair::from_secret(secret).unwrap(); assert_eq!(format!("{}", kp), expected); } diff --git a/parity-crypto/src/publickey/mod.rs b/parity-crypto/src/publickey/mod.rs index 97679356b..12b07d176 100644 --- a/parity-crypto/src/publickey/mod.rs +++ b/parity-crypto/src/publickey/mod.rs @@ -31,9 +31,7 @@ pub mod error; pub use self::ec_math_utils::public_is_valid; pub use self::ecdsa_signature::{recover, sign, verify_address, verify_public, Signature}; pub use self::error::Error; -pub use self::extended_keys::{ - Derivation, DerivationError, ExtendedKeyPair, ExtendedPublic, ExtendedSecret, -}; +pub use self::extended_keys::{Derivation, DerivationError, ExtendedKeyPair, ExtendedPublic, ExtendedSecret}; pub use self::keypair::{public_to_address, KeyPair}; pub use self::keypair_generator::Random; pub use self::secret_key::Secret; diff --git a/parity-crypto/src/publickey/secret_key.rs b/parity-crypto/src/publickey/secret_key.rs index 9864ab6ef..e5dfa43ed 100644 --- a/parity-crypto/src/publickey/secret_key.rs +++ b/parity-crypto/src/publickey/secret_key.rs @@ -73,9 +73,7 @@ impl Secret { /// Creates zero key, which is invalid for crypto operations, but valid for math operation. pub fn zero() -> Self { - Secret { - inner: H256::zero(), - } + Secret { inner: H256::zero() } } /// Imports and validates the key. @@ -221,9 +219,7 @@ impl Secret { impl FromStr for Secret { type Err = Error; fn from_str(s: &str) -> Result { - Ok(H256::from_str(s) - .map_err(|e| Error::Custom(format!("{:?}", e)))? - .into()) + Ok(H256::from_str(s).map_err(|e| Error::Custom(format!("{:?}", e)))?.into()) } } @@ -277,8 +273,7 @@ mod tests { inversion.mul(&secret).unwrap(); assert_eq!( inversion, - Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001") - .unwrap() + Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap() ); } @@ -299,8 +294,7 @@ mod tests { pow0.pow(0).unwrap(); assert_eq!( pow0, - Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001") - .unwrap() + Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap() ); let mut pow1 = secret.clone(); diff --git a/parity-crypto/src/scrypt.rs b/parity-crypto/src/scrypt.rs index a44464b52..add19a3ea 100644 --- a/parity-crypto/src/scrypt.rs +++ b/parity-crypto/src/scrypt.rs @@ -21,13 +21,7 @@ use scrypt::{scrypt, ScryptParams}; #[cfg(test)] use std::io::Error; -pub fn derive_key( - pass: &[u8], - salt: &[u8], - n: u32, - p: u32, - r: u32, -) -> Result<(Vec, Vec), ScryptError> { +pub fn derive_key(pass: &[u8], salt: &[u8], n: u32, p: u32, r: u32) -> Result<(Vec, Vec), ScryptError> { // sanity checks let log_n = (32 - n.leading_zeros() - 1) as u8; if log_n as u32 >= r * 16 { @@ -52,18 +46,12 @@ pub fn derive_key( pub fn test_derive() -> Result<(), Error> { let pass = [109, 121, 112, 97, 115, 115, 10]; let salt = [ - 109, 121, 115, 97, 108, 116, 115, 104, 111, 117, 108, 100, 102, 105, 108, 108, 115, 111, - 109, 109, 101, 98, 121, 116, 101, 108, 101, 110, 103, 116, 104, 10, - ]; - let r1 = [ - 93, 134, 79, 68, 223, 27, 44, 174, 236, 184, 179, 203, 74, 139, 73, 66, - ]; - let r2 = [ - 2, 24, 239, 131, 172, 164, 18, 171, 132, 207, 22, 217, 150, 20, 203, 37, - ]; - let l1 = [ - 6, 90, 119, 45, 67, 2, 99, 151, 81, 88, 166, 210, 244, 19, 123, 208, + 109, 121, 115, 97, 108, 116, 115, 104, 111, 117, 108, 100, 102, 105, 108, 108, 115, 111, 109, 109, 101, 98, + 121, 116, 101, 108, 101, 110, 103, 116, 104, 10, ]; + let r1 = [93, 134, 79, 68, 223, 27, 44, 174, 236, 184, 179, 203, 74, 139, 73, 66]; + let r2 = [2, 24, 239, 131, 172, 164, 18, 171, 132, 207, 22, 217, 150, 20, 203, 37]; + let l1 = [6, 90, 119, 45, 67, 2, 99, 151, 81, 88, 166, 210, 244, 19, 123, 208]; let l2 = [ 253, 123, 132, 12, 188, 89, 196, 2, 107, 224, 239, 231, 135, 177, 125, 62, ]; diff --git a/parity-path/src/lib.rs b/parity-path/src/lib.rs index 0fda82610..c286678ba 100644 --- a/parity-path/src/lib.rs +++ b/parity-path/src/lib.rs @@ -91,24 +91,15 @@ pub mod ethereum { /// Restricts the permissions of given path only to the owner. #[cfg(unix)] -pub fn restrict_permissions_owner( - file_path: &Path, - write: bool, - executable: bool, -) -> Result<(), String> { - let perms = ::std::os::unix::fs::PermissionsExt::from_mode( - 0o400 + write as u32 * 0o200 + executable as u32 * 0o100, - ); +pub fn restrict_permissions_owner(file_path: &Path, write: bool, executable: bool) -> Result<(), String> { + let perms = + ::std::os::unix::fs::PermissionsExt::from_mode(0o400 + write as u32 * 0o200 + executable as u32 * 0o100); ::std::fs::set_permissions(file_path, perms).map_err(|e| format!("{:?}", e)) } /// Restricts the permissions of given path only to the owner. #[cfg(not(unix))] -pub fn restrict_permissions_owner( - _file_path: &Path, - _write: bool, - _executable: bool, -) -> Result<(), String> { +pub fn restrict_permissions_owner(_file_path: &Path, _write: bool, _executable: bool) -> Result<(), String> { //TODO: implement me Ok(()) } diff --git a/parity-util-mem/src/impls.rs b/parity-util-mem/src/impls.rs index 155f37aa4..ca36ce193 100644 --- a/parity-util-mem/src/impls.rs +++ b/parity-util-mem/src/impls.rs @@ -21,9 +21,8 @@ use super::{MallocSizeOf, MallocSizeOfOps}; use elastic_array::{ - ElasticArray1024, ElasticArray128, ElasticArray16, ElasticArray2, ElasticArray2048, - ElasticArray256, ElasticArray32, ElasticArray36, ElasticArray4, ElasticArray512, - ElasticArray64, ElasticArray8, + ElasticArray1024, ElasticArray128, ElasticArray16, ElasticArray2, ElasticArray2048, ElasticArray256, + ElasticArray32, ElasticArray36, ElasticArray4, ElasticArray512, ElasticArray64, ElasticArray8, }; use ethereum_types::{Bloom, H128, H160, H256, H264, H32, H512, H520, H64, U128, U256, U512, U64}; use parking_lot::{Mutex, RwLock}; diff --git a/parity-util-mem/src/malloc_size.rs b/parity-util-mem/src/malloc_size.rs index eedf5fc2a..da0b8ae4b 100644 --- a/parity-util-mem/src/malloc_size.rs +++ b/parity-util-mem/src/malloc_size.rs @@ -149,10 +149,7 @@ impl MallocSizeOfOps { /// Call `have_seen_ptr_op` on `ptr`. pub fn have_seen_ptr(&mut self, ptr: *const T) -> bool { - let have_seen_ptr_op = self - .have_seen_ptr_op - .as_mut() - .expect("missing have_seen_ptr_op"); + let have_seen_ptr_op = self.have_seen_ptr_op.as_mut().expect("missing have_seen_ptr_op"); have_seen_ptr_op(ptr as *const c_void) } } diff --git a/parity-util-mem/src/sizeof.rs b/parity-util-mem/src/sizeof.rs index 9a1ffec41..ef63e1000 100644 --- a/parity-util-mem/src/sizeof.rs +++ b/parity-util-mem/src/sizeof.rs @@ -17,9 +17,7 @@ //! Estimation for heapsize calculation. Usable to replace call to allocator method (for some //! allocators or simply because we just need a deterministic cunsumption measurement). -use crate::malloc_size::{ - MallocShallowSizeOf, MallocSizeOf, MallocSizeOfOps, MallocUnconditionalShallowSizeOf, -}; +use crate::malloc_size::{MallocShallowSizeOf, MallocSizeOf, MallocSizeOfOps, MallocUnconditionalShallowSizeOf}; #[cfg(not(feature = "std"))] use alloc::boxed::Box; #[cfg(not(feature = "std"))] diff --git a/primitive-types/impls/codec/src/lib.rs b/primitive-types/impls/codec/src/lib.rs index ee01bbb13..ea478de98 100644 --- a/primitive-types/impls/codec/src/lib.rs +++ b/primitive-types/impls/codec/src/lib.rs @@ -28,11 +28,8 @@ macro_rules! impl_uint_codec { impl $crate::codec::EncodeLike for $name {} impl $crate::codec::Decode for $name { - fn decode( - input: &mut I, - ) -> core::result::Result { - <[u8; $len * 8] as $crate::codec::Decode>::decode(input) - .map(|b| $name::from_little_endian(&b)) + fn decode(input: &mut I) -> core::result::Result { + <[u8; $len * 8] as $crate::codec::Decode>::decode(input).map(|b| $name::from_little_endian(&b)) } } }; @@ -51,9 +48,7 @@ macro_rules! impl_fixed_hash_codec { impl $crate::codec::EncodeLike for $name {} impl $crate::codec::Decode for $name { - fn decode( - input: &mut I, - ) -> core::result::Result { + fn decode(input: &mut I) -> core::result::Result { <[u8; $len] as $crate::codec::Decode>::decode(input).map($name) } } diff --git a/primitive-types/impls/rlp/src/lib.rs b/primitive-types/impls/rlp/src/lib.rs index 9599e4eb0..da82d0d79 100644 --- a/primitive-types/impls/rlp/src/lib.rs +++ b/primitive-types/impls/rlp/src/lib.rs @@ -57,20 +57,15 @@ macro_rules! impl_fixed_hash_rlp { impl $crate::rlp::Decodable for $name { fn decode(rlp: &$crate::rlp::Rlp) -> Result { - rlp.decoder() - .decode_value(|bytes| match bytes.len().cmp(&$size) { - $crate::core_::cmp::Ordering::Less => { - Err($crate::rlp::DecoderError::RlpIsTooShort) - } - $crate::core_::cmp::Ordering::Greater => { - Err($crate::rlp::DecoderError::RlpIsTooBig) - } - $crate::core_::cmp::Ordering::Equal => { - let mut t = [0u8; $size]; - t.copy_from_slice(bytes); - Ok($name(t)) - } - }) + rlp.decoder().decode_value(|bytes| match bytes.len().cmp(&$size) { + $crate::core_::cmp::Ordering::Less => Err($crate::rlp::DecoderError::RlpIsTooShort), + $crate::core_::cmp::Ordering::Greater => Err($crate::rlp::DecoderError::RlpIsTooBig), + $crate::core_::cmp::Ordering::Equal => { + let mut t = [0u8; $size]; + t.copy_from_slice(bytes); + Ok($name(t)) + } + }) } } }; diff --git a/primitive-types/impls/serde/benches/impl_serde.rs b/primitive-types/impls/serde/benches/impl_serde.rs index faf8596ae..a5001c13c 100644 --- a/primitive-types/impls/serde/benches/impl_serde.rs +++ b/primitive-types/impls/serde/benches/impl_serde.rs @@ -29,13 +29,7 @@ impl_uint_serde!(U256, 4); #[derive(Debug, Deserialize, Serialize)] struct Bytes(#[serde(with = "impl_serde::serialize")] Vec); -criterion_group!( - impl_serde, - u256_to_hex, - hex_to_u256, - bytes_to_hex, - hex_to_bytes, -); +criterion_group!(impl_serde, u256_to_hex, hex_to_u256, bytes_to_hex, hex_to_bytes,); criterion_main!(impl_serde); fn u256_to_hex(c: &mut Criterion) { @@ -87,11 +81,7 @@ fn bytes_to_hex(c: &mut Criterion) { c.bench( "bytes to hex", - ParameterizedBenchmark::new( - "", - |b, x| b.iter(|| black_box(serde_json::to_string(&x))), - parameters, - ), + ParameterizedBenchmark::new("", |b, x| b.iter(|| black_box(serde_json::to_string(&x))), parameters), ); } diff --git a/primitive-types/impls/serde/benches/input.rs b/primitive-types/impls/serde/benches/input.rs index 3fd3c297e..00d5efdc5 100644 --- a/primitive-types/impls/serde/benches/input.rs +++ b/primitive-types/impls/serde/benches/input.rs @@ -1,6 +1,5 @@ /// Hexdecimal string 64 chars (32 bytes) -pub const HEX_64_CHARS: &str = - "\"0x6402541b4e3c2ab65306aec48fce5adedc60e3ac465c3d7036c731e0b2e49209\""; +pub const HEX_64_CHARS: &str = "\"0x6402541b4e3c2ab65306aec48fce5adedc60e3ac465c3d7036c731e0b2e49209\""; /// Hexdecimal string 256 chars (128 bytes) pub const HEX_256_CHARS: &str = "\"0x2568f30caf43f5f11ec121695200e166f89b17149743da42fdff7dba5504c527b34c898ef20a61a45109b7a6e6a516994567932b31478cfa3a3bd4b058e36e88a51400403be492afb01039910c45376951d2bbec9a838666404b14850c6a8efe07b30b7cedc3e84f59b678b5d812feb4adc7e2c39d681366563ef45669a33a7604415e46a3df671968e38df6115c80eedb96dd326a273404a4b9b9957055d22e7091d3e663faa6c54a48888f29778db6f7c5199a2ccd2237c265d30ea67aed475cf459ca8039831971c2e04eb6b89951d4ba472ef8b196e60e2875e3ec2955a07956936d56162d6758eb0fe09d2b2b12e27217f26aa38f90f5def14ab7c215d3\""; diff --git a/primitive-types/impls/serde/src/serialize.rs b/primitive-types/impls/serde/src/serialize.rs index 1dc627927..c9ca92233 100644 --- a/primitive-types/impls/serde/src/serialize.rs +++ b/primitive-types/impls/serde/src/serialize.rs @@ -82,9 +82,7 @@ impl<'a> fmt::Display for ExpectedLen<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match *self { ExpectedLen::Exact(ref v) => write!(fmt, "length of {}", v.len() * 2), - ExpectedLen::Between(min, ref v) => { - write!(fmt, "length between ({}; {}]", min * 2, v.len() * 2) - } + ExpectedLen::Between(min, ref v) => write!(fmt, "length between ({}; {}]", min * 2, v.len() * 2), } } } @@ -127,10 +125,7 @@ where } b => { let ch = char::from(b); - return Err(E::custom(&format!( - "invalid hex character: {}, at {}", - ch, idx - ))); + return Err(E::custom(&format!("invalid hex character: {}, at {}", ch, idx))); } } @@ -155,10 +150,7 @@ where /// Deserialize into vector of bytes with additional size check. /// Returns number of bytes written. -pub fn deserialize_check_len<'a, 'de, D>( - deserializer: D, - len: ExpectedLen<'a>, -) -> Result +pub fn deserialize_check_len<'a, 'de, D>(deserializer: D, len: ExpectedLen<'a>) -> Result where D: Deserializer<'de>, { @@ -180,9 +172,7 @@ where let is_len_valid = match self.len { ExpectedLen::Exact(ref slice) => v.len() == 2 * slice.len() + 2, - ExpectedLen::Between(min, ref slice) => { - v.len() <= 2 * slice.len() + 2 && v.len() > 2 * min + 2 - } + ExpectedLen::Between(min, ref slice) => v.len() <= 2 * slice.len() + 2 && v.len() > 2 * min + 2, }; if !is_len_valid { @@ -210,10 +200,7 @@ where } b => { let ch = char::from(b); - return Err(E::custom(&format!( - "invalid hex character: {}, at {}", - ch, idx - ))); + return Err(E::custom(&format!("invalid hex character: {}, at {}", ch, idx))); } } @@ -264,18 +251,12 @@ mod tests { #[test] fn should_not_fail_on_other_strings() { - let a: Bytes = serde_json::from_str( - "\"0x7f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587\"", - ) - .unwrap(); - let b: Bytes = serde_json::from_str( - "\"0x7f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587b\"", - ) - .unwrap(); - let c: Bytes = serde_json::from_str( - "\"0x7f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587b4\"", - ) - .unwrap(); + let a: Bytes = + serde_json::from_str("\"0x7f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587\"").unwrap(); + let b: Bytes = + serde_json::from_str("\"0x7f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587b\"").unwrap(); + let c: Bytes = + serde_json::from_str("\"0x7f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587b4\"").unwrap(); assert_eq!(a.0.len(), 31); assert_eq!(b.0.len(), 32); diff --git a/rlp/benches/rlp.rs b/rlp/benches/rlp.rs index 6f6402a99..1fcd8b21f 100644 --- a/rlp/benches/rlp.rs +++ b/rlp/benches/rlp.rs @@ -21,8 +21,7 @@ fn bench_encode(c: &mut Criterion) { c.bench_function("encode_u256", |b| { b.iter(|| { let mut stream = rlp::RlpStream::new(); - let uint: primitive_types::U256 = - "8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0".into(); + let uint: primitive_types::U256 = "8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0".into(); stream.append(&uint); let _ = stream.out(); }) @@ -42,11 +41,7 @@ fn bench_encode(c: &mut Criterion) { let mut stream = rlp::RlpStream::new_list(3); stream.begin_list(0); stream.begin_list(1).begin_list(0); - stream - .begin_list(2) - .begin_list(0) - .begin_list(1) - .begin_list(0); + stream.begin_list(2).begin_list(0).begin_list(1).begin_list(0); let _ = stream.out(); }) }); @@ -72,9 +67,8 @@ fn bench_decode(c: &mut Criterion) { c.bench_function("decode_u256", |b| { b.iter(|| { let data = vec![ - 0xa0, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x09, 0x10, 0x20, 0x30, 0x40, - 0x50, 0x60, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x12, 0xf0, + 0xa0, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x09, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x77, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xf0, ]; let rlp = rlp::Rlp::new(&data); let _: primitive_types::U256 = rlp.as_val().unwrap(); diff --git a/rlp/src/rlpin.rs b/rlp/src/rlpin.rs index 91d6be3b2..847792b56 100644 --- a/rlp/src/rlpin.rs +++ b/rlp/src/rlpin.rs @@ -50,10 +50,7 @@ pub struct PayloadInfo { pub value_len: usize, } -fn calculate_payload_info( - header_bytes: &[u8], - len_of_len: usize, -) -> Result { +fn calculate_payload_info(header_bytes: &[u8], len_of_len: usize) -> Result { let header_len = 1 + len_of_len; match header_bytes.get(1) { Some(&0) => return Err(DecoderError::RlpDataLenWithZeroPrefix), @@ -72,10 +69,7 @@ fn calculate_payload_info( impl PayloadInfo { fn new(header_len: usize, value_len: usize) -> PayloadInfo { - PayloadInfo { - header_len, - value_len, - } + PayloadInfo { header_len, value_len } } /// Total size of the RLP. @@ -85,9 +79,7 @@ impl PayloadInfo { /// Create a new object from the given bytes RLP. The bytes pub fn from(header_bytes: &[u8]) -> Result { - let l = *header_bytes - .first() - .ok_or_else(|| DecoderError::RlpIsTooShort)?; + let l = *header_bytes.first().ok_or_else(|| DecoderError::RlpIsTooShort)?; if l <= 0x7f { Ok(PayloadInfo::new(0, 1)) } else if l <= 0xb7 { @@ -121,9 +113,7 @@ impl<'a> fmt::Display for Rlp<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { match self.prototype() { Ok(Prototype::Null) => write!(f, "null"), - Ok(Prototype::Data(_)) => { - write!(f, "\"0x{}\"", self.data().unwrap().to_hex::()) - } + Ok(Prototype::Data(_)) => write!(f, "\"0x{}\"", self.data().unwrap().to_hex::()), Ok(Prototype::List(len)) => { write!(f, "[")?; for i in 0..len - 1 { @@ -194,9 +184,7 @@ impl<'a> Rlp<'a> { pub fn size(&self) -> usize { if self.is_data() { // TODO: No panic on malformed data, but ideally would Err on no PayloadInfo. - BasicDecoder::payload_info(self.bytes) - .map(|b| b.value_len) - .unwrap_or(0) + BasicDecoder::payload_info(self.bytes).map(|b| b.value_len).unwrap_or(0) } else { 0 } @@ -360,10 +348,7 @@ where type IntoIter = RlpIterator<'a, 'view>; fn into_iter(self) -> Self::IntoIter { - RlpIterator { - rlp: self, - index: 0, - } + RlpIterator { rlp: self, index: 0 } } } @@ -424,9 +409,7 @@ impl<'a> BasicDecoder<'a> { } let len = decode_usize(&bytes[1..begin_of_value])?; - let last_index_of_value = begin_of_value - .checked_add(len) - .ok_or(DecoderError::RlpInvalidLength)?; + let last_index_of_value = begin_of_value.checked_add(len).ok_or(DecoderError::RlpInvalidLength)?; if bytes.len() < last_index_of_value { return Err(DecoderError::RlpInconsistentLengthAndData); } diff --git a/rlp/src/stream.rs b/rlp/src/stream.rs index a23e3a6cc..5a40f95aa 100644 --- a/rlp/src/stream.rs +++ b/rlp/src/stream.rs @@ -202,8 +202,7 @@ impl RlpStream { self.buffer.push(0); let position = self.buffer.len(); - self.unfinished_lists - .push(ListInfo::new(position, Some(len))); + self.unfinished_lists.push(ListInfo::new(position, Some(len))); } } @@ -326,9 +325,7 @@ impl RlpStream { Some(ref mut x) => { x.current += inserted_items; match x.max { - Some(ref max) if x.current > *max => { - panic!("You cannot append more items then you expect!") - } + Some(ref max) if x.current > *max => panic!("You cannot append more items then you expect!"), Some(ref max) => x.current == *max, _ => false, } @@ -384,8 +381,7 @@ impl<'a> BasicEncoder<'a> { let buffer: [u8; 4] = size.to_be_bytes(); assert!(position <= self.buffer.len()); - self.buffer - .extend_from_slice(&buffer[leading_empty_bytes..]); + self.buffer.extend_from_slice(&buffer[leading_empty_bytes..]); self.buffer[position..].rotate_right(size_bytes as usize); size_bytes as u8 } diff --git a/rlp/tests/tests.rs b/rlp/tests/tests.rs index 1e0fae34d..e3aa4a3f5 100644 --- a/rlp/tests/tests.rs +++ b/rlp/tests/tests.rs @@ -156,22 +156,15 @@ fn encode_u64() { fn encode_u256() { let tests = vec![ ETestPair(U256::from(0u64), vec![0x80u8]), - ETestPair( - U256::from(0x0100_0000u64), - vec![0x84, 0x01, 0x00, 0x00, 0x00], - ), - ETestPair( - U256::from(0xffff_ffffu64), - vec![0x84, 0xff, 0xff, 0xff, 0xff], - ), + ETestPair(U256::from(0x0100_0000u64), vec![0x84, 0x01, 0x00, 0x00, 0x00]), + ETestPair(U256::from(0xffff_ffffu64), vec![0x84, 0xff, 0xff, 0xff, 0xff]), ETestPair( ("8090a0b0c0d0e0f00910203040506077000000000000\ 000100000000000012f0") .into(), vec![ - 0xa0, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x09, 0x10, 0x20, 0x30, 0x40, - 0x50, 0x60, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x12, 0xf0, + 0xa0, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x09, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x77, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xf0, ], ), ]; @@ -188,11 +181,10 @@ fn encode_str() { ETestPair( "Lorem ipsum dolor sit amet, consectetur adipisicing elit", vec![ - 0xb8, 0x38, b'L', b'o', b'r', b'e', b'm', b' ', b'i', b'p', b's', b'u', b'm', b' ', - b'd', b'o', b'l', b'o', b'r', b' ', b's', b'i', b't', b' ', b'a', b'm', b'e', b't', - b',', b' ', b'c', b'o', b'n', b's', b'e', b'c', b't', b'e', b't', b'u', b'r', b' ', - b'a', b'd', b'i', b'p', b'i', b's', b'i', b'c', b'i', b'n', b'g', b' ', b'e', b'l', - b'i', b't', + 0xb8, 0x38, b'L', b'o', b'r', b'e', b'm', b' ', b'i', b'p', b's', b'u', b'm', b' ', b'd', b'o', b'l', + b'o', b'r', b' ', b's', b'i', b't', b' ', b'a', b'm', b'e', b't', b',', b' ', b'c', b'o', b'n', b's', + b'e', b'c', b't', b'e', b't', b'u', b'r', b' ', b'a', b'd', b'i', b'p', b'i', b's', b'i', b'c', b'i', + b'n', b'g', b' ', b'e', b'l', b'i', b't', ], ), ]; @@ -204,8 +196,8 @@ fn encode_address() { let tests = vec![ETestPair( H160::from(hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106")), vec![ - 0x94, 0xef, 0x2d, 0x6d, 0x19, 0x40, 0x84, 0xc2, 0xde, 0x36, 0xe0, 0xda, 0xbf, 0xce, - 0x45, 0xd0, 0x46, 0xb3, 0x7d, 0x11, 0x06, + 0x94, 0xef, 0x2d, 0x6d, 0x19, 0x40, 0x84, 0xc2, 0xde, 0x36, 0xe0, 0xda, 0xbf, 0xce, 0x45, 0xd0, 0x46, 0xb3, + 0x7d, 0x11, 0x06, ], )]; run_encode_tests(tests); @@ -329,22 +321,15 @@ fn decode_untrusted_u64() { fn decode_untrusted_u256() { let tests = vec![ DTestPair(U256::from(0u64), vec![0x80u8]), - DTestPair( - U256::from(0x0100_0000u64), - vec![0x84, 0x01, 0x00, 0x00, 0x00], - ), - DTestPair( - U256::from(0xffff_ffffu64), - vec![0x84, 0xff, 0xff, 0xff, 0xff], - ), + DTestPair(U256::from(0x0100_0000u64), vec![0x84, 0x01, 0x00, 0x00, 0x00]), + DTestPair(U256::from(0xffff_ffffu64), vec![0x84, 0xff, 0xff, 0xff, 0xff]), DTestPair( ("8090a0b0c0d0e0f00910203040506077000000000000\ 000100000000000012f0") .into(), vec![ - 0xa0, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x09, 0x10, 0x20, 0x30, 0x40, - 0x50, 0x60, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x12, 0xf0, + 0xa0, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x09, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x77, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xf0, ], ), ]; @@ -361,11 +346,10 @@ fn decode_untrusted_str() { DTestPair( "Lorem ipsum dolor sit amet, consectetur adipisicing elit".to_owned(), vec![ - 0xb8, 0x38, b'L', b'o', b'r', b'e', b'm', b' ', b'i', b'p', b's', b'u', b'm', b' ', - b'd', b'o', b'l', b'o', b'r', b' ', b's', b'i', b't', b' ', b'a', b'm', b'e', b't', - b',', b' ', b'c', b'o', b'n', b's', b'e', b'c', b't', b'e', b't', b'u', b'r', b' ', - b'a', b'd', b'i', b'p', b'i', b's', b'i', b'c', b'i', b'n', b'g', b' ', b'e', b'l', - b'i', b't', + 0xb8, 0x38, b'L', b'o', b'r', b'e', b'm', b' ', b'i', b'p', b's', b'u', b'm', b' ', b'd', b'o', b'l', + b'o', b'r', b' ', b's', b'i', b't', b' ', b'a', b'm', b'e', b't', b',', b' ', b'c', b'o', b'n', b's', + b'e', b'c', b't', b'e', b't', b'u', b'r', b' ', b'a', b'd', b'i', b'p', b'i', b's', b'i', b'c', b'i', + b'n', b'g', b' ', b'e', b'l', b'i', b't', ], ), ]; @@ -377,8 +361,8 @@ fn decode_untrusted_address() { let tests = vec![DTestPair( H160::from(hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106")), vec![ - 0x94, 0xef, 0x2d, 0x6d, 0x19, 0x40, 0x84, 0xc2, 0xde, 0x36, 0xe0, 0xda, 0xbf, 0xce, - 0x45, 0xd0, 0x46, 0xb3, 0x7d, 0x11, 0x06, + 0x94, 0xef, 0x2d, 0x6d, 0x19, 0x40, 0x84, 0xc2, 0xde, 0x36, 0xe0, 0xda, 0xbf, 0xce, 0x45, 0xd0, 0x46, 0xb3, + 0x7d, 0x11, 0x06, ], )]; run_decode_tests(tests); @@ -465,9 +449,7 @@ fn test_rlp_nested_empty_list_encode() { #[test] fn test_rlp_list_length_overflow() { - let data: Vec = vec![ - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, - ]; + let data: Vec = vec![0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00]; let rlp = Rlp::new(&data); let as_val: Result = rlp.val_at(0); assert_eq!(Err(DecoderError::RlpIsTooShort), as_val); @@ -590,9 +572,7 @@ fn test_nested_list_roundtrip() { impl Encodable for Nest { fn rlp_append(&self, s: &mut RlpStream) { - s.begin_unbounded_list() - .append_list(&self.0) - .finalize_unbounded_list(); + s.begin_unbounded_list().append_list(&self.0).finalize_unbounded_list(); } } diff --git a/rustfmt.toml b/rustfmt.toml index 218e20321..768ff5c47 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,2 @@ hard_tabs = true +max_width = 120 diff --git a/transaction-pool/src/error.rs b/transaction-pool/src/error.rs index fb1e89e4b..348082f6a 100644 --- a/transaction-pool/src/error.rs +++ b/transaction-pool/src/error.rs @@ -34,14 +34,10 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Error::AlreadyImported(h) => write!(f, "[{:?}] already imported", h), - Error::TooCheapToEnter(hash, min_score) => write!( - f, - "[{:x}] too cheap to enter the pool. Min score: {}", - hash, min_score - ), - Error::TooCheapToReplace(old_hash, hash) => { - write!(f, "[{:x}] too cheap to replace: {:x}", hash, old_hash) + Error::TooCheapToEnter(hash, min_score) => { + write!(f, "[{:x}] too cheap to enter the pool. Min score: {}", hash, min_score) } + Error::TooCheapToReplace(old_hash, hash) => write!(f, "[{:x}] too cheap to replace: {:x}", hash, old_hash), } } } @@ -58,9 +54,7 @@ where match (self, other) { (&AlreadyImported(ref h1), &AlreadyImported(ref h2)) => h1 == h2, - (&TooCheapToEnter(ref h1, ref s1), &TooCheapToEnter(ref h2, ref s2)) => { - h1 == h2 && s1 == s2 - } + (&TooCheapToEnter(ref h1, ref s1), &TooCheapToEnter(ref h2, ref s2)) => h1 == h2 && s1 == s2, (&TooCheapToReplace(ref old1, ref new1), &TooCheapToReplace(ref old2, ref new2)) => { old1 == old2 && new1 == new2 } diff --git a/transaction-pool/src/pool.rs b/transaction-pool/src/pool.rs index 262aee1b6..72b546920 100644 --- a/transaction-pool/src/pool.rs +++ b/transaction-pool/src/pool.rs @@ -138,11 +138,7 @@ where /// new transaction via the supplied `ShouldReplace` implementation and may be evicted. /// /// The `Listener` will be informed on any drops or rejections. - pub fn import( - &mut self, - transaction: T, - replace: &dyn ShouldReplace, - ) -> error::Result, T::Hash> { + pub fn import(&mut self, transaction: T, replace: &dyn ShouldReplace) -> error::Result, T::Hash> { let mem_usage = transaction.mem_usage(); if self.by_hash.contains_key(transaction.hash()) { @@ -158,19 +154,18 @@ where // TODO [ToDr] Most likely move this after the transaction is inserted. // Avoid using should_replace, but rather use scoring for that. { - let remove_worst = - |s: &mut Self, transaction| match s.remove_worst(transaction, replace) { - Err(err) => { - s.listener.rejected(transaction, &err); - Err(err) - } - Ok(None) => Ok(false), - Ok(Some(removed)) => { - s.listener.dropped(&removed, Some(transaction)); - s.finalize_remove(removed.hash()); - Ok(true) - } - }; + let remove_worst = |s: &mut Self, transaction| match s.remove_worst(transaction, replace) { + Err(err) => { + s.listener.rejected(transaction, &err); + Err(err) + } + Ok(None) => Ok(false), + Ok(Some(removed)) => { + s.listener.dropped(&removed, Some(transaction)); + s.finalize_remove(removed.hash()); + Ok(true) + } + }; while self.by_hash.len() + 1 > self.options.max_count { trace!( @@ -227,8 +222,7 @@ where return Err(error); } AddResult::TooCheapToEnter(new, score) => { - let error = - error::Error::TooCheapToEnter(new.hash().clone(), format!("{:#x}", score)); + let error = error::Error::TooCheapToEnter(new.hash().clone(), format!("{:#x}", score)); self.listener.rejected(&new, &error); return Err(error); } @@ -262,9 +256,8 @@ where let worst_collection = &mut self.worst_transactions; let best_collection = &mut self.best_transactions; - let is_same = |a: &(S::Score, Transaction), b: &(S::Score, Transaction)| { - a.0 == b.0 && a.1.hash() == b.1.hash() - }; + let is_same = + |a: &(S::Score, Transaction), b: &(S::Score, Transaction)| a.0 == b.0 && a.1.hash() == b.1.hash(); let update = |collection: &mut BTreeSet<_>, (score, tx), remove| { if remove { @@ -321,9 +314,7 @@ where Some(old) => { let txs = &self.transactions; let get_replace_tx = |tx| { - let sender_txs = txs - .get(transaction.sender()) - .map(|txs| txs.iter().as_slice()); + let sender_txs = txs.get(transaction.sender()).map(|txs| txs.iter().as_slice()); ReplaceTransaction::new(tx, sender_txs) }; let old_replace = get_replace_tx(&old.transaction); @@ -408,9 +399,7 @@ where /// Removes all stalled transactions from given sender. fn remove_stalled>(&mut self, sender: &T::Sender, ready: &mut R) -> usize { - let removed_from_set = self.remove_from_set(sender, |transactions, scoring| { - transactions.cull(ready, scoring) - }); + let removed_from_set = self.remove_from_set(sender, |transactions, scoring| transactions.cull(ready, scoring)); match removed_from_set { Some(removed) => { @@ -465,9 +454,7 @@ where /// Returns senders ordered by priority of their transactions. pub fn senders(&self) -> impl Iterator { - self.best_transactions - .iter() - .map(|tx| tx.transaction.sender()) + self.best_transactions.iter().map(|tx| tx.transaction.sender()) } /// Returns an iterator of pending (ready) transactions. @@ -480,11 +467,7 @@ where } /// Returns pending (ready) transactions from given sender. - pub fn pending_from_sender>( - &self, - ready: R, - sender: &T::Sender, - ) -> PendingIterator<'_, T, R, S, L> { + pub fn pending_from_sender>(&self, ready: R, sender: &T::Sender) -> PendingIterator<'_, T, R, S, L> { let best_transactions = self .transactions .get(sender) @@ -682,11 +665,7 @@ where return Some(best.transaction.transaction); } - trace!( - "[{:?}] Ignoring {:?} transaction.", - best.transaction.hash(), - tx_state - ); + trace!("[{:?}] Ignoring {:?} transaction.", best.transaction.hash(), tx_state); } None diff --git a/transaction-pool/src/replace.rs b/transaction-pool/src/replace.rs index 56ea719ce..916f81ab3 100644 --- a/transaction-pool/src/replace.rs +++ b/transaction-pool/src/replace.rs @@ -28,10 +28,7 @@ pub struct ReplaceTransaction<'a, T> { impl<'a, T> ReplaceTransaction<'a, T> { /// Creates a new `ReplaceTransaction` - pub fn new( - transaction: &'a Transaction, - pooled_by_sender: Option<&'a [Transaction]>, - ) -> Self { + pub fn new(transaction: &'a Transaction, pooled_by_sender: Option<&'a [Transaction]>) -> Self { ReplaceTransaction { transaction, pooled_by_sender, @@ -51,9 +48,5 @@ pub trait ShouldReplace { /// Decides if `new` should push out `old` transaction from the pool. /// /// NOTE returning `InsertNew` here can lead to some transactions being accepted above pool limits. - fn should_replace( - &self, - old: &ReplaceTransaction<'_, T>, - new: &ReplaceTransaction<'_, T>, - ) -> Choice; + fn should_replace(&self, old: &ReplaceTransaction<'_, T>, new: &ReplaceTransaction<'_, T>) -> Choice; } diff --git a/transaction-pool/src/scoring.rs b/transaction-pool/src/scoring.rs index 94908c7d5..b8a21c467 100644 --- a/transaction-pool/src/scoring.rs +++ b/transaction-pool/src/scoring.rs @@ -94,12 +94,7 @@ pub trait Scoring: fmt::Debug { /// Updates the transaction scores given a list of transactions and a change to previous scoring. /// NOTE: you can safely assume that both slices have the same length. /// (i.e. score at index `i` represents transaction at the same index) - fn update_scores( - &self, - txs: &[Transaction], - scores: &mut [Self::Score], - change: Change, - ); + fn update_scores(&self, txs: &[Transaction], scores: &mut [Self::Score], change: Change); /// Decides if the transaction should ignore per-sender limit in the pool. /// @@ -137,11 +132,10 @@ impl Clone for ScoreWithRef { impl Ord for ScoreWithRef { fn cmp(&self, other: &Self) -> cmp::Ordering { - other.score.cmp(&self.score).then( - self.transaction - .insertion_id - .cmp(&other.transaction.insertion_id), - ) + other + .score + .cmp(&self.score) + .then(self.transaction.insertion_id.cmp(&other.transaction.insertion_id)) } } diff --git a/transaction-pool/src/tests/helpers.rs b/transaction-pool/src/tests/helpers.rs index eed525671..f757ac8d7 100644 --- a/transaction-pool/src/tests/helpers.rs +++ b/transaction-pool/src/tests/helpers.rs @@ -28,9 +28,7 @@ pub struct DummyScoring { impl DummyScoring { pub fn always_insert() -> Self { - DummyScoring { - always_insert: true, - } + DummyScoring { always_insert: true } } } diff --git a/transaction-pool/src/tests/mod.rs b/transaction-pool/src/tests/mod.rs index c52287b18..547975e32 100644 --- a/transaction-pool/src/tests/mod.rs +++ b/transaction-pool/src/tests/mod.rs @@ -651,11 +651,8 @@ fn should_import_even_if_limit_is_reached_and_should_replace_returns_insert_new( ..Default::default() }, ); - txq.import( - b.tx().nonce(0).gas_price(5).new(), - &mut DummyScoring::always_insert(), - ) - .unwrap(); + txq.import(b.tx().nonce(0).gas_price(5).new(), &mut DummyScoring::always_insert()) + .unwrap(); assert_eq!( txq.light_status(), LightStatus { @@ -666,11 +663,8 @@ fn should_import_even_if_limit_is_reached_and_should_replace_returns_insert_new( ); // when - txq.import( - b.tx().nonce(1).gas_price(5).new(), - &mut DummyScoring::always_insert(), - ) - .unwrap(); + txq.import(b.tx().nonce(1).gas_price(5).new(), &mut DummyScoring::always_insert()) + .unwrap(); // then assert_eq!( @@ -713,8 +707,7 @@ fn should_not_import_even_if_limit_is_reached_and_should_replace_returns_false() assert_eq!( err, error::Error::TooCheapToEnter( - H256::from_str("00000000000000000000000000000000000000000000000000000000000001f5") - .unwrap(), + H256::from_str("00000000000000000000000000000000000000000000000000000000000001f5").unwrap(), "0x5".into() ) ); @@ -740,11 +733,8 @@ fn should_import_even_if_sender_limit_is_reached() { ..Default::default() }, ); - txq.import( - b.tx().nonce(0).gas_price(5).new(), - &mut DummyScoring::always_insert(), - ) - .unwrap(); + txq.import(b.tx().nonce(0).gas_price(5).new(), &mut DummyScoring::always_insert()) + .unwrap(); assert_eq!( txq.light_status(), LightStatus { @@ -755,11 +745,8 @@ fn should_import_even_if_sender_limit_is_reached() { ); // when - txq.import( - b.tx().nonce(1).gas_price(5).new(), - &mut DummyScoring::always_insert(), - ) - .unwrap(); + txq.import(b.tx().nonce(1).gas_price(5).new(), &mut DummyScoring::always_insert()) + .unwrap(); // then assert_eq!( @@ -789,11 +776,7 @@ mod listener { .push(if old.is_some() { "replaced" } else { "added" }); } - fn rejected( - &mut self, - _tx: &SharedTransaction, - _reason: &error::Error, - ) { + fn rejected(&mut self, _tx: &SharedTransaction, _reason: &error::Error) { self.0.borrow_mut().push("rejected".into()); } @@ -851,10 +834,7 @@ mod listener { assert_eq!(*results.borrow(), &["added", "dropped", "added"]); // Reject (too cheap) import(&mut txq, b.tx().sender(2).nonce(1).gas_price(2).new()).unwrap_err(); - assert_eq!( - *results.borrow(), - &["added", "dropped", "added", "rejected"] - ); + assert_eq!(*results.borrow(), &["added", "dropped", "added", "rejected"]); assert_eq!(txq.light_status().transaction_count, 2); } @@ -874,10 +854,7 @@ mod listener { txq.remove(&tx1.hash(), false); assert_eq!(*results.borrow(), &["added", "added", "canceled"]); txq.remove(&tx2.hash(), true); - assert_eq!( - *results.borrow(), - &["added", "added", "canceled", "invalid"] - ); + assert_eq!(*results.borrow(), &["added", "added", "canceled", "invalid"]); assert_eq!(txq.light_status().transaction_count, 0); } diff --git a/transaction-pool/src/transactions.rs b/transaction-pool/src/transactions.rs index b21bad038..f093758e4 100644 --- a/transaction-pool/src/transactions.rs +++ b/transaction-pool/src/transactions.rs @@ -65,9 +65,7 @@ impl> Transactions { self.transactions.iter() } - pub fn worst_and_best( - &self, - ) -> Option<((S::Score, Transaction), (S::Score, Transaction))> { + pub fn worst_and_best(&self) -> Option<((S::Score, Transaction), (S::Score, Transaction))> { let len = self.scores.len(); self.scores.get(0).cloned().map(|best| { let worst = self.scores[len - 1].clone(); @@ -105,34 +103,18 @@ impl> Transactions { } else { self.transactions.push(tx.clone()); self.scores.push(Default::default()); - scoring.update_scores( - &self.transactions, - &mut self.scores, - scoring::Change::InsertedAt(index), - ); + scoring.update_scores(&self.transactions, &mut self.scores, scoring::Change::InsertedAt(index)); AddResult::Ok(tx) } } pub fn update_scores(&mut self, scoring: &S, event: S::Event) { - scoring.update_scores( - &self.transactions, - &mut self.scores, - scoring::Change::Event(event), - ); + scoring.update_scores(&self.transactions, &mut self.scores, scoring::Change::Event(event)); } - pub fn add( - &mut self, - new: Transaction, - scoring: &S, - max_count: usize, - ) -> AddResult, S::Score> { - let index = match self - .transactions - .binary_search_by(|old| scoring.compare(old, &new)) - { + pub fn add(&mut self, new: Transaction, scoring: &S, max_count: usize) -> AddResult, S::Score> { + let index = match self.transactions.binary_search_by(|old| scoring.compare(old, &new)) { Ok(index) => index, Err(index) => index, }; @@ -153,11 +135,7 @@ impl> Transactions { scoring::Choice::InsertNew => { self.transactions.insert(index, new.clone()); self.scores.insert(index, Default::default()); - scoring.update_scores( - &self.transactions, - &mut self.scores, - scoring::Change::InsertedAt(index), - ); + scoring.update_scores(&self.transactions, &mut self.scores, scoring::Change::InsertedAt(index)); if self.transactions.len() > max_count { let old = self.transactions.pop().expect("len is non-zero"); @@ -176,11 +154,7 @@ impl> Transactions { // New transaction is replacing some other transaction already in the queue. scoring::Choice::ReplaceOld => { let old = mem::replace(&mut self.transactions[index], new.clone()); - scoring.update_scores( - &self.transactions, - &mut self.scores, - scoring::Change::ReplacedAt(index), - ); + scoring.update_scores(&self.transactions, &mut self.scores, scoring::Change::ReplacedAt(index)); AddResult::Replaced { old, new } } @@ -188,10 +162,7 @@ impl> Transactions { } pub fn remove(&mut self, tx: &T, scoring: &S) -> bool { - let index = match self - .transactions - .binary_search_by(|old| scoring.compare(old, tx)) - { + let index = match self.transactions.binary_search_by(|old| scoring.compare(old, tx)) { Ok(index) => index, Err(_) => { warn!("Attempting to remove non-existent transaction {:?}", tx); @@ -202,19 +173,11 @@ impl> Transactions { self.transactions.remove(index); self.scores.remove(index); // Update scoring - scoring.update_scores( - &self.transactions, - &mut self.scores, - scoring::Change::RemovedAt(index), - ); + scoring.update_scores(&self.transactions, &mut self.scores, scoring::Change::RemovedAt(index)); return true; } - pub fn cull>( - &mut self, - ready: &mut R, - scoring: &S, - ) -> SmallVec<[Transaction; PER_SENDER]> { + pub fn cull>(&mut self, ready: &mut R, scoring: &S) -> SmallVec<[Transaction; PER_SENDER]> { let mut result = SmallVec::new(); if self.is_empty() { return result; diff --git a/triehash/src/lib.rs b/triehash/src/lib.rs index cbbaa0f81..2d8a26af1 100644 --- a/triehash/src/lib.rs +++ b/triehash/src/lib.rs @@ -57,12 +57,7 @@ where H: Hasher, ::Out: cmp::Ord, { - trie_root::( - input - .into_iter() - .enumerate() - .map(|(i, v)| (rlp::encode(&i), v)), - ) + trie_root::(input.into_iter().enumerate().map(|(i, v)| (rlp::encode(&i), v))) } /// Generates a trie root hash for a vector of key-value tuples @@ -184,11 +179,7 @@ fn hex_prefix_encode<'a>(nibbles: &'a [u8], leaf: bool) -> impl Iterator(input: &[(A, B)], pre_len: usize, stream: &mut RlpStream) @@ -335,10 +326,7 @@ mod tests { b"A", b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" as &[u8] )]), - H256::from(hex!( - "d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab" - )) - .as_ref(), + H256::from(hex!("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab")).as_ref(), ); } diff --git a/uint/benches/bigint.rs b/uint/benches/bigint.rs index ee0591a97..e4e326148 100644 --- a/uint/benches/bigint.rs +++ b/uint/benches/bigint.rs @@ -163,10 +163,7 @@ fn u256_mul(c: &mut Criterion) { (U256::max_value(), 1u64), (U256::from(3), u64::max_value()), ( - U256::from_dec_str( - "21674844646682989462120101885968193938394323990565507610662749", - ) - .unwrap(), + U256::from_dec_str("21674844646682989462120101885968193938394323990565507610662749").unwrap(), 173, ), ], @@ -226,12 +223,7 @@ fn u256_mul_full(c: &mut Criterion) { b.iter(|| { let y = *y; let U512(ref u512words) = x.full_mul(U256([y, y, y, y])); - black_box(U256([ - u512words[0], - u512words[2], - u512words[2], - u512words[3], - ])) + black_box(U256([u512words[0], u512words[2], u512words[2], u512words[3]])) }) }, vec![(U256::from(42), 1u64), (U256::from(3), u64::max_value())], @@ -240,18 +232,8 @@ fn u256_mul_full(c: &mut Criterion) { } fn u256_div(c: &mut Criterion) { - let one = U256([ - 12767554894655550452, - 16333049135534778834, - 140317443000293558, - 598963, - ]); - let two = U256([ - 2096410819092764509, - 8483673822214032535, - 36306297304129857, - 3453, - ]); + let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); + let two = U256([2096410819092764509, 8483673822214032535, 36306297304129857, 3453]); c.bench_function("u256_div", move |b| b.iter(|| black_box(one / two))); } @@ -268,28 +250,12 @@ fn u256_rem(c: &mut Criterion) { U256::from(u64::from(u32::max_value()) + 1), ), ( - U256([ - 12767554894655550452, - 16333049135534778834, - 140317443000293558, - 598963, - ]), - U256([ - 2096410819092764509, - 8483673822214032535, - 36306297304129857, - 3453, - ]), + U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]), + U256([2096410819092764509, 8483673822214032535, 36306297304129857, 3453]), ), ( - U256::from_str( - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", - ) - .unwrap(), - U256::from_str( - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0", - ) - .unwrap(), + U256::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(), + U256::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0").unwrap(), ), ], ), @@ -326,10 +292,8 @@ fn u512_pairs() -> Vec<(U512, U512)> { ]), ), ( - U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") - .unwrap(), - U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0") - .unwrap(), + U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(), + U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0").unwrap(), ), ] } @@ -451,14 +415,12 @@ fn u512_mul_u32_vs_u64(c: &mut Criterion) { } fn bench_u512_mul_u32(b: &mut Bencher, i: u32) { - let x = - U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); + let x = U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); b.iter(|| black_box(x * i)); } fn bench_u512_mul_u64(b: &mut Bencher, i: u64) { - let x = - U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); + let x = U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); b.iter(|| black_box(x * i)); } @@ -478,10 +440,8 @@ fn mulmod_u512_vs_biguint_vs_gmp(c: &mut Criterion) { } fn bench_biguint_mulmod(b: &mut Bencher, z: U256) { - let x = - U256::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); - let y = - U256::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); + let x = U256::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); + let y = U256::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); b.iter(|| { let w = to_biguint(x) * to_biguint(y); black_box(from_biguint(w % to_biguint(z))) @@ -489,10 +449,8 @@ fn bench_biguint_mulmod(b: &mut Bencher, z: U256) { } fn bench_gmp_mulmod(b: &mut Bencher, z: U256) { - let x = - U256::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); - let y = - U256::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); + let x = U256::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); + let y = U256::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); b.iter(|| { let w = to_gmp(x) * to_gmp(y); black_box(from_gmp(w % to_gmp(z))) @@ -500,10 +458,8 @@ fn bench_gmp_mulmod(b: &mut Bencher, z: U256) { } fn bench_u512_mulmod(b: &mut Bencher, z: U256) { - let x = - U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); - let y = - U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); + let x = U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); + let y = U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(); let z = U512([z.0[0], z.0[1], z.0[2], z.0[3], 0, 0, 0, 0]); b.iter(|| { let w = x.overflowing_mul(y).0; @@ -520,18 +476,8 @@ fn u128_mul(c: &mut Criterion) { } fn u256_bit_and(c: &mut Criterion) { - let one = U256([ - 12767554894655550452, - 16333049135534778834, - 140317443000293558, - 598963, - ]); - let two = U256([ - 2096410819092764509, - 8483673822214032535, - 36306297304129857, - 3453, - ]); + let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); + let two = U256([2096410819092764509, 8483673822214032535, 36306297304129857, 3453]); c.bench_function("u256_bit_and", move |b| b.iter(|| black_box(one & two))); } @@ -560,18 +506,8 @@ fn u512_bit_and(c: &mut Criterion) { } fn u256_bit_xor(c: &mut Criterion) { - let one = U256([ - 12767554894655550452, - 16333049135534778834, - 140317443000293558, - 598963, - ]); - let two = U256([ - 2096410819092764509, - 8483673822214032535, - 36306297304129857, - 3453, - ]); + let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); + let two = U256([2096410819092764509, 8483673822214032535, 36306297304129857, 3453]); c.bench_function("u256_bit_xor", move |b| b.iter(|| black_box(one ^ two))); } @@ -600,18 +536,8 @@ fn u512_bit_xor(c: &mut Criterion) { } fn u256_bit_or(c: &mut Criterion) { - let one = U256([ - 12767554894655550452, - 16333049135534778834, - 140317443000293558, - 598963, - ]); - let two = U256([ - 2096410819092764509, - 8483673822214032535, - 36306297304129857, - 3453, - ]); + let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); + let two = U256([2096410819092764509, 8483673822214032535, 36306297304129857, 3453]); c.bench_function("u256_bit_or", move |b| b.iter(|| black_box(one | two))); } @@ -640,12 +566,7 @@ fn u512_bit_or(c: &mut Criterion) { } fn u256_not(c: &mut Criterion) { - let one = U256([ - 12767554894655550452, - 16333049135534778834, - 140317443000293558, - 598963, - ]); + let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); c.bench_function("u256_not", move |b| b.iter(|| black_box(!one))); } @@ -664,12 +585,7 @@ fn u512_not(c: &mut Criterion) { } fn u256_shl(c: &mut Criterion) { - let one = U256([ - 12767554894655550452, - 16333049135534778834, - 140317443000293558, - 598963, - ]); + let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); c.bench_function("u256_shl", move |b| b.iter(|| black_box(one << 128))); } @@ -688,12 +604,7 @@ fn u512_shl(c: &mut Criterion) { } fn u256_shr(c: &mut Criterion) { - let one = U256([ - 12767554894655550452, - 16333049135534778834, - 140317443000293558, - 598963, - ]); + let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); c.bench_function("u256_shr", move |b| b.iter(|| black_box(one >> 128))); } @@ -712,18 +623,8 @@ fn u512_shr(c: &mut Criterion) { } fn u256_ord(c: &mut Criterion) { - let one = U256([ - 12767554894655550452, - 16333049135534778834, - 140317443000293558, - 598963, - ]); - let two = U256([ - 2096410819092764509, - 8483673822214032535, - 36306297304129857, - 3453, - ]); + let one = U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]); + let two = U256([2096410819092764509, 8483673822214032535, 36306297304129857, 3453]); c.bench_function("u256_ord", move |b| b.iter(|| black_box(one < two))); } @@ -755,8 +656,8 @@ fn u256_from_le(c: &mut Criterion) { c.bench_function("u256_from_le", |b| { b.iter(|| { let raw = black_box([ - 1u8, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, - 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, + 1u8, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, + 101, 103, 107, 109, 113, 127, ]); black_box(U256::from_little_endian(&raw[..])) }) @@ -767,8 +668,8 @@ fn u256_from_be(c: &mut Criterion) { c.bench_function("u256_from_be", |b| { b.iter(|| { let raw = black_box([ - 1u8, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, - 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, + 1u8, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, + 101, 103, 107, 109, 113, 127, ]); black_box(U256::from_big_endian(&raw[..])) }) @@ -777,13 +678,11 @@ fn u256_from_be(c: &mut Criterion) { fn from_fixed_array(c: &mut Criterion) { let ary512: [u8; 64] = [ - 255, 0, 0, 123, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 121, 0, 0, 0, 0, 0, 213, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, 67, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 123, + 255, 0, 0, 123, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 121, 0, 0, 0, 0, 0, 213, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, 67, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 123, ]; let ary256: [u8; 32] = [ - 255, 0, 0, 123, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 121, 0, 0, 0, 0, 0, 213, 0, 0, - 0, 0, 0, 0, + 255, 0, 0, 123, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 121, 0, 0, 0, 0, 0, 213, 0, 0, 0, 0, 0, 0, ]; c.bench_function("from_fixed_array", move |b| { b.iter(|| { diff --git a/uint/examples/modular.rs b/uint/examples/modular.rs index 1c0e3fb2d..abc754f82 100644 --- a/uint/examples/modular.rs +++ b/uint/examples/modular.rs @@ -19,10 +19,8 @@ fn main() { // imagine the field 0..p // where the p is defined below // (it's a prime!) - let p = U256::from_dec_str( - "38873241744847760218045702002058062581688990428170398542849190507947196700873", - ) - .expect("p to be a good number in the example"); + let p = U256::from_dec_str("38873241744847760218045702002058062581688990428170398542849190507947196700873") + .expect("p to be a good number in the example"); // then, on this field, // (p-1) + (p+1) = 0 diff --git a/uint/tests/uint_tests.rs b/uint/tests/uint_tests.rs index d36e4b27d..2d43e761e 100644 --- a/uint/tests/uint_tests.rs +++ b/uint/tests/uint_tests.rs @@ -89,8 +89,8 @@ fn uint256_from() { U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from( &[ - 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x09, 0x10, 0x20, 0x30, 0x40, 0x50, - 0x60, 0x77, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x12u8, 0xf0 + 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x09, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x77, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x12u8, 0xf0 ][..] ) ); @@ -105,14 +105,8 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!( - U256([0x12f0, 0, 0, 0]), - U256::from_str("0000000012f0").unwrap() - ); - assert_eq!( - U256([0x12f0, 1, 0, 0]), - U256::from_str("0100000000000012f0").unwrap() - ); + assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("0000000012f0").unwrap()); + assert_eq!(U256([0x12f0, 1, 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() @@ -122,14 +116,8 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!( - U256([0x12f0, 0, 0, 0]), - U256::from_str("0000000012f0").unwrap() - ); - assert_eq!( - U256([0x12f0, 1, 0, 0]), - U256::from_str("0100000000000012f0").unwrap() - ); + assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("0000000012f0").unwrap()); + assert_eq!(U256([0x12f0, 1, 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() @@ -139,14 +127,8 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!( - U256([0x12f0, 0, 0, 0]), - U256::from_str("0000000012f0").unwrap() - ); - assert_eq!( - U256([0x12f0, 1, 0, 0]), - U256::from_str("0100000000000012f0").unwrap() - ); + assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("0000000012f0").unwrap()); + assert_eq!(U256([0x12f0, 1, 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() @@ -156,14 +138,8 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!( - U256([0x12f0, 0, 0, 0]), - U256::from_str("0000000012f0").unwrap() - ); - assert_eq!( - U256([0x12f0, 1, 0, 0]), - U256::from_str("0100000000000012f0").unwrap() - ); + assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("0000000012f0").unwrap()); + assert_eq!(U256([0x12f0, 1, 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() @@ -173,14 +149,8 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!( - U256([0x12f0, 0, 0, 0]), - U256::from_str("0000000012f0").unwrap() - ); - assert_eq!( - U256([0x12f0, 1, 0, 0]), - U256::from_str("0100000000000012f0").unwrap() - ); + assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("0000000012f0").unwrap()); + assert_eq!(U256([0x12f0, 1, 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() @@ -190,14 +160,8 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!( - U256([0x12f0, 0, 0, 0]), - U256::from_str("0000000012f0").unwrap() - ); - assert_eq!( - U256([0x12f0, 1, 0, 0]), - U256::from_str("0100000000000012f0").unwrap() - ); + assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("0000000012f0").unwrap()); + assert_eq!(U256([0x12f0, 1, 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() @@ -207,14 +171,8 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!( - U256([0x12f0, 0, 0, 0]), - U256::from_str("0000000012f0").unwrap() - ); - assert_eq!( - U256([0x12f0, 1, 0, 0]), - U256::from_str("0100000000000012f0").unwrap() - ); + assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("0000000012f0").unwrap()); + assert_eq!(U256([0x12f0, 1, 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() @@ -224,14 +182,8 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from_str("1010").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("12f0").unwrap()); - assert_eq!( - U256([0x12f0, 0, 0, 0]), - U256::from_str("0000000012f0").unwrap() - ); - assert_eq!( - U256([0x12f0, 1, 0, 0]), - U256::from_str("0100000000000012f0").unwrap() - ); + assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from_str("0000000012f0").unwrap()); + assert_eq!(U256([0x12f0, 1, 0, 0]), U256::from_str("0100000000000012f0").unwrap()); assert_eq!( U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from_str("8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").unwrap() @@ -274,10 +226,7 @@ fn uint256_try_into_primitives() { ($small: ty, $big: ty) => { assert_eq!( U256::from(<$small>::max_value() as $big + 1).try_into() as Result<$small, _>, - Err(concat!( - "integer overflow when casting to ", - stringify!($small) - )) + Err(concat!("integer overflow when casting to ", stringify!($small))) ); }; } @@ -346,10 +295,7 @@ fn uint256_bits_test() { assert_eq!(U256::from(0x01ffu64).byte(1), 0x1); assert_eq!(U256([0u64, 0xfc, 0, 0]).byte(8), 0xfc); assert_eq!(U256([0u64, 0, 0, u64::max_value()]).byte(31), 0xff); - assert_eq!( - U256([0u64, 0, 0, (u64::max_value() >> 8) + 1]).byte(31), - 0x01 - ); + assert_eq!(U256([0u64, 0, 0, (u64::max_value() >> 8) + 1]).byte(31), 0x01); } #[test] @@ -384,28 +330,20 @@ fn uint256_arithmetic_test() { assert_eq!(shr, U256([0x7DDE000000000000u64, 0x0001BD5B7DDFBD5B, 0, 0])); // Increment let incr = shr + U256::from(1u64); - assert_eq!( - incr, - U256([0x7DDE000000000001u64, 0x0001BD5B7DDFBD5B, 0, 0]) - ); + assert_eq!(incr, U256([0x7DDE000000000001u64, 0x0001BD5B7DDFBD5B, 0, 0])); // Subtraction let sub = overflowing!(incr.overflowing_sub(init)); assert_eq!(sub, U256([0x9F30411021524112u64, 0x0001BD5B7DDFBD5A, 0, 0])); // Multiplication let mult = sub * 300u32; - assert_eq!( - mult, - U256([0x8C8C3EE70C644118u64, 0x0209E7378231E632, 0, 0]) - ); + assert_eq!(mult, U256([0x8C8C3EE70C644118u64, 0x0209E7378231E632, 0, 0])); // Division assert_eq!(U256::from(105u8) / U256::from(5u8), U256::from(21u8)); let div = mult / U256::from(300u16); assert_eq!(div, U256([0x9F30411021524112u64, 0x0001BD5B7DDFBD5A, 0, 0])); - let a = - U256::from_str("ff000000000000000000000000000000000000000000000000000000000000d1").unwrap(); - let b = - U256::from_str("00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2e").unwrap(); + let a = U256::from_str("ff000000000000000000000000000000000000000000000000000000000000d1").unwrap(); + let b = U256::from_str("00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2e").unwrap(); println!("{:x}", a); println!("{:x}", b); assert_eq!(!a, b); @@ -433,19 +371,10 @@ fn uint256_extreme_bitshift_test() { assert_eq!(init << 64, U256([0, 0xDEADBEEFDEADBEEF, 0, 0])); let add = (init << 64) + init; assert_eq!(add, U256([0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF, 0, 0])); - assert_eq!( - add >> 0, - U256([0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF, 0, 0]) - ); - assert_eq!( - add << 0, - U256([0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF, 0, 0]) - ); + assert_eq!(add >> 0, U256([0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF, 0, 0])); + assert_eq!(add << 0, U256([0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF, 0, 0])); assert_eq!(add >> 64, U256([0xDEADBEEFDEADBEEF, 0, 0, 0])); - assert_eq!( - add << 64, - U256([0, 0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF, 0]) - ); + assert_eq!(add << 64, U256([0, 0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF, 0])); } #[test] @@ -523,15 +452,11 @@ fn uint256_overflowing_pow() { assert_eq!( U256::from(2).overflowing_pow(U256::from(0xff)), ( - U256::from_str("8000000000000000000000000000000000000000000000000000000000000000") - .unwrap(), + U256::from_str("8000000000000000000000000000000000000000000000000000000000000000").unwrap(), false ) ); - assert_eq!( - U256::from(2).overflowing_pow(U256::from(0x100)), - (U256::zero(), true) - ); + assert_eq!(U256::from(2).overflowing_pow(U256::from(0x100)), (U256::zero(), true)); } #[test] @@ -546,8 +471,7 @@ fn uint256_mul2() { assert_eq!( a * b, - U512::from_str("10000000000000000fffffffffffffffcffffffffffffffff0000000000000002") - .unwrap() + U512::from_str("10000000000000000fffffffffffffffcffffffffffffffff0000000000000002").unwrap() ); } @@ -577,8 +501,7 @@ fn uint256_mul_overflow() { U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") .unwrap() .overflowing_mul( - U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") - .unwrap() + U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() ), (U256::from_str("1").unwrap(), true) ); @@ -589,8 +512,7 @@ fn uint256_mul_overflow() { #[allow(unused_must_use)] fn uint256_mul_overflow_panic() { U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() - * U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") - .unwrap(); + * U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap(); } #[test] @@ -600,8 +522,7 @@ fn uint256_sub_overflow() { .unwrap() .overflowing_sub(U256::from_str("1").unwrap()), ( - U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") - .unwrap(), + U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap(), true ) ); @@ -617,8 +538,7 @@ fn uint256_sub_overflow_panic() { #[test] fn uint256_shl() { assert_eq!( - U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() - << 4, + U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() << 4, U256::from_str("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0").unwrap() ); } @@ -626,13 +546,11 @@ fn uint256_shl() { #[test] fn uint256_shl_words() { assert_eq!( - U256::from_str("0000000000000001ffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() - << 64, + U256::from_str("0000000000000001ffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() << 64, U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000").unwrap() ); assert_eq!( - U256::from_str("0000000000000000ffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() - << 64, + U256::from_str("0000000000000000ffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() << 64, U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000").unwrap() ); } @@ -664,15 +582,10 @@ fn uint256_from_dec_str() { assert_eq!(U256::from_dec_str("10").unwrap(), U256::from(10u64)); assert_eq!(U256::from_dec_str("1024").unwrap(), U256::from(1024u64)); assert_eq!( - U256::from_dec_str( - "115792089237316195423570985008687907853269984665640564039457584007913129639936" - ), + U256::from_dec_str("115792089237316195423570985008687907853269984665640564039457584007913129639936"), Err(FromDecStrErr::InvalidLength) ); - assert_eq!( - U256::from_dec_str("0x11"), - Err(FromDecStrErr::InvalidCharacter) - ); + assert_eq!(U256::from_dec_str("0x11"), Err(FromDecStrErr::InvalidCharacter)); } #[test] @@ -688,40 +601,32 @@ fn display_uint_zero() { #[test] fn u512_multi_adds() { - let (result, _) = - U512([0, 0, 0, 0, 0, 0, 0, 0]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, 0])); + let (result, _) = U512([0, 0, 0, 0, 0, 0, 0, 0]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, 0])); assert_eq!(result, U512([0, 0, 0, 0, 0, 0, 0, 0])); - let (result, _) = - U512([1, 0, 0, 0, 0, 0, 0, 1]).overflowing_add(U512([1, 0, 0, 0, 0, 0, 0, 1])); + let (result, _) = U512([1, 0, 0, 0, 0, 0, 0, 1]).overflowing_add(U512([1, 0, 0, 0, 0, 0, 0, 1])); assert_eq!(result, U512([2, 0, 0, 0, 0, 0, 0, 2])); - let (result, _) = - U512([0, 0, 0, 0, 0, 0, 0, 1]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, 1])); + let (result, _) = U512([0, 0, 0, 0, 0, 0, 0, 1]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, 1])); assert_eq!(result, U512([0, 0, 0, 0, 0, 0, 0, 2])); - let (result, _) = - U512([0, 0, 0, 0, 0, 0, 2, 1]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 3, 1])); + let (result, _) = U512([0, 0, 0, 0, 0, 0, 2, 1]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 3, 1])); assert_eq!(result, U512([0, 0, 0, 0, 0, 0, 5, 2])); - let (result, _) = - U512([1, 2, 3, 4, 5, 6, 7, 8]).overflowing_add(U512([9, 10, 11, 12, 13, 14, 15, 16])); + let (result, _) = U512([1, 2, 3, 4, 5, 6, 7, 8]).overflowing_add(U512([9, 10, 11, 12, 13, 14, 15, 16])); assert_eq!(result, U512([10, 12, 14, 16, 18, 20, 22, 24])); - let (_, overflow) = - U512([0, 0, 0, 0, 0, 0, 2, 1]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 3, 1])); + let (_, overflow) = U512([0, 0, 0, 0, 0, 0, 2, 1]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 3, 1])); assert!(!overflow); - let (_, overflow) = U512([MAX, MAX, MAX, MAX, MAX, MAX, MAX, MAX]) - .overflowing_add(U512([MAX, MAX, MAX, MAX, MAX, MAX, MAX, MAX])); + let (_, overflow) = + U512([MAX, MAX, MAX, MAX, MAX, MAX, MAX, MAX]).overflowing_add(U512([MAX, MAX, MAX, MAX, MAX, MAX, MAX, MAX])); assert!(overflow); - let (_, overflow) = - U512([0, 0, 0, 0, 0, 0, 0, MAX]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, MAX])); + let (_, overflow) = U512([0, 0, 0, 0, 0, 0, 0, MAX]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, MAX])); assert!(overflow); - let (_, overflow) = - U512([0, 0, 0, 0, 0, 0, 0, MAX]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, 0])); + let (_, overflow) = U512([0, 0, 0, 0, 0, 0, 0, MAX]).overflowing_add(U512([0, 0, 0, 0, 0, 0, 0, 0])); assert!(!overflow); } @@ -755,14 +660,10 @@ fn u256_multi_subs() { let (_, overflow) = U256([0, 0, 2, 1]).overflowing_sub(U256([0, 0, 3, 1])); assert!(overflow); - let (result, overflow) = - U256([MAX, MAX, MAX, MAX]).overflowing_sub(U256([MAX / 2, MAX / 2, MAX / 2, MAX / 2])); + let (result, overflow) = U256([MAX, MAX, MAX, MAX]).overflowing_sub(U256([MAX / 2, MAX / 2, MAX / 2, MAX / 2])); assert!(!overflow); - assert_eq!( - U256([MAX / 2 + 1, MAX / 2 + 1, MAX / 2 + 1, MAX / 2 + 1]), - result - ); + assert_eq!(U256([MAX / 2 + 1, MAX / 2 + 1, MAX / 2 + 1, MAX / 2 + 1]), result); let (result, overflow) = U256([0, 0, 0, 1]).overflowing_sub(U256([0, 0, 1, 0])); assert!(!overflow); @@ -775,20 +676,16 @@ fn u256_multi_subs() { #[test] fn u512_multi_subs() { - let (result, _) = - U512([0, 0, 0, 0, 0, 0, 0, 0]).overflowing_sub(U512([0, 0, 0, 0, 0, 0, 0, 0])); + let (result, _) = U512([0, 0, 0, 0, 0, 0, 0, 0]).overflowing_sub(U512([0, 0, 0, 0, 0, 0, 0, 0])); assert_eq!(result, U512([0, 0, 0, 0, 0, 0, 0, 0])); - let (result, _) = - U512([10, 9, 8, 7, 6, 5, 4, 3]).overflowing_sub(U512([9, 8, 7, 6, 5, 4, 3, 2])); + let (result, _) = U512([10, 9, 8, 7, 6, 5, 4, 3]).overflowing_sub(U512([9, 8, 7, 6, 5, 4, 3, 2])); assert_eq!(result, U512([1, 1, 1, 1, 1, 1, 1, 1])); - let (_, overflow) = - U512([10, 9, 8, 7, 6, 5, 4, 3]).overflowing_sub(U512([9, 8, 7, 6, 5, 4, 3, 2])); + let (_, overflow) = U512([10, 9, 8, 7, 6, 5, 4, 3]).overflowing_sub(U512([9, 8, 7, 6, 5, 4, 3, 2])); assert!(!overflow); - let (_, overflow) = - U512([9, 8, 7, 6, 5, 4, 3, 2]).overflowing_sub(U512([10, 9, 8, 7, 6, 5, 4, 3])); + let (_, overflow) = U512([9, 8, 7, 6, 5, 4, 3, 2]).overflowing_sub(U512([10, 9, 8, 7, 6, 5, 4, 3])); assert!(overflow); } @@ -918,14 +815,12 @@ fn u256_multi_muls_overflow() { #[test] fn u512_div() { let fuzz_data = [ - 0x38, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0x7, 0x0, - 0x0, 0x0, 0x0, 0xc1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0xfe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, + 0x38, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0x7, 0x0, 0x0, 0x0, 0x0, 0xc1, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ]; let a = U512::from_little_endian(&fuzz_data[..64]); let b = U512::from_little_endian(&fuzz_data[64..]); @@ -944,8 +839,8 @@ fn big_endian() { source.to_big_endian(&mut target); assert_eq!( vec![ - 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, - 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8 + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8 ], target ); @@ -956,8 +851,8 @@ fn big_endian() { source.to_big_endian(&mut target); assert_eq!( vec![ - 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, - 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8 + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8 ], target ); @@ -968,20 +863,18 @@ fn big_endian() { source.to_big_endian(&mut target); assert_eq!( vec![ - 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, - 0u8, 0u8, 0u8, 0u8, 0u8, 2u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8 + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 2u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8 ], target ); - let source = - U256::from_str("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20").unwrap(); + let source = U256::from_str("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20").unwrap(); source.to_big_endian(&mut target); assert_eq!( vec![ - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, - 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, - 0x1d, 0x1e, 0x1f, 0x20 + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, + 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20 ], target ); @@ -1020,29 +913,24 @@ fn u256_multi_muls2() { assert_eq!(U256([0, 0, 0, u64::max_value()]), result); let x1: U256 = "0000000000000000000000000000000000000000000000000000012365124623".into(); - let x2sqr_right: U256 = - "000000000000000000000000000000000000000000014baeef72e0378e2328c9".into(); + let x2sqr_right: U256 = "000000000000000000000000000000000000000000014baeef72e0378e2328c9".into(); let x1sqr = x1 * x1; assert_eq!(x2sqr_right, x1sqr); let x1cube = x1sqr * x1; - let x1cube_right: U256 = - "0000000000000000000000000000000001798acde139361466f712813717897b".into(); + let x1cube_right: U256 = "0000000000000000000000000000000001798acde139361466f712813717897b".into(); assert_eq!(x1cube_right, x1cube); let x1quad = x1cube * x1; - let x1quad_right: U256 = - "000000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1".into(); + let x1quad_right: U256 = "000000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1".into(); assert_eq!(x1quad_right, x1quad); let x1penta = x1quad * x1; - let x1penta_right: U256 = - "00000000000001e92875ac24be246e1c57e0507e8c46cc8d233b77f6f4c72993".into(); + let x1penta_right: U256 = "00000000000001e92875ac24be246e1c57e0507e8c46cc8d233b77f6f4c72993".into(); assert_eq!(x1penta_right, x1penta); let x1septima = x1penta * x1; - let x1septima_right: U256 = - "00022cca1da3f6e5722b7d3cc5bbfb486465ebc5a708dd293042f932d7eee119".into(); + let x1septima_right: U256 = "00022cca1da3f6e5722b7d3cc5bbfb486465ebc5a708dd293042f932d7eee119".into(); assert_eq!(x1septima_right, x1septima); } @@ -1062,9 +950,8 @@ fn example() { fn little_endian() { let number: U256 = "00022cca1da3f6e5722b7d3cc5bbfb486465ebc5a708dd293042f932d7eee119".into(); let expected = [ - 0x19, 0xe1, 0xee, 0xd7, 0x32, 0xf9, 0x42, 0x30, 0x29, 0xdd, 0x08, 0xa7, 0xc5, 0xeb, 0x65, - 0x64, 0x48, 0xfb, 0xbb, 0xc5, 0x3c, 0x7d, 0x2b, 0x72, 0xe5, 0xf6, 0xa3, 0x1d, 0xca, 0x2c, - 0x02, 0x00, + 0x19, 0xe1, 0xee, 0xd7, 0x32, 0xf9, 0x42, 0x30, 0x29, 0xdd, 0x08, 0xa7, 0xc5, 0xeb, 0x65, 0x64, 0x48, 0xfb, + 0xbb, 0xc5, 0x3c, 0x7d, 0x2b, 0x72, 0xe5, 0xf6, 0xa3, 0x1d, 0xca, 0x2c, 0x02, 0x00, ]; let mut result = [0u8; 32]; number.to_little_endian(&mut result); @@ -1074,8 +961,8 @@ fn little_endian() { #[test] fn slice_roundtrip() { let raw = [ - 1u8, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, - 83, 89, 97, 101, 103, 107, 109, 113, 127, + 1u8, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, + 107, 109, 113, 127, ]; let u256: U256 = (&raw[..]).into(); @@ -1090,8 +977,8 @@ fn slice_roundtrip() { #[test] fn slice_roundtrip_le() { let raw = [ - 1u8, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, - 83, 89, 97, 101, 103, 107, 109, 113, 127, + 1u8, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, + 107, 109, 113, 127, ]; let u256 = U256::from_little_endian(&raw[..]); @@ -1106,8 +993,8 @@ fn slice_roundtrip_le() { #[test] fn slice_roundtrip_le2() { let raw = [ - 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, - 97, 101, 103, 107, 109, 113, 127, + 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, + 109, 113, 127, ]; let u256 = U256::from_little_endian(&raw[..]); @@ -1122,8 +1009,7 @@ fn slice_roundtrip_le2() { #[test] fn from_little_endian() { let source: [u8; 32] = [ - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; let number = U256::from_little_endian(&source[..]); @@ -1134,8 +1020,7 @@ fn from_little_endian() { #[test] fn from_big_endian() { let source: [u8; 32] = [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ]; let number = U256::from_big_endian(&source[..]); @@ -1146,8 +1031,7 @@ fn from_big_endian() { #[test] fn into_fixed_array() { let expected: [u8; 32] = [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ]; let ary: [u8; 32] = U256::from(1).into(); assert_eq!(ary, expected); @@ -1156,8 +1040,7 @@ fn into_fixed_array() { #[test] fn test_u256_from_fixed_array() { let ary = [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, - 0, 123, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 123, ]; let num: U256 = ary.into(); assert_eq!(num, U256::from(std::u64::MAX) + 1 + 123); @@ -1169,8 +1052,7 @@ fn test_u256_from_fixed_array() { #[test] fn test_from_ref_to_fixed_array() { let ary: &[u8; 32] = &[ - 1, 0, 1, 2, 1, 0, 1, 2, 3, 0, 3, 4, 3, 0, 3, 4, 5, 0, 5, 6, 5, 0, 5, 6, 7, 0, 7, 8, 7, 0, - 7, 8, + 1, 0, 1, 2, 1, 0, 1, 2, 3, 0, 3, 4, 3, 0, 3, 4, 5, 0, 5, 6, 5, 0, 5, 6, 7, 0, 7, 8, 7, 0, 7, 8, ]; let big: U256 = ary.into(); // the numbers are each row of 8 bytes reversed and cast to u64 @@ -1188,9 +1070,8 @@ fn test_from_ref_to_fixed_array() { #[test] fn test_u512_from_fixed_array() { let ary = [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 123, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 123, ]; let num: U512 = ary.into(); assert_eq!(num, U512::from(123)); @@ -1202,23 +1083,19 @@ fn test_u512_from_fixed_array() { #[test] fn leading_zeros() { assert_eq!( - U256::from("000000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1") - .leading_zeros(), + U256::from("000000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1").leading_zeros(), 95 ); assert_eq!( - U256::from("f00000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1") - .leading_zeros(), + U256::from("f00000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1").leading_zeros(), 0 ); assert_eq!( - U256::from("0000000000000000000000000000000000000000000000000000000000000001") - .leading_zeros(), + U256::from("0000000000000000000000000000000000000000000000000000000000000001").leading_zeros(), 255 ); assert_eq!( - U256::from("0000000000000000000000000000000000000000000000000000000000000000") - .leading_zeros(), + U256::from("0000000000000000000000000000000000000000000000000000000000000000").leading_zeros(), 256 ); } @@ -1226,23 +1103,19 @@ fn leading_zeros() { #[test] fn trailing_zeros() { assert_eq!( - U256::from("1adbdd6bd6ff027485484b97f8a6a4c7129756dd100000000000000000000000") - .trailing_zeros(), + U256::from("1adbdd6bd6ff027485484b97f8a6a4c7129756dd100000000000000000000000").trailing_zeros(), 92 ); assert_eq!( - U256::from("1adbdd6bd6ff027485484b97f8a6a4c7129756dd10000000000000000000000f") - .trailing_zeros(), + U256::from("1adbdd6bd6ff027485484b97f8a6a4c7129756dd10000000000000000000000f").trailing_zeros(), 0 ); assert_eq!( - U256::from("8000000000000000000000000000000000000000000000000000000000000000") - .trailing_zeros(), + U256::from("8000000000000000000000000000000000000000000000000000000000000000").trailing_zeros(), 255 ); assert_eq!( - U256::from("0000000000000000000000000000000000000000000000000000000000000000") - .trailing_zeros(), + U256::from("0000000000000000000000000000000000000000000000000000000000000000").trailing_zeros(), 256 ); } From b10ffee4500265a20abfd6b69d76a5b6dcdf9ce3 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Mon, 28 Oct 2019 12:04:29 +0100 Subject: [PATCH 08/15] rustfmt: use_small_heuristics = "Max" --- ethbloom/src/lib.rs | 4 +- ethereum-types/src/hash.rs | 69 ++-- ethereum-types/src/uint.rs | 8 +- ethereum-types/tests/serde.rs | 92 ++---- fixed-hash/src/hash.rs | 3 +- fixed-hash/src/tests.rs | 25 +- keccak-hash/src/lib.rs | 15 +- kvdb-memorydb/src/lib.rs | 25 +- kvdb-rocksdb/src/lib.rs | 55 +--- kvdb-web/src/indexed_db.rs | 35 +- kvdb/src/lib.rs | 27 +- parity-crypto/benches/bench.rs | 4 +- parity-crypto/src/aes.rs | 5 +- parity-crypto/src/publickey/extended_keys.rs | 60 +--- parity-crypto/src/publickey/keypair.rs | 5 +- .../src/publickey/keypair_generator.rs | 4 +- parity-crypto/src/publickey/secret_key.rs | 11 +- parity-crypto/src/scrypt.rs | 4 +- parity-util-mem/src/allocators.rs | 6 +- parity-util-mem/src/lib.rs | 5 +- parity-util-mem/src/malloc_size.rs | 17 +- .../impls/serde/benches/impl_serde.rs | 12 +- rlp/src/rlpin.rs | 22 +- rlp/src/stream.rs | 16 +- rlp/tests/tests.rs | 50 +-- rustfmt.toml | 1 + trace-time/src/lib.rs | 5 +- transaction-pool/src/options.rs | 6 +- transaction-pool/src/pool.rs | 67 +--- transaction-pool/src/replace.rs | 5 +- transaction-pool/src/scoring.rs | 18 +- transaction-pool/src/tests/mod.rs | 300 +++--------------- transaction-pool/src/transactions.rs | 39 +-- triehash/src/lib.rs | 22 +- uint/benches/bigint.rs | 77 +---- uint/tests/uint_tests.rs | 136 ++------ 36 files changed, 261 insertions(+), 994 deletions(-) diff --git a/ethbloom/src/lib.rs b/ethbloom/src/lib.rs index 70f5db822..61afa629e 100644 --- a/ethbloom/src/lib.rs +++ b/ethbloom/src/lib.rs @@ -263,6 +263,7 @@ mod tests { use hex_literal::hex; #[test] + #[rustfmt::skip] fn it_works() { let bloom = Bloom::from_str( "00000000000000000000000000000000\ @@ -281,8 +282,7 @@ mod tests { 00000000000000000000000000000000\ 00000000000000000000000000000000\ 00000000000000000000000000000000", - ) - .unwrap(); + ).unwrap(); let address = hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106"); let topic = hex!("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc"); diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index 0de3d2625..9fe385c5b 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -76,18 +76,9 @@ mod tests { (H160::from_low_u64_be(2), "0x0000000000000000000000000000000000000002"), (H160::from_low_u64_be(15), "0x000000000000000000000000000000000000000f"), (H160::from_low_u64_be(16), "0x0000000000000000000000000000000000000010"), - ( - H160::from_low_u64_be(1_000), - "0x00000000000000000000000000000000000003e8", - ), - ( - H160::from_low_u64_be(100_000), - "0x00000000000000000000000000000000000186a0", - ), - ( - H160::from_low_u64_be(u64::max_value()), - "0x000000000000000000000000ffffffffffffffff", - ), + (H160::from_low_u64_be(1_000), "0x00000000000000000000000000000000000003e8"), + (H160::from_low_u64_be(100_000), "0x00000000000000000000000000000000000186a0"), + (H160::from_low_u64_be(u64::max_value()), "0x000000000000000000000000ffffffffffffffff"), ]; for (number, expected) in tests { @@ -99,30 +90,12 @@ mod tests { #[test] fn test_serialize_h256() { let tests = vec![ - ( - H256::from_low_u64_be(0), - "0x0000000000000000000000000000000000000000000000000000000000000000", - ), - ( - H256::from_low_u64_be(2), - "0x0000000000000000000000000000000000000000000000000000000000000002", - ), - ( - H256::from_low_u64_be(15), - "0x000000000000000000000000000000000000000000000000000000000000000f", - ), - ( - H256::from_low_u64_be(16), - "0x0000000000000000000000000000000000000000000000000000000000000010", - ), - ( - H256::from_low_u64_be(1_000), - "0x00000000000000000000000000000000000000000000000000000000000003e8", - ), - ( - H256::from_low_u64_be(100_000), - "0x00000000000000000000000000000000000000000000000000000000000186a0", - ), + (H256::from_low_u64_be(0), "0x0000000000000000000000000000000000000000000000000000000000000000"), + (H256::from_low_u64_be(2), "0x0000000000000000000000000000000000000000000000000000000000000002"), + (H256::from_low_u64_be(15), "0x000000000000000000000000000000000000000000000000000000000000000f"), + (H256::from_low_u64_be(16), "0x0000000000000000000000000000000000000000000000000000000000000010"), + (H256::from_low_u64_be(1_000), "0x00000000000000000000000000000000000000000000000000000000000003e8"), + (H256::from_low_u64_be(100_000), "0x00000000000000000000000000000000000000000000000000000000000186a0"), ( H256::from_low_u64_be(u64::max_value()), "0x000000000000000000000000000000000000000000000000ffffffffffffffff", @@ -137,21 +110,15 @@ mod tests { #[test] fn test_serialize_invalid() { - assert!( - ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000\"") - .unwrap_err() - .is_data() - ); - assert!( - ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000g\"") - .unwrap_err() - .is_data() - ); - assert!( - ser::from_str::("\"0x00000000000000000000000000000000000000000000000000000000000000000\"") - .unwrap_err() - .is_data() - ); + assert!(ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000\"") + .unwrap_err() + .is_data()); + assert!(ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000g\"") + .unwrap_err() + .is_data()); + assert!(ser::from_str::("\"0x00000000000000000000000000000000000000000000000000000000000000000\"") + .unwrap_err() + .is_data()); assert!(ser::from_str::("\"\"").unwrap_err().is_data()); assert!(ser::from_str::("\"0\"").unwrap_err().is_data()); assert!(ser::from_str::("\"10\"").unwrap_err().is_data()); diff --git a/ethereum-types/src/uint.rs b/ethereum-types/src/uint.rs index c7cef887b..5cf35feae 100644 --- a/ethereum-types/src/uint.rs +++ b/ethereum-types/src/uint.rs @@ -63,11 +63,9 @@ mod tests { ser::to_string_pretty(&!U256::zero()).unwrap(), "\"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"" ); - assert!( - ser::from_str::("\"0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"") - .unwrap_err() - .is_data() - ); + assert!(ser::from_str::("\"0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"") + .unwrap_err() + .is_data()); } #[test] diff --git a/ethereum-types/tests/serde.rs b/ethereum-types/tests/serde.rs index e7da96322..4a92241cf 100644 --- a/ethereum-types/tests/serde.rs +++ b/ethereum-types/tests/serde.rs @@ -24,10 +24,7 @@ macro_rules! test { ($name::from(1_000), "0x3e8"), ($name::from(100_000), "0x186a0"), ($name::from(u64::max_value()), "0xffffffffffffffff"), - ( - $name::from(u64::max_value()) + $name::from(1u64), - "0x10000000000000000", - ), + ($name::from(u64::max_value()) + $name::from(1u64), "0x10000000000000000"), ]; for (number, expected) in tests { @@ -54,11 +51,9 @@ fn test_large_values() { ser::to_string_pretty(&!U256::zero()).unwrap(), "\"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"" ); - assert!( - ser::from_str::("\"0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"") - .unwrap_err() - .is_data() - ); + assert!(ser::from_str::("\"0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"") + .unwrap_err() + .is_data()); } #[test] @@ -68,18 +63,9 @@ fn test_h160() { (H160::from_low_u64_be(2), "0x0000000000000000000000000000000000000002"), (H160::from_low_u64_be(15), "0x000000000000000000000000000000000000000f"), (H160::from_low_u64_be(16), "0x0000000000000000000000000000000000000010"), - ( - H160::from_low_u64_be(1_000), - "0x00000000000000000000000000000000000003e8", - ), - ( - H160::from_low_u64_be(100_000), - "0x00000000000000000000000000000000000186a0", - ), - ( - H160::from_low_u64_be(u64::max_value()), - "0x000000000000000000000000ffffffffffffffff", - ), + (H160::from_low_u64_be(1_000), "0x00000000000000000000000000000000000003e8"), + (H160::from_low_u64_be(100_000), "0x00000000000000000000000000000000000186a0"), + (H160::from_low_u64_be(u64::max_value()), "0x000000000000000000000000ffffffffffffffff"), ]; for (number, expected) in tests { @@ -91,34 +77,13 @@ fn test_h160() { #[test] fn test_h256() { let tests = vec![ - ( - H256::from_low_u64_be(0), - "0x0000000000000000000000000000000000000000000000000000000000000000", - ), - ( - H256::from_low_u64_be(2), - "0x0000000000000000000000000000000000000000000000000000000000000002", - ), - ( - H256::from_low_u64_be(15), - "0x000000000000000000000000000000000000000000000000000000000000000f", - ), - ( - H256::from_low_u64_be(16), - "0x0000000000000000000000000000000000000000000000000000000000000010", - ), - ( - H256::from_low_u64_be(1_000), - "0x00000000000000000000000000000000000000000000000000000000000003e8", - ), - ( - H256::from_low_u64_be(100_000), - "0x00000000000000000000000000000000000000000000000000000000000186a0", - ), - ( - H256::from_low_u64_be(u64::max_value()), - "0x000000000000000000000000000000000000000000000000ffffffffffffffff", - ), + (H256::from_low_u64_be(0), "0x0000000000000000000000000000000000000000000000000000000000000000"), + (H256::from_low_u64_be(2), "0x0000000000000000000000000000000000000000000000000000000000000002"), + (H256::from_low_u64_be(15), "0x000000000000000000000000000000000000000000000000000000000000000f"), + (H256::from_low_u64_be(16), "0x0000000000000000000000000000000000000000000000000000000000000010"), + (H256::from_low_u64_be(1_000), "0x00000000000000000000000000000000000000000000000000000000000003e8"), + (H256::from_low_u64_be(100_000), "0x00000000000000000000000000000000000000000000000000000000000186a0"), + (H256::from_low_u64_be(u64::max_value()), "0x000000000000000000000000000000000000000000000000ffffffffffffffff"), ]; for (number, expected) in tests { @@ -129,21 +94,15 @@ fn test_h256() { #[test] fn test_invalid() { - assert!( - ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000\"") - .unwrap_err() - .is_data() - ); - assert!( - ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000g\"") - .unwrap_err() - .is_data() - ); - assert!( - ser::from_str::("\"0x00000000000000000000000000000000000000000000000000000000000000000\"") - .unwrap_err() - .is_data() - ); + assert!(ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000\"") + .unwrap_err() + .is_data()); + assert!(ser::from_str::("\"0x000000000000000000000000000000000000000000000000000000000000000g\"") + .unwrap_err() + .is_data()); + assert!(ser::from_str::("\"0x00000000000000000000000000000000000000000000000000000000000000000\"") + .unwrap_err() + .is_data()); assert!(ser::from_str::("\"\"").unwrap_err().is_data()); assert!(ser::from_str::("\"0\"").unwrap_err().is_data()); assert!(ser::from_str::("\"10\"").unwrap_err().is_data()); @@ -153,8 +112,5 @@ fn test_invalid() { fn test_invalid_char() { const INVALID_STR: &str = "\"0x000000000000000000000000000000000000000000000000000000000000000g\""; const EXPECTED_MSG: &str = "invalid hex character: g, at 65 at line 1 column 68"; - assert_eq!( - ser::from_str::(INVALID_STR).unwrap_err().to_string(), - EXPECTED_MSG - ); + assert_eq!(ser::from_str::(INVALID_STR).unwrap_err().to_string(), EXPECTED_MSG); } diff --git a/fixed-hash/src/hash.rs b/fixed-hash/src/hash.rs index 778f234c0..25098b5ad 100644 --- a/fixed-hash/src/hash.rs +++ b/fixed-hash/src/hash.rs @@ -803,8 +803,7 @@ macro_rules! impl_fixed_hash_conversions { ); let mut ret = $small_ty::zero(); - ret.as_bytes_mut() - .copy_from_slice(&value[(large_ty_size - small_ty_size)..large_ty_size]); + ret.as_bytes_mut().copy_from_slice(&value[(large_ty_size - small_ty_size)..large_ty_size]); ret } } diff --git a/fixed-hash/src/tests.rs b/fixed-hash/src/tests.rs index 734d59de2..c587281b4 100644 --- a/fixed-hash/src/tests.rs +++ b/fixed-hash/src/tests.rs @@ -154,22 +154,13 @@ mod to_low_u64 { #[test] fn smaller_size() { assert_eq!(H32::from([0x01, 0x23, 0x45, 0x67]).to_low_u64_be(), 0x0123_4567); - assert_eq!( - H32::from([0x01, 0x23, 0x45, 0x67]).to_low_u64_le(), - 0x6745_2301_0000_0000 - ); + assert_eq!(H32::from([0x01, 0x23, 0x45, 0x67]).to_low_u64_le(), 0x6745_2301_0000_0000); } #[test] fn equal_size() { - assert_eq!( - H64::from([0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF]).to_low_u64_le(), - 0xEFCD_AB89_6745_2301 - ); - assert_eq!( - H64::from([0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF]).to_low_u64_be(), - 0x0123_4567_89AB_CDEF - ) + assert_eq!(H64::from([0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF]).to_low_u64_le(), 0xEFCD_AB89_6745_2301); + assert_eq!(H64::from([0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF]).to_low_u64_be(), 0x0123_4567_89AB_CDEF) } #[test] @@ -202,14 +193,8 @@ mod from_low_u64 { #[test] fn smaller_size() { - assert_eq!( - H32::from_low_u64_be(0x0123_4567_89AB_CDEF), - H32::from([0x01, 0x23, 0x45, 0x67]) - ); - assert_eq!( - H32::from_low_u64_le(0x0123_4567_89AB_CDEF), - H32::from([0xEF, 0xCD, 0xAB, 0x89]) - ); + assert_eq!(H32::from_low_u64_be(0x0123_4567_89AB_CDEF), H32::from([0x01, 0x23, 0x45, 0x67])); + assert_eq!(H32::from_low_u64_le(0x0123_4567_89AB_CDEF), H32::from([0xEF, 0xCD, 0xAB, 0x89])); } #[test] diff --git a/keccak-hash/src/lib.rs b/keccak-hash/src/lib.rs index adfe26114..4f19937ae 100644 --- a/keccak-hash/src/lib.rs +++ b/keccak-hash/src/lib.rs @@ -50,19 +50,13 @@ pub fn keccak>(s: T) -> H256 { pub unsafe fn keccak_256_unchecked(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) { // 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. - Keccak::keccak256( - slice::from_raw_parts(input, inputlen), - slice::from_raw_parts_mut(out, outlen), - ); + Keccak::keccak256(slice::from_raw_parts(input, inputlen), slice::from_raw_parts_mut(out, outlen)); } pub unsafe fn keccak_512_unchecked(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) { // 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. - Keccak::keccak512( - slice::from_raw_parts(input, inputlen), - slice::from_raw_parts_mut(out, outlen), - ); + Keccak::keccak512(slice::from_raw_parts(input, inputlen), slice::from_raw_parts_mut(out, outlen)); } pub fn keccak_256(input: &[u8], mut output: &mut [u8]) { @@ -161,9 +155,6 @@ mod tests { let hash = keccak_buffer(&mut file).unwrap(); // then - assert_eq!( - format!("{:x}", hash), - "68371d7e884c168ae2022c82bd837d51837718a7f7dfb7aa3f753074a35e1d87" - ); + assert_eq!(format!("{:x}", hash), "68371d7e884c168ae2022c82bd837d51837718a7f7dfb7aa3f753074a35e1d87"); } } diff --git a/kvdb-memorydb/src/lib.rs b/kvdb-memorydb/src/lib.rs index ca10a9d33..8491129a0 100644 --- a/kvdb-memorydb/src/lib.rs +++ b/kvdb-memorydb/src/lib.rs @@ -38,19 +38,14 @@ pub fn create(num_cols: u32) -> InMemory { cols.insert(Some(idx), BTreeMap::new()); } - InMemory { - columns: RwLock::new(cols), - } + InMemory { columns: RwLock::new(cols) } } impl KeyValueDB for InMemory { fn get(&self, col: Option, key: &[u8]) -> io::Result> { let columns = self.columns.read(); match columns.get(&col) { - None => Err(io::Error::new( - io::ErrorKind::Other, - format!("No such column family: {:?}", col), - )), + None => Err(io::Error::new(io::ErrorKind::Other, format!("No such column family: {:?}", col))), Some(map) => Ok(map.get(key).cloned()), } } @@ -59,10 +54,9 @@ impl KeyValueDB for InMemory { let columns = self.columns.read(); match columns.get(&col) { None => None, - Some(map) => map - .iter() - .find(|&(ref k, _)| k.starts_with(prefix)) - .map(|(_, v)| v.to_vec().into_boxed_slice()), + Some(map) => { + map.iter().find(|&(ref k, _)| k.starts_with(prefix)).map(|(_, v)| v.to_vec().into_boxed_slice()) + } } } @@ -93,9 +87,7 @@ impl KeyValueDB for InMemory { match self.columns.read().get(&col) { Some(map) => Box::new( // TODO: worth optimizing at all? - map.clone() - .into_iter() - .map(|(k, v)| (k.into_boxed_slice(), v.into_vec().into_boxed_slice())), + map.clone().into_iter().map(|(k, v)| (k.into_boxed_slice(), v.into_vec().into_boxed_slice())), ), None => Box::new(None.into_iter()), } @@ -118,9 +110,6 @@ impl KeyValueDB for InMemory { } fn restore(&self, _new_db: &str) -> io::Result<()> { - Err(io::Error::new( - io::ErrorKind::Other, - "Attempted to restore in-memory database", - )) + Err(io::Error::new(io::ErrorKind::Other, "Attempted to restore in-memory database")) } } diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index 97d2602bc..c4a9c0b15 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -134,11 +134,7 @@ impl CompactionProfile { /// Default profile suitable for SSD storage pub fn ssd() -> CompactionProfile { - CompactionProfile { - initial_file_size: 64 * MB as u64, - block_size: 16 * KB, - write_rate_limit: None, - } + CompactionProfile { initial_file_size: 64 * MB as u64, block_size: 16 * KB, write_rate_limit: None } } /// Slow HDD compaction profile @@ -219,8 +215,7 @@ struct DBAndColumns { fn col_config(config: &DatabaseConfig, block_opts: &BlockBasedOptions) -> io::Result { let mut opts = Options::new(); - opts.set_parsed_options("level_compaction_dynamic_level_bytes=true") - .map_err(other_io_err)?; + opts.set_parsed_options("level_compaction_dynamic_level_bytes=true").map_err(other_io_err)?; opts.set_block_based_table_factory(block_opts); @@ -233,8 +228,7 @@ fn col_config(config: &DatabaseConfig, block_opts: &BlockBasedOptions) -> io::Re opts.optimize_level_style_compaction(config.memory_budget_per_col() as i32); opts.set_target_file_size_base(config.compaction.initial_file_size); - opts.set_parsed_options("compression_per_level=") - .map_err(other_io_err)?; + opts.set_parsed_options("compression_per_level=").map_err(other_io_err)?; Ok(opts) } @@ -285,15 +279,13 @@ impl Database { let mut opts = Options::new(); if let Some(rate_limit) = config.compaction.write_rate_limit { - opts.set_parsed_options(&format!("rate_limiter_bytes_per_sec={}", rate_limit)) - .map_err(other_io_err)?; + opts.set_parsed_options(&format!("rate_limiter_bytes_per_sec={}", rate_limit)).map_err(other_io_err)?; } opts.set_use_fsync(false); opts.create_if_missing(true); opts.set_max_open_files(config.max_open_files); opts.set_parsed_options("keep_log_file_num=1").map_err(other_io_err)?; - opts.set_parsed_options("bytes_per_sync=1048576") - .map_err(other_io_err)?; + opts.set_parsed_options("bytes_per_sync=1048576").map_err(other_io_err)?; opts.set_db_write_buffer_size(config.memory_budget_per_col() / 2); opts.increase_parallelism(cmp::max(1, ::num_cpus::get() as i32 / 2)); @@ -521,10 +513,7 @@ impl Database { Some(&KeyState::Delete) => Ok(None), None => col .map_or_else( - || { - db.get_opt(key, &self.read_opts) - .map(|r| r.map(|v| DBValue::from_slice(&v))) - }, + || db.get_opt(key, &self.read_opts).map(|r| r.map(|v| DBValue::from_slice(&v))), |c| { db.get_cf_opt(cfs[c as usize], key, &self.read_opts) .map(|r| r.map(|v| DBValue::from_slice(&v))) @@ -565,10 +554,9 @@ impl Database { let mut overlay_data = overlay .iter() .filter_map(|(k, v)| match *v { - KeyState::Insert(ref value) => Some(( - k.clone().into_vec().into_boxed_slice(), - value.clone().into_vec().into_boxed_slice(), - )), + KeyState::Insert(ref value) => { + Some((k.clone().into_vec().into_boxed_slice(), value.clone().into_vec().into_boxed_slice())) + } KeyState::Delete => None, }) .collect::>(); @@ -582,10 +570,7 @@ impl Database { }, ); - Some(DatabaseIterator { - iter: interleave_ordered(overlay_data, iter), - _marker: PhantomData, - }) + Some(DatabaseIterator { iter: interleave_ordered(overlay_data, iter), _marker: PhantomData }) } None => None, } @@ -606,10 +591,7 @@ impl Database { }, ); - Some(DatabaseIterator { - iter: interleave_ordered(Vec::new(), iter), - _marker: PhantomData, - }) + Some(DatabaseIterator { iter: interleave_ordered(Vec::new(), iter), _marker: PhantomData }) } None => None, } @@ -671,10 +653,7 @@ impl Database { /// Drop a column family. pub fn drop_column(&self) -> io::Result<()> { match *self.db.write() { - Some(DBAndColumns { - ref mut db, - ref mut cfs, - }) => { + Some(DBAndColumns { ref mut db, ref mut cfs }) => { if let Some(col) = cfs.pop() { let name = format!("col{}", cfs.len()); drop(col); @@ -689,16 +668,10 @@ impl Database { /// Add a column family. pub fn add_column(&self) -> io::Result<()> { match *self.db.write() { - Some(DBAndColumns { - ref mut db, - ref mut cfs, - }) => { + Some(DBAndColumns { ref mut db, ref mut cfs }) => { let col = cfs.len() as u32; let name = format!("col{}", col); - cfs.push( - db.create_cf(&name, &col_config(&self.config, &self.block_opts)?) - .map_err(other_io_err)?, - ); + cfs.push(db.create_cf(&name, &col_config(&self.config, &self.block_opts)?).map_err(other_io_err)?); Ok(()) } None => Ok(()), diff --git a/kvdb-web/src/indexed_db.rs b/kvdb-web/src/indexed_db.rs index 9074c7d90..99b06569e 100644 --- a/kvdb-web/src/indexed_db.rs +++ b/kvdb-web/src/indexed_db.rs @@ -53,12 +53,8 @@ pub fn open(name: &str, version: Option, columns: u32) -> impl Future idb_factory - .open_with_u32(name, version) - .expect("TypeError is not possible with Rust; qed"), - None => idb_factory - .open(name) - .expect("TypeError is not possible with Rust; qed"), + Some(version) => idb_factory.open_with_u32(name, version).expect("TypeError is not possible with Rust; qed"), + None => idb_factory.open(name).expect("TypeError is not possible with Rust; qed"), }; try_create_missing_stores(&open_request, columns, version); @@ -68,9 +64,7 @@ pub fn open(name: &str, version: Option, columns: u32) -> impl Future().expect("Event target is IdbRequest; qed"); - let result = req - .result() - .expect("IndexedDB.onsuccess should have a valid result; qed"); + let result = req.result().expect("IndexedDB.onsuccess should have a valid result; qed"); assert!(result.is_instance_of::()); let db = IdbDatabase::from(result); @@ -79,11 +73,7 @@ pub fn open(name: &str, version: Option, columns: u32) -> impl Future Array { fn try_create_missing_stores(req: &IdbOpenDbRequest, columns: u32, version: Option) { let on_upgradeneeded = Closure::once(move |event: &Event| { - debug!( - "Upgrading or creating the database to version {:?}, columns {}", - version, columns - ); + debug!("Upgrading or creating the database to version {:?}, columns {}", version, columns); // Extract database handle from the event let target = event.target().expect("Event should have a target; qed"); let req = target.dyn_ref::().expect("Event target is IdbRequest; qed"); @@ -209,13 +196,9 @@ pub fn idb_cursor(idb: &IdbDatabase, col: u32) -> impl Stream, V // TODO: we could read all the columns in one db transaction let store_name = store_name(col); let store_name = store_name.as_str(); - let txn = idb - .transaction_with_str(store_name) - .expect("The stores were created on open: {}; qed"); + let txn = idb.transaction_with_str(store_name).expect("The stores were created on open: {}; qed"); - let store = txn - .object_store(store_name) - .expect("Opening a store shouldn't fail; qed"); + let store = txn.object_store(store_name).expect("Opening a store shouldn't fail; qed"); let cursor = store.open_cursor().expect("Opening a cursor shouldn't fail; qed"); let (tx, rx) = channel::mpsc::unbounded(); @@ -223,9 +206,7 @@ pub fn idb_cursor(idb: &IdbDatabase, col: u32) -> impl Stream, V let on_cursor = Closure::wrap(Box::new(move |event: &Event| { // Extract the cursor from the event let target = event.target().expect("on_cursor should have a target; qed"); - let req = target - .dyn_ref::() - .expect("target should be IdbRequest; qed"); + let req = target.dyn_ref::().expect("target should be IdbRequest; qed"); let result = req.result().expect("IdbRequest should have a result; qed"); let cursor: &IdbCursorWithValue = result.unchecked_ref(); diff --git a/kvdb/src/lib.rs b/kvdb/src/lib.rs index 0f2230864..46c53e5f0 100644 --- a/kvdb/src/lib.rs +++ b/kvdb/src/lib.rs @@ -38,15 +38,8 @@ pub struct DBTransaction { /// Database operation. #[derive(Clone, PartialEq)] pub enum DBOp { - Insert { - col: Option, - key: ElasticArray32, - value: DBValue, - }, - Delete { - col: Option, - key: ElasticArray32, - }, + Insert { col: Option, key: ElasticArray32, value: DBValue }, + Delete { col: Option, key: ElasticArray32 }, } impl DBOp { @@ -75,31 +68,21 @@ impl DBTransaction { /// Create new transaction with capacity. pub fn with_capacity(cap: usize) -> DBTransaction { - DBTransaction { - ops: Vec::with_capacity(cap), - } + DBTransaction { ops: Vec::with_capacity(cap) } } /// Insert a key-value pair in the transaction. Any existing value will be overwritten upon write. pub fn put(&mut self, col: Option, key: &[u8], value: &[u8]) { let mut ekey = ElasticArray32::new(); ekey.append_slice(key); - self.ops.push(DBOp::Insert { - col: col, - key: ekey, - value: DBValue::from_slice(value), - }); + self.ops.push(DBOp::Insert { col: col, key: ekey, value: DBValue::from_slice(value) }); } /// Insert a key-value pair in the transaction. Any existing value will be overwritten upon write. pub fn put_vec(&mut self, col: Option, key: &[u8], value: Bytes) { let mut ekey = ElasticArray32::new(); ekey.append_slice(key); - self.ops.push(DBOp::Insert { - col: col, - key: ekey, - value: DBValue::from_vec(value), - }); + self.ops.push(DBOp::Insert { col: col, key: ekey, value: DBValue::from_vec(value) }); } /// Delete value by key. diff --git a/parity-crypto/benches/bench.rs b/parity-crypto/benches/bench.rs index c33ba9bbf..e0830bb98 100644 --- a/parity-crypto/benches/bench.rs +++ b/parity-crypto/benches/bench.rs @@ -58,7 +58,5 @@ fn ecdh_agree(c: &mut Criterion) { let public = keypair.public().clone(); let secret = keypair.secret().clone(); - c.bench_function("ecdh_agree", move |b| { - b.iter(|| parity_crypto::publickey::ecdh::agree(&secret, &public)) - }); + c.bench_function("ecdh_agree", move |b| b.iter(|| parity_crypto::publickey::ecdh::agree(&secret, &public))); } diff --git a/parity-crypto/src/aes.rs b/parity-crypto/src/aes.rs index bef5ef832..de643dceb 100644 --- a/parity-crypto/src/aes.rs +++ b/parity-crypto/src/aes.rs @@ -55,10 +55,7 @@ pub struct AesCtr256(aes_ctr::Aes256Ctr); impl AesCtr256 { /// New encoder/decoder pub fn new(key: &[u8], iv: &[u8]) -> Result { - Ok(AesCtr256(aes_ctr::Aes256Ctr::new( - GenericArray::from_slice(key), - GenericArray::from_slice(iv), - ))) + Ok(AesCtr256(aes_ctr::Aes256Ctr::new(GenericArray::from_slice(key), GenericArray::from_slice(iv)))) } /// In place encrypt a content without padding, the content length must be a multiple diff --git a/parity-crypto/src/publickey/extended_keys.rs b/parity-crypto/src/publickey/extended_keys.rs index e0e31d847..40b33640e 100644 --- a/parity-crypto/src/publickey/extended_keys.rs +++ b/parity-crypto/src/publickey/extended_keys.rs @@ -84,10 +84,7 @@ pub struct ExtendedSecret { impl ExtendedSecret { /// New extended key from given secret and chain code. pub fn with_code(secret: Secret, chain_code: H256) -> ExtendedSecret { - ExtendedSecret { - secret: secret, - chain_code: chain_code, - } + ExtendedSecret { secret: secret, chain_code: chain_code } } /// New extended key from given secret with the random chain code. @@ -129,18 +126,12 @@ pub struct ExtendedPublic { impl ExtendedPublic { /// New extended public key from known parent and chain code pub fn new(public: Public, chain_code: H256) -> Self { - ExtendedPublic { - public: public, - chain_code: chain_code, - } + ExtendedPublic { public: public, chain_code: chain_code } } /// Create new extended public key from known secret pub fn from_secret(secret: &ExtendedSecret) -> Result { - Ok(ExtendedPublic::new( - derivation::point(**secret.as_raw())?, - secret.chain_code.clone(), - )) + Ok(ExtendedPublic::new(derivation::point(**secret.as_raw())?, secret.chain_code.clone())) } /// Derive new public key @@ -168,10 +159,7 @@ impl ExtendedKeyPair { let extended_secret = ExtendedSecret::new(secret); let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Valid `Secret` always produces valid public; qed"); - ExtendedKeyPair { - secret: extended_secret, - public: extended_public, - } + ExtendedKeyPair { secret: extended_secret, public: extended_public } } pub fn with_code(secret: Secret, public: Public, chain_code: H256) -> Self { @@ -185,10 +173,7 @@ impl ExtendedKeyPair { let extended_secret = ExtendedSecret::with_code(secret, chain_code); let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Valid `Secret` always produces valid public; qed"); - ExtendedKeyPair { - secret: extended_secret, - public: extended_public, - } + ExtendedKeyPair { secret: extended_secret, public: extended_public } } pub fn with_seed(seed: &[u8]) -> Result { @@ -213,10 +198,7 @@ impl ExtendedKeyPair { { let derived = self.secret.derive(index); - Ok(ExtendedKeyPair { - public: ExtendedPublic::from_secret(&derived)?, - secret: derived, - }) + Ok(ExtendedKeyPair { public: ExtendedPublic::from_secret(&derived)?, secret: derived }) } } @@ -364,9 +346,7 @@ mod derivation { .expect("Valid private key produces valid public key"); // Adding two points on the elliptic curves (combining two public keys) - new_public - .add_assign(&SECP256K1, &public_sec) - .expect("Addition of two valid points produce valid point"); + new_public.add_assign(&SECP256K1, &public_sec).expect("Addition of two valid points produce valid point"); let serialized = new_public.serialize_vec(&SECP256K1, false); @@ -413,10 +393,8 @@ mod tests { use std::str::FromStr; fn master_chain_basic() -> (H256, H256) { - let seed = H128::from_str("000102030405060708090a0b0c0d0e0f") - .expect("Seed should be valid H128") - .as_bytes() - .to_vec(); + let seed = + H128::from_str("000102030405060708090a0b0c0d0e0f").expect("Seed should be valid H128").as_bytes().to_vec(); derivation::seed_pair(&*seed) } @@ -462,9 +440,7 @@ mod tests { ); let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); - let derived_public = extended_public - .derive(0.into()) - .expect("First derivation of public should succeed"); + let derived_public = extended_public.derive(0.into()).expect("First derivation of public should succeed"); assert_eq!( *derived_public.public(), H512::from_str("f7b3244c96688f92372bfd4def26dc4151529747bab9f188a4ad34e141d47bd66522ff048bc6f19a0a4429b04318b1a8796c000265b4fa200dae5f6dda92dd94").unwrap(), @@ -475,11 +451,7 @@ mod tests { H256::from_low_u64_be(64), ); assert_eq!( - **keypair - .derive(2147483648u32.into()) - .expect("Derivation of keypair should succeed") - .secret() - .as_raw(), + **keypair.derive(2147483648u32.into()).expect("Derivation of keypair should succeed").secret().as_raw(), H256::from_str("edef54414c03196557cf73774bc97a645c9a1df2164ed34f0c2a78d1375a930c").unwrap(), ); } @@ -524,9 +496,7 @@ mod tests { let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); let derived_secret0 = extended_secret.derive(0.into()); - let derived_public0 = extended_public - .derive(0.into()) - .expect("First derivation of public should succeed"); + let derived_public0 = extended_public.derive(0.into()).expect("First derivation of public should succeed"); let public_from_secret0 = ExtendedPublic::from_secret(&derived_secret0).expect("Extended public should be created"); @@ -536,10 +506,8 @@ mod tests { #[test] fn test_seeds() { - let seed = H128::from_str("000102030405060708090a0b0c0d0e0f") - .expect("Seed should be valid H128") - .as_bytes() - .to_vec(); + let seed = + H128::from_str("000102030405060708090a0b0c0d0e0f").expect("Seed should be valid H128").as_bytes().to_vec(); // private key from bitcoin test vector // xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs diff --git a/parity-crypto/src/publickey/keypair.rs b/parity-crypto/src/publickey/keypair.rs index c0403aa39..a9dc05cab 100644 --- a/parity-crypto/src/publickey/keypair.rs +++ b/parity-crypto/src/publickey/keypair.rs @@ -55,10 +55,7 @@ impl KeyPair { let mut public = Public::default(); public.as_bytes_mut().copy_from_slice(&serialized[1..65]); - let keypair = KeyPair { - secret: secret, - public: public, - }; + let keypair = KeyPair { secret: secret, public: public }; Ok(keypair) } diff --git a/parity-crypto/src/publickey/keypair_generator.rs b/parity-crypto/src/publickey/keypair_generator.rs index 361d8a359..2ae91db6e 100644 --- a/parity-crypto/src/publickey/keypair_generator.rs +++ b/parity-crypto/src/publickey/keypair_generator.rs @@ -38,9 +38,7 @@ impl Generator for OsRng { type Error = Infallible; fn generate(&mut self) -> Result { - let (sec, publ) = SECP256K1 - .generate_keypair(self) - .expect("context always created with full capabilities; qed"); + let (sec, publ) = SECP256K1.generate_keypair(self).expect("context always created with full capabilities; qed"); Ok(KeyPair::from_keypair(sec, publ)) } diff --git a/parity-crypto/src/publickey/secret_key.rs b/parity-crypto/src/publickey/secret_key.rs index e5dfa43ed..e721ec66b 100644 --- a/parity-crypto/src/publickey/secret_key.rs +++ b/parity-crypto/src/publickey/secret_key.rs @@ -52,11 +52,7 @@ impl fmt::Debug for Secret { impl fmt::Display for Secret { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - write!( - fmt, - "Secret: 0x{:x}{:x}..{:x}{:x}", - self.inner[0], self.inner[1], self.inner[30], self.inner[31] - ) + write!(fmt, "Secret: 0x{:x}{:x}..{:x}{:x}", self.inner[0], self.inner[1], self.inner[30], self.inner[31]) } } @@ -292,10 +288,7 @@ mod tests { let mut pow0 = secret.clone(); pow0.pow(0).unwrap(); - assert_eq!( - pow0, - Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap() - ); + assert_eq!(pow0, Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap()); let mut pow1 = secret.clone(); pow1.pow(1).unwrap(); diff --git a/parity-crypto/src/scrypt.rs b/parity-crypto/src/scrypt.rs index add19a3ea..eea1931b3 100644 --- a/parity-crypto/src/scrypt.rs +++ b/parity-crypto/src/scrypt.rs @@ -52,9 +52,7 @@ pub fn test_derive() -> Result<(), Error> { let r1 = [93, 134, 79, 68, 223, 27, 44, 174, 236, 184, 179, 203, 74, 139, 73, 66]; let r2 = [2, 24, 239, 131, 172, 164, 18, 171, 132, 207, 22, 217, 150, 20, 203, 37]; let l1 = [6, 90, 119, 45, 67, 2, 99, 151, 81, 88, 166, 210, 244, 19, 123, 208]; - let l2 = [ - 253, 123, 132, 12, 188, 89, 196, 2, 107, 224, 239, 231, 135, 177, 125, 62, - ]; + let l2 = [253, 123, 132, 12, 188, 89, 196, 2, 107, 224, 239, 231, 135, 177, 125, 62]; let (l, r) = derive_key(&pass[..], &salt, 262, 1, 8).unwrap(); assert!(l == r1); diff --git a/parity-util-mem/src/allocators.rs b/parity-util-mem/src/allocators.rs index 3919c4356..d2953ecfb 100644 --- a/parity-util-mem/src/allocators.rs +++ b/parity-util-mem/src/allocators.rs @@ -130,11 +130,7 @@ mod usable_size { /// Get a new instance of a MallocSizeOfOps pub fn new_malloc_size_ops() -> MallocSizeOfOps { - MallocSizeOfOps::new( - usable_size::malloc_usable_size, - usable_size::new_enclosing_size_fn(), - None, - ) + MallocSizeOfOps::new(usable_size::malloc_usable_size, usable_size::new_enclosing_size_fn(), None) } /// Extension methods for `MallocSizeOf` trait, do not implement diff --git a/parity-util-mem/src/lib.rs b/parity-util-mem/src/lib.rs index e2198981e..43fbc4ab6 100644 --- a/parity-util-mem/src/lib.rs +++ b/parity-util-mem/src/lib.rs @@ -56,10 +56,7 @@ cfg_if::cfg_if! { pub mod allocators; -#[cfg(any( - all(target_os = "macos", not(feature = "jemalloc-global"),), - feature = "estimate-heapsize" -))] +#[cfg(any(all(target_os = "macos", not(feature = "jemalloc-global"),), feature = "estimate-heapsize"))] pub mod sizeof; /// This is a copy of patched crate `malloc_size_of` as a module. diff --git a/parity-util-mem/src/malloc_size.rs b/parity-util-mem/src/malloc_size.rs index da0b8ae4b..a3018af1f 100644 --- a/parity-util-mem/src/malloc_size.rs +++ b/parity-util-mem/src/malloc_size.rs @@ -202,10 +202,7 @@ pub trait MallocConditionalShallowSizeOf { fn conditional_shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize; } -#[cfg(not(any( - all(target_os = "macos", not(feature = "jemalloc-global"),), - feature = "estimate-heapsize" -)))] +#[cfg(not(any(all(target_os = "macos", not(feature = "jemalloc-global"),), feature = "estimate-heapsize")))] pub mod inner_allocator_use { use super::*; @@ -404,9 +401,7 @@ where // `ops.malloc_enclosing_size_of()` then gives us the storage size. // This assumes that the `HashSet`'s contents (values and hashes) // are all stored in a single contiguous heap allocation. - self.iter() - .next() - .map_or(0, |t| unsafe { ops.malloc_enclosing_size_of(t) }) + self.iter().next().map_or(0, |t| unsafe { ops.malloc_enclosing_size_of(t) }) } else { // An estimate. self.capacity() * (size_of::() + size_of::()) @@ -438,9 +433,7 @@ where fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { // See the implementation for std::collections::HashSet for details. if ops.has_malloc_enclosing_size_of() { - self.values() - .next() - .map_or(0, |v| unsafe { ops.malloc_enclosing_size_of(v) }) + self.values().next().map_or(0, |v| unsafe { ops.malloc_enclosing_size_of(v) }) } else { self.capacity() * (size_of::() + size_of::() + size_of::()) } @@ -470,9 +463,7 @@ where { fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { if ops.has_malloc_enclosing_size_of() { - self.values() - .next() - .map_or(0, |v| unsafe { ops.malloc_enclosing_size_of(v) }) + self.values().next().map_or(0, |v| unsafe { ops.malloc_enclosing_size_of(v) }) } else { self.len() * (size_of::() + size_of::() + size_of::()) } diff --git a/primitive-types/impls/serde/benches/impl_serde.rs b/primitive-types/impls/serde/benches/impl_serde.rs index a5001c13c..d19a97fda 100644 --- a/primitive-types/impls/serde/benches/impl_serde.rs +++ b/primitive-types/impls/serde/benches/impl_serde.rs @@ -61,11 +61,7 @@ fn hex_to_u256(c: &mut Criterion) { c.bench( "hex_to_u256", - ParameterizedBenchmark::new( - "", - |b, x| b.iter(|| black_box(serde_json::from_str::(&x))), - parameters, - ), + ParameterizedBenchmark::new("", |b, x| b.iter(|| black_box(serde_json::from_str::(&x))), parameters), ); } @@ -97,10 +93,6 @@ fn hex_to_bytes(c: &mut Criterion) { c.bench( "hex to bytes", - ParameterizedBenchmark::new( - "", - |b, x| b.iter(|| black_box(serde_json::from_str::(&x))), - parameters, - ), + ParameterizedBenchmark::new("", |b, x| b.iter(|| black_box(serde_json::from_str::(&x))), parameters), ); } diff --git a/rlp/src/rlpin.rs b/rlp/src/rlpin.rs index 847792b56..dd2ee9826 100644 --- a/rlp/src/rlpin.rs +++ b/rlp/src/rlpin.rs @@ -129,11 +129,7 @@ impl<'a> fmt::Display for Rlp<'a> { impl<'a> Rlp<'a> { pub fn new(bytes: &'a [u8]) -> Rlp<'a> { - Rlp { - bytes, - offset_cache: Cell::new(None), - count_cache: Cell::new(None), - } + Rlp { bytes, offset_cache: Cell::new(None), count_cache: Cell::new(None) } } pub fn as_raw<'view>(&'view self) -> &'a [u8] @@ -202,11 +198,9 @@ impl<'a> Rlp<'a> { // current search index, otherwise move to beginning of list let cache = self.offset_cache.get(); let (bytes, indexes_to_skip, bytes_consumed) = match cache { - Some(ref cache) if cache.index <= index => ( - Rlp::consume(self.bytes, cache.offset)?, - index - cache.index, - cache.offset, - ), + Some(ref cache) if cache.index <= index => { + (Rlp::consume(self.bytes, cache.offset)?, index - cache.index, cache.offset) + } _ => { let (bytes, consumed) = self.consume_list_payload()?; (bytes, index, consumed) @@ -217,8 +211,7 @@ impl<'a> Rlp<'a> { let (bytes, consumed) = Rlp::consume_items(bytes, indexes_to_skip)?; // update the cache - self.offset_cache - .set(Some(OffsetCache::new(index, bytes_consumed + consumed))); + self.offset_cache.set(Some(OffsetCache::new(index, bytes_consumed + consumed))); // construct new rlp let found = BasicDecoder::payload_info(bytes)?; @@ -302,10 +295,7 @@ impl<'a> Rlp<'a> { if self.bytes.len() < (item.header_len + item.value_len) { return Err(DecoderError::RlpIsTooShort); } - Ok(( - &self.bytes[item.header_len..item.header_len + item.value_len], - item.header_len, - )) + Ok((&self.bytes[item.header_len..item.header_len + item.value_len], item.header_len)) } /// consumes fixed number of items diff --git a/rlp/src/stream.rs b/rlp/src/stream.rs index 5a40f95aa..581f5efbe 100644 --- a/rlp/src/stream.rs +++ b/rlp/src/stream.rs @@ -21,11 +21,7 @@ struct ListInfo { impl ListInfo { fn new(position: usize, max: Option) -> ListInfo { - ListInfo { - position, - current: 0, - max, - } + ListInfo { position, current: 0, max } } } @@ -45,11 +41,7 @@ impl Default for RlpStream { impl RlpStream { /// Initializes instance of empty `Stream`. pub fn new() -> Self { - RlpStream { - unfinished_lists: Vec::with_capacity(16), - buffer: Vec::with_capacity(1024), - finished_list: false, - } + RlpStream { unfinished_lists: Vec::with_capacity(16), buffer: Vec::with_capacity(1024), finished_list: false } } /// Initializes the `Stream` as a list. @@ -369,9 +361,7 @@ pub struct BasicEncoder<'a> { impl<'a> BasicEncoder<'a> { fn new(stream: &'a mut RlpStream) -> Self { - BasicEncoder { - buffer: &mut stream.buffer, - } + BasicEncoder { buffer: &mut stream.buffer } } fn insert_size(&mut self, size: usize, position: usize) -> u8 { diff --git a/rlp/tests/tests.rs b/rlp/tests/tests.rs index e3aa4a3f5..84a090e09 100644 --- a/rlp/tests/tests.rs +++ b/rlp/tests/tests.rs @@ -21,9 +21,7 @@ fn test_rlp_display() { #[test] fn length_overflow() { - let bs = [ - 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe5, - ]; + let bs = [0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe5]; let rlp = Rlp::new(&bs); let res: Result = rlp.as_val(); assert_eq!(Err(DecoderError::RlpInvalidLength), res); @@ -231,10 +229,7 @@ fn encode_vector_u64() { #[test] fn encode_vector_str() { - let tests = vec![VETestPair( - vec!["cat", "dog"], - vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'], - )]; + let tests = vec![VETestPair(vec!["cat", "dog"], vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'])]; run_encode_tests_list(tests); } @@ -282,20 +277,13 @@ fn decode_vector_u8() { #[test] fn decode_untrusted_u8() { - let tests = vec![ - DTestPair(0x0u8, vec![0x80]), - DTestPair(0x77u8, vec![0x77]), - DTestPair(0xccu8, vec![0x81, 0xcc]), - ]; + let tests = vec![DTestPair(0x0u8, vec![0x80]), DTestPair(0x77u8, vec![0x77]), DTestPair(0xccu8, vec![0x81, 0xcc])]; run_decode_tests(tests); } #[test] fn decode_untrusted_u16() { - let tests = vec![ - DTestPair(0x100u16, vec![0x82, 0x01, 0x00]), - DTestPair(0xffffu16, vec![0x82, 0xff, 0xff]), - ]; + let tests = vec![DTestPair(0x100u16, vec![0x82, 0x01, 0x00]), DTestPair(0xffffu16, vec![0x82, 0xff, 0xff])]; run_decode_tests(tests); } @@ -522,26 +510,11 @@ fn test_canonical_list_encoding() { // https://github.com/paritytech/parity-common/issues/48 #[test] fn test_inner_length_capping_for_short_lists() { - assert_eq!( - Rlp::new(&[0xc0, 0x82, b'a', b'b']).val_at::(0), - Err(DecoderError::RlpIsTooShort) - ); - assert_eq!( - Rlp::new(&[0xc0 + 1, 0x82, b'a', b'b']).val_at::(0), - Err(DecoderError::RlpIsTooShort) - ); - assert_eq!( - Rlp::new(&[0xc0 + 2, 0x82, b'a', b'b']).val_at::(0), - Err(DecoderError::RlpIsTooShort) - ); - assert_eq!( - Rlp::new(&[0xc0 + 3, 0x82, b'a', b'b']).val_at::(0), - Ok("ab".to_owned()) - ); - assert_eq!( - Rlp::new(&[0xc0 + 4, 0x82, b'a', b'b']).val_at::(0), - Err(DecoderError::RlpIsTooShort) - ); + assert_eq!(Rlp::new(&[0xc0, 0x82, b'a', b'b']).val_at::(0), Err(DecoderError::RlpIsTooShort)); + assert_eq!(Rlp::new(&[0xc0 + 1, 0x82, b'a', b'b']).val_at::(0), Err(DecoderError::RlpIsTooShort)); + assert_eq!(Rlp::new(&[0xc0 + 2, 0x82, b'a', b'b']).val_at::(0), Err(DecoderError::RlpIsTooShort)); + assert_eq!(Rlp::new(&[0xc0 + 3, 0x82, b'a', b'b']).val_at::(0), Ok("ab".to_owned())); + assert_eq!(Rlp::new(&[0xc0 + 4, 0x82, b'a', b'b']).val_at::(0), Err(DecoderError::RlpIsTooShort)); } // test described in @@ -554,10 +527,7 @@ fn test_nested_list_roundtrip() { impl Encodable for Inner { fn rlp_append(&self, s: &mut RlpStream) { - s.begin_unbounded_list() - .append(&self.0) - .append(&self.1) - .finalize_unbounded_list(); + s.begin_unbounded_list().append(&self.0).append(&self.1).finalize_unbounded_list(); } } diff --git a/rustfmt.toml b/rustfmt.toml index 768ff5c47..cba0d885c 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1,3 @@ hard_tabs = true max_width = 120 +use_small_heuristics = "Max" diff --git a/trace-time/src/lib.rs b/trace-time/src/lib.rs index 7a832656e..65769ee81 100644 --- a/trace-time/src/lib.rs +++ b/trace-time/src/lib.rs @@ -36,10 +36,7 @@ pub struct PerfTimer { impl PerfTimer { /// Create an instance with given name. pub fn new(name: &'static str) -> PerfTimer { - PerfTimer { - name, - start: Instant::now(), - } + PerfTimer { name, start: Instant::now() } } } diff --git a/transaction-pool/src/options.rs b/transaction-pool/src/options.rs index 291001a20..8e1c1002d 100644 --- a/transaction-pool/src/options.rs +++ b/transaction-pool/src/options.rs @@ -27,10 +27,6 @@ pub struct Options { impl Default for Options { fn default() -> Self { - Options { - max_count: 1024, - max_per_sender: 16, - max_mem_usage: 8 * 1024 * 1024, - } + Options { max_count: 1024, max_per_sender: 16, max_mem_usage: 8 * 1024 * 1024 } } } diff --git a/transaction-pool/src/pool.rs b/transaction-pool/src/pool.rs index 72b546920..63bb0a07f 100644 --- a/transaction-pool/src/pool.rs +++ b/transaction-pool/src/pool.rs @@ -46,10 +46,7 @@ pub struct Transaction { impl Clone for Transaction { fn clone(&self) -> Self { - Transaction { - insertion_id: self.insertion_id, - transaction: self.transaction.clone(), - } + Transaction { insertion_id: self.insertion_id, transaction: self.transaction.clone() } } } @@ -146,10 +143,7 @@ where } self.insertion_id += 1; - let transaction = Transaction { - insertion_id: self.insertion_id, - transaction: Arc::new(transaction), - }; + let transaction = Transaction { insertion_id: self.insertion_id, transaction: Arc::new(transaction) }; // TODO [ToDr] Most likely move this after the transaction is inserted. // Avoid using should_replace, but rather use scoring for that. @@ -168,22 +162,14 @@ where }; while self.by_hash.len() + 1 > self.options.max_count { - trace!( - "Count limit reached: {} > {}", - self.by_hash.len() + 1, - self.options.max_count - ); + trace!("Count limit reached: {} > {}", self.by_hash.len() + 1, self.options.max_count); if !remove_worst(self, &transaction)? { break; } } while self.mem_usage + mem_usage > self.options.max_mem_usage { - trace!( - "Mem limit reached: {} > {}", - self.mem_usage + mem_usage, - self.options.max_mem_usage - ); + trace!("Mem limit reached: {} > {}", self.mem_usage + mem_usage, self.options.max_mem_usage); if !remove_worst(self, &transaction)? { break; } @@ -191,10 +177,8 @@ where } let (result, prev_state, current_state) = { - let transactions = self - .transactions - .entry(transaction.sender().clone()) - .or_insert_with(Transactions::default); + let transactions = + self.transactions.entry(transaction.sender().clone()).or_insert_with(Transactions::default); // get worst and best transactions for comparison let prev = transactions.worst_and_best(); let result = transactions.add(transaction, &self.scoring, self.options.max_per_sender); @@ -306,10 +290,7 @@ where // No elements to remove? and the pool is still full? None => { warn!("The pool is full but there are no transactions to remove."); - return Err(error::Error::TooCheapToEnter( - transaction.hash().clone(), - "unknown".into(), - )); + return Err(error::Error::TooCheapToEnter(transaction.hash().clone(), "unknown".into())); } Some(old) => { let txs = &self.transactions; @@ -441,10 +422,7 @@ where /// Returns worst transaction in the queue (if any). pub fn worst_transaction(&self) -> Option> { - self.worst_transactions - .iter() - .next_back() - .map(|x| x.transaction.transaction.clone()) + self.worst_transactions.iter().next_back().map(|x| x.transaction.transaction.clone()) } /// Returns true if the pool is at it's capacity. @@ -459,11 +437,7 @@ where /// Returns an iterator of pending (ready) transactions. pub fn pending>(&self, ready: R) -> PendingIterator<'_, T, R, S, L> { - PendingIterator { - ready, - best_transactions: self.best_transactions.clone(), - pool: self, - } + PendingIterator { ready, best_transactions: self.best_transactions.clone(), pool: self } } /// Returns pending (ready) transactions from given sender. @@ -480,20 +454,12 @@ where }) .unwrap_or_default(); - PendingIterator { - ready, - best_transactions, - pool: self, - } + PendingIterator { ready, best_transactions, pool: self } } /// Returns unprioritized list of ready transactions. pub fn unordered_pending>(&self, ready: R) -> UnorderedIterator<'_, T, R, S> { - UnorderedIterator { - ready, - senders: self.transactions.iter(), - transactions: None, - } + UnorderedIterator { ready, senders: self.transactions.iter(), transactions: None } } /// Update score of transactions of a particular sender. @@ -633,15 +599,8 @@ where fn next(&mut self) -> Option { while !self.best_transactions.is_empty() { let best = { - let best = self - .best_transactions - .iter() - .next() - .expect("current_best is not empty; qed") - .clone(); - self.best_transactions - .take(&best) - .expect("Just taken from iterator; qed") + let best = self.best_transactions.iter().next().expect("current_best is not empty; qed").clone(); + self.best_transactions.take(&best).expect("Just taken from iterator; qed") }; let tx_state = self.ready.is_ready(&best.transaction); diff --git a/transaction-pool/src/replace.rs b/transaction-pool/src/replace.rs index 916f81ab3..a278edb80 100644 --- a/transaction-pool/src/replace.rs +++ b/transaction-pool/src/replace.rs @@ -29,10 +29,7 @@ pub struct ReplaceTransaction<'a, T> { impl<'a, T> ReplaceTransaction<'a, T> { /// Creates a new `ReplaceTransaction` pub fn new(transaction: &'a Transaction, pooled_by_sender: Option<&'a [Transaction]>) -> Self { - ReplaceTransaction { - transaction, - pooled_by_sender, - } + ReplaceTransaction { transaction, pooled_by_sender } } } diff --git a/transaction-pool/src/scoring.rs b/transaction-pool/src/scoring.rs index b8a21c467..313bd6bc3 100644 --- a/transaction-pool/src/scoring.rs +++ b/transaction-pool/src/scoring.rs @@ -123,19 +123,13 @@ impl ScoreWithRef { impl Clone for ScoreWithRef { fn clone(&self) -> Self { - ScoreWithRef { - score: self.score.clone(), - transaction: self.transaction.clone(), - } + ScoreWithRef { score: self.score.clone(), transaction: self.transaction.clone() } } } impl Ord for ScoreWithRef { fn cmp(&self, other: &Self) -> cmp::Ordering { - other - .score - .cmp(&self.score) - .then(self.transaction.insertion_id.cmp(&other.transaction.insertion_id)) + other.score.cmp(&self.score).then(self.transaction.insertion_id.cmp(&other.transaction.insertion_id)) } } @@ -158,13 +152,7 @@ mod tests { use super::*; fn score(score: u64, insertion_id: u64) -> ScoreWithRef<(), u64> { - ScoreWithRef { - score, - transaction: Transaction { - insertion_id, - transaction: Default::default(), - }, - } + ScoreWithRef { score, transaction: Transaction { insertion_id, transaction: Default::default() } } } #[test] diff --git a/transaction-pool/src/tests/mod.rs b/transaction-pool/src/tests/mod.rs index 547975e32..db5ea2885 100644 --- a/transaction-pool/src/tests/mod.rs +++ b/transaction-pool/src/tests/mod.rs @@ -56,10 +56,7 @@ type TestPool = Pool; impl TestPool { pub fn with_limit(max_count: usize) -> Self { - Self::with_options(Options { - max_count, - ..Default::default() - }) + Self::with_options(Options { max_count, ..Default::default() }) } } @@ -75,41 +72,20 @@ fn should_clear_queue() { // given let b = TransactionBuilder::default(); let mut txq = TestPool::default(); - assert_eq!( - txq.light_status(), - LightStatus { - mem_usage: 0, - transaction_count: 0, - senders: 0, - } - ); + assert_eq!(txq.light_status(), LightStatus { mem_usage: 0, transaction_count: 0, senders: 0 }); let tx1 = b.tx().nonce(0).new(); let tx2 = b.tx().nonce(1).mem_usage(1).new(); // add import(&mut txq, tx1).unwrap(); import(&mut txq, tx2).unwrap(); - assert_eq!( - txq.light_status(), - LightStatus { - mem_usage: 1, - transaction_count: 2, - senders: 1, - } - ); + assert_eq!(txq.light_status(), LightStatus { mem_usage: 1, transaction_count: 2, senders: 1 }); // when txq.clear(); // then - assert_eq!( - txq.light_status(), - LightStatus { - mem_usage: 0, - transaction_count: 0, - senders: 0, - } - ); + assert_eq!(txq.light_status(), LightStatus { mem_usage: 0, transaction_count: 0, senders: 0 }); } #[test] @@ -147,20 +123,14 @@ fn should_replace_transaction() { #[test] fn should_reject_if_above_count() { let b = TransactionBuilder::default(); - let mut txq = TestPool::with_options(Options { - max_count: 1, - ..Default::default() - }); + let mut txq = TestPool::with_options(Options { max_count: 1, ..Default::default() }); // Reject second let tx1 = b.tx().nonce(0).new(); let tx2 = b.tx().nonce(1).new(); let hash = tx2.hash.clone(); import(&mut txq, tx1).unwrap(); - assert_eq!( - import(&mut txq, tx2).unwrap_err(), - error::Error::TooCheapToEnter(hash, "0x0".into()) - ); + assert_eq!(import(&mut txq, tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into())); assert_eq!(txq.light_status().transaction_count, 1); txq.clear(); @@ -176,20 +146,14 @@ fn should_reject_if_above_count() { #[test] fn should_reject_if_above_mem_usage() { let b = TransactionBuilder::default(); - let mut txq = TestPool::with_options(Options { - max_mem_usage: 1, - ..Default::default() - }); + let mut txq = TestPool::with_options(Options { max_mem_usage: 1, ..Default::default() }); // Reject second let tx1 = b.tx().nonce(1).mem_usage(1).new(); let tx2 = b.tx().nonce(2).mem_usage(2).new(); let hash = tx2.hash.clone(); import(&mut txq, tx1).unwrap(); - assert_eq!( - import(&mut txq, tx2).unwrap_err(), - error::Error::TooCheapToEnter(hash, "0x0".into()) - ); + assert_eq!(import(&mut txq, tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into())); assert_eq!(txq.light_status().transaction_count, 1); txq.clear(); @@ -205,20 +169,14 @@ fn should_reject_if_above_mem_usage() { #[test] fn should_reject_if_above_sender_count() { let b = TransactionBuilder::default(); - let mut txq = TestPool::with_options(Options { - max_per_sender: 1, - ..Default::default() - }); + let mut txq = TestPool::with_options(Options { max_per_sender: 1, ..Default::default() }); // Reject second let tx1 = b.tx().nonce(1).new(); let tx2 = b.tx().nonce(2).new(); let hash = tx2.hash.clone(); import(&mut txq, tx1).unwrap(); - assert_eq!( - import(&mut txq, tx2).unwrap_err(), - error::Error::TooCheapToEnter(hash, "0x0".into()) - ); + assert_eq!(import(&mut txq, tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into())); assert_eq!(txq.light_status().transaction_count, 1); txq.clear(); @@ -229,10 +187,7 @@ fn should_reject_if_above_sender_count() { let hash = tx2.hash.clone(); import(&mut txq, tx1).unwrap(); // This results in error because we also compare nonces - assert_eq!( - import(&mut txq, tx2).unwrap_err(), - error::Error::TooCheapToEnter(hash, "0x0".into()) - ); + assert_eq!(import(&mut txq, tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into())); assert_eq!(txq.light_status().transaction_count, 1); } @@ -263,22 +218,8 @@ fn should_construct_pending() { import(&mut txq, b.tx().sender(1).nonce(5).new()).unwrap(); assert_eq!(txq.light_status().transaction_count, 11); - assert_eq!( - txq.status(NonceReady::default()), - Status { - stalled: 0, - pending: 9, - future: 2, - } - ); - assert_eq!( - txq.status(NonceReady::new(1)), - Status { - stalled: 3, - pending: 6, - future: 2, - } - ); + assert_eq!(txq.status(NonceReady::default()), Status { stalled: 0, pending: 9, future: 2 }); + assert_eq!(txq.status(NonceReady::new(1)), Status { stalled: 3, pending: 6, future: 2 }); // when let mut current_gas = U256::zero(); @@ -341,22 +282,8 @@ fn should_return_unordered_iterator() { let tx9 = import(&mut txq, b.tx().sender(2).nonce(0).new()).unwrap(); assert_eq!(txq.light_status().transaction_count, 11); - assert_eq!( - txq.status(NonceReady::default()), - Status { - stalled: 0, - pending: 9, - future: 2, - } - ); - assert_eq!( - txq.status(NonceReady::new(1)), - Status { - stalled: 3, - pending: 6, - future: 2, - } - ); + assert_eq!(txq.status(NonceReady::default()), Status { stalled: 0, pending: 9, future: 2 }); + assert_eq!(txq.status(NonceReady::new(1)), Status { stalled: 3, pending: 6, future: 2 }); // when let all: Vec<_> = txq.unordered_pending(NonceReady::default()).collect(); @@ -413,22 +340,8 @@ fn should_update_scoring_correctly() { import(&mut txq, b.tx().sender(1).nonce(5).new()).unwrap(); assert_eq!(txq.light_status().transaction_count, 11); - assert_eq!( - txq.status(NonceReady::default()), - Status { - stalled: 0, - pending: 9, - future: 2, - } - ); - assert_eq!( - txq.status(NonceReady::new(1)), - Status { - stalled: 3, - pending: 6, - future: 2, - } - ); + assert_eq!(txq.status(NonceReady::default()), Status { stalled: 0, pending: 9, future: 2 }); + assert_eq!(txq.status(NonceReady::new(1)), Status { stalled: 3, pending: 6, future: 2 }); txq.update_scores(&Address::zero(), ()); @@ -490,35 +403,14 @@ fn should_cull_stalled_transactions() { import(&mut txq, b.tx().sender(1).nonce(1).new()).unwrap(); import(&mut txq, b.tx().sender(1).nonce(5).new()).unwrap(); - assert_eq!( - txq.status(NonceReady::new(1)), - Status { - stalled: 2, - pending: 2, - future: 2, - } - ); + assert_eq!(txq.status(NonceReady::new(1)), Status { stalled: 2, pending: 2, future: 2 }); // when assert_eq!(txq.cull(None, NonceReady::new(1)), 2); // then - assert_eq!( - txq.status(NonceReady::new(1)), - Status { - stalled: 0, - pending: 2, - future: 2, - } - ); - assert_eq!( - txq.light_status(), - LightStatus { - transaction_count: 4, - senders: 2, - mem_usage: 0, - } - ); + assert_eq!(txq.status(NonceReady::new(1)), Status { stalled: 0, pending: 2, future: 2 }); + assert_eq!(txq.light_status(), LightStatus { transaction_count: 4, senders: 2, mem_usage: 0 }); } #[test] @@ -534,36 +426,15 @@ fn should_cull_stalled_transactions_from_a_sender() { import(&mut txq, b.tx().sender(1).nonce(1).new()).unwrap(); import(&mut txq, b.tx().sender(1).nonce(2).new()).unwrap(); - assert_eq!( - txq.status(NonceReady::new(2)), - Status { - stalled: 4, - pending: 1, - future: 0, - } - ); + assert_eq!(txq.status(NonceReady::new(2)), Status { stalled: 4, pending: 1, future: 0 }); // when let sender = Address::zero(); assert_eq!(txq.cull(Some(&[sender]), NonceReady::new(2)), 2); // then - assert_eq!( - txq.status(NonceReady::new(2)), - Status { - stalled: 2, - pending: 1, - future: 0, - } - ); - assert_eq!( - txq.light_status(), - LightStatus { - transaction_count: 3, - senders: 1, - mem_usage: 0, - } - ); + assert_eq!(txq.status(NonceReady::new(2)), Status { stalled: 2, pending: 1, future: 0 }); + assert_eq!(txq.light_status(), LightStatus { transaction_count: 3, senders: 1, mem_usage: 0 }); } #[test] @@ -576,36 +447,15 @@ fn should_re_insert_after_cull() { import(&mut txq, b.tx().nonce(1).new()).unwrap(); import(&mut txq, b.tx().sender(1).nonce(0).new()).unwrap(); import(&mut txq, b.tx().sender(1).nonce(1).new()).unwrap(); - assert_eq!( - txq.status(NonceReady::new(1)), - Status { - stalled: 2, - pending: 2, - future: 0, - } - ); + assert_eq!(txq.status(NonceReady::new(1)), Status { stalled: 2, pending: 2, future: 0 }); // when assert_eq!(txq.cull(None, NonceReady::new(1)), 2); - assert_eq!( - txq.status(NonceReady::new(1)), - Status { - stalled: 0, - pending: 2, - future: 0, - } - ); + assert_eq!(txq.status(NonceReady::new(1)), Status { stalled: 0, pending: 2, future: 0 }); import(&mut txq, b.tx().nonce(0).gas_price(5).new()).unwrap(); import(&mut txq, b.tx().sender(1).nonce(0).new()).unwrap(); - assert_eq!( - txq.status(NonceReady::new(1)), - Status { - stalled: 2, - pending: 2, - future: 0, - } - ); + assert_eq!(txq.status(NonceReady::new(1)), Status { stalled: 2, pending: 2, future: 0 }); } #[test] @@ -644,37 +494,15 @@ fn should_return_is_full() { fn should_import_even_if_limit_is_reached_and_should_replace_returns_insert_new() { // given let b = TransactionBuilder::default(); - let mut txq = TestPool::with_scoring( - DummyScoring::always_insert(), - Options { - max_count: 1, - ..Default::default() - }, - ); - txq.import(b.tx().nonce(0).gas_price(5).new(), &mut DummyScoring::always_insert()) - .unwrap(); - assert_eq!( - txq.light_status(), - LightStatus { - transaction_count: 1, - senders: 1, - mem_usage: 0, - } - ); + let mut txq = TestPool::with_scoring(DummyScoring::always_insert(), Options { max_count: 1, ..Default::default() }); + txq.import(b.tx().nonce(0).gas_price(5).new(), &mut DummyScoring::always_insert()).unwrap(); + assert_eq!(txq.light_status(), LightStatus { transaction_count: 1, senders: 1, mem_usage: 0 }); // when - txq.import(b.tx().nonce(1).gas_price(5).new(), &mut DummyScoring::always_insert()) - .unwrap(); + txq.import(b.tx().nonce(1).gas_price(5).new(), &mut DummyScoring::always_insert()).unwrap(); // then - assert_eq!( - txq.light_status(), - LightStatus { - transaction_count: 2, - senders: 1, - mem_usage: 0, - } - ); + assert_eq!(txq.light_status(), LightStatus { transaction_count: 2, senders: 1, mem_usage: 0 }); } #[test] @@ -683,22 +511,9 @@ fn should_not_import_even_if_limit_is_reached_and_should_replace_returns_false() // given let b = TransactionBuilder::default(); - let mut txq = TestPool::with_scoring( - DummyScoring::default(), - Options { - max_count: 1, - ..Default::default() - }, - ); + let mut txq = TestPool::with_scoring(DummyScoring::default(), Options { max_count: 1, ..Default::default() }); import(&mut txq, b.tx().nonce(0).gas_price(5).new()).unwrap(); - assert_eq!( - txq.light_status(), - LightStatus { - transaction_count: 1, - senders: 1, - mem_usage: 0, - } - ); + assert_eq!(txq.light_status(), LightStatus { transaction_count: 1, senders: 1, mem_usage: 0 }); // when let err = import(&mut txq, b.tx().nonce(1).gas_price(5).new()).unwrap_err(); @@ -711,14 +526,7 @@ fn should_not_import_even_if_limit_is_reached_and_should_replace_returns_false() "0x5".into() ) ); - assert_eq!( - txq.light_status(), - LightStatus { - transaction_count: 1, - senders: 1, - mem_usage: 0, - } - ); + assert_eq!(txq.light_status(), LightStatus { transaction_count: 1, senders: 1, mem_usage: 0 }); } #[test] @@ -727,36 +535,16 @@ fn should_import_even_if_sender_limit_is_reached() { let b = TransactionBuilder::default(); let mut txq = TestPool::with_scoring( DummyScoring::always_insert(), - Options { - max_count: 1, - max_per_sender: 1, - ..Default::default() - }, - ); - txq.import(b.tx().nonce(0).gas_price(5).new(), &mut DummyScoring::always_insert()) - .unwrap(); - assert_eq!( - txq.light_status(), - LightStatus { - transaction_count: 1, - senders: 1, - mem_usage: 0, - } + Options { max_count: 1, max_per_sender: 1, ..Default::default() }, ); + txq.import(b.tx().nonce(0).gas_price(5).new(), &mut DummyScoring::always_insert()).unwrap(); + assert_eq!(txq.light_status(), LightStatus { transaction_count: 1, senders: 1, mem_usage: 0 }); // when - txq.import(b.tx().nonce(1).gas_price(5).new(), &mut DummyScoring::always_insert()) - .unwrap(); + txq.import(b.tx().nonce(1).gas_price(5).new(), &mut DummyScoring::always_insert()).unwrap(); // then - assert_eq!( - txq.light_status(), - LightStatus { - transaction_count: 2, - senders: 1, - mem_usage: 0, - } - ); + assert_eq!(txq.light_status(), LightStatus { transaction_count: 2, senders: 1, mem_usage: 0 }); } mod listener { @@ -771,9 +559,7 @@ mod listener { impl Listener for MyListener { fn added(&mut self, _tx: &SharedTransaction, old: Option<&SharedTransaction>) { - self.0 - .borrow_mut() - .push(if old.is_some() { "replaced" } else { "added" }); + self.0.borrow_mut().push(if old.is_some() { "replaced" } else { "added" }); } fn rejected(&mut self, _tx: &SharedTransaction, _reason: &error::Error) { @@ -805,11 +591,7 @@ mod listener { let mut txq = Pool::new( listener, DummyScoring::default(), - Options { - max_per_sender: 1, - max_count: 2, - ..Default::default() - }, + Options { max_per_sender: 1, max_count: 2, ..Default::default() }, ); assert!(results.borrow().is_empty()); diff --git a/transaction-pool/src/transactions.rs b/transaction-pool/src/transactions.rs index f093758e4..5fc963d78 100644 --- a/transaction-pool/src/transactions.rs +++ b/transaction-pool/src/transactions.rs @@ -45,10 +45,7 @@ pub struct Transactions> { impl> Default for Transactions { fn default() -> Self { - Transactions { - transactions: Default::default(), - scores: Default::default(), - } + Transactions { transactions: Default::default(), scores: Default::default() } } } @@ -77,17 +74,14 @@ impl> Transactions { } pub fn find_next(&self, tx: &T, scoring: &S) -> Option<(S::Score, Transaction)> { - self.transactions - .binary_search_by(|old| scoring.compare(old, &tx)) - .ok() - .and_then(|index| { - let index = index + 1; - if index < self.scores.len() { - Some((self.scores[index].clone(), self.transactions[index].clone())) - } else { - None - } - }) + self.transactions.binary_search_by(|old| scoring.compare(old, &tx)).ok().and_then(|index| { + let index = index + 1; + if index < self.scores.len() { + Some((self.scores[index].clone(), self.transactions[index].clone())) + } else { + None + } + }) } fn push_cheapest_transaction( @@ -127,10 +121,7 @@ impl> Transactions { // Decide if the transaction should replace some other. match scoring.choose(&self.transactions[index], &new) { // New transaction should be rejected - scoring::Choice::RejectNew => AddResult::TooCheap { - old: self.transactions[index].clone(), - new, - }, + scoring::Choice::RejectNew => AddResult::TooCheap { old: self.transactions[index].clone(), new }, // New transaction should be kept along with old ones. scoring::Choice::InsertNew => { self.transactions.insert(index, new.clone()); @@ -204,9 +195,7 @@ impl> Transactions { for _ in 0..first_non_stalled { self.scores.pop(); result.push( - self.transactions - .pop() - .expect("first_non_stalled is never greater than transactions.len(); qed"), + self.transactions.pop().expect("first_non_stalled is never greater than transactions.len(); qed"), ); } @@ -214,11 +203,7 @@ impl> Transactions { self.scores.reverse(); // update scoring - scoring.update_scores( - &self.transactions, - &mut self.scores, - scoring::Change::Culled(result.len()), - ); + scoring.update_scores(&self.transactions, &mut self.scores, scoring::Change::Culled(result.len())); // reverse the result to maintain correct order. result.reverse(); diff --git a/triehash/src/lib.rs b/triehash/src/lib.rs index 2d8a26af1..41b2a0d17 100644 --- a/triehash/src/lib.rs +++ b/triehash/src/lib.rs @@ -26,11 +26,7 @@ use hash_db::Hasher; use rlp::RlpStream; fn shared_prefix_len(first: &[T], second: &[T]) -> usize { - first - .iter() - .zip(second.iter()) - .position(|(f, s)| f != s) - .unwrap_or_else(|| cmp::min(first.len(), second.len())) + first.iter().zip(second.iter()).position(|(f, s)| f != s).unwrap_or_else(|| cmp::min(first.len(), second.len())) } /// Generates a trie root hash for a vector of values @@ -105,11 +101,7 @@ where } // then move them to a vector - let input = input - .into_iter() - .zip(lens.windows(2)) - .map(|((_, v), w)| (&nibbles[w[0]..w[1]], v)) - .collect::>(); + let input = input.into_iter().zip(lens.windows(2)).map(|((_, v), w)| (&nibbles[w[0]..w[1]], v)).collect::>(); let mut stream = RlpStream::new(); hash256rlp::(&input, 0, &mut stream); @@ -215,9 +207,7 @@ where // skip first tuple .skip(1) // get minimum number of shared nibbles between first and each successive - .fold(key.len(), |acc, &(ref k, _)| { - cmp::min(shared_prefix_len(key, k.as_ref()), acc) - }); + .fold(key.len(), |acc, &(ref k, _)| cmp::min(shared_prefix_len(key, k.as_ref()), acc)); // if shared prefix is higher than current prefix append its // new part of the key to the stream @@ -239,11 +229,7 @@ where // iterate over all possible nibbles for i in 0..16 { // count how many successive elements have same next nibble - let len = input - .iter() - .skip(begin) - .take_while(|pair| pair.0.as_ref()[pre_len] == i) - .count(); + let len = input.iter().skip(begin).take_while(|pair| pair.0.as_ref()[pre_len] == i).count(); // if at least 1 successive element has the same nibble // append their suffixes diff --git a/uint/benches/bigint.rs b/uint/benches/bigint.rs index e4e326148..ea0284cdd 100644 --- a/uint/benches/bigint.rs +++ b/uint/benches/bigint.rs @@ -106,11 +106,7 @@ fn u128_div(c: &mut Criterion) { black_box(x / u128::from(*z)) }) }, - vec![ - (0u64, u64::max_value(), 100u64), - (u64::max_value(), u64::max_value(), 99), - (42, 42, 100500), - ], + vec![(0u64, u64::max_value(), 100u64), (u64::max_value(), u64::max_value(), 99), (42, 42, 100500)], ), ); } @@ -162,10 +158,7 @@ fn u256_mul(c: &mut Criterion) { vec![ (U256::max_value(), 1u64), (U256::from(3), u64::max_value()), - ( - U256::from_dec_str("21674844646682989462120101885968193938394323990565507610662749").unwrap(), - 173, - ), + (U256::from_dec_str("21674844646682989462120101885968193938394323990565507610662749").unwrap(), 173), ], ), ); @@ -245,10 +238,7 @@ fn u256_rem(c: &mut Criterion) { |b, (x, y)| b.iter(|| black_box(x % y)), vec![ (U256::max_value(), U256::from(1u64)), - ( - U256::from(u64::max_value()), - U256::from(u64::from(u32::max_value()) + 1), - ), + (U256::from(u64::max_value()), U256::from(u64::from(u32::max_value()) + 1)), ( U256([12767554894655550452, 16333049135534778834, 140317443000293558, 598963]), U256([2096410819092764509, 8483673822214032535, 36306297304129857, 3453]), @@ -265,31 +255,10 @@ fn u256_rem(c: &mut Criterion) { fn u512_pairs() -> Vec<(U512, U512)> { vec![ (U512::from(1u64), U512::from(0u64)), + (U512::from(u64::max_value()), U512::from(u64::from(u32::max_value()) + 1)), ( - U512::from(u64::max_value()), - U512::from(u64::from(u32::max_value()) + 1), - ), - ( - U512([ - 12767554894655550452, - 16333049135534778834, - 140317443000293558, - 598963, - 0, - 0, - 0, - 0, - ]), - U512([ - 0, - 0, - 0, - 0, - 2096410819092764509, - 8483673822214032535, - 36306297304129857, - 3453, - ]), + U512([12767554894655550452, 16333049135534778834, 140317443000293558, 598963, 0, 0, 0, 0]), + U512([0, 0, 0, 0, 2096410819092764509, 8483673822214032535, 36306297304129857, 3453]), ), ( U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(), @@ -299,31 +268,20 @@ fn u512_pairs() -> Vec<(U512, U512)> { } fn u512_add(c: &mut Criterion) { - c.bench( - "u512_add", - ParameterizedBenchmark::new("", |b, (x, y)| b.iter(|| black_box(x + y)), u512_pairs()), - ); + c.bench("u512_add", ParameterizedBenchmark::new("", |b, (x, y)| b.iter(|| black_box(x + y)), u512_pairs())); } fn u512_sub(c: &mut Criterion) { c.bench( "u512_sub", - ParameterizedBenchmark::new( - "", - |b, (x, y)| b.iter(|| black_box(x.overflowing_sub(*y).0)), - u512_pairs(), - ), + ParameterizedBenchmark::new("", |b, (x, y)| b.iter(|| black_box(x.overflowing_sub(*y).0)), u512_pairs()), ); } fn u512_mul(c: &mut Criterion) { c.bench( "u512_mul", - ParameterizedBenchmark::new( - "", - |b, (x, y)| b.iter(|| black_box(x.overflowing_mul(*y).0)), - u512_pairs(), - ), + ParameterizedBenchmark::new("", |b, (x, y)| b.iter(|| black_box(x.overflowing_mul(*y).0)), u512_pairs()), ); } @@ -378,12 +336,8 @@ fn u512_rem(c: &mut Criterion) { fn conversions(c: &mut Criterion) { c.bench( "conversions biguint vs gmp", - ParameterizedBenchmark::new( - "BigUint", - |b, i| bench_convert_to_biguit(b, *i), - vec![0, 42, u64::max_value()], - ) - .with_function("gmp", |b, i| bench_convert_to_gmp(b, *i)), + ParameterizedBenchmark::new("BigUint", |b, i| bench_convert_to_biguit(b, *i), vec![0, 42, u64::max_value()]) + .with_function("gmp", |b, i| bench_convert_to_gmp(b, *i)), ); } @@ -470,9 +424,7 @@ fn bench_u512_mulmod(b: &mut Bencher, z: U256) { // NOTE: uses native `u128` and does not measure this crates performance, // but might be interesting as a comparison. fn u128_mul(c: &mut Criterion) { - c.bench_function("u128_mul", |b| { - b.iter(|| black_box(12345u128 * u128::from(u64::max_value()))) - }); + c.bench_function("u128_mul", |b| b.iter(|| black_box(12345u128 * u128::from(u64::max_value())))); } fn u256_bit_and(c: &mut Criterion) { @@ -681,9 +633,8 @@ fn from_fixed_array(c: &mut Criterion) { 255, 0, 0, 123, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 121, 0, 0, 0, 0, 0, 213, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, 67, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 123, ]; - let ary256: [u8; 32] = [ - 255, 0, 0, 123, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 121, 0, 0, 0, 0, 0, 213, 0, 0, 0, 0, 0, 0, - ]; + let ary256: [u8; 32] = + [255, 0, 0, 123, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 121, 0, 0, 0, 0, 0, 213, 0, 0, 0, 0, 0, 0]; c.bench_function("from_fixed_array", move |b| { b.iter(|| { let _: U512 = black_box(ary512.into()); diff --git a/uint/tests/uint_tests.rs b/uint/tests/uint_tests.rs index 2d43e761e..ddeb747c3 100644 --- a/uint/tests/uint_tests.rs +++ b/uint/tests/uint_tests.rs @@ -77,14 +77,8 @@ fn uint256_from() { assert_eq!(U256([0x1010, 0, 0, 0]), U256::from(&[0x10u8, 0x10][..])); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from(&[0x12u8, 0xf0][..])); assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from(&[0, 0x12u8, 0xf0][..])); - assert_eq!( - U256([0x12f0, 0, 0, 0]), - U256::from(&[0, 0, 0, 0, 0, 0, 0, 0x12u8, 0xf0][..]) - ); - assert_eq!( - U256([0x12f0, 1, 0, 0]), - U256::from(&[1, 0, 0, 0, 0, 0, 0, 0x12u8, 0xf0][..]) - ); + assert_eq!(U256([0x12f0, 0, 0, 0]), U256::from(&[0, 0, 0, 0, 0, 0, 0, 0x12u8, 0xf0][..])); + assert_eq!(U256([0x12f0, 1, 0, 0]), U256::from(&[1, 0, 0, 0, 0, 0, 0, 0x12u8, 0xf0][..])); assert_eq!( U256([0x12f0, 1, 0x0910203040506077, 0x8090a0b0c0d0e0f0]), U256::from( @@ -194,10 +188,7 @@ fn uint256_from() { fn uint256_try_into_primitives() { macro_rules! try_into_uint_primitive_ok { ($primitive: ty) => { - assert_eq!( - U256::from(10).try_into() as Result<$primitive, _>, - Ok(<$primitive>::from(10u8)) - ); + assert_eq!(U256::from(10).try_into() as Result<$primitive, _>, Ok(<$primitive>::from(10u8))); }; } try_into_uint_primitive_ok!(u8); @@ -209,10 +200,7 @@ fn uint256_try_into_primitives() { macro_rules! try_into_iint_primitive_ok { ($primitive: ty) => { - assert_eq!( - U256::from(10).try_into() as Result<$primitive, _>, - Ok(<$primitive>::from(10i8)) - ); + assert_eq!(U256::from(10).try_into() as Result<$primitive, _>, Ok(<$primitive>::from(10i8))); }; } try_into_iint_primitive_ok!(i8); @@ -235,20 +223,14 @@ fn uint256_try_into_primitives() { try_into_primitive_err!(u32, u64); try_into_primitive_err!(usize, u128); try_into_primitive_err!(u64, u128); - assert_eq!( - U256([0, 0, 1, 0]).try_into() as Result, - Err("integer overflow when casting to u128") - ); + assert_eq!(U256([0, 0, 1, 0]).try_into() as Result, Err("integer overflow when casting to u128")); try_into_primitive_err!(i8, i16); try_into_primitive_err!(i16, i32); try_into_primitive_err!(i32, i64); try_into_primitive_err!(isize, i128); try_into_primitive_err!(i64, i128); try_into_primitive_err!(i128, u128); - assert_eq!( - U256([0, 0, 1, 0]).try_into() as Result, - Err("integer overflow when casting to i128") - ); + assert_eq!(U256([0, 0, 1, 0]).try_into() as Result, Err("integer overflow when casting to i128")); } #[test] @@ -451,10 +433,7 @@ pub fn display_u512() { fn uint256_overflowing_pow() { assert_eq!( U256::from(2).overflowing_pow(U256::from(0xff)), - ( - U256::from_str("8000000000000000000000000000000000000000000000000000000000000000").unwrap(), - false - ) + (U256::from_str("8000000000000000000000000000000000000000000000000000000000000000").unwrap(), false) ); assert_eq!(U256::from(2).overflowing_pow(U256::from(0x100)), (U256::zero(), true)); } @@ -469,10 +448,7 @@ fn uint256_mul2() { let a = U512::from_str("10000000000000000fffffffffffffffe").unwrap(); let b = U512::from_str("ffffffffffffffffffffffffffffffff").unwrap(); - assert_eq!( - a * b, - U512::from_str("10000000000000000fffffffffffffffcffffffffffffffff0000000000000002").unwrap() - ); + assert_eq!(a * b, U512::from_str("10000000000000000fffffffffffffffcffffffffffffffff0000000000000002").unwrap()); } #[test] @@ -498,11 +474,9 @@ fn uint512_mul() { #[test] fn uint256_mul_overflow() { assert_eq!( - U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") - .unwrap() - .overflowing_mul( - U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() - ), + U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap().overflowing_mul( + U256::from_str("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap() + ), (U256::from_str("1").unwrap(), true) ); } @@ -518,13 +492,8 @@ fn uint256_mul_overflow_panic() { #[test] fn uint256_sub_overflow() { assert_eq!( - U256::from_str("0") - .unwrap() - .overflowing_sub(U256::from_str("1").unwrap()), - ( - U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap(), - true - ) + U256::from_str("0").unwrap().overflowing_sub(U256::from_str("1").unwrap()), + (U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap(), true) ); } @@ -940,10 +909,7 @@ fn example() { for _ in 0..200 { val = val * U256::from(2) } - assert_eq!( - &format!("{}", val), - "1643897619276947051879427220465009342380213662639797070513307648" - ); + assert_eq!(&format!("{}", val), "1643897619276947051879427220465009342380213662639797070513307648"); } #[test] @@ -1008,9 +974,8 @@ fn slice_roundtrip_le2() { #[test] fn from_little_endian() { - let source: [u8; 32] = [ - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]; + let source: [u8; 32] = + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; let number = U256::from_little_endian(&source[..]); @@ -1019,9 +984,8 @@ fn from_little_endian() { #[test] fn from_big_endian() { - let source: [u8; 32] = [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - ]; + let source: [u8; 32] = + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]; let number = U256::from_big_endian(&source[..]); @@ -1030,18 +994,15 @@ fn from_big_endian() { #[test] fn into_fixed_array() { - let expected: [u8; 32] = [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - ]; + let expected: [u8; 32] = + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]; let ary: [u8; 32] = U256::from(1).into(); assert_eq!(ary, expected); } #[test] fn test_u256_from_fixed_array() { - let ary = [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 123, - ]; + let ary = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 123]; let num: U256 = ary.into(); assert_eq!(num, U256::from(std::u64::MAX) + 1 + 123); @@ -1051,20 +1012,11 @@ fn test_u256_from_fixed_array() { #[test] fn test_from_ref_to_fixed_array() { - let ary: &[u8; 32] = &[ - 1, 0, 1, 2, 1, 0, 1, 2, 3, 0, 3, 4, 3, 0, 3, 4, 5, 0, 5, 6, 5, 0, 5, 6, 7, 0, 7, 8, 7, 0, 7, 8, - ]; + let ary: &[u8; 32] = + &[1, 0, 1, 2, 1, 0, 1, 2, 3, 0, 3, 4, 3, 0, 3, 4, 5, 0, 5, 6, 5, 0, 5, 6, 7, 0, 7, 8, 7, 0, 7, 8]; let big: U256 = ary.into(); // the numbers are each row of 8 bytes reversed and cast to u64 - assert_eq!( - big, - U256([ - 504410889324070664, - 360293493601469702, - 216176097878868740, - 72058702156267778u64 - ]) - ); + assert_eq!(big, U256([504410889324070664, 360293493601469702, 216176097878868740, 72058702156267778u64])); } #[test] @@ -1082,42 +1034,18 @@ fn test_u512_from_fixed_array() { #[test] fn leading_zeros() { - assert_eq!( - U256::from("000000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1").leading_zeros(), - 95 - ); - assert_eq!( - U256::from("f00000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1").leading_zeros(), - 0 - ); - assert_eq!( - U256::from("0000000000000000000000000000000000000000000000000000000000000001").leading_zeros(), - 255 - ); - assert_eq!( - U256::from("0000000000000000000000000000000000000000000000000000000000000000").leading_zeros(), - 256 - ); + assert_eq!(U256::from("000000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1").leading_zeros(), 95); + assert_eq!(U256::from("f00000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1").leading_zeros(), 0); + assert_eq!(U256::from("0000000000000000000000000000000000000000000000000000000000000001").leading_zeros(), 255); + assert_eq!(U256::from("0000000000000000000000000000000000000000000000000000000000000000").leading_zeros(), 256); } #[test] fn trailing_zeros() { - assert_eq!( - U256::from("1adbdd6bd6ff027485484b97f8a6a4c7129756dd100000000000000000000000").trailing_zeros(), - 92 - ); - assert_eq!( - U256::from("1adbdd6bd6ff027485484b97f8a6a4c7129756dd10000000000000000000000f").trailing_zeros(), - 0 - ); - assert_eq!( - U256::from("8000000000000000000000000000000000000000000000000000000000000000").trailing_zeros(), - 255 - ); - assert_eq!( - U256::from("0000000000000000000000000000000000000000000000000000000000000000").trailing_zeros(), - 256 - ); + assert_eq!(U256::from("1adbdd6bd6ff027485484b97f8a6a4c7129756dd100000000000000000000000").trailing_zeros(), 92); + assert_eq!(U256::from("1adbdd6bd6ff027485484b97f8a6a4c7129756dd10000000000000000000000f").trailing_zeros(), 0); + assert_eq!(U256::from("8000000000000000000000000000000000000000000000000000000000000000").trailing_zeros(), 255); + assert_eq!(U256::from("0000000000000000000000000000000000000000000000000000000000000000").trailing_zeros(), 256); } #[cfg(feature = "quickcheck")] From 87db8dff8d0687e68229ad867462dfa3e966116d Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Mon, 28 Oct 2019 12:20:34 +0100 Subject: [PATCH 09/15] fix CI --- rustfmt.toml | 3 +++ uint/src/uint.rs | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index cba0d885c..1aedb923e 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,6 @@ hard_tabs = true max_width = 120 use_small_heuristics = "Max" +ignore = [ + "uint/src/uint.rs", +] diff --git a/uint/src/uint.rs b/uint/src/uint.rs index 034636e73..64990bf5c 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -29,8 +29,6 @@ //! implementations for even more speed, hidden behind the `x64_arithmetic` //! feature flag. -#![rustfmt::skip] - /// Conversion from decimal string error #[derive(Debug, PartialEq)] pub enum FromDecStrErr { From e00cbadd8124b8f5ae243dd0de433aeb617f2cd7 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Mon, 28 Oct 2019 12:22:58 +0100 Subject: [PATCH 10/15] argh --- rustfmt.toml | 3 --- uint/src/lib.rs | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index 1aedb923e..cba0d885c 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,6 +1,3 @@ hard_tabs = true max_width = 120 use_small_heuristics = "Max" -ignore = [ - "uint/src/uint.rs", -] diff --git a/uint/src/lib.rs b/uint/src/lib.rs index 519028a9d..bba720be8 100644 --- a/uint/src/lib.rs +++ b/uint/src/lib.rs @@ -35,5 +35,6 @@ pub use static_assertions; pub use crunchy::unroll; #[macro_use] +#[rustfmt::skip] mod uint; pub use crate::uint::*; From a517a0136b2c3cc2448721139dc6ae4a4bdca3d9 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Mon, 28 Oct 2019 12:40:29 +0100 Subject: [PATCH 11/15] CONTRIBUTING: mention gitter --- CONTRIBUTING.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2727bb7a4..bbe6e0c0e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,9 @@ parity-common welcomes contribution from everyone in the form of suggestions, bu reports, pull requests, and feedback. This document gives some guidance if you are thinking of helping us. -Please reach out here in a GitHub issue if we can do anything to help you contribute. +Please reach out here in a GitHub issue or in the parity channel on [gitter] if we can do anything to help you contribute. + +[gitter]: https://gitter.im/paritytech/parity ## Submitting bug reports and feature requests @@ -37,8 +39,8 @@ When making a new release make sure to follow these steps: After the PR is merged into master: * `cargo publish` on the latest master (try with `--dry-run` first) -* Add a git tag in format `-v`, -e.g. `git tag impl-serde-v0.2.2` and push it with `git push origin impl-serde-v0.2.2` +* Add a git tag in format `-v`, +e.g. `git tag impl-serde-v0.2.2` and push it with `git push origin impl-serde-v0.2.2` ## Conduct From 3fd73cbc6a61afedebd3118445dabbfaea778714 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Tue, 29 Oct 2019 15:31:47 +0100 Subject: [PATCH 12/15] impl-serde: bump to 0.2.3 --- primitive-types/impls/serde/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitive-types/impls/serde/Cargo.toml b/primitive-types/impls/serde/Cargo.toml index 0e2342f34..dc01bc6ab 100644 --- a/primitive-types/impls/serde/Cargo.toml +++ b/primitive-types/impls/serde/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "impl-serde" -version = "0.2.2" +version = "0.2.3" authors = ["Parity Technologies "] edition = "2018" license = "Apache-2.0/MIT" From 6a33a17f0d0f0ade0c7fb77c7d3a5fa24e42657e Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Tue, 29 Oct 2019 15:55:57 +0100 Subject: [PATCH 13/15] Revert "impl-serde: bump to 0.2.3" This reverts commit 3fd73cbc6a61afedebd3118445dabbfaea778714. --- primitive-types/impls/serde/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitive-types/impls/serde/Cargo.toml b/primitive-types/impls/serde/Cargo.toml index dc01bc6ab..0e2342f34 100644 --- a/primitive-types/impls/serde/Cargo.toml +++ b/primitive-types/impls/serde/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "impl-serde" -version = "0.2.3" +version = "0.2.2" authors = ["Parity Technologies "] edition = "2018" license = "Apache-2.0/MIT" From 7f946cea067b0016f1d40f42e35afdba86097474 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Tue, 29 Oct 2019 16:02:54 +0100 Subject: [PATCH 14/15] fmt --- primitive-types/impls/serde/src/serialize.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/primitive-types/impls/serde/src/serialize.rs b/primitive-types/impls/serde/src/serialize.rs index 050a5460f..59d117fd0 100644 --- a/primitive-types/impls/serde/src/serialize.rs +++ b/primitive-types/impls/serde/src/serialize.rs @@ -231,10 +231,10 @@ where mod tests { extern crate serde_derive; - use self::serde_derive::{Serialize, Deserialize}; + use self::serde_derive::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] - struct Bytes(#[serde(with="super")] Vec); + struct Bytes(#[serde(with = "super")] Vec); #[test] fn should_not_fail_on_short_string() { From 444ce01f0f3d5deaf939c8eb91117a78e56d9ac8 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Wed, 30 Oct 2019 10:22:55 +0100 Subject: [PATCH 15/15] impl-serde: update changelog for 0.2.3 --- primitive-types/impls/serde/CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/primitive-types/impls/serde/CHANGELOG.md b/primitive-types/impls/serde/CHANGELOG.md index 927c9dc9c..a63cfb2f1 100644 --- a/primitive-types/impls/serde/CHANGELOG.md +++ b/primitive-types/impls/serde/CHANGELOG.md @@ -1,7 +1,11 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.2.3] - 2019-10-29 +### Fixed +- Fixed a bug in empty slice serialization (https://github.com/paritytech/parity-common/pull/253)