Skip to content

Commit

Permalink
add: newcoin: MicroBitcoin (MBC) power2b (cyclic-software#31)
Browse files Browse the repository at this point in the history
* add: newcoin: MicroBitcoin (MBC)
* add: yespower-1.0.1-power2b (MBC)
* https://github.com/decryp2kanon/yespower-1.0.1-power2b
* move: _P2B _p2b yespower_tls_p2b PBKDF2_SHA256_P2B yespower_p2b YESPOWER_1_0_BLAKE2B, Swidth_to_Sbytes1_P2b yespower_binary_t_p2b HMAC_SHA256_Buf_P2b smix_1_0_p2b
* fix: memcpy
  • Loading branch information
decryp2kanon authored Mar 21, 2020
1 parent be223e9 commit 529c2de
Show file tree
Hide file tree
Showing 22 changed files with 6,101 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ config.sub
mingw32-config.cache

# yespower
yespower-1.0.1/.dirstamp
yespower-1.0.1*/.dirstamp

# release
sugarmaker-v*/
Expand Down
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ sugarmaker_SOURCES = elist.h miner.h compat.h \
YespowerUrx.c \
YespowerLitb.c \
YespowerIots.c \
YespowerItc.c
YespowerItc.c \
yespower-1.0.1-power2b/sha256-p2b.c yespower-1.0.1-power2b/yespower-opt-p2b.c yespower-1.0.1-power2b/blake2b.c \
YespowerMbc.c

sugarmaker_LDFLAGS = $(PTHREAD_FLAGS)
sugarmaker_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@
Expand Down
84 changes: 84 additions & 0 deletions YespowerMbc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2011 ArtForz, 2011-2014 pooler, 2018 The Resistance developers, 2020 The Sugarchain Yumekawa developers
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is loosly based on a tiny portion of pooler's cpuminer scrypt.c.
*/

#include "cpuminer-config.h"
#include "miner.h"

#include "yespower-1.0.1-power2b/yespower-p2b.h"

#include <stdlib.h>
#include <string.h>
#include <inttypes.h>

int scanhash_mbc_yespower(int thr_id, uint32_t *pdata,
const uint32_t *ptarget,
uint32_t max_nonce, unsigned long *hashes_done)
{
static const yespower_params_t params = {
.version = YESPOWER_1_0_BLAKE2B,
.N = 2048,
.r = 32,
.pers = (const uint8_t *)"Now I am become Death, the destroyer of worlds",
.perslen = 46
};
union {
uint8_t u8[8];
uint32_t u32[20];
} data;
union {
yespower_binary_t_p2b yb;
uint32_t u32[7];
} hash;
uint32_t n = pdata[19] - 1;
const uint32_t Htarg = ptarget[7];
int i;

for (i = 0; i < 19; i++)
be32enc(&data.u32[i], pdata[i]);

do {
be32enc(&data.u32[19], ++n);

if (yespower_tls_p2b(data.u8, 80, &params, &hash.yb))
abort();

if (le32dec(&hash.u32[7]) <= Htarg) {
for (i = 0; i < 7; i++)
hash.u32[i] = le32dec(&hash.u32[i]);
if (fulltest(hash.u32, ptarget)) {
*hashes_done = n - pdata[19] + 1;
pdata[19] = n;
return 1;
}
}
} while (n < max_nonce && !work_restart[thr_id].restart);

*hashes_done = n - pdata[19] + 1;
pdata[19] = n;
return 0;
}
20 changes: 16 additions & 4 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ enum algos {
ALGO_LITB_YESPOWER_1_0_1,
ALGO_IOTS_YESPOWER_1_0_1,
ALGO_ITC_YESPOWER_1_0_1,
ALGO_MBC_YESPOWER_1_0_1,
};

static const char *algo_names[] = {
Expand All @@ -118,6 +119,7 @@ static const char *algo_names[] = {
[ALGO_LITB_YESPOWER_1_0_1] = "YespowerLitb",
[ALGO_IOTS_YESPOWER_1_0_1] = "YespowerIots",
[ALGO_ITC_YESPOWER_1_0_1] = "YespowerItc",
[ALGO_MBC_YESPOWER_1_0_1] = "YespowerMbc",
};

bool opt_debug = false;
Expand Down Expand Up @@ -181,10 +183,11 @@ Options:\n\
YespowerSugar: Sugarchain (default)\n\
YespowerIso: IsotopeC\n\
YespowerNull: CranePay, Bellcoin, Veco, SwampCoin\n\
YespowerUrx: UraniumX\n\
YespowerLitb: LightBit\n\
YespowerIots: IOTS\n\
YespowerItc: Intercoin\n\
YespowerUrx: UraniumX\n\
YespowerLitb: LightBit\n\
YespowerIots: IOTS\n\
YespowerItc: Intercoin\n\
YespowerMbc: power2b for MicroBitcoin\n\
-o, --url=URL URL of mining server\n\
-O, --userpass=U:P username:password pair for mining server\n\
-u, --user=USERNAME username for mining server\n\
Expand Down Expand Up @@ -1213,6 +1216,9 @@ static void *miner_thread(void *userdata)
case ALGO_ITC_YESPOWER_1_0_1:
max64 = 499;
break;
case ALGO_MBC_YESPOWER_1_0_1:
max64 = 499;
break;
}
}
if (work.data[19] + max64 > end_nonce)
Expand Down Expand Up @@ -1268,6 +1274,12 @@ static void *miner_thread(void *userdata)
);
break;

