Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
S1nus committed Aug 21, 2024
1 parent 4fa90fc commit 2f40a19
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 44 deletions.
29 changes: 9 additions & 20 deletions src/lib/commitment/test/Commitment.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ contract CommitmentTest is DSTest {
if (!compareStrings(out, vecs[i].shares)) {
console.log("expected: ", vecs[i].shares);
console.log("got: ", out);
revert();
}
}
}
Expand All @@ -79,31 +80,19 @@ contract CommitmentTest is DSTest {
TestVector[] memory vecs = abi.decode(vecsData, (TestVector[]));


//for (uint i = 0; i < vecs.length; i++) {
bytes29 nsString = bytes29(fromHex(vecs[0].namespace));
for (uint i = 0; i < vecs.length; i++) {
bytes29 nsString = bytes29(fromHex(vecs[i].namespace));
Namespace memory ns = toNamespace(nsString);
bytes memory data = fromHex(vecs[0].data);
bytes memory data = fromHex(vecs[i].data);
(bytes[] memory shares, bool err) = _bytesToSharesV0(data, ns);
bytes32 commitment = _createCommitment(shares, ns);
if (!compareStrings(_bytesToHexString(abi.encodePacked(commitment)), vecs[0].commitment)) {
console.log("Commitment mismatch for vector ", 0);
console.log("expected: ", vecs[0].commitment);
if (!compareStrings(_bytesToHexString(abi.encodePacked(commitment)), vecs[i].commitment)) {
console.log("Commitment mismatch for vector ", i);
console.log("expected: ", vecs[i].commitment);
console.log("got: ", _bytesToHexString(abi.encodePacked(commitment)));
return;
revert();
}
//}
console.log("All good :)");
}

/*bytes32 dummy = hex"000000000000000000000000000000000000005cfe5e6a0c8e6402fd5e010000";
NamespaceNode memory node = NamespaceNode(ns, ns, dummy);
NamespaceNode[] memory nodes = new NamespaceNode[](1);
nodes[0] = node;
NamespaceMerkleMultiproof memory nullproof = NamespaceMerkleMultiproof(0, 0, new NamespaceNode[](0));
NamespaceMerkleMultiproof memory populatedProof = NamespaceMerkleMultiproof(0, 1, nodes);
(NamespaceNode memory root,,,) = NamespaceMerkleTree._computeRoot(populatedProof, nodes, 0, 1, 0, 0);
console.log(_bytesToHexString(abi.encodePacked(node.digest)));
console.log(_bytesToHexString(abi.encodePacked(root.digest)));*/
//for (uint i = 0; i < vecs.length; i++) {
//}
}
}
26 changes: 3 additions & 23 deletions src/lib/tree/namespace/NamespaceMerkleTree.sol
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ library NamespaceMerkleTree {
NamespaceMerkleMultiproof memory proof,
Namespace memory namespace,
bytes[] memory data
) internal returns (bool) {
) internal pure returns (bool) {
// Hash all the leaves to get leaf nodes.
NamespaceNode[] memory nodes = new NamespaceNode[](data.length);
for (uint256 i = 0; i < data.length; ++i) {
Expand All @@ -168,7 +168,7 @@ library NamespaceMerkleTree {
NamespaceNode memory root,
NamespaceMerkleMultiproof memory proof,
NamespaceNode[] memory leafNodes
) internal returns (bool) {
) internal pure returns (bool) {
uint256 leafIndex = 0;
NamespaceNode[] memory leftSubtrees = new NamespaceNode[](proof.sideNodes.length);

Expand Down Expand Up @@ -212,7 +212,7 @@ library NamespaceMerkleTree {
uint256 end,
uint256 headProof,
uint256 headLeaves
) public returns (NamespaceNode memory, uint256, uint256, bool) {
) public pure returns (NamespaceNode memory, uint256, uint256, bool) {
// reached a leaf
if (end - begin == 1) {
// if current range overlaps with proof range, pop and return a leaf
Expand Down Expand Up @@ -250,26 +250,6 @@ library NamespaceMerkleTree {
return (hash, newHeadProof, newHeadLeaves, false);
}

/*function _computeTreeRoot(
NamespaceNode[] memory leafNodes,
uint256 start,
uint256 end
) public pure returns (NamespaceNode memory, bool err) {
if (end-start == 0) {
}
else if (end-start == 1) {
}
else {
uint256 k = _getSplitPoint(end - start);
// TODO: error handling
(NamespaceNode memory left,) = _computeTreeRoot(leafNodes, start, start + k);
(NamespaceNode memory right,) = _computeTreeRoot(leafNodes, start + k, end);
return (nodeDigest(left, right), false);
}
}*/

/// @notice Pop from the leaf nodes array slice if it's not empty.
/// @param nodes Entire leaf nodes array.
/// @param headLeaves Head of leaf nodes array slice.
Expand Down
3 changes: 2 additions & 1 deletion src/lib/verifier/DAVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ library DAVerifier {
/// @return an error code if the proof is invalid, ErrorCodes.NoError otherwise.
function verifySharesToDataRootTupleRoot(IDAOracle _bridge, SharesProof memory _sharesProof)
internal
view
returns (bool, ErrorCodes)
{
// checking that the data root was committed to by the Blobstream smart contract.
Expand Down Expand Up @@ -121,7 +122,7 @@ library DAVerifier {
NamespaceNode[] memory _rowRoots,
BinaryMerkleProof[] memory _rowProofs,
bytes32 _root
) internal returns (bool, ErrorCodes) {
) internal pure returns (bool, ErrorCodes) {
// verifying the row root to data root tuple root proof.
(bool success, ErrorCodes errorCode) = verifyMultiRowRootsToDataRootTupleRootProof(_rowRoots, _rowProofs, _root);
if (!success) {
Expand Down

0 comments on commit 2f40a19

Please sign in to comment.