Bitcoin Forum

Alternate cryptocurrencies => Altcoin Discussion => Topic started by: wsxdrfv on February 11, 2018, 11:44:31 AM



Title: Where is hashing algorithm code?
Post by: wsxdrfv on February 11, 2018, 11:44:31 AM
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.



Title: Re: Where is hashing algorithm code?
Post by: bob123 on February 11, 2018, 01:35:06 PM
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 (https://en.wikipedia.org/wiki/SHA-2)
scrypt: https://en.wikipedia.org/wiki/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 (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".


Title: Re: Where is hashing algorithm code?
Post by: t1192002 on February 11, 2018, 02:34:06 PM
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 (https://en.wikipedia.org/wiki/SHA-2)
scrypt: https://en.wikipedia.org/wiki/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 (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?


Title: Re: Where is hashing algorithm code?
Post by: bob123 on February 11, 2018, 03:21:18 PM
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 (https://en.wikipedia.org/wiki/Hash_function)


Title: Re: Where is hashing algorithm code?
Post by: tromp on February 11, 2018, 04:13:00 PM
Encryption != Hashing

And Proof-of-Work is not (necessarily) Hashing [1]

[1] http://cryptorials.io/beyond-hashcash-proof-work-theres-mining-hashing/


Title: Re: Where is hashing algorithm code?
Post by: wsxdrfv on February 12, 2018, 03:44:04 AM
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 (https://en.wikipedia.org/wiki/SHA-2)
scrypt: https://en.wikipedia.org/wiki/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 (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?


Title: Re: Where is hashing algorithm code?
Post by: RGBKey on February 12, 2018, 04:14:20 AM
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 (https://en.wikipedia.org/wiki/SHA-2)
scrypt: https://en.wikipedia.org/wiki/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 (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 (https://github.com/bitcoin/bitcoin/search?utf8=%E2%9C%93&q=sha256+OR+hash) before you attempt to make your own coin, as that's what it sounds like what you want to do.


Title: Re: Where is hashing algorithm code?
Post by: t1192002 on February 12, 2018, 12:58:50 PM
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 (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.


Title: Re: Where is hashing algorithm code?
Post by: hatshepsut93 on June 30, 2018, 01:32:20 PM
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.


Title: Re: Where is hashing algorithm code?
Post by: LighningCashDev on February 11, 2019, 07:49:07 AM
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 )

https://i.ibb.co/PMm5Fp2/Screenshot-from-2019-02-11-02-46-48.png

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



Title: Re: Where is hashing algorithm code?
Post by: LighningCashDev on February 11, 2019, 07:58:43 AM
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 )


Title: Re: Where is hashing algorithm code?
Post by: ItaCraft on February 15, 2019, 09:01:59 PM
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) (https://github.com/bitcoin/bitcoin/blob/master/src/hash.h#L196), That is declared on the file hash.h

Code:
/** Compute the 256-bit hash of an object's serialization. */
template<typename T>
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 (https://github.com/bitcoin/bitcoin/blob/master/src/hash.h#L136) which is a simple sha256d hashing algorithm result


(Please, let me know if I'm wrong, I'm still studying bitcoin code)