Update after reading some code:
- Nfactor is only used for memory allocation size - so it has no actual effect on the implementation; in other words, N is not dynamic
- The code is quite messy, and even something as simple as the memory allocator is broken (it pretty much ignores the size of the allocation request)
I think this one gets a "scamcoin" classification...
Luke-Jr, interesting comment. I had a brief go at the code as well, but can't confirm your findings. Maybe you were a bit quick shouting "scamcoin", eh?
- Yes, the scrypt codebase is ugly. #define's and #ifdefs everywhere. Is this a copy of the original scrypt?
- The scrypt romix code in scrypt-jane-romix-template.h (function called SCRYPT_ROMIX_FN) does use N (i.e. Nfactor) looping from 1 to N, in addition to increasing the mem size by N. I don't know enough about the underlying crypto, but I believe complexity scales at least by O(N2).
- The allocate and free methods are totally fine. You have tripped over an #ifdef:
// jomay: I left out the test code - this is the one you've read.
// It works fine in practice as well, but makes the scrypt() function non re-entrant.
#else
// jomay: here goes the real deal - fully functional, no mem leak, fine.
static scrypt_aligned_alloc scrypt_alloc(uint64_t size) {
static const size_t max_alloc = (size_t)-1;
scrypt_aligned_alloc aa;
size += (SCRYPT_BLOCK_BYTES - 1);
if (size > max_alloc)
scrypt_fatal_error("scrypt: not enough address space on this CPU to allocate required memory");
aa.mem = (uint8_t *)malloc((size_t)size);
aa.ptr = (uint8_t *)(((size_t)aa.mem + (SCRYPT_BLOCK_BYTES - 1)) & ~(SCRYPT_BLOCK_BYTES - 1));
if (!aa.mem)
scrypt_fatal_error("scrypt: out of memory");
return aa;
}
static void scrypt_free(scrypt_aligned_alloc *aa) {
free(aa->mem);
}
#endif
Where did it come from?
YACoins scrypt-jane master branch: https://github.com/pocopoco/yacoin/blob/master/src/scrypt-jane/
scrypt_alloc is at lines 86-129. As clearly stated above, the posted code simply leaves out the SCRYPT_TEST_SPEED #ifdef branch: https://github.com/pocopoco/yacoin/blob/master/src/scrypt-jane/scrypt-jane.c
SCRYPT_ROMIX_FN is defined here: https://github.com/pocopoco/yacoin/blob/master/src/scrypt-jane/code/scrypt-jane-romix-template.h
Where did you look at?