Verified contractExactMIT
OPStackChainMessenger
Address0xd464ebb70bafe66b97df6b8ccb113aa7cd7cd15f
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.18
- Same code
4 more contracts
Details
- Compiler
- solc 0.8.18+commit.87f61d96
- Language
- solidity
- Optimization
- Yes, 300 runs
- EVM version
- paris
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 19,879,881
- Creation transaction
- 0xc837e5b88e…153a690165
7 files
- src/OPStackChainMessenger.solmain1.96 KB
- lib/openzeppelin-contracts/contracts/access/Ownable.sol2.62 KB
- lib/openzeppelin-contracts/contracts/utils/Context.sol962 B
- src/interfaces/IChainMessenger.sol223 B
- src/interfaces/IController.sol3.19 KB
- src/interfaces/IControllerOracle.sol2.23 KB
- src/interfaces/IOPCrossDomainMessenger.sol272 B
src/OPStackChainMessenger.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import {Ownable} from "openzeppelin-contracts/contracts/access/Ownable.sol";
import {IController} from "./interfaces/IController.sol";
import {IOPCrossDomainMessenger} from "./interfaces/IOPCrossDomainMessenger.sol";
import {IControllerOracle} from "./interfaces/IControllerOracle.sol";
import {IChainMessenger} from "./interfaces/IChainMessenger.sol";
contract OPStackChainMessenger is Ownable, IChainMessenger {
address private _controllerRelayer;
address private _controllerOracle;
IOPCrossDomainMessenger private _crossDomainMessenger;
error WrongControllerRelayer();
constructor(address controllerRelayer, address controllerOracle, address crossDomainMessenger) {
_controllerRelayer = controllerRelayer;
_controllerOracle = controllerOracle;
_crossDomainMessenger = IOPCrossDomainMessenger(crossDomainMessenger);
}
function relayMessage(address committer, IController.Group memory group) external {
if (msg.sender != _controllerRelayer) {
revert WrongControllerRelayer();
}
// call portal of L2 chain on L1 to trigger message relay, e.g. for OP this is to call
_crossDomainMessenger.sendMessage(
_controllerOracle,
abi.encodeWithSelector(IControllerOracle.updateGroup.selector, committer, group),
// 20% more gas than the actual gas used
(344270 + 157160 * uint32(group.size)) * 6 / 5
);
}
function setControllerRelayer(address controllerRelayer) external onlyOwner {
_controllerRelayer = controllerRelayer;
}
function setControllerOracle(address controllerOracle) external onlyOwner {
_controllerOracle = controllerOracle;
}
function setCrossDomainMessenger(address crossDomainMessenger) external onlyOwner {
_crossDomainMessenger = IOPCrossDomainMessenger(crossDomainMessenger);
}
}
lib/openzeppelin-contracts/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
lib/openzeppelin-contracts/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
src/interfaces/IChainMessenger.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import {IController} from "./IController.sol";
interface IChainMessenger {
function relayMessage(address committer, IController.Group memory group) external;
}
src/interfaces/IController.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
interface IController {
struct Group {
uint256 index;
uint256 epoch;
uint256 size;
uint256 threshold;
Member[] members;
address[] committers;
CommitCache[] commitCacheList;
bool isStrictlyMajorityConsensusReached;
uint256[4] publicKey;
}
struct Member {
address nodeIdAddress;
uint256[4] partialPublicKey;
}
struct CommitResult {
uint256 groupEpoch;
uint256[4] publicKey;
address[] disqualifiedNodes;
}
struct CommitCache {
address[] nodeIdAddress;
CommitResult commitResult;
}
struct CommitDkgParams {
uint256 groupIndex;
uint256 groupEpoch;
bytes publicKey;
bytes partialPublicKey;
address[] disqualifiedNodes;
}
// node transaction
function nodeJoin(address nodeIdAddress) external returns (uint256 groupIndex);
function nodeLeave(address nodeIdAddress) external;
function commitDkg(CommitDkgParams memory params) external;
function postProcessDkg(uint256 groupIndex, uint256 groupEpoch) external;
// nodeRegistry transaction
function nodeWithdrawETH(address recipient, uint256 ethAmount) external;
// adapter transaction
function addReward(address[] memory nodes, uint256 ethAmount, uint256 arpaAmount) external;
function setLastOutput(uint256 lastOutput) external;
// view
function getControllerConfig()
external
view
returns (
address nodeRegistryContractAddress,
address adapterContractAddress,
uint256 disqualifiedNodePenaltyAmount,
uint256 defaultNumberOfCommitters,
uint256 defaultDkgPhaseDuration,
uint256 groupMaxCapacity,
uint256 idealNumberOfGroups,
uint256 dkgPostProcessReward
);
/// @notice Get list of all group indexes where group.isStrictlyMajorityConsensusReached == true
/// @return uint256[] List of valid group indexes
function getValidGroupIndices() external view returns (uint256[] memory);
function getGroupEpoch() external view returns (uint256);
function getGroupCount() external view returns (uint256);
function getGroup(uint256 index) external view returns (Group memory);
function getGroupThreshold(uint256 groupIndex) external view returns (uint256, uint256);
function getMember(uint256 groupIndex, uint256 memberIndex) external view returns (Member memory);
/// @notice Get the group index and member index of a given node.
function getBelongingGroup(address nodeAddress) external view returns (int256, int256);
function getCoordinator(uint256 groupIndex) external view returns (address);
function getLastOutput() external view returns (uint256);
/// @notice Check to see if a group has a partial public key registered for a given node.
/// @return bool True if the node has a partial public key registered for the group.
function isPartialKeyRegistered(uint256 groupIndex, address nodeIdAddress) external view returns (bool);
}
src/interfaces/IControllerOracle.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
interface IControllerOracle {
struct Group {
uint256 index;
uint256 epoch;
uint256 size;
uint256 threshold;
Member[] members;
address[] committers;
CommitCache[] commitCacheList;
bool isStrictlyMajorityConsensusReached;
uint256[4] publicKey;
}
struct Member {
address nodeIdAddress;
uint256[4] partialPublicKey;
}
struct CommitResult {
uint256 groupEpoch;
uint256[4] publicKey;
address[] disqualifiedNodes;
}
struct CommitCache {
address[] nodeIdAddress;
CommitResult commitResult;
}
struct CommitDkgParams {
uint256 groupIndex;
uint256 groupEpoch;
bytes publicKey;
bytes partialPublicKey;
address[] disqualifiedNodes;
}
// relay transaction
function updateGroup(address committer, Group memory group) external;
// node transaction
function nodeWithdraw(address recipient) external;
// adapter transaction
function addReward(address[] memory nodes, uint256 ethAmount, uint256 arpaAmount) external;
function setLastOutput(uint256 lastOutput) external;
// view
/// @notice Get list of all group indexes where group.isStrictlyMajorityConsensusReached == true
/// @return uint256[] List of valid group indexes
function getValidGroupIndices() external view returns (uint256[] memory);
function getGroupEpoch() external view returns (uint256);
function getGroupCount() external view returns (uint256);
function getGroup(uint256 index) external view returns (Group memory);
function getGroupThreshold(uint256 groupIndex) external view returns (uint256, uint256);
function getMember(uint256 groupIndex, uint256 memberIndex) external view returns (Member memory);
/// @notice Get the group index and member index of a given node.
function getBelongingGroup(address nodeAddress) external view returns (int256, int256);
function getNodeWithdrawableTokens(address nodeAddress) external view returns (uint256, uint256);
function getLastOutput() external view returns (uint256);
}
src/interfaces/IOPCrossDomainMessenger.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
interface IOPCrossDomainMessenger {
function sendMessage(address _target, bytes calldata _message, uint32 _minGasLimit) external payable;
function xDomainMessageSender() external view returns (address);
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 300,
"enabled": true
},
"evmVersion": "paris",
"remappings": [
":Randcast-User-Contract/=lib/Randcast-User-Contract/contracts/",
":Staking-v0.1/=lib/Staking-v0.1/src/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":fx-portal/=lib/fx-portal/contracts/",
":openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.