编译器
0.6.12+commit.27d51765
文件 1 的 9:AbstractBridge.sol
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
import { IBridgehub, L2TransactionRequestDirect } from './system/IBridgehub.sol';
import { Ownable } from '@openzeppelin/contracts/access/Ownable.sol';
import { ReentrancyGuard } from '@openzeppelin/contracts/utils/ReentrancyGuard.sol';
import { Pausable } from '@openzeppelin/contracts/utils/Pausable.sol';
contract AbstractBridge is Ownable, ReentrancyGuard, Pausable {
uint256 constant FEE_DECIMALS = 1e4;
IBridgehub public bridgehub;
uint256 public operatorFee;
address public feeTo;
struct ZkBridgeHubConfig {
uint256 chainId;
bytes l2Calldata;
uint256 l2GasLimit;
uint256 l2GasPrice;
uint256 l2GasPerPubdataByteLimit;
bytes[] factoryDeps;
}
ZkBridgeHubConfig public bridgeConfig;
constructor(address _bridgehub) public Ownable() {
bridgehub = IBridgehub(_bridgehub);
}
function setOperatorFee(uint256 _fee) public onlyOwner {
operatorFee = _fee;
}
function setFeeTo(address _feeTo) public onlyOwner {
feeTo = _feeTo;
}
function setBridgehub(address _bridgehub) public onlyOwner {
bridgehub = IBridgehub(_bridgehub);
}
function setBridgeConfig(ZkBridgeHubConfig memory _bridgeConfig) public onlyOwner {
bridgeConfig = _bridgeConfig;
}
function _handleDepositEth(address _to) internal whenNotPaused {
require(address(bridgehub) != address(0), 'Bridge address unset');
uint256 operatorShare = (msg.value * operatorFee) / FEE_DECIMALS;
uint256 l1Value = msg.value - operatorShare;
uint256 gasFee = bridgehub.l2TransactionBaseCost(
bridgeConfig.chainId,
bridgeConfig.l2GasPrice,
bridgeConfig.l2GasLimit,
bridgeConfig.l2GasPerPubdataByteLimit
);
uint256 l2Value = l1Value - ((gasFee * 11000) / FEE_DECIMALS);
bridgehub.requestL2TransactionDirect{ value: l1Value }(
L2TransactionRequestDirect(
bridgeConfig.chainId,
l1Value,
_to,
l2Value,
bridgeConfig.l2Calldata,
bridgeConfig.l2GasLimit,
bridgeConfig.l2GasPerPubdataByteLimit,
bridgeConfig.factoryDeps,
_to
)
);
if (operatorShare > 0) {
payable(feeTo).transfer(operatorShare);
}
}
function bridgeEth(address _to) external payable nonReentrant {
_handleDepositEth(_to);
}
receive() external payable nonReentrant {
_handleDepositEth(msg.sender);
}
}
文件 2 的 9: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 的 9:IBridgehub.sol
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
import {IL1SharedBridge} from "./IL1SharedBridge.sol";
import {L2Message, L2Log, TxStatus} from "./Messaging.sol";
struct L2TransactionRequestDirect {
uint256 chainId;
uint256 mintValue;
address l2Contract;
uint256 l2Value;
bytes l2Calldata;
uint256 l2GasLimit;
uint256 l2GasPerPubdataByteLimit;
bytes[] factoryDeps;
address refundRecipient;
}
struct L2TransactionRequestTwoBridgesOuter {
uint256 chainId;
uint256 mintValue;
uint256 l2Value;
uint256 l2GasLimit;
uint256 l2GasPerPubdataByteLimit;
address refundRecipient;
address secondBridgeAddress;
uint256 secondBridgeValue;
bytes secondBridgeCalldata;
}
struct L2TransactionRequestTwoBridgesInner {
bytes32 magicValue;
address l2Contract;
bytes l2Calldata;
bytes[] factoryDeps;
bytes32 txDataHash;
}
interface IBridgehub {
event NewPendingAdmin(address indexed oldPendingAdmin, address indexed newPendingAdmin);
event NewAdmin(address indexed oldAdmin, address indexed newAdmin);
function setPendingAdmin(address _newPendingAdmin) external;
function acceptAdmin() external;
function stateTransitionManagerIsRegistered(address _stateTransitionManager) external view returns (bool);
function stateTransitionManager(uint256 _chainId) external view returns (address);
function tokenIsRegistered(address _baseToken) external view returns (bool);
function baseToken(uint256 _chainId) external view returns (address);
function sharedBridge() external view returns (IL1SharedBridge);
function getHyperchain(uint256 _chainId) external view returns (address);
function proveL2MessageInclusion(
uint256 _chainId,
uint256 _batchNumber,
uint256 _index,
L2Message calldata _message,
bytes32[] calldata _proof
) external view returns (bool);
function proveL2LogInclusion(
uint256 _chainId,
uint256 _batchNumber,
uint256 _index,
L2Log memory _log,
bytes32[] calldata _proof
) external view returns (bool);
function proveL1ToL2TransactionStatus(
uint256 _chainId,
bytes32 _l2TxHash,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBatch,
bytes32[] calldata _merkleProof,
TxStatus _status
) external view returns (bool);
function requestL2TransactionDirect(
L2TransactionRequestDirect calldata _request
) external payable returns (bytes32 canonicalTxHash);
function requestL2TransactionTwoBridges(
L2TransactionRequestTwoBridgesOuter calldata _request
) external payable returns (bytes32 canonicalTxHash);
function l2TransactionBaseCost(
uint256 _chainId,
uint256 _gasPrice,
uint256 _l2GasLimit,
uint256 _l2GasPerPubdataByteLimit
) external view returns (uint256);
function createNewChain(
uint256 _chainId,
address _stateTransitionManager,
address _baseToken,
uint256 _salt,
address _admin,
bytes calldata _initData
) external returns (uint256 chainId);
function addStateTransitionManager(address _stateTransitionManager) external;
function removeStateTransitionManager(address _stateTransitionManager) external;
function addToken(address _token) external;
function setSharedBridge(address _sharedBridge) external;
event NewChain(uint256 indexed chainId, address stateTransitionManager, address indexed chainGovernance);
}
文件 4 的 9:IL1ERC20Bridge.sol
pragma solidity ^0.6.12;
import {IL1SharedBridge} from "./IL1SharedBridge.sol";
interface IL1ERC20Bridge {
event DepositInitiated(
bytes32 indexed l2DepositTxHash,
address indexed from,
address indexed to,
address l1Token,
uint256 amount
);
event WithdrawalFinalized(address indexed to, address indexed l1Token, uint256 amount);
event ClaimedFailedDeposit(address indexed to, address indexed l1Token, uint256 amount);
function isWithdrawalFinalized(uint256 _l2BatchNumber, uint256 _l2MessageIndex) external view returns (bool);
function deposit(
address _l2Receiver,
address _l1Token,
uint256 _amount,
uint256 _l2TxGasLimit,
uint256 _l2TxGasPerPubdataByte,
address _refundRecipient
) external payable returns (bytes32 txHash);
function deposit(
address _l2Receiver,
address _l1Token,
uint256 _amount,
uint256 _l2TxGasLimit,
uint256 _l2TxGasPerPubdataByte
) external payable returns (bytes32 txHash);
function claimFailedDeposit(
address _depositSender,
address _l1Token,
bytes32 _l2TxHash,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBatch,
bytes32[] calldata _merkleProof
) external;
function finalizeWithdrawal(
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBatch,
bytes calldata _message,
bytes32[] calldata _merkleProof
) external;
function l2TokenAddress(address _l1Token) external view returns (address);
function SHARED_BRIDGE() external view returns (IL1SharedBridge);
function l2TokenBeacon() external view returns (address);
function l2Bridge() external view returns (address);
function depositAmount(
address _account,
address _l1Token,
bytes32 _depositL2TxHash
) external returns (uint256 amount);
function transferTokenToSharedBridge(address _token) external;
}
文件 5 的 9:IL1SharedBridge.sol
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
import {L2TransactionRequestTwoBridgesInner} from "./IBridgehub.sol";
import {IBridgehub} from "./IBridgehub.sol";
import {IL1ERC20Bridge} from "./IL1ERC20Bridge.sol";
interface IL1SharedBridge {
event NewPendingAdmin(address indexed oldPendingAdmin, address indexed newPendingAdmin);
event NewAdmin(address indexed oldAdmin, address indexed newAdmin);
event LegacyDepositInitiated(
uint256 indexed chainId,
bytes32 indexed l2DepositTxHash,
address indexed from,
address to,
address l1Token,
uint256 amount
);
event BridgehubDepositInitiated(
uint256 indexed chainId,
bytes32 indexed txDataHash,
address indexed from,
address to,
address l1Token,
uint256 amount
);
event BridgehubDepositBaseTokenInitiated(
uint256 indexed chainId,
address indexed from,
address l1Token,
uint256 amount
);
event BridgehubDepositFinalized(
uint256 indexed chainId,
bytes32 indexed txDataHash,
bytes32 indexed l2DepositTxHash
);
event WithdrawalFinalizedSharedBridge(
uint256 indexed chainId,
address indexed to,
address indexed l1Token,
uint256 amount
);
event ClaimedFailedDepositSharedBridge(
uint256 indexed chainId,
address indexed to,
address indexed l1Token,
uint256 amount
);
function isWithdrawalFinalized(
uint256 _chainId,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex
) external view returns (bool);
function depositLegacyErc20Bridge(
address _msgSender,
address _l2Receiver,
address _l1Token,
uint256 _amount,
uint256 _l2TxGasLimit,
uint256 _l2TxGasPerPubdataByte,
address _refundRecipient
) external payable returns (bytes32 txHash);
function claimFailedDepositLegacyErc20Bridge(
address _depositSender,
address _l1Token,
uint256 _amount,
bytes32 _l2TxHash,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBatch,
bytes32[] calldata _merkleProof
) external;
function claimFailedDeposit(
uint256 _chainId,
address _depositSender,
address _l1Token,
uint256 _amount,
bytes32 _l2TxHash,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBatch,
bytes32[] calldata _merkleProof
) external;
function finalizeWithdrawalLegacyErc20Bridge(
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBatch,
bytes calldata _message,
bytes32[] calldata _merkleProof
) external returns (address l1Receiver, address l1Token, uint256 amount);
function finalizeWithdrawal(
uint256 _chainId,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBatch,
bytes calldata _message,
bytes32[] calldata _merkleProof
) external;
function setEraPostDiamondUpgradeFirstBatch(uint256 _eraPostDiamondUpgradeFirstBatch) external;
function setEraPostLegacyBridgeUpgradeFirstBatch(uint256 _eraPostLegacyBridgeUpgradeFirstBatch) external;
function setEraLegacyBridgeLastDepositTime(
uint256 _eraLegacyBridgeLastDepositBatch,
uint256 _eraLegacyBridgeLastDepositTxNumber
) external;
function L1_WETH_TOKEN() external view returns (address);
function BRIDGE_HUB() external view returns (IBridgehub);
function legacyBridge() external view returns (IL1ERC20Bridge);
function l2BridgeAddress(uint256 _chainId) external view returns (address);
function depositHappened(uint256 _chainId, bytes32 _l2TxHash) external view returns (bytes32);
function bridgehubDeposit(
uint256 _chainId,
address _prevMsgSender,
uint256 _l2Value,
bytes calldata _data
) external payable returns (L2TransactionRequestTwoBridgesInner memory request);
function bridgehubDepositBaseToken(
uint256 _chainId,
address _prevMsgSender,
address _l1Token,
uint256 _amount
) external payable;
function bridgehubConfirmL2Transaction(uint256 _chainId, bytes32 _txDataHash, bytes32 _txHash) external;
function receiveEth(uint256 _chainId) external payable;
function setPendingAdmin(address _newPendingAdmin) external;
function acceptAdmin() external;
}
文件 6 的 9:Messaging.sol
pragma solidity ^0.6.12;
enum TxStatus {
Failure,
Success
}
struct L2Log {
uint8 l2ShardId;
bool isService;
uint16 txNumberInBatch;
address sender;
bytes32 key;
bytes32 value;
}
struct L2Message {
uint16 txNumberInBatch;
address sender;
bytes data;
}
struct WritePriorityOpParams {
uint256 txId;
uint256 l2GasPrice;
uint64 expirationTimestamp;
BridgehubL2TransactionRequest request;
}
struct L2CanonicalTransaction {
uint256 txType;
uint256 from;
uint256 to;
uint256 gasLimit;
uint256 gasPerPubdataByteLimit;
uint256 maxFeePerGas;
uint256 maxPriorityFeePerGas;
uint256 paymaster;
uint256 nonce;
uint256 value;
uint256[4] reserved;
bytes data;
bytes signature;
uint256[] factoryDeps;
bytes paymasterInput;
bytes reservedDynamic;
}
struct BridgehubL2TransactionRequest {
address sender;
address contractL2;
uint256 mintValue;
uint256 l2Value;
bytes l2Calldata;
uint256 l2GasLimit;
uint256 l2GasPerPubdataByteLimit;
bytes[] factoryDeps;
address refundRecipient;
}
文件 7 的 9: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;
}
}
文件 8 的 9:Pausable.sol
pragma solidity >=0.6.0 <0.8.0;
import "./Context.sol";
abstract contract Pausable is Context {
event Paused(address account);
event Unpaused(address account);
bool private _paused;
constructor () internal {
_paused = false;
}
function paused() public view virtual returns (bool) {
return _paused;
}
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_;
}
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_;
}
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
文件 9 的 9:ReentrancyGuard.sol
pragma solidity >=0.6.0 <0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor () internal {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
{
"compilationTarget": {
"contracts/AbstractBridge.sol": "AbstractBridge"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 100000
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_bridgehub","type":"address"}],"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"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"bridgeConfig","outputs":[{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"bytes","name":"l2Calldata","type":"bytes"},{"internalType":"uint256","name":"l2GasLimit","type":"uint256"},{"internalType":"uint256","name":"l2GasPrice","type":"uint256"},{"internalType":"uint256","name":"l2GasPerPubdataByteLimit","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"}],"name":"bridgeEth","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"bridgehub","outputs":[{"internalType":"contract IBridgehub","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeTo","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operatorFee","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":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"bytes","name":"l2Calldata","type":"bytes"},{"internalType":"uint256","name":"l2GasLimit","type":"uint256"},{"internalType":"uint256","name":"l2GasPrice","type":"uint256"},{"internalType":"uint256","name":"l2GasPerPubdataByteLimit","type":"uint256"},{"internalType":"bytes[]","name":"factoryDeps","type":"bytes[]"}],"internalType":"struct AbstractBridge.ZkBridgeHubConfig","name":"_bridgeConfig","type":"tuple"}],"name":"setBridgeConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_bridgehub","type":"address"}],"name":"setBridgehub","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeTo","type":"address"}],"name":"setFeeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_fee","type":"uint256"}],"name":"setOperatorFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]