scipr-lab / libsnark

C++ library for zkSNARKs
Other
1.81k stars 572 forks source link

What is 2-to-1 hash? #146

Open RamboRick opened 5 years ago

RamboRick commented 5 years ago

The example of sha256 is 2-to-1 hash! In my mind, there is an input and it will generate the hash value as the output. Why here needs left_bv and right_bv ? What is the relationship with single hash? Thank you.

derekzx commented 5 years ago

https://github.com/scipr-lab/libsnark/issues/132

It only applies the compression function.

mathcrypto commented 5 years ago

@fanghaos2014 you can use the sha256 2-to-1 to compute the hash in Merkle tree for example. Let's say you want to compute the Merkle root and you have the leaf digest H_1 (which would be left_bv or right_bv depending on the direction selector) and you take another digest H_2 from the Merkle path in the same tree depth as the leaf to compute the hash of their concatenation H_12= sha256(H_1||H_2). You continue doing so until you compute the Merkle root.