Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Monero v7
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Weichhold committed Mar 16, 2018
1 parent 43d6de8 commit 2fb3c9c
Show file tree
Hide file tree
Showing 127 changed files with 4,820 additions and 981 deletions.
4 changes: 2 additions & 2 deletions src/MiningCore.Tests/Crypto/CrytonoteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class CrytonoteTests : TestBase
public void Crytonote_Hash_Slow()
{
var blobConverted = "0106a2aaafd505583cf50bcc743d04d831d2b119dc94ad88679e359076ee3f18d258ee138b3b42580100a4b1e2f4baf6ab7109071ab59bc52dba740d1de99fa0ae0c4afd6ea9f40c5d87ec01".HexToByteArray();
var result = LibCryptonote.CryptonightHashSlow(blobConverted).ToHexString();
var result = LibCryptonote.CryptonightHashSlow(blobConverted, 0).ToHexString();

Assert.Equal("a845ffbdf83ae9a8ffa504a1011efbd5ed2294bb9da591d3b583740568402c00", result);
}

[Fact]
public void Cryptonote_SlowHash_Should_Throw_On_Null_Argument()
{
Assert.Throws<ArgumentNullException>(() => LibCryptonote.CryptonightHashSlow(null));
Assert.Throws<ArgumentNullException>(() => LibCryptonote.CryptonightHashSlow(null, 0));
}

[Fact]
Expand Down
19 changes: 13 additions & 6 deletions src/MiningCore/Blockchain/Monero/MoneroJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,23 @@ public class MoneroJob
switch (poolConfig.Coin.Type)
{
case CoinType.AEON:
hashSlow = LibCryptonote.CryptonightHashSlowLite;
hashSlow = (buf, variant)=> LibCryptonote.CryptonightHashSlowLite(buf);
break;

default:
hashSlow = LibCryptonote.CryptonightHashSlow;
case CoinType.XMR:
hashSlow = LibCryptonote.CryptonightHashSlow;
break;

default:
hashSlow = (buf, variant) => LibCryptonote.CryptonightHashSlow(buf, 0);
break;
}

BlockTemplate = blockTemplate;
PrepareBlobTemplate(instanceId);
}

private readonly Func<byte[], PooledArraySegment<byte>> hashSlow;
private readonly Func<byte[], int, PooledArraySegment<byte>> hashSlow;

private byte[] blobTemplate;
private uint extraNonce;
Expand Down Expand Up @@ -162,8 +166,11 @@ public void PrepareWorkerJob(MoneroWorkerJob workerJob, out string blob, out str
if (blobConverted == null)
throw new StratumException(StratumError.MinusOne, "malformed blob");

// hash it
using (var hashSeg = hashSlow(blobConverted))
// PoW variant
var hashVariant = blobConverted[0] >= 7 ? blobConverted[0] - 6 : 0;

// hash it
using (var hashSeg = hashSlow(blobConverted, hashVariant))
{
var hash = hashSeg.ToHexString();
if (hash != workerHash)
Expand Down
6 changes: 3 additions & 3 deletions src/MiningCore/Native/LibCryptonote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static unsafe class LibCryptonote
private static extern UInt64 decode_integrated_address(byte* input, int inputSize);

[DllImport("libcryptonote", EntryPoint = "cn_slow_hash_export", CallingConvention = CallingConvention.Cdecl)]
private static extern int cn_slow_hash(byte* input, byte* output, uint inputLength);
private static extern int cn_slow_hash(byte* input, byte* output, uint inputLength, int variant);

[DllImport("libcryptonote", EntryPoint = "cn_slow_hash_lite_export", CallingConvention = CallingConvention.Cdecl)]
private static extern int cn_slow_hash_lite(byte* input, byte* output, uint inputLength);
Expand Down Expand Up @@ -124,7 +124,7 @@ public static UInt64 DecodeIntegratedAddress(string address)
}
}

