1

Is 0x0 just zero? thanks

keccak256(number) = 0x0; 

Or when not used as address I mean just to denote variable?

2

The 0x prefix means hexadecimal and it's a way to tell programs, contracts, APIs that the input should be interpreted as a hexadecimal number (we'll shorten to hex). 0x0 is actually 0 but in hex. Usually we use 0x0 to check whether the address is not set by us and it is set to default value by the solidity which is 0x0.

require(_addressIn != address(0))

E.g. 0x0 in Solidity is short for 0x0000000000000000000000000000000000000000, and if we use this as some address than it does have value greater than zero. check here.

Keccak256 computes the Ethereum-SHA-3 (Keccak-256) hash (doc) of the arguments passed into the function. So the above line of code is not correct because keccak256(number) is returning the hash value which you can store in some variable, instead you are trying to treat the output hash value as an variable and assigning the 0x0 to that.

I hope it helps.

  • 1
    "0x0 in Solidity is short for 0x0000000000000000000000000000000000000000" I guess technically that's true, just like in decimal, 0 is short for 0000000000 (for any number of 0s). But I think it's misleading to say that, as it makes people think it represents some special value or some specific type. It just means 0. – smarx Mar 12 at 1:17
3

The example given wouldn't actually work because you're trying to assign 0x0 to the keccak function.

It has the same meaning as bytes32(0). So, you can go:

require(bytes32(0) == 0x0);

That would be comparing equivalents. It was possible to compare address and 0x0 but the trend seems to be toward explicit type casting, so you would go address(0) with a recent compiler.

This type of expression is often used to validate inputs, in particular, catching important values that were not passed in. This is common:

function doSomething(bytes32 key) ... {
  require(key != 0x0);
  // carry on
}

Hope it helps.

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.