Skip to content

Commit

Permalink
modify kingcoin different diff calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcoin committed Aug 21, 2013
1 parent 6d6763a commit 4908a98
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ bool CAddrMan::Add_(const CAddress &addr, const CNetAddr& source, int64 nTimePen
return false;

// stochastic test: previous nRefCount == N: 2^N times harder to increase it
int nFactor = 1;
int nDiffParameter = 1;
for (int n=0; n<pinfo->nRefCount; n++)
nFactor *= 2;
if (nFactor > 1 && (GetRandInt(nFactor) != 0))
nDiffParameter *= 2;
if (nDiffParameter > 1 && (GetRandInt(nDiffParameter) != 0))
return false;
} else {
pinfo = Create(addr, source, &nId);
Expand Down
10 changes: 5 additions & 5 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Value gethashespersec(const Array& params, bool fHelp)

Value getmininginfo(const Array& params, bool fHelp)
{
unsigned char Nfactor;
unsigned char NDiffParameter;
uint64_t N;

if (fHelp || params.size() != 0)
Expand All @@ -122,11 +122,11 @@ Value getmininginfo(const Array& params, bool fHelp)
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
obj.push_back(Pair("testnet", fTestNet));

// WM - Tweaks to report current Nfactor and N.
Nfactor = CalculateN( nBestHeightTime );
N = 1 << ( Nfactor + 1 );
// WM - Tweaks to report current NDiffParameter and N.
NDiffParameter = CalculateN( nBestHeightTime );
N = 1 << ( NDiffParameter + 1 );

//obj.push_back( Pair( "Nfactor", Nfactor ) );
//obj.push_back( Pair( "NDiffParameter", NDiffParameter ) );
//obj.push_back( Pair( "N", N ) );

// WM - Report current Proof-of-Work block reward.
Expand Down
2 changes: 1 addition & 1 deletion src/scrypt-new/code/scrypt-new-test-vectors.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
typedef struct scrypt_test_setting_t {
const char *pw, *salt;
uint8_t Nfactor, rfactor, pfactor;
uint8_t NDiffParameter, rfactor, pfactor;
} scrypt_test_setting;

static const scrypt_test_setting post_settings[] = {
Expand Down
4 changes: 2 additions & 2 deletions src/scrypt-new/scrypt-new-speed.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ get_ticks(void) {

typedef struct scrypt_speed_settings_t {
const char *desc;
uint8_t Nfactor, rfactor, pfactor;
uint8_t NDiffParameter, rfactor, pfactor;
} scrypt_speed_settings;

/* scrypt_r_32kb is set to a 32kb chunk, so (1 << (scrypt_r_32kb - 5)) = 1kb chunk */
Expand Down Expand Up @@ -96,7 +96,7 @@ int main() {
s = &settings[i];
minticks = maxticks;
for (passes = 0; passes < 16; passes++)
timeit(scrypt(password, sizeof(password), salt, sizeof(salt), s->Nfactor, s->rfactor, s->pfactor, digest, sizeof(digest)), minticks)
timeit(scrypt(password, sizeof(password), salt, sizeof(salt), s->NDiffParameter, s->rfactor, s->pfactor, digest, sizeof(digest)), minticks)

printf("%s, %.0f ticks\n", s->desc, (double)minticks);
}
Expand Down
8 changes: 4 additions & 4 deletions src/scrypt-new/scrypt-new.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ scrypt_power_on_self_test() {

for (i = 0, scrypt_valid = 1; post_settings[i].pw; i++) {
t = post_settings + i;
scrypt((uint8_t *)t->pw, strlen(t->pw), (uint8_t *)t->salt, strlen(t->salt), t->Nfactor, t->rfactor, t->pfactor, test_digest, sizeof(test_digest));
scrypt((uint8_t *)t->pw, strlen(t->pw), (uint8_t *)t->salt, strlen(t->salt), t->NDiffParameter, t->rfactor, t->pfactor, test_digest, sizeof(test_digest));
scrypt_valid &= scrypt_verify(post_vectors[i], test_digest, sizeof(test_digest));
}

Expand Down Expand Up @@ -132,7 +132,7 @@ scrypt_free(scrypt_aligned_alloc *aa) {


void
scrypt(const uint8_t *password, size_t password_len, const uint8_t *salt, size_t salt_len, uint8_t Nfactor, uint8_t rfactor, uint8_t pfactor, uint8_t *out, size_t bytes) {
scrypt(const uint8_t *password, size_t password_len, const uint8_t *salt, size_t salt_len, uint8_t NDiffParameter, uint8_t rfactor, uint8_t pfactor, uint8_t *out, size_t bytes) {
scrypt_aligned_alloc YX, V;
uint8_t *X, *Y;
uint32_t N, r, p, chunk_bytes, i;
Expand All @@ -150,14 +150,14 @@ scrypt(const uint8_t *password, size_t password_len, const uint8_t *salt, size_t
}
#endif

if (Nfactor > scrypt_maxN)
if (NDiffParameter > scrypt_maxN)
scrypt_fatal_error("scrypt: N out of range");
if (rfactor > scrypt_maxr)
scrypt_fatal_error("scrypt: r out of range");
if (pfactor > scrypt_maxp)
scrypt_fatal_error("scrypt: p out of range");

N = (1 << (Nfactor + 1));
N = (1 << (NDiffParameter + 1));
r = (1 << rfactor);
p = (1 << pfactor);

Expand Down
6 changes: 3 additions & 3 deletions src/scrypt-new/scrypt-new.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define SCRYPT_JANE_H

/*
Nfactor: Increases CPU & Memory Hardness
N = (1 << (Nfactor + 1)): How many times to mix a chunk and how many temporary chunks are used
NDiffParameter: Increases CPU & Memory Hardness
N = (1 << (NDiffParameter + 1)): How many times to mix a chunk and how many temporary chunks are used
rfactor: Increases Memory Hardness
r = (1 << rfactor): How large a chunk is
Expand All @@ -22,6 +22,6 @@
typedef void (*scrypt_fatal_errorfn)(const char *msg);
void scrypt_set_fatal_error(scrypt_fatal_errorfn fn);

void scrypt(const unsigned char *password, size_t password_len, const unsigned char *salt, size_t salt_len, unsigned char Nfactor, unsigned char rfactor, unsigned char pfactor, unsigned char *out, size_t bytes);
void scrypt(const unsigned char *password, size_t password_len, const unsigned char *salt, size_t salt_len, unsigned char NDiffParameter, unsigned char rfactor, unsigned char pfactor, unsigned char *out, size_t bytes);

#endif /* SCRYPT_JANE_H */
8 changes: 4 additions & 4 deletions src/scrypt_mine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ static void scrypt(const void* input, size_t inputlen, uint32_t *res, void *scra
PBKDF2_SHA256((const uint8_t*)input, inputlen, (uint8_t *)X, 128, 1, (uint8_t*)res, 32);
}

void scrypt_hash(const void* input, size_t inputlen, uint32_t *res, unsigned char Nfactor)
void scrypt_hash(const void* input, size_t inputlen, uint32_t *res, unsigned char NDiffParameter)
{
return scrypt((const unsigned char*)input, inputlen,
(const unsigned char*)input, inputlen,
Nfactor, 0, 0, (unsigned char*)res, 32);
NDiffParameter, 0, 0, (unsigned char*)res, 32);
}

#ifdef SCRYPT_3WAY
Expand Down Expand Up @@ -139,7 +139,7 @@ static void scrypt_3way(const void *input1, const void *input2, const void *inpu

unsigned int scanhash_scrypt(block_header *pdata,
uint32_t max_nonce, uint32_t &hash_count,
void *result, block_header *res_header, unsigned char Nfactor)
void *result, block_header *res_header, unsigned char NDiffParameter)
{
hash_count = 0;
block_header data = *pdata;
Expand Down Expand Up @@ -199,7 +199,7 @@ unsigned int scanhash_scrypt(block_header *pdata,
//scrypt(&data, 80, hash, scratchbuf);
scrypt((const unsigned char*)&data, 80,
(const unsigned char*)&data, 80,
Nfactor, 0, 0, (unsigned char*)hash, 32);
NDiffParameter, 0, 0, (unsigned char*)hash, 32);
hash_count += 1;
#endif
if (hashc[31] == 0 && hashc[30] == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/scrypt_mine.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ void scrypt_buffer_free(void *scratchpad);

unsigned int scanhash_scrypt(block_header *pdata,
uint32_t max_nonce, uint32_t &hash_count,
void *result, block_header *res_header, unsigned char Nfactor);
void *result, block_header *res_header, unsigned char NDiffParameter);

void scrypt_hash(const void* input, size_t inputlen, uint32_t *res, unsigned char Nfactor);
void scrypt_hash(const void* input, size_t inputlen, uint32_t *res, unsigned char NDiffParameter);

#endif // SCRYPT_MINE_H

0 comments on commit 4908a98

Please sign in to comment.