Skip to content

Commit

Permalink
Imported BLS12-381 curve functions. Added BLS signature scheme and te…
Browse files Browse the repository at this point in the history
…st. Removed ethash and presale import code. Added precompiled contracts for BLS12-381.
  • Loading branch information
xko938174 committed Jan 16, 2018
1 parent 18da148 commit b4a1af3
Show file tree
Hide file tree
Showing 84 changed files with 974 additions and 29,212 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Expand Up @@ -21,6 +21,12 @@
#
# (c) 2014-2016 cpp-ethereum contributors.
#------------------------------------------------------------------------------
add_definitions(-DPUBLICCHAIN=$ENV{PUBLICCHAIN})
if(PUBLICCHAIN)
add_definitions(-DNETWORKP2PPORT=40404 )
else()
add_definitions(-DNETWORKP2PPORT=41414 )
endif()

cmake_minimum_required(VERSION 3.5.1)

Expand Down
2 changes: 1 addition & 1 deletion cmake/ProjectPairing.cmake
Expand Up @@ -6,7 +6,7 @@ set(LIBRARY_DIR "${prefix}/lib64/")
ExternalProject_Add(pairing
PREFIX "${prefix}"
URL file:///home/w/pairing-ariel.tar.gz
URL_HASH SHA256=b5610368cb7d0cf479b1a3e3b24acad9f48b9f0dec9e647d067b2a8b16cf1dc4
URL_HASH SHA256=c88d8f041067f35cab3b4a0bc9bc31008c11a5b4bac74a5a65d4afb7ecf8bd14
BUILD_BYPRODUCTS "${PAIRING_LIBRARY}"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_INSTALL_DIR=<INSTALL_DIR>
-DCMAKE_LIB_TARGET_LOCATION=${LIBRARY_DIR}
Expand Down
33 changes: 5 additions & 28 deletions eth/AccountManager.cpp
Expand Up @@ -37,10 +37,8 @@ void AccountManager::streamAccountHelp(ostream& _out)
<< " account import [<uuid>|<file>|<secret-hex>] Import keys from given source and place in wallet.\n";
}

void AccountManager::streamWalletHelp(ostream& _out)
void AccountManager::streamWalletHelp(ostream&)
{
_out
<< " wallet import <file> Import a presale wallet.\n";
}

bool AccountManager::execute(int argc, char** argv)
Expand All @@ -49,28 +47,7 @@ bool AccountManager::execute(int argc, char** argv)
{
if (3 < argc && string(argv[2]) == "import")
{
if (!openWallet())
return false;
string file = argv[3];
string name = "presale wallet";
string pw;
try
{
KeyPair k = m_keyManager->presaleSecret(
contentsString(file),
[&](bool){ return (pw = getPassword("Enter the passphrase for the presale key: "));}
);
m_keyManager->import(k.secret(), name, pw, "Same passphrase as used for presale key");
cout << " Address: {" << k.address().hex() << "}\n";
}
catch (Exception const& _e)
{
if (auto err = boost::get_error_info<errinfo_comment>(_e))
cout << " Decryption failed: " << *err << "\n";
else
cout << " Decryption failed: Unknown reason.\n";
return false;
}
return false;
}
else
streamWalletHelp(cout);
Expand Down Expand Up @@ -211,12 +188,12 @@ string AccountManager::createPassword(string const& _prompt) const
return ret;
}

KeyPair AccountManager::makeKey() const
KeyPair<dev::BLS> AccountManager::makeKey() const
{
bool icap = true;
KeyPair k(Secret::random());
KeyPair<dev::BLS> k(Secret::random());
while (icap && k.address()[0])
k = KeyPair(Secret(sha3(k.secret().ref())));
k = KeyPair<dev::BLS>(Secret(sha3(k.secret().ref())));
return k;
}

