|
|
|
|
|
|
|
pragma solidity >=0.7.0;
|
|
|
|
contract Ownable
|
|
{
|
|
|
|
|
|
address private _owner;
|
|
|
|
|
|
|
|
constructor()
|
|
{
|
|
_owner = msg.sender;
|
|
}
|
|
|
|
|
|
|
|
function owner() public view returns(address)
|
|
{
|
|
return _owner;
|
|
}
|
|
|
|
|
|
|
|
|
|
modifier onlyOwner()
|
|
{
|
|
require(isOwner(),
|
|
"Function accessible only by the owner !!");
|
|
_;
|
|
}
|
|
|
|
|
|
|
|
function isOwner() public view returns(bool)
|
|
{
|
|
return msg.sender == _owner;
|
|
}
|
|
}
|
|
|
|
contract Notarizer is Ownable
|
|
{
|
|
uint256 public prevBlock;
|
|
event RootHash(bytes32 rootHash, uint256 indexed prevBlock);
|
|
|
|
|
|
function storeNewRootHash(bytes32 _rootHash) onlyOwner external {
|
|
emit RootHash(_rootHash, prevBlock);
|
|
prevBlock = block.number;
|
|
}
|
|
|
|
function verify(bytes32 root, bytes32 leaf, bytes32[] memory proof) external pure returns (bool) {
|
|
bytes32 computedHash = leaf;
|
|
for (uint256 i = 0; i < proof.length; i++) {
|
|
bytes32 proofElement = proof[i];
|
|
if (computedHash < proofElement) {
|
|
|
|
computedHash = keccak256(
|
|
abi.encodePacked(computedHash, proofElement)
|
|
);
|
|
} else {
|
|
|
|
computedHash = keccak256(
|
|
abi.encodePacked(proofElement, computedHash)
|
|
);
|
|
}
|
|
}
|
|
|
|
return computedHash == root;
|
|
}
|
|
} |