modifiers.sol

Overview

This file defines an abstract Solidity contract named Modifiers, which encapsulates several reusable function modifiers for access control and transaction validation in smart contracts. These modifiers enforce constraints such as ownership verification, minimum value transfers, and minimum contract balance requirements. By inheriting this contract, other contracts can easily apply these common checks to their functions, promoting code reuse and standardized error handling.

The contract extends from an imported Errors contract, thereby utilizing predefined error messages for consistent revert reasons. It also imports some data structures from structs.sol, specifically making use of an optional(uint256) type in one of the modifiers.


Contract: Modifiers

Declaration

abstract contract Modifiers is Errors

Constants

Name

Type

Value

Description

versionModifiers

string

"1.0.0"

Version identifier of this contract

MIN_BALANCE

uint64

100000 vmshell

Minimum balance constant, using vmshell denomination

vmshell is a denomination unit, likely specific to the environment or blockchain this Solidity variant targets.


Modifiers

Modifiers are used to add pre-condition checks to smart contract functions.

1. onlyOwnerPubkeyOptional

modifier onlyOwnerPubkeyOptional(optional(uint256) rootpubkey)

2. onlyOwnerPubkey

modifier onlyOwnerPubkey(uint256 rootpubkey)

3. onlyOwnerAddress

modifier onlyOwnerAddress(address addr)

4. minValue

modifier minValue(uint128 val)

5. senderIs

modifier senderIs(address sender)

6. minBalance

modifier minBalance(uint128 val)

Implementation Details


Interaction with Other Files

Contracts that inherit Modifiers will gain access to these modifiers and the error messages, facilitating consistent and reusable access control checks across the system.


Usage Example

contract MyContract is Modifiers {
    uint256 public ownerPubkey;

    constructor(uint256 _ownerPubkey) public {
        ownerPubkey = _ownerPubkey;
    }

    function sensitiveAction() external onlyOwnerPubkey(ownerPubkey) minValue(1_000_000) {
        // Function body only executes if caller is owner and sent at least 1_000_000 units of value
    }
}

Structure Diagram

classDiagram
class Modifiers {
<<abstract>>
+versionModifiers: string
+MIN_BALANCE: uint64
+onlyOwnerPubkeyOptional()
+onlyOwnerPubkey()
+onlyOwnerAddress()
+minValue()
+senderIs()
+minBalance()
}
Modifiers --|> Errors