State smart contract
The contract is aimed to be a part of a core protocol for self-sovereign identity system. Its purpose is to store the meta information about identities.
In particular, State contract stores the data of uint256 type for each identity, which is called "identity state" or state. The state represents a root of special cryptographic structure, which is out of scope of smart contract logic. But the only thing that smart contract should check is that the caller knows some private key, which public key is inside the structure. The overall check is hidden in the Zero-knowledge proof verifier smart contract attached to the State contract. The verifier contract was automatically generated by the Iden3 SnarkJS ZK library and was audited by the library creators.
Another data structure used by State is a Sparse Merkle Tree, which keeps the whole tree on chain as well as its full history. Each tree leaf consist of an index and a value. The indexes keep identity identifier and values keep states. The main purpose of the SMT is to provide inclusion and non-inclusion proofs of the states of identities into the SMT root. The tree processing logic is implemented by the Smt library contract linked to the state contract.
Take into account that the State contract and SMT library import Poseidon.sol contract, which is nothing more than a "placeholder" for auto generated EVM code. The code is responsible for the onchain Poseidon hash implementation. There is a helper method in the repo, which uses the circomlibjs Poseidon ABI and code generator.
Finally, the State contract is OwnableUpgradeable, which means that it works via the ERC1967 Proxy contract, that keeps all its state. Any further upgrades of the State contract should avoid any storage collisions.