zawy12 / proof-of-work Goto Github PK
View Code? Open in Web Editor NEWA simple POW that changes every nonce.
A simple POW that changes every nonce.
I'm exploring the following procedure in this Github and have implemented it in the code file pow_gpu.cpp. It's hopefully a demonstration of how to make it difficult to improve the efficiency of a GPU by optimized coding, and to possibly make it difficult for a GPU to do better than a CPU on a hash/electricity basis. It does not protect against FPGA's or ASICs because the core functions can be optimized, but I'll try to use its structure to try to construct much more general algorithms on the fly in each iteration of each nonce. My next comment in this issue will start exploring that.
"function" can be any valid program that has a standard output type (I've chosen doubles and math functions for now).
// coin defines it own functions
myhash = ffx32;
while (myhash >= target) {
nonce++;
h = sha256 ( "previous_block_hash" + "nonce");
seed = get_seed ( h )
for (1 to 10,000) {
sequence = get_a_sequence_of_functions ( seed )
for (1 to N_functions) {
seed = execute_function ( seed );
seed = normalize_seed_to_safe_input_form ( seed );
}
}
myhash = hash(seed)
}
claim my block;
I've chosen math functions for C++ that I hope a GPU can't optimize or do better than a CPU (due to its internal math co-processor). The functions' slowness makes the support code become less relevant. I have to select the function, normalize the output, shift it a variable way based so it's not connected to previous math function, and prevent potential round off error. The 3 lines to do this are:
// The following takes 40 ns.
long double seed = frexp (k , &n); // get significant digits from the output from previous function
// Now reject top 2 b/c above output is binary weirdness (0.50 to 0.99). BTW, conversely, bottom
// 2 digits of doubles are not random b/c they are needed to convert decimal to a precise binary.
seed = modfl (100*seed , &intpart); // Turn top 2 fractparts into intparts & get remaining fractpart
seed = (int64_t)(seed*1e12); // Reject bottom digits to prevent rounding differences. Faster than trunc().
A FPGA might have a big advantage by having dedicated circuits for each of the small number of functions I've chosen. This paper shows how to calculate cosine (or sine) in 30 clock cycles, where my code requires 235 cycles on my CPU. This paper says CPUs can't compete with FPGAs for individual math functions. It appears FPGAs can do the basic math functions I've used with 10x less electricity.
Speeds on 3.4 GHz intel i7-2600 with doubles. Add about 30% for long doubles. Notice the last calculation consists of 3 really fast functions, inverse, erf, and sqrt.
if ( functs[seq] == 1 ) { k = pow(k,5.123); } // 60 ns
else if ( functs[seq] == 2 ){ k = log(k); } // 80 ns, 100 ns w/ long doubles
else if ( functs[seq] == 3 ){ k = exp(k*1e-11); } // 72 ns
else if ( functs[seq] == 4 ){ k = sin(k*6.28e-12)+1.01; } // 70 ns, 88 w/ long doubles
else if ( functs[seq] == 5 ){ k = asin(k*1e-12); } // 30 ns, 50 w/ longs
else if ( functs[seq] == 6 ){ k = sinh(k*1e-11); } // 55 ns
else if ( functs[seq] == 7 ){ k = asinh(k*1e-12); } // 53 ns asinh(k*1e-12);
else if ( functs[seq] == 8 ){ k = 1/erf(0.001*sqrt(sqrt(k))); } // 40 ns, 60 w/ longs
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.