Skip to content

Commit

Permalink
Use sha256 for the MerkleProof custom hash tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Jul 15, 2024
1 parent f388e69 commit b7d56bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contracts/mocks/MerkleProofCustomHashMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {MerkleProof} from "../utils/cryptography/MerkleProof.sol";
// This could be a library, but then we would have to add it to the Stateless.sol mock for upgradeable tests
abstract contract MerkleProofCustomHashMock {
function customHash(bytes32 a, bytes32 b) internal pure returns (bytes32) {
return a < b ? keccak256(abi.encode(bytes32(0), a, b)) : keccak256(abi.encode(bytes32(0), b, a));
return a < b ? sha256(abi.encode(a, b)) : sha256(abi.encode(b, a));
}

function verify(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal view returns (bool) {
Expand Down
6 changes: 3 additions & 3 deletions test/utils/cryptography/MerkleProof.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const { SimpleMerkleTree } = require('@openzeppelin/merkle-tree');
// generate bytes32 leaves from a string
const toLeaves = (str, separator = '') => str.split(separator).map(e => ethers.keccak256(ethers.toUtf8Bytes(e)));
// internal node hashes
const hashSorted = (...elements) => ethers.keccak256(Buffer.concat(elements.map(ethers.getBytes).sort(Buffer.compare)));
const defaultHash = (a, b) => hashSorted(a, b);
const customHash = (a, b) => hashSorted(ethers.ZeroHash, a, b);
const concatSorted = (...elements) => Buffer.concat(elements.map(ethers.getBytes).sort(Buffer.compare));
const defaultHash = (a, b) => ethers.keccak256(concatSorted(a, b));
const customHash = (a, b) => ethers.sha256(concatSorted(a, b));

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

0 comments on commit b7d56bb

Please sign in to comment.