Description:
Proxy contract enabling upgradeable smart contract patterns. Delegates calls to an implementation contract.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"contracts/DelegateFactory.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "./Delegate_n.sol";
import "./IDelegate_n.sol";
// The Delegate Factory creates delegates (i.e. smart contracts)
// It takes commands from the AI passes them through to each delegate
// Its functions can only be called by the 2/3-MultiSig or a designated EOA
// Note: The designated EOA starts as the deployer address, but this can be changed by the 2/3-MultiSig
contract DelegateFactory {
address public initialAuthorizedSigner;
address public multisigTwothird;
address public deployer;
address[] public allDelegates;
event DelegateDeployed(address indexed delegateAddress);
event DeployerChanged(address indexed oldDeployer, address indexed newDeployer);
constructor(address _multisigTwothird, address _initialAuthorizedSigner) {
require(_multisigTwothird != address(0), "Invalid multisig");
multisigTwothird = _multisigTwothird;
initialAuthorizedSigner = _initialAuthorizedSigner;
deployer = msg.sender;
}
// Both the 2/3-MultiSig and (designated) admin EOA can call these functions
modifier onlyOwner() {
require(
msg.sender == multisigTwothird || msg.sender == deployer,
"Only deployer or multisig"
);
_;
}
// Only the 2/3-MultiSig can designate a new admin EOA
function changeDeployer(address newDeployer) external {
require(msg.sender == multisigTwothird, "Only multisig can change deployer");
require(newDeployer != address(0), "Invalid deployer");
address oldDeployer = deployer;
deployer = newDeployer;
emit DeployerChanged(oldDeployer, newDeployer);
}
// Creates new delegates (i.e. smart contracts) as defined by Delegate_n.sol
function createDelegate() external returns (address) {
Delegate_n delegate = new Delegate_n(address(this), multisigTwothird, initialAuthorizedSigner);
allDelegates.push(address(delegate));
emit DelegateDeployed(address(delegate));
return address(delegate);
}
// Etherscan viewable function showing the addresses of all delegates
// under control by the Delegate Factory
function getAllDelegates() external view returns (address[] memory) {
return allDelegates;
}
// ================== BATCH VOTING ==================
// This enum helps our functions easily know which DAO we are commanding our
// delegates to cast votes on. This is more efficient and error-resistant than
// string or address comparisons
enum DaoType { Uniswap, Sky, OZ, Optimism, Gnosis }
// Whenever we have a batch of votes we want different delegates to cast on
// different DAOs, we organize these voting instructions into the following struct
struct VoteInstruction {
address delegate;
DaoType daoType;
address target; // governor/Chief
uint256 proposalId; // for Uniswap/OZ/OP
uint8 support; // for Uniswap/OZ/OP
string reason; // optional for Uniswap/OZ
address[] yays; // for Sky only
}
// Whenever the AI (or our 2/3-MultiSig) wants to execute voting decisions, we organize
// them all into a batch so that they can all fit in one transaction (and save gas costs)
function batchVote(VoteInstruction[] calldata instructions) external onlyOwner {
for (uint256 i = 0; i < instructions.length; i++) {
VoteInstruction calldata v = instructions[i];
IDelegate_n delegate = IDelegate_n(v.delegate);
if (v.daoType == DaoType.Uniswap) {
if (bytes(v.reason).length > 0) {
delegate.castVoteWithReasonUniswap(v.target, v.proposalId, v.support, v.reason);
} else {
delegate.castVoteUniswap(v.target, v.proposalId, v.support);
}
} else if (v.daoType == DaoType.OZ) {
if (bytes(v.reason).length > 0) {
delegate.castVoteWithReasonOZ(v.target, v.proposalId, v.support, v.reason);
} else {
delegate.castVoteOZ(v.target, v.proposalId, v.support);
}
} else if (v.daoType == DaoType.Sky) {
delegate.voteSky(v.target, v.yays);
} else if (v.daoType == DaoType.Optimism) {
// We might need to add voting logic here in the future for OP-based DAOs (rare)
} else if (v.daoType == DaoType.Gnosis) {
if (bytes(v.reason).length > 0) {
delegate.castVoteWithReasonGnosis(v.target, v.proposalId, v.support, v.reason);
} else {
delegate.castVoteGnosis(v.target, v.proposalId, v.support);
}
} else {
revert("Unknown DAO type");
}
}
}
}
"
},
"contracts/Delegate_n.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "../lib/openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol";
import "../lib/openzeppelin-contracts/contracts/interfaces/IERC1271.sol";
import "../lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol";
// ========== INTERFACES ==========
// Interfaces are meant to hold the functions that are defined by the rsp. Governor contracts
// We split up the interfaces by DAO (incl. Governor contract and Token contract)
// The token contract defines how the delegation functions are syntaxed
// The governor contract defines how the vote-casting functions are syntaxed
// --- Uniswap ---
interface IUniswapGovernorBravo {
function castVote(uint256 proposalId, uint8 support) external returns (uint256);
function castVoteWithReason(uint256 proposalId, uint8 support, string calldata reason) external returns (uint256);
function castVoteBySig(uint256 proposalId, uint8 support, uint8 v, bytes32 r, bytes32 s) external returns (uint256);
}
interface IUniToken {
function delegate(address delegatee) external;
function transfer(address to, uint256 amount) external returns (bool);
}
// --- Sky DAO ---
interface ISkyChief {
function vote(address[] calldata yays) external;
}
interface ISkyToken {
function delegate(address delegatee) external;
function transfer(address to, uint256 amount) external returns (bool);
}
// --- OpenZeppelin Governor (This is our SimulatorDAO on Sepolia) ---
interface IOpenZeppelinGovernor {
function castVote(uint256 proposalId, uint8 support) external returns (uint256);
function castVoteWithReason(uint256 proposalId, uint8 support, string calldata reason) external returns (uint256);
}
interface IOZToken {
function delegate(address delegatee) external;
function transfer(address to, uint256 amount) external returns (bool);
}
// --- Gnosis DAO ---
interface IGnosisGovernor {
function castVote(uint256 proposalId, uint8 support) external returns (uint256);
function castVoteWithReason(uint256 proposalId, uint8 support, string calldata reason) external returns (uint256);
}
interface IGnosisToken {
function delegate(address delegatee) external;
function transfer(address to, uint256 amount) external returns (bool);
}
// ========== MAIN CONTRACT ==========
// This delegate contract should only have its functions called by:
// - 2/3-MultiSig (Master)
// - DelegateFactory.sol (Master unless blocked by 2/3-MultiSig)
contract Delegate_n is IERC1271, ReentrancyGuard {
mapping(address => bool) public isAuthorizedSigner;
address public immutable factory;
address public immutable multisigTwothird;
bool public factoryBlocked;
// Both the Delegate Factory and 2/3-MultiSig can call the functions with this modifier
// unless the 2/3-MultiSig has blocked the Delegate Factory (and thereby blocked the AI)
modifier onlyFactoryOrMultisig() {
if (factoryBlocked) {
require(msg.sender == multisigTwothird, "Blocked: Only multisig");
} else {
require(msg.sender == factory || msg.sender == multisigTwothird, "Only factory or multisig");
}
_;
}
// Used only for the block/unblocking function, which should only be callable by
// the Delegate Factory (which receives commands by the AI)
modifier onlyMultisig() {
require(msg.sender == multisigTwothird, "Only multisig");
_;
}
constructor(address _factory, address _multisigTwothird, address _initialAuthorizedSigner) {
require(_factory != address(0), "Invalid factory");
require(_factory.code.length > 0, "Factory must be contract");
require(_multisigTwothird != address(0), "Invalid multisig");
require(_initialAuthorizedSigner != address(0), "Invalid signer");
factory = _factory;
multisigTwothird = _multisigTwothird;
// Authorize the initial signer
isAuthorizedSigner[_initialAuthorizedSigner] = true;
}
// ========== Change the authorized signer for Offchain Voting ==========
event AuthorizedSignerAdded(address signer);
event AuthorizedSignerRemoved(address signer);
event FactoryBlocked();
event FactoryUnblocked();
event VoteCast(address indexed governor, uint256 proposalId, uint8 support, string reason);
event BatchExecuted(uint256 callsExecuted);
function addAuthorizedSigner(address signer) external onlyMultisig {
require(signer != address(0), "Zero address");
isAuthorizedSigner[signer] = true;
emit AuthorizedSignerAdded(signer);
}
function removeAuthorizedSigner(address signer) external onlyMultisig {
isAuthorizedSigner[signer] = false;
emit AuthorizedSignerRemoved(signer);
}
// ========== BLOCK/UNBLOCK FACTORY ==========
// Both the 2/3-MultiSig and Delegate Factory have access to the delegation/vote casting functions
// Unless the Delegate Factory is blocked by the 2/3-MultiSig
// This can happen if we do not want the AI to engage in unilateral vote casting decision making
function blockFactory() external onlyMultisig {
factoryBlocked = true;
emit FactoryBlocked();
}
function unblockFactory() external onlyMultisig {
factoryBlocked = false;
emit FactoryUnblocked();
}
// ========== VOTE CASTING / DELEGATION ===========
// Now we use the interfaces to connect the vote-casting commands by the
// AI to the correct syntax used by the Governor contract of the respective DAO
// ========== UNISWAP ==========
function castVoteUniswap(address governor, uint256 proposalId, uint8 support) external onlyFactoryOrMultisig {
IUniswapGovernorBravo(governor).castVote(proposalId, support);
emit VoteCast(governor, proposalId, support, "");
}
function castVoteWithReasonUniswap(address governor, uint256 proposalId, uint8 support, string calldata reason) external onlyFactoryOrMultisig {
IUniswapGovernorBravo(governor).castVoteWithReason(proposalId, support, reason);
emit VoteCast(governor, proposalId, support, reason);
}
function castVoteBySigUniswap(address governor, uint256 proposalId, uint8 support, uint8 v, bytes32 r, bytes32 s) external onlyFactoryOrMultisig {
IUniswapGovernorBravo(governor).castVoteBySig(proposalId, support, v, r, s);
}
function delegateUni(address uniToken, address delegatee) external onlyFactoryOrMultisig {
IUniToken(uniToken).delegate(delegatee);
}
// ========== SKY DAO ==========
function voteSky(address chief, address[] calldata yays) external onlyFactoryOrMultisig {
ISkyChief(chief).vote(yays);
}
function delegateSky(address skyToken, address delegatee) external onlyFactoryOrMultisig {
ISkyToken(skyToken).delegate(delegatee);
}
// ========== OPENZEPPELIN GOVERNOR ==========
function castVoteOZ(address governor, uint256 proposalId, uint8 support) external onlyFactoryOrMultisig {
IOpenZeppelinGovernor(governor).castVote(proposalId, support);
emit VoteCast(governor, proposalId, support, "");
}
function castVoteWithReasonOZ(address governor, uint256 proposalId, uint8 support, string calldata reason) external onlyFactoryOrMultisig {
IOpenZeppelinGovernor(governor).castVoteWithReason(proposalId, support, reason);
emit VoteCast(governor, proposalId, support, reason);
}
function delegateOZ(address ozToken, address delegatee) external onlyFactoryOrMultisig {
IOZToken(ozToken).delegate(delegatee);
}
// ========== GNOSIS DAO ==========
function castVoteGnosis(address governor, uint256 proposalId, uint8 support) external onlyFactoryOrMultisig {
IGnosisGovernor(governor).castVote(proposalId, support);
emit VoteCast(governor, proposalId, support, "");
}
function castVoteWithReasonGnosis(address governor, uint256 proposalId, uint8 support, string calldata reason) external onlyFactoryOrMultisig {
IGnosisGovernor(governor).castVoteWithReason(proposalId, support, reason);
emit VoteCast(governor, proposalId, support, reason);
}
function delegateGnosis(address gnosisToken, address delegatee) external onlyFactoryOrMultisig {
IGnosisToken(gnosisToken).delegate(delegatee);
}
// ========== OFF-CHAIN VOTING ========================
// This function needs to be present because e.g. Snapshot will call this function
// on our smart contract to verify the signature, so we need to have it here
function isValidSignature(
bytes32 hash,
bytes memory signature
) public view override returns (bytes4) {
address signer = ECDSA.recover(hash, signature);
if (isAuthorizedSigner[signer]) {
return 0x1626ba7e;
} else {
return 0x00000000;
}
}
// ========== SINGLE TOKEN TRANSFER FUNCTION ==========
// In case this delegate receives tokens, it can later transfer them to someone else
function transferToken(address token, address to, uint256 amount) external onlyFactoryOrMultisig {
require(token != address(0) && to != address(0), "Zero address");
// Works for any ERC20, revert if fails
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(
bytes4(keccak256("transfer(address,uint256)")),
to, amount
));
require(success && (data.length == 0 || abi.decode(data, (bool))), "Transfer failed");
}
// ========== ARBITRARY EXECUTION FUNCTION ==========
/**
* @notice Execute multiple arbitrary function calls on target contracts, with optional ETH for each
* @dev Only callable by factory or multisig. All calls are made in order and revert if any fail.
* @param targets The contracts to call
* @param data The calldata (function selector + arguments) for each call
* @param values Amounts of ETH to send with each call
* @return results Return data from each call
*/
function manageBatch(
address[] calldata targets,
bytes[] calldata data,
uint256[] calldata values
)
external
onlyFactoryOrMultisig
nonReentrant
returns (bytes[] memory results)
{
require(
targets.length == data.length && targets.length == values.length,
"Array length mismatch"
);
results = new bytes[](targets.length);
for (uint256 i = 0; i < targets.length; i++) {
require(targets[i] != address(0), "Target cannot be zero address");
(bool success, bytes memory returndata) = targets[i].call{value: values[i]}(data[i]);
require(success, "Delegate_n: batch call failed");
results[i] = returndata;
}
emit BatchExecuted(targets.length);
}
// ========== ALLOW RECEIVING ETHER ==========
/**
* @notice Allow contract to receive ETH
*/
receive() external payable {}
}
"
},
"contracts/IDelegate_n.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
// This interface specifies the functions which the Factory may need to call.
// The other functions within Delegate_n.sol are not called by the factory.
// If this were to change, e.g. we want delegates to receive tokens and delegate them
// then those other functions (e.g. ISkyToken.delegate()) which are not present here, must be added.
interface IDelegate_n {
function castVoteWithReasonUniswap(address governor, uint256 proposalId, uint8 support, string calldata reason) external;
function castVoteUniswap(address governor, uint256 proposalId, uint8 support) external;
function castVoteWithReasonOZ(address governor, uint256 proposalId, uint8 support, string calldata reason) external;
function castVoteOZ(address governor, uint256 proposalId, uint8 support) external;
function voteSky(address chief, address[] calldata yays) external;
function castVoteWithReasonGnosis(address governor, uint256 proposalId, uint8 support, string calldata reason) external;
function castVoteGnosis(address governor, uint256 proposalId, uint8 support) external;
}
"
},
"lib/openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.20;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS
}
/**
* @dev The signature derives the `address(0)`.
*/
error ECDSAInvalidSignature();
/**
* @dev The signature has an invalid length.
*/
error ECDSAInvalidSignatureLength(uint256 length);
/**
* @dev The signature has an S value that is in the upper half order.
*/
error ECDSAInvalidSignatureS(bytes32 s);
/**
* @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
* return address(0) without also returning an error description. Errors are documented using an enum (error type)
* and a bytes32 providing additional information about the error.
*
* If no error is returned, then the address can be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*/
function tryRecover(
bytes32 hash,
bytes memory signature
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly ("memory-safe") {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
unchecked {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
// We do not check for an overflow here since the shift operation results in 0 or 1.
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS, s);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature, bytes32(0));
}
return (signer, RecoverError.NoError, bytes32(0));
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
*/
function _throwError(RecoverError error, bytes32 errorArg) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert ECDSAInvalidSignature();
} else if (error == RecoverError.InvalidSignatureLength) {
revert ECDSAInvalidSignatureLength(uint256(errorArg));
} else if (error == RecoverError.InvalidSignatureS) {
revert ECDSAInvalidSignatureS(errorArg);
}
}
}
"
},
"lib/openzeppelin-contracts/contracts/interfaces/IERC1271.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1271.sol)
pragma solidity >=0.5.0;
/**
* @dev Interface of the ERC-1271 standard signature validation method for
* contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
*/
interface IERC1271 {
/**
* @dev Should return whether the signature provided is valid for the provided data
* @param hash Hash of the data to be signed
* @param signature Signature byte array associated with `hash`
*/
function isValidSignature(bytes32 hash, bytes calldata signature) external view returns (bytes4 magicValue);
}
"
},
"lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @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].
*/
abstract contract ReentrancyGuard {
// 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;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = 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();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = 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 _status == ENTERED;
}
}
"
}
},
"settings": {
"remappings": [
"forge-std/=lib/forge-std/src/",
"@openzeppelin/=lib/openzeppelin-contracts/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": false
}
}}
Submitted on: 2025-09-19 13:09:25
Comments
Log in to comment.
No comments yet.