case ALGO_MBC_YESPOWER_1_0_1:
rc = scanhash_mbc_yespower(
thr_id, work.data, work.target, max_nonce, &hashes_done
);
break;

default:
/* should never happen */
goto out;
Expand Down
4 changes: 4 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ extern int scanhash_itc_yespower(int thr_id, uint32_t *pdata,
const uint32_t *ptarget,
uint32_t max_nonce, unsigned long *hashes_done);

extern int scanhash_mbc_yespower(int thr_id, uint32_t *pdata,
const uint32_t *ptarget,
uint32_t max_nonce, unsigned long *hashes_done);

struct thr_info {
int id;
pthread_t pth;
Expand Down
18 changes: 18 additions & 0 deletions yespower-1.0.1-power2b/CHANGES
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Changes made between 1.0.0 (2018/07/12) and 1.0.1 (2019/06/30).

Fill the destination buffer with all set bits on error for fail-safety
of the caller's "< target" check in case the caller neglects to check
for errors.

Simplified SMix2 for its final invocation with Nloop=2 in yespower 0.5.

Revised the "XOR of yespower" tests to trigger duplicate index in the
last SMix2 invocation in yespower 0.5 for N=2048 with at least one of
the values of r being tested. This is needed to test that a proper
kind of BlockMix is used in that special case, which would previously be
left untested.

Added x32 ABI support (x86-64 with 32-bit pointers).

Added a bit more detail to the README on caching of the computed PoW
hashes when integrating yespower in an altcoin based on Bitcoin Core.
95 changes: 95 additions & 0 deletions yespower-1.0.1-power2b/PERFORMANCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
Included with yespower is the "benchmark" program, which is built by
simply invoking "make". When invoked without parameters, it tests
yespower 0.5 at N = 2048, r = 8, which appears to be the lowest setting
in use by existing cryptocurrencies. On an i7-4770K with 4x DDR3-1600
(on two memory channels) running CentOS 7 for x86-64 (and built with
CentOS 7's default version of gcc) and with thread affinity set, this
reports between 3700 and 3800 hashes per second for both SSE2 and AVX
builds, e.g.:

$ GOMP_CPU_AFFINITY=0-7 OMP_NUM_THREADS=4 ./benchmark
version=0.5 N=2048 r=8
Will use 2048.00 KiB RAM
a5 9f ec 4c 4f dd a1 6e 3b 14 05 ad da 66 d5 25 b6 8e 7c ad fc fe 6a c0 66 c7 ad 11 8c d8 05 90
Benchmarking 1 thread ...
1018 H/s real, 1018 H/s virtual (2047 hashes in 2.01 seconds)
Benchmarking 4 threads ...
3773 H/s real, 950 H/s virtual (8188 hashes in 2.17 seconds)
min 0.984 ms, avg 1.052 ms, max 1.074 ms

Running 8 threads (to match the logical rather than the physical CPU
core count) results in very slightly worse performance on this system,
but this might be the other way around on another and/or with other
parameters. Upgrading to yespower 1.0, performance at these parameters
improves to almost 4000 hashes per second:

$ GOMP_CPU_AFFINITY=0-7 OMP_NUM_THREADS=4 ./benchmark 10
version=1.0 N=2048 r=8
Will use 2048.00 KiB RAM
d0 78 cd d4 cf 3f 5a a8 4e 3c 4a 58 66 29 81 d8 2d 27 e5 67 36 37 c4 be 77 63 61 32 24 c1 8a 93
Benchmarking 1 thread ...
1080 H/s real, 1080 H/s virtual (4095 hashes in 3.79 seconds)
Benchmarking 4 threads ...
3995 H/s real, 1011 H/s virtual (16380 hashes in 4.10 seconds)
min 0.923 ms, avg 0.989 ms, max 1.137 ms

Running 8 threads results in substantial slowdown with this new version
(to between 3200 and 3400 hashes per second) because of cache thrashing.

For higher settings such as those achieving 8 MiB instead of the 2 MiB
above, this system performs at around 800 hashes per second for yespower
0.5 and at around 830 hashes per second for yespower 1.0:

$ GOMP_CPU_AFFINITY=0-7 OMP_NUM_THREADS=4 ./benchmark 5 2048 32
version=0.5 N=2048 r=32
Will use 8192.00 KiB RAM
56 0a 89 1b 5c a2 e1 c6 36 11 1a 9f f7 c8 94 a5 d0 a2 60 2f 43 fd cf a5 94 9b 95 e2 2f e4 46 1e
Benchmarking 1 thread ...
265 H/s real, 265 H/s virtual (1023 hashes in 3.85 seconds)
Benchmarking 4 threads ...
803 H/s real, 200 H/s virtual (4092 hashes in 5.09 seconds)
min 4.924 ms, avg 4.980 ms, max 5.074 ms

$ GOMP_CPU_AFFINITY=0-7 OMP_NUM_THREADS=4 ./benchmark 10 2048 32
version=1.0 N=2048 r=32
Will use 8192.00 KiB RAM
f7 69 26 ae 4a dc 56 53 90 2f f0 22 78 ea aa 39 eb 99 84 11 ac 3e a6 24 2e 19 6d fb c4 3d 68 25
Benchmarking 1 thread ...
275 H/s real, 275 H/s virtual (1023 hashes in 3.71 seconds)
Benchmarking 4 threads ...
831 H/s real, 209 H/s virtual (4092 hashes in 4.92 seconds)
min 3.614 ms, avg 4.769 ms, max 5.011 ms

Again, running 8 threads results in a slowdown, albeit not as bad as can
be seen for lower settings.

On x86(-64), the following code versions may reasonably be built: SSE2,
AVX, and XOP. (There's no reason to build for AVX2 and higher, which is
unsuitable for and thus unused by current yespower anyway. There's also
no reason to build yespower as-is for SSE4, although there's a disabled
by default 32-bit specific SSE4 code version that may be re-enabled and
given a try if someone is so inclined; it may perform slightly slower or
slightly faster across different systems.)

yescrypt and especially yespower 1.0 have been designed to fit the SSE2
instruction set almost perfectly, so there's very little benefit from
the AVX and XOP builds, yet even at yespower 1.0 there may be
performance differences between SSE2, AVX, and XOP builds within 2% or
so (and it is unclear which is the fastest on a given system until
tested, except that where XOP is supported it is almost always faster
than AVX).

Proper setting of thread affinities to run exactly one thread per
physical CPU core is non-trivial. In the above examples, it so happened
that the first 4 logical CPU numbers corresponded to different physical
cores, but this won't always be the case. This can vary even between
apparently similar systems. On Linux, the mapping of logical CPUs to
physical cores may be obtained from /proc/cpuinfo (on x86[-64] and MIC)
or sysfs, which an optimized implementation of e.g. a cryptocurrency
miner could use. If you do not bother obtaining this information from
the operating system, you might be better off not setting thread
affinities at all (in order to avoid the risk of doing this incorrectly,
which would have a greater negative performance impact) and/or running
as many threads as there are logical CPUs. Also, there's no certainty
whether different and future CPUs will run yespower faster using one or
maybe more threads per physical core.
Loading

0 comments on commit 529c2de

Please sign in to comment.