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
375 changes: 286 additions & 89 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ws = { git = "https://github.com/oasislabs/ws-rs", branch = "ekiden" }

[patch.crates-io]
# TODO: Remove when merged upstream (briansmith/ring#738).
ring = { git = "https://github.com/akash-fortanix/ring", branch = "sgx-target" }
ring = { git = "https://github.com/oasislabs/ring-sgx", branch = "sgx-target" }
# TODO: Remove when merged upstream (rust-lang-deprecated/rustc-serialize#195).
rustc-serialize = { git = "https://github.com/jethrogb/rustc-serialize", branch = "portability" }

Expand Down
4 changes: 2 additions & 2 deletions ekiden_crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ deoxysii = { git = "https://github.com/oasislabs/deoxysii-rust" }
failure = "0.1.5"
rand = "0.6.5"
# TODO: Change version when merged upstream (briansmith/ring#738).
ring = "=0.14.5"
ring = "0.16"
rustc-hex = "2.0.1"
serde = "1.0.71"
serde_derive = "1.0"
untrusted = "0.6.2"
untrusted = "0.7"
x25519-dalek = "0.5.1"
2 changes: 1 addition & 1 deletion ekiden_crypto/src/mrae/deoxysii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn derive_symmetric_key(public: &[u8; 32], private: &[u8; 32]) -> [u8; KEY_SIZE]

let pmk = private.diffie_hellman(&public);

let k = hmac::SigningKey::new(&digest::SHA256, b"MRAE_Box_Deoxys-II-256-128");
let k = hmac::SigningKey::new(hmac::HMAC_SHA256, b"MRAE_Box_Deoxys-II-256-128");
let mut ctx = hmac::SigningContext::with_key(&k);

ctx.update(pmk.as_bytes());
Expand Down
14 changes: 8 additions & 6 deletions ekiden_crypto/src/signature.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! Signature types.
use failure::Fallible;
use failure::{format_err, Fallible};
use ring::{
rand,
signature::{verify, Ed25519KeyPair, KeyPair, ED25519},
signature::{Ed25519KeyPair, KeyPair, VerificationAlgorithm as _, ED25519},
};
use serde_derive::{Deserialize, Serialize};
use untrusted;

use super::hash::Hash;

Expand All @@ -22,14 +21,15 @@ impl PrivateKey {
.unwrap()
.as_ref()
.to_vec();
let key = Ed25519KeyPair::from_pkcs8(untrusted::Input::from(&key_pkcs8)).unwrap();
let key = Ed25519KeyPair::from_pkcs8(&key_pkcs8).unwrap();

PrivateKey(key)
}

/// Loads the private key pair from PKCS8 encoded data.
pub fn from_pkcs8(key: &[u8]) -> Fallible<Self> {
let key = Ed25519KeyPair::from_pkcs8(untrusted::Input::from(key))?;
let key = Ed25519KeyPair::from_pkcs8(key)
.map_err(|e| format_err!("could not parse private key: {}", e))?;
Ok(PrivateKey(key))
}

Expand Down Expand Up @@ -64,7 +64,9 @@ impl Signature {
let digest = untrusted::Input::from(digest.as_ref());
let sig = untrusted::Input::from(self.as_ref());

Ok(verify(&ED25519, pk, digest, sig)?)
Ok(ED25519
.verify(pk, digest, sig)
.map_err(|_| format_err!("signature verification failed"))?)
}
}

Expand Down
27 changes: 15 additions & 12 deletions src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use ethcore::{
state::State,
transaction::{Action, LocalizedTransaction, SignedTransaction, UnverifiedTransaction},
types::ids::BlockId,
vm::{EnvInfo, Error as VmError},
vm::{CreateContractAddress, EnvInfo, Error as VmError, OasisContract},
};
use ethereum_types::{Bloom, H256, H64, U256};
use failure::{format_err, Error, Fallible};
Expand Down Expand Up @@ -404,15 +404,19 @@ impl Blockchain {
gas_used: outcome.receipt.gas_used,
contract_address: match txn.action {
Action::Call(_) => None,
Action::Create => Some(
contract_address(
genesis::SPEC.engine.create_address_scheme(number),
&txn.sender(),
&txn.nonce,
&txn.data,
)
.0,
),
Action::Create => {
let address_scheme = OasisContract::from_code(&txn.data)
.ok()
.flatten()
.and_then(|hdr| {
hdr.salt_if_confidential
.map(|salt| CreateContractAddress::FromSaltAndCodeHash(salt.into()))
})
.unwrap_or_else(|| {
genesis::SPEC.engine.machine().create_address_scheme(number)
});
Some(contract_address(address_scheme, &txn.sender(), &txn.nonce, &txn.data).0)
}
},
logs: logs,
log_bloom: outcome.receipt.log_bloom,
Expand Down Expand Up @@ -670,7 +674,6 @@ impl EthereumBlock {

/// Retrieve an Ethereum block with additional metadata.
pub fn rich_block(&self, include_txs: bool) -> EthRpcRichBlock {
let eip86_transition = genesis::SPEC.params().eip86_transition;
let rich_header = self.rich_header();

EthRpcRichBlock {
Expand Down Expand Up @@ -698,7 +701,7 @@ impl EthereumBlock {
self.transactions
.clone()
.into_iter()
.map(|txn| EthRpcTransaction::from_localized(txn, eip86_transition))
.map(|txn| EthRpcTransaction::from_localized(txn))
.collect(),
),
false => EthRpcBlockTransactions::Hashes(
Expand Down
10 changes: 3 additions & 7 deletions src/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,12 @@ impl Eth for EthClient {

fn transaction_by_hash(&self, hash: RpcH256) -> BoxFuture<Option<RpcTransaction>> {
let hash = hash.into();
let eip86_transition = genesis::SPEC.params().eip86_transition;

Box::new(
self.blockchain
.get_txn_by_hash(hash)
.and_then(move |txn| {
txn.map(|txn| Ok(RpcTransaction::from_localized(txn, eip86_transition)))
txn.map(|txn| Ok(RpcTransaction::from_localized(txn)))
.transpose()
})
.map_err(jsonrpc_error),
Expand All @@ -286,13 +285,12 @@ impl Eth for EthClient {
index: Index,
) -> BoxFuture<Option<RpcTransaction>> {
let hash = hash.into();
let eip86_transition = genesis::SPEC.params().eip86_transition;

Box::new(
self.blockchain
.get_txn_by_block_hash_and_index(hash, index.value() as u32)
.and_then(move |txn| {
txn.map(|txn| Ok(RpcTransaction::from_localized(txn, eip86_transition)))
txn.map(|txn| Ok(RpcTransaction::from_localized(txn)))
.transpose()
})
.map_err(jsonrpc_error),
Expand All @@ -309,13 +307,11 @@ impl Eth for EthClient {
return Box::new(future::ok(None));
}

let eip86_transition = genesis::SPEC.params().eip86_transition;

Box::new(
self.blockchain
.get_txn(block_number_to_id(num), index.value() as u32)
.and_then(move |txn| {
txn.map(|txn| Ok(RpcTransaction::from_localized(txn, eip86_transition)))
txn.map(|txn| Ok(RpcTransaction::from_localized(txn)))
.transpose()
})
.map_err(jsonrpc_error),
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

//! Oasis local chain.

#![feature(option_flattening)]

extern crate clap;
extern crate futures;
extern crate lazy_static;
Expand Down