A Hash or also called hash function is any algorithm that maps data of arbitrary length to data of a fixed length. The values returned by a hash function are called hash values, hash codes, hash sums, checksums or simply hashes. Recent development of internet payment networks and digital money, such as Bitcoin, also uses a form of 'hashing' for checksums, and has brought additional attention to the term.
Hash function Review
Hash functions are primarily used to generate fixed-length output data that acts as a shortened reference to the original data. This is useful when the original data is too cumbersome to use in its entirety.
One practical use is a data structure called a hash table where the data is stored associatively. Searching linearly for a person's name in a list becomes cumbersome as the length of the list increases, but the hashed value can be used to store a reference to the original data and retrieve constant time (barring collisions). Another use is in cryptography, the science of encoding and safeguarding data. It is easy to generate hash values from input data and easy to verify that the data matches the hash, but hard to 'fake' a hash value to hide malicious data. This is the principle behind the PGP algorithm for data validation.
To be considered effective a hash function has to have following properties:
- Computational efficiency - it shouldn't take a long time to compute a hash from a given input.
- Collision resistance - it should be hard to find to distinct inputs that would result in the same hash after the application of the hash function.
- Ability to hide information - it should be hard to derive anything useful about the input from the hash whether it be the whole input data or as simple info about it as whether it is an odd or an even number.
- Random-looking hash - the hash should look like it was a result of several random events, like flipping a coin. There shouldn't be an apparent particular transformation protocol.
Bitcoin Hash function
Bitcoin uses the SHA-256 hash algorithm to generate verifiably "random" numbers in a way that requires a predictable amount of CPU effort. Generating a SHA-256 hash with a value less than the current target solves a block and wins you some coins.
The MD5, SHA-1, SHA-256 and SHA-512 test results based on two cases with short string (36 and 49 chars) and longer string (72 and 85 chars).
- SHA-256 is faster with 31% than SHA-512 only when hashing small strings. When the string is longer SHA-512 is faster with 2.9%.
- Time to get system time stamp is ~121.6 ms per 1M iterations.
- Time to generate UUID is ~670.4 ms per 1M iterations.
- SHA-1 is fastest hashing function with ~587.9 ms per 1M operations for short strings and 881.7 ms per 1M for longer strings.
- MD5 is 7.6% slower than SHA-1 for short strings and 1.3% for longer strings.
- SHA-256 is 15.5% slower than SHA-1 for short strings and 23.4% for longer strings.
- SHA-512 is 51.7% slower that SHA-1 for short strings and 20% for longer.
What is a hash Bitcoin
In the bitcoin protocol, hash functions are part of the block hashing algorithm which is used to write new transactions into the blockchain through the mining process.
Hash functions in bitcoin mining, the inputs for the function are all of the most recent, not-yet-confirmed transactions (along with some additional inputs relating to the timestamp and a reference to the previous block).
In the code example above, we’ve already seen that changing a small part of the input for a hash function results in a completely different output. This property is crucial to the ‘proof of work’ algorithm involved in mining: to successfully ‘solve’ a block, miners try to combine all of the inputs with their own arbitrary piece of input data in such a way that the resulting hash starts with a certain number of zeroes.
As a hash function example, we could try ‘mining’ with our Python hash function by manually adding exclamation points after “CoinDesk rocks!” until we find a hash that starts with a single zero.
Hash example: >>> hash("CoinDesk rocks!!") 66925f1da83c54354da73d81e013974d >>> hash("CoinDesk rocks!!!") c8de96b4cf781a6373766c668ceac0f0 >>> hash("CoinDesk rocks!!!!") 9ea367cea6a2cc4a6f5a1d9a334d0d9e >>> hash("CoinDesk rocks!!!!!") b8d43387d98f035e2f0ac49740a5af38 >>> hash("CoinDesk rocks!!!!!!") 0fe46518541f4739613b9ce29ecea6b6 => SOLVED!
Solving the hash functions in bitcoin block – which at the time of writing must start with 18 zeros – requires an extremely large amount of computation (and so the combined processing power of all the computers in the network still takes approximately 10 minutes to solve a block).
It’s the need for this large amount of processing power that means new bitcoins get mined over a long period of time, not all at once.
In order to earn bitcoins through mining, you need to put in the huge amount of work necessary to solve a block – and by earning that reward, you’re locking in all of the new transactions into a block, which is added to the permanent record of all previous transactions: the blockchain.
Bitcoin transaction hash in wallet
Transaction hash (txid) is an identifier used to uniquely identify a particular transaction. All on-chain transactions (the transactions from or to external addresses) have a unique txid that can be seen in transaction details. A transaction hash usually looks like a random set of letters and numbers. All on-chain transactions (depositing and withdrawing of funds) have a unique txid that can be found in transaction details.
In Freewallet apps:
Tap on a transaction > Search for Hash in the list > Check your transaction in the blockchain.
- Hash function page on Wikipedia.org