Bitcoin Forum
May 28, 2024, 08:28:08 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 [49]
961  Other / Beginners & Help / Re: A newbie wants to understand the bitcoin mining concept on: January 21, 2012, 09:23:00 PM
Since the hashes are declared as uint8, you should see it as unsigned, so no they will never be negative.


Thanks...I was just confused about the difficulty, since the wiki says it's signed...
962  Other / Beginners & Help / Re: Newbies Hangout on: January 17, 2012, 12:12:16 AM
Hmmh...so far it doesn't feel so bad being a newbie here...I already got a nice reply from a forum member.

And I admit, that it'll take some time before I'll understand the details of mining, so it's ok to be considered a newbie for a while...
963  Other / Beginners & Help / Re: A newbie wants to understand the bitcoin mining concept on: January 16, 2012, 06:53:48 PM
The current code is available here:

http://www.forum64.de/wbb3/board25-coder-unter-sich/board308-programmieren/board29-cross-development/45342-bitcoin-mining-auf-dem-c64/#post579246

At the moment, it's just a hack to get something going. The sha256 code is a mixture of some implementations, found at various place of the net. Some of it is from Christophe Devine, but I couldn't use the optimized code with the unrolled loops due to memory constraints. The Makefile does no real speed optimization yet, since I wanted the code to be optimized for size and not speed.  The networking part is completely missing yet, but I doubt if it makes sense to request actual blocks, since the breadbox is just too slow for productive work (100 nonces in 274 seconds at the moment).

Ciao,
Andreas
964  Other / Beginners & Help / Re: A newbie wants to understand the bitcoin mining concept on: January 16, 2012, 05:19:38 PM
Thanks a lot for your comment. I had the option of a negative difficulty in my code, because the wiki said, that it's a signed value. From a practical point of view, a negative difficulty doesn't make much sense, so I will fix my code.

Thanks again for your reply,
Andreas
965  Other / Beginners & Help / A newbie wants to understand the bitcoin mining concept on: January 16, 2012, 01:16:09 PM
Hi!

Sorry for my poor Englisch, but it's not my native tongue, since I'm from Germany.

I have read about the bitcoin concept a while ago and already installed a miner on my Radeon 5850. Works ago, but I'd like to get a small miner going on my daily coding machine, which has a GeForce 7. So I got me BrookGPU, got some demo apps going and want to write some code for it.

Since I have not much clue about the whole mining process, I thought that I should start with a very simple demo app, called hashcode and modify it to do something useful. So I ported it to the cc65 compiler and run it on Vice (a c64 emulator) just to have some fun with it and to understand the code etc.

My current problem is the difficulty <=> hash comparison. I wrote a decode function for the difficulty according to the Wiki entry:

Code:
/**
 * Decode the target into a 256 bit int. See the target entry in the bitcoin wiki for details.
 */
void decodeDifficulty( uint8 *targetArray, uint32 target) {
  uint32 offset = ( ( target >> 24) - 3) << 3;
  int bitshift = offset & 7;
  int currentByte = offset >> 3;
  uint32 targetBits = target & (uint32)0x00ffffff;

  if( targetBits & 0x00800000) {  // Is the difficulty negative?
    targetBits |= (uint32)0xff000000;
    bzero( targetArray, sizeof(uint8) * currentByte);  // Empty everything below the bitmask
    memset( &targetArray[ currentByte + 4], 0xff, sizeof( uint8) * ( SHA256_DIGEST_LENGTH - 4 - currentByte));  // Fill bits over the bitmask with 1 for sign extension
  } else {
    bzero( targetArray, sizeof(uint8) * SHA256_DIGEST_LENGTH);  // Empty the target array
  }

  targetArray[ currentByte++] = (uint8)( targetBits & 0xff);
  targetBits >>= 8;
  targetArray[ currentByte++] = (uint8)( targetBits & 0xff);
  targetBits >>= 8;
  targetArray[ currentByte++] = (uint8)( targetBits & 0xff);
  targetBits >>= 8;
  targetArray[ currentByte] = (uint8)( targetBits & 0xff);
}

and a compare function for 32 byte integers:

Code:
/**
 * Compare 2 256 bit integer values.
 *
 * @return a value > 0, if hash1 > hash2 , a value < 0, if hash1 < hash2 and 0 if they are equal.
 */
int compareHash( uint8 *hash1, uint8 *hash2) {
  uint8 msb1, msb2;
  int currentByte;
  int byteDifference;

  // Check, if both numbers have the same sign..
  msb1 = hash1[ SHA256_DIGEST_LENGTH - 1] & 0x80;
  msb2 = hash2[ SHA256_DIGEST_LENGTH - 1] & 0x80;

  if( msb1 != msb2) {  // Both numbers differ in sign
    return msb1 ? -1 : 1;
  }
 
  // We have to compare byte by byte... :-(
  for( currentByte = SHA256_DIGEST_LENGTH - 1; currentByte >= 0; --currentByte) {

    byteDifference = hash1[ currentByte] - hash2[ currentByte];  // Compute the difference of the current bytes-.

    if( byteDifference) {     // If the bytes differ.
      return byteDifference;  // just return the difference.
    }
  }

  return 0;  // both ints are equal.
}

, but what happens if the hash is greater then 0x8000.... => is negative? It's smaller in my current code, so it would be a solution, which is wrong as I understand it. So should I compare abs(hash) < difficulty ?

Thanks in advance,
Andreas
Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 [49]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!