-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from morpho-org/certora/hash-key
[Certora] Hash key
- Loading branch information
Showing
10 changed files
with
136 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ jobs: | |
|
||
matrix: | ||
conf: | ||
- MerkleTrees | ||
- MerkleTree | ||
- UniversalRewardsDistributor | ||
|
||
steps: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
certora/confs/MerkleTrees.conf → certora/confs/MerkleTree.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
{ | ||
"files": [ | ||
"certora/helpers/MerkleTrees.sol" | ||
"certora/helpers/MerkleTree.sol" | ||
], | ||
"verify": "MerkleTrees:certora/specs/MerkleTrees.spec", | ||
"verify": "MerkleTree:certora/specs/MerkleTree.spec", | ||
"optimistic_loop": true, | ||
"loop_iter": "2", | ||
"rule_sanity": "basic", | ||
"server": "production", | ||
"msg": "Merkle Trees", | ||
"msg": "Merkle Tree", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// SPDX-License-Identifier: GNU AGPLv3 | ||
pragma solidity ^0.8.0; | ||
|
||
import "./MerkleTreeLib.sol"; | ||
|
||
contract MerkleTree { | ||
using MerkleTreeLib for MerkleTreeLib.Node; | ||
using MerkleTreeLib for MerkleTreeLib.Tree; | ||
|
||
MerkleTreeLib.Tree tree; | ||
|
||
function newLeaf(address addr, address reward, uint256 value) public { | ||
tree.newLeaf(addr, reward, value); | ||
} | ||
|
||
function newInternalNode(bytes32 parent, bytes32 left, bytes32 right) public { | ||
tree.newInternalNode(parent, left, right); | ||
} | ||
|
||
function setRoot(bytes32 id) public { | ||
tree.setRoot(id); | ||
} | ||
|
||
function getRoot() public view returns (bytes32) { | ||
return tree.getRoot(); | ||
} | ||
|
||
function getLeft(bytes32 id) public view returns (bytes32) { | ||
return tree.getLeft(id); | ||
} | ||
|
||
function getRight(bytes32 id) public view returns (bytes32) { | ||
return tree.getRight(id); | ||
} | ||
|
||
function getValue(address addr, address reward) public view returns (uint256) { | ||
return tree.getValue(addr, reward); | ||
} | ||
|
||
function getHash(bytes32 id) public view returns (bytes32) { | ||
return tree.getHash(id); | ||
} | ||
|
||
function isEmpty(bytes32 id) public view returns (bool) { | ||
return tree.nodes[id].isEmpty(); | ||
} | ||
|
||
function isWellFormed(bytes32 id) public view returns (bool) { | ||
return tree.isWellFormed(id); | ||
} | ||
|
||
// Only go up to a given depth, to avoid CVL recursion protection. | ||
function wellFormedUpTo(bytes32 id, uint256 depth) public view { | ||
if (depth == 0) return; | ||
|
||
require(tree.isWellFormed(id)); | ||
|
||
bytes32 left = tree.getLeft(id); | ||
bytes32 right = tree.getRight(id); | ||
if (left != 0) { | ||
wellFormedUpTo(left, depth - 1); | ||
wellFormedUpTo(right, depth - 1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
methods { | ||
function getRoot() external returns(bytes32) envfree; | ||
function getValue(address, address) external returns(uint256) envfree; | ||
function isEmpty(bytes32) external returns(bool) envfree; | ||
function isWellFormed(bytes32) external returns(bool) envfree; | ||
} | ||
|
||
invariant zeroIsEmpty() | ||
isEmpty(to_bytes32(0)); | ||
|
||
invariant rootIsZeroOrNotEmpty() | ||
getRoot() == to_bytes32(0) || !isEmpty(getRoot()); | ||
|
||
invariant wellFormed(bytes32 id) | ||
isWellFormed(id) | ||
{ preserved { | ||
requireInvariant zeroIsEmpty(); | ||
requireInvariant wellFormed(id); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.