modifiers.sol
Overview
This Solidity source file defines an abstract contract Modifiers which centralizes a collection of constants and reusable function modifiers to enforce common access controls, validations, and gas acceptance patterns in the GOSH smart contract ecosystem. The contract inherits from an Errors contract to utilize standardized error codes for revert messages.
The purpose of Modifiers is to provide a consistent and maintainable way to implement permission checks (such as ownership and sender verification), resource constraints (minimum balance or message value), and transaction acceptance across various contracts within the system. This helps reduce code duplication and enhances security by standardizing validation logic.
Constants
The file declares numerous constants used throughout the system, categorized as follows:
TvmCell Identifiers: Numeric constants identifying different smart contract components, such as m_PopitGame, m_PopCoinWallet, m_PopCoinRoot, etc.
Deployment Fees: Fixed deployment fees for various contract types, expressed in
vmshellunits (e.g., FEE_DEPLOY_POPIT_GAME_WALLET, FEE_DEPLOY_POP_COIN_WALLET).Balance Thresholds: Constants defining minimum balance requirements for contracts, such as
ROOT_BALANCEandCONTRACT_BALANCE.Currency and Reward Parameters: Identifiers and timing constants related to currencies and reward periods (e.g.,
CURRENCIES_ID,RewardPeriod).Size and Limit Constants: Parameters controlling limits on queued requests, lifetimes of keys, maximum numbers of factors or cards, and maximum lengths.
Cryptographic and Bitwise Constants: Values such as
BASE_PARTandSHIFTused in cryptographic or bit-shifting operations.WASM Module Information: Constants specifying the WASM module and function for TLS checking.
These constants are intended for use in various parts of the GOSH ecosystem and provide standardized values that ensure consistency and prevent magic numbers scattered across the codebase.
Contract: Modifiers
The Modifiers contract is an abstract contract extending from Errors, indicating it cannot be instantiated directly but serves as a base for other contracts.
Properties
versionModifiers: A string indicating the version of this modifiers contract ("1.0.0").
Modifiers
Modifiers are reusable pieces of code that can be attached to functions to enforce certain preconditions or behaviors.
onlyOwnerPubkey(uint256 rootpubkey)
Purpose: Ensures that the message sender's public key matches the specified
rootpubkey.Parameters:
rootpubkey(uint256): The expected owner's public key.
Behavior: Reverts with
ERR_NOT_OWNERif the sender's public key does not match.Usage Example:
function sensitiveFunction() external onlyOwnerPubkey(ownerPubkey) { // function logic }
onlyOwner
Purpose: Restricts function access to the contract owner, identified by the contract's public key.
Behavior: Checks if
msg.pubkey()equalstvm.pubkey(). Reverts withERR_NOT_OWNERif not.Usage Example:
function adminFunction() external onlyOwner { // admin-only logic }
accept
Purpose: Accepts inbound external messages, allowing the contract to process them.
Behavior: Calls
tvm.accept()before function execution.Usage Example:
function receiveFunds() external accept { // logic that requires message acceptance }
onlyOwnerWallet(optional(address) owner_wallet, uint256 rootpubkey)
Purpose: Restricts function access to either the owner's public key or the specified owner wallet address.
Parameters:
owner_wallet(optional(address)): Optional address of the owner's wallet.rootpubkey(uint256): Owner's public key.
Behavior:
If the sender's public key is not equal to
rootpubkey, it requires:owner_walletto be present.msg.senderequalsowner_wallet.
Reverts with
ERR_NOT_OWNERon failure.
Usage Example:
function updateSettings(optional(address) ownerWallet) external onlyOwnerWallet(ownerWallet, rootPubkey) { // update logic }
onlyOwnerWalletOpt(optional(address) owner_wallet, optional(uint256) rootpubkey)
Purpose: Similar to
onlyOwnerWalletbut bothowner_walletandrootpubkeyare optional.Parameters:
owner_wallet(optional(address)): Optional owner wallet address.rootpubkey(optional(uint256)): Optional owner public key.
Behavior:
If
rootpubkeyis provided, requiresmsg.pubkey()equalsrootpubkey.Otherwise, requires
owner_walletto be present andmsg.senderequalsowner_wallet.Reverts with
ERR_NOT_OWNERif conditions are not met.
Usage Example:
function privilegedAction(optional(address) ownerWallet, optional(uint256) rootPubkey) external onlyOwnerWalletOpt(ownerWallet, rootPubkey) { // privileged logic }
onlyOwnerAddress(address addr)
Purpose: Permits access only if the sender's address matches the specified
addr.Parameters:
addr(address): The authorized sender address.
Behavior: Reverts with
ERR_NOT_OWNERifmsg.senderis notaddr.Usage Example:
function restrictedCall() external onlyOwnerAddress(authorizedAddress) { // restricted logic }
minValue(uint128 val)
Purpose: Ensures the inbound message value is at least
val.Parameters:
val(uint128): Minimum allowed value.
Behavior: Reverts with
ERR_LOW_VALUEifmsg.value<val.Usage Example:
function payableFunction() external minValue(1000000) { // logic requiring minimum value }
senderIs(address sender)
Purpose: Restricts function calls to a specific sender address.
Parameters:
sender(address): Expected sender address.
Behavior: Reverts with
ERR_INVALID_SENDERifmsg.senderis notsender.Usage Example:
function onlyFromTrusted() external senderIs(trustedAddress) { // logic }
minBalance(uint128 val)
Purpose: Requires the contract balance to be above a certain threshold.
Parameters:
val(uint128): Minimum required balance.
Behavior: Reverts with
ERR_LOW_BALANCEifaddress(this).balance≤val + 1 vmshell.Usage Example:
function criticalOperation() external minBalance(5000000) { // operation requiring sufficient contract balance }
Important Implementation Details
The contract uses
requirestatements with custom error codes defined in the inheritedErrorscontract to enforce access control and validation.The contract utilizes
optionaltypes for owner wallet addresses and public keys, allowing flexible authorization checks depending on the presence or absence of these parameters.The
acceptmodifier callstvm.accept(), which is necessary in TON-based smart contracts to accept inbound messages and allow processing.Constants related to deployment fees (
FEE_DEPLOY_*) and balance thresholds (ROOT_BALANCE,CONTRACT_BALANCE) suggest this contract plays a role in managing resource constraints for deploying and operating various components in the GOSH ecosystem.The public key and address checks help secure function calls, preventing unauthorized interactions.
Interactions with Other Parts of the System
This file imports
"./structs/structs.sol"and"./errors.sol". TheErrorscontract provides error codes used in require statements, ensuring standardized revert messages across contracts.Contracts that inherit from
Modifiersgain access to these modifiers and constants, enabling them to enforce consistent authorization and validation without redefining these rules.The
Modifierscontract is likely used across multiple smart contracts, such as wallets (PopCoinWallet), token roots (PopCoinRoot), games (PopitGame), multifactor authentication modules (MvMultifactor), indexers, and boost components, as suggested by the constants naming.The constants related to WASM modules and TLS checking indicate possible integration with external verification or cryptographic modules.
This contract helps coordinate security and operational constraints within the broader system by providing foundational building blocks for other contracts.
Mermaid Diagram: Contract Structure
classDiagram
class Modifiers {
+string versionModifiers
+modifier onlyOwnerPubkey()
+modifier onlyOwner()
+modifier accept()
+modifier onlyOwnerWallet()
+modifier onlyOwnerWalletOpt()
+modifier onlyOwnerAddress()
+modifier minValue()
+modifier senderIs()
+modifier minBalance()
}
Modifiers --|> Errors
The diagram illustrates the Modifiers contract inheriting from Errors and lists the available modifiers and the versionModifiers property. This structure reflects how Modifiers serves as a base for access control and validation in the system.