예제 #1
0
void scrypt_process_cpu(minerScryptBlock_t* block)
{
	scrypt_testStuff();
	uint32 outputHash[32/4];	
	char scratchpad[SCRYPT_SCRATCHPAD_SIZE];
	uint32 shareCompare = *(uint32*)(block->targetShare+32-4);
	uint32 nonce = 0;
	for(uint32 t=0; t<32768; t++)
	{
		for(uint32 x=0; x<4096; x++)
		{
			block->nonce = nonce;
			nonce++;
			scrypt_1024_1_1_256_sp((const char*)block, (char*)outputHash, scratchpad);
			if( outputHash[7] < shareCompare )
			{
				totalShareCount++;
				xptMiner_submitShare(block);
			}
			//__debugbreak();
			totalCollisionCount++;
		}
		//if( block->height != monitorCurrentBlockHeight )
		//{
		//	printf("cancled\n");
		//	break;
		//}
	}
	
	//printf("next\n");
	


}
예제 #2
0
파일: scrypt.c 프로젝트: CyberLeo/cgminer
void scrypt_outputhash(struct work *work)
{
	uint32_t data[20];
	char *scratchbuf;
	uint32_t *nonce = (uint32_t *)(work->data + 76);

	be32enc_vect(data, (const uint32_t *)work->data, 19);
	data[19] = htobe32(*nonce);
	scratchbuf = alloca(131584);
	work->outputhash = scrypt_1024_1_1_256_sp(data, scratchbuf);
}
예제 #3
0
파일: scrypt.c 프로젝트: pavlog/cgminer
/* Used externally as confirmation of correct OCL code */
bool scrypt_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
{
	uint32_t tmp_hash7, Htarg = ((const uint32_t *)ptarget)[7];
	char *scratchbuf;
	uint32_t data[20];

	be32enc_vect(data, (const uint32_t *)pdata, 19);
	data[19] = byteswap(nonce);
	scratchbuf = (char*)alloca(131584);
	tmp_hash7 = scrypt_1024_1_1_256_sp(data, scratchbuf);

	return (tmp_hash7 <= Htarg);
}
예제 #4
0
파일: scrypt.c 프로젝트: Axadiw/sgminer
void scrypt_regenhash(struct work *work)
{
	uint32_t data[20];
	char *scratchbuf;
	uint32_t *nonce = (uint32_t *)(work->data + 76);
	uint32_t *ohash = (uint32_t *)(work->hash);

	be32enc_vect(data, (const uint32_t *)work->data, 19);
	data[19] = htobe32(*nonce);
	scratchbuf = (char *)alloca(SCRATCHBUF_SIZE);
	scrypt_1024_1_1_256_sp(data, scratchbuf, ohash);
	flip32(ohash, ohash);
}
예제 #5
0
파일: scrypt.c 프로젝트: Axadiw/sgminer
bool scanhash_scrypt(struct thr_info *thr, const unsigned char __maybe_unused *pmidstate,
		     unsigned char *pdata, unsigned char __maybe_unused *phash1,
		     unsigned char __maybe_unused *phash, const unsigned char *ptarget,
		     uint32_t max_nonce, uint32_t *last_nonce, uint32_t n)
{
	uint32_t *nonce = (uint32_t *)(pdata + 76);
	char *scratchbuf;
	uint32_t data[20];
	uint32_t tmp_hash7;
	uint32_t Htarg = le32toh(((const uint32_t *)ptarget)[7]);
	bool ret = false;

	be32enc_vect(data, (const uint32_t *)pdata, 19);

	scratchbuf = (char *)malloc(SCRATCHBUF_SIZE);
	if (unlikely(!scratchbuf)) {
		applog(LOG_ERR, "Failed to malloc scratchbuf in scanhash_scrypt");
		return ret;
	}

	while(1) {
		uint32_t ostate[8];

		*nonce = ++n;
		data[19] = htobe32(n);
		scrypt_1024_1_1_256_sp(data, scratchbuf, ostate);
		tmp_hash7 = be32toh(ostate[7]);

		if (unlikely(tmp_hash7 <= Htarg)) {
			((uint32_t *)pdata)[19] = htobe32(n);
			*last_nonce = n;
			ret = true;
			break;
		}

		if (unlikely((n >= max_nonce) || thr->work_restart)) {
			*last_nonce = n;
			break;
		}
	}

	free(scratchbuf);;
	return ret;
}
예제 #6
0
파일: scrypt.c 프로젝트: djtms/altcoin
void scrypt_regenhash(struct work *work)
{
	uint32_t data[20];
	char *scratchbuf;
	uint32_t timestamp;
	cl_uint nfactor = 10;    // scrypt default	
	uint32_t *nonce = (uint32_t *)(work->data + 76);
	uint32_t *ohash = (uint32_t *)(work->hash);
 	
	//if (opt_scrypt_vert) {
		timestamp = bswap_32(*((uint32_t *)(work->data + 17*4)));
 		nfactor = alt_GetNfactor(timestamp) + 1;
  //}	

	be32enc_vect(data, (const uint32_t *)work->data, 19);
	data[19] = htobe32(*nonce);
	//scratchbuf = alloca(SCRATCHBUF_SIZE);
	scratchbuf = alloca((1 << nfactor) * 128 + 512);
	scrypt_1024_1_1_256_sp(data, scratchbuf, ohash, (1 << nfactor));
	flip32(ohash, ohash);
}
예제 #7
0
파일: scrypt.c 프로젝트: Axadiw/sgminer
/* Used externally as confirmation of correct OCL code */
int scrypt_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
{
	uint32_t tmp_hash7, Htarg = le32toh(((const uint32_t *)ptarget)[7]);
	uint32_t data[20], ohash[8];
	char *scratchbuf;

	be32enc_vect(data, (const uint32_t *)pdata, 19);
	data[19] = htobe32(nonce);
	scratchbuf = (char *)alloca(SCRATCHBUF_SIZE);
	scrypt_1024_1_1_256_sp(data, scratchbuf, ohash);
	tmp_hash7 = be32toh(ohash[7]);

	applog(LOG_DEBUG, "htarget %08lx diff1 %08lx hash %08lx",
				(long unsigned int)Htarg,
				(long unsigned int)diff1targ,
				(long unsigned int)tmp_hash7);
	if (tmp_hash7 > diff1targ)
		return -1;
	if (tmp_hash7 > Htarg)
		return 0;
	return 1;
}
예제 #8
0
void scrypt_regenhash(struct work *work)
{
	uint32_t data[20];
	char *scratchbuf;
	uint32_t timestamp;
	cl_uint nfactor = 10;    // scrypt default	
	uint32_t *nonce = (uint32_t *)(work->data + 76);
	uint32_t *ohash = (uint32_t *)(work->hash);
 	
	if (opt_nscrypt) {
		timestamp = bswap_32(*((uint32_t *)(work->data + 17*4)));

		// find a way to implement r/m learning -- simulate it for the miners
 	//	nfactor = vert_GetNfactor(timestamp) + 1;
 		nfactor = hin_getNFactor(work->work_block,work->work_difficulty) + 1;
	}	

	be32enc_vect(data, (const uint32_t *)work->data, 19);
	data[19] = htobe32(*nonce);
	//scratchbuf = alloca(SCRATCHBUF_SIZE);
	scratchbuf = alloca((1 << nfactor) * 128 + 512);
	scrypt_1024_1_1_256_sp(data, scratchbuf, ohash, (1 << nfactor));
	flip32(ohash, ohash);
}
static bool epiphany_scrypt(struct thr_info *thr, const unsigned char __maybe_unused *pmidstate,
		     unsigned char *pdata, unsigned char __maybe_unused *phash1,
		     unsigned char __maybe_unused *phash, const unsigned char *ptarget,
		     uint32_t max_nonce, uint32_t *last_nonce, uint32_t n)
{

	uint32_t i;
	e_epiphany_t *dev = &thr->cgpu->epiphany_dev;
	e_mem_t *emem = &thr->cgpu->epiphany_emem;
	unsigned rows = thr->cgpu->epiphany_rows;
	unsigned cols = thr->cgpu->epiphany_cols;

	uint8_t *core_working = calloc(rows*cols, sizeof(uint8_t));
	uint32_t *core_nonce = calloc(rows*cols, sizeof(uint32_t));
	uint32_t cores_working = 0;

	uint32_t *nonce = (uint32_t *)(pdata + 76);

	uint32_t ostate;
	uint32_t data[20];
	const uint8_t core_go = 1;

	uint32_t tmp_hash7;
	uint32_t Htarg = ((const uint32_t *)ptarget)[7];
	bool ret = false;

	be32enc_vect(data, (const uint32_t *)pdata, 19);

	if (e_start_group(dev) == E_ERR) {
		applog(LOG_ERR, "Error: Could not start Epiphany cores.");
		return false;
	}

	off_t offdata = offsetof(shared_buf_t, data);
	off_t offostate = offsetof(shared_buf_t, ostate);
	off_t offcorego = offsetof(shared_buf_t, go);
	off_t offcoreend = offsetof(shared_buf_t, working);
	off_t offcore;

#ifdef EPIPHANY_DEBUG
	#define SCRATCHBUF_SIZE	(131584)
	uint32_t ostate2[8];
	char *scratchbuf = malloc(SCRATCHBUF_SIZE);
	uint32_t *ostatearm = calloc(rows*cols, sizeof(uint32_t));
#endif

	i = 0;
	while(1) {

		offcore = i * sizeof(shared_buf_t);

		if ((!core_working[i]) && (n < max_nonce)) {

			*nonce = ++n;
			data[19] = n;
			core_working[i] = 1;
			cores_working++;
			core_nonce[i] = n;

#ifdef EPIPHANY_DEBUG
			scrypt_1024_1_1_256_sp(data, scratchbuf, ostate2);
			ostatearm[i] = ostate2[7];
#endif

			e_write(emem, 0, 0, offcore + offdata, (void *) data, sizeof(data));
			e_write(emem, 0, 0, offcore + offcoreend, (void *) &core_working[i], sizeof(core_working[i]));
			e_write(emem, 0, 0, offcore + offcorego, (void *) &core_go, sizeof(core_go));

		}

		e_read(emem, 0, 0, offcore + offcoreend, (void *) &(core_working[i]), sizeof(core_working[i]));

		if (!core_working[i]) {

			e_read(emem, 0, 0, offcore + offostate, (void *) &(ostate), sizeof(ostate));
#ifdef EPIPHANY_DEBUG
			applog(LOG_DEBUG, "CORE %u - EPI HASH %u - ARM HASH %u - %s", i, ostate, ostatearm[i], ((ostate==ostatearm[i])? "OK":"FAIL"));
#endif
			tmp_hash7 = be32toh(ostate);
			cores_working--;
			if (unlikely(tmp_hash7 <= Htarg)) {
				((uint32_t *)pdata)[19] = htobe32(core_nonce[i]);
				*last_nonce = core_nonce[i];
#ifdef EPIPHANY_DEBUG
				free(scratchbuf);
#endif
				return true;
			}

		}

		if (unlikely(((n >= max_nonce) && !cores_working) || thr->work_restart)) {
			*last_nonce = n;
#ifdef EPIPHANY_DEBUG
			free(scratchbuf);
#endif
			return false;
		}

		i++;
		i %= rows * cols;

	}

#ifdef EPIPHANY_DEBUG
	free(scratchbuf);
#endif

	return false;
}