Expand Down
2 changes: 1 addition & 1 deletion eth/AccountManager.h
Expand Up @@ -43,7 +43,7 @@ class AccountManager
/// ask end user to create a password.
std::string createPassword(std::string const& _prompt) const;
/// creates a ramdom secret/address pair. It uses ICAP.
dev::KeyPair makeKey() const;
dev::KeyPair<dev::BLS> makeKey() const;
/// instanciate KeyManager and open the wallet.
bool openWallet();

Expand Down
65 changes: 0 additions & 65 deletions eth/MinerAux.h
Expand Up @@ -212,10 +212,6 @@ class MinerCLI
{
if (m_minerType == "cpu")
EthashCPUMiner::setNumInstances(m_miningThreads);
if (mode == OperationMode::DAGInit)
doInitDAG(m_initDAG);
else if (mode == OperationMode::Benchmark)
doBenchmark(m_minerType, m_benchmarkWarmup, m_benchmarkTrial, m_benchmarkTrials);
}

static void streamHelp(ostream& _out)
Expand Down Expand Up @@ -244,67 +240,6 @@ class MinerCLI
bool shouldPrecompute() const { return m_precompute; }

private:
void doInitDAG(unsigned _n)
{
h256 seedHash = EthashAux::seedHash(_n);
cout << "Initializing DAG for epoch beginning #" << (_n / 30000 * 30000) << " (seedhash " << seedHash.abridged() << "). This will take a while." << endl;
EthashAux::full(seedHash, true);
exit(0);
}

void doBenchmark(std::string _m, unsigned _warmupDuration = 15, unsigned _trialDuration = 3, unsigned _trials = 5)
{
BlockHeader genesis;
genesis.setDifficulty(1 << 18);
cdebug << Ethash::boundary(genesis);

GenericFarm<EthashProofOfWork> f;
map<string, GenericFarm<EthashProofOfWork>::SealerDescriptor> sealers;
sealers["cpu"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{&EthashCPUMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashCPUMiner(ci); }};
f.setSealers(sealers);
f.onSolutionFound([&](EthashProofOfWork::Solution) { return false; });

string platformInfo = EthashCPUMiner::platformInfo();
cout << "Benchmarking on platform: " << platformInfo << endl;

cout << "Preparing DAG..." << endl;
Ethash::ensurePrecomputed(0);

genesis.setDifficulty(u256(1) << 63);
f.setWork(genesis);
f.start(_m);

map<u256, WorkingProgress> results;
u256 mean = 0;
u256 innerMean = 0;
for (unsigned i = 0; i <= _trials; ++i)
{
if (!i)
cout << "Warming up..." << endl;
else
cout << "Trial " << i << "... " << flush;
this_thread::sleep_for(chrono::seconds(i ? _trialDuration : _warmupDuration));

auto mp = f.miningProgress();
f.resetMiningProgress();
if (!i)
continue;
auto rate = mp.rate();

cout << rate << endl;
results[rate] = mp;
mean += rate;
}
f.stop();
int j = -1;
for (auto const& r: results)
if (++j > 0 && j < (int)_trials - 1)
innerMean += r.second.rate();
innerMean /= (_trials - 2);
cout << "min/mean/max: " << results.begin()->second.rate() << "/" << (mean / _trials) << "/" << results.rbegin()->second.rate() << " H/s" << endl;
cout << "inner mean: " << innerMean << " H/s" << endl;
exit(0);
}

/// Operating mode.
OperationMode mode;
Expand Down
19 changes: 5 additions & 14 deletions eth/main.cpp
Expand Up @@ -204,12 +204,6 @@ void setDefaultOrCLocale()
#endif
}

void importPresale(KeyManager& _km, string const& _file, function<string()> _pass)
{
KeyPair k = _km.presaleSecret(contentsString(_file), [&](bool){ return _pass(); });
_km.import(k.secret(), "Presale wallet" + _file + " (insecure)");
}

Address c_config = Address("ccdeac59d35627b7de09332e819d5159e7bb7250");
string pretty(h160 _a, dev::eth::State const& _st)
{
Expand Down Expand Up @@ -293,7 +287,7 @@ int main(int argc, char** argv)
setDefaultOrCLocale();

// Init secp256k1 context by calling one of the functions.
toPublic({});
toPublic<dev::ECDSA>({});

// Init defaults
Defaults::get();
Expand Down Expand Up @@ -340,10 +334,10 @@ int main(int argc, char** argv)
/// Networking params.
string clientName;
string listenIP;
unsigned short listenPort = 30303;
unsigned short listenPort = dev::p2p::c_defaultIPPort;
string publicIP;
string remoteHost;
unsigned short remotePort = 30303;
unsigned short remotePort = dev::p2p::c_defaultIPPort;

unsigned peers = 11;
unsigned peerStretch = 7;
Expand All @@ -354,7 +348,7 @@ int main(int argc, char** argv)
bool enableDiscovery = false;
bool noPinning = false;
static const unsigned NoNetworkID = (unsigned)-1;
unsigned networkID = NoNetworkID;
unsigned networkID = (unsigned) eth::Network::EthereumYNetwork;

/// Mining params
unsigned mining = 0;
Expand Down Expand Up @@ -735,7 +729,7 @@ int main(int argc, char** argv)
if (!required && type != "default")
continue;

Public publicKey(fromHex(pubk));
ECDSA::Public publicKey(fromHex(pubk));
try
{
preferredNodes[publicKey] = make_pair(NodeIPEndpoint(bi::address::from_string(hostIP), port, port), required);
Expand Down Expand Up @@ -1060,9 +1054,6 @@ int main(int argc, char** argv)
return -1;
}

for (auto const& presale: presaleImports)
importPresale(keyManager, presale, [&](){ return getPassword("Enter your wallet password for " + presale + ": "); });

for (auto const& s: toImport)
{
keyManager.import(s, "Imported key (UNSAFE)");
Expand Down
45 changes: 14 additions & 31 deletions ethkey/KeyAux.h
Expand Up @@ -96,8 +96,7 @@ class KeyCLI
New,
Import,
ImportWithAddress,
ImportPresale,
Export,
Export,
Recode,
Kill,
Inspect,
Expand Down Expand Up @@ -239,12 +238,6 @@ class KeyCLI
m_inputs = strings(1, argv[++i]);
m_name = argv[++i];
}
else if ((arg == "--import-presale" || arg == "importpresale") && i + 2 < argc)
{
m_mode = OperationMode::ImportPresale;
m_inputs = strings(1, argv[++i]);
m_name = argv[++i];
}
else if ((arg == "--import-with-address" || arg == "importwithaddress") && i + 3 < argc)
{
m_mode = OperationMode::ImportWithAddress;
Expand All @@ -267,11 +260,11 @@ class KeyCLI
return true;
}

KeyPair makeKey() const
KeyPair<BLS> makeKey() const
{
KeyPair k(Secret::random());
KeyPair<BLS> k(Secret::random());
while (m_icap && k.address()[0])
k = KeyPair(Secret(sha3(k.secret().ref())));
k = KeyPair<BLS>(Secret(sha3(k.secret().ref())));
return k;
}

Expand Down Expand Up @@ -363,11 +356,9 @@ class KeyCLI
cout << " gas: " << t.gas() << endl;
cout << " gas price: " << formatBalance(t.gasPrice()) << " (" << t.gasPrice() << " wei)" << endl;
cout << " signing hash: " << t.sha3(WithoutSignature).hex() << endl;
if (t.safeSender())
if (t.sender())
{
cout << " v: " << (int)t.signature().v << endl;
cout << " r: " << t.signature().r << endl;
cout << " s: " << t.signature().s << endl;
cout << " publicKey: " << t.signature().publicKey.hex() << endl;
}
}
catch (Exception& ex)
Expand Down Expand Up @@ -410,7 +401,7 @@ class KeyCLI
{
keyManager(true);
if (m_inputs.empty())
m_inputs.push_back(toAddress(KeyManager::brain(getPassword("Enter brain wallet key phrase: "))).hex());
m_inputs.push_back(toAddress<BLS>(KeyManager::brain(getPassword("Enter brain wallet key phrase: "))).hex());
for (auto i: m_inputs)
{
Address a = userToAddress(i);
Expand Down Expand Up @@ -458,7 +449,7 @@ class KeyCLI
u = secretStore().importKey(input);
}
if (!u && b.size() == 32)
u = secretStore().importSecret(b, lockPassword(toAddress(Secret(b)).abridged()));
u = secretStore().importSecret(b, lockPassword(toAddress<BLS>(Secret(b)).abridged()));
if (!u)
{
cerr << "Cannot import " << input << " not a file or secret." << endl;
Expand All @@ -475,17 +466,17 @@ class KeyCLI
bytesSec s = secretStore().secret(u, [&](){ return getPassword("Enter passphrase for key " + i + ": "); });
cout << "Key " << i << ":" << endl;
cout << " UUID: " << toUUID(u) << ":" << endl;
cout << " Address: " << toAddress(Secret(s)).hex() << endl;
cout << " Address: " << toAddress<BLS>(Secret(s)).hex() << endl;
cout << " Secret: " << (m_showSecret ? toHex(s.ref()) : (toHex(s.ref().cropped(0, 8)) + "...")) << endl;
}
else if (h128 u = fromUUID(i))
{
bytesSec s = secretStore().secret(u, [&](){ return getPassword("Enter passphrase for key " + toUUID(u) + ": "); });
cout << "Key " << i << ":" << endl;
cout << " Address: " << toAddress(Secret(s)).hex() << endl;
cout << " Address: " << toAddress<BLS>(Secret(s)).hex() << endl;
cout << " Secret: " << (m_showSecret ? toHex(s.ref()) : (toHex(s.ref().cropped(0, 8)) + "...")) << endl;
}
else if (Address a = toAddress(i))
else if (Address a = toAddress<BLS>(i))
{
cout << "Key " << a.abridged() << ":" << endl;
cout << " Address: " << a.hex() << endl;
Expand Down Expand Up @@ -583,7 +574,7 @@ class KeyCLI
u = keyManager().store().importKey(i);
}
if (!u && b.size() == 32)
u = keyManager().store().importSecret(b, lockPassword(toAddress(Secret(b)).abridged()));
u = keyManager().store().importSecret(b, lockPassword(toAddress<BLS>(Secret(b)).abridged()));
if (!u)
{
cerr << "Cannot import " << i << " not a file or secret." << endl;
Expand All @@ -596,15 +587,7 @@ class KeyCLI
cout << " Address: " << m_address << endl;
break;
}
case OperationMode::ImportPresale:
{
keyManager();
std::string pw;
KeyPair k = keyManager().presaleSecret(contentsString(m_inputs[0]), [&](bool){ return (pw = getPassword("Enter the passphrase for the presale key: ")); });
keyManager().import(k.secret(), m_name, pw, "Same passphrase as used for presale key");
break;
}
case OperationMode::Recode:
case OperationMode::Recode:
for (auto const& i: m_inputs)
if (Address a = userToAddress(i))
{
Expand Down Expand Up @@ -696,7 +679,7 @@ class KeyCLI
<< " list List all keys available in wallet." << endl
<< " new <name> Create a new key with given name and add it in the wallet." << endl
<< " import [<uuid>|<file>|<secret-hex>] <name> Import keys from given source and place in wallet." << endl
<< " importpresale <file> <name> Import a presale wallet into a key with the given name." << endl
// << " importpresale <file> <name> Import a presale wallet into a key with the given name." << endl
<< " importwithaddress [<uuid>|<file>|<secret-hex>] <address> <name> Import keys from given source with given address and place in wallet." << endl
<< " export [ <address>|<uuid> , ... ] Export given keys." << endl
<< " inspect [ <address>|<name>|<uuid>|<brainwallet> ] ... Print information on the given keys." << endl
Expand Down

0 comments on commit b4a1af3

Please sign in to comment.