Author

Topic: Where is hashing algorithm code? (Read 485 times)

member
Activity: 138
Merit: 10
February 15, 2019, 04:01:59 PM
#12
According to the bitcoin source code, the hash for the block header can be seen from the file src/primitives/block.cpp under
Code:
uint256 CBlockHeader::GetHash() const
{
    return SerializeHash(*this);
}

https://github.com/bitcoin/bitcoin/blob/master/src/primitives/block.cpp#L13

Which return the value of SerializeHash(*this), That is declared on the file hash.h

Code:
/** Compute the 256-bit hash of an object's serialization. */
template
uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
{
    CHashWriter ss(nType, nVersion);
    ss << obj;
    return ss.GetHash();
}

And according to the comment above it,
 /** Compute the 256-bit hash of an object's serialization. */

The SerializeHash will call CHashWriter and return the value of GetHash which is a simple sha256d hashing algorithm result


(Please, let me know if I'm wrong, I'm still studying bitcoin code)
member
Activity: 293
Merit: 13
AKA merlin.
February 11, 2019, 02:58:43 AM
#11
1 - https://github.com/litecoin-project/litecoin/tree/40809aed657502e9de158e2cfe2c659a316f2f90       
                                       
( bitcoin )



2 - https://github.com/litecoin-project/litecoin/tree/9ab59ab97a351a814ceeea0ee2c74943698bb3ae     
             
 (Litecoin: CLIENT_VERSION_IS_RELEASE = false )



3 - https://github.com/litecoin-project/litecoin/tree/2acab1baf17c096ba9064f35b56d667e67a1f130
               
