Skip to content

Instantly share code, notes, and snippets.

@secretshardul
Created December 3, 2022 16:47
Show Gist options
  • Save secretshardul/00208b0fb3a06e25021846ce798c1938 to your computer and use it in GitHub Desktop.
Save secretshardul/00208b0fb3a06e25021846ce798c1938 to your computer and use it in GitHub Desktop.
Merkle log
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
library MerkleLog {
// The merkle root of log values from 0.100 to 9.999 in X64 format
bytes32 constant root = 0x998add033af31411c96b8272b055b95b55d92f349c84111d5fac9e2cfcad7589;
function log10 (
int64 characteristic,
uint16 mantissa,
uint128 logX64,
bytes32[] memory proof
) public pure returns (int128) {
bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(mantissa, logX64))));
require(MerkleProof.verify(proof, root, leaf), "Invalid proof");
// Add characteristicX64
return (int128(characteristic) << 64) + int128(logX64);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment