编译器
0.6.12+commit.27d51765
文件 1 的 7:BaseMessengerWrapper.sol
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/access/Ownable.sol";
import "../interfaces/optimism/messengers/iOVM_L1CrossDomainMessenger.sol";
import "./MessengerWrapper.sol";
contract BaseMessengerWrapper is MessengerWrapper, Ownable {
iOVM_L1CrossDomainMessenger public immutable l1MessengerAddress;
address public immutable l2BridgeAddress;
uint256 public defaultL2GasLimit;
mapping (bytes4 => uint256) public l2GasLimitForSignature;
constructor(
address _l1BridgeAddress,
address _l2BridgeAddress,
iOVM_L1CrossDomainMessenger _l1MessengerAddress,
uint256 _l2ChainId,
uint256 _defaultL2GasLimit
)
public
MessengerWrapper(_l1BridgeAddress, _l2ChainId)
{
l2BridgeAddress = _l2BridgeAddress;
l1MessengerAddress = _l1MessengerAddress;
defaultL2GasLimit = _defaultL2GasLimit;
}
function sendCrossDomainMessage(bytes memory _calldata) public override onlyL1Bridge {
uint256 l2GasLimit = l2GasLimitForCalldata(_calldata);
l1MessengerAddress.sendMessage(
l2BridgeAddress,
_calldata,
uint32(l2GasLimit)
);
}
function verifySender(address l1BridgeCaller, bytes memory ) public override {
if (isRootConfirmation) return;
require(l1BridgeCaller == address(l1MessengerAddress), "BASE_MSG_WPR: Caller is not l1MessengerAddress");
require(l1MessengerAddress.xDomainMessageSender() == l2BridgeAddress, "BASE_MSG_WPR: Invalid cross-domain sender");
}
function setDefaultL2GasLimit(uint256 _l2GasLimit) external onlyOwner {
defaultL2GasLimit = _l2GasLimit;
}
function setL2GasLimitForSignature(uint256 _l2GasLimit, bytes4 signature) external onlyOwner {
l2GasLimitForSignature[signature] = _l2GasLimit;
}
function l2GasLimitForCalldata(bytes memory _calldata) private view returns (uint256) {
uint256 l2GasLimit;
if (_calldata.length >= 4) {
bytes4 functionSignature = bytes4(toUint32(_calldata, 0));
l2GasLimit = l2GasLimitForSignature[functionSignature];
}
if (l2GasLimit == 0) {
l2GasLimit = defaultL2GasLimit;
}
return l2GasLimit;
}
function toUint32(bytes memory _bytes, uint256 _start) private pure returns (uint32) {
require(_bytes.length >= _start + 4, "OVM_MSG_WPR: out of bounds");
uint32 tempUint;
assembly {
tempUint := mload(add(add(_bytes, 0x4), _start))
}
return tempUint;
}
}
文件 2 的 7:Context.sol
pragma solidity >=0.6.0 <0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
文件 3 的 7:IMessengerWrapper.sol
pragma solidity >=0.6.12 <=0.8.9;
pragma experimental ABIEncoderV2;
interface IMessengerWrapper {
function sendCrossDomainMessage(bytes memory _calldata) external;
function verifySender(address l1BridgeCaller, bytes memory _data) external;
function confirmRoots(
bytes32[] calldata rootHashes,
uint256[] calldata destinationChainIds,
uint256[] calldata totalAmounts,
uint256[] calldata rootCommittedAts
) external;
}
文件 4 的 7:MessengerWrapper.sol
pragma solidity >=0.6.12 <=0.8.9;
pragma experimental ABIEncoderV2;
import "../interfaces/IMessengerWrapper.sol";
contract IL1Bridge {
struct TransferBond {
address bonder;
uint256 createdAt;
uint256 totalAmount;
uint256 challengeStartTime;
address challenger;
bool challengeResolved;
}
uint256 public challengePeriod;
mapping(bytes32 => TransferBond) public transferBonds;
function getIsBonder(address maybeBonder) public view returns (bool) {}
function getTransferRootId(bytes32 rootHash, uint256 totalAmount) public pure returns (bytes32) {}
function confirmTransferRoot(
uint256 originChainId,
bytes32 rootHash,
uint256 destinationChainId,
uint256 totalAmount,
uint256 rootCommittedAt
)
external
{}
}
abstract contract MessengerWrapper is IMessengerWrapper {
address public immutable l1BridgeAddress;
uint256 public immutable l2ChainId;
bool public isRootConfirmation = false;
constructor(address _l1BridgeAddress, uint256 _l2ChainId) internal {
l1BridgeAddress = _l1BridgeAddress;
l2ChainId = _l2ChainId;
}
modifier onlyL1Bridge {
require(msg.sender == l1BridgeAddress, "MW: Sender must be the L1 Bridge");
_;
}
modifier rootConfirmation {
isRootConfirmation = true;
_;
isRootConfirmation = false;
}
function confirmRoots (
bytes32[] calldata rootHashes,
uint256[] calldata destinationChainIds,
uint256[] calldata totalAmounts,
uint256[] calldata rootCommittedAts
) external override rootConfirmation {
IL1Bridge l1Bridge = IL1Bridge(l1BridgeAddress);
require(l1Bridge.getIsBonder(msg.sender), "MW: Sender must be a bonder");
require(rootHashes.length == totalAmounts.length, "MW: rootHashes and totalAmounts must be the same length");
uint256 challengePeriod = l1Bridge.challengePeriod();
for (uint256 i = 0; i < rootHashes.length; i++) {
bool canConfirm = canConfirmRoot(l1Bridge, rootHashes[i], totalAmounts[i], challengePeriod);
require(canConfirm, "MW: Root cannot be confirmed");
l1Bridge.confirmTransferRoot(
l2ChainId,
rootHashes[i],
destinationChainIds[i],
totalAmounts[i],
rootCommittedAts[i]
);
}
}
function canConfirmRoot (IL1Bridge l1Bridge, bytes32 rootHash, uint256 totalAmount, uint256 challengePeriod) public view returns (bool) {
bytes32 transferRootId = l1Bridge.getTransferRootId(rootHash, totalAmount);
(,uint256 createdAt,,uint256 challengeStartTime,,) = l1Bridge.transferBonds(transferRootId);
uint256 timeSinceBondCreation = block.timestamp - createdAt;
if (
createdAt != 0 &&
challengeStartTime == 0 &&
timeSinceBondCreation > challengePeriod
) {
return true;
}
return false;
}
}
文件 5 的 7:Ownable.sol
pragma solidity >=0.6.0 <0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
文件 6 的 7:iOVM_BaseCrossDomainMessenger.sol
pragma solidity >0.5.0 <0.8.0;
pragma experimental ABIEncoderV2;
interface iOVM_BaseCrossDomainMessenger {
event SentMessage(bytes message);
event RelayedMessage(bytes32 msgHash);
function xDomainMessageSender() external view returns (address);
function sendMessage(
address _target,
bytes calldata _message,
uint32 _gasLimit
) external;
function deposit(
address _depositor,
uint256 _amount,
bool _send
) external;
}
文件 7 的 7:iOVM_L1CrossDomainMessenger.sol
pragma solidity >0.5.0 <0.8.0;
pragma experimental ABIEncoderV2;
import { iOVM_BaseCrossDomainMessenger } from "./iOVM_BaseCrossDomainMessenger.sol";
interface iOVM_L1CrossDomainMessenger is iOVM_BaseCrossDomainMessenger {}
{
"compilationTarget": {
"contracts/wrappers/BaseMessengerWrapper.sol": "BaseMessengerWrapper"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 50000
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_l1BridgeAddress","type":"address"},{"internalType":"address","name":"_l2BridgeAddress","type":"address"},{"internalType":"contract iOVM_L1CrossDomainMessenger","name":"_l1MessengerAddress","type":"address"},{"internalType":"uint256","name":"_l2ChainId","type":"uint256"},{"internalType":"uint256","name":"_defaultL2GasLimit","type":"uint256"}],"stateMutability":"nonpayable","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"},{"inputs":[{"internalType":"contract IL1Bridge","name":"l1Bridge","type":"address"},{"internalType":"bytes32","name":"rootHash","type":"bytes32"},{"internalType":"uint256","name":"totalAmount","type":"uint256"},{"internalType":"uint256","name":"challengePeriod","type":"uint256"}],"name":"canConfirmRoot","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32[]","name":"rootHashes","type":"bytes32[]"},{"internalType":"uint256[]","name":"destinationChainIds","type":"uint256[]"},{"internalType":"uint256[]","name":"totalAmounts","type":"uint256[]"},{"internalType":"uint256[]","name":"rootCommittedAts","type":"uint256[]"}],"name":"confirmRoots","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"defaultL2GasLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isRootConfirmation","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"l1BridgeAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"l1MessengerAddress","outputs":[{"internalType":"contract iOVM_L1CrossDomainMessenger","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"l2BridgeAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"l2ChainId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"name":"l2GasLimitForSignature","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"_calldata","type":"bytes"}],"name":"sendCrossDomainMessage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_l2GasLimit","type":"uint256"}],"name":"setDefaultL2GasLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_l2GasLimit","type":"uint256"},{"internalType":"bytes4","name":"signature","type":"bytes4"}],"name":"setL2GasLimitForSignature","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"l1BridgeCaller","type":"address"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"verifySender","outputs":[],"stateMutability":"nonpayable","type":"function"}]