scipr-lab / libsnark

C++ library for zkSNARKs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is 2-to-1 hash?

RamboRick opened this issue · comments

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.

commented

#132

It only applies the compression function.

@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.