Verified contractExactMIT
VerifiableFactory
Address0xb676dd5546443486fbbdb372f83e9133edc75708
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.25
- Same code
Only this contract
Details
- Compiler
- solc 0.8.25+commit.b61c2a91
- Language
- solidity
- Optimization
- Yes, 1,000 runs
- EVM version
- shanghai
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,425,316
- Creation transaction
- 0x83fa31ebef…c285ba7805
8 files
- lib/contracts-v2/contracts/lib/verifiable-factory/src/VerifiableFactory.solmain3.42 KB
- lib/contracts-v2/contracts/lib/openzeppelin-contracts/contracts/utils/Create2.sol4.47 KB
- lib/contracts-v2/contracts/lib/openzeppelin-contracts/contracts/utils/Errors.sol896 B
- lib/contracts-v2/contracts/lib/verifiable-factory/src/CloneProxyBytecode.sol1.59 KB
- lib/contracts-v2/contracts/lib/verifiable-factory/src/IProxyAuthorization.sol182 B
- lib/contracts-v2/contracts/lib/verifiable-factory/src/IUUPSProxy.sol875 B
- lib/contracts-v2/contracts/lib/verifiable-factory/src/IVerifiableFactory.sol457 B
- lib/contracts-v2/contracts/lib/verifiable-factory/src/UUPSProxyLogic.sol5.67 KB
lib/contracts-v2/contracts/lib/verifiable-factory/src/VerifiableFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
import {CloneProxyBytecode} from "./CloneProxyBytecode.sol";
import {UUPSProxyLogic} from "./UUPSProxyLogic.sol";
import {IUUPSProxy} from "./IUUPSProxy.sol";
import {IVerifiableFactory} from "./IVerifiableFactory.sol";
contract VerifiableFactory is IVerifiableFactory {
address public immutable proxyLogic;
constructor() {
proxyLogic = address(new UUPSProxyLogic());
}
/**
* @dev Deploys a new verifiable proxy clone at a deterministic address.
*
* The deployed proxy is an EIP-1167-style clone that delegates proxy mechanics to the
* factory's `proxyLogic` contract. The clone runtime also appends the derived salt so the
* factory can later verify the proxy's CREATE2 address.
*
* The CREATE2 salt is `keccak256(abi.encode(msg.sender, salt))`, so two callers can reuse
* the same user salt without colliding.
*
* @param implementation The address of the contract implementation the proxy will delegate calls to.
* @param salt A value provided by the caller to ensure uniqueness of the proxy address.
* @return proxy The address of the deployed proxy clone.
*/
function deployProxy(address implementation, uint256 salt, bytes memory data) external returns (address proxy) {
bytes32 outerSalt = keccak256(abi.encode(msg.sender, salt));
bytes memory executableBytecode = _proxyCreationCode(outerSalt);
assembly {
proxy := create2(0, add(executableBytecode, 0x20), mload(executableBytecode), outerSalt)
if iszero(proxy) {
revert(0, 0)
}
}
IUUPSProxy(proxy).initialize(implementation, data);
emit ProxyDeployed(msg.sender, proxy, salt, implementation);
}
/**
* @dev Verifies a proxy contract and returns its current implementation.
*
* This function attempts to validate a proxy contract by retrieving its salt
* and reconstructing the address to ensure it was correctly deployed by the
* current factory.
*
* @param proxy The address of the proxy contract being verified.
* @return implementation The proxy's current implementation.
*/
function verifyContract(address proxy) public view returns (address implementation) {
if (!isContract(proxy)) revert VerificationFailed(proxy);
try IUUPSProxy(proxy).getVerifiableProxyData() returns (bytes32 salt, address actualImplementation) {
if (_verifyContract(proxy, salt)) return actualImplementation;
} catch {}
revert VerificationFailed(proxy);
}
function _verifyContract(address proxy, bytes32 salt) private view returns (bool) {
bytes memory proxyBytecode = _proxyCreationCode(salt);
address expectedProxyAddress = Create2.computeAddress(salt, keccak256(proxyBytecode), address(this));
return expectedProxyAddress == proxy;
}
function _proxyCreationCode(bytes32 salt) private view returns (bytes memory creationCode) {
creationCode = CloneProxyBytecode.creationCode(proxyLogic, salt);
}
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
}
lib/contracts-v2/contracts/lib/openzeppelin-contracts/contracts/utils/Create2.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Create2.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Helper to make usage of the `CREATE2` EVM opcode easier and safer.
* `CREATE2` can be used to compute in advance the address where a smart
* contract will be deployed, which allows for interesting new mechanisms known
* as 'counterfactual interactions'.
*
* See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more
* information.
*/
library Create2 {
/**
* @dev There's no code to deploy.
*/
error Create2EmptyBytecode();
/**
* @dev Deploys a contract using `CREATE2`. The address where the contract
* will be deployed can be known in advance via {computeAddress}.
*
* The bytecode for a contract can be obtained from Solidity with
* `type(contractName).creationCode`.
*
* Requirements:
*
* - `bytecode` must not be empty.
* - `salt` must have not been used for `bytecode` already.
* - the factory must have a balance of at least `amount`.
* - if `amount` is non-zero, `bytecode` must have a `payable` constructor.
*/
function deploy(uint256 amount, bytes32 salt, bytes memory bytecode) internal returns (address addr) {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
if (bytecode.length == 0) {
revert Create2EmptyBytecode();
}
assembly ("memory-safe") {
addr := create2(amount, add(bytecode, 0x20), mload(bytecode), salt)
// if no address was created, and returndata is not empty, bubble revert
if and(iszero(addr), not(iszero(returndatasize()))) {
let p := mload(0x40)
returndatacopy(p, 0, returndatasize())
revert(p, returndatasize())
}
}
if (addr == address(0)) {
revert Errors.FailedDeployment();
}
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the
* `bytecodeHash` or `salt` will result in a new destination address.
*/
function computeAddress(bytes32 salt, bytes32 bytecodeHash) internal view returns (address) {
return computeAddress(salt, bytecodeHash, address(this));
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at
* `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.
*/
function computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) internal pure returns (address addr) {
assembly ("memory-safe") {
let ptr := mload(0x40) // Get free memory pointer
// | | ↓ ptr ... ↓ ptr + 0x0B (start) ... ↓ ptr + 0x20 ... ↓ ptr + 0x40 ... |
// |-------------------|---------------------------------------------------------------------------|
// | bytecodeHash | CCCCCCCCCCCCC...CC |
// | salt | BBBBBBBBBBBBB...BB |
// | deployer | 000000...0000AAAAAAAAAAAAAAAAAAA...AA |
// | 0xFF | FF |
// |-------------------|---------------------------------------------------------------------------|
// | memory | 000000...00FFAAAAAAAAAAAAAAAAAAA...AABBBBBBBBBBBBB...BBCCCCCCCCCCCCC...CC |
// | keccak(start, 85) | ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ |
mstore(add(ptr, 0x40), bytecodeHash)
mstore(add(ptr, 0x20), salt)
mstore(ptr, deployer) // Right-aligned with 12 preceding garbage bytes
let start := add(ptr, 0x0b) // The hashed data starts at the final garbage byte which we will set to 0xff
mstore8(start, 0xff)
addr := and(keccak256(start, 85), 0xffffffffffffffffffffffffffffffffffffffff)
}
}
}
lib/contracts-v2/contracts/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/contracts-v2/contracts/lib/verifiable-factory/src/CloneProxyBytecode.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
library CloneProxyBytecode {
// EIP-1167 minimal proxy creation/runtime code:
// https://eips.ethereum.org/EIPS/eip-1167
//
// Standard runtime is 45 bytes:
// 363d3d373d3d3d363d73<20-byte implementation>5af43d82803e903d91602b57fd5bf3
//
// We append a 32-byte salt to the runtime and make the creation stub return 77 bytes
// instead of the standard 45. The proxy still executes the same minimal-proxy logic;
// UUPSProxyLogic reads the appended salt with extcodecopy().
uint256 internal constant CREATION_CODE_LENGTH = 0x57;
function creationCode(address logic, bytes32 salt) internal pure returns (bytes memory code) {
code = new bytes(CREATION_CODE_LENGTH);
assembly ("memory-safe") {
let ptr := add(code, 0x20)
// Creation stub plus runtime prefix. The creation stub returns 77 bytes:
// 45 bytes of EIP-1167 runtime plus our appended 32-byte salt.
mstore(ptr, 0x3d604d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
// Fill the EIP-1167 PUSH20 slot with the shared proxy logic address.
mstore(add(ptr, 0x14), shl(0x60, logic))
// Runtime suffix: delegatecall to `logic`, copy returndata, then return or revert.
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
// Append salt after the executable minimal-proxy runtime for extcodecopy().
mstore(add(ptr, 0x37), salt)
}
}
}
lib/contracts-v2/contracts/lib/verifiable-factory/src/IProxyAuthorization.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IProxyAuthorization {
function canUpgradeFrom(address previousImplementation) external view returns (bool);
}
lib/contracts-v2/contracts/lib/verifiable-factory/src/IUUPSProxy.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IUUPSProxy {
/// @dev Error selector: `0x0760838f`
error ImplementationCannotBeZeroAddress();
/// @dev Error selector: `0x0dc149f0`
error AlreadyInitialized();
/// @dev Error selector: `0x40dde935`
error ImplementationNotSet();
/// @dev Error selector: `0xca331687`
error InvalidUpgradeTarget(address currentImplementation, address newImplementation);
/// @dev Error selector: `0x784cf700`
error UpgradeNotAllowedInContext();
/// @dev Error selector: `0x2be61883`
error UnexpectedUpgrade();
function initialize(address implementation, bytes calldata data) external payable;
function getVerifiableProxyData() external view returns (bytes32 salt, address implementation);
function verifiableProxyFactory() external view returns (address);
}
lib/contracts-v2/contracts/lib/verifiable-factory/src/IVerifiableFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IVerifiableFactory {
error VerificationFailed(address proxy);
event ProxyDeployed(address indexed sender, address indexed proxyAddress, uint256 salt, address implementation);
function deployProxy(address implementation, uint256 salt, bytes memory data) external returns (address);
function verifyContract(address proxy) external view returns (address implementation);
}
lib/contracts-v2/contracts/lib/verifiable-factory/src/UUPSProxyLogic.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IProxyAuthorization} from "./IProxyAuthorization.sol";
import {IUUPSProxy} from "./IUUPSProxy.sol";
contract UUPSProxyLogic is IUUPSProxy {
/// @dev `keccak256(bytes("eip1967.proxy.implementation")) - 1`.
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/// @dev `bytes4(keccak256(bytes("ImplementationCannotBeZeroAddress()")))`.
uint256 internal constant _IMPLEMENTATION_CANNOT_BE_ZERO_ADDRESS_ERROR_SELECTOR = 0x0760838f;
/// @dev `bytes4(keccak256(bytes("AlreadyInitialized()")))`.
uint256 internal constant _ALREADY_INITIALIZED_ERROR_SELECTOR = 0x0dc149f0;
/// @dev `bytes4(keccak256(bytes("UpgradeNotAllowedInContext()")))`.
uint256 internal constant _UPGRADE_NOT_ALLOWED_IN_CONTEXT_ERROR_SELECTOR = 0x784cf700;
/// @dev `bytes4(keccak256(bytes("UnexpectedUpgrade()")))`.
uint256 internal constant _UNEXPECTED_UPGRADE_ERROR_SELECTOR = 0x2be61883;
/// @dev `bytes4(keccak256(bytes("ERC1967InvalidImplementation(address)")))`.
uint256 internal constant _ERC1967_INVALID_IMPLEMENTATION_ERROR_SELECTOR = 0x4c9c8ce3;
/// @dev `bytes4(keccak256(bytes("ERC1967NonPayable()")))`.
uint256 internal constant _ERC1967_NON_PAYABLE_ERROR_SELECTOR = 0xb398979f;
/// @dev `bytes4(keccak256(bytes("Upgraded(address)")))`.
uint256 internal constant _UPGRADED_EVENT_SELECTOR =
0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b;
address public immutable verifiableProxyFactory;
constructor() {
verifiableProxyFactory = msg.sender;
}
function initialize(address implementation, bytes calldata data) external payable {
assembly {
if eq(implementation, 0) {
mstore(0, _IMPLEMENTATION_CANNOT_BE_ZERO_ADDRESS_ERROR_SELECTOR)
revert(0x1c, 0x04)
}
if iszero(eq(sload(_IMPLEMENTATION_SLOT), 0)) {
mstore(0, _ALREADY_INITIALIZED_ERROR_SELECTOR)
revert(0x1c, 0x04)
}
if iszero(extcodesize(implementation)) {
mstore(0, _ERC1967_INVALID_IMPLEMENTATION_ERROR_SELECTOR)
mstore(0x20, implementation)
revert(0x1c, 0x24)
}
sstore(_IMPLEMENTATION_SLOT, implementation)
log2(0, 0, _UPGRADED_EVENT_SELECTOR, implementation)
let dlength := data.length
switch dlength
case 0 {
if callvalue() {
mstore(0, _ERC1967_NON_PAYABLE_ERROR_SELECTOR)
revert(0x1c, 0x04)
}
}
default {
calldatacopy(0, data.offset, dlength)
let result := delegatecall(gas(), implementation, 0, dlength, 0, 0)
if iszero(result) {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
}
}
}
function getVerifiableProxyData() public view returns (bytes32 salt, address implementation) {
assembly {
extcodecopy(address(), 0, sub(extcodesize(address()), 0x20), 0x20)
salt := mload(0)
implementation := sload(_IMPLEMENTATION_SLOT)
}
}
function upgradeToAndCall(address newImplementation, bytes calldata) external payable {
if (newImplementation == address(0)) revert ImplementationCannotBeZeroAddress();
address implementation = _implementation();
if (implementation == address(0)) revert ImplementationNotSet();
IProxyAuthorization newImpl = IProxyAuthorization(newImplementation);
if (!newImpl.canUpgradeFrom(implementation)) {
revert InvalidUpgradeTarget(implementation, newImplementation);
}
_delegateUpgrade(implementation, newImplementation);
}
function _implementation() internal view returns (address impl) {
assembly {
impl := sload(_IMPLEMENTATION_SLOT)
}
}
function _delegate(address implementation, bool checkImplementation) internal {
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
if checkImplementation {
if iszero(eq(implementation, sload(_IMPLEMENTATION_SLOT))) {
mstore(0, _UPGRADE_NOT_ALLOWED_IN_CONTEXT_ERROR_SELECTOR)
revert(0x1c, 0x04)
}
}
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
function _delegateUpgrade(address implementation, address expectedImplementation) internal {
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
if iszero(result) {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
if iszero(eq(expectedImplementation, sload(_IMPLEMENTATION_SLOT))) {
mstore(0, _UNEXPECTED_UPGRADE_ERROR_SELECTOR)
revert(0x1c, 0x04)
}
returndatacopy(0, 0, returndatasize())
return(0, returndatasize())
}
}
fallback() external payable {
_delegate(_implementation(), true);
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 1000,
"enabled": true
},
"evmVersion": "shanghai",
"remappings": [
"forge-std/=lib/contracts-v2/contracts/lib/forge-std/src/",
"@ensv2/=lib/contracts-v2/contracts/src/",
"@openzeppelin/contracts/=lib/contracts-v2/contracts/lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-v5/=lib/contracts-v2/contracts/lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/contracts-v2/contracts/lib/openzeppelin-contracts-upgradeable/contracts/",
"@ens/contracts/=lib/contracts-v2/contracts/lib/ens-contracts/contracts/",
"@ensdomains/buffer/=lib/contracts-v2/contracts/lib/buffer/",
"@ensdomains/verifiable-factory/=lib/contracts-v2/contracts/lib/verifiable-factory/src/",
"@unruggable/gateways/=lib/contracts-v2/contracts/lib/unruggable-gateways/",
"solady/=lib/contracts-v2/contracts/lib/solady/src/",
"lib/contracts-v2/contracts/lib/ens-contracts/:@openzeppelin/contracts/=lib/contracts-v2/contracts/lib/openzeppelin-contracts-v4/contracts/",
"lib/contracts-v2/contracts/lib/ens-contracts/:@openzeppelin/contracts-v5/=lib/contracts-v2/contracts/lib/openzeppelin-contracts/contracts/",
"lib/contracts-v2/contracts/lib/ens-contracts/:@ensdomains/solsha1/contracts/=lib/contracts-v2/contracts/lib/solsha1/contracts/",
"lib/contracts-v2/contracts/lib/ens-contracts/:@unruggable/gateways/=lib/contracts-v2/contracts/lib/unruggable-gateways/contracts/",
"buffer/=lib/contracts-v2/contracts/lib/buffer/contracts/",
"contracts-v2/=lib/contracts-v2/",
"ens-contracts/=lib/contracts-v2/contracts/lib/ens-contracts/contracts/",
"openzeppelin-contracts-upgradeable/=lib/contracts-v2/contracts/lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts-v4/=lib/contracts-v2/contracts/lib/openzeppelin-contracts-v4/",
"openzeppelin-contracts/=lib/contracts-v2/contracts/lib/openzeppelin-contracts/",
"optimism/=lib/contracts-v2/contracts/lib/unruggable-gateways/lib/optimism/packages/contracts-bedrock/src/",
"solsha1/=lib/contracts-v2/contracts/lib/solsha1/contracts/",
"unruggable-gateways/=lib/contracts-v2/contracts/lib/unruggable-gateways/contracts/",
"verifiable-factory/=lib/contracts-v2/contracts/lib/verifiable-factory/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.