编译器
0.8.27+commit.40a35a09
文件 1 的 10:AccessControl.sol
pragma solidity ^0.8.20;
import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
mapping(bytes32 role => 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 returns (bool) {
return _roles[role].hasRole[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 AccessControlUnauthorizedAccount(account, role);
}
}
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
return _roles[role].adminRole;
}
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
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 returns (bool) {
if (!hasRole(role, account)) {
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}
文件 2 的 10:Context.sol
pragma solidity ^0.8.20;
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;
}
}
文件 3 的 10:ERC165.sol
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 4 的 10:IAccessControl.sol
pragma solidity ^0.8.20;
interface IAccessControl {
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
error AccessControlBadConfirmation();
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 callerConfirmation) external;
}
文件 5 的 10:IActivityMonitor.sol
pragma solidity 0.8.27;
interface IActivityMonitor {
function markActivity(uint256[] calldata validators) external;
function validatorLastActivity(uint256 validatorId) external returns(uint256);
}
文件 6 的 10:IERC165.sol
pragma solidity ^0.8.20;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 7 的 10:IProvingContract.sol
pragma solidity 0.8.27;
interface IProvingContract {
function proofVerifier() external view returns(address);
function setProofVerifier(address proofVerifier) external;
function setExitAdministrator(address exitAdministrator) external;
}
文件 8 的 10:IStateOracle.sol
pragma solidity 0.8.27;
interface IStateOracle {
function lastState() external view returns (bytes32);
function lastBlockNum() external view returns (uint256);
function lastUpdateTime() external view returns (uint256);
function chainId() external view returns (uint256);
function update(uint256 blockNum, bytes32 stateRoot) external;
}
文件 9 的 10:IUpdateVerifier.sol
pragma solidity 0.8.27;
interface IUpdateVerifier {
struct Validator {
uint256 id;
address addr;
uint256 weight;
}
function verifyUpdate(uint256 blockNum, bytes32 stateRoot, uint256 chainId, bytes calldata newValidators, address proofVerifier, address updateVerifier, address exitAdmin, bytes[] calldata signatures) external view returns (uint256[] memory);
function setValidators(bytes calldata newValidators) external;
function lastValidatorId() external view returns(uint256);
function validatorAddress(uint256 index) external view returns(address);
function validatorWeight(address addr) external view returns(uint256);
function validatorId(address addr) external view returns(uint256);
function totalWeight() external view returns(uint256);
function getQuorum() external view returns (uint256);
}
文件 10 的 10:UpdateManager.sol
pragma solidity 0.8.27;
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {IStateOracle} from "./interfaces/IStateOracle.sol";
import {IUpdateVerifier} from "./interfaces/IUpdateVerifier.sol";
import {IProvingContract} from "./interfaces/IProvingContract.sol";
import {IActivityMonitor} from "./interfaces/IActivityMonitor.sol";
contract UpdateManager is AccessControl {
IStateOracle public immutable stateOracle;
IUpdateVerifier public updateVerifier;
IProvingContract public immutable provingContract;
IActivityMonitor public activityMonitor;
uint256 public heartbeat;
uint256 public fastLanePadding;
uint256 public fastLaneFee;
bool public fastLaneInUse;
bytes32 public constant HEARTBEAT_ROLE = keccak256("HEARTBEAT_ROLE");
bytes32 public constant MONITOR_SETTER_ROLE = keccak256("MONITOR_SETTER_ROLE");
bytes32 public constant FEE_SETTER_ROLE = keccak256("FEE_SETTER_ROLE");
event FastLaneRequest(uint256 blockNum);
event HeartbeatSet(uint256 heartbeat);
event FastLanePaddingSet(uint256 padding);
event FastLaneFeeSet(uint256 fee);
event ActivityMonitorSet(IActivityMonitor activityMonitor);
event UpdateVerifierSet(IUpdateVerifier updateVerifier);
constructor(IStateOracle _stateOracle, IUpdateVerifier _updateVerifier, IProvingContract _provingContract, address admin, uint256 _heartbeat) {
require(address(_stateOracle) != address(0), "StateOracle not set");
require(address(_updateVerifier) != address(0), "UpdateVerifier not set");
require(address(_provingContract) != address(0), "ProvingContract not set");
require(admin != address(0), "Admin not set");
require(_heartbeat >= 1, "Heartbeat must be positive");
stateOracle = _stateOracle;
updateVerifier = _updateVerifier;
provingContract = _provingContract;
heartbeat = _heartbeat;
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}
function update(uint256 blockNum, bytes32 stateRoot, bytes calldata newValidators, address _proofVerifier, address _updateVerifier, address _exitAdmin, bytes[] calldata signatures) external {
uint256 _chainId = stateOracle.chainId();
uint256[] memory validators = updateVerifier.verifyUpdate(blockNum, stateRoot, _chainId, newValidators, _proofVerifier, _updateVerifier, _exitAdmin, signatures);
stateOracle.update(blockNum, stateRoot);
if (_proofVerifier != address(0)) {
provingContract.setProofVerifier(_proofVerifier);
}
if (_exitAdmin != address(0)) {
provingContract.setExitAdministrator(_exitAdmin);
}
if (_updateVerifier != address(0)) {
updateVerifier = IUpdateVerifier(_updateVerifier);
emit UpdateVerifierSet(IUpdateVerifier(_updateVerifier));
}
if (newValidators.length != 0) {
updateVerifier.setValidators(newValidators);
}
if (newValidators.length != 0) {
updateVerifier.setValidators(newValidators);
}
if (address(activityMonitor) != address(0)) {
activityMonitor.markActivity(validators);
}
if (fastLaneInUse) {
fastLaneInUse = false;
(bool success, ) = msg.sender.call{value: address(this).balance}("");
require(success, "Failed to transfer update reward");
}
}
function payFastLane(uint256 blockNum) external payable {
require(!fastLaneInUse, "Fast lane busy");
require(msg.value >= fastLaneFee, "Insufficient fee value");
uint256 lastStateUpdate = stateOracle.lastBlockNum();
uint256 nextStateUpdate = lastStateUpdate - (lastStateUpdate % heartbeat) + heartbeat;
require(blockNum > lastStateUpdate + fastLanePadding, "Block number too low");
require(blockNum < nextStateUpdate - fastLanePadding, "Block number too high");
fastLaneInUse = true;
emit FastLaneRequest(blockNum);
}
function setHeartbeat(uint256 _heartbeat) onlyRole(HEARTBEAT_ROLE) external {
require(_heartbeat >= 1, "Heartbeat must be positive");
require(fastLanePadding < _heartbeat, "Heartbeat must be greater than fast lane padding");
heartbeat = _heartbeat;
emit HeartbeatSet(_heartbeat);
}
function setFastLanePadding(uint256 _padding) onlyRole(HEARTBEAT_ROLE) external {
require(_padding < heartbeat, "Padding must be less than heartbeat");
fastLanePadding = _padding;
emit FastLanePaddingSet(_padding);
}
function setFastLaneFee(uint256 _fee) onlyRole(FEE_SETTER_ROLE) external {
fastLaneFee = _fee;
emit FastLaneFeeSet(_fee);
}
function setActivityMonitor(IActivityMonitor _monitor) onlyRole(MONITOR_SETTER_ROLE) external {
activityMonitor = _monitor;
emit ActivityMonitorSet(_monitor);
}
function chainId() external view returns(uint256) {
return stateOracle.chainId();
}
function lastBlockNum() external view returns(uint256) {
return stateOracle.lastBlockNum();
}
function proofVerifier() external view returns(address) {
return provingContract.proofVerifier();
}
}
{
"compilationTarget": {
"contracts/UpdateManager.sol": "UpdateManager"
},
"evmVersion": "cancun",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"contract IStateOracle","name":"_stateOracle","type":"address"},{"internalType":"contract IUpdateVerifier","name":"_updateVerifier","type":"address"},{"internalType":"contract IProvingContract","name":"_provingContract","type":"address"},{"internalType":"address","name":"admin","type":"address"},{"internalType":"uint256","name":"_heartbeat","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IActivityMonitor","name":"activityMonitor","type":"address"}],"name":"ActivityMonitorSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"FastLaneFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"padding","type":"uint256"}],"name":"FastLanePaddingSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"blockNum","type":"uint256"}],"name":"FastLaneRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"heartbeat","type":"uint256"}],"name":"HeartbeatSet","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":"contract IUpdateVerifier","name":"updateVerifier","type":"address"}],"name":"UpdateVerifierSet","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FEE_SETTER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"HEARTBEAT_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MONITOR_SETTER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"activityMonitor","outputs":[{"internalType":"contract IActivityMonitor","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"chainId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fastLaneFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fastLaneInUse","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fastLanePadding","outputs":[{"internalType":"uint256","name":"","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":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"heartbeat","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastBlockNum","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"blockNum","type":"uint256"}],"name":"payFastLane","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"proofVerifier","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"provingContract","outputs":[{"internalType":"contract IProvingContract","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"callerConfirmation","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IActivityMonitor","name":"_monitor","type":"address"}],"name":"setActivityMonitor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_fee","type":"uint256"}],"name":"setFastLaneFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_padding","type":"uint256"}],"name":"setFastLanePadding","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_heartbeat","type":"uint256"}],"name":"setHeartbeat","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stateOracle","outputs":[{"internalType":"contract IStateOracle","name":"","type":"address"}],"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":"uint256","name":"blockNum","type":"uint256"},{"internalType":"bytes32","name":"stateRoot","type":"bytes32"},{"internalType":"bytes","name":"newValidators","type":"bytes"},{"internalType":"address","name":"_proofVerifier","type":"address"},{"internalType":"address","name":"_updateVerifier","type":"address"},{"internalType":"address","name":"_exitAdmin","type":"address"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"}],"name":"update","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateVerifier","outputs":[{"internalType":"contract IUpdateVerifier","name":"","type":"address"}],"stateMutability":"view","type":"function"}]