Skip to content

Instantly share code, notes, and snippets.

@YHTerrance
Created November 13, 2022 00:59
Show Gist options
  • Save YHTerrance/5ee7b901d67e4f4637ee247b29b69291 to your computer and use it in GitHub Desktop.
Save YHTerrance/5ee7b901d67e4f4637ee247b29b69291 to your computer and use it in GitHub Desktop.
This is the solver for FinTech 2022 Homework 4 Problem 4
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Solver {
bytes32[] public hashes;
bytes32[] public proof;
constructor() {
string[7] memory tx = [
"zkpenguin",
"zkpancake",
"zkpolice",
"zkpig",
"zkplayground",
"zkpigeon",
"zkpoison"
];
for (uint256 i = 0; i < tx.length; i++) {
hashes.push(keccak256(abi.encodePacked(tx[i])));
}
}
function computeProof() public {
// 1st hash
proof.push(hashes[0]);
// 2nd hash
proof.push(_hashPair(hashes[1], hashes[2]));
// 3rd hash
proof.push(_hashPair(_hashPair(hashes[3], hashes[5]), hashes[6])); // maybe add keccak256 here
}
function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
}
function _efficientHash(bytes32 a, bytes32 b)
private
pure
returns (bytes32 value)
{
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment