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

Commit

Permalink
Merge branch 'master' into signer-dapps
Browse files Browse the repository at this point in the history
Conflicts:
	Cargo.lock
	ethcore/res/ethereum/tests
	signer/Cargo.toml
	signer/src/lib.rs
	signer/src/ws_server/session.rs
  • Loading branch information
Tomasz Drwięga committed Oct 17, 2016
2 parents 7c23bb2 + b5c65e3 commit d3998a1
Show file tree
Hide file tree
Showing 82 changed files with 2,222 additions and 1,431 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions dapps/js-glue/src/lib.rs.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,3 @@ pub trait WebApp : Default + Send + Sync {
fn file(&self, path: &str) -> Option<&File>;
fn info(&self) -> Info;
}

#[cfg(test)]
mod tests {
#[test]
fn it_works() {
}
}
3 changes: 2 additions & 1 deletion ethcore/res/ethereum/classic.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"frontierCompatibilityModeLimit": "0x118c30"
"homesteadTransition": "0x118c30",
"eip150Transition": "0x2625a0"
}
}
},
Expand Down
43 changes: 43 additions & 0 deletions ethcore/res/ethereum/eip150_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "Homestead (Test)",
"engine": {
"Ethash": {
"params": {
"gasLimitBoundDivisor": "0x0400",
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"homesteadTransition": "0x0",
"eip150Transition": "0x0"
}
}
},
"params": {
"accountStartNonce": "0x00",
"maximumExtraDataSize": "0x20",
"minGasLimit": "0x1388",
"networkID" : "0x1"
},
"genesis": {
"seal": {
"ethereum": {
"nonce": "0x0000000000000042",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
},
"difficulty": "0x400000000",
"author": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"gasLimit": "0x1388"
},
"accounts": {
"0000000000000000000000000000000000000001": { "balance": "1", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } },
"0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
"0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
"0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } }
}
}
5 changes: 3 additions & 2 deletions ethcore/res/ethereum/expanse.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
"durationLimit": "0x3C",
"blockReward": "0x6f05b59d3b200000",
"registrar" : "0x6c221ca53705f3497ec90ca7b84c59ae7382fc21",
"frontierCompatibilityModeLimit": "0x30d40",
"homesteadTransition": "0x30d40",
"difficultyHardforkTransition": "0x59d9",
"difficultyHardforkBoundDivisor": "0x0200",
"bombDefuseTransition": "0x30d40"
"bombDefuseTransition": "0x30d40",
"eip150Transition": "0x7fffffffffffffff"
}
}
},
Expand Down
7 changes: 4 additions & 3 deletions ethcore/res/ethereum/frontier.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"frontierCompatibilityModeLimit": "0x118c30",
"homesteadTransition": "0x118c30",
"daoHardforkTransition": "0x1d4c00",
"daoHardforkBeneficiary": "0xbf4ed7b27f1d666546e30d74d50d173d20bca754",
"daoHardforkAccounts": [
"daoHardforkAccounts": [
"0xd4fe7bc31cedb7bfb8a345f31e668033056b2728",
"0xb3fb0e5aba0e20e5c49d252dfd30e102b171a425",
"0x2c19c7f9ae8b751e37aeb2d93a699722395ae18f",
Expand Down Expand Up @@ -129,7 +129,8 @@
"0x7602b46df5390e432ef1c307d4f2c9ff6d65cc97",
"0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
"0x807640a13483f8ac783c557fcdf27be11ea4ac7a"
]
],
"eip150Transition": "0x259518"
}
}
},
Expand Down
5 changes: 3 additions & 2 deletions ethcore/res/ethereum/frontier_like_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"frontierCompatibilityModeLimit": "0x118c30",
"homesteadTransition": "0x118c30",
"daoHardforkTransition": "0x1d4c00",
"daoHardforkBeneficiary": "0xbf4ed7b27f1d666546e30d74d50d173d20bca754",
"daoHardforkAccounts": [
Expand Down Expand Up @@ -129,7 +129,8 @@
"0x7602b46df5390e432ef1c307d4f2c9ff6d65cc97",
"0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
"0x807640a13483f8ac783c557fcdf27be11ea4ac7a"
]
],
"eip150Transition": "0x7fffffffffffffff"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion ethcore/res/ethereum/frontier_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"frontierCompatibilityModeLimit": "0xffffffffffffffff"
"homesteadTransition": "0x7fffffffffffffff",
"eip150Transition": "0x7fffffffffffffff"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion ethcore/res/ethereum/homestead_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"frontierCompatibilityModeLimit": "0x0"
"homesteadTransition": "0x0",
"eip150Transition": "0x7fffffffffffffff"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion ethcore/res/ethereum/morden.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"registrar": "0x52dff57a8a1532e6afb3dc07e2af58bb9eb05b3d",
"frontierCompatibilityModeLimit": "0x789b0"
"homesteadTransition": "0x789b0",
"eip150Transition": "0x1b34d8"
}
}
},
Expand Down
4 changes: 3 additions & 1 deletion ethcore/res/ethereum/olympic.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x08",
"blockReward": "0x14D1120D7B160000",
"registrar": "5e70c0bbcd5636e0f9f9316e9f8633feb64d4050"
"registrar": "5e70c0bbcd5636e0f9f9316e9f8633feb64d4050",
"homesteadTransition": "0x7fffffffffffffff",
"eip150Transition": "0x7fffffffffffffff"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion ethcore/res/ethereum/tests
Submodule tests updated 41 files
+424 −0 BlockchainTests/EIP150/bcBlockGasLimitTest.json
+11,690 −0 BlockchainTests/EIP150/bcForkStressTest.json
+1,117 −0 BlockchainTests/EIP150/bcGasPricerTest.json
+1,241 −0 BlockchainTests/EIP150/bcInvalidHeaderTest.json
+6,076 −0 BlockchainTests/EIP150/bcInvalidRLPTest.json
+3,528 −0 BlockchainTests/EIP150/bcMultiChainTest.json
+980 −0 BlockchainTests/EIP150/bcRPC_API_Test.json
+1,145 −0 BlockchainTests/EIP150/bcStateTest.json
+5,468 −0 BlockchainTests/EIP150/bcTotalDifficultyTest.json
+2,771 −0 BlockchainTests/EIP150/bcUncleHeaderValiditiy.json
+4,514 −0 BlockchainTests/EIP150/bcUncleTest.json
+1,902 −0 BlockchainTests/EIP150/bcValidBlockTest.json
+10,915 −0 BlockchainTests/EIP150/bcWalletTest.json
+3,310 −0 StateTests/EIP150/Homestead/stBoundsTest.json
+7,159 −0 StateTests/EIP150/Homestead/stCallCodes.json
+2,649 −0 StateTests/EIP150/Homestead/stCallCreateCallCodeTest.json
+5,861 −0 StateTests/EIP150/Homestead/stCallDelegateCodes.json
+5,842 −0 StateTests/EIP150/Homestead/stCallDelegateCodesCallCode.json
+2,561 −0 StateTests/EIP150/Homestead/stDelegatecallTest.json
+320 −0 StateTests/EIP150/Homestead/stHomeSteadSpecific.json
+1,093 −0 StateTests/EIP150/Homestead/stInitCodeTest.json
+3,855 −0 StateTests/EIP150/Homestead/stLogTests.json
+4,091 −0 StateTests/EIP150/Homestead/stMemoryTest.json
+5,928 −0 StateTests/EIP150/Homestead/stPreCompiledContracts.json
+8,066 −0 StateTests/EIP150/Homestead/stQuadraticComplexityTest.json
+3,100 −0 StateTests/EIP150/Homestead/stRecursiveCreate.json
+1,307 −0 StateTests/EIP150/Homestead/stRefundTest.json
+541 −0 StateTests/EIP150/Homestead/stSpecialTest.json
+8,694 −0 StateTests/EIP150/Homestead/stSystemOperationsTest.json
+2,618 −0 StateTests/EIP150/Homestead/stTransactionTest.json
+3,319 −0 StateTests/EIP150/Homestead/stWalletTest.json
+2,974 −0 StateTests/EIP150/stChangedTests.json
+842 −0 StateTests/EIP150/stEIPSpecificTest.json
+2,228 −0 StateTests/EIP150/stEIPsingleCodeGasPrices.json
+695 −0 StateTests/EIP150/stMemExpandingEIPCalls.json
+5 −5 StateTests/Homestead/stSystemOperationsTest.json
+70 −0 StateTests/Homestead/stTransactionTest.json
+1 −1 StateTests/stSystemOperationsTest.json
+0 −0 ansible/ec2.py
+0 −0 ansible/test-files/create-docker-images.sh
+0 −0 ansible/test-files/testrunner.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "DAO hard-fork consensus test",
"name": "EIP150.1b hard-fork consensus test",
"engine": {
"Ethash": {
"params": {
Expand All @@ -9,7 +9,7 @@
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"frontierCompatibilityModeLimit": "0x5",
"homesteadTransition": "0x5",
"daoHardforkTransition": "0x8",
"daoHardforkBeneficiary": "0xbf4ed7b27f1d666546e30d74d50d173d20bca754",
"daoHardforkAccounts": [
Expand Down Expand Up @@ -129,7 +129,8 @@
"0x7602b46df5390e432ef1c307d4f2c9ff6d65cc97",
"0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
"0x807640a13483f8ac783c557fcdf27be11ea4ac7a"
]
],
"eip150Transition": "0xa"
}
}
},
Expand Down
95 changes: 41 additions & 54 deletions ethcore/src/account_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::time::{Instant, Duration};
use util::{Mutex, RwLock};
use ethstore::{SecretStore, Error as SSError, SafeAccount, EthStore};
use ethstore::dir::{KeyDirectory};
use ethstore::ethkey::{Address, Message, Secret, Random, Generator};
use ethstore::ethkey::{Address, Message, Public, Secret, Random, Generator};
use ethjson::misc::AccountMeta;
pub use ethstore::ethkey::Signature;

Expand Down Expand Up @@ -182,9 +182,16 @@ impl AccountProvider {

/// Creates new random account.
pub fn new_account(&self, password: &str) -> Result<Address, Error> {
let secret = Random.generate().unwrap().secret().clone();
self.new_account_and_public(password).map(|d| d.0)
}

/// Creates new random account and returns address and public key
pub fn new_account_and_public(&self, password: &str) -> Result<(Address, Public), Error> {
let acc = Random.generate().unwrap();
let public = acc.public().clone();
let secret = acc.secret().clone();
let address = try!(self.sstore.insert_account(secret, password));
Ok(address)
Ok((address, public))
}

/// Inserts new account into underlying store.
Expand Down Expand Up @@ -280,6 +287,21 @@ impl AccountProvider {
Ok(())
}

fn password(&self, account: &Address) -> Result<String, Error> {
let mut unlocked = self.unlocked.lock();
let data = try!(unlocked.get(account).ok_or(Error::NotUnlocked)).clone();
if let Unlock::Temp = data.unlock {
unlocked.remove(account).expect("data exists: so key must exist: qed");
}
if let Unlock::Timed((ref start, ref duration)) = data.unlock {
if start.elapsed() > Duration::from_millis(*duration as u64) {
unlocked.remove(account).expect("data exists: so key must exist: qed");
return Err(Error::NotUnlocked);
}
}
Ok(data.password.clone())
}

/// Unlocks account permanently.
pub fn unlock_account_permanently(&self, account: Address, password: String) -> Result<(), Error> {
self.unlock_account(account, password, Unlock::Perm)
Expand All @@ -301,51 +323,16 @@ impl AccountProvider {
unlocked.get(&account).is_some()
}

/// Signs the message. Account must be unlocked.
pub fn sign(&self, account: Address, message: Message) -> Result<Signature, Error> {
let data = {
let mut unlocked = self.unlocked.lock();
let data = try!(unlocked.get(&account).ok_or(Error::NotUnlocked)).clone();
if let Unlock::Temp = data.unlock {
unlocked.remove(&account).expect("data exists: so key must exist: qed");
}
if let Unlock::Timed((ref start, ref duration)) = data.unlock {
if start.elapsed() > Duration::from_millis(*duration as u64) {
unlocked.remove(&account).expect("data exists: so key must exist: qed");
return Err(Error::NotUnlocked);
}
}
data
};

let signature = try!(self.sstore.sign(&account, &data.password, &message));
Ok(signature)
}

/// Decrypts a message. Account must be unlocked.
pub fn decrypt(&self, account: Address, shared_mac: &[u8], message: &[u8]) -> Result<Vec<u8>, Error> {
let data = {
let mut unlocked = self.unlocked.lock();
let data = try!(unlocked.get(&account).ok_or(Error::NotUnlocked)).clone();
if let Unlock::Temp = data.unlock {
unlocked.remove(&account).expect("data exists: so key must exist: qed");
}
if let Unlock::Timed((ref start, ref duration)) = data.unlock {
if start.elapsed() > Duration::from_millis(*duration as u64) {
unlocked.remove(&account).expect("data exists: so key must exist: qed");
return Err(Error::NotUnlocked);
}
}
data
};

Ok(try!(self.sstore.decrypt(&account, &data.password, shared_mac, message)))
/// Signs the message. If password is not provided the account must be unlocked.
pub fn sign(&self, account: Address, password: Option<String>, message: Message) -> Result<Signature, Error> {
let password = try!(password.map(Ok).unwrap_or_else(|| self.password(&account)));
Ok(try!(self.sstore.sign(&account, &password, &message)))
}

/// Unlocks an account, signs the message, and locks it again.
pub fn sign_with_password(&self, account: Address, password: String, message: Message) -> Result<Signature, Error> {
let signature = try!(self.sstore.sign(&account, &password, &message));
Ok(signature)
/// Decrypts a message. If password is not provided the account must be unlocked.
pub fn decrypt(&self, account: Address, password: Option<String>, shared_mac: &[u8], message: &[u8]) -> Result<Vec<u8>, Error> {
let password = try!(password.map(Ok).unwrap_or_else(|| self.password(&account)));
Ok(try!(self.sstore.decrypt(&account, &password, shared_mac, message)))
}

/// Returns the underlying `SecretStore` reference if one exists.
Expand Down Expand Up @@ -386,8 +373,8 @@ mod tests {
assert!(ap.insert_account(kp.secret().clone(), "test").is_ok());
assert!(ap.unlock_account_temporarily(kp.address(), "test1".into()).is_err());
assert!(ap.unlock_account_temporarily(kp.address(), "test".into()).is_ok());
assert!(ap.sign(kp.address(), Default::default()).is_ok());
assert!(ap.sign(kp.address(), Default::default()).is_err());
assert!(ap.sign(kp.address(), None, Default::default()).is_ok());
assert!(ap.sign(kp.address(), None, Default::default()).is_err());
}

#[test]
Expand All @@ -397,11 +384,11 @@ mod tests {
assert!(ap.insert_account(kp.secret().clone(), "test").is_ok());
assert!(ap.unlock_account_permanently(kp.address(), "test1".into()).is_err());
assert!(ap.unlock_account_permanently(kp.address(), "test".into()).is_ok());
assert!(ap.sign(kp.address(), Default::default()).is_ok());
assert!(ap.sign(kp.address(), Default::default()).is_ok());
assert!(ap.sign(kp.address(), None, Default::default()).is_ok());
assert!(ap.sign(kp.address(), None, Default::default()).is_ok());
assert!(ap.unlock_account_temporarily(kp.address(), "test".into()).is_ok());
assert!(ap.sign(kp.address(), Default::default()).is_ok());
assert!(ap.sign(kp.address(), Default::default()).is_ok());
assert!(ap.sign(kp.address(), None, Default::default()).is_ok());
assert!(ap.sign(kp.address(), None, Default::default()).is_ok());
}

#[test]
Expand All @@ -411,8 +398,8 @@ mod tests {
assert!(ap.insert_account(kp.secret().clone(), "test").is_ok());
assert!(ap.unlock_account_timed(kp.address(), "test1".into(), 2000).is_err());
assert!(ap.unlock_account_timed(kp.address(), "test".into(), 2000).is_ok());
assert!(ap.sign(kp.address(), Default::default()).is_ok());
assert!(ap.sign(kp.address(), None, Default::default()).is_ok());
::std::thread::sleep(Duration::from_millis(2000));
assert!(ap.sign(kp.address(), Default::default()).is_err());
assert!(ap.sign(kp.address(), None, Default::default()).is_err());
}
}
Loading

0 comments on commit d3998a1

Please sign in to comment.