Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions foundry.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"lib/forge-std": {
"rev": "e4aef94c1768803a16fe19f7ce8b65defd027cfd"
},
"lib/openzeppelin-contracts": {
"rev": "cb2aaaa04a292887c49839cd958b08a83979d746"
}
}
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ libs = ['lib']
fuzz_runs=5000
fuzz.max_test_rejects=500000
fs_permissions = [{ access = "read-write", path = "./"}]
ffi = true

# See more config options https://github.com/gakonst/foundry/tree/master/config
8 changes: 5 additions & 3 deletions src/common/MurkyBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pragma solidity ^0.8.4;

abstract contract MurkyBase {
/// @dev Thrown when trying to generate a root or proof for a single leaf array
error SingleLeaf();
/**
*
* CONSTRUCTOR *
Expand All @@ -21,7 +23,7 @@ abstract contract MurkyBase {
* PROOF VERIFICATION *
*
*/
function verifyProof(bytes32 root, bytes32[] memory proof, bytes32 valueToProve)
function verifyProof(bytes32 root, bytes32[] calldata proof, bytes32 valueToProve)
external
pure
virtual
Expand All @@ -44,15 +46,15 @@ abstract contract MurkyBase {
*
*/
function getRoot(bytes32[] memory data) public pure virtual returns (bytes32) {
require(data.length > 1, "won't generate root for single leaf");
if (data.length <= 1) revert SingleLeaf();
while (data.length > 1) {
data = hashLevel(data);
}
return data[0];
}

function getProof(bytes32[] memory data, uint256 node) public pure virtual returns (bytes32[] memory) {
require(data.length > 1, "won't generate proof for single leaf");
if (data.length <= 1) revert SingleLeaf();
// The size of the proof is equal to the ceiling of log2(numLeaves)
bytes32[] memory result = new bytes32[](log2ceilBitMagic(data.length));
uint256 pos = 0;
Expand Down
5 changes: 3 additions & 2 deletions src/test/Merkle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.4;

import "../Merkle.sol";
import "../common/MurkyBase.sol";
import "forge-std/Test.sol";
import "openzeppelin-contracts/contracts/utils/cryptography/MerkleProof.sol";

Expand Down Expand Up @@ -68,14 +69,14 @@ contract ContractTest is Test {
function testWontGetRootSingleLeaf() public {
bytes32[] memory data = new bytes32[](1);
data[0] = bytes32(0x0);
vm.expectRevert("won't generate root for single leaf");
vm.expectRevert(MurkyBase.SingleLeaf.selector);
m.getRoot(data);
}

function testWontGetProofSingleLeaf() public {
bytes32[] memory data = new bytes32[](1);
data[0] = bytes32(0x0);
vm.expectRevert("won't generate proof for single leaf");
vm.expectRevert(MurkyBase.SingleLeaf.selector);
m.getProof(data, 0x0);
}

Expand Down
5 changes: 3 additions & 2 deletions src/test/Xorkle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.4;

import "../Xorkle.sol";
import "../common/MurkyBase.sol";
import "forge-std/Test.sol";

contract ContractTest is Test {
Expand Down Expand Up @@ -52,14 +53,14 @@ contract ContractTest is Test {
function testWontGetRootSingleLeaf() public {
bytes32[] memory data = new bytes32[](1);
data[0] = bytes32(0x0);
vm.expectRevert("won't generate root for single leaf");
vm.expectRevert(MurkyBase.SingleLeaf.selector);
m.getRoot(data);
}

function testWontGetProofSingleLeaf() public {
bytes32[] memory data = new bytes32[](1);
data[0] = bytes32(0x0);
vm.expectRevert("won't generate proof for single leaf");
vm.expectRevert(MurkyBase.SingleLeaf.selector);
m.getProof(data, 0x0);
}

Expand Down