modifiers.sol
Overview
The modifiers.sol file defines an abstract Solidity contract named Modifiers that provides a set of reusable modifiers, constants, and access control mechanisms to be used by other contracts in the system. It extends from the Errors contract, presumably containing error codes and messages, to enforce common validation rules and preconditions across contract functions. This modular approach promotes code reuse and consistent security checks, especially around ownership verification and message sender validation.
The file also includes several constant declarations related to deployment fees, minimum balances, and currency identifiers, which standardize these values across contracts utilizing this module.
Contract: Modifiers
Description
The Modifiers contract is an abstract contract that acts as a foundational building block for other contracts. It centralizes common validation logic via Solidity modifiers, which enforce conditions such as ownership verification, minimum balance checks, and message sender validation before function execution proceeds.
Constants
Constant Name | Type | Value | Description |
|---|---|---|---|
| string |
| Version identifier for this modifiers contract. |
| uint8 |
| TvmCell constant likely used for configuration validation. |
| uint128 |
| Fee required for deploying configuration. |
| uint64 |
| Minimum balance threshold for the contract. |
| uint64 |
| Balance related to ECC (Elliptic Curve Cryptography). |
| uint64 |
| Minimum balance required to deploy. |
| uint32 |
| Identifier for primary currency. |
| uint32 |
| Identifier for shell currency. |
| uint128 |
| Maximum allowed size for keys, likely in a data structure. |
Modifiers
Modifiers in Solidity are used to change the behavior of functions by adding prerequisite checks or logic that runs before and/or after the function body. The Modifiers contract defines the following:
onlyOwnerPubkeyOptional
modifier onlyOwnerPubkeyOptional(optional(uint256) rootpubkey)
Parameters:
rootpubkey- An optional 256-bit unsigned integer representing the owner's public key.
Behavior:
Checks that therootpubkeyis provided (has a value) and that the message’s public key (msg.pubkey()) matches therootpubkey. If either condition fails, it triggers the errorERR_NOT_OWNERfromErrors.Usage Example:
function restrictedFunction(optional(uint256) rootpubkey) public onlyOwnerPubkeyOptional(rootpubkey) {
// function logic
}
onlyOwner
modifier onlyOwner()
Parameters: None.
Behavior:
Ensures that the message’s public key matches the contract’s own public key (tvm.pubkey()). This is typically used to restrict access to the contract deployer or owner.Usage Example:
function adminFunction() public onlyOwner {
// function logic
}
accept
modifier accept()
Parameters: None.
Behavior:
Callstvm.accept()to explicitly accept an external inbound message, allowing further execution and message processing.Usage Example:
function payableFunction() public accept {
// function logic
}
onlyOwnerPubkey
modifier onlyOwnerPubkey(uint256 rootpubkey)
Parameters:
rootpubkey- 256-bit unsigned integer representing the owner’s public key.
Behavior:
Requires that the message’s public key matches the providedrootpubkey.Usage Example:
function secureFunction(uint256 rootpubkey) public onlyOwnerPubkey(rootpubkey) {
// function logic
}
onlyOwnerAddress
modifier onlyOwnerAddress(address addr)
Parameters:
addr- The address that must match the message sender.
Behavior:
Ensures thatmsg.sendermatches the specified addressaddr.Usage Example:
function functionForSpecificSender(address addr) public onlyOwnerAddress(addr) {
// function logic
}
minValue
modifier minValue(uint128 val)
Parameters:
val- Minimum value (in tokens) required from the message caller.
Behavior:
Validates that the message value (msg.value) is at leastval. ThrowsERR_LOW_VALUEif not.Usage Example:
function payableFunction() public minValue(1 vmshell) {
// function logic
}
senderIs
modifier senderIs(address sender)
Parameters:
sender- Expected sender address.
Behavior:
Requires thatmsg.sendermatches the expectedsender. ThrowsERR_INVALID_SENDERif not.Usage Example:
function restrictedToSender(address sender) public senderIs(sender) {
// function logic
}
minBalance
modifier minBalance(uint128 val)
Parameters:
val- Minimum balance threshold.
Behavior:
Ensures the contract’s balance exceedsval + 1 vmshell. ThrowsERR_LOW_BALANCEif balance is insufficient.Usage Example:
function sensitiveOperation() public minBalance(1000 vmshell) {
// function logic
}
Implementation Details
The contract relies on Solidity’s modifier feature to enforce pre-execution checks on functions.
It uses
requirestatements with error codes imported from theErrorscontract, maintaining a consistent error handling strategy.Constants such as
FEE_DEPLOY_CONFIGandMIN_BALANCEare denominated invmshell, which is likely the project’s native token or unit of currency.The contract uses
optional(uint256)type in theonlyOwnerPubkeyOptionalmodifier, leveraging Solidity’s optional types to handle presence or absence of values cleanly.The
acceptmodifier explicitly callstvm.accept(), a function specific to the TON Virtual Machine (TVM) environment, indicating this code is designed for deployment on that platform.Ownership is primarily controlled via public key matching (
msg.pubkey()), a common pattern in TVM-based smart contracts.The structure of this contract suggests it is meant to be inherited by other contracts requiring standardized access control and validation logic.
Interactions with Other Files
Imports
Errorsfrom"./errors.sol", which likely contains the error constants such asERR_NOT_OWNER,ERR_LOW_VALUE,ERR_INVALID_SENDER, andERR_LOW_BALANCE. This modular separation allows centralized error management.Imports
"./structs/structs.sol", though no explicit usage of structs from this import is visible within this file. It is possible the imported structs are used in contracts inheriting fromModifiers.The constants and modifiers defined here are intended to be used by other contracts in the system, promoting uniform validation rules and reducing redundancy.
The use of TVM-specific functions and units (
vmshell,tvm.accept(),msg.pubkey()) indicates tight coupling with the TON blockchain environment.
Visual Diagram
classDiagram
class Modifiers {
+string versionModifiers
+uint8 m_ConfigCode
+uint128 FEE_DEPLOY_CONFIG
+uint64 MIN_BALANCE
+uint64 BALANCE_ECC
+uint64 MIN_BALANCE_DEPLOY
+uint32 CURRENCIES_ID
+uint32 CURRENCIES_ID_SHELL
+uint128 MAX_SIZE_OF_KEYS
+onlyOwnerPubkeyOptional(optional(uint256))
+onlyOwner()
+accept()
+onlyOwnerPubkey(uint256)
+onlyOwnerAddress(address)
+minValue(uint128)
+senderIs(address)
+minBalance(uint128)
}
Modifiers --|> Errors