Skip to content

Commit b7d56bb

Browse files
committed
Use sha256 for the MerkleProof custom hash tests
1 parent f388e69 commit b7d56bb

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

contracts/mocks/MerkleProofCustomHashMock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {MerkleProof} from "../utils/cryptography/MerkleProof.sol";
77
// This could be a library, but then we would have to add it to the Stateless.sol mock for upgradeable tests
88
abstract contract MerkleProofCustomHashMock {
99
function customHash(bytes32 a, bytes32 b) internal pure returns (bytes32) {
10-
return a < b ? keccak256(abi.encode(bytes32(0), a, b)) : keccak256(abi.encode(bytes32(0), b, a));
10+
return a < b ? sha256(abi.encode(a, b)) : sha256(abi.encode(b, a));
1111
}
1212

1313
function verify(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal view returns (bool) {

test/utils/cryptography/MerkleProof.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const { SimpleMerkleTree } = require('@openzeppelin/merkle-tree');
66
// generate bytes32 leaves from a string
77
const toLeaves = (str, separator = '') => str.split(separator).map(e => ethers.keccak256(ethers.toUtf8Bytes(e)));
88
// internal node hashes
9-
const hashSorted = (...elements) => ethers.keccak256(Buffer.concat(elements.map(ethers.getBytes).sort(Buffer.compare)));
10-
const defaultHash = (a, b) => hashSorted(a, b);
11-
const customHash = (a, b) => hashSorted(ethers.ZeroHash, a, b);
9+
const concatSorted = (...elements) => Buffer.concat(elements.map(ethers.getBytes).sort(Buffer.compare));
10+
const defaultHash = (a, b) => ethers.keccak256(concatSorted(a, b));
11+
const customHash = (a, b) => ethers.sha256(concatSorted(a, b));
1212

1313
describe('MerkleProof', function () {
1414
for (const { title, contractName, nodeHash } of [

0 commit comments

Comments
 (0)