Skip to content

Commit

Permalink
Added --keyspace option: Specify the key space:
Browse files Browse the repository at this point in the history
--keyspace START            (Starts at 1, continues until program is stopped)
--keyspace START:END        (Starts at START, ends at END)
--keyspace START:+NUM_KEYS  (starts at START, ends at START + NUM_KEYS)
--keyspace :END             (Starts at 1, stops at END)
--keyspace :+OFFSET         (Starts at 1, stops at 1 + OFFSET)

Added --stride option: Specify how much to increment the key:

--stride 2:  START, START + 2, START + 4, etc
--stride 5: START, START + 5, START + 10, START + 15, etc

Added --share option: Search a section of the keyspace:
--share 1/10:   Divide the keyspace into 10 equal sections, search the
first one

--share 99/100: Divide the keyspace into 100 equal sections, search the
99th one

--share 40/40: Divide the keyspace into 40 equal sections, search the
final one

Added --continue: Save progress so the program can continue where it
left off. By default, status is saved every 60 seconds.

--continue FILE: Save progress information in file FILE.

Added --compression as an alternative to -c and -u:

--compression COMPRESSED
--compression UNCOMPRESSED
--compression BOTH

Removed:
-s, --start
-r, --range

since they are replaced by --keyspace
  • Loading branch information
brichard19 committed Nov 19, 2018
1 parent 67d2308 commit 75a91e3
Show file tree
Hide file tree
Showing 31 changed files with 587 additions and 213 deletions.
6 changes: 2 additions & 4 deletions AddrGen/AddrGen.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down Expand Up @@ -137,8 +136,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
Expand Down
6 changes: 2 additions & 4 deletions AddressUtil/AddressUtil.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down Expand Up @@ -135,8 +134,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
Expand Down
38 changes: 25 additions & 13 deletions CLKeySearchDevice/CLKeySearchDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ uint64_t CLKeySearchDevice::getOptimalBloomFilterMask(double p, size_t n)
{
double m = 3.6 * ceil((n * std::log(p)) / std::log(1 / std::pow(2, std::log(2))));

unsigned int bits = std::ceil(std::log(m) / std::log(2));
unsigned int bits = (unsigned int)std::ceil(std::log(m) / std::log(2));

return ((uint64_t)1 << bits) - 1;
}
Expand Down Expand Up @@ -146,7 +146,7 @@ void CLKeySearchDevice::initializeBloomFilter(const std::vector<struct hash160>

void CLKeySearchDevice::allocateBuffers()
{
size_t numKeys = _threads * _blocks * _pointsPerThread;
size_t numKeys = (size_t)_threads * _blocks * _pointsPerThread;
size_t size = numKeys * 8 * sizeof(unsigned int);

// X values
Expand Down Expand Up @@ -187,7 +187,7 @@ void CLKeySearchDevice::setIncrementor(secp256k1::ecpoint &p)
_clContext->copyHostToDevice(buf, _yInc, 8 * sizeof(unsigned int));
}

void CLKeySearchDevice::init(const secp256k1::uint256 &start, int compression)
void CLKeySearchDevice::init(const secp256k1::uint256 &start, int compression, uint64_t stride)
{
if(start.cmp(secp256k1::N) >= 0) {
throw KeySearchException("Starting key is out of range");
Expand All @@ -203,15 +203,15 @@ void CLKeySearchDevice::init(const secp256k1::uint256 &start, int compression)

// Set the incrementor
secp256k1::ecpoint g = secp256k1::G();
secp256k1::ecpoint p = secp256k1::multiplyPoint(secp256k1::uint256(_threads * _blocks * _pointsPerThread), g);
secp256k1::ecpoint p = secp256k1::multiplyPoint(secp256k1::uint256(_threads * _blocks * _pointsPerThread).mul(secp256k1::uint256(_stride)), g);

setIncrementor(p);
}

void CLKeySearchDevice::doStep()
{
try {
uint64_t numKeys = _blocks * _threads * _pointsPerThread;
uint64_t numKeys = (uint64_t)_blocks * _threads * _pointsPerThread;

if(_iterations < 2 && _start.cmp(numKeys) <= 0) {

Expand Down Expand Up @@ -327,7 +327,7 @@ size_t CLKeySearchDevice::getResults(std::vector<KeySearchResult> &results)

uint64_t CLKeySearchDevice::keysPerStep()
{
return _threads * _blocks * _pointsPerThread;
return (uint64_t)_threads * _blocks * _pointsPerThread;
}

std::string CLKeySearchDevice::getDeviceName()
Expand Down Expand Up @@ -415,8 +415,9 @@ void CLKeySearchDevice::getResultsInternal()
KeySearchResult minerResult;

// Calculate the private key based on the number of iterations and the current thread
uint64_t offset = (uint64_t)_blocks * _threads * _pointsPerThread * _iterations + getPrivateKeyOffset(ptr[i].thread, ptr[i].block, ptr[i].idx);
secp256k1::uint256 privateKey = secp256k1::addModN(_start, secp256k1::uint256(offset));
//secp256k1::uint256 offset((uint64_t)_blocks * _threads * _pointsPerThread * _iterations + getPrivateKeyOffset(ptr[i].thread, ptr[i].block, ptr[i].idx));
secp256k1::uint256 offset = (secp256k1::uint256((uint64_t)_blocks * _threads * _pointsPerThread * _iterations) + secp256k1::uint256(getPrivateKeyOffset(ptr[i].thread, ptr[i].block, ptr[i].idx))) * _stride;
secp256k1::uint256 privateKey = secp256k1::addModN(_start, offset);

minerResult.privateKey = privateKey;
minerResult.compressed = ptr[i].compressed;
Expand All @@ -438,14 +439,17 @@ void CLKeySearchDevice::getResultsInternal()

void CLKeySearchDevice::selfTest()
{
unsigned int numPoints = _threads * _blocks * _pointsPerThread;
uint64_t numPoints = (uint64_t)_threads * _blocks * _pointsPerThread;
std::vector<secp256k1::uint256> privateKeys;

// Generate key pairs for k, k+1, k+2 ... k + <total points in parallel - 1>
secp256k1::uint256 privKey = _start;

for(uint64_t i = 0; i < numPoints; i++) {
privateKeys.push_back(privKey.add(i));
privateKeys.push_back(_start);

for(uint64_t i = 1; i < numPoints; i++) {
privKey = privKey.add(_stride);
privateKeys.push_back(privKey);
}

unsigned int *xBuf = new unsigned int[numPoints * 8];
Expand Down Expand Up @@ -524,7 +528,7 @@ void CLKeySearchDevice::initializeBasePoints()
std::vector<secp256k1::ecpoint> table;

table.push_back(secp256k1::G());
for(int i = 1; i < 256; i++) {
for(uint64_t i = 1; i < 256; i++) {

secp256k1::ecpoint p = doublePoint(table[i - 1]);
if(!pointExists(p)) {
Expand Down Expand Up @@ -570,7 +574,7 @@ int CLKeySearchDevice::getIndex(int block, int thread, int idx)

void CLKeySearchDevice::generateStartingPoints()
{
uint64_t totalPoints = _pointsPerThread * _threads * _blocks;
uint64_t totalPoints = (uint64_t)_pointsPerThread * _threads * _blocks;
uint64_t totalMemory = totalPoints * 40;

std::vector<secp256k1::uint256> exponents;
Expand Down Expand Up @@ -618,4 +622,12 @@ void CLKeySearchDevice::generateStartingPoints()
}

Logger::log(LogLevel::Info, "Done");
}


secp256k1::uint256 CLKeySearchDevice::getNextKey()
{
uint64_t totalPoints = (uint64_t)_pointsPerThread * _threads * _blocks;

return _start + secp256k1::uint256(totalPoints) * _iterations * _stride;
}
16 changes: 10 additions & 6 deletions CLKeySearchDevice/CLKeySearchDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

typedef struct CLTargetList_
{
cl_ulong mask;
cl_ulong size;
cl_mem ptr;
cl_ulong mask = 0;
cl_ulong size = 0;
cl_mem ptr = 0;
}CLTargetList;

class CLKeySearchDevice : public KeySearchDevice {
Expand Down Expand Up @@ -40,10 +40,12 @@ class CLKeySearchDevice : public KeySearchDevice {

cl_device_id _device;

int _compression;
int _compression = PointCompressionType::COMPRESSED;

uint64_t _iterations;

uint64_t _stride = 1;

std::string _deviceName;

// Device memory pointers
Expand Down Expand Up @@ -86,7 +88,7 @@ class CLKeySearchDevice : public KeySearchDevice {

void selfTest();

bool _useBloomFilter;
bool _useBloomFilter = false;

void setTargetsInternal();
void setTargetsList();
Expand All @@ -111,7 +113,7 @@ class CLKeySearchDevice : public KeySearchDevice {


// Initialize the device
virtual void init(const secp256k1::uint256 &start, int compression);
virtual void init(const secp256k1::uint256 &start, int compression, uint64_t stride);

// Perform one iteration
virtual void doStep();
Expand All @@ -130,6 +132,8 @@ class CLKeySearchDevice : public KeySearchDevice {

// Memory information for this device
virtual void getMemoryInfo(uint64_t &freeMem, uint64_t &totalMem);

virtual secp256k1::uint256 getNextKey();
};

#endif
Expand Down
2 changes: 1 addition & 1 deletion CmdParse/CmdParse.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class OptArg {

bool equals(std::string shortForm, std::string longForm = "")
{
return option == shortForm || option == longForm;
return (shortForm.length() > 0 && option == shortForm) || option == longForm;
}
};

Expand Down
6 changes: 2 additions & 4 deletions CmdParse/CmdParse.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down Expand Up @@ -123,8 +122,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
Expand Down
6 changes: 2 additions & 4 deletions CryptoUtil/CryptoUtil.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down Expand Up @@ -126,8 +125,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
Expand Down
30 changes: 21 additions & 9 deletions CudaKeySearchDevice/CudaKeySearchDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ CudaKeySearchDevice::CudaKeySearchDevice(int device, int threads, int pointsPerT
_pointsPerThread = pointsPerThread;
}

void CudaKeySearchDevice::init(const secp256k1::uint256 &start, int compression)
void CudaKeySearchDevice::init(const secp256k1::uint256 &start, int compression, uint64_t stride)
{
if(start.cmp(secp256k1::N) >= 0) {
throw KeySearchException("Starting key is out of range");
Expand All @@ -67,6 +67,8 @@ void CudaKeySearchDevice::init(const secp256k1::uint256 &start, int compression)

_compression = compression;

_stride = stride;

try {
cuda::CudaDeviceInfo info = cuda::getDeviceInfo(_device);
_deviceName = info.name;
Expand All @@ -87,7 +89,7 @@ void CudaKeySearchDevice::init(const secp256k1::uint256 &start, int compression)

// Set the incrementor
secp256k1::ecpoint g = secp256k1::G();
secp256k1::ecpoint p = secp256k1::multiplyPoint(secp256k1::uint256(_threads * _blocks * _pointsPerThread), g);
secp256k1::ecpoint p = secp256k1::multiplyPoint(secp256k1::uint256(_threads * _blocks * _pointsPerThread).mul(secp256k1::uint256(_stride)), g);

cudaCall(_resultList.init(sizeof(CudaDeviceResult), 16));

Expand All @@ -97,7 +99,7 @@ void CudaKeySearchDevice::init(const secp256k1::uint256 &start, int compression)

void CudaKeySearchDevice::generateStartingPoints()
{
uint64_t totalPoints = _pointsPerThread * _threads * _blocks;
uint64_t totalPoints = (uint64_t)_pointsPerThread * _threads * _blocks;
uint64_t totalMemory = totalPoints * 40;

std::vector<secp256k1::uint256> exponents;
Expand All @@ -107,8 +109,11 @@ void CudaKeySearchDevice::generateStartingPoints()
// Generate key pairs for k, k+1, k+2 ... k + <total points in parallel - 1>
secp256k1::uint256 privKey = _startExponent;

for(uint64_t i = 0; i < totalPoints; i++) {
exponents.push_back(privKey.add(i));
exponents.push_back(privKey);

for(uint64_t i = 1; i < totalPoints; i++) {
privKey = privKey.add(_stride);
exponents.push_back(privKey);
}

cudaCall(_deviceKeys.init(_blocks, _threads, _pointsPerThread, exponents));
Expand Down Expand Up @@ -144,7 +149,7 @@ void CudaKeySearchDevice::setTargets(const std::set<KeySearchTarget> &targets)

void CudaKeySearchDevice::doStep()
{
uint64_t numKeys = _blocks * _threads * _pointsPerThread;
uint64_t numKeys = (uint64_t)_blocks * _threads * _pointsPerThread;

try {
if(_iterations < 2 && _startExponent.cmp(numKeys) <= 0) {
Expand All @@ -163,7 +168,7 @@ void CudaKeySearchDevice::doStep()

uint64_t CudaKeySearchDevice::keysPerStep()
{
return _blocks * _threads * _pointsPerThread;
return (uint64_t)_blocks * _threads * _pointsPerThread;
}

std::string CudaKeySearchDevice::getDeviceName()
Expand Down Expand Up @@ -240,8 +245,8 @@ void CudaKeySearchDevice::getResultsInternal()
KeySearchResult minerResult;

// Calculate the private key based on the number of iterations and the current thread
uint64_t offset = (uint64_t)_blocks * _threads * _pointsPerThread * _iterations + getPrivateKeyOffset(rPtr->thread, rPtr->block, rPtr->idx);
secp256k1::uint256 privateKey = secp256k1::addModN(_startExponent, secp256k1::uint256(offset));
secp256k1::uint256 offset = (secp256k1::uint256((uint64_t)_blocks * _threads * _pointsPerThread * _iterations) + secp256k1::uint256(getPrivateKeyOffset(rPtr->thread, rPtr->block, rPtr->idx)))* _stride;
secp256k1::uint256 privateKey = secp256k1::addModN(_startExponent, offset);

minerResult.privateKey = privateKey;
minerResult.compressed = rPtr->compressed;
Expand Down Expand Up @@ -306,4 +311,11 @@ size_t CudaKeySearchDevice::getResults(std::vector<KeySearchResult> &resultsOut)
_results.clear();

return resultsOut.size();
}

secp256k1::uint256 CudaKeySearchDevice::getNextKey()
{
uint64_t totalPoints = (uint64_t)_pointsPerThread * _threads * _blocks;

return _startExponent + secp256k1::uint256(totalPoints) * _iterations * _stride;
}
6 changes: 5 additions & 1 deletion CudaKeySearchDevice/CudaKeySearchDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ class CudaKeySearchDevice : public KeySearchDevice {

uint32_t getPrivateKeyOffset(int thread, int block, int point);

uint64_t _stride;

bool verifyKey(const secp256k1::uint256 &privateKey, const secp256k1::ecpoint &publicKey, const unsigned int hash[5], bool compressed);

public:

CudaKeySearchDevice(int device, int threads, int pointsPerThread, int blocks = 0);

virtual void init(const secp256k1::uint256 &start, int compression);
virtual void init(const secp256k1::uint256 &start, int compression, uint64_t stride);

virtual void doStep();

Expand All @@ -82,6 +84,8 @@ class CudaKeySearchDevice : public KeySearchDevice {
virtual std::string getDeviceName();

virtual void getMemoryInfo(uint64_t &freeMem, uint64_t &totalMem);

virtual secp256k1::uint256 getNextKey();
};

#endif
Loading

0 comments on commit 75a91e3

Please sign in to comment.