VerifiersLib.sol

Overview

VerifiersLib.sol is a Solidity library designed to provide utility functions for calculating deterministic addresses and composing state initialization data for various smart contracts within the system. The library supports contracts such as PopitGame, PopCoinWallet, PopCoinRoot, Multifactor, NameIndex (Indexer), and Boost. It leverages the TON Virtual Machine (TVM) specifics for creating TvmCell objects for contract code and state initialization, and for generating addresses by hashing these state initializations.

Additionally, the library includes utility functions for validating string names and computing efficient mathematical operations such as integer logarithm base 2 (log2).

This library plays a critical role in the contract deployment process by ensuring addresses are computed off-chain in a deterministic manner, allowing for pre-calculation of contract addresses before deployment.


Detailed API Documentation

Constants


Address Calculation and State Initialization Functions

For each supported contract type, the library provides a trio of functions:

  1. calculate<Contract>Address: Computes the deterministic contract address based on the encoded state initialization.

  2. composeStateInit: Prepares the state initialization cell, encoding contract code and variable initializers.

  3. buildCode: Generates the contract code cell with embedded version and relevant parameters used as a salt.


1. PopitGame Contract

Usage example:

address popitGameAddr = VerifiersLib.calculatePopitGameAddress(codeCell, rootAddr, ownerAddr);

2. PopCoinWallet Contract


3. PopCoinRoot Contract


4. Multifactor Contract


5. Indexer Contract (NameIndex)


6. Boost Contract


Utility Functions

log2(uint256 x) returns (uint64 n)

Computes the integer base-2 logarithm of x using bit-shifting.
Parameters:

Implementation details:
This function uses a sequence of right bit-shifts to efficiently find the position of the highest set bit.


checkName(string name) returns (bool)

Validates a string name to ensure it meets specific character and length constraints suitable for contract or user naming.

Parameters:

Returns:

Validation rules:


Implementation Details and Algorithms


Interaction with Other Contracts and Files


Visual Diagram: Structure of VerifiersLib.sol

flowchart TB
A[VerifiersLib]
subgraph AddressCalculationFunctions
direction TB
PGAddress[calculatePopitGameAddress]
PCWAddress[calculatePopCoinWalletAddress]
PCRAddress[calculatePopCoinRootAddress]
MFAddress[calculateMultifactorAddress]
IDXAddress[calculateIndexerAddress]
BSTAddress[calculateBoostAddress]
end
subgraph StateInitComposers
direction TB
PGState[composePopitGameStateInit]
PCWState[composePopCoinWalletStateInit]
PCRState[composePopCoinRootStateInit]
MFState[composeMultifactorStateInit]
IDXState[composeIndexerStateInit]
BSTState[composeBoostStateInit]
end
subgraph CodeBuilders
direction TB
PGCode[buildPopitGameCode]
PCWCode[buildPopCoinWalletCode]
PCRCode[buildPopCoinRootCode]
MFCode[buildMultifactorCode]
IDXCode[buildIndexerCode]
BSTCode[buildBoostCode]
end
subgraph UtilityFunctions
log2Func[log2]
checkNameFunc[checkName]
end
A --> AddressCalculationFunctions
A --> StateInitComposers
A --> CodeBuilders
A --> UtilityFunctions
AddressCalculationFunctions --> StateInitComposers
StateInitComposers --> CodeBuilders

Notes on Specific Contracts Referenced

For further details on these contracts' internal mechanics and their relationships, refer to their respective contract documentation.


Usage Example (PopitGame Address Calculation)

TvmCell popitGameCode = ... ; // precompiled code cell for PopitGame
address rootAddress = 0x123...;
address ownerAddress = 0xabc...;

address calculatedAddress = VerifiersLib.calculatePopitGameAddress(popitGameCode, rootAddress, ownerAddress);

This calculates the on-chain address where a PopitGame contract would be deployed with the specified parameters.


This library is fundamental for deterministic contract deployment and safe initialization practices within the system.