Skip to content

Commit b60332e

Browse files
author
Docs Syncer
committed
CI: 7b34e8f
1 parent 3004910 commit b60332e

File tree

2 files changed

+183
-1
lines changed

2 files changed

+183
-1
lines changed

docs/reference/contracts/libs/data-structures/CartesianMerkleTree.md

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ library CartesianMerkleTree
1111
Cartesian Merkle Tree Module
1212

1313
A 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

1616
Gas 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
3939
CartesianMerkleTree.Proof memory proof = uintTreaple.getProof(100, 0);
4040
41+
uintTreaple.verifyProof(proof);
42+
4143
uintTreaple.getNodeByKey(100);
4244
4345
uintTreaple.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

docs/reference/contracts/libs/data-structures/IncrementalMerkleTree.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,38 @@ Return values:
210210
| :--- | :------ | :-------------------------------- |
211211
| [0] | bytes32 | The root hash of the Merkle tree. |
212212

213+
### verifyProof
214+
215+
```solidity
216+
function verifyProof(
217+
IncrementalMerkleTree.UintIMT storage tree,
218+
bytes32[] memory siblings_,
219+
uint256 directionBits_,
220+
bytes32 leaf_
221+
) internal view returns (bool)
222+
```
223+
224+
The function to verify a proof of a leaf's existence in the uint256 tree.
225+
Complexity is O(log(n)), where n is the number of elements in the tree.
226+
227+
228+
229+
Parameters:
230+
231+
| Name | Type | Description |
232+
| :------------- | :----------------------------------- | :------------------------------- |
233+
| tree | struct IncrementalMerkleTree.UintIMT | self. |
234+
| siblings_ | bytes32[] | The siblings of the leaf. |
235+
| directionBits_ | uint256 | The direction bits of the leaf. |
236+
| leaf_ | bytes32 | The leaf. |
237+
238+
239+
Return values:
240+
241+
| Name | Type | Description |
242+
| :--- | :--- | :------------------------------------------- |
243+
| [0] | bool | True if the proof is valid, false otherwise. |
244+
213245
### height
214246

215247
```solidity
@@ -347,6 +379,38 @@ function root(
347379
The function to return the root hash of the bytes32 tree.
348380
Complexity is O(log(n) + h), where n is the number of elements in the tree and
349381
h is the height of the tree.
382+
### verifyProof
383+
384+
```solidity
385+
function verifyProof(
386+
IncrementalMerkleTree.Bytes32IMT storage tree,
387+
bytes32[] memory siblings_,
388+
uint256 directionBits_,
389+
bytes32 leaf_
390+
) internal view returns (bool)
391+
```
392+
393+
The function to verify a proof of a leaf's existence in the bytes32 tree.
394+
Complexity is O(log(n)), where n is the number of elements in the tree.
395+
396+
397+
398+
Parameters:
399+
400+
| Name | Type | Description |
401+
| :------------- | :-------------------------------------- | :------------------------------- |
402+
| tree | struct IncrementalMerkleTree.Bytes32IMT | self. |
403+
| siblings_ | bytes32[] | The siblings of the leaf. |
404+
| directionBits_ | uint256 | The direction bits of the leaf. |
405+
| leaf_ | bytes32 | The leaf. |
406+
407+
408+
Return values:
409+
410+
| Name | Type | Description |
411+
| :--- | :--- | :------------------------------------------- |
412+
| [0] | bool | True if the proof is valid, false otherwise. |
413+
350414
### height
351415

352416
```solidity
@@ -454,6 +518,38 @@ function root(
454518
The function to return the root hash of the address tree.
455519
Complexity is O(log(n) + h), where n is the number of elements in the tree and
456520
h is the height of the tree.
521+
### verifyProof
522+
523+
```solidity
524+
function verifyProof(
525+
IncrementalMerkleTree.AddressIMT storage tree,
526+
bytes32[] memory siblings_,
527+
uint256 directionBits_,
528+
bytes32 leaf_
529+
) internal view returns (bool)
530+
```
531+
532+
The function to verify a proof of a leaf's existence in the address tree.
533+
Complexity is O(log(n)), where n is the number of elements in the tree.
534+
535+
536+
537+
Parameters:
538+
539+
| Name | Type | Description |
540+
| :------------- | :-------------------------------------- | :------------------------------- |
541+
| tree | struct IncrementalMerkleTree.AddressIMT | self. |
542+
| siblings_ | bytes32[] | The siblings of the leaf. |
543+
| directionBits_ | uint256 | The direction bits of the leaf. |
544+
| leaf_ | bytes32 | The leaf. |
545+
546+
547+
Return values:
548+
549+
| Name | Type | Description |
550+
| :--- | :--- | :------------------------------------------- |
551+
| [0] | bool | True if the proof is valid, false otherwise. |
552+
457553
### height
458554

459555
```solidity

0 commit comments

Comments
 (0)