Unverified Commit 06666be9 by Francisco Giordano Committed by GitHub

change MerkleProof interface to take array of bytes32 (#879)

parent 915f74c5
...@@ -14,21 +14,11 @@ library MerkleProof { ...@@ -14,21 +14,11 @@ library MerkleProof {
* @param _root Merkle root * @param _root Merkle root
* @param _leaf Leaf of Merkle tree * @param _leaf Leaf of Merkle tree
*/ */
function verifyProof(bytes _proof, bytes32 _root, bytes32 _leaf) public pure returns (bool) { function verifyProof(bytes32[] _proof, bytes32 _root, bytes32 _leaf) public pure returns (bool) {
// Check if proof length is a multiple of 32
if (_proof.length % 32 != 0) {
return false;
}
bytes32 proofElement;
bytes32 computedHash = _leaf; bytes32 computedHash = _leaf;
for (uint256 i = 32; i <= _proof.length; i += 32) { for (uint256 i = 0; i < _proof.length; i++) {
// solium-disable-next-line security/no-inline-assembly bytes32 proofElement = _proof[i];
assembly {
// Load the current element of the proof
proofElement := mload(add(_proof, i))
}
if (computedHash < proofElement) { if (computedHash < proofElement) {
// Hash(current computed hash + current element of the proof) // Hash(current computed hash + current element of the proof)
......
...@@ -79,7 +79,7 @@ export default class MerkleTree { ...@@ -79,7 +79,7 @@ export default class MerkleTree {
getHexProof (el) { getHexProof (el) {
const proof = this.getProof(el); const proof = this.getProof(el);
return this.bufArrToHex(proof); return this.bufArrToHexArr(proof);
} }
getPairElement (idx, layer) { getPairElement (idx, layer) {
...@@ -117,12 +117,12 @@ export default class MerkleTree { ...@@ -117,12 +117,12 @@ export default class MerkleTree {
}); });
} }
bufArrToHex (arr) { bufArrToHexArr (arr) {
if (arr.some(el => !Buffer.isBuffer(el))) { if (arr.some(el => !Buffer.isBuffer(el))) {
throw new Error('Array is not an array of buffers'); throw new Error('Array is not an array of buffers');
} }
return '0x' + arr.map(el => el.toString('hex')).join(''); return arr.map(el => '0x' + el.toString('hex'));
} }
sortAndConcat (...args) { sortAndConcat (...args) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment