编译器
0.8.19+commit.7dd6d404
文件 1 的 31:AccessControl.sol
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(account),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
文件 2 的 31:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 3 的 31:ECDSA.sol
pragma solidity ^0.8.0;
import "../Strings.sol";
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return;
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
assembly {
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);
}
}
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32")
mstore(0x1c, hash)
message := keccak256(0x00, 0x3c)
}
}
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
assembly {
let ptr := mload(0x40)
mstore(ptr, "\x19\x01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
data := keccak256(ptr, 0x42)
}
}
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x00", validator, data));
}
}
文件 4 的 31:ERC165.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 5 的 31:Errors.sol
pragma solidity ^0.8.0;
library Errors {
string internal constant INVALID_ARGUMENT = "LZ10000";
string internal constant ONLY_REGISTERED = "LZ10001";
string internal constant ONLY_REGISTERED_OR_DEFAULT = "LZ10002";
string internal constant INVALID_AMOUNT = "LZ10003";
string internal constant INVALID_NONCE = "LZ10004";
string internal constant SAME_VALUE = "LZ10005";
string internal constant UNSORTED = "LZ10006";
string internal constant INVALID_VERSION = "LZ10007";
string internal constant INVALID_EID = "LZ10008";
string internal constant INVALID_SIZE = "LZ10009";
string internal constant ONLY_NON_DEFAULT = "LZ10010";
string internal constant INVALID_VERIFIERS = "LZ10011";
string internal constant INVALID_WORKER_ID = "LZ10012";
string internal constant DUPLICATED_OPTION = "LZ10013";
string internal constant INVALID_LEGACY_OPTION = "LZ10014";
string internal constant INVALID_VERIFIER_OPTION = "LZ10015";
string internal constant INVALID_WORKER_OPTIONS = "LZ10016";
string internal constant INVALID_EXECUTOR_OPTION = "LZ10017";
string internal constant INVALID_ADDRESS = "LZ10018";
string internal constant OUT_OF_RANGE = "LZ20000";
string internal constant INVALID_STATE = "LZ30000";
string internal constant SEND_REENTRANCY = "LZ30001";
string internal constant RECEIVE_REENTRANCY = "LZ30002";
string internal constant COMPOSE_REENTRANCY = "LZ30003";
string internal constant PERMISSION_DENIED = "LZ50000";
string internal constant NOT_FOUND = "LZ60000";
string internal constant ALREADY_EXISTS = "LZ80000";
string internal constant NOT_IMPLEMENTED = "LZC0000";
string internal constant UNSUPPORTED_INTERFACE = "LZC0001";
string internal constant UNSUPPORTED_OPTION_TYPE = "LZC0002";
string internal constant UNAVAILABLE = "LZD0000";
string internal constant NATIVE_COIN_UNAVAILABLE = "LZD0001";
string internal constant TOKEN_UNAVAILABLE = "LZD0002";
string internal constant DEFAULT_LIBRARY_UNAVAILABLE = "LZD0003";
string internal constant VERIFIERS_UNAVAILABLE = "LZD0004";
}
文件 6 的 31:IAccessControl.sol
pragma solidity ^0.8.0;
interface IAccessControl {
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
function hasRole(bytes32 role, address account) external view returns (bool);
function getRoleAdmin(bytes32 role) external view returns (bytes32);
function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
function renounceRole(bytes32 role, address account) external;
}
文件 7 的 31:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 8 的 31:ILayerZeroEndpointV2.sol
pragma solidity >=0.8.0;
import "./IMessageLibManager.sol";
import "./IMessagingComposer.sol";
import "./IMessagingChannel.sol";
import "./IMessagingContext.sol";
import {Origin} from "../MessagingStructs.sol";
struct MessagingParams {
uint32 dstEid;
bytes32 receiver;
bytes message;
bytes options;
}
struct MessagingReceipt {
bytes32 guid;
uint64 nonce;
MessagingFee fee;
}
struct MessagingFee {
uint nativeFee;
uint lzTokenFee;
}
interface ILayerZeroEndpointV2 is IMessageLibManager, IMessagingComposer, IMessagingChannel, IMessagingContext {
event PacketSent(bytes encodedPayload, bytes options, address sendLibrary);
event PacketDelivered(Origin origin, address receiver, bytes32 payloadHash);
event PacketReceived(Origin origin, address receiver);
event LzReceiveFailed(Origin origin, address receiver, bytes reason);
event LayerZeroTokenSet(address token);
function quote(
address _sender,
uint32 _dstEid,
bytes calldata _message,
bool _payInLzToken,
bytes calldata _options
) external view returns (MessagingFee memory);
function send(
MessagingParams calldata _params,
uint _lzTokenFee,
address payable _refundAddress
) external payable returns (MessagingReceipt memory);
function sendWithAlt(
MessagingParams calldata _params,
uint _lzTokenFee,
uint _altTokenFee
) external returns (MessagingReceipt memory);
function deliver(Origin calldata _origin, address _receiver, bytes32 _payloadHash) external;
function deliverable(Origin calldata _origin, address _receiveLib, address _receiver) external view returns (bool);
function lzReceive(
Origin calldata _origin,
address _receiver,
bytes32 _guid,
bytes calldata _message,
bytes calldata _extraData
) external payable returns (bool, bytes memory);
function clear(Origin calldata _origin, bytes32 _guid, bytes calldata _message) external;
function setLayerZeroToken(address _layerZeroToken) external;
function layerZeroToken() external view returns (address);
function altFeeToken() external view returns (address);
}
文件 9 的 31:ILayerZeroExecutor.sol
pragma solidity >=0.8.0;
interface ILayerZeroExecutor {
function assignJob(
uint32 _dstEid,
address _sender,
uint _calldataSize,
bytes calldata _options
) external payable returns (uint price);
function getFee(
uint32 _dstEid,
address _sender,
uint _calldataSize,
bytes calldata _options
) external view returns (uint price);
}
文件 10 的 31:ILayerZeroTreasury.sol
pragma solidity >=0.8.0;
interface ILayerZeroTreasury {
function getFee(address _sender, uint32 _eid, uint _totalFee, bool _payInLzToken) external view returns (uint);
}
文件 11 的 31:ILayerZeroUltraLightNodeV2.sol
pragma solidity >=0.8.0;
interface ILayerZeroUltraLightNodeV2 {
function validateTransactionProof(
uint16 _srcChainId,
address _dstAddress,
uint _gasLimit,
bytes32 _lookupHash,
bytes32 _blockData,
bytes calldata _transactionProof
) external;
function updateHash(uint16 _srcChainId, bytes32 _lookupHash, uint _confirmations, bytes32 _blockData) external;
function withdrawNative(address payable _to, uint _amount) external;
function withdrawZRO(address _to, uint _amount) external;
function getAppConfig(
uint16 _remoteChainId,
address _userApplicationAddress
) external view returns (ApplicationConfiguration memory);
function accruedNativeFee(address _address) external view returns (uint);
struct ApplicationConfiguration {
uint16 inboundProofLibraryVersion;
uint64 inboundBlockConfirmations;
address relayer;
uint16 outboundProofType;
uint64 outboundBlockConfirmations;
address oracle;
}
event HashReceived(
uint16 indexed srcChainId,
address indexed oracle,
bytes32 lookupHash,
bytes32 blockData,
uint confirmations
);
event RelayerParams(bytes adapterParams, uint16 outboundProofType);
event Packet(bytes payload);
event InvalidDst(
uint16 indexed srcChainId,
bytes srcAddress,
address indexed dstAddress,
uint64 nonce,
bytes32 payloadHash
);
event PacketReceived(
uint16 indexed srcChainId,
bytes srcAddress,
address indexed dstAddress,
uint64 nonce,
bytes32 payloadHash
);
event AppConfigUpdated(address indexed userApplication, uint indexed configType, bytes newConfig);
event AddInboundProofLibraryForChain(uint16 indexed chainId, address lib);
event EnableSupportedOutboundProof(uint16 indexed chainId, uint16 proofType);
event SetChainAddressSize(uint16 indexed chainId, uint size);
event SetDefaultConfigForChainId(
uint16 indexed chainId,
uint16 inboundProofLib,
uint64 inboundBlockConfirm,
address relayer,
uint16 outboundProofType,
uint64 outboundBlockConfirm,
address oracle
);
event SetDefaultAdapterParamsForChainId(uint16 indexed chainId, uint16 indexed proofType, bytes adapterParams);
event SetLayerZeroToken(address indexed tokenAddress);
event SetRemoteUln(uint16 indexed chainId, bytes32 uln);
event SetTreasury(address indexed treasuryAddress);
event WithdrawZRO(address indexed msgSender, address indexed to, uint amount);
event WithdrawNative(address indexed msgSender, address indexed to, uint amount);
}
文件 12 的 31:ILayerZeroVerifier.sol
pragma solidity >=0.8.0;
interface ILayerZeroVerifier {
struct AssignJobParam {
uint32 dstEid;
bytes packetHeader;
bytes32 payloadHash;
uint64 confirmations;
address sender;
}
function assignJob(AssignJobParam calldata _param, bytes calldata _options) external payable returns (uint fee);
function getFee(
uint32 _dstEid,
uint64 _confirmations,
address _sender,
bytes calldata _options
) external view returns (uint fee);
}
文件 13 的 31:IMessageLib.sol
pragma solidity >=0.8.0;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {MessagingFee, SetConfigParam} from "./ILayerZeroEndpointV2.sol";
import {Packet, PacketForQuote} from "../MessagingStructs.sol";
interface IMessageLib is IERC165 {
function send(
Packet calldata _packet,
bytes calldata _options,
bool _payInLzToken
) external returns (MessagingFee memory, bytes memory encodedPacket);
function quote(
PacketForQuote calldata _packet,
bool _payInLzToken,
bytes calldata _options
) external view returns (MessagingFee memory);
function setTreasury(address _treasury) external;
function setConfig(address _oapp, uint32 _eid, SetConfigParam[] calldata _config) external;
function snapshotConfig(uint32[] calldata _eids, address _oapp) external;
function resetConfig(uint32[] calldata _eids, address _oapp) external;
function getConfig(
uint32 _eid,
address _oapp,
uint32 _configType
) external view returns (bytes memory config, bool isDefault);
function getDefaultConfig(uint32 _eid, uint32 _configType) external view returns (bytes memory);
function isSupportedEid(uint32 _eid) external view returns (bool);
function withdrawFee(address _to, uint _amount) external;
function withdrawLzTokenFee(address _lzToken, address _to, uint _amount) external;
function version() external view returns (uint64 major, uint8 minor, uint8 endpointVersion);
}
文件 14 的 31:IMessageLibManager.sol
pragma solidity >=0.8.0;
struct SetConfigParam {
uint32 configType;
bytes config;
}
interface IMessageLibManager {
struct Timeout {
address lib;
uint expiry;
}
event LibraryRegistered(address newLib);
event DefaultSendLibrarySet(uint32 eid, address newLib);
event DefaultReceiveLibrarySet(uint32 eid, address oldLib, address newLib);
event DefaultReceiveLibraryTimeoutSet(uint32 eid, address oldLib, uint expiry);
event SendLibrarySet(address sender, uint32 eid, address newLib);
event ReceiveLibrarySet(address receiver, uint32 eid, address oldLib, address newLib);
event ReceiveLibraryTimoutSet(address receiver, uint32 eid, address oldLib, uint timeout);
function registerLibrary(address _lib) external;
function isRegisteredLibrary(address _lib) external view returns (bool);
function getRegisteredLibraries() external view returns (address[] memory);
function setDefaultSendLibrary(uint32 _eid, address _newLib) external;
function defaultSendLibrary(uint32 _eid) external view returns (address);
function setDefaultReceiveLibrary(uint32 _eid, address _newLib, uint _timeout) external;
function defaultReceiveLibrary(uint32 _eid) external view returns (address);
function setDefaultReceiveLibraryTimeout(uint32 _eid, address _lib, uint _expiry) external;
function defaultReceiveLibraryTimeout(uint32 _eid) external view returns (address lib, uint expiry);
function defaultConfig(address _lib, uint32 _eid, uint32 _configType) external view returns (bytes memory);
function isSupportedEid(uint32 _eid) external view returns (bool);
function setSendLibrary(uint32 _eid, address _newLib) external;
function getSendLibrary(address _sender, uint32 _eid) external view returns (address lib);
function isDefaultSendLibrary(address _sender, uint32 _eid) external view returns (bool);
function setReceiveLibrary(uint32 _eid, address _newLib, uint _gracePeriod) external;
function getReceiveLibrary(address _receiver, uint32 _eid) external view returns (address lib, bool isDefault);
function setReceiveLibraryTimeout(uint32 _eid, address _lib, uint _gracePeriod) external;
function receiveLibraryTimeout(address _receiver, uint32 _eid) external view returns (address lib, uint expiry);
function setConfig(address _lib, uint32 _eid, SetConfigParam[] calldata _params) external;
function getConfig(
address _oapp,
address _lib,
uint32 _eid,
uint32 _configType
) external view returns (bytes memory config, bool isDefault);
function snapshotConfig(address _lib, uint32[] calldata _eids) external;
function resetConfig(address _lib, uint32[] calldata _eids) external;
}
文件 15 的 31:IMessagingChannel.sol
pragma solidity >=0.8.0;
interface IMessagingChannel {
event InboundNonceSkipped(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce);
function eid() external view returns (uint32);
function skip(uint32 _srcEid, bytes32 _sender, uint64 _nonce) external;
function nextGuid(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (bytes32);
function inboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);
function outboundNonce(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (uint64);
function inboundPayloadHash(
address _receiver,
uint32 _srcEid,
bytes32 _sender,
uint64 _nonce
) external view returns (bytes32);
function hasPayloadHash(
address _receiver,
uint32 _srcEid,
bytes32 _sender,
uint64 _nonce
) external view returns (bool);
}
文件 16 的 31:IMessagingComposer.sol
pragma solidity >=0.8.0;
interface IMessagingComposer {
event ComposedMessageDelivered(address receiver, address composer, bytes32 guid, bytes message);
event ComposedMessageReceived(address receiver, address composer, bytes32 guid);
event LzComposeFailed(address receiver, address composer, bytes32 guid, bytes reason);
function deliverComposedMessage(address _composer, bytes32 _guid, bytes calldata _message) external;
function lzCompose(
address _receiver,
address _composer,
bytes32 _guid,
bytes calldata _message,
bytes calldata _extraData
) external payable returns (bool, bytes memory);
}
文件 17 的 31:IMessagingContext.sol
pragma solidity >=0.8.0;
interface IMessagingContext {
function isSendingMessage() external view returns (bool);
function getSendContext() external view returns (uint32, address);
}
文件 18 的 31:IUltraLightNode.sol
pragma solidity >=0.8.0;
import {DeliveryState} from "../../MessageLibBase.sol";
interface IUltraLightNode {
function verify(bytes calldata _packetHeader, bytes32 _payloadHash, uint64 _confirmations) external;
function deliver(bytes calldata _packetHeader, bytes32 _payloadHash) external;
function deliverable(bytes calldata _packetHeader, bytes32 _payloadHash) external view returns (DeliveryState);
}
文件 19 的 31:IVerifier.sol
pragma solidity >=0.8.0;
import "../../interfaces/IWorker.sol";
import "./ILayerZeroVerifier.sol";
interface IVerifier is IWorker, ILayerZeroVerifier {
struct DstConfigParam {
uint32 dstEid;
uint64 gas;
uint16 multiplierBps;
uint128 floorMarginUSD;
}
struct DstConfig {
uint64 gas;
uint16 multiplierBps;
uint128 floorMarginUSD;
}
event SetDstConfig(DstConfigParam[] params);
function dstConfig(uint32 _dstEid) external view returns (uint64, uint16, uint128);
}
文件 20 的 31:IVerifierFeeLib.sol
pragma solidity >=0.8.0;
import "./IVerifier.sol";
interface IVerifierFeeLib {
struct FeeParams {
address priceFeed;
uint32 dstEid;
uint64 confirmations;
address sender;
uint64 quorum;
uint16 defaultMultiplierBps;
}
function getFeeOnSend(
FeeParams memory _params,
IVerifier.DstConfig memory _dstConfig,
bytes memory _options
) external payable returns (uint fee);
function getFee(
FeeParams calldata _params,
IVerifier.DstConfig calldata _dstConfig,
bytes calldata _options
) external view returns (uint fee);
}
文件 21 的 31:IWorker.sol
pragma solidity >=0.8.0;
interface IWorker {
event SetWorkerLib(address workerLib);
event SetPriceFeed(address priceFeed);
event SetDefaultMultiplierBps(uint16 multiplierBps);
event Withdraw(address lib, address to, uint amount);
function setPriceFeed(address _priceFeed) external;
function priceFeed() external view returns (address);
function setDefaultMultiplierBps(uint16 _multiplierBps) external;
function defaultMultiplierBps() external view returns (uint16);
function withdrawFee(address _lib, address _to, uint _amount) external;
}
文件 22 的 31:Math.sol
pragma solidity ^0.8.0;
library Math {
enum Rounding {
Down,
Up,
Zero
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a & b) + (a ^ b) / 2;
}
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
return a == 0 ? 0 : (a - 1) / b + 1;
}
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
uint256 prod0;
uint256 prod1;
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
return prod0 / denominator;
}
require(denominator > prod1, "Math: mulDiv overflow");
uint256 remainder;
assembly {
remainder := mulmod(x, y, denominator)
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
uint256 twos = denominator & (~denominator + 1);
assembly {
denominator := div(denominator, twos)
prod0 := div(prod0, twos)
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
uint256 inverse = (3 * denominator) ^ 2;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
result = prod0 * inverse;
return result;
}
}
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 result = 1 << (log2(a) >> 1);
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
文件 23 的 31:MessageLibBase.sol
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/Errors.sol";
import "./interfaces/ILayerZeroExecutor.sol";
import "./interfaces/ILayerZeroTreasury.sol";
struct WorkerOptions {
uint8 workerId;
bytes options;
}
enum DeliveryState {
Signing,
Deliverable,
Delivered,
Waiting
}
abstract contract MessageLibBase is Ownable {
address internal immutable endpoint;
uint32 internal immutable localEid;
uint internal immutable treasuryGasCap;
address public treasury;
mapping(address worker => uint) public fees;
event ExecutorFeePaid(address executor, uint fee);
event TreasurySet(address treasury);
modifier onlyEndpoint() {
require(endpoint == msg.sender, Errors.PERMISSION_DENIED);
_;
}
constructor(address _endpoint, uint32 _localEid, uint _treasuryGasCap) {
endpoint = _endpoint;
localEid = _localEid;
treasuryGasCap = _treasuryGasCap;
}
function _assertMessageSize(uint _actual, uint _max) internal pure {
require(_actual <= _max, Errors.INVALID_SIZE);
}
function _sendToExecutor(
address _executor,
uint32 _dstEid,
address _sender,
uint _msgSize,
bytes memory _executorOptions
) internal returns (uint executorFee) {
executorFee = ILayerZeroExecutor(_executor).assignJob(_dstEid, _sender, _msgSize, _executorOptions);
if (executorFee > 0) {
fees[_executor] += executorFee;
}
emit ExecutorFeePaid(_executor, executorFee);
}
function _sendToTreasury(
address _sender,
uint32 _dstEid,
uint _totalNativeFee,
bool _payInLzToken
) internal returns (uint treasuryNativeFee, uint lzTokenFee) {
(treasuryNativeFee, lzTokenFee) = _quoteTreasuryFee(_sender, _dstEid, _totalNativeFee, _payInLzToken);
if (treasuryNativeFee > 0) {
fees[treasury] += treasuryNativeFee;
}
}
function _quote(
address _sender,
uint32 _dstEid,
uint _msgSize,
bool _payInLzToken,
bytes calldata _options
) internal view returns (uint, uint) {
require(_options.length > 0, Errors.INVALID_ARGUMENT);
(bytes memory executorOptions, WorkerOptions[] memory otherWorkerOptions) = _getExecutorAndOtherOptions(
_options
);
(uint nativeFee, address executor, uint maxMsgSize) = _quoteWorkers(_sender, _dstEid, otherWorkerOptions);
_assertMessageSize(_msgSize, maxMsgSize);
nativeFee += ILayerZeroExecutor(executor).getFee(_dstEid, _sender, _msgSize, executorOptions);
(uint treasuryNativeFee, uint lzTokenFee) = _quoteTreasuryFee(_sender, _dstEid, nativeFee, _payInLzToken);
if (treasuryNativeFee > 0) {
nativeFee += treasuryNativeFee;
}
return (nativeFee, lzTokenFee);
}
function _quoteTreasuryFee(
address _sender,
uint32 _eid,
uint _totalFee,
bool _payInLzToken
) internal view returns (uint nativeFee, uint lzTokenFee) {
if (treasury != address(0x0)) {
try ILayerZeroTreasury(treasury).getFee(_sender, _eid, _totalFee, _payInLzToken) returns (
uint treasuryFee
) {
if (_payInLzToken) {
lzTokenFee = treasuryFee;
} else {
uint gasFeeEstimate = tx.gasprice * treasuryGasCap;
uint nativeFeeCap = _totalFee > gasFeeEstimate ? _totalFee : gasFeeEstimate;
nativeFee = treasuryFee > nativeFeeCap ? nativeFeeCap : treasuryFee;
}
} catch {
}
}
}
function _transferNative(address _to, uint _amount) internal {
(bool success, ) = _to.call{value: _amount}("");
require(success, Errors.INVALID_STATE);
}
function _assertAndDebitAmount(address _to, uint _amount) internal {
uint fee = fees[msg.sender];
require(_to != address(0x0) && _amount <= fee, Errors.INVALID_ARGUMENT);
unchecked {
fees[msg.sender] = fee - _amount;
}
}
function _setTreasury(address _treasury) internal {
treasury = _treasury;
emit TreasurySet(_treasury);
}
function _quoteWorkers(
address _oapp,
uint32 _eid,
WorkerOptions[] memory _options
) internal view virtual returns (uint nativeFee, address executor, uint maxMsgSize);
function _getExecutorAndOtherOptions(
bytes calldata _options
) internal view virtual returns (bytes memory executorOptions, WorkerOptions[] memory otherWorkerOptions);
}
文件 24 的 31:MessagingStructs.sol
pragma solidity >=0.8.0;
struct PacketForQuote {
address sender;
uint32 dstEid;
bytes message;
}
struct Packet {
uint64 nonce;
uint32 srcEid;
address sender;
uint32 dstEid;
bytes32 receiver;
bytes32 guid;
bytes message;
}
struct Origin {
uint32 srcEid;
bytes32 sender;
uint64 nonce;
}
文件 25 的 31:MultiSig.sol
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
abstract contract MultiSig {
enum Errors {
NoError,
SignatureError,
DuplicatedSigner,
SignerNotInCommittee
}
mapping(address signer => bool active) public signers;
uint64 public signerSize;
uint64 public quorum;
event UpdateSigner(address _signer, bool _active);
event UpdateQuorum(uint64 _quorum);
modifier onlySigner() {
require(signers[msg.sender], "MultiSig: caller must be signer");
_;
}
constructor(address[] memory _signers, uint64 _quorum) {
require(_signers.length >= _quorum && _quorum > 0, "MultiSig: signers too few");
address lastSigner = address(0);
for (uint i = 0; i < _signers.length; i++) {
address signer = _signers[i];
require(signer > lastSigner, "MultiSig: signers not sorted");
signers[signer] = true;
lastSigner = signer;
}
signerSize = uint64(_signers.length);
quorum = _quorum;
}
function _setSigner(address _signer, bool _active) internal {
require(signers[_signer] != _active, "MultiSig: signer already in that state");
signers[_signer] = _active;
signerSize = _active ? signerSize + 1 : signerSize - 1;
require(signerSize >= quorum, "MultiSig: committee size < threshold");
emit UpdateSigner(_signer, _active);
}
function _setQuorum(uint64 _quorum) internal {
require(_quorum <= signerSize && _quorum > 0, "MultiSig: invalid quorum");
quorum = _quorum;
emit UpdateQuorum(_quorum);
}
function verifySignatures(bytes32 _hash, bytes calldata _signatures) public view returns (bool, Errors) {
if (_signatures.length != uint(quorum) * 65) {
return (false, Errors.SignatureError);
}
bytes32 messageDigest = _getEthSignedMessageHash(_hash);
address lastSigner = address(0);
for (uint i = 0; i < quorum; i++) {
bytes calldata signature = _signatures[i * 65:(i + 1) * 65];
(address currentSigner, ECDSA.RecoverError error) = ECDSA.tryRecover(messageDigest, signature);
if (error != ECDSA.RecoverError.NoError) return (false, Errors.SignatureError);
if (currentSigner <= lastSigner) return (false, Errors.DuplicatedSigner);
if (!signers[currentSigner]) return (false, Errors.SignerNotInCommittee);
lastSigner = currentSigner;
}
return (true, Errors.NoError);
}
function _getEthSignedMessageHash(bytes32 _messageHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", _messageHash));
}
}
文件 26 的 31:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 27 的 31:Pausable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Pausable is Context {
event Paused(address account);
event Unpaused(address account);
bool private _paused;
constructor() {
_paused = false;
}
modifier whenNotPaused() {
_requireNotPaused();
_;
}
modifier whenPaused() {
_requirePaused();
_;
}
function paused() public view virtual returns (bool) {
return _paused;
}
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
function _requirePaused() internal view virtual {
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());
}
}
文件 28 的 31:SignedMath.sol
pragma solidity ^0.8.0;
library SignedMath {
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
function average(int256 a, int256 b) internal pure returns (int256) {
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
function abs(int256 n) internal pure returns (uint256) {
unchecked {
return uint256(n >= 0 ? n : -n);
}
}
}
文件 29 的 31:Strings.sol
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
文件 30 的 31:VerifierNetwork.sol
pragma solidity ^0.8.19;
import "@layerzerolabs/lz-evm-v1-0.8/contracts/interfaces/ILayerZeroUltraLightNodeV2.sol";
import "../Worker.sol";
import "./MultiSig.sol";
import "./interfaces/IVerifier.sol";
import "./interfaces/IVerifierFeeLib.sol";
import "./interfaces/IUltraLightNode.sol";
import {DeliveryState} from "../MessageLibBase.sol";
struct ExecuteParam {
uint32 vid;
address target;
bytes callData;
uint expiration;
bytes signatures;
}
contract VerifierNetwork is Worker, MultiSig, IVerifier {
uint32 public immutable vid;
mapping(uint32 dstEid => DstConfig) public dstConfig;
mapping(bytes32 executableHash => bool used) public usedHashes;
event VerifySignaturesFailed(uint idx);
event ExecuteFailed(uint _index, bytes _data);
event HashAlreadyUsed(ExecuteParam param, bytes32 _hash);
event VerifierFeePaid(uint fee);
constructor(
uint32 _vid,
address[] memory _messageLibs,
address _priceFeed,
address[] memory _signers,
uint64 _quorum,
address[] memory _admins
) Worker(_messageLibs, _priceFeed, 12000, address(0x0), _admins) MultiSig(_signers, _quorum) {
vid = _vid;
}
modifier onlySelfOrAdmin(bytes32 _role) {
if (_role == ALLOWLIST || _role == DENYLIST || _role == MESSAGE_LIB_ROLE) {
require(address(this) == msg.sender, "Verifier: caller must be self");
} else if (_role == ADMIN_ROLE) {
_checkRole(ADMIN_ROLE);
} else {
revert("Verifier: invalid role");
}
_;
}
modifier onlySelf() {
require(address(this) == msg.sender, "Verifier: caller must be self");
_;
}
function setSigner(address _signer, bool _active) external onlySelf {
_setSigner(_signer, _active);
}
function setQuorum(uint64 _quorum) external onlySelf {
_setQuorum(_quorum);
}
function verifyAndDeliver(
IUltraLightNode _uln,
bytes calldata _packetHeader,
bytes32 _payloadHash,
uint64 _confirmations
) external onlySelf {
require(hasRole(MESSAGE_LIB_ROLE, address(_uln)), "Verifier: invalid uln");
_uln.verify(_packetHeader, _payloadHash, _confirmations);
if (_uln.deliverable(_packetHeader, _payloadHash) == DeliveryState.Deliverable) {
_uln.deliver(_packetHeader, _payloadHash);
}
}
function grantRole(bytes32 _role, address _account) public override onlySelfOrAdmin(_role) {
_grantRole(_role, _account);
}
function revokeRole(bytes32 _role, address _account) public override onlySelfOrAdmin(_role) {
_revokeRole(_role, _account);
}
function quorumChangeAdmin(ExecuteParam calldata _param) external {
require(_param.expiration > block.timestamp, "Verifier: expired");
require(_param.target == address(this), "Verifier: invalid target");
require(_param.vid == vid, "Verifier: invalid vid");
bytes32 hash = hashCallData(_param.vid, _param.target, _param.callData, _param.expiration);
(bool sigsValid, ) = verifySignatures(hash, _param.signatures);
require(sigsValid, "Verifier: invalid signatures");
require(!usedHashes[hash], "Verifier: hash already used");
usedHashes[hash] = true;
_grantRole(ADMIN_ROLE, abi.decode(_param.callData, (address)));
}
function setDstConfig(DstConfigParam[] calldata _params) external onlyRole(ADMIN_ROLE) {
for (uint i = 0; i < _params.length; ++i) {
DstConfigParam calldata param = _params[i];
dstConfig[param.dstEid] = DstConfig(param.gas, param.multiplierBps, param.floorMarginUSD);
}
emit SetDstConfig(_params);
}
function execute(ExecuteParam[] calldata _params) external onlyRole(ADMIN_ROLE) {
for (uint i = 0; i < _params.length; ++i) {
ExecuteParam calldata param = _params[i];
if (param.vid != vid) {
continue;
}
if (param.expiration <= block.timestamp) {
continue;
}
bytes32 hash = hashCallData(param.vid, param.target, param.callData, param.expiration);
(bool sigsValid, ) = verifySignatures(hash, param.signatures);
if (!sigsValid) {
emit VerifySignaturesFailed(i);
continue;
}
bool shouldCheckHash = _shouldCheckHash(bytes4(param.callData));
if (shouldCheckHash) {
if (usedHashes[hash]) {
emit HashAlreadyUsed(param, hash);
continue;
} else {
usedHashes[hash] = true;
}
}
(bool success, bytes memory rtnData) = param.target.call(param.callData);
if (!success) {
if (shouldCheckHash) {
usedHashes[hash] = false;
}
emit ExecuteFailed(i, rtnData);
}
}
}
function withdrawFeeFromUlnV2(address _lib, address payable _to, uint _amount) external onlyRole(ADMIN_ROLE) {
require(hasRole(MESSAGE_LIB_ROLE, _lib), "Verifier: Invalid message lib");
ILayerZeroUltraLightNodeV2(_lib).withdrawNative(_to, _amount);
}
function assignJob(
AssignJobParam calldata _param,
bytes calldata _options
) external payable onlyRole(MESSAGE_LIB_ROLE) onlyAcl(_param.sender) returns (uint totalFee) {
IVerifierFeeLib.FeeParams memory feeParams = IVerifierFeeLib.FeeParams(
priceFeed,
_param.dstEid,
_param.confirmations,
_param.sender,
quorum,
defaultMultiplierBps
);
totalFee = IVerifierFeeLib(workerFeeLib).getFeeOnSend(feeParams, dstConfig[_param.dstEid], _options);
}
function assignJob(
uint16 _dstEid,
uint16 ,
uint64 _confirmations,
address _sender
) external onlyRole(MESSAGE_LIB_ROLE) onlyAcl(_sender) returns (uint totalFee) {
IVerifierFeeLib.FeeParams memory params = IVerifierFeeLib.FeeParams(
priceFeed,
_dstEid,
_confirmations,
_sender,
quorum,
defaultMultiplierBps
);
totalFee = IVerifierFeeLib(workerFeeLib).getFeeOnSend(params, dstConfig[_dstEid], bytes(""));
emit VerifierFeePaid(totalFee);
}
function getFee(
uint32 _dstEid,
uint64 _confirmations,
address _sender,
bytes calldata _options
) external view onlyAcl(_sender) returns (uint fee) {
IVerifierFeeLib.FeeParams memory params = IVerifierFeeLib.FeeParams(
priceFeed,
_dstEid,
_confirmations,
_sender,
quorum,
defaultMultiplierBps
);
return IVerifierFeeLib(workerFeeLib).getFee(params, dstConfig[_dstEid], _options);
}
function getFee(
uint16 _dstEid,
uint16 ,
uint64 _confirmations,
address _sender
) public view onlyAcl(_sender) returns (uint fee) {
IVerifierFeeLib.FeeParams memory params = IVerifierFeeLib.FeeParams(
priceFeed,
_dstEid,
_confirmations,
_sender,
quorum,
defaultMultiplierBps
);
return IVerifierFeeLib(workerFeeLib).getFee(params, dstConfig[_dstEid], bytes(""));
}
function hashCallData(
uint32 _vid,
address _target,
bytes calldata _callData,
uint _expiration
) public pure returns (bytes32) {
return keccak256(abi.encodePacked(_vid, _target, _expiration, _callData));
}
function _shouldCheckHash(bytes4 _functionSig) internal pure returns (bool) {
return
_functionSig != IUltraLightNode.verify.selector &&
_functionSig != this.verifyAndDeliver.selector &&
_functionSig != ILayerZeroUltraLightNodeV2.updateHash.selector;
}
}
文件 31 的 31:Worker.sol
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessageLib.sol";
import "./interfaces/IWorker.sol";
abstract contract Worker is AccessControl, Pausable, IWorker {
bytes32 internal constant MESSAGE_LIB_ROLE = keccak256("MESSAGE_LIB_ROLE");
bytes32 internal constant ALLOWLIST = keccak256("ALLOWLIST");
bytes32 internal constant DENYLIST = keccak256("DENYLIST");
bytes32 internal constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
address public workerFeeLib;
uint64 public allowlistSize;
uint16 public defaultMultiplierBps;
address public priceFeed;
constructor(
address[] memory _messageLibs,
address _priceFeed,
uint16 _defaultMultiplierBps,
address _roleAdmin,
address[] memory _admins
) {
defaultMultiplierBps = _defaultMultiplierBps;
priceFeed = _priceFeed;
if (_roleAdmin != address(0x0)) {
_grantRole(DEFAULT_ADMIN_ROLE, _roleAdmin);
}
for (uint i = 0; i < _messageLibs.length; ++i) {
_grantRole(MESSAGE_LIB_ROLE, _messageLibs[i]);
}
for (uint i = 0; i < _admins.length; ++i) {
_grantRole(ADMIN_ROLE, _admins[i]);
}
}
modifier onlyAcl(address _sender) {
require(hasAcl(_sender), "Worker: not allowed");
_;
}
function hasAcl(address _sender) public view returns (bool) {
if (hasRole(DENYLIST, _sender)) {
return false;
} else if (allowlistSize == 0 || hasRole(ALLOWLIST, _sender)) {
return true;
} else {
return false;
}
}
function setPaused(bool _paused) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (_paused) {
_pause();
} else {
_unpause();
}
}
function setPriceFeed(address _priceFeed) external onlyRole(ADMIN_ROLE) {
priceFeed = _priceFeed;
emit SetPriceFeed(_priceFeed);
}
function setWorkerFeeLib(address _workerFeeLib) external onlyRole(ADMIN_ROLE) {
workerFeeLib = _workerFeeLib;
emit SetWorkerLib(_workerFeeLib);
}
function setDefaultMultiplierBps(uint16 _multiplierBps) external onlyRole(ADMIN_ROLE) {
defaultMultiplierBps = _multiplierBps;
emit SetDefaultMultiplierBps(_multiplierBps);
}
function withdrawFee(address _lib, address _to, uint _amount) external onlyRole(ADMIN_ROLE) {
require(hasRole(MESSAGE_LIB_ROLE, _lib), "Worker: Invalid message lib");
IMessageLib(_lib).withdrawFee(_to, _amount);
emit Withdraw(_lib, _to, _amount);
}
function _grantRole(bytes32 _role, address _account) internal override {
if (_role == ALLOWLIST && !hasRole(_role, _account)) {
++allowlistSize;
}
super._grantRole(_role, _account);
}
function _revokeRole(bytes32 _role, address _account) internal override {
if (_role == ALLOWLIST && hasRole(_role, _account)) {
--allowlistSize;
}
super._revokeRole(_role, _account);
}
function renounceRole(bytes32 , address ) public pure override {
revert("Worker: cannot renounce role");
}
}
{
"compilationTarget": {
"contracts/uln/VerifierNetwork.sol": "VerifierNetwork"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 20000
},
"remappings": []
}
[{"inputs":[{"internalType":"uint32","name":"_vid","type":"uint32"},{"internalType":"address[]","name":"_messageLibs","type":"address[]"},{"internalType":"address","name":"_priceFeed","type":"address"},{"internalType":"address[]","name":"_signers","type":"address[]"},{"internalType":"uint64","name":"_quorum","type":"uint64"},{"internalType":"address[]","name":"_admins","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_index","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"_data","type":"bytes"}],"name":"ExecuteFailed","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint32","name":"vid","type":"uint32"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"bytes","name":"signatures","type":"bytes"}],"indexed":false,"internalType":"struct ExecuteParam","name":"param","type":"tuple"},{"indexed":false,"internalType":"bytes32","name":"_hash","type":"bytes32"}],"name":"HashAlreadyUsed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"multiplierBps","type":"uint16"}],"name":"SetDefaultMultiplierBps","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint32","name":"dstEid","type":"uint32"},{"internalType":"uint64","name":"gas","type":"uint64"},{"internalType":"uint16","name":"multiplierBps","type":"uint16"},{"internalType":"uint128","name":"floorMarginUSD","type":"uint128"}],"indexed":false,"internalType":"struct IVerifier.DstConfigParam[]","name":"params","type":"tuple[]"}],"name":"SetDstConfig","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"priceFeed","type":"address"}],"name":"SetPriceFeed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"workerLib","type":"address"}],"name":"SetWorkerLib","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"_quorum","type":"uint64"}],"name":"UpdateQuorum","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_signer","type":"address"},{"indexed":false,"internalType":"bool","name":"_active","type":"bool"}],"name":"UpdateSigner","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"VerifierFeePaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"idx","type":"uint256"}],"name":"VerifySignaturesFailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"lib","type":"address"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allowlistSize","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"dstEid","type":"uint32"},{"internalType":"bytes","name":"packetHeader","type":"bytes"},{"internalType":"bytes32","name":"payloadHash","type":"bytes32"},{"internalType":"uint64","name":"confirmations","type":"uint64"},{"internalType":"address","name":"sender","type":"address"}],"internalType":"struct ILayerZeroVerifier.AssignJobParam","name":"_param","type":"tuple"},{"internalType":"bytes","name":"_options","type":"bytes"}],"name":"assignJob","outputs":[{"internalType":"uint256","name":"totalFee","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_dstEid","type":"uint16"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint64","name":"_confirmations","type":"uint64"},{"internalType":"address","name":"_sender","type":"address"}],"name":"assignJob","outputs":[{"internalType":"uint256","name":"totalFee","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"defaultMultiplierBps","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"dstEid","type":"uint32"}],"name":"dstConfig","outputs":[{"internalType":"uint64","name":"gas","type":"uint64"},{"internalType":"uint16","name":"multiplierBps","type":"uint16"},{"internalType":"uint128","name":"floorMarginUSD","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"vid","type":"uint32"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"bytes","name":"signatures","type":"bytes"}],"internalType":"struct ExecuteParam[]","name":"_params","type":"tuple[]"}],"name":"execute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_dstEid","type":"uint32"},{"internalType":"uint64","name":"_confirmations","type":"uint64"},{"internalType":"address","name":"_sender","type":"address"},{"internalType":"bytes","name":"_options","type":"bytes"}],"name":"getFee","outputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"_dstEid","type":"uint16"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint64","name":"_confirmations","type":"uint64"},{"internalType":"address","name":"_sender","type":"address"}],"name":"getFee","outputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_role","type":"bytes32"},{"internalType":"address","name":"_account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_sender","type":"address"}],"name":"hasAcl","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_vid","type":"uint32"},{"internalType":"address","name":"_target","type":"address"},{"internalType":"bytes","name":"_callData","type":"bytes"},{"internalType":"uint256","name":"_expiration","type":"uint256"}],"name":"hashCallData","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"priceFeed","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"quorum","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"vid","type":"uint32"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"bytes","name":"signatures","type":"bytes"}],"internalType":"struct ExecuteParam","name":"_param","type":"tuple"}],"name":"quorumChangeAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"address","name":"","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_role","type":"bytes32"},{"internalType":"address","name":"_account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_multiplierBps","type":"uint16"}],"name":"setDefaultMultiplierBps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"dstEid","type":"uint32"},{"internalType":"uint64","name":"gas","type":"uint64"},{"internalType":"uint16","name":"multiplierBps","type":"uint16"},{"internalType":"uint128","name":"floorMarginUSD","type":"uint128"}],"internalType":"struct IVerifier.DstConfigParam[]","name":"_params","type":"tuple[]"}],"name":"setDstConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_paused","type":"bool"}],"name":"setPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_priceFeed","type":"address"}],"name":"setPriceFeed","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"_quorum","type":"uint64"}],"name":"setQuorum","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"},{"internalType":"bool","name":"_active","type":"bool"}],"name":"setSigner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_workerFeeLib","type":"address"}],"name":"setWorkerFeeLib","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"signerSize","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"signer","type":"address"}],"name":"signers","outputs":[{"internalType":"bool","name":"active","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"executableHash","type":"bytes32"}],"name":"usedHashes","outputs":[{"internalType":"bool","name":"used","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IUltraLightNode","name":"_uln","type":"address"},{"internalType":"bytes","name":"_packetHeader","type":"bytes"},{"internalType":"bytes32","name":"_payloadHash","type":"bytes32"},{"internalType":"uint64","name":"_confirmations","type":"uint64"}],"name":"verifyAndDeliver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_hash","type":"bytes32"},{"internalType":"bytes","name":"_signatures","type":"bytes"}],"name":"verifySignatures","outputs":[{"internalType":"bool","name":"","type":"bool"},{"internalType":"enum MultiSig.Errors","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vid","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_lib","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_lib","type":"address"},{"internalType":"address payable","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawFeeFromUlnV2","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"workerFeeLib","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]