编译器
0.8.10+commit.fc410830
文件 1 的 2:EIP173Proxy.sol
pragma solidity ^0.8.0;
import "./Proxy.sol";
interface ERC165 {
function supportsInterface(bytes4 id) external view returns (bool);
}
contract EIP173Proxy is Proxy {
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor(
address implementationAddress,
address ownerAddress,
bytes memory data
) payable {
_setImplementation(implementationAddress, data);
_setOwner(ownerAddress);
}
function owner() external view returns (address) {
return _owner();
}
function supportsInterface(bytes4 id) external view returns (bool) {
if (id == 0x01ffc9a7 || id == 0x7f5828d0) {
return true;
}
if (id == 0xFFFFFFFF) {
return false;
}
ERC165 implementation;
assembly {
implementation := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)
}
try implementation.supportsInterface(id) returns (bool support) {
return support;
} catch {
return false;
}
}
function transferOwnership(address newOwner) external onlyOwner {
_setOwner(newOwner);
}
function upgradeTo(address newImplementation) external onlyOwner {
_setImplementation(newImplementation, "");
}
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable onlyOwner {
_setImplementation(newImplementation, data);
}
modifier onlyOwner() {
require(msg.sender == _owner(), "NOT_AUTHORIZED");
_;
}
function _owner() internal view returns (address adminAddress) {
assembly {
adminAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103)
}
}
function _setOwner(address newOwner) internal {
address previousOwner = _owner();
assembly {
sstore(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103, newOwner)
}
emit OwnershipTransferred(previousOwner, newOwner);
}
}
文件 2 的 2:Proxy.sol
pragma solidity ^0.8.0;
abstract contract Proxy {
event ProxyImplementationUpdated(address indexed previousImplementation, address indexed newImplementation);
receive() external payable virtual {
revert("ETHER_REJECTED");
}
fallback() external payable {
_fallback();
}
function _fallback() internal {
assembly {
let implementationAddress := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)
calldatacopy(0x0, 0x0, calldatasize())
let success := delegatecall(gas(), implementationAddress, 0x0, calldatasize(), 0, 0)
let retSz := returndatasize()
returndatacopy(0, 0, retSz)
switch success
case 0 {
revert(0, retSz)
}
default {
return(0, retSz)
}
}
}
function _setImplementation(address newImplementation, bytes memory data) internal {
address previousImplementation;
assembly {
previousImplementation := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)
}
assembly {
sstore(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc, newImplementation)
}
emit ProxyImplementationUpdated(previousImplementation, newImplementation);
if (data.length > 0) {
(bool success, ) = newImplementation.delegatecall(data);
if (!success) {
assembly {
let returnDataSize := returndatasize()
returndatacopy(0, 0, returnDataSize)
revert(0, returnDataSize)
}
}
}
}
}
{
"compilationTarget": {
"solc_0.8/proxy/EIP173Proxy.sol": "EIP173Proxy"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 999999
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"implementationAddress","type":"address"},{"internalType":"address","name":"ownerAddress","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"stateMutability":"payable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousImplementation","type":"address"},{"indexed":true,"internalType":"address","name":"newImplementation","type":"address"}],"name":"ProxyImplementationUpdated","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"id","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]