@@ -11,7 +11,7 @@ library CartesianMerkleTree
1111Cartesian Merkle Tree Module
1212
1313A magnificent ZK-friendly data structure based on a Binary Search Tree + Heap + Merkle Tree. Short names: CMT, Treaple.
14- Possesses deterministic and idemponent properties. Can be used as a substitute for a Sparse Merkle Tree (SMT).
14+ Possesses deterministic and idempotent properties. Can be used as a substitute for a Sparse Merkle Tree (SMT).
1515
1616Gas usage for adding and removing 1,000 elements to a CMT with the keccak256 and poseidon hash functions is detailed below:
1717
@@ -38,6 +38,8 @@ uintTreaple.getRoot();
3838
3939CartesianMerkleTree.Proof memory proof = uintTreaple.getProof(100, 0);
4040
41+ uintTreaple.verifyProof(proof);
42+
4143uintTreaple.getNodeByKey(100);
4244
4345uintTreaple.remove(100);
@@ -369,6 +371,34 @@ Return values:
369371| :--- | :------------------------------- | :---------------- |
370372| [ 0] | struct CartesianMerkleTree.Proof | CMT proof struct. |
371373
374+ ### verifyProof
375+
376+ ``` solidity
377+ function verifyProof(
378+ CartesianMerkleTree.UintCMT storage treaple,
379+ CartesianMerkleTree.Proof memory proof_
380+ ) internal view returns (bool)
381+ ```
382+
383+ The function to verify the proof for inclusion or exclusion of a node in the CMT.
384+ Complexity is O(log(n)), where n is the max depth of the treaple.
385+
386+
387+
388+ Parameters:
389+
390+ | Name | Type | Description |
391+ | :------ | :--------------------------------- | :--------------------- |
392+ | treaple | struct CartesianMerkleTree.UintCMT | self. |
393+ | proof_ | struct CartesianMerkleTree.Proof | The CMT proof struct. |
394+
395+
396+ Return values:
397+
398+ | Name | Type | Description |
399+ | :--- | :--- | :------------------------------------------- |
400+ | [ 0] | bool | True if the proof is valid, false otherwise. |
401+
372402### getRoot
373403
374404``` solidity
@@ -669,6 +699,34 @@ Return values:
669699| :--- | :------------------------------- | :---------------- |
670700| [ 0] | struct CartesianMerkleTree.Proof | CMT proof struct. |
671701
702+ ### verifyProof
703+
704+ ``` solidity
705+ function verifyProof(
706+ CartesianMerkleTree.Bytes32CMT storage treaple,
707+ CartesianMerkleTree.Proof memory proof_
708+ ) internal view returns (bool)
709+ ```
710+
711+ The function to verify the proof for inclusion or exclusion of a node in the CMT.
712+ Complexity is O(log(n)), where n is the max depth of the treaple.
713+
714+
715+
716+ Parameters:
717+
718+ | Name | Type | Description |
719+ | :------ | :------------------------------------ | :--------------------- |
720+ | treaple | struct CartesianMerkleTree.Bytes32CMT | self. |
721+ | proof_ | struct CartesianMerkleTree.Proof | The CMT proof struct. |
722+
723+
724+ Return values:
725+
726+ | Name | Type | Description |
727+ | :--- | :--- | :------------------------------------------- |
728+ | [ 0] | bool | True if the proof is valid, false otherwise. |
729+
672730### getRoot
673731
674732``` solidity
@@ -969,6 +1027,34 @@ Return values:
9691027| :--- | :------------------------------- | :---------------- |
9701028| [ 0] | struct CartesianMerkleTree.Proof | CMT proof struct. |
9711029
1030+ ### verifyProof
1031+
1032+ ``` solidity
1033+ function verifyProof(
1034+ CartesianMerkleTree.AddressCMT storage treaple,
1035+ CartesianMerkleTree.Proof memory proof_
1036+ ) internal view returns (bool)
1037+ ```
1038+
1039+ The function to verify the proof for inclusion or exclusion of a node in the CMT.
1040+ Complexity is O(log(n)), where n is the max depth of the treaple.
1041+
1042+
1043+
1044+ Parameters:
1045+
1046+ | Name | Type | Description |
1047+ | :------ | :------------------------------------ | :--------------------- |
1048+ | treaple | struct CartesianMerkleTree.AddressCMT | self. |
1049+ | proof_ | struct CartesianMerkleTree.Proof | The CMT proof struct. |
1050+
1051+
1052+ Return values:
1053+
1054+ | Name | Type | Description |
1055+ | :--- | :--- | :------------------------------------------- |
1056+ | [ 0] | bool | True if the proof is valid, false otherwise. |
1057+
9721058### getRoot
9731059
9741060``` solidity
0 commit comments