Skip to content

Commit fc56e44

Browse files
authored
Add explanation for double hashing (#24)
1 parent 33eea2b commit fc56e44

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ This library works on "standard" merkle trees designed for Ethereum smart contra
116116
- The leaves are sorted.
117117
- The leaves are the result of ABI encoding a series of values.
118118
- The hash used is Keccak256.
119-
- The leaves are double-hashed to prevent [second preimage attacks].
119+
- The leaves are double-hashed[^1] to prevent [second preimage attacks].
120120

121121
[second preimage attacks]: https://flawed.net.nz/2018/02/21/attacking-merkle-trees-with-a-second-preimage-attack/
122122

@@ -268,3 +268,5 @@ Corresponds to the following expression in Solidity:
268268
```solidity
269269
bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(alice, 100))));
270270
```
271+
272+
[^1]: The underlying reason for hashing the leaves twice is to prevent the leaf values from being 64 bytes long _prior_ to hashing. Otherwise, the concatenation of a sorted pair of internal nodes in the Merkle tree could be reinterpreted as a leaf value. See [here](https://github.com/OpenZeppelin/openzeppelin-contracts/issues/3091) for more details.

0 commit comments

Comments
 (0)