public static PooledArraySegment<byte> CryptonightHashSlow(byte[] data)
public static PooledArraySegment<byte> CryptonightHashSlow(byte[] data, int variant)
{
Contract.RequiresNonNull(data, nameof(data));

Expand All @@ -134,7 +134,7 @@ public static PooledArraySegment<byte> CryptonightHashSlow(byte[] data)
{
fixed(byte* output = result.Array)
{
cn_slow_hash(input, output, (uint) data.Length);
cn_slow_hash(input, output, (uint) data.Length, variant);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/MiningCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ private static void OnAppDomainUnhandledException(object sender, UnhandledExcept

private static void TouchNativeLibs()
{
Console.WriteLine(LibCryptonote.CryptonightHashSlow(Encoding.UTF8.GetBytes("test")).ToHexString());
Console.WriteLine(LibCryptonote.CryptonightHashSlow(Encoding.UTF8.GetBytes("test"), 0).ToHexString());
Console.WriteLine(LibCryptonote.CryptonightHashFast(Encoding.UTF8.GetBytes("test")).ToHexString());
Console.WriteLine(new Blake().Digest(Encoding.UTF8.GetBytes("test"), 0).ToHexString());
}
Expand Down
Binary file modified src/MiningCore/runtimes/win-x64/native/libcryptonote.dll
Binary file not shown.
Binary file modified src/MiningCore/runtimes/win-x86/native/libcryptonote.dll
Binary file not shown.
3 changes: 2 additions & 1 deletion src/Native/libcryptonote/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ LDLIBS = -lboost_system -lboost_date_time
TARGET = libcryptonote.so

OBJECTS = contrib/epee/src/hex.o \
common/base58.o crypto/aesb.o crypto/blake256.o crypto/chacha8.o \
common/base58.o crypto/aesb.o crypto/blake256.o crypto/chacha.o \
contrib/epee/src/memwipe.o \
crypto/crypto-ops-data.o crypto/crypto-ops.o crypto/crypto.o crypto/groestl.o crypto/hash-extra-blake.o \
crypto/hash-extra-groestl.o crypto/hash-extra-jh.o crypto/hash-extra-skein.o crypto/hash.o crypto/jh.o \
crypto/keccak.o crypto/oaes_lib.o crypto/random.o crypto/skein.o crypto/slow-hash.o crypto/tree-hash.o \
Expand Down
3 changes: 2 additions & 1 deletion src/Native/libcryptonote/Makefile.MSys2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ LDLIBS = -lboost_system-mt -lboost_date_time-mt
TARGET = libcryptonote.dll

OBJECTS = contrib/epee/src/hex.o \
common/base58.o crypto/aesb.o crypto/blake256.o crypto/chacha8.o \
common/base58.o crypto/aesb.o crypto/blake256.o crypto/chacha.o \
contrib/epee/src/memwipe.o \
crypto/crypto-ops-data.o crypto/crypto-ops.o crypto/crypto.o crypto/groestl.o crypto/hash-extra-blake.o \
crypto/hash-extra-groestl.o crypto/hash-extra-jh.o crypto/hash-extra-skein.o crypto/hash.o crypto/jh.o \
crypto/keccak.o crypto/oaes_lib.o crypto/random.o crypto/skein.o crypto/slow-hash.o crypto/tree-hash.o \
Expand Down
18 changes: 9 additions & 9 deletions src/Native/libcryptonote/common/base58.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2017, The Monero Project
// Copyright (c) 2014-2018, The Monero Project
//
// All rights reserved.
//
Expand Down Expand Up @@ -36,7 +36,7 @@

#include "crypto/hash.h"
#include "int-util.h"
// OW: unused #include "util.h"
#include "util.h"
#include "varint.h"

namespace tools
Expand Down Expand Up @@ -111,13 +111,13 @@ namespace tools
uint64_t res = 0;
switch (9 - size)
{
case 1: res |= *data++;
case 2: res <<= 8; res |= *data++;
case 3: res <<= 8; res |= *data++;
case 4: res <<= 8; res |= *data++;
case 5: res <<= 8; res |= *data++;
case 6: res <<= 8; res |= *data++;
case 7: res <<= 8; res |= *data++;
case 1: res |= *data++; /* FALLTHRU */
case 2: res <<= 8; res |= *data++; /* FALLTHRU */
case 3: res <<= 8; res |= *data++; /* FALLTHRU */
case 4: res <<= 8; res |= *data++; /* FALLTHRU */
case 5: res <<= 8; res |= *data++; /* FALLTHRU */
case 6: res <<= 8; res |= *data++; /* FALLTHRU */
case 7: res <<= 8; res |= *data++; /* FALLTHRU */
case 8: res <<= 8; res |= *data; break;
default: assert(false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Native/libcryptonote/common/base58.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2017, The Monero Project
// Copyright (c) 2014-2018, The Monero Project
//
// All rights reserved.
//
Expand Down
19 changes: 12 additions & 7 deletions src/Native/libcryptonote/common/int-util.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2017, The Monero Project
// Copyright (c) 2014-2018, The Monero Project
//
// All rights reserved.
//
Expand Down Expand Up @@ -35,14 +35,18 @@
#include <stdint.h>
#include <string.h>

#if !defined(_MSC_VER)
#ifndef _MSC_VER
#include <sys/param.h>
#endif

#if defined(__ANDROID__)
#include <byteswap.h>
#endif

#if defined(__sun) && defined(__SVR4)
#include <endian.h>
#endif

#if defined(_MSC_VER)
#include <stdlib.h>

Expand Down Expand Up @@ -205,13 +209,14 @@ static inline void memcpy_swap64(void *dst, const void *src, size_t n) {
}
}

#ifdef _MSC_VER
# define LITTLE_ENDIAN 1234
# define BIG_ENDIAN 4321
# define BYTE_ORDER LITTLE_ENDIAN
#endif

#if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN)
#if !defined(_MSC_VER)
static_assert(false, "BYTE_ORDER is undefined. Perhaps, GNU extensions are not enabled");
#else
#define LITTLE_ENDIAN 1234
#define BYTE_ORDER LITTLE_ENDIAN
#endif
#endif

#if BYTE_ORDER == LITTLE_ENDIAN
Expand Down
2 changes: 1 addition & 1 deletion src/Native/libcryptonote/common/pod-class.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2017, The Monero Project
// Copyright (c) 2014-2018, The Monero Project
//
// All rights reserved.
//
Expand Down

0 comments on commit 2fb3c9c

Please sign in to comment.