modifiers.sol
Overview
The modifiers.sol file defines an abstract contract Modifiers that provides a collection of access control and validation modifiers for use in other contracts within the system. These modifiers enforce ownership, sender identity, minimum value requirements, and balance checks to restrict function execution according to the caller's credentials or message parameters. The file also contains numerous compile-time constant definitions used throughout the system, such as code type identifiers, deployment fees, maximum limits, and protocol parameters.
This contract inherits from Errors, indicating that it uses standardized error codes and messages from the imported errors.sol. It imports structs/structs.sol as well, although no direct references to structs are visible in this file.
Constants
The file declares multiple categories of constants:
TvmCell constants: Identifiers (uint8) for various contract or data types such as m_BlockKeeperEpochCode, m_BLSKeyCode, m_LicenseCode, etc.
Deployment fees: Fixed fees (uint64) expressed in
vmshellunits for deploying various wallet and manager contracts.Protocol numeric constants: Limits and parameters such as maximum license numbers, reputation coefficients, total supply, block rates, epoch identifiers, and unlock durations.
Enumerations: State identifiers like PRE_EPOCH_DEPLOYED, EPOCH_DEPLOYED, LICENSE_REST, LICENSE_PRE_EPOCH, etc.
Miscellaneous: Constants for controlling stakes, proxy lists, license types, and reward waits.
These constants serve as system-wide parameters ensuring standardized values and limits are referenced consistently, avoiding magic numbers in the codebase.
Contract: Modifiers
Inheritance
Inherits from
Errors, which presumably defines error codes and messages used in require statements.
Properties
versionModifiers: A string constant indicating the version of this modifiers contract ("1.0.0").
Modifiers
Modifiers in Solidity are used to change the behavior of functions by adding pre- and post-conditions. This contract defines several such modifiers, some of which are overloaded with optional parameters.
1. onlyOwnerPubkey(uint256 rootpubkey)
Purpose: Restricts function execution to the caller whose
msg.pubkey()matches the providedrootpubkey.Parameters:
rootpubkey: The public key of the owner authorized to execute the function.
Error: Throws
ERR_NOT_OWNERif the caller's public key does not match.Usage Example:
function sensitiveAction() external onlyOwnerPubkey(ownerKey) { // function logic }Notes: Enforces ownership via the public key embedded in the message.
2. onlyOwnerWallet(optional(address) owner_wallet, uint256 rootpubkey)
Purpose: Restricts execution to either the wallet owner or the owner public key.
Parameters:
owner_wallet: An optional address representing the wallet owner.rootpubkey: The owner's public key.
Logic:
If the caller's public key is different from
rootpubkey, the modifier requires thatowner_walletis present and that the sender's address is equal toowner_wallet.
Error: Throws
ERR_NOT_OWNERif neither condition is met.Usage Example:
function updateSettings() external onlyOwnerWallet(ownerAddress, ownerPubKey) { // update logic }
3. onlyOwnerWalletOpt(optional(address) owner_wallet, optional(uint256) rootpubkey)
Purpose: Similar to
onlyOwnerWallet, but both parameters are optional.Parameters:
owner_wallet: Optional wallet owner address.rootpubkey: Optional owner public key.
Logic:
If
rootpubkeyis present, require caller's public key to match.Else require
owner_walletto be present and sender to matchowner_wallet.
Error: Throws
ERR_NOT_OWNERif conditions fail.Usage: Useful when ownership credentials might be stored in either form.
4. onlyOwnerAddress(address addr)
Purpose: Ensures the caller's address matches the provided address.
Parameters:
addr: The authorized address.
Error: Throws
ERR_NOT_OWNERifmsg.senderis notaddr.Usage:
function restricted() external onlyOwnerAddress(authorizedAddr) { // logic }
5. minValue(uint128 val)
Purpose: Requires that the message value (
msg.value) sent with the transaction is at leastval.Parameters:
val: Minimum required value.
Error: Throws
ERR_LOW_VALUEifmsg.value < val.Usage:
function payFunction() external minValue(100) { // logic }
6. senderIs(address sender)
Purpose: Restricts execution to a specific sender address.
Parameters:
sender: The required sender address.
Error: Throws
ERR_INVALID_SENDERifmsg.sender != sender.Usage:
function onlyFrom(addressA) external senderIs(addressA) { // logic }
7. senderOfTwo(address sender, address sender1)
Purpose: Restricts execution to one of two possible sender addresses.
Parameters:
sender: First allowed sender address.sender1: Second allowed sender address.
Logic:
If
msg.sender != sender1, requiremsg.sender == sender.
Error: Throws
ERR_INVALID_SENDERif neither matches.Usage:
function onlyTwoSenders() external senderOfTwo(addr1, addr2) { // logic }
8. minBalance(uint128 val)
Purpose: Ensures that the contract's balance is greater than
val + 1 vmshell.Parameters:
val: Minimum required balance.
Error: Throws
ERR_LOW_BALANCEif balance condition fails.Usage:
function withdraw() external minBalance(1000) { // logic }
9. onlyOwner
Purpose: Restricts execution to the owner whose public key matches the current contract's public key (
tvm.pubkey()).Error: Throws
ERR_NOT_OWNERifmsg.pubkey() != tvm.pubkey().Usage:
function ownerOnlyAction() external onlyOwner { // logic }
10. accept()
Purpose: Calls
tvm.accept()to accept an external inbound message and pay for gas.Usage: Typically used at the start of functions that require accepting external calls.
Implementation Details
The contract uses
requirestatements with error codes inherited from theErrorscontract to enforce restrictions.It leverages Solidity's
optionaltype to allow flexible ownership validation.Constant values are declared with descriptive names and units where applicable (e.g.,
vmshell).Modifiers are designed for common permission and validation patterns encountered in blockchain smart contracts, especially those involving wallet ownership and transaction validation.
Interactions with Other Components
Errorscontract: Provides standardized error codes/messages used forrequirestatements.structs/structs.sol: Although imported, this file does not directly use any structs. It is likely used by contracts that inherit fromModifiers.The constants defined here are intended for use across the system, including contracts related to block keepers, block managers, license management, BLS keys, and staking mechanics.
Modifier functions are intended to be used in other contracts that inherit from
Modifiers, ensuring consistent permission checks and validations.
Diagram: Contract Structure and Modifier Relationships
classDiagram
class Modifiers {
<<abstract>>
+versionModifiers: string
+onlyOwnerPubkey()
+onlyOwnerWallet()
+onlyOwnerWalletOpt()
+onlyOwnerAddress()
+minValue()
+senderIs()
+senderOfTwo()
+minBalance()
+onlyOwner()
+accept()
}
Modifiers --|> Errors
Note: This class diagram shows the Modifiers abstract contract with its primary modifiers and the inheritance from the Errors contract. The modifiers are methods that apply preconditions on function execution.