Verified contractExactUNLICENSED
EIP712LegacyVerifier
Address0xbe21f4679ec100ef2edddfcb526080d4d1809dc1
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.35
- Same code
1 more contract
Details
- Compiler
- solc 0.8.35+commit.47b9dedd
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- UNLICENSED
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,351,648
- Creation transaction
- 0x5808ead752…a341de48a3
7 files
- contracts/term/VerifierTerm.solmain17.12 KB
- @openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol4.05 KB
- @openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol144 B
- @openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol1.22 KB
- @openzeppelin/contracts/proxy/utils/Initializable.sol9.28 KB
- @openzeppelin/contracts/utils/ReentrancyGuard.sol4.77 KB
- @openzeppelin/contracts/utils/StorageSlot.sol4.18 KB
contracts/term/VerifierTerm.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
contract EIP712LegacyVerifier is Initializable, ReentrancyGuard, OwnableUpgradeable {
struct Legacy {
address legacyAddress;
uint256 timestamp;
bytes signature;
}
mapping(address => Legacy[]) public legacySigned;
address public transferLegacyEOA;
address public transferLegacy;
address public multisigLegacy;
mapping(bytes => uint256) signatureUsed;
// ── Versioned terms acceptance (deferred item `legacy-tos-version`) ──
// APPENDED storage (upgrade-safe): binds each consent record to the exact
// ToS document in force at signing, not just who/when. The owner publishes
// the active terms as a short human-readable version tag (goes inside the
// signed message) plus the keccak256 hash of the full ToS document text
// (stays on-chain, linking tag -> exact document).
string public activeTermsVersion;
bytes32 public activeTermsHash;
/// @dev ToS document hash snapshotted per consent signature (the signature
/// bytes are unique — enforced by `signatureUsed`). Zero for records made
/// before terms versioning was activated or via the legacy message format.
mapping(bytes => bytes32) public signatureTermsHash;
/// @dev Version tag by document hash — lets views reconstruct the exact
/// historical message a record was signed over even after the active
/// terms move on. One-time write per published terms version.
mapping(bytes32 => string) public termsVersionOf;
// ── Tx-based consent registry (deferred item `timelock-consent-parity`) ──
// APPENDED storage (upgrade-safe). Second consent modality alongside the
// signed-message path above: for actions where the consenting party IS the
// transaction signer (EOA creates with the in-form checkbox, gift-timelock
// creates), the transaction signature itself is the cryptographic
// attribution — the authorized router records "msg.sender accepted the
// active terms (hash H, version V) at time T" with no separate wallet
// popup. The signed-message path remains for flows where msg.sender is not
// the consenting party (Safe-based legacies, future sponsored creates).
/// @dev Contracts allowed to record tx-based consent (the routers). The
/// legacy `onlyRouter` trio is not reused because this registry must cover
/// the timelock router too, and be extensible without another upgrade.
mapping(address => bool) public consentRecorders;
struct Consent {
bytes32 termsHash;
uint64 timestamp;
address recorder;
uint256 refId;
}
/// @dev Per-user append-only consent log (tx-based modality only; the
/// signed-message modality keeps using `legacySigned`).
mapping(address => Consent[]) public userConsents;
// ── Self-recorded consent (2026-11 train, closes `shield-vault-consent`) ──
// APPENDED storage (upgrade-safe). Third modality, for products that cannot
// call this verifier themselves: ShieldVault is immutable and must never
// depend on an upgradeable contract. The user's own transaction records
// "msg.sender accepted terms H for reference (contract, id)" next to the
// action it covers (a vault `open`), so attribution is the user's signature
// and nothing calls into or out of the referenced contract.
struct SelfConsent {
bytes32 termsHash;
uint64 timestamp;
address refContract;
uint256 refId;
}
/// @dev Per-user append-only log of self-recorded consents.
mapping(address => SelfConsent[]) public userSelfConsents;
event LegacySigned(address indexed user, uint256 legacyId, uint256 timestamp);
/// @dev Emitted alongside LegacySigned when the consent bound a specific
/// terms version. Kept as a separate additive event so existing indexers
/// are untouched.
event LegacySignedVersioned(address indexed user, uint256 legacyId, uint256 timestamp, string termsVersion, bytes32 termsHash);
event ActiveTermsUpdated(string termsVersion, bytes32 termsHash);
/// @dev Tx-based consent record. `refId` is recorder-scoped context (the
/// legacy id for the EOA router, the timelock id for the timelock router).
event ConsentRecorded(
address indexed user,
bytes32 indexed termsHash,
address indexed recorder,
uint256 refId,
string termsVersion,
uint256 timestamp
);
event ConsentRecorderSet(address indexed recorder, bool allowed);
/// @dev Self-recorded consent. `refContract` / `refId` name what it covers
/// (a ShieldVault and its position id); they are the user's own claim,
/// checked off-chain against that contract's events.
event SelfConsentRecorded(
address indexed user,
bytes32 indexed termsHash,
address indexed refContract,
uint256 refId,
string termsVersion,
uint256 timestamp
);
error InvalidSignature();
error SignatureUsed();
error TimestampOutOfRange();
error InvalidV();
error HexLengthInsufficient();
error ZeroAddressNotAllowed();
error UnauthorizedCaller();
error AlreadyInit();
error InvalidTerms();
error NoActiveTerms();
string private constant MESSAGE_PREFIX = "By proceeding with creating a new contract, I agree to 10102's Terms of Service";
uint256 private constant MAX_PAST_OFFSET = 30 minutes;
uint256 private constant MAX_FUTURE_OFFSET = 30 minutes;
constructor () {
_disableInitializers();
}
function initialize(address initialOwner) public initializer {
__Ownable_init(initialOwner);
}
modifier onlyRouter() {
if (msg.sender != transferLegacy && msg.sender != transferLegacyEOA && msg.sender != multisigLegacy) revert UnauthorizedCaller();
_;
}
function setRouterAddresses(address _transferLegacyEOA, address _transferLegacy, address _multisigLegacy) external onlyOwner {
//if (transferLegacyEOA != address(0)) revert AlreadyInit();
// _transferLegacy is allowed to be address(0) since the Safe-source
// Transfer flow was sunset (v2026.05.18). The storage slot is
// preserved for upgradeability — see comment in LegacyDeployer.sol.
if (_transferLegacyEOA == address(0) || _multisigLegacy == address(0)) {
revert ZeroAddressNotAllowed();
}
transferLegacyEOA = _transferLegacyEOA;
transferLegacy = _transferLegacy;
multisigLegacy = _multisigLegacy;
}
/// @notice Publish the terms version users must accept from now on.
/// @param termsVersion_ Short human-readable tag embedded in the signed
/// message (e.g. "v2026-07"). Empty string (with zero hash) disables
/// versioning and falls back to the legacy message format.
/// @param termsHash_ keccak256 of the full ToS document text in force —
/// the on-chain link from the tag to the exact terms.
function setActiveTerms(string calldata termsVersion_, bytes32 termsHash_) external onlyOwner {
// Both set or both empty — a tag without a document hash (or vice
// versa) would break the tag -> document bind this feature exists for.
if ((bytes(termsVersion_).length == 0) != (termsHash_ == bytes32(0))) revert InvalidTerms();
activeTermsVersion = termsVersion_;
activeTermsHash = termsHash_;
if (termsHash_ != bytes32(0)) {
termsVersionOf[termsHash_] = termsVersion_;
}
emit ActiveTermsUpdated(termsVersion_, termsHash_);
}
/// @notice Authorize (or revoke) a contract to record tx-based consent.
function setConsentRecorder(address recorder_, bool allowed_) external onlyOwner {
if (recorder_ == address(0)) revert ZeroAddressNotAllowed();
consentRecorders[recorder_] = allowed_;
emit ConsentRecorderSet(recorder_, allowed_);
}
/**
* @notice Record tx-based consent for `user_`, binding it to the active
* terms. Only callable by authorized recorder contracts (the routers),
* which pass their tx signer as `user_` — the transaction signature is the
* cryptographic attribution, so no separate message signature is needed.
* Requires published active terms: consent must always bind to an exact
* terms document, otherwise the record would attest to nothing.
*/
function recordConsent(address user_, uint256 refId_) external {
if (!consentRecorders[msg.sender]) revert UnauthorizedCaller();
if (activeTermsHash == bytes32(0)) revert NoActiveTerms();
userConsents[user_].push(
Consent({termsHash: activeTermsHash, timestamp: uint64(block.timestamp), recorder: msg.sender, refId: refId_})
);
emit ConsentRecorded(user_, activeTermsHash, msg.sender, refId_, activeTermsVersion, block.timestamp);
}
function getUserConsentCount(address user) external view returns (uint256) {
return userConsents[user].length;
}
/**
* @notice Record that the caller accepts the active terms for `refContract_`
* / `refId_` (e.g. a ShieldVault position). `termsHash_` is the document the
* app showed; it must be the active one, so a terms change between display
* and transaction reverts instead of recording consent to unseen terms.
*/
function recordSelfConsent(bytes32 termsHash_, address refContract_, uint256 refId_) external {
if (activeTermsHash == bytes32(0)) revert NoActiveTerms();
if (termsHash_ != activeTermsHash) revert InvalidTerms();
if (refContract_ == address(0)) revert ZeroAddressNotAllowed();
userSelfConsents[msg.sender].push(
SelfConsent({termsHash: termsHash_, timestamp: uint64(block.timestamp), refContract: refContract_, refId: refId_})
);
emit SelfConsentRecorded(msg.sender, termsHash_, refContract_, refId_, activeTermsVersion, block.timestamp);
}
function getUserSelfConsentCount(address user) external view returns (uint256) {
return userSelfConsents[user].length;
}
/// @notice A self-recorded consent with the version tag its terms hash was published under.
function getUserSelfConsent(
address user,
uint256 index
) external view returns (bytes32 termsHash, string memory termsVersion, uint256 timestamp, address refContract, uint256 refId) {
SelfConsent memory c = userSelfConsents[user][index];
return (c.termsHash, termsVersionOf[c.termsHash], c.timestamp, c.refContract, c.refId);
}
/// @notice Full tx-based consent record incl. the version tag the bound
/// terms hash was published under.
function getUserConsent(
address user,
uint256 index
) external view returns (bytes32 termsHash, string memory termsVersion, uint256 timestamp, address recorder, uint256 refId) {
Consent memory c = userConsents[user][index];
return (c.termsHash, termsVersionOf[c.termsHash], c.timestamp, c.recorder, c.refId);
}
/// @notice Store a legacy agreement signed via signMessage.
/// @dev Dual-accept: when active terms are published, first verify against
/// the versioned message (binding the consent to `activeTermsHash`); fall
/// back to the legacy un-versioned message so pre-upgrade frontends and
/// already-stashed signatures keep working (those record a zero hash).
function storeLegacyAgreement(address user, address legacyAddress, uint256 timestamp, bytes calldata signature) external nonReentrant onlyRouter {
uint256 nowTs = block.timestamp;
if (timestamp < nowTs - MAX_PAST_OFFSET || timestamp > nowTs + MAX_FUTURE_OFFSET) {
revert TimestampOutOfRange();
}
if (signatureUsed[signature] != 0) revert SignatureUsed();
bool versioned = false;
if (activeTermsHash != bytes32(0)) {
bytes32 versionedHash = _getEthSignedMessageHash(generateVersionedMessage(timestamp));
versioned = recoverSigner(versionedHash, signature) == user;
}
if (!versioned) {
bytes32 legacyHash = _getEthSignedMessageHash(generateMessage(timestamp));
if (recoverSigner(legacyHash, signature) != user) {
revert InvalidSignature();
}
}
legacySigned[user].push(Legacy({legacyAddress: legacyAddress, timestamp: timestamp, signature: signature}));
signatureUsed[signature] = timestamp;
emit LegacySigned(user, uint256(uint160(legacyAddress)), timestamp);
if (versioned) {
signatureTermsHash[signature] = activeTermsHash;
emit LegacySignedVersioned(user, uint256(uint160(legacyAddress)), timestamp, activeTermsVersion, activeTermsHash);
}
}
function _getEthSignedMessageHash(string memory message) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", _uintToString(bytes(message).length), message));
}
function getUserLegacyCount(address user) external view returns (uint256) {
return legacySigned[user].length;
}
function getUserLegacy(
address user,
uint256 index
) external view returns (address legacyAddress, uint256 timestamp, string memory message, bytes memory signature) {
Legacy memory legacy = legacySigned[user][index];
// Reconstruct the exact message this record was signed over: versioned
// records use the historical tag looked up via their document hash.
// (Pre-existing bug fixed in passing: this used to call
// generateMessage(timestamp) on the still-unassigned named return —
// i.e. always timestamp 0 — instead of the record's own timestamp.)
bytes32 tHash = signatureTermsHash[legacy.signature];
string memory termString = tHash == bytes32(0)
? generateMessage(legacy.timestamp)
: _versionedMessage(termsVersionOf[tHash], legacy.timestamp);
return (legacy.legacyAddress, legacy.timestamp, termString, legacy.signature);
}
function recoverSigner(bytes32 digest, bytes memory signature) public pure returns (address) {
if (signature.length != 65) {
revert InvalidSignature();
}
bytes32 r;
bytes32 s;
uint8 v;
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
// Validate s is in lower half of secp256k1 curve order (EIP-2)
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
revert InvalidSignature();
}
if (v < 27) v += 27;
if (v != 27 && v != 28) {
revert InvalidV();
}
return ecrecover(digest, v, r, s);
}
function generateMessage(uint256 timestamp) public pure returns (string memory) {
return string.concat(MESSAGE_PREFIX, " at timestamp ", _uintToString(timestamp), ".");
}
/// @notice The message users must sign while terms versioning is active.
/// Frontends call this (or mirror its format) so wallet prompt and
/// on-chain verification agree byte-for-byte. Falls back to the legacy
/// format when no active terms are published.
function generateVersionedMessage(uint256 timestamp) public view returns (string memory) {
if (activeTermsHash == bytes32(0)) return generateMessage(timestamp);
return _versionedMessage(activeTermsVersion, timestamp);
}
function _versionedMessage(string memory termsVersion_, uint256 timestamp) internal pure returns (string memory) {
return string.concat(
MESSAGE_PREFIX,
" (version ",
termsVersion_,
") at timestamp ",
_uintToString(timestamp),
"."
);
}
/// @notice Terms-document hash bound to a stored consent record; zero for
/// records created before versioning was active.
function getUserLegacyTermsHash(address user, uint256 index) external view returns (bytes32) {
return signatureTermsHash[legacySigned[user][index].signature];
}
function _uintToString(uint256 value) internal pure returns (string memory) {
if (value == 0) return "0";
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + (value % 10)));
value /= 10;
}
return string(buffer);
}
function _toHexString(address account) internal pure returns (string memory) {
return _toHexString(uint256(uint160(account)), 20);
}
function _toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes16 _hexSymbols = "0123456789abcdef";
bytes memory buffer = new bytes(2 + length * 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 + length * 2; i > 2; --i) {
buffer[i - 1] = _hexSymbols[value & 0xf];
value >>= 4;
}
if (value != 0) revert HexLengthInsufficient();
return string(buffer);
}
}
@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Ownable
struct OwnableStorage {
address _owner;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;
function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
assembly {
$.slot := OwnableStorageLocation
}
}
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
function __Ownable_init(address initialOwner) internal onlyInitializing {
__Ownable_init_unchained(initialOwner);
}
function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
OwnableStorage storage $ = _getOwnableStorage();
return $._owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
OwnableStorage storage $ = _getOwnableStorage();
address oldOwner = $._owner;
$._owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
@openzeppelin/contracts/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reinitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Pointer to storage slot. Allows integrators to override it with a custom storage location.
*
* NOTE: Consider following the ERC-7201 formula to derive storage locations.
*/
function _initializableStorageSlot() internal pure virtual returns (bytes32) {
return INITIALIZABLE_STORAGE;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
bytes32 slot = _initializableStorageSlot();
assembly {
$.slot := slot
}
}
}
@openzeppelin/contracts/utils/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
import {StorageSlot} from "./StorageSlot.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*
* IMPORTANT: Deprecated. This storage-based reentrancy guard will be removed and replaced
* by the {ReentrancyGuardTransient} variant in v6.0.
*
* @custom:stateless
*/
abstract contract ReentrancyGuard {
using StorageSlot for bytes32;
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant REENTRANCY_GUARD_STORAGE =
0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
/**
* @dev A `view` only version of {nonReentrant}. Use to block view functions
* from being called, preventing reading from inconsistent contract state.
*
* CAUTION: This is a "view" modifier and does not change the reentrancy
* status. Use it only on view functions. For payable or non-payable functions,
* use the standard {nonReentrant} modifier instead.
*/
modifier nonReentrantView() {
_nonReentrantBeforeView();
_;
}
function _nonReentrantBeforeView() private view {
if (_reentrancyGuardEntered()) {
revert ReentrancyGuardReentrantCall();
}
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
_nonReentrantBeforeView();
// Any calls to nonReentrant after this point will fail
_reentrancyGuardStorageSlot().getUint256Slot().value = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _reentrancyGuardStorageSlot().getUint256Slot().value == ENTERED;
}
function _reentrancyGuardStorageSlot() internal pure virtual returns (bytes32) {
return REENTRANCY_GUARD_STORAGE;
}
}
@openzeppelin/contracts/utils/StorageSlot.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC-1967 implementation slot:
* ```solidity
* contract ERC1967 {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
/**
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"useLiteralContent": true
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.