Skip to content

Commit

Permalink
fix: new interface for node creation
Browse files Browse the repository at this point in the history
  • Loading branch information
QGarchery committed Mar 11, 2024
1 parent 38276f2 commit f5daa10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
19 changes: 6 additions & 13 deletions certora/helpers/MerkleTrees.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,14 @@ contract MerkleTrees {

mapping(address => MerkleTreeLib.Tree) trees;

function newLeaf(
address treeAddress,
address addr,
uint256 value
) public {
trees[treeAddress].newLeaf(addr, value);
function newLeaf(address treeAddress, MerkleTreeLib.Leaf memory leaf) public {
trees[treeAddress].newLeaf(leaf);
}

function newInternalNode(
address treeAddress,
address parent,
address left,
address right
) public {
trees[treeAddress].newInternalNode(parent, left, right);
function newInternalNode(address treeAddress, MerkleTreeLib.InternalNode memory internalNode)
public
{
trees[treeAddress].newInternalNode(internalNode);
}

function setRoot(address treeAddress, address addr) public {
Expand Down
14 changes: 7 additions & 7 deletions certora/specs/MerkleTrees.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-only

methods {
function newInternalNode(address, address, address, address) external envfree;
function newInternalNode(address, MerkleTreeLib.InternalNode) external envfree;

function getRoot(address) external returns address envfree;
function getValue(address, address) external returns uint256 envfree;
Expand All @@ -14,9 +14,9 @@ invariant zeroIsEmpty(address tree)

invariant nonEmptyHasValue(address tree, address addr)
! isEmpty(tree, addr) => getValue(tree, addr) != 0
{ preserved newInternalNode(address _, address parent, address left, address right) {
requireInvariant nonEmptyHasValue(tree, left);
requireInvariant nonEmptyHasValue(tree, right);
{ preserved newInternalNode(address _, MerkleTreeLib.InternalNode internalNode) {
requireInvariant nonEmptyHasValue(tree, internalNode.left);
requireInvariant nonEmptyHasValue(tree, internalNode.right);
}
}

Expand All @@ -28,9 +28,9 @@ invariant wellFormed(address tree, address addr)
{ preserved {
requireInvariant zeroIsEmpty(tree);
}
preserved newInternalNode(address _, address parent, address left, address right) {
preserved newInternalNode(address _, MerkleTreeLib.InternalNode internalNode) {
requireInvariant zeroIsEmpty(tree);
requireInvariant nonEmptyHasValue(tree, left);
requireInvariant nonEmptyHasValue(tree, right);
requireInvariant nonEmptyHasValue(tree, internalNode.left);
requireInvariant nonEmptyHasValue(tree, internalNode.right);
}
}

0 comments on commit f5daa10

Please sign in to comment.