1

I was going through the Create Your Own CryptoCurrency documentation and got stuck at the proofOfWork section. In this, they try to do a check i.e.

require(n >= bytes(difficulty)) //Check if its under difficulty

I wanted to understand, what kind of comparison is being done here?

  1. Is is byte-to-byte comparison?
  2. Is there some conversion happening before the check?
  3. Or, its just a length check (which I think isn't the case, but just to be sure, I added it here).

If someone can point me to the right resource on the same.

  • 1
    The current code in the linked page reads require(n >= bytes8(difficulty)). bytes8 is a fixed-length array of bytes that defines >=, among other comparators. I assume it's doing a byte-to-byte comparison. The code you shared shouldn't compile. – user19510 Dec 5 '17 at 22:12
  • Hmm. If you can provide any reference for this assumption. Thanks – farhankhwaja Dec 5 '17 at 23:34
  • Sorry, but I didn't see the implementation details anywhere. My assumption is just based on the fact that otherwise such a comparison wouldn't make sense. Compiling the code and looking at the assembly might be a good way to verify if we're unable to find documentation. – user19510 Dec 5 '17 at 23:59
  • Yeah. Even I didn’t find any docs on this. Oh ok. Will try doing that. – farhankhwaja Dec 6 '17 at 0:12
0

if n is greater then or equals to the number of bytes in the difficulty then it will be TRUE statement.

Bytes function in python explained:

Return a new “bytes” object, which is an immutable sequence of integers in the range 0 <= x < 256. bytes

ex:

var n = 16
var difficulty = 0x10

var bytes = bytes(difficulty) // 16
n >= bytes is true
  • I'm not sure what you're basing this answer on. Could you provide some evidence for your claim? – user19510 Dec 5 '17 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.