Verified contractPartialMIT
SignerRegistry
Address0x1612c1db1e373019b35748e3e57bddef8a8c8fde
- Balance
0 ETH
- Transactions
18
- Compiler
solc 0.8.35
- Same code
Only this contract
Details
- Compiler
- solc 0.8.35+commit.47b9dedd
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- prague
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,275,164
- Creation transaction
- 0xd3d8f52b3e…27c0e09b78
8 files
- contracts/signerRegistry/SignerRegistry.solmain14.86 KB
- lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/access/Ownable.sol3.1 KB
- lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol2.48 KB
- lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/Address.sol6.03 KB
- lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/Errors.sol896 B
- lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol3.38 KB
- lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol7.82 KB
contracts/signerRegistry/SignerRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import '@openzeppelin/access/Ownable2Step.sol';
import '@openzeppelin/utils/cryptography/ECDSA.sol';
import '@openzeppelin/utils/Address.sol';
import '@openzeppelin/utils/ReentrancyGuard.sol';
/// @notice What the registry rotates: `MarketMakingStrategy` and `SolverVault` both expose this, owner-gated.
interface ISignerTarget {
function setSigner(address signer) external;
}
interface IOwned {
function owner() external view returns (address);
}
/// @notice The targets' UUPS upgrade entry point.
interface IUpgradeable {
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable;
}
/**
* @title SignerRegistry
* @notice Owns the signer-gated contracts on one chain (hub `MarketMakingStrategy`, `SolverVault`s) and
* rotates their enclave signer from one set of admin signatures that is valid on every chain.
*
* Every enclave restart creates a new key, so the signer changes often. A Safe signature is bound to one
* chain, which would make each restart one Safe transaction per chain. Here the rotation admins (a few
* technical hardware keys) sign one chain-agnostic EIP-712 `RotateSigner`, and a gas wallet relays the
* same signatures to the registry on each chain.
*
* Roles:
* - owner (Safe): everything else. It reaches the targets through {execute} (upgrades, whitelists,
* limits, rescue, moving a target out), sets the signer directly as a fallback ({setSignerByOwner}),
* invalidates outstanding rotations, and manages admins, gas wallets and targets.
* - admins: approve a rotation, `threshold` of them.
* - new signer (the enclave key): co-signs `AcceptSigner`, proving the address is a live key that saw
* this exact rotation, so a typo or a stale address can't be installed. It proves possession only:
* the admins are the root of trust and must check the attestation themselves.
* - gas wallets: the only callers of {rotate}.
*
* No on-chain kill switch: the enclave key never leaves the enclave, so stopping the enclave (or the
* watchdog stopping its instance) ends all signing. The owner can still point every target at a dead
* address with {setSignerByOwner}, which also kills every outstanding rotation signature.
*
* Replay: the domain has no chainId on purpose, so the same signatures rotate every chain. `SCOPE` keeps
* registries of different deployments (staging, prod) apart. `nonce` only moves up, by at most
* {MAX_NONCE_JUMP} per rotation, so a chain that missed a rotation can catch up, an older signature is
* dead once a newer one has landed, and no signature can exhaust the nonce space. A registry deployed
* later in the same scope (replacement, new chain) starts at the current `nonce` so old signatures don't
* replay on it.
*
* Not upgradeable: replace it by having the owner drop each target with {setTargets}, then {execute}
* `transferOwnership` on it.
*/
contract SignerRegistry is Ownable2Step, ReentrancyGuard {
/// @notice Longest a rotation signature may be submitted ahead of its deadline.
uint256 public constant MAX_ROTATION_LIFETIME = 1 days;
/// @notice Furthest a rotation may move `nonce` forward; the owner covers bigger gaps with
/// {invalidateNonces}.
uint256 public constant MAX_NONCE_JUMP = 64;
bytes32 public constant DOMAIN_TYPEHASH = keccak256('EIP712Domain(string name,string version)');
bytes32 public constant ROTATE_TYPEHASH =
keccak256('RotateSigner(bytes32 scope,address newSigner,uint256 nonce,uint256 deadline)');
bytes32 public constant ACCEPT_TYPEHASH =
keccak256('AcceptSigner(bytes32 scope,address newSigner,uint256 nonce,uint256 deadline)');
/// @notice No chainId and no verifyingContract: one signature for every chain's registry.
bytes32 public constant DOMAIN_SEPARATOR =
keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256('SodaxSignerRegistry'), keccak256('1')));
/// @notice Which deployment these signatures belong to, e.g. `keccak256("sodax-mm/staging")`.
bytes32 public immutable SCOPE;
/// @notice The signer last installed on every target.
address public signer;
/// @notice Nonce of the last applied rotation, or the owner's invalidation floor.
uint256 public nonce;
uint256 public threshold;
uint256 public adminCount;
mapping(address => bool) public isAdmin;
mapping(address => bool) public gasWallets;
address[] private _targets;
event SignerRotated(uint256 indexed nonce, address indexed signer);
event SignerSetByOwner(address indexed signer);
event NoncesInvalidated(uint256 nonce);
event AdminSet(address indexed admin, bool allowed, uint256 adminCount);
event ThresholdSet(uint256 threshold);
event GasWalletSet(address indexed gasWallet, bool allowed);
event TargetsSet(address[] targets);
event Executed(address indexed target, bytes4 indexed selector);
error NotGasWallet();
error Expired();
error DeadlineTooFar();
error StaleNonce();
error NonceJumpTooFar();
error InvalidSigner();
error BadAcceptSignature();
error NotEnoughAdmins();
error AdminsNotSorted();
error NotAdmin(address recovered);
error InvalidThreshold();
error InvalidTarget(address target);
error InvalidGasWallet();
error SelectorNotAllowed(bytes4 selector);
error Disabled();
/// @param _initialNonce The scope's current nonce on the other chains, so rotations signed before
/// this deployment can't replay on it (0 for a new scope).
constructor(address _owner, bytes32 _scope, uint256 _initialNonce) Ownable(_owner) {
SCOPE = _scope;
nonce = _initialNonce;
}
// ─── Rotation ──────────────────────────────────────────────────────
/// @notice Gas wallet: install `newSigner` on every target. All or nothing.
/// @param adminSigs `RotateSigner` signatures, ordered by strictly ascending signer address.
/// @param acceptSig `AcceptSigner` signature by `newSigner` over the same fields.
function rotate(
address newSigner,
uint256 rotationNonce,
uint256 deadline,
bytes[] calldata adminSigs,
bytes calldata acceptSig
) external nonReentrant {
if (!gasWallets[msg.sender]) revert NotGasWallet();
if (newSigner == address(0)) revert InvalidSigner();
if (block.timestamp > deadline) revert Expired();
if (deadline > block.timestamp + MAX_ROTATION_LIFETIME) revert DeadlineTooFar();
if (rotationNonce <= nonce) revert StaleNonce();
if (rotationNonce > nonce + MAX_NONCE_JUMP) revert NonceJumpTooFar();
_checkAdmins(_rotateHash(newSigner, rotationNonce, deadline), adminSigs);
bytes32 acceptHash = keccak256(abi.encode(ACCEPT_TYPEHASH, SCOPE, newSigner, rotationNonce, deadline));
if (ECDSA.recover(_digest(acceptHash), acceptSig) != newSigner) revert BadAcceptSignature();
nonce = rotationNonce;
signer = newSigner;
_installAll(newSigner);
emit SignerRotated(rotationNonce, newSigner);
}
/// @notice EIP-712 digest admins sign for a rotation.
function rotateDigest(address newSigner, uint256 rotationNonce, uint256 deadline) external view returns (bytes32) {
return _digest(_rotateHash(newSigner, rotationNonce, deadline));
}
/// @notice EIP-712 digest the new signer signs.
function acceptDigest(address newSigner, uint256 rotationNonce, uint256 deadline) external view returns (bytes32) {
return _digest(keccak256(abi.encode(ACCEPT_TYPEHASH, SCOPE, newSigner, rotationNonce, deadline)));
}
function targets() external view returns (address[] memory) {
return _targets;
}
// ─── Owner ─────────────────────────────────────────────────────────
/// @notice Owner: call a target as its owner (upgrades, config, rescue, moving a target out with
/// `transferOwnership`). Refused:
/// - `setSigner`: the signer goes through {setSignerByOwner} so `signer` stays true;
/// - `renounceOwnership`: an ownerless target can never be rotated or rescued;
/// - `upgradeToAndCall` with a non-empty call: the inner call would run as the registry and
/// reach `setSigner`/`renounceOwnership` past the checks above. Upgrade with empty data, then
/// configure through separate {execute} calls;
/// - `transferOwnership` of a target still in {targets}: once moved out it would make every
/// {rotate} and {setSignerByOwner} revert. Drop it with {setTargets} first.
function execute(address target, bytes calldata data) external onlyOwner nonReentrant returns (bytes memory result) {
if (target == address(this)) revert InvalidTarget(target);
bytes4 selector = bytes4(data);
if (selector == ISignerTarget.setSigner.selector || selector == Ownable.renounceOwnership.selector) {
revert SelectorNotAllowed(selector);
}
if (selector == IUpgradeable.upgradeToAndCall.selector) {
(, bytes memory initCall) = abi.decode(data[4:], (address, bytes));
if (initCall.length != 0) revert SelectorNotAllowed(selector);
}
if (selector == Ownable.transferOwnership.selector && _isTarget(target)) revert SelectorNotAllowed(selector);
result = Address.functionCall(target, data);
emit Executed(target, selector);
}
/// @notice Owner: install `newSigner` on every target without admin signatures (lost admins,
/// recovery). In an emergency, a dead address such as 0x…dEaD disables signing everywhere.
/// @dev Also moves `nonce` up by {MAX_NONCE_JUMP}, which kills every rotation signed before this call
/// (a rotation can only land within {MAX_NONCE_JUMP} of `nonce`). Otherwise a pending, already-signed
/// rotation relayed later would undo an emergency stop. The next rotation is signed for the new
/// `nonce + 1`, which is what the rotation tooling picks (highest registry nonce + 1).
function setSignerByOwner(address newSigner) external onlyOwner nonReentrant {
if (newSigner == address(0)) revert InvalidSigner();
uint256 newNonce = nonce + MAX_NONCE_JUMP;
nonce = newNonce;
emit NoncesInvalidated(newNonce);
signer = newSigner;
_installAll(newSigner);
emit SignerSetByOwner(newSigner);
}
/// @notice Owner: kill every outstanding rotation signature with a nonce up to `newNonce`, or let a
/// chain catch up by more than {MAX_NONCE_JUMP}.
function invalidateNonces(uint256 newNonce) external onlyOwner {
if (newNonce <= nonce) revert StaleNonce();
nonce = newNonce;
emit NoncesInvalidated(newNonce);
}
/// @notice Owner: add or remove an admin. Removing may leave fewer admins than `threshold`; rotations
/// then need new admins first, which is what revoking a compromised sole admin requires.
function setAdmin(address admin, bool allowed) external onlyOwner {
if (admin == address(0)) revert NotAdmin(admin);
if (isAdmin[admin] != allowed) {
isAdmin[admin] = allowed;
allowed ? adminCount++ : adminCount--;
}
emit AdminSet(admin, allowed, adminCount);
}
function setThreshold(uint256 _threshold) external onlyOwner {
if (_threshold == 0 || _threshold > adminCount) revert InvalidThreshold();
threshold = _threshold;
emit ThresholdSet(_threshold);
}
function setGasWallet(address gasWallet, bool allowed) external onlyOwner {
if (gasWallet == address(0)) revert InvalidGasWallet();
gasWallets[gasWallet] = allowed;
emit GasWalletSet(gasWallet, allowed);
}
/// @notice Owner: the contracts each rotation updates. Each must already be owned by the registry, and
/// each gets the current signer right away.
function setTargets(address[] calldata newTargets) external onlyOwner nonReentrant {
for (uint256 i; i < newTargets.length; ++i) {
address target = newTargets[i];
if (target == address(this) || IOwned(target).owner() != address(this)) revert InvalidTarget(target);
for (uint256 j; j < i; ++j) {
if (newTargets[j] == target) revert InvalidTarget(target);
}
}
_targets = newTargets;
if (signer != address(0)) _installAll(signer);
emit TargetsSet(newTargets);
}
/// @notice Disabled: an ownerless registry would leave every target ownerless.
function renounceOwnership() public pure override {
revert Disabled();
}
/// @dev The registry owning itself would lock out every owner function.
function transferOwnership(address newOwner) public override onlyOwner {
if (newOwner == address(this)) revert InvalidTarget(newOwner);
super.transferOwnership(newOwner);
}
// ─── Internal ──────────────────────────────────────────────────────
function _checkAdmins(bytes32 structHash, bytes[] calldata adminSigs) private view {
// threshold == 0 (never configured) must not let an empty signature list through.
if (threshold == 0 || adminSigs.length < threshold) revert NotEnoughAdmins();
bytes32 digest = _digest(structHash);
address previous;
for (uint256 i; i < adminSigs.length; ++i) {
address recovered = ECDSA.recover(digest, adminSigs[i]);
if (recovered <= previous) revert AdminsNotSorted();
if (!isAdmin[recovered]) revert NotAdmin(recovered);
previous = recovered;
}
}
function _isTarget(address target) private view returns (bool) {
uint256 n = _targets.length;
for (uint256 i; i < n; ++i) {
if (_targets[i] == target) return true;
}
return false;
}
function _installAll(address newSigner) private {
uint256 n = _targets.length;
for (uint256 i; i < n; ++i) {
ISignerTarget(_targets[i]).setSigner(newSigner);
}
}
function _rotateHash(address newSigner, uint256 rotationNonce, uint256 deadline) private view returns (bytes32) {
return keccak256(abi.encode(ROTATE_TYPEHASH, SCOPE, newSigner, rotationNonce, deadline));
}
function _digest(bytes32 structHash) private pure returns (bytes32) {
return keccak256(abi.encodePacked('\x19\x01', DOMAIN_SEPARATOR, structHash));
}
}
lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.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 Ownable is Context {
address private _owner;
/**
* @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.
*/
constructor(address initialOwner) {
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) {
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 {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This extension of the {Ownable} contract includes a two-step mechanism to transfer
* ownership, where the new owner must call {acceptOwnership} in order to replace the
* old one. This can help prevent common mistakes, such as transfers of ownership to
* incorrect accounts, or to contracts that are unable to interact with the
* permission system.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*
* Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}
lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert Errors.FailedCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly ("memory-safe") {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}
lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @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 Context {
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;
}
}
lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/Errors.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}
lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol
// 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;
}
}
lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol
// 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);
}
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "prague",
"remappings": [
"@openzeppelin-upgradeable/proxy/=lib/openzeppelin-contracts-upgradeable/contracts/proxy/",
"@openzeppelin-upgradeable/access/=lib/openzeppelin-contracts-upgradeable/contracts/access/",
"@openzeppelin-upgradeable/token/=lib/openzeppelin-contracts-upgradeable/contracts/token/",
"@openzeppelin-upgradeable/utils/=lib/openzeppelin-contracts-upgradeable/contracts/utils/",
"openzeppelin-contracts/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/",
"@openzeppelin/token/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/",
"@openzeppelin/proxy/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/proxy/",
"@openzeppelin/access/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/access/",
"@openzeppelin/interfaces/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/interfaces/",
"@openzeppelin/utils/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/",
"@openzeppelin/governance/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/governance/",
"@openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/",
"@layerzerolabs/lz-evm-oapp-v2/=lib/LayerZero-v2/packages/layerzero-v2/evm/oapp/",
"@layerzerolabs/lz-evm-protocol-v2/=lib/LayerZero-v2/packages/layerzero-v2/evm/protocol/",
"@layerzerolabs/lz-evm-messagelib-v2/=lib/LayerZero-v2/packages/layerzero-v2/evm/messagelib/",
"@pythnetwork/=lib/pyth-sdk-solidity/",
"@money-market/=contracts/moneyMarket/src/",
"@money-market-scripts/=contracts/moneyMarket/scripts/",
"@money-market-tests/=contracts/moneyMarket/tests/",
"@contracts/=contracts/",
"solidity-utils/=lib/solidity-utils/src/",
"@pyth-lazer/=lib/pyth-crosschain/lazer/contracts/evm/src/",
"LayerZero-v2/=lib/LayerZero-v2/",
"createx/=lib/pyth-crosschain/lazer/contracts/evm/lib/createx/src/",
"ds-test/=lib/solmate/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-foundry-upgrades/=lib/pyth-crosschain/target_chains/ethereum/sdk/stylus/pyth-mock-solidity/lib/openzeppelin-foundry-upgrades/src/",
"pyth-crosschain/=lib/pyth-crosschain/",
"pyth-sdk-solidity/=lib/pyth-sdk-solidity/",
"solady/=lib/pyth-crosschain/lazer/contracts/evm/lib/createx/lib/solady/",
"solidity-stringutils/=lib/pyth-crosschain/target_chains/ethereum/sdk/stylus/pyth-mock-solidity/lib/openzeppelin-foundry-upgrades/lib/solidity-stringutils/",
"solmate/=lib/solmate/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.