Solidity modules and utilities that go far beyond mediocre solidity.
- Implementation of the Contracts Registry pattern
- State-of-the-art cryptography primitives (ECDSA over 256-bit, 384-bit, and 512-bit curves, RSASSA-PSS)
- Advanced data structures (Vector, DynamicSet, PriorityQueue, AVLTree)
- ZK-friendly Cartesian Merkle Tree, Sparse Merkle Tree, and Incremental Merkle Tree implementations
- Versatile access control smart contracts (Merkle whitelists, RBAC)
- Enhanced and simplified Diamond pattern
- Flexible finance instruments (Staking, Vesting)
- Robust UniswapV2 and UniswapV3 oracles
- Lightweight SBT implementation
- Hyperoptimized uint512 BigInt library
- Utilities to ease work with memory, types, ERC20 decimals, arrays, sets, and ZK proofs
Built with courage and aspiration to perfection.
$ npm install @solarity/solidity-lib
The latest stable version is always in the master
branch.
Check out the project's documentation with broad explanations and usage examples of every module. Full natspec
guides are also available in the source code.
You will find the smart contracts in the /contracts
directory. Feel free to play around and check the project's structure.
Once the npm package is installed, one can use the library just like that:
pragma solidity ^0.8.21;
import {AMultiOwnable} from "@solarity/solidity-lib/access/AMultiOwnable.sol";
import {TypeCaster} from "@solarity/solidity-lib/libs/utils/TypeCaster.sol";
import {CartesianMerkleTree} from "@solarity/solidity-lib/libs/data-structures/CartesianMerkleTree.sol";
import {Groth16VerifierHelper} from "@solarity/solidity-lib/libs/zkp/Groth16VerifierHelper.sol";
contract Example is AMultiOwnable {
using CartesianMerkleTree for CartesianMerkleTree.UintCMT;
using Groth16VerifierHelper for address;
CartesianMerkleTree.UintCMT internal _uintTreaple;
address internal _treapleVerifier;
function __Example_init(address treapleVerifier_) initializer {
__AMultiOwnable_init();
_uintTreaple.initialize(40);
_treapleVerifier = treapleVerifier_;
}
function addToTree(uint256 key_) external onlyOwner {
_uintTreaple.add(key_);
}
function getMerkleProof(uint256 key_) external view returns (CartesianMerkleTree.Proof memory) {
return _uintTreaple.getProof(key_, 0);
}
function verifyZKProof(Groth16VerifierHelper.ProofPoints memory proof_) external view {
uint256[] memory pubSignals_ = TypeCaster.asSingletonArray(_uintTreaple.getRoot());
require(_treapleVerifier.verifyProof(proof_, pubSignals_), "ZKP verification failed");
}
}
This example showcases the basic usage of a CartesianMerkleTree
with ZK proofs. The contract's MultiOwner
may add elements to the tree to then privately prove their existence. Also, the Groth16VerifierHelper
library is used to simplify the interaction with the ZK verifier.
Tip
The library is designed to work cohesively with hardhat-zkit and circom-lib packages.
We are open to any mind-blowing ideas! Please take a look at our contribution guidelines to get involved.
The library is released under the MIT License.