Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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 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

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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth mentioning the exception of serde that isn't following semver? Caution against rand upgrades?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what to add here. Although serde doesn't follow semver for minor and patch bumping, it will bump major on a breaking change. And not sure how rand is different in terms of breaking changes from other crates. But open to any suggestions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serde: so you're saying we don't need to mention it not following semver because minor/patchreleases are backwards compatible?rand: my thinking was simply that some crate updates are (much) more risky than others, but it's hard to come out and say "don't send PRs to upgrade rand` because it's a mess". But I guess we can handle that as/if PRs come in.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, pretty much


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:
Comment thread
ordian marked this conversation as resolved.
* Submit a PR with a version bump and list all major and breaking changes in the crate's changelog

After the PR is merged into master:
* `cargo publish` on the latest master (try with `--dry-run` first)
* Add a git tag in format `<crate-name>-v<version>`,
e.g. `git tag impl-serde-v0.2.2` and push it with `git push origin impl-serde-v0.2.2`

## 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
7 changes: 7 additions & 0 deletions contract-address/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

The format is based on [Keep a Changelog].

[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/

## [Unreleased]
153 changes: 73 additions & 80 deletions contract-address/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,95 +27,88 @@ 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<ContractAddress> 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);
}
}
11 changes: 11 additions & 0 deletions ethbloom/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 3 additions & 2 deletions ethbloom/benches/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ fn test_bloom() -> Bloom {
00000000000000000000000000000000\
00000000000000000000000000000000\
00000000000000000000000000000000\
00000000000000000000000000000000"
).unwrap()
00000000000000000000000000000000",
)
.unwrap()
}

fn test_topic() -> Vec<u8> {
Expand Down
2 changes: 1 addition & 1 deletion ethbloom/benches/unrolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
});
});
Expand Down
26 changes: 18 additions & 8 deletions ethbloom/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -139,7 +139,10 @@ impl Bloom {
self.contains_bloom(&bloom)
}

pub fn contains_bloom<'a, B>(&self, bloom: B) -> bool where BloomRef<'a>: From<B> {
pub fn contains_bloom<'a, B>(&self, bloom: B) -> bool
where
BloomRef<'a>: From<B>,
{
let bloom_ref: BloomRef<'_> = bloom.into();
// workaround for https://github.com/rust-lang/rust/issues/43644
self.contains_bloom_ref(bloom_ref)
Expand Down Expand Up @@ -182,7 +185,10 @@ impl Bloom {
}
}

pub fn accrue_bloom<'a, B>(&mut self, bloom: B) where BloomRef<'a>: From<B> {
pub fn accrue_bloom<'a, B>(&mut self, bloom: B)
where
BloomRef<'a>: From<B>,
{
let bloom_ref: BloomRef<'_> = bloom.into();
assert_eq!(self.0.len(), BLOOM_SIZE);
assert_eq!(bloom_ref.0.len(), BLOOM_SIZE);
Expand Down Expand Up @@ -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<B> {
pub fn contains_bloom<'b, B>(&self, bloom: B) -> bool
where
BloomRef<'b>: From<B>,
{
let bloom_ref: BloomRef<'_> = bloom.into();
assert_eq!(self.0.len(), BLOOM_SIZE);
assert_eq!(bloom_ref.0.len(), BLOOM_SIZE);
Expand Down Expand Up @@ -249,11 +258,12 @@ 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]
#[rustfmt::skip]
fn it_works() {
let bloom = Bloom::from_str(
"00000000000000000000000000000000\
Expand All @@ -271,7 +281,7 @@ mod tests {
00000000000000000000000000000000\
00000000000000000000000000000000\
00000000000000000000000000000000\
00000000000000000000000000000000"
00000000000000000000000000000000",
).unwrap();
let address = hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106");
let topic = hex!("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc");
Expand Down
9 changes: 9 additions & 0 deletions ethereum-types/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Loading