Lean Incremental Merkle tree implementation in Solidity.
[!NOTE]
This library has been audited as part of the Semaphore V4 PSE audit: https://semaphore.pse.dev/Semaphore_4.0.0_Audit.pdf.
The LeanIMT is an optimized binary version of the IMT into binary-focused model, eliminating the need for zero values and allowing dynamic depth adjustment. Unlike the IMT, which uses a zero hash for incomplete nodes, the LeanIMT directly adopts the left child's value when a node lacks a right counterpart. The tree's depth dynamically adjusts to the count of leaves, enhancing efficiency by reducing the number of required hash calculations. To understand more about the LeanIMT, take a look at this visual explanation.
Install the @zk-kit/lean-imt.sol
package with npm:
npm i @zk-kit/lean-imt.sol --save
or yarn:
yarn add @zk-kit/lean-imt.sol
Please, see the test contracts for guidance on utilizing the libraries.