Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
[ethcore-private-tx] fix some compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ordian committed May 17, 2019
1 parent 657afa3 commit 3478523
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
10 changes: 5 additions & 5 deletions ethcore/private-tx/src/encryptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl SecretStoreEncryptor {
let requester = self.config.key_server_account.ok_or_else(|| Error::KeyServerAccountNotSet)?;

// key id in SS is H256 && we have H160 here => expand with assitional zeros
let contract_address_extended: H256 = contract_address.into();
let contract_address_extended: H256 = (*contract_address).into();
let base_url = self.config.base_url.clone().ok_or_else(|| Error::KeyServerNotSet)?;

// prepare request url
Expand Down Expand Up @@ -156,7 +156,7 @@ impl SecretStoreEncryptor {
let decrypted_key = Public::from_slice(&decrypted_bytes);

// and now take x coordinate of Public as a key
let key: Bytes = (*decrypted_key)[..INIT_VEC_LEN].into();
let key: Bytes = decrypted_key.as_bytes()[..INIT_VEC_LEN].into();

// cache the key in the session and clear expired sessions
self.sessions.lock().insert(*contract_address, EncryptionSession{
Expand Down Expand Up @@ -212,11 +212,11 @@ impl Encryptor for SecretStoreEncryptor {
}?;

// encrypt data
let mut cypher = Vec::with_capacity(plain_data.len() + initialisation_vector.len());
let mut cypher = Vec::with_capacity(plain_data.len() + initialisation_vector.as_bytes().len());
cypher.extend(repeat(0).take(plain_data.len()));
crypto::aes::encrypt_128_ctr(&key, initialisation_vector, plain_data, &mut cypher)
crypto::aes::encrypt_128_ctr(&key, initialisation_vector.as_bytes(), plain_data, &mut cypher)
.map_err(|e| Error::Encrypt(e.to_string()))?;
cypher.extend_from_slice(&initialisation_vector);
cypher.extend_from_slice(&initialisation_vector.as_bytes());

Ok(cypher)
}
Expand Down
8 changes: 4 additions & 4 deletions ethcore/private-tx/src/key_server_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ use_contract!(keys_acl_contract, "res/keys_acl.json");

/// Returns the address (of the contract), that corresponds to the key
pub fn key_to_address(key: &H256) -> Address {
Address::from_slice(&key.to_vec()[..10])
Address::from_slice(&key.as_bytes()[..10])
}

/// Returns the key from the key server associated with the contract
pub fn address_to_key(contract_address: &Address) -> H256 {
// Current solution uses contract address extended with 0 as id
let contract_address_extended: H256 = contract_address.into();
let contract_address_extended: H256 = (*contract_address).into();

H256::from_slice(&contract_address_extended)
H256::from_slice(contract_address_extended.as_bytes())
}

/// Trait for keys server keys provider.
Expand Down Expand Up @@ -170,4 +170,4 @@ mod tests {
keys_data.update_acl_contract();
assert_eq!(keys_data.keys_acl_contract.read().unwrap(), key.address());
}
}
}
15 changes: 8 additions & 7 deletions ethcore/private-tx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub use log::{Logging, TransactionLog, ValidatorLog, PrivateTxStatus, FileLogsSe

use std::sync::{Arc, Weak};
use std::collections::{HashMap, HashSet, BTreeMap};
use ethereum_types::{H128, H256, U256, Address};
use ethereum_types::{H128, H256, U256, Address, BigEndianHash};
use hash::keccak;
use rlp::*;
use parking_lot::RwLock;
Expand Down Expand Up @@ -285,9 +285,10 @@ impl Provider {
/// Calculate hash from united private state and contract nonce
pub fn calculate_state_hash(&self, state: &Bytes, nonce: U256) -> H256 {
let state_hash = keccak(state);
let nonce_h256: H256 = BigEndianHash::from_uint(&nonce);
let mut state_buf = [0u8; 64];
state_buf[..32].clone_from_slice(&state_hash);
state_buf[32..].clone_from_slice(&H256::from(nonce));
state_buf[..32].clone_from_slice(state_hash.as_bytes());
state_buf[32..].clone_from_slice(nonce_h256.as_bytes());
keccak(&state_buf.as_ref())
}

Expand Down Expand Up @@ -481,13 +482,13 @@ impl Provider {

fn iv_from_transaction(transaction: &SignedTransaction) -> H128 {
let nonce = keccak(&transaction.nonce.rlp_bytes());
let (iv, _) = nonce.split_at(INIT_VEC_LEN);
let (iv, _) = nonce.as_bytes().split_at(INIT_VEC_LEN);
H128::from_slice(iv)
}

fn iv_from_address(contract_address: &Address) -> H128 {
let address = keccak(&contract_address.rlp_bytes());
let (iv, _) = address.split_at(INIT_VEC_LEN);
let (iv, _) = address.as_bytes().split_at(INIT_VEC_LEN);
H128::from_slice(iv)
}

Expand Down Expand Up @@ -536,8 +537,8 @@ impl Provider {
// Sort the storage to guarantee the order for all parties
let sorted_storage: BTreeMap<&H256, &H256> = storage.iter().collect();
for (key, value) in sorted_storage {
raw.extend_from_slice(key);
raw.extend_from_slice(value);
raw.extend_from_slice(key.as_bytes());
raw.extend_from_slice(value.as_bytes());
};
raw
}
Expand Down
12 changes: 8 additions & 4 deletions ethcore/private-tx/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.

use ethereum_types::{H256, U256, Address};
use ethereum_types::{H256, U256, Address, BigEndianHash};
use bytes::Bytes;
use hash::keccak;
use rlp::Encodable;
Expand All @@ -38,7 +38,7 @@ impl PrivateTransaction {
PrivateTransaction {
encrypted,
contract,
hash: 0.into(),
hash: H256::zero(),
}.compute_hash()
}

Expand Down Expand Up @@ -87,7 +87,7 @@ impl SignedPrivateTransaction {
r: sig.r().into(),
s: sig.s().into(),
v: add_chain_replay_protection(sig.v() as u64, chain_id),
hash: 0.into(),
hash: H256::zero(),
}.compute_hash()
}

Expand All @@ -100,7 +100,11 @@ impl SignedPrivateTransaction {

/// Construct a signature object from the sig.
pub fn signature(&self) -> Signature {
Signature::from_rsv(&self.r.into(), &self.s.into(), self.standard_v())
Signature::from_rsv(
&BigEndianHash::from_uint(&self.r),
&BigEndianHash::from_uint(&self.s),
self.standard_v(),
)
}

/// Get the hash of of the original transaction.
Expand Down

0 comments on commit 3478523

Please sign in to comment.