( Litecoin: Scrypt n=1024 Pow hash based upon Colin Percival's Tarnsnap… )



4 - https://github.com/litecoin-project/litecoin/tree/d6e580d43fd6ba511db3c47eed53c64c07d3c734
                     
( Litecoin: Adapt scrypt code to C++ )



5 - https://github.com/litecoin-project/litecoin/tree/9b5ca659e4ce1d56edb55acd5c51aed88bb8a4c6

(Litecoin: Default TCP ports, mainnet 9333 testnet 19333 RPC ports, ma… )


6 - https://github.com/litecoin-project/litecoin/tree/0b646aed42d44a3e7f41bff590f00395d6e390c8

( Litecoin: Protocol, genesis and parameters * 2.5 minute average between blocks * 3.5 days between diff changes * 84 million coin limit * Addresses begin with L )
member
Activity: 293
Merit: 13
AKA merlin.
February 11, 2019, 02:49:07 AM
#10
Some answers :

First Litecoin's commits were actually a bitcoin's branch on github, NOT a github's fork of bitcoin.....

So here are the first "commits" for Litecoin :


Litecoin: Scrypt n=1024 Pow hash based upon Colin Percival's Tarnsnap…


https://github.com/bitcoin/bitcoin/commit/2acab1baf17c096ba9064f35b56d667e67a1f130

https://github.com/bitcoin/bitcoin/tree/2acab1baf17c096ba9064f35b56d667e67a1f130




Litecoin: Adapt scrypt code to C++


https://github.com/bitcoin/bitcoin/commit/d6e580d43fd6ba511db3c47eed53c64c07d3c734

https://github.com/bitcoin/bitcoin/tree/d6e580d43fd6ba511db3c47eed53c64c07d3c734


All those commits can be found here :

https://github.com/bitcoin/bitcoin/compare/master...litecoin-project:0.8

( search on the page for Commits on Jul 07, 2013 )



then, use Meld on ubuntu to compare with bitcoin's source code at this time !

legendary
Activity: 3038
Merit: 2162
June 30, 2018, 08:32:20 AM
#9
So bitcoin uses sha256, litecoin scrypt, dash x11.

Where is revision location(source code filename, approx line position)  of this algorithm?

Is it widespread and hard to revise? or easy to change?

How change to x11 algorithm? Some site says x11 is best algorithm.



I'm not a C++ developer, but I think the SHA256 implementation used by Bitcoin Core client is here: https://github.com/bitcoin/bitcoin/blob/master/src/crypto/sha256.cpp

I would strongly advice against modifying anything in this or any other hashing algorithm, they were carefully tuned to be as secure as possible, and changing just a few constants can drastically reduce their security.

If you want to create a fork of Bitcoin with different algorithm, you'll have to do a lot of work. You will very likely fail if you are not an experienced programmer.
newbie
Activity: 27
Merit: 0
February 12, 2018, 07:58:50 AM
#8
The work which has to be done to find a new block is not directly dependend on the algorithm.
Additionally you can't decrypt anything in this scenario.

Encryption != Hashing [1]

Hashing is a one-way-function.
This means: You can (relatively) easy calculate a hash of any value. But you can't get the original value out of the hash.

When you are trying to find a new block (mining) you are basically calculating hashes until you find one hash that (for example) begins with 10 zeros.
The difficulty adjusts to assure a new block every 10 minutes. You can look at the difficulty as "X zeros have to be at the beginning of the hash".

On average there has to be Y hashes calculated until a valid one is found. Thats basically a "probability-game".
[1] A more detailed explanation: https://en.wikipedia.org/wiki/Hash_function

Thanks you so much man. You deserve a like/thumb up. Which I cant find in this forum lol.
hero member
Activity: 854
Merit: 658
rgbkey.github.io/pgp.txt
February 11, 2018, 11:14:20 PM
#7
So bitcoin uses sha256, litecoin scrypt, dash x11.
Where is revision location(source code filename, approx line position)  of this algorithm?

Simply google. Those algorithms (SHA, scrypt) weren't invented for those cryptocurrencies.
They existed before.

SHA: https://en.wikipedia.org/wiki/SHA-2
scrypt: https://en.wikipedia.org/wiki/Scrypt

X11 is concatenated algorithm composed of  BLAKE, BMW, Grøstl, JH, Keccak, Skein, Luffa, CubeHash, SHAvite, SIMD and Echo.



How change to x11 algorithm? Some site says x11 is best algorithm.

Changing the algorithm would require a hard fork (https://en.wikipedia.org/wiki/Fork_(blockchain)#Hard_fork).
There is no "best" algorithm.
Simply because there is no definition of a "best" algorithm.

Additionally you should not believe what you read on "some site".

Thanks, but what I wondered is where should I revise at bitcoin source code to change its algorithm from sha256 to another?

It looks like you better have a good idea of what you're doing before you attempt to make your own coin, as that's what it sounds like what you want to do.
jr. member
Activity: 413
Merit: 5
February 11, 2018, 10:44:04 PM
#6
So bitcoin uses sha256, litecoin scrypt, dash x11.
Where is revision location(source code filename, approx line position)  of this algorithm?

Simply google. Those algorithms (SHA, scrypt) weren't invented for those cryptocurrencies.
They existed before.

SHA: https://en.wikipedia.org/wiki/SHA-2
scrypt: https://en.wikipedia.org/wiki/Scrypt

X11 is concatenated algorithm composed of  BLAKE, BMW, Grøstl, JH, Keccak, Skein, Luffa, CubeHash, SHAvite, SIMD and Echo.



How change to x11 algorithm? Some site says x11 is best algorithm.

Changing the algorithm would require a hard fork (https://en.wikipedia.org/wiki/Fork_(blockchain)#Hard_fork).
There is no "best" algorithm.
Simply because there is no definition of a "best" algorithm.

Additionally you should not believe what you read on "some site".

Thanks, but what I wondered is where should I revise at bitcoin source code to change its algorithm from sha256 to another?
legendary
Activity: 990
Merit: 1108
February 11, 2018, 11:13:00 AM
#5
legendary
Activity: 1624
Merit: 2481
February 11, 2018, 10:21:18 AM
#4
Just wonder that the work of finding a new block(mining) is it kind of decrypting these algorithm?

The work which has to be done to find a new block is not directly dependend on the algorithm.
Additionally you can't decrypt anything in this scenario.

Encryption != Hashing [1]

Hashing is a one-way-function.
This means: You can (relatively) easy calculate a hash of any value. But you can't get the original value out of the hash.

When you are trying to find a new block (mining) you are basically calculating hashes until you find one hash that (for example) begins with 10 zeros.
The difficulty adjusts to assure a new block every 10 minutes. You can look at the difficulty as "X zeros have to be at the beginning of the hash".

On average there has to be Y hashes calculated until a valid one is found. Thats basically a "probability-game".



[1] A more detailed explanation: https://en.wikipedia.org/wiki/Hash_function
newbie
Activity: 27
Merit: 0
February 11, 2018, 09:34:06 AM
#3
So bitcoin uses sha256, litecoin scrypt, dash x11.
Where is revision location(source code filename, approx line position)  of this algorithm?

Simply google. Those algorithms (SHA, scrypt) weren't invented for those cryptocurrencies.
They existed before.

SHA: https://en.wikipedia.org/wiki/SHA-2
scrypt: https://en.wikipedia.org/wiki/Scrypt

X11 is concatenated algorithm composed of  BLAKE, BMW, Grøstl, JH, Keccak, Skein, Luffa, CubeHash, SHAvite, SIMD and Echo.



How change to x11 algorithm? Some site says x11 is best algorithm.

Changing the algorithm would require a hard fork (https://en.wikipedia.org/wiki/Fork_(blockchain)#Hard_fork).
There is no "best" algorithm.
Simply because there is no definition of a "best" algorithm.

Additionally you should not believe what you read on "some site".

Thanks for your informative explanation.
Just wonder that the work of finding a new block(mining) is it kind of decrypting these algorithm?
legendary
Activity: 1624
Merit: 2481
February 11, 2018, 08:35:06 AM
#2
So bitcoin uses sha256, litecoin scrypt, dash x11.
Where is revision location(source code filename, approx line position)  of this algorithm?

Simply google. Those algorithms (SHA, scrypt) weren't invented for those cryptocurrencies.
They existed before.

SHA: https://en.wikipedia.org/wiki/SHA-2
scrypt: https://en.wikipedia.org/wiki/Scrypt

X11 is concatenated algorithm composed of  BLAKE, BMW, Grøstl, JH, Keccak, Skein, Luffa, CubeHash, SHAvite, SIMD and Echo.



How change to x11 algorithm? Some site says x11 is best algorithm.

Changing the algorithm would require a hard fork (https://en.wikipedia.org/wiki/Fork_(blockchain)#Hard_fork).
There is no "best" algorithm.
Simply because there is no definition of a "best" algorithm.

Additionally you should not believe what you read on "some site".
jr. member
Activity: 413
Merit: 5
February 11, 2018, 06:44:31 AM
#1
So bitcoin uses sha256, litecoin scrypt, dash x11.

Where is revision location(source code filename, approx line position)  of this algorithm?

Is it widespread and hard to revise? or easy to change?

How change to x11 algorithm? Some site says x11 is best algorithm.

Jump to: