Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- AccountingOracle
- Optimization enabled
- true
- Compiler version
- v0.8.9+commit.e5eed63a
- Optimization runs
- 150
- EVM Version
- istanbul
- Verified at
- 2024-06-07T12:42:42.596731Z
Constructor Arguments
0x00000000000000000000000022ae3d0b58dd75fcaedeb8ecde3c6a5a59599047000000000000000000000000a484daaeab44914d5f55712075e9be6983400eb10000000000000000000000000bb280df53da700b7f1bed5a126c32f949a0eb04000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000064377651
Arg [0] (address) : 0x22ae3d0b58dd75fcaedeb8ecde3c6a5a59599047
Arg [1] (address) : 0xa484daaeab44914d5f55712075e9be6983400eb1
Arg [2] (address) : 0x0bb280df53da700b7f1bed5a126c32f949a0eb04
Arg [3] (uint256) : 10
Arg [4] (uint256) : 1681356369
contracts/0.8.9/oracle/AccountingOracle.sol
// SPDX-FileCopyrightText: 2023 Lido <info@lido.fi>
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.9;
import { SafeCast } from "@openzeppelin/contracts-v4.4/utils/math/SafeCast.sol";
import { ILidoLocator } from "../../common/interfaces/ILidoLocator.sol";
import { UnstructuredStorage } from "../lib/UnstructuredStorage.sol";
import { BaseOracle, IConsensusContract } from "./BaseOracle.sol";
interface ILido {
function handleOracleReport(
// Oracle timings
uint256 _currentReportTimestamp,
uint256 _timeElapsedSeconds,
// CL values
uint256 _clValidators,
uint256 _clBalance,
// EL values
uint256 _withdrawalVaultBalance,
uint256 _elRewardsVaultBalance,
uint256 _sharesRequestedToBurn,
// Decision about withdrawals processing
uint256[] calldata _withdrawalFinalizationBatches,
uint256 _simulatedShareRate
) external;
}
interface ILegacyOracle {
// only called before the migration
function getBeaconSpec() external view returns (
uint64 epochsPerFrame,
uint64 slotsPerEpoch,
uint64 secondsPerSlot,
uint64 genesisTime
);
function getLastCompletedEpochId() external view returns (uint256);
// only called after the migration
function handleConsensusLayerReport(
uint256 refSlot,
uint256 clBalance,
uint256 clValidators
) external;
}
interface IOracleReportSanityChecker {
function checkExitedValidatorsRatePerDay(uint256 _exitedValidatorsCount) external view;
function checkAccountingExtraDataListItemsCount(uint256 _extraDataListItemsCount) external view;
function checkNodeOperatorsPerExtraDataItemCount(uint256 _itemIndex, uint256 _nodeOperatorsCount) external view;
}
interface IStakingRouter {
function updateExitedValidatorsCountByStakingModule(
uint256[] calldata moduleIds,
uint256[] calldata exitedValidatorsCounts
) external returns (uint256);
function reportStakingModuleExitedValidatorsCountByNodeOperator(
uint256 stakingModuleId,
bytes calldata nodeOperatorIds,
bytes calldata exitedValidatorsCounts
) external;
function reportStakingModuleStuckValidatorsCountByNodeOperator(
uint256 stakingModuleId,
bytes calldata nodeOperatorIds,
bytes calldata stuckValidatorsCounts
) external;
function onValidatorsCountsByNodeOperatorReportingFinished() external;
}
interface IWithdrawalQueue {
function onOracleReport(bool isBunkerMode, uint256 prevReportTimestamp, uint256 currentReportTimestamp) external;
}
contract AccountingOracle is BaseOracle {
using UnstructuredStorage for bytes32;
using SafeCast for uint256;
error LidoLocatorCannotBeZero();
error AdminCannotBeZero();
error LegacyOracleCannotBeZero();
error LidoCannotBeZero();
error IncorrectOracleMigration(uint256 code);
error SenderNotAllowed();
error InvalidExitedValidatorsData();
error UnsupportedExtraDataFormat(uint256 format);
error UnsupportedExtraDataType(uint256 itemIndex, uint256 dataType);
error CannotSubmitExtraDataBeforeMainData();
error ExtraDataAlreadyProcessed();
error ExtraDataListOnlySupportsSingleTx();
error UnexpectedExtraDataHash(bytes32 consensusHash, bytes32 receivedHash);
error UnexpectedExtraDataFormat(uint256 expectedFormat, uint256 receivedFormat);
error ExtraDataItemsCountCannotBeZeroForNonEmptyData();
error ExtraDataHashCannotBeZeroForNonEmptyData();
error UnexpectedExtraDataItemsCount(uint256 expectedCount, uint256 receivedCount);
error UnexpectedExtraDataIndex(uint256 expectedIndex, uint256 receivedIndex);
error InvalidExtraDataItem(uint256 itemIndex);
error InvalidExtraDataSortOrder(uint256 itemIndex);
event ExtraDataSubmitted(uint256 indexed refSlot, uint256 itemsProcessed, uint256 itemsCount);
event WarnExtraDataIncompleteProcessing(
uint256 indexed refSlot,
uint256 processedItemsCount,
uint256 itemsCount
);
struct ExtraDataProcessingState {
uint64 refSlot;
uint16 dataFormat;
bool submitted;
uint64 itemsCount;
uint64 itemsProcessed;
uint256 lastSortingKey;
bytes32 dataHash;
}
/// @notice An ACL role granting the permission to submit the data for a committee report.
bytes32 public constant SUBMIT_DATA_ROLE = keccak256("SUBMIT_DATA_ROLE");
/// @dev Storage slot: ExtraDataProcessingState state
bytes32 internal constant EXTRA_DATA_PROCESSING_STATE_POSITION =
keccak256("lido.AccountingOracle.extraDataProcessingState");
address public immutable LIDO;
ILidoLocator public immutable LOCATOR;
address public immutable LEGACY_ORACLE;
///
/// Initialization & admin functions
///
constructor(
address lidoLocator,
address lido,
address legacyOracle,
uint256 secondsPerSlot,
uint256 genesisTime
)
BaseOracle(secondsPerSlot, genesisTime)
{
if (lidoLocator == address(0)) revert LidoLocatorCannotBeZero();
if (legacyOracle == address(0)) revert LegacyOracleCannotBeZero();
if (lido == address(0)) revert LidoCannotBeZero();
LOCATOR = ILidoLocator(lidoLocator);
LIDO = lido;
LEGACY_ORACLE = legacyOracle;
}
function initialize(
address admin,
address consensusContract,
uint256 consensusVersion
) external {
if (admin == address(0)) revert AdminCannotBeZero();
uint256 lastProcessingRefSlot = _checkOracleMigration(LEGACY_ORACLE, consensusContract);
_initialize(admin, consensusContract, consensusVersion, lastProcessingRefSlot);
}
function initializeWithoutMigration(
address admin,
address consensusContract,
uint256 consensusVersion,
uint256 lastProcessingRefSlot
) external {
if (admin == address(0)) revert AdminCannotBeZero();
_initialize(admin, consensusContract, consensusVersion, lastProcessingRefSlot);
}
///
/// Data provider interface
///
struct ReportData {
///
/// Oracle consensus info
///
/// @dev Version of the oracle consensus rules. Current version expected
/// by the oracle can be obtained by calling getConsensusVersion().
uint256 consensusVersion;
/// @dev Reference slot for which the report was calculated. If the slot
/// contains a block, the state being reported should include all state
/// changes resulting from that block. The epoch containing the slot
/// should be finalized prior to calculating the report.
uint256 refSlot;
///
/// CL values
///
/// @dev The number of validators on consensus layer that were ever deposited
/// via Lido as observed at the reference slot.
uint256 numValidators;
/// @dev Cumulative balance of all Lido validators on the consensus layer
/// as observed at the reference slot.
uint256 clBalanceGwei;
/// @dev Ids of staking modules that have more exited validators than the number
/// stored in the respective staking module contract as observed at the reference
/// slot.
uint256[] stakingModuleIdsWithNewlyExitedValidators;
/// @dev Number of ever exited validators for each of the staking modules from
/// the stakingModuleIdsWithNewlyExitedValidators array as observed at the
/// reference slot.
uint256[] numExitedValidatorsByStakingModule;
///
/// EL values
///
/// @dev The ETH balance of the Lido withdrawal vault as observed at the reference slot.
uint256 withdrawalVaultBalance;
/// @dev The ETH balance of the Lido execution layer rewards vault as observed
/// at the reference slot.
uint256 elRewardsVaultBalance;
/// @dev The shares amount requested to burn through Burner as observed
/// at the reference slot. The value can be obtained in the following way:
/// `(coverSharesToBurn, nonCoverSharesToBurn) = IBurner(burner).getSharesRequestedToBurn()
/// sharesRequestedToBurn = coverSharesToBurn + nonCoverSharesToBurn`
uint256 sharesRequestedToBurn;
///
/// Decision
///
/// @dev The ascendingly-sorted array of withdrawal request IDs obtained by calling
/// WithdrawalQueue.calculateFinalizationBatches. Empty array means that no withdrawal
/// requests should be finalized.
uint256[] withdrawalFinalizationBatches;
/// @dev The share/ETH rate with the 10^27 precision (i.e. the price of one stETH share
/// in ETH where one ETH is denominated as 10^27) that would be effective as the result of
/// applying this oracle report at the reference slot, with withdrawalFinalizationBatches
/// set to empty array and simulatedShareRate set to 0.
uint256 simulatedShareRate;
/// @dev Whether, based on the state observed at the reference slot, the protocol should
/// be in the bunker mode.
bool isBunkerMode;
///
/// Extra data — the oracle information that allows asynchronous processing, potentially in
/// chunks, after the main data is processed. The oracle doesn't enforce that extra data
/// attached to some data report is processed in full before the processing deadline expires
/// or a new data report starts being processed, but enforces that no processing of extra
/// data for a report is possible after its processing deadline passes or a new data report
/// arrives.
///
/// Extra data is an array of items, each item being encoded as follows:
///
/// 3 bytes 2 bytes X bytes
/// | itemIndex | itemType | itemPayload |
///
/// itemIndex is a 0-based index into the extra data array;
/// itemType is the type of extra data item;
/// itemPayload is the item's data which interpretation depends on the item's type.
///
/// Items should be sorted ascendingly by the (itemType, ...itemSortingKey) compound key
/// where `itemSortingKey` calculation depends on the item's type (see below).
///
/// ----------------------------------------------------------------------------------------
///
/// itemType=0 (EXTRA_DATA_TYPE_STUCK_VALIDATORS): stuck validators by node operators.
/// itemPayload format:
///
/// | 3 bytes | 8 bytes | nodeOpsCount * 8 bytes | nodeOpsCount * 16 bytes |
/// | moduleId | nodeOpsCount | nodeOperatorIds | stuckValidatorsCounts |
///
/// moduleId is the staking module for which exited keys counts are being reported.
///
/// nodeOperatorIds contains an array of ids of node operators that have total stuck
/// validators counts changed compared to the staking module smart contract storage as
/// observed at the reference slot. Each id is a 8-byte uint, ids are packed tightly.
///
/// nodeOpsCount contains the number of node operator ids contained in the nodeOperatorIds
/// array. Thus, nodeOpsCount = byteLength(nodeOperatorIds) / 8.
///
/// stuckValidatorsCounts contains an array of stuck validators total counts, as observed at
/// the reference slot, for the node operators from the nodeOperatorIds array, in the same
/// order. Each count is a 16-byte uint, counts are packed tightly. Thus,
/// byteLength(stuckValidatorsCounts) = nodeOpsCount * 16.
///
/// nodeOpsCount must not be greater than maxAccountingExtraDataListItemsCount specified
/// in OracleReportSanityChecker contract. If a staking module has more node operators
/// with total stuck validators counts changed compared to the staking module smart contract
/// storage (as observed at the reference slot), reporting for that module should be split
/// into multiple items.
///
/// Item sorting key is a compound key consisting of the module id and the first reported
/// node operator's id:
///
/// itemSortingKey = (moduleId, nodeOperatorIds[0:8])
///
/// ----------------------------------------------------------------------------------------
///
/// itemType=1 (EXTRA_DATA_TYPE_EXITED_VALIDATORS): exited validators by node operators.
///
/// The payload format is exactly the same as for itemType=EXTRA_DATA_TYPE_STUCK_VALIDATORS,
/// except that, instead of stuck validators counts, exited validators counts are reported.
/// The `itemSortingKey` is calculated identically.
///
/// ----------------------------------------------------------------------------------------
///
/// The oracle daemon should report exited/stuck validators counts ONLY for those
/// (moduleId, nodeOperatorId) pairs that contain outdated counts in the staking
/// module smart contract as observed at the reference slot.
///
/// Extra data array can be passed in different formats, see below.
///
/// @dev Format of the extra data.
///
/// Currently, only the EXTRA_DATA_FORMAT_EMPTY=0 and EXTRA_DATA_FORMAT_LIST=1
/// formats are supported. See the constant defining a specific data format for
/// more info.
///
uint256 extraDataFormat;
/// @dev Hash of the extra data. See the constant defining a specific extra data
/// format for the info on how to calculate the hash.
///
/// Must be set to a zero hash if the oracle report contains no extra data.
///
bytes32 extraDataHash;
/// @dev Number of the extra data items.
///
/// Must be set to zero if the oracle report contains no extra data.
///
uint256 extraDataItemsCount;
}
uint256 public constant EXTRA_DATA_TYPE_STUCK_VALIDATORS = 1;
uint256 public constant EXTRA_DATA_TYPE_EXITED_VALIDATORS = 2;
/// @notice The extra data format used to signify that the oracle report contains no extra data.
///
uint256 public constant EXTRA_DATA_FORMAT_EMPTY = 0;
/// @notice The list format for the extra data array. Used when all extra data processing
/// fits into a single transaction.
///
/// Extra data is passed within a single transaction as a bytearray containing all data items
/// packed tightly.
///
/// Hash is a keccak256 hash calculated over the bytearray items. The Solidity equivalent of
/// the hash calculation code would be `keccak256(array)`, where `array` has the `bytes` type.
///
uint256 public constant EXTRA_DATA_FORMAT_LIST = 1;
/// @notice Submits report data for processing.
///
/// @param data The data. See the `ReportData` structure's docs for details.
/// @param contractVersion Expected version of the oracle contract.
///
/// Reverts if:
/// - The caller is not a member of the oracle committee and doesn't possess the
/// SUBMIT_DATA_ROLE.
/// - The provided contract version is different from the current one.
/// - The provided consensus version is different from the expected one.
/// - The provided reference slot differs from the current consensus frame's one.
/// - The processing deadline for the current consensus frame is missed.
/// - The keccak256 hash of the ABI-encoded data is different from the last hash
/// provided by the hash consensus contract.
/// - The provided data doesn't meet safety checks.
///
function submitReportData(ReportData calldata data, uint256 contractVersion) external {
_checkMsgSenderIsAllowedToSubmitData();
_checkContractVersion(contractVersion);
_checkConsensusData(data.refSlot, data.consensusVersion, keccak256(abi.encode(data)));
uint256 prevRefSlot = _startProcessing();
_handleConsensusReportData(data, prevRefSlot);
}
/// @notice Triggers the processing required when no extra data is present in the report,
/// i.e. when extra data format equals EXTRA_DATA_FORMAT_EMPTY.
///
function submitReportExtraDataEmpty() external {
_submitReportExtraDataEmpty();
}
/// @notice Submits report extra data in the EXTRA_DATA_FORMAT_LIST format for processing.
///
/// @param items The extra data items list. See docs for the `EXTRA_DATA_FORMAT_LIST`
/// constant for details.
///
function submitReportExtraDataList(bytes calldata items) external {
_submitReportExtraDataList(items);
}
struct ProcessingState {
/// @notice Reference slot for the current reporting frame.
uint256 currentFrameRefSlot;
/// @notice The last time at which a data can be submitted for the current reporting frame.
uint256 processingDeadlineTime;
/// @notice Hash of the main report data. Zero bytes if consensus on the hash hasn't been
/// reached yet for the current reporting frame.
bytes32 mainDataHash;
/// @notice Whether the main report data for the current reporting frame has already been
/// submitted.
bool mainDataSubmitted;
/// @notice Hash of the extra report data. Should be ignored unless `mainDataSubmitted`
/// is true.
bytes32 extraDataHash;
/// @notice Format of the extra report data for the current reporting frame. Should be
/// ignored unless `mainDataSubmitted` is true.
uint256 extraDataFormat;
/// @notice Whether any extra report data for the current reporting frame has been submitted.
bool extraDataSubmitted;
/// @notice Total number of extra report data items for the current reporting frame.
/// Should be ignored unless `mainDataSubmitted` is true.
uint256 extraDataItemsCount;
/// @notice How many extra report data items are already submitted for the current
/// reporting frame.
uint256 extraDataItemsSubmitted;
}
/// @notice Returns data processing state for the current reporting frame.
/// @return result See the docs for the `ProcessingState` struct.
///
function getProcessingState() external view returns (ProcessingState memory result) {
ConsensusReport memory report = _storageConsensusReport().value;
result.currentFrameRefSlot = _getCurrentRefSlot();
if (report.hash == bytes32(0) || result.currentFrameRefSlot != report.refSlot) {
return result;
}
result.processingDeadlineTime = report.processingDeadlineTime;
result.mainDataHash = report.hash;
uint256 processingRefSlot = LAST_PROCESSING_REF_SLOT_POSITION.getStorageUint256();
result.mainDataSubmitted = report.refSlot == processingRefSlot;
if (!result.mainDataSubmitted) {
return result;
}
ExtraDataProcessingState memory extraState = _storageExtraDataProcessingState().value;
result.extraDataHash = extraState.dataHash;
result.extraDataFormat = extraState.dataFormat;
result.extraDataSubmitted = extraState.submitted;
result.extraDataItemsCount = extraState.itemsCount;
result.extraDataItemsSubmitted = extraState.itemsProcessed;
}
///
/// Implementation & helpers
///
/// @dev Returns last processed reference slot of the legacy oracle.
///
/// Old oracle didn't specify what slot use as a reference one, but actually
/// used the first slot of the first frame's epoch. The new oracle uses the
/// last slot of the previous frame's last epoch as a reference one.
///
/// Oracle migration scheme:
///
/// last old frame <--------->
/// old frames |r . . |
/// new frames r| . . r| . . r|
/// first new frame <--------->
/// events 0 1 2 3 4
/// time ------------------------------------------------>
///
/// 0. last reference slot of legacy oracle
/// 1. last legacy oracle's consensus report arrives
/// 2. new oracle is deployed and enabled, legacy oracle is disabled and upgraded to
/// the compatibility implementation
/// 3. first reference slot of the new oracle
/// 4. first new oracle's consensus report arrives
///
function _checkOracleMigration(
address legacyOracle,
address consensusContract
)
internal view returns (uint256)
{
(uint256 initialEpoch,
uint256 epochsPerFrame) = IConsensusContract(consensusContract).getFrameConfig();
(uint256 slotsPerEpoch,
uint256 secondsPerSlot,
uint256 genesisTime) = IConsensusContract(consensusContract).getChainConfig();
{
// check chain spec to match the prev. one (a block is used to reduce stack allocation)
(uint256 legacyEpochsPerFrame,
uint256 legacySlotsPerEpoch,
uint256 legacySecondsPerSlot,
uint256 legacyGenesisTime) = ILegacyOracle(legacyOracle).getBeaconSpec();
if (slotsPerEpoch != legacySlotsPerEpoch ||
secondsPerSlot != legacySecondsPerSlot ||
genesisTime != legacyGenesisTime
) {
revert IncorrectOracleMigration(0);
}
if (epochsPerFrame != legacyEpochsPerFrame) {
revert IncorrectOracleMigration(1);
}
}
uint256 legacyProcessedEpoch = ILegacyOracle(legacyOracle).getLastCompletedEpochId();
if (initialEpoch != legacyProcessedEpoch + epochsPerFrame) {
revert IncorrectOracleMigration(2);
}
// last processing ref. slot of the new oracle should be set to the last processed
// ref. slot of the legacy oracle, i.e. the first slot of the last processed epoch
return legacyProcessedEpoch * slotsPerEpoch;
}
function _initialize(
address admin,
address consensusContract,
uint256 consensusVersion,
uint256 lastProcessingRefSlot
) internal {
_setupRole(DEFAULT_ADMIN_ROLE, admin);
BaseOracle._initialize(consensusContract, consensusVersion, lastProcessingRefSlot);
}
function _handleConsensusReport(
ConsensusReport memory /* report */,
uint256 /* prevSubmittedRefSlot */,
uint256 prevProcessingRefSlot
) internal override {
ExtraDataProcessingState memory state = _storageExtraDataProcessingState().value;
if (state.refSlot == prevProcessingRefSlot && (
!state.submitted || state.itemsProcessed < state.itemsCount
)) {
emit WarnExtraDataIncompleteProcessing(
prevProcessingRefSlot,
state.itemsProcessed,
state.itemsCount
);
}
}
function _checkMsgSenderIsAllowedToSubmitData() internal view {
address sender = _msgSender();
if (!hasRole(SUBMIT_DATA_ROLE, sender) && !_isConsensusMember(sender)) {
revert SenderNotAllowed();
}
}
function _handleConsensusReportData(ReportData calldata data, uint256 prevRefSlot) internal {
if (data.extraDataFormat == EXTRA_DATA_FORMAT_EMPTY) {
if (data.extraDataHash != bytes32(0)) {
revert UnexpectedExtraDataHash(bytes32(0), data.extraDataHash);
}
if (data.extraDataItemsCount != 0) {
revert UnexpectedExtraDataItemsCount(0, data.extraDataItemsCount);
}
} else {
if (data.extraDataFormat != EXTRA_DATA_FORMAT_LIST) {
revert UnsupportedExtraDataFormat(data.extraDataFormat);
}
if (data.extraDataItemsCount == 0) {
revert ExtraDataItemsCountCannotBeZeroForNonEmptyData();
}
if (data.extraDataHash == bytes32(0)) {
revert ExtraDataHashCannotBeZeroForNonEmptyData();
}
}
IOracleReportSanityChecker(LOCATOR.oracleReportSanityChecker())
.checkAccountingExtraDataListItemsCount(data.extraDataItemsCount);
ILegacyOracle(LEGACY_ORACLE).handleConsensusLayerReport(
data.refSlot,
data.clBalanceGwei * 1e9,
data.numValidators
);
uint256 slotsElapsed = data.refSlot - prevRefSlot;
IStakingRouter stakingRouter = IStakingRouter(LOCATOR.stakingRouter());
IWithdrawalQueue withdrawalQueue = IWithdrawalQueue(LOCATOR.withdrawalQueue());
_processStakingRouterExitedValidatorsByModule(
stakingRouter,
data.stakingModuleIdsWithNewlyExitedValidators,
data.numExitedValidatorsByStakingModule,
slotsElapsed
);
withdrawalQueue.onOracleReport(
data.isBunkerMode,
GENESIS_TIME + prevRefSlot * SECONDS_PER_SLOT,
GENESIS_TIME + data.refSlot * SECONDS_PER_SLOT
);
ILido(LIDO).handleOracleReport(
GENESIS_TIME + data.refSlot * SECONDS_PER_SLOT,
slotsElapsed * SECONDS_PER_SLOT,
data.numValidators,
data.clBalanceGwei * 1e9,
data.withdrawalVaultBalance,
data.elRewardsVaultBalance,
data.sharesRequestedToBurn,
data.withdrawalFinalizationBatches,
data.simulatedShareRate
);
_storageExtraDataProcessingState().value = ExtraDataProcessingState({
refSlot: data.refSlot.toUint64(),
dataFormat: data.extraDataFormat.toUint16(),
submitted: false,
dataHash: data.extraDataHash,
itemsCount: data.extraDataItemsCount.toUint16(),
itemsProcessed: 0,
lastSortingKey: 0
});
}
function _processStakingRouterExitedValidatorsByModule(
IStakingRouter stakingRouter,
uint256[] calldata stakingModuleIds,
uint256[] calldata numExitedValidatorsByStakingModule,
uint256 slotsElapsed
) internal {
if (stakingModuleIds.length != numExitedValidatorsByStakingModule.length) {
revert InvalidExitedValidatorsData();
}
if (stakingModuleIds.length == 0) {
return;
}
for (uint256 i = 1; i < stakingModuleIds.length;) {
if (stakingModuleIds[i] <= stakingModuleIds[i - 1]) {
revert InvalidExitedValidatorsData();
}
unchecked { ++i; }
}
for (uint256 i = 0; i < stakingModuleIds.length;) {
if (numExitedValidatorsByStakingModule[i] == 0) {
revert InvalidExitedValidatorsData();
}
unchecked { ++i; }
}
uint256 newlyExitedValidatorsCount = stakingRouter.updateExitedValidatorsCountByStakingModule(
stakingModuleIds,
numExitedValidatorsByStakingModule
);
uint256 exitedValidatorsRatePerDay =
newlyExitedValidatorsCount * (1 days) /
(SECONDS_PER_SLOT * slotsElapsed);
IOracleReportSanityChecker(LOCATOR.oracleReportSanityChecker())
.checkExitedValidatorsRatePerDay(exitedValidatorsRatePerDay);
}
function _submitReportExtraDataEmpty() internal {
ExtraDataProcessingState memory procState = _storageExtraDataProcessingState().value;
_checkCanSubmitExtraData(procState, EXTRA_DATA_FORMAT_EMPTY);
if (procState.submitted) revert ExtraDataAlreadyProcessed();
IStakingRouter(LOCATOR.stakingRouter()).onValidatorsCountsByNodeOperatorReportingFinished();
_storageExtraDataProcessingState().value.submitted = true;
emit ExtraDataSubmitted(procState.refSlot, 0, 0);
}
function _checkCanSubmitExtraData(ExtraDataProcessingState memory procState, uint256 format)
internal view
{
_checkMsgSenderIsAllowedToSubmitData();
ConsensusReport memory report = _storageConsensusReport().value;
if (report.hash == bytes32(0) || procState.refSlot != report.refSlot) {
revert CannotSubmitExtraDataBeforeMainData();
}
_checkProcessingDeadline();
if (procState.dataFormat != format) {
revert UnexpectedExtraDataFormat(procState.dataFormat, format);
}
}
struct ExtraDataIterState {
// volatile
uint256 index;
uint256 itemType;
uint256 dataOffset;
uint256 lastSortingKey;
// config
address stakingRouter;
}
function _submitReportExtraDataList(bytes calldata items) internal {
ExtraDataProcessingState memory procState = _storageExtraDataProcessingState().value;
_checkCanSubmitExtraData(procState, EXTRA_DATA_FORMAT_LIST);
if (procState.itemsProcessed == procState.itemsCount) {
revert ExtraDataAlreadyProcessed();
}
if (procState.itemsProcessed != 0) {
revert ExtraDataListOnlySupportsSingleTx();
}
bytes32 dataHash = keccak256(items);
if (dataHash != procState.dataHash) {
revert UnexpectedExtraDataHash(procState.dataHash, dataHash);
}
ExtraDataIterState memory iter = ExtraDataIterState({
index: 0,
itemType: 0,
dataOffset: 0,
lastSortingKey: 0,
stakingRouter: LOCATOR.stakingRouter()
});
_processExtraDataItems(items, iter);
uint256 itemsProcessed = iter.index + 1;
if (itemsProcessed != procState.itemsCount) {
revert UnexpectedExtraDataItemsCount(procState.itemsCount, itemsProcessed);
}
procState.submitted = true;
procState.itemsProcessed = uint64(itemsProcessed);
procState.lastSortingKey = iter.lastSortingKey;
_storageExtraDataProcessingState().value = procState;
IStakingRouter(iter.stakingRouter).onValidatorsCountsByNodeOperatorReportingFinished();
emit ExtraDataSubmitted(procState.refSlot, itemsProcessed, itemsProcessed);
}
function _processExtraDataItems(bytes calldata data, ExtraDataIterState memory iter) internal {
uint256 dataOffset = iter.dataOffset;
uint256 maxNodeOperatorsPerItem = 0;
uint256 maxNodeOperatorItemIndex = 0;
while (dataOffset < data.length) {
uint256 index;
uint256 itemType;
/// @solidity memory-safe-assembly
assembly {
// layout at the dataOffset:
// | 3 bytes | 2 bytes | X bytes |
// | itemIndex | itemType | itemPayload |
let header := calldataload(add(data.offset, dataOffset))
index := shr(232, header)
itemType := and(shr(216, header), 0xffff)
dataOffset := add(dataOffset, 5)
}
if (iter.itemType == 0) {
if (index != 0) {
revert UnexpectedExtraDataIndex(0, index);
}
} else if (index != iter.index + 1) {
revert UnexpectedExtraDataIndex(iter.index + 1, index);
}
iter.index = index;
iter.itemType = itemType;
iter.dataOffset = dataOffset;
if (itemType == EXTRA_DATA_TYPE_EXITED_VALIDATORS ||
itemType == EXTRA_DATA_TYPE_STUCK_VALIDATORS
) {
uint256 nodeOpsProcessed = _processExtraDataItem(data, iter);
if (nodeOpsProcessed > maxNodeOperatorsPerItem) {
maxNodeOperatorsPerItem = nodeOpsProcessed;
maxNodeOperatorItemIndex = index;
}
} else {
revert UnsupportedExtraDataType(index, itemType);
}
assert(iter.dataOffset > dataOffset);
dataOffset = iter.dataOffset;
}
assert(maxNodeOperatorsPerItem > 0);
IOracleReportSanityChecker(LOCATOR.oracleReportSanityChecker())
.checkNodeOperatorsPerExtraDataItemCount(maxNodeOperatorItemIndex, maxNodeOperatorsPerItem);
}
function _processExtraDataItem(bytes calldata data, ExtraDataIterState memory iter) internal returns (uint256) {
uint256 dataOffset = iter.dataOffset;
uint256 moduleId;
uint256 nodeOpsCount;
uint256 firstNodeOpId;
bytes calldata nodeOpIds;
bytes calldata valuesCounts;
if (dataOffset + 35 > data.length) {
// has to fit at least moduleId (3 bytes), nodeOpsCount (8 bytes),
// and data for one node operator (8 + 16 bytes), total 35 bytes
revert InvalidExtraDataItem(iter.index);
}
/// @solidity memory-safe-assembly
assembly {
// layout at the dataOffset:
// | 3 bytes | 8 bytes | nodeOpsCount * 8 bytes | nodeOpsCount * 16 bytes |
// | moduleId | nodeOpsCount | nodeOperatorIds | validatorsCounts |
let header := calldataload(add(data.offset, dataOffset))
moduleId := shr(232, header)
nodeOpsCount := and(shr(168, header), 0xffffffffffffffff)
nodeOpIds.offset := add(data.offset, add(dataOffset, 11))
nodeOpIds.length := mul(nodeOpsCount, 8)
firstNodeOpId := shr(192, calldataload(nodeOpIds.offset))
valuesCounts.offset := add(nodeOpIds.offset, nodeOpIds.length)
valuesCounts.length := mul(nodeOpsCount, 16)
dataOffset := sub(add(valuesCounts.offset, valuesCounts.length), data.offset)
}
if (moduleId == 0) {
revert InvalidExtraDataItem(iter.index);
}
unchecked {
// | 2 bytes | 19 bytes | 3 bytes | 8 bytes |
// | itemType | 00000000 | moduleId | firstNodeOpId |
uint256 sortingKey = (iter.itemType << 240) | (moduleId << 64) | firstNodeOpId;
if (sortingKey <= iter.lastSortingKey) {
revert InvalidExtraDataSortOrder(iter.index);
}
iter.lastSortingKey = sortingKey;
}
if (dataOffset > data.length || nodeOpsCount == 0) {
revert InvalidExtraDataItem(iter.index);
}
if (iter.itemType == EXTRA_DATA_TYPE_STUCK_VALIDATORS) {
IStakingRouter(iter.stakingRouter)
.reportStakingModuleStuckValidatorsCountByNodeOperator(moduleId, nodeOpIds, valuesCounts);
} else {
IStakingRouter(iter.stakingRouter)
.reportStakingModuleExitedValidatorsCountByNodeOperator(moduleId, nodeOpIds, valuesCounts);
}
iter.dataOffset = dataOffset;
return nodeOpsCount;
}
///
/// Storage helpers
///
struct StorageExtraDataProcessingState {
ExtraDataProcessingState value;
}
function _storageExtraDataProcessingState()
internal pure returns (StorageExtraDataProcessingState storage r)
{
bytes32 position = EXTRA_DATA_PROCESSING_STATE_POSITION;
assembly { r.slot := position }
}
}
@openzeppelin/contracts-v4.4/access/IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
@openzeppelin/contracts-v4.4/access/IAccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
/**
* @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
*/
interface IAccessControlEnumerable is IAccessControl {
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) external view returns (address);
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) external view returns (uint256);
}
@openzeppelin/contracts-v4.4/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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;
}
}
@openzeppelin/contracts-v4.4/utils/Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
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] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
@openzeppelin/contracts-v4.4/utils/introspection/ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
@openzeppelin/contracts-v4.4/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
@openzeppelin/contracts-v4.4/utils/math/SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/math/SafeCast.sol)
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128) {
require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
return int128(value);
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64) {
require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
return int64(value);
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32) {
require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
return int32(value);
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16) {
require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
return int16(value);
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8) {
require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
return int8(value);
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}
@openzeppelin/contracts-v4.4/utils/structs/EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/structs/EnumerableSet.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastvalue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastvalue;
// Update the index for the moved value
set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
return _values(set._inner);
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
assembly {
result := store
}
return result;
}
}
contracts/0.8.9/lib/Math.sol
// SPDX-FileCopyrightText: 2023 Lido <info@lido.fi>
// SPDX-License-Identifier: MIT
// See contracts/COMPILERS.md
pragma solidity 0.8.9;
library Math {
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;
}
/// @notice Tests if x ∈ [a, b) (mod n)
///
function pointInHalfOpenIntervalModN(uint256 x, uint256 a, uint256 b, uint256 n)
internal pure returns (bool)
{
return (x + n - a) % n < (b - a) % n;
}
/// @notice Tests if x ∈ [a, b] (mod n)
///
function pointInClosedIntervalModN(uint256 x, uint256 a, uint256 b, uint256 n)
internal pure returns (bool)
{
return (x + n - a) % n <= (b - a) % n;
}
}
contracts/0.8.9/lib/UnstructuredStorage.sol
/*
* SPDX-License-Identifier: MIT
*/
pragma solidity 0.8.9;
/**
* @notice Aragon Unstructured Storage library
*/
library UnstructuredStorage {
function getStorageBool(bytes32 position) internal view returns (bool data) {
assembly { data := sload(position) }
}
function getStorageAddress(bytes32 position) internal view returns (address data) {
assembly { data := sload(position) }
}
function getStorageBytes32(bytes32 position) internal view returns (bytes32 data) {
assembly { data := sload(position) }
}
function getStorageUint256(bytes32 position) internal view returns (uint256 data) {
assembly { data := sload(position) }
}
function setStorageBool(bytes32 position, bool data) internal {
assembly { sstore(position, data) }
}
function setStorageAddress(bytes32 position, address data) internal {
assembly { sstore(position, data) }
}
function setStorageBytes32(bytes32 position, bytes32 data) internal {
assembly { sstore(position, data) }
}
function setStorageUint256(bytes32 position, uint256 data) internal {
assembly { sstore(position, data) }
}
}
contracts/0.8.9/oracle/BaseOracle.sol
// SPDX-FileCopyrightText: 2023 Lido <info@lido.fi>
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.9;
import { SafeCast } from "@openzeppelin/contracts-v4.4/utils/math/SafeCast.sol";
import { UnstructuredStorage } from "../lib/UnstructuredStorage.sol";
import { Versioned } from "../utils/Versioned.sol";
import { AccessControlEnumerable } from "../utils/access/AccessControlEnumerable.sol";
import { IReportAsyncProcessor } from "./HashConsensus.sol";
interface IConsensusContract {
function getIsMember(address addr) external view returns (bool);
function getCurrentFrame() external view returns (
uint256 refSlot,
uint256 reportProcessingDeadlineSlot
);
function getChainConfig() external view returns (
uint256 slotsPerEpoch,
uint256 secondsPerSlot,
uint256 genesisTime
);
function getFrameConfig() external view returns (uint256 initialEpoch, uint256 epochsPerFrame);
function getInitialRefSlot() external view returns (uint256);
}
abstract contract BaseOracle is IReportAsyncProcessor, AccessControlEnumerable, Versioned {
using UnstructuredStorage for bytes32;
using SafeCast for uint256;
error AddressCannotBeZero();
error AddressCannotBeSame();
error VersionCannotBeSame();
error UnexpectedChainConfig();
error SenderIsNotTheConsensusContract();
error InitialRefSlotCannotBeLessThanProcessingOne(uint256 initialRefSlot, uint256 processingRefSlot);
error RefSlotMustBeGreaterThanProcessingOne(uint256 refSlot, uint256 processingRefSlot);
error RefSlotCannotDecrease(uint256 refSlot, uint256 prevRefSlot);
error NoConsensusReportToProcess();
error ProcessingDeadlineMissed(uint256 deadline);
error RefSlotAlreadyProcessing();
error UnexpectedRefSlot(uint256 consensusRefSlot, uint256 dataRefSlot);
error UnexpectedConsensusVersion(uint256 expectedVersion, uint256 receivedVersion);
error HashCannotBeZero();
error UnexpectedDataHash(bytes32 consensusHash, bytes32 receivedHash);
error SecondsPerSlotCannotBeZero();
event ConsensusHashContractSet(address indexed addr, address indexed prevAddr);
event ConsensusVersionSet(uint256 indexed version, uint256 indexed prevVersion);
event ReportSubmitted(uint256 indexed refSlot, bytes32 hash, uint256 processingDeadlineTime);
event ReportDiscarded(uint256 indexed refSlot, bytes32 hash);
event ProcessingStarted(uint256 indexed refSlot, bytes32 hash);
event WarnProcessingMissed(uint256 indexed refSlot);
struct ConsensusReport {
bytes32 hash;
uint64 refSlot;
uint64 processingDeadlineTime;
}
/// @notice An ACL role granting the permission to set the consensus
/// contract address by calling setConsensusContract.
bytes32 public constant MANAGE_CONSENSUS_CONTRACT_ROLE =
keccak256("MANAGE_CONSENSUS_CONTRACT_ROLE");
/// @notice An ACL role granting the permission to set the consensus
/// version by calling setConsensusVersion.
bytes32 public constant MANAGE_CONSENSUS_VERSION_ROLE =
keccak256("MANAGE_CONSENSUS_VERSION_ROLE");
/// @dev Storage slot: address consensusContract
bytes32 internal constant CONSENSUS_CONTRACT_POSITION =
keccak256("lido.BaseOracle.consensusContract");
/// @dev Storage slot: uint256 consensusVersion
bytes32 internal constant CONSENSUS_VERSION_POSITION =
keccak256("lido.BaseOracle.consensusVersion");
/// @dev Storage slot: uint256 lastProcessingRefSlot
bytes32 internal constant LAST_PROCESSING_REF_SLOT_POSITION =
keccak256("lido.BaseOracle.lastProcessingRefSlot");
/// @dev Storage slot: ConsensusReport consensusReport
bytes32 internal constant CONSENSUS_REPORT_POSITION =
keccak256("lido.BaseOracle.consensusReport");
uint256 public immutable SECONDS_PER_SLOT;
uint256 public immutable GENESIS_TIME;
///
/// Initialization & admin functions
///
constructor(uint256 secondsPerSlot, uint256 genesisTime) {
if (secondsPerSlot == 0) revert SecondsPerSlotCannotBeZero();
SECONDS_PER_SLOT = secondsPerSlot;
GENESIS_TIME = genesisTime;
}
/// @notice Returns the address of the HashConsensus contract.
///
function getConsensusContract() external view returns (address) {
return CONSENSUS_CONTRACT_POSITION.getStorageAddress();
}
/// @notice Sets the address of the HashConsensus contract.
///
function setConsensusContract(address addr) external onlyRole(MANAGE_CONSENSUS_CONTRACT_ROLE) {
_setConsensusContract(addr, LAST_PROCESSING_REF_SLOT_POSITION.getStorageUint256());
}
/// @notice Returns the current consensus version expected by the oracle contract.
///
/// Consensus version must change every time consensus rules change, meaning that
/// an oracle looking at the same reference slot would calculate a different hash.
///
function getConsensusVersion() external view returns (uint256) {
return CONSENSUS_VERSION_POSITION.getStorageUint256();
}
/// @notice Sets the consensus version expected by the oracle contract.
///
function setConsensusVersion(uint256 version) external onlyRole(MANAGE_CONSENSUS_VERSION_ROLE) {
_setConsensusVersion(version);
}
///
/// Data provider interface
///
/// @notice Returns the last consensus report hash and metadata.
///
function getConsensusReport() external view returns (
bytes32 hash,
uint256 refSlot,
uint256 processingDeadlineTime,
bool processingStarted
) {
ConsensusReport memory report = _storageConsensusReport().value;
uint256 processingRefSlot = LAST_PROCESSING_REF_SLOT_POSITION.getStorageUint256();
return (
report.hash,
report.refSlot,
report.processingDeadlineTime,
report.hash != bytes32(0) && report.refSlot == processingRefSlot
);
}
///
/// Consensus contract interface
///
/// @notice Called by HashConsensus contract to push a consensus report for processing.
///
/// Note that submitting the report doesn't require the processor to start processing it right
/// away, this can happen later (see `getLastProcessingRefSlot`). Until processing is started,
/// HashConsensus is free to reach consensus on another report for the same reporting frame an
/// submit it using this same function, or to lose the consensus on the submitted report,
/// notifying the processor via `discardConsensusReport`.
///
function submitConsensusReport(bytes32 reportHash, uint256 refSlot, uint256 deadline) external {
_checkSenderIsConsensusContract();
uint256 prevSubmittedRefSlot = _storageConsensusReport().value.refSlot;
if (refSlot < prevSubmittedRefSlot) {
revert RefSlotCannotDecrease(refSlot, prevSubmittedRefSlot);
}
uint256 prevProcessingRefSlot = LAST_PROCESSING_REF_SLOT_POSITION.getStorageUint256();
if (refSlot <= prevProcessingRefSlot) {
revert RefSlotMustBeGreaterThanProcessingOne(refSlot, prevProcessingRefSlot);
}
if (_getTime() > deadline) {
revert ProcessingDeadlineMissed(deadline);
}
if (refSlot != prevSubmittedRefSlot && prevProcessingRefSlot != prevSubmittedRefSlot) {
emit WarnProcessingMissed(prevSubmittedRefSlot);
}
if (reportHash == bytes32(0)) {
revert HashCannotBeZero();
}
emit ReportSubmitted(refSlot, reportHash, deadline);
ConsensusReport memory report = ConsensusReport({
hash: reportHash,
refSlot: refSlot.toUint64(),
processingDeadlineTime: deadline.toUint64()
});
_storageConsensusReport().value = report;
_handleConsensusReport(report, prevSubmittedRefSlot, prevProcessingRefSlot);
}
/// @notice Called by HashConsensus contract to notify that the report for the given ref. slot
/// is not a conensus report anymore and should be discarded. This can happen when a member
/// changes their report, is removed from the set, or when the quorum value gets increased.
///
/// Only called when, for the given reference slot:
///
/// 1. there previously was a consensus report; AND
/// 1. processing of the consensus report hasn't started yet; AND
/// 2. report processing deadline is not expired yet; AND
/// 3. there's no consensus report now (otherwise, `submitConsensusReport` is called instead).
///
/// Can be called even when there's no submitted non-discarded consensus report for the current
/// reference slot, i.e. can be called multiple times in succession.
///
function discardConsensusReport(uint256 refSlot) external {
_checkSenderIsConsensusContract();
ConsensusReport memory submittedReport = _storageConsensusReport().value;
if (refSlot < submittedReport.refSlot) {
revert RefSlotCannotDecrease(refSlot, submittedReport.refSlot);
} else if (refSlot > submittedReport.refSlot) {
return;
}
uint256 lastProcessingRefSlot = LAST_PROCESSING_REF_SLOT_POSITION.getStorageUint256();
if (refSlot <= lastProcessingRefSlot) {
revert RefSlotAlreadyProcessing();
}
_storageConsensusReport().value.hash = bytes32(0);
_handleConsensusReportDiscarded(submittedReport);
emit ReportDiscarded(submittedReport.refSlot, submittedReport.hash);
}
/// @notice Returns the last reference slot for which processing of the report was started.
///
function getLastProcessingRefSlot() external view returns (uint256) {
return LAST_PROCESSING_REF_SLOT_POSITION.getStorageUint256();
}
///
/// Descendant contract interface
///
/// @notice Initializes the contract storage. Must be called by a descendant
/// contract as part of its initialization.
///
function _initialize(
address consensusContract,
uint256 consensusVersion,
uint256 lastProcessingRefSlot
) internal virtual {
_initializeContractVersionTo(1);
_setConsensusContract(consensusContract, lastProcessingRefSlot);
_setConsensusVersion(consensusVersion);
LAST_PROCESSING_REF_SLOT_POSITION.setStorageUint256(lastProcessingRefSlot);
_storageConsensusReport().value.refSlot = lastProcessingRefSlot.toUint64();
}
/// @notice Returns whether the given address is a member of the oracle committee.
///
function _isConsensusMember(address addr) internal view returns (bool) {
address consensus = CONSENSUS_CONTRACT_POSITION.getStorageAddress();
return IConsensusContract(consensus).getIsMember(addr);
}
/// @notice Called when the oracle gets a new consensus report from the HashConsensus contract.
///
/// Keep in mind that, until you call `_startProcessing`, the oracle committee is free to
/// reach consensus on another report for the same reporting frame and re-submit it using
/// this function, or lose consensus on the report and ask to discard it by calling the
/// `_handleConsensusReportDiscarded` function.
///
function _handleConsensusReport(
ConsensusReport memory report,
uint256 prevSubmittedRefSlot,
uint256 prevProcessingRefSlot
) internal virtual;
/// @notice Called when the HashConsensus contract loses consensus on a previously submitted
/// report that is not processing yet and asks to discard this report. Only called if there is
/// no new consensus report at the moment; otherwise, `_handleConsensusReport` is called instead.
///
function _handleConsensusReportDiscarded(ConsensusReport memory report) internal virtual {}
/// @notice May be called by a descendant contract to check if the received data matches
/// the currently submitted consensus report. Reverts otherwise.
///
function _checkConsensusData(uint256 refSlot, uint256 consensusVersion, bytes32 hash)
internal view
{
ConsensusReport memory report = _storageConsensusReport().value;
if (refSlot != report.refSlot) {
revert UnexpectedRefSlot(report.refSlot, refSlot);
}
uint256 expectedConsensusVersion = CONSENSUS_VERSION_POSITION.getStorageUint256();
if (consensusVersion != expectedConsensusVersion) {
revert UnexpectedConsensusVersion(expectedConsensusVersion, consensusVersion);
}
if (hash != report.hash) {
revert UnexpectedDataHash(report.hash, hash);
}
}
/// @notice Called by a descendant contract to mark the current consensus report
/// as being processed. Returns the last ref. slot which processing was started
/// before the call.
///
/// Before this function is called, the oracle committee is free to reach consensus
/// on another report for the same reporting frame. After this function is called,
/// the consensus report for the current frame is guaranteed to remain the same.
///
function _startProcessing() internal returns (uint256) {
ConsensusReport memory report = _storageConsensusReport().value;
if (report.hash == bytes32(0)) {
revert NoConsensusReportToProcess();
}
_checkProcessingDeadline(report.processingDeadlineTime);
uint256 prevProcessingRefSlot = LAST_PROCESSING_REF_SLOT_POSITION.getStorageUint256();
if (prevProcessingRefSlot == report.refSlot) {
revert RefSlotAlreadyProcessing();
}
LAST_PROCESSING_REF_SLOT_POSITION.setStorageUint256(report.refSlot);
emit ProcessingStarted(report.refSlot, report.hash);
return prevProcessingRefSlot;
}
/// @notice Reverts if the processing deadline for the current consensus report is missed.
///
function _checkProcessingDeadline() internal view {
_checkProcessingDeadline(_storageConsensusReport().value.processingDeadlineTime);
}
function _checkProcessingDeadline(uint256 deadlineTime) internal view {
if (_getTime() > deadlineTime) revert ProcessingDeadlineMissed(deadlineTime);
}
/// @notice Returns the reference slot for the current frame.
///
function _getCurrentRefSlot() internal view returns (uint256) {
address consensusContract = CONSENSUS_CONTRACT_POSITION.getStorageAddress();
(uint256 refSlot, ) = IConsensusContract(consensusContract).getCurrentFrame();
return refSlot;
}
///
/// Implementation & helpers
///
function _setConsensusVersion(uint256 version) internal {
uint256 prevVersion = CONSENSUS_VERSION_POSITION.getStorageUint256();
if (version == prevVersion) revert VersionCannotBeSame();
CONSENSUS_VERSION_POSITION.setStorageUint256(version);
emit ConsensusVersionSet(version, prevVersion);
}
function _setConsensusContract(address addr, uint256 lastProcessingRefSlot) internal {
if (addr == address(0)) revert AddressCannotBeZero();
address prevAddr = CONSENSUS_CONTRACT_POSITION.getStorageAddress();
if (addr == prevAddr) revert AddressCannotBeSame();
(, uint256 secondsPerSlot, uint256 genesisTime) = IConsensusContract(addr).getChainConfig();
if (secondsPerSlot != SECONDS_PER_SLOT || genesisTime != GENESIS_TIME) {
revert UnexpectedChainConfig();
}
uint256 initialRefSlot = IConsensusContract(addr).getInitialRefSlot();
if (initialRefSlot < lastProcessingRefSlot) {
revert InitialRefSlotCannotBeLessThanProcessingOne(initialRefSlot, lastProcessingRefSlot);
}
CONSENSUS_CONTRACT_POSITION.setStorageAddress(addr);
emit ConsensusHashContractSet(addr, prevAddr);
}
function _checkSenderIsConsensusContract() internal view {
if (_msgSender() != CONSENSUS_CONTRACT_POSITION.getStorageAddress()) {
revert SenderIsNotTheConsensusContract();
}
}
function _getTime() internal virtual view returns (uint256) {
return block.timestamp; // solhint-disable-line not-rely-on-time
}
///
/// Storage helpers
///
struct StorageConsensusReport {
ConsensusReport value;
}
function _storageConsensusReport() internal pure returns (StorageConsensusReport storage r) {
bytes32 position = CONSENSUS_REPORT_POSITION;
assembly { r.slot := position }
}
}
contracts/0.8.9/oracle/HashConsensus.sol
// SPDX-FileCopyrightText: 2023 Lido <info@lido.fi>
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.9;
import { SafeCast } from "@openzeppelin/contracts-v4.4/utils/math/SafeCast.sol";
import { Math } from "../lib/Math.sol";
import { AccessControlEnumerable } from "../utils/access/AccessControlEnumerable.sol";
/// @notice A contract that gets consensus reports (i.e. hashes) pushed to and processes them
/// asynchronously.
///
/// HashConsensus doesn't expect any specific behavior from a report processor, and guarantees
/// the following:
///
/// 1. HashConsensus won't submit reports via `IReportAsyncProcessor.submitConsensusReport` or ask
/// to discard reports via `IReportAsyncProcessor.discardConsensusReport` for any slot up to (and
/// including) the slot returned from `IReportAsyncProcessor.getLastProcessingRefSlot`.
///
/// 2. HashConsensus won't accept member reports (and thus won't include such reports in calculating
/// the consensus) that have `consensusVersion` argument of the `HashConsensus.submitReport` call
/// holding a diff. value than the one returned from `IReportAsyncProcessor.getConsensusVersion()`
/// at the moment of the `HashConsensus.submitReport` call.
///
interface IReportAsyncProcessor {
/// @notice Submits a consensus report for processing.
///
/// Note that submitting the report doesn't require the processor to start processing it right
/// away, this can happen later (see `getLastProcessingRefSlot`). Until processing is started,
/// HashConsensus is free to reach consensus on another report for the same reporting frame an
/// submit it using this same function, or to lose the consensus on the submitted report,
/// notifying the processor via `discardConsensusReport`.
///
function submitConsensusReport(bytes32 report, uint256 refSlot, uint256 deadline) external;
/// @notice Notifies that the report for the given ref. slot is not a conensus report anymore
/// and should be discarded. This can happen when a member changes their report, is removed
/// from the set, or when the quorum value gets increased.
///
/// Only called when, for the given reference slot:
///
/// 1. there previously was a consensus report; AND
/// 1. processing of the consensus report hasn't started yet; AND
/// 2. report processing deadline is not expired yet; AND
/// 3. there's no consensus report now (otherwise, `submitConsensusReport` is called instead).
///
/// Can be called even when there's no submitted non-discarded consensus report for the current
/// reference slot, i.e. can be called multiple times in succession.
///
function discardConsensusReport(uint256 refSlot) external;
/// @notice Returns the last reference slot for which processing of the report was started.
///
/// HashConsensus won't submit reports for any slot less than or equal to this slot.
///
function getLastProcessingRefSlot() external view returns (uint256);
/// @notice Returns the current consensus version.
///
/// Consensus version must change every time consensus rules change, meaning that
/// an oracle looking at the same reference slot would calculate a different hash.
///
/// HashConsensus won't accept member reports any consensus version different form the
/// one returned from this function.
///
function getConsensusVersion() external view returns (uint256);
}
/// @notice A contract managing oracle members committee and allowing the members to reach
/// consensus on a hash for each reporting frame.
///
/// Time is divided in frames of equal length, each having reference slot and processing
/// deadline. Report data must be gathered by looking at the world state at the moment of
/// the frame's reference slot (including any state changes made in that slot), and must
/// be processed before the frame's processing deadline.
///
/// Frame length is defined in Ethereum consensus layer epochs. Reference slot for each
/// frame is set to the last slot of the epoch preceding the frame's first epoch. The
/// processing deadline is set to the last slot of the last epoch of the frame.
///
/// This means that all state changes a report processing could entail are guaranteed to be
/// observed while gathering data for the next frame's report. This is an important property
/// given that oracle reports sometimes have to contain diffs instead of the full state which
/// might be impractical or even impossible to transmit and process.
///
contract HashConsensus is AccessControlEnumerable {
using SafeCast for uint256;
error InvalidChainConfig();
error NumericOverflow();
error AdminCannotBeZero();
error ReportProcessorCannotBeZero();
error DuplicateMember();
error AddressCannotBeZero();
error InitialEpochIsYetToArrive();
error InitialEpochAlreadyArrived();
error InitialEpochRefSlotCannotBeEarlierThanProcessingSlot();
error EpochsPerFrameCannotBeZero();
error NonMember();
error UnexpectedConsensusVersion(uint256 expected, uint256 received);
error QuorumTooSmall(uint256 minQuorum, uint256 receivedQuorum);
error InvalidSlot();
error DuplicateReport();
error EmptyReport();
error StaleReport();
error NonFastLaneMemberCannotReportWithinFastLaneInterval();
error NewProcessorCannotBeTheSame();
error ConsensusReportAlreadyProcessing();
error FastLanePeriodCannotBeLongerThanFrame();
event FrameConfigSet(uint256 newInitialEpoch, uint256 newEpochsPerFrame);
event FastLaneConfigSet(uint256 fastLaneLengthSlots);
event MemberAdded(address indexed addr, uint256 newTotalMembers, uint256 newQuorum);
event MemberRemoved(address indexed addr, uint256 newTotalMembers, uint256 newQuorum);
event QuorumSet(uint256 newQuorum, uint256 totalMembers, uint256 prevQuorum);
event ReportReceived(uint256 indexed refSlot, address indexed member, bytes32 report);
event ConsensusReached(uint256 indexed refSlot, bytes32 report, uint256 support);
event ConsensusLost(uint256 indexed refSlot);
event ReportProcessorSet(address indexed processor, address indexed prevProcessor);
struct FrameConfig {
uint64 initialEpoch;
uint64 epochsPerFrame;
uint64 fastLaneLengthSlots;
}
/// @dev Oracle reporting is divided into frames, each lasting the same number of slots.
///
/// The start slot of the next frame is always the next slot after the end slot of the previous
/// frame.
///
/// Each frame also has a reference slot: if the oracle report contains any data derived from
/// onchain data, the onchain data should be sampled at the reference slot.
///
struct ConsensusFrame {
// frame index; increments by 1 with each frame but resets to zero on frame size change
uint256 index;
// the slot at which to read the state around which consensus is being reached;
// if the slot contains a block, the state should include all changes from that block
uint256 refSlot;
// the last slot at which a report can be reported and processed
uint256 reportProcessingDeadlineSlot;
}
struct ReportingState {
// the last reference slot any report was received for
uint64 lastReportRefSlot;
// the last reference slot a consensus was reached for
uint64 lastConsensusRefSlot;
// the last consensus variant index
uint64 lastConsensusVariantIndex;
}
struct MemberState {
// the last reference slot a report from this member was received for
uint64 lastReportRefSlot;
// the variant index of the last report from this member
uint64 lastReportVariantIndex;
}
struct ReportVariant {
// the reported hash
bytes32 hash;
// how many unique members from the current set reported this hash in the current frame
uint64 support;
}
/// @notice An ACL role granting the permission to modify members list members and
/// change the quorum by calling addMember, removeMember, and setQuorum functions.
bytes32 public constant MANAGE_MEMBERS_AND_QUORUM_ROLE =
keccak256("MANAGE_MEMBERS_AND_QUORUM_ROLE");
/// @notice An ACL role granting the permission to disable the consensus by calling
/// the disableConsensus function. Enabling the consensus back requires the possession
/// of the MANAGE_QUORUM_ROLE.
bytes32 public constant DISABLE_CONSENSUS_ROLE = keccak256("DISABLE_CONSENSUS_ROLE");
/// @notice An ACL role granting the permission to change reporting interval duration
/// and fast lane reporting interval length by calling setFrameConfig.
bytes32 public constant MANAGE_FRAME_CONFIG_ROLE = keccak256("MANAGE_FRAME_CONFIG_ROLE");
/// @notice An ACL role granting the permission to change fast lane reporting interval
/// length by calling setFastLaneLengthSlots.
bytes32 public constant MANAGE_FAST_LANE_CONFIG_ROLE = keccak256("MANAGE_FAST_LANE_CONFIG_ROLE");
/// @notice An ACL role granting the permission to change еру report processor
/// contract by calling setReportProcessor.
bytes32 public constant MANAGE_REPORT_PROCESSOR_ROLE = keccak256("MANAGE_REPORT_PROCESSOR_ROLE");
/// Chain specification
uint64 internal immutable SLOTS_PER_EPOCH;
uint64 internal immutable SECONDS_PER_SLOT;
uint64 internal immutable GENESIS_TIME;
/// @dev A quorum value that effectively disables the oracle.
uint256 internal constant UNREACHABLE_QUORUM = type(uint256).max;
bytes32 internal constant ZERO_HASH = bytes32(0);
/// @dev An offset from the processing deadline slot of the previous frame (i.e. the last slot
/// at which a report for the prev. frame can be submitted and its processing started) to the
/// reference slot of the next frame (equal to the last slot of the previous frame).
/// frame[i].reportProcessingDeadlineSlot := frame[i + 1].refSlot - DEADLINE_SLOT_OFFSET
uint256 internal constant DEADLINE_SLOT_OFFSET = 0;
/// @dev Reporting frame configuration
FrameConfig internal _frameConfig;
/// @dev Oracle committee members states array
MemberState[] internal _memberStates;
/// @dev Oracle committee members' addresses array
address[] internal _memberAddresses;
/// @dev Mapping from an oracle committee member address to the 1-based index in the
/// members array
mapping(address => uint256) internal _memberIndices1b;
/// @dev A structure containing the last reference slot any report was received for, the last
/// reference slot consensus report was achieved for, and the last consensus variant index
ReportingState internal _reportingState;
/// @dev Oracle committee members quorum value, must be larger than totalMembers // 2
uint256 internal _quorum;
/// @dev Mapping from a report variant index to the ReportVariant structure
mapping(uint256 => ReportVariant) internal _reportVariants;
/// @dev The number of report variants
uint256 internal _reportVariantsLength;
/// @dev The address of the report processor contract
address internal _reportProcessor;
///
/// Initialization
///
constructor(
uint256 slotsPerEpoch,
uint256 secondsPerSlot,
uint256 genesisTime,
uint256 epochsPerFrame,
uint256 fastLaneLengthSlots,
address admin,
address reportProcessor
) {
if (slotsPerEpoch == 0) revert InvalidChainConfig();
if (secondsPerSlot == 0) revert InvalidChainConfig();
SLOTS_PER_EPOCH = slotsPerEpoch.toUint64();
SECONDS_PER_SLOT = secondsPerSlot.toUint64();
GENESIS_TIME = genesisTime.toUint64();
if (admin == address(0)) revert AdminCannotBeZero();
if (reportProcessor == address(0)) revert ReportProcessorCannotBeZero();
_setupRole(DEFAULT_ADMIN_ROLE, admin);
uint256 farFutureEpoch = _computeEpochAtTimestamp(type(uint64).max);
_setFrameConfig(farFutureEpoch, epochsPerFrame, fastLaneLengthSlots, FrameConfig(0, 0, 0));
_reportProcessor = reportProcessor;
}
///
/// Time
///
/// @notice Returns the immutable chain parameters required to calculate epoch and slot
/// given a timestamp.
///
function getChainConfig() external view returns (
uint256 slotsPerEpoch,
uint256 secondsPerSlot,
uint256 genesisTime
) {
return (SLOTS_PER_EPOCH, SECONDS_PER_SLOT, GENESIS_TIME);
}
/// @notice Returns the time-related configuration.
///
/// @return initialEpoch Epoch of the frame with zero index.
/// @return epochsPerFrame Length of a frame in epochs.
/// @return fastLaneLengthSlots Length of the fast lane interval in slots; see `getIsFastLaneMember`.
///
function getFrameConfig() external view returns (
uint256 initialEpoch,
uint256 epochsPerFrame,
uint256 fastLaneLengthSlots
) {
FrameConfig memory config = _frameConfig;
return (config.initialEpoch, config.epochsPerFrame, config.fastLaneLengthSlots);
}
/// @notice Returns the current reporting frame.
///
/// @return refSlot The frame's reference slot: if the data the consensus is being reached upon
/// includes or depends on any onchain state, this state should be queried at the
/// reference slot. If the slot contains a block, the state should include all changes
/// from that block.
///
/// @return reportProcessingDeadlineSlot The last slot at which the report can be processed by
/// the report processor contract.
///
function getCurrentFrame() external view returns (
uint256 refSlot,
uint256 reportProcessingDeadlineSlot
) {
ConsensusFrame memory frame = _getCurrentFrame();
return (frame.refSlot, frame.reportProcessingDeadlineSlot);
}
/// @notice Returns the earliest possible reference slot, i.e. the reference slot of the
/// reporting frame with zero index.
///
function getInitialRefSlot() external view returns (uint256) {
return _getInitialFrame().refSlot;
}
/// @notice Sets a new initial epoch given that the current initial epoch is in the future.
///
/// @param initialEpoch The new initial epoch.
///
function updateInitialEpoch(uint256 initialEpoch) external onlyRole(DEFAULT_ADMIN_ROLE) {
FrameConfig memory prevConfig = _frameConfig;
if (_computeEpochAtTimestamp(_getTime()) >= prevConfig.initialEpoch) {
revert InitialEpochAlreadyArrived();
}
_setFrameConfig(
initialEpoch,
prevConfig.epochsPerFrame,
prevConfig.fastLaneLengthSlots,
prevConfig
);
if (_getInitialFrame().refSlot < _getLastProcessingRefSlot()) {
revert InitialEpochRefSlotCannotBeEarlierThanProcessingSlot();
}
}
/// @notice Updates the time-related configuration.
///
/// @param epochsPerFrame Length of a frame in epochs.
/// @param fastLaneLengthSlots Length of the fast lane interval in slots; see `getIsFastLaneMember`.
///
function setFrameConfig(uint256 epochsPerFrame, uint256 fastLaneLengthSlots)
external onlyRole(MANAGE_FRAME_CONFIG_ROLE)
{
// Updates epochsPerFrame in a way that either keeps the current reference slot the same
// or increases it by at least the minimum of old and new frame sizes.
uint256 timestamp = _getTime();
uint256 currentFrameStartEpoch = _computeFrameStartEpoch(timestamp, _frameConfig);
_setFrameConfig(currentFrameStartEpoch, epochsPerFrame, fastLaneLengthSlots, _frameConfig);
}
///
/// Members
///
/// @notice Returns whether the given address is currently a member of the consensus.
///
function getIsMember(address addr) external view returns (bool) {
return _isMember(addr);
}
/// @notice Returns whether the given address is a fast lane member for the current reporting
/// frame.
///
/// Fast lane members is a subset of all members that changes each reporting frame. These
/// members can, and are expected to, submit a report during the first part of the frame called
/// the "fast lane interval" and defined via `setFrameConfig` or `setFastLaneLengthSlots`. Under
/// regular circumstances, all other members are only allowed to submit a report after the fast
/// lane interval passes.
///
/// The fast lane subset consists of `quorum` members; selection is implemented as a sliding
/// window of the `quorum` width over member indices (mod total members). The window advances
/// by one index each reporting frame.
///
/// This is done to encourage each member from the full set to participate in reporting on a
/// regular basis, and identify any malfunctioning members.
///
/// With the fast lane mechanism active, it's sufficient for the monitoring to check that
/// consensus is consistently reached during the fast lane part of each frame to conclude that
/// all members are active and share the same consensus rules.
///
/// However, there is no guarantee that, at any given time, it holds true that only the current
/// fast lane members can or were able to report during the currently-configured fast lane
/// interval of the current frame. In particular, this assumption can be violated in any frame
/// during which the members set, initial epoch, or the quorum number was changed, or the fast
/// lane interval length was increased. Thus, the fast lane mechanism should not be used for any
/// purpose other than monitoring of the members liveness, and monitoring tools should take into
/// consideration the potential irregularities within frames with any configuration changes.
///
function getIsFastLaneMember(address addr) external view returns (bool) {
uint256 index1b = _memberIndices1b[addr];
unchecked {
return index1b > 0 && _isFastLaneMember(index1b - 1, _getCurrentFrame().index);
}
}
/// @notice Returns all current members, together with the last reference slot each member
/// submitted a report for.
///
function getMembers() external view returns (
address[] memory addresses,
uint256[] memory lastReportedRefSlots
) {
return _getMembers(false);
}
/// @notice Returns the subset of the oracle committee members (consisting of `quorum` items)
/// that changes each frame.
///
/// See `getIsFastLaneMember`.
///
function getFastLaneMembers() external view returns (
address[] memory addresses,
uint256[] memory lastReportedRefSlots
) {
return _getMembers(true);
}
/// @notice Sets the duration of the fast lane interval of the reporting frame.
///
/// See `getIsFastLaneMember`.
///
/// @param fastLaneLengthSlots The length of the fast lane reporting interval in slots. Setting
/// it to zero disables the fast lane subset, allowing any oracle to report starting from
/// the first slot of a frame and until the frame's reporting deadline.
///
function setFastLaneLengthSlots(uint256 fastLaneLengthSlots)
external onlyRole(MANAGE_FAST_LANE_CONFIG_ROLE)
{
_setFastLaneLengthSlots(fastLaneLengthSlots);
}
function addMember(address addr, uint256 quorum)
external
onlyRole(MANAGE_MEMBERS_AND_QUORUM_ROLE)
{
_addMember(addr, quorum);
}
function removeMember(address addr, uint256 quorum)
external
onlyRole(MANAGE_MEMBERS_AND_QUORUM_ROLE)
{
_removeMember(addr, quorum);
}
function getQuorum() external view returns (uint256) {
return _quorum;
}
function setQuorum(uint256 quorum) external {
// access control is performed inside the next call
_setQuorumAndCheckConsensus(quorum, _memberStates.length);
}
/// @notice Disables the oracle by setting the quorum to an unreachable value.
///
function disableConsensus() external {
// access control is performed inside the next call
_setQuorumAndCheckConsensus(UNREACHABLE_QUORUM, _memberStates.length);
}
///
/// Report processor
///
function getReportProcessor() external view returns (address) {
return _reportProcessor;
}
function setReportProcessor(address newProcessor)
external
onlyRole(MANAGE_REPORT_PROCESSOR_ROLE)
{
_setReportProcessor(newProcessor);
}
///
/// Consensus
///
/// @notice Returns info about the current frame and consensus state in that frame.
///
/// @return refSlot Reference slot of the current reporting frame.
///
/// @return consensusReport Consensus report for the current frame, if any.
/// Zero bytes otherwise.
///
/// @return isReportProcessing If consensus report for the current frame is already
/// being processed. Consensus can be changed before the processing starts.
///
function getConsensusState() external view returns (
uint256 refSlot,
bytes32 consensusReport,
bool isReportProcessing
) {
refSlot = _getCurrentFrame().refSlot;
(consensusReport,,) = _getConsensusReport(refSlot, _quorum);
isReportProcessing = _getLastProcessingRefSlot() == refSlot;
}
/// @notice Returns report variants and their support for the current reference slot.
///
function getReportVariants() external view returns (
bytes32[] memory variants,
uint256[] memory support
) {
if (_reportingState.lastReportRefSlot != _getCurrentFrame().refSlot) {
return (variants, support);
}
uint256 variantsLength = _reportVariantsLength;
variants = new bytes32[](variantsLength);
support = new uint256[](variantsLength);
for (uint256 i = 0; i < variantsLength; ++i) {
ReportVariant memory variant = _reportVariants[i];
variants[i] = variant.hash;
support[i] = variant.support;
}
}
struct MemberConsensusState {
/// @notice Current frame's reference slot.
uint256 currentFrameRefSlot;
/// @notice Consensus report for the current frame, if any. Zero bytes otherwise.
bytes32 currentFrameConsensusReport;
/// @notice Whether the provided address is a member of the oracle committee.
bool isMember;
/// @notice Whether the oracle committee member is in the fast lane members subset
/// of the current reporting frame. See `getIsFastLaneMember`.
bool isFastLane;
/// @notice Whether the oracle committee member is allowed to submit a report at
/// the moment of the call.
bool canReport;
/// @notice The last reference slot for which the member submitted a report.
uint256 lastMemberReportRefSlot;
/// @notice The hash reported by the member for the current frame, if any.
/// Zero bytes otherwise.
bytes32 currentFrameMemberReport;
}
/// @notice Returns the extended information related to an oracle committee member with the
/// given address and the current consensus state. Provides all the information needed for
/// an oracle daemon to decide if it needs to submit a report.
///
/// @param addr The member address.
/// @return result See the docs for `MemberConsensusState`.
///
function getConsensusStateForMember(address addr)
external view returns (MemberConsensusState memory result)
{
ConsensusFrame memory frame = _getCurrentFrame();
result.currentFrameRefSlot = frame.refSlot;
(result.currentFrameConsensusReport,,) = _getConsensusReport(frame.refSlot, _quorum);
uint256 index = _memberIndices1b[addr];
result.isMember = index != 0;
if (index != 0) {
unchecked { --index; } // convert to 0-based
MemberState memory memberState = _memberStates[index];
result.lastMemberReportRefSlot = memberState.lastReportRefSlot;
result.currentFrameMemberReport =
result.lastMemberReportRefSlot == frame.refSlot
? _reportVariants[memberState.lastReportVariantIndex].hash
: ZERO_HASH;
uint256 slot = _computeSlotAtTimestamp(_getTime());
result.canReport = slot <= frame.reportProcessingDeadlineSlot &&
frame.refSlot > _getLastProcessingRefSlot();
result.isFastLane = _isFastLaneMember(index, frame.index);
if (!result.isFastLane && result.canReport) {
result.canReport = slot > frame.refSlot + _frameConfig.fastLaneLengthSlots;
}
}
}
/// @notice Used by oracle members to submit hash of the data calculated for the given
/// reference slot.
///
/// @param slot The reference slot the data was calculated for. Reverts if doesn't match
/// the current reference slot.
///
/// @param report Hash of the data calculated for the given reference slot.
///
/// @param consensusVersion Version of the oracle consensus rules. Reverts if doesn't
/// match the version returned by the currently set consensus report processor,
/// or zero if no report processor is set.
///
function submitReport(uint256 slot, bytes32 report, uint256 consensusVersion) external {
_submitReport(slot, report, consensusVersion);
}
///
/// Implementation: time
///
function _setFrameConfig(
uint256 initialEpoch,
uint256 epochsPerFrame,
uint256 fastLaneLengthSlots,
FrameConfig memory prevConfig
) internal {
if (epochsPerFrame == 0) revert EpochsPerFrameCannotBeZero();
if (fastLaneLengthSlots > epochsPerFrame * SLOTS_PER_EPOCH) {
revert FastLanePeriodCannotBeLongerThanFrame();
}
_frameConfig = FrameConfig(
initialEpoch.toUint64(),
epochsPerFrame.toUint64(),
fastLaneLengthSlots.toUint64()
);
if (initialEpoch != prevConfig.initialEpoch || epochsPerFrame != prevConfig.epochsPerFrame) {
emit FrameConfigSet(initialEpoch, epochsPerFrame);
}
if (fastLaneLengthSlots != prevConfig.fastLaneLengthSlots) {
emit FastLaneConfigSet(fastLaneLengthSlots);
}
}
function _getCurrentFrame() internal view returns (ConsensusFrame memory) {
return _getFrameAtTimestamp(_getTime(), _frameConfig);
}
function _getInitialFrame() internal view returns (ConsensusFrame memory) {
return _getFrameAtIndex(0, _frameConfig);
}
function _getFrameAtTimestamp(uint256 timestamp, FrameConfig memory config)
internal view returns (ConsensusFrame memory)
{
return _getFrameAtIndex(_computeFrameIndex(timestamp, config), config);
}
function _getFrameAtIndex(uint256 frameIndex, FrameConfig memory config)
internal view returns (ConsensusFrame memory)
{
uint256 frameStartEpoch = _computeStartEpochOfFrameWithIndex(frameIndex, config);
uint256 frameStartSlot = _computeStartSlotAtEpoch(frameStartEpoch);
uint256 nextFrameStartSlot = frameStartSlot + config.epochsPerFrame * SLOTS_PER_EPOCH;
return ConsensusFrame({
index: frameIndex,
refSlot: uint64(frameStartSlot - 1),
reportProcessingDeadlineSlot: uint64(nextFrameStartSlot - 1 - DEADLINE_SLOT_OFFSET)
});
}
function _computeFrameStartEpoch(uint256 timestamp, FrameConfig memory config)
internal view returns (uint256)
{
return _computeStartEpochOfFrameWithIndex(_computeFrameIndex(timestamp, config), config);
}
function _computeStartEpochOfFrameWithIndex(uint256 frameIndex, FrameConfig memory config)
internal pure returns (uint256)
{
return config.initialEpoch + frameIndex * config.epochsPerFrame;
}
function _computeFrameIndex(uint256 timestamp, FrameConfig memory config)
internal view returns (uint256)
{
uint256 epoch = _computeEpochAtTimestamp(timestamp);
if (epoch < config.initialEpoch) {
revert InitialEpochIsYetToArrive();
}
return (epoch - config.initialEpoch) / config.epochsPerFrame;
}
function _computeTimestampAtSlot(uint256 slot) internal view returns (uint256) {
// See: github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#compute_timestamp_at_slot
return GENESIS_TIME + slot * SECONDS_PER_SLOT;
}
function _computeSlotAtTimestamp(uint256 timestamp) internal view returns (uint256) {
return (timestamp - GENESIS_TIME) / SECONDS_PER_SLOT;
}
function _computeEpochAtSlot(uint256 slot) internal view returns (uint256) {
// See: github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#compute_epoch_at_slot
return slot / SLOTS_PER_EPOCH;
}
function _computeEpochAtTimestamp(uint256 timestamp) internal view returns (uint256) {
return _computeEpochAtSlot(_computeSlotAtTimestamp(timestamp));
}
function _computeStartSlotAtEpoch(uint256 epoch) internal view returns (uint256) {
// See: github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#compute_start_slot_at_epoch
return epoch * SLOTS_PER_EPOCH;
}
function _getTime() internal virtual view returns (uint256) {
return block.timestamp; // solhint-disable-line not-rely-on-time
}
///
/// Implementation: members
///
function _isMember(address addr) internal view returns (bool) {
return _memberIndices1b[addr] != 0;
}
function _getMemberIndex(address addr) internal view returns (uint256) {
uint256 index1b = _memberIndices1b[addr];
if (index1b == 0) {
revert NonMember();
}
unchecked {
return uint256(index1b - 1);
}
}
function _addMember(address addr, uint256 quorum) internal {
if (_isMember(addr)) revert DuplicateMember();
if (addr == address(0)) revert AddressCannotBeZero();
_memberStates.push(MemberState(0, 0));
_memberAddresses.push(addr);
uint256 newTotalMembers = _memberStates.length;
_memberIndices1b[addr] = newTotalMembers;
emit MemberAdded(addr, newTotalMembers, quorum);
_setQuorumAndCheckConsensus(quorum, newTotalMembers);
}
function _removeMember(address addr, uint256 quorum) internal {
uint256 index = _getMemberIndex(addr);
uint256 newTotalMembers = _memberStates.length - 1;
assert(index <= newTotalMembers);
MemberState memory memberState = _memberStates[index];
if (index != newTotalMembers) {
address addrToMove = _memberAddresses[newTotalMembers];
_memberAddresses[index] = addrToMove;
_memberStates[index] = _memberStates[newTotalMembers];
_memberIndices1b[addrToMove] = index + 1;
}
_memberStates.pop();
_memberAddresses.pop();
_memberIndices1b[addr] = 0;
emit MemberRemoved(addr, newTotalMembers, quorum);
if (memberState.lastReportRefSlot > 0) {
// member reported at least once
ConsensusFrame memory frame = _getCurrentFrame();
if (memberState.lastReportRefSlot == frame.refSlot &&
_getLastProcessingRefSlot() < frame.refSlot
) {
// member reported for the current ref. slot and the consensus report
// is not processing yet => need to cancel the member's report
--_reportVariants[memberState.lastReportVariantIndex].support;
}
}
_setQuorumAndCheckConsensus(quorum, newTotalMembers);
}
function _setFastLaneLengthSlots(uint256 fastLaneLengthSlots) internal {
FrameConfig memory frameConfig = _frameConfig;
if (fastLaneLengthSlots > frameConfig.epochsPerFrame * SLOTS_PER_EPOCH) {
revert FastLanePeriodCannotBeLongerThanFrame();
}
if (fastLaneLengthSlots != frameConfig.fastLaneLengthSlots) {
_frameConfig.fastLaneLengthSlots = fastLaneLengthSlots.toUint64();
emit FastLaneConfigSet(fastLaneLengthSlots);
}
}
/// @dev Returns start and past-end incides (mod totalMembers) of the fast lane members subset.
///
function _getFastLaneSubset(uint256 frameIndex, uint256 totalMembers)
internal view returns (uint256 startIndex, uint256 pastEndIndex)
{
uint256 quorum = _quorum;
if (quorum >= totalMembers) {
startIndex = 0;
pastEndIndex = totalMembers;
} else {
startIndex = frameIndex % totalMembers;
pastEndIndex = startIndex + quorum;
}
}
/// @dev Tests whether the member with the given `index` is in the fast lane subset for the
/// given reporting `frameIndex`.
///
function _isFastLaneMember(uint256 index, uint256 frameIndex) internal view returns (bool) {
uint256 totalMembers = _memberStates.length;
(uint256 flLeft, uint256 flPastRight) = _getFastLaneSubset(frameIndex, totalMembers);
unchecked {
return (
flPastRight != 0 &&
Math.pointInClosedIntervalModN(index, flLeft, flPastRight - 1, totalMembers)
);
}
}
function _getMembers(bool fastLane) internal view returns (
address[] memory addresses,
uint256[] memory lastReportedRefSlots
) {
uint256 totalMembers = _memberStates.length;
uint256 left;
uint256 right;
if (fastLane) {
(left, right) = _getFastLaneSubset(_getCurrentFrame().index, totalMembers);
} else {
right = totalMembers;
}
addresses = new address[](right - left);
lastReportedRefSlots = new uint256[](addresses.length);
for (uint256 i = left; i < right; ++i) {
uint256 iModTotal = i % totalMembers;
MemberState memory memberState = _memberStates[iModTotal];
uint256 k = i - left;
addresses[k] = _memberAddresses[iModTotal];
lastReportedRefSlots[k] = memberState.lastReportRefSlot;
}
}
///
/// Implementation: consensus
///
function _submitReport(uint256 slot, bytes32 report, uint256 consensusVersion) internal {
if (slot == 0) revert InvalidSlot();
if (slot > type(uint64).max) revert NumericOverflow();
if (report == ZERO_HASH) revert EmptyReport();
uint256 memberIndex = _getMemberIndex(_msgSender());
MemberState memory memberState = _memberStates[memberIndex];
uint256 expectedConsensusVersion = _getConsensusVersion();
if (consensusVersion != expectedConsensusVersion) {
revert UnexpectedConsensusVersion(expectedConsensusVersion, consensusVersion);
}
uint256 timestamp = _getTime();
uint256 currentSlot = _computeSlotAtTimestamp(timestamp);
FrameConfig memory config = _frameConfig;
ConsensusFrame memory frame = _getFrameAtTimestamp(timestamp, config);
if (slot != frame.refSlot) revert InvalidSlot();
if (currentSlot > frame.reportProcessingDeadlineSlot) revert StaleReport();
if (currentSlot <= frame.refSlot + config.fastLaneLengthSlots &&
!_isFastLaneMember(memberIndex, frame.index)
) {
revert NonFastLaneMemberCannotReportWithinFastLaneInterval();
}
if (slot <= _getLastProcessingRefSlot()) {
// consensus for the ref. slot was already reached and consensus report is processing
if (slot == memberState.lastReportRefSlot) {
// member sends a report for the same slot => let them know via a revert
revert ConsensusReportAlreadyProcessing();
} else {
// member hasn't sent a report for this slot => normal operation, do nothing
return;
}
}
uint256 variantsLength;
if (_reportingState.lastReportRefSlot != slot) {
// first report for a new slot => clear report variants
_reportingState.lastReportRefSlot = uint64(slot);
variantsLength = 0;
} else {
variantsLength = _reportVariantsLength;
}
uint64 varIndex = 0;
bool prevConsensusLost = false;
while (varIndex < variantsLength && _reportVariants[varIndex].hash != report) {
++varIndex;
}
if (slot == memberState.lastReportRefSlot) {
uint64 prevVarIndex = memberState.lastReportVariantIndex;
assert(prevVarIndex < variantsLength);
if (varIndex == prevVarIndex) {
revert DuplicateReport();
} else {
uint256 support = --_reportVariants[prevVarIndex].support;
if (support == _quorum - 1) {
prevConsensusLost = true;
}
}
}
uint256 support;
if (varIndex < variantsLength) {
support = ++_reportVariants[varIndex].support;
} else {
support = 1;
_reportVariants[varIndex] = ReportVariant({hash: report, support: 1});
_reportVariantsLength = ++variantsLength;
}
_memberStates[memberIndex] = MemberState({
lastReportRefSlot: uint64(slot),
lastReportVariantIndex: varIndex
});
emit ReportReceived(slot, _msgSender(), report);
if (support >= _quorum) {
_consensusReached(frame, report, varIndex, support);
} else if (prevConsensusLost) {
_consensusNotReached(frame);
}
}
function _consensusReached(
ConsensusFrame memory frame,
bytes32 report,
uint256 variantIndex,
uint256 support
) internal {
if (_reportingState.lastConsensusRefSlot != frame.refSlot ||
_reportingState.lastConsensusVariantIndex != variantIndex
) {
_reportingState.lastConsensusRefSlot = uint64(frame.refSlot);
_reportingState.lastConsensusVariantIndex = uint64(variantIndex);
emit ConsensusReached(frame.refSlot, report, support);
_submitReportForProcessing(frame, report);
}
}
function _consensusNotReached(ConsensusFrame memory frame) internal {
if (_reportingState.lastConsensusRefSlot == frame.refSlot) {
_reportingState.lastConsensusRefSlot = 0;
emit ConsensusLost(frame.refSlot);
_cancelReportProcessing(frame);
}
}
function _setQuorumAndCheckConsensus(uint256 quorum, uint256 totalMembers) internal {
if (quorum <= totalMembers / 2) {
revert QuorumTooSmall(totalMembers / 2 + 1, quorum);
}
// we're explicitly allowing quorum values greater than the number of members to
// allow effectively disabling the oracle in case something unpredictable happens
uint256 prevQuorum = _quorum;
if (quorum != prevQuorum) {
_checkRole(
quorum == UNREACHABLE_QUORUM ? DISABLE_CONSENSUS_ROLE : MANAGE_MEMBERS_AND_QUORUM_ROLE,
_msgSender()
);
_quorum = quorum;
emit QuorumSet(quorum, totalMembers, prevQuorum);
}
if (_computeEpochAtTimestamp(_getTime()) >= _frameConfig.initialEpoch) {
_checkConsensus(quorum);
}
}
function _checkConsensus(uint256 quorum) internal {
uint256 timestamp = _getTime();
ConsensusFrame memory frame = _getFrameAtTimestamp(timestamp, _frameConfig);
if (_computeSlotAtTimestamp(timestamp) > frame.reportProcessingDeadlineSlot) {
// a report for the current ref. slot cannot be processed anymore
return;
}
if (_getLastProcessingRefSlot() >= frame.refSlot) {
// a consensus report for the current ref. slot is already being processed
return;
}
(bytes32 consensusReport, int256 consensusVariantIndex, uint256 support) =
_getConsensusReport(frame.refSlot, quorum);
if (consensusVariantIndex >= 0) {
_consensusReached(frame, consensusReport, uint256(consensusVariantIndex), support);
} else {
_consensusNotReached(frame);
}
}
function _getConsensusReport(uint256 currentRefSlot, uint256 quorum)
internal view returns (bytes32 report, int256 variantIndex, uint256 support)
{
if (_reportingState.lastReportRefSlot != currentRefSlot) {
// there were no reports for the current ref. slot
return (ZERO_HASH, -1, 0);
}
uint256 variantsLength = _reportVariantsLength;
variantIndex = -1;
report = ZERO_HASH;
support = 0;
for (uint256 i = 0; i < variantsLength; ++i) {
uint256 iSupport = _reportVariants[i].support;
if (iSupport >= quorum) {
variantIndex = int256(i);
report = _reportVariants[i].hash;
support = iSupport;
break;
}
}
return (report, variantIndex, support);
}
///
/// Implementation: report processing
///
function _setReportProcessor(address newProcessor) internal {
address prevProcessor = _reportProcessor;
if (newProcessor == address(0)) revert ReportProcessorCannotBeZero();
if (newProcessor == prevProcessor) revert NewProcessorCannotBeTheSame();
_reportProcessor = newProcessor;
emit ReportProcessorSet(newProcessor, prevProcessor);
ConsensusFrame memory frame = _getCurrentFrame();
uint256 lastConsensusRefSlot = _reportingState.lastConsensusRefSlot;
uint256 processingRefSlotPrev = IReportAsyncProcessor(prevProcessor).getLastProcessingRefSlot();
uint256 processingRefSlotNext = IReportAsyncProcessor(newProcessor).getLastProcessingRefSlot();
if (
processingRefSlotPrev < frame.refSlot &&
processingRefSlotNext < frame.refSlot &&
lastConsensusRefSlot == frame.refSlot
) {
bytes32 report = _reportVariants[_reportingState.lastConsensusVariantIndex].hash;
_submitReportForProcessing(frame, report);
}
}
function _getLastProcessingRefSlot() internal view returns (uint256) {
return IReportAsyncProcessor(_reportProcessor).getLastProcessingRefSlot();
}
function _submitReportForProcessing(ConsensusFrame memory frame, bytes32 report) internal {
IReportAsyncProcessor(_reportProcessor).submitConsensusReport(
report,
frame.refSlot,
_computeTimestampAtSlot(frame.reportProcessingDeadlineSlot)
);
}
function _cancelReportProcessing(ConsensusFrame memory frame) internal {
IReportAsyncProcessor(_reportProcessor).discardConsensusReport(frame.refSlot);
}
function _getConsensusVersion() internal view returns (uint256) {
return IReportAsyncProcessor(_reportProcessor).getConsensusVersion();
}
}
contracts/0.8.9/utils/Versioned.sol
// SPDX-FileCopyrightText: 2022 Lido <info@lido.fi>
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.9;
import "../lib/UnstructuredStorage.sol";
contract Versioned {
using UnstructuredStorage for bytes32;
event ContractVersionSet(uint256 version);
error NonZeroContractVersionOnInit();
error InvalidContractVersionIncrement();
error UnexpectedContractVersion(uint256 expected, uint256 received);
/// @dev Storage slot: uint256 version
/// Version of the initialized contract storage.
/// The version stored in CONTRACT_VERSION_POSITION equals to:
/// - 0 right after the deployment, before an initializer is invoked (and only at that moment);
/// - N after calling initialize(), where N is the initially deployed contract version;
/// - N after upgrading contract by calling finalizeUpgrade_vN().
bytes32 internal constant CONTRACT_VERSION_POSITION = keccak256("lido.Versioned.contractVersion");
uint256 internal constant PETRIFIED_VERSION_MARK = type(uint256).max;
constructor() {
// lock version in the implementation's storage to prevent initialization
CONTRACT_VERSION_POSITION.setStorageUint256(PETRIFIED_VERSION_MARK);
}
/// @notice Returns the current contract version.
function getContractVersion() public view returns (uint256) {
return CONTRACT_VERSION_POSITION.getStorageUint256();
}
function _checkContractVersion(uint256 version) internal view {
uint256 expectedVersion = getContractVersion();
if (version != expectedVersion) {
revert UnexpectedContractVersion(expectedVersion, version);
}
}
/// @dev Sets the contract version to N. Should be called from the initialize() function.
function _initializeContractVersionTo(uint256 version) internal {
if (getContractVersion() != 0) revert NonZeroContractVersionOnInit();
_setContractVersion(version);
}
/// @dev Updates the contract version. Should be called from a finalizeUpgrade_vN() function.
function _updateContractVersion(uint256 newVersion) internal {
if (newVersion != getContractVersion() + 1) revert InvalidContractVersionIncrement();
_setContractVersion(newVersion);
}
function _setContractVersion(uint256 version) private {
CONTRACT_VERSION_POSITION.setStorageUint256(version);
emit ContractVersionSet(version);
}
}
contracts/0.8.9/utils/access/AccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol)
//
// A modified AccessControl contract using unstructured storage. Copied from tree:
// https://github.com/OpenZeppelin/openzeppelin-contracts/tree/6bd6b76/contracts/access
//
/* See contracts/COMPILERS.md */
pragma solidity 0.8.9;
import "@openzeppelin/contracts-v4.4/access/IAccessControl.sol";
import "@openzeppelin/contracts-v4.4/utils/Context.sol";
import "@openzeppelin/contracts-v4.4/utils/Strings.sol";
import "@openzeppelin/contracts-v4.4/utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
/// @dev Storage slot: mapping(bytes32 => RoleData) _roles
bytes32 private constant ROLES_POSITION = keccak256("openzeppelin.AccessControl._roles");
function _storageRoles() private pure returns (mapping(bytes32 => RoleData) storage _roles) {
bytes32 position = ROLES_POSITION;
assembly { _roles.slot := position }
}
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role, _msgSender());
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view override returns (bool) {
return _storageRoles()[role].members[account];
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(uint160(account), 20),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view override returns (bytes32) {
return _storageRoles()[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_storageRoles()[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_storageRoles()[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_storageRoles()[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
contracts/0.8.9/utils/access/AccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/AccessControlEnumerable.sol)
//
// A modified AccessControlEnumerable contract using unstructured storage. Copied from tree:
// https://github.com/OpenZeppelin/openzeppelin-contracts/tree/6bd6b76/contracts/access
//
/* See contracts/COMPILERS.md */
pragma solidity 0.8.9;
import "@openzeppelin/contracts-v4.4/access/IAccessControlEnumerable.sol";
import "@openzeppelin/contracts-v4.4/utils/structs/EnumerableSet.sol";
import "./AccessControl.sol";
/**
* @dev Extension of {AccessControl} that allows enumerating the members of each role.
*/
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
using EnumerableSet for EnumerableSet.AddressSet;
/// @dev Storage slot: mapping(bytes32 => EnumerableSet.AddressSet) _roleMembers
bytes32 private constant ROLE_MEMBERS_POSITION = keccak256("openzeppelin.AccessControlEnumerable._roleMembers");
function _storageRoleMembers() private pure returns (
mapping(bytes32 => EnumerableSet.AddressSet) storage _roleMembers
) {
bytes32 position = ROLE_MEMBERS_POSITION;
assembly { _roleMembers.slot := position }
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) public view override returns (address) {
return _storageRoleMembers()[role].at(index);
}
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) public view override returns (uint256) {
return _storageRoleMembers()[role].length();
}
/**
* @dev Overload {_grantRole} to track enumerable memberships
*/
function _grantRole(bytes32 role, address account) internal virtual override {
super._grantRole(role, account);
_storageRoleMembers()[role].add(account);
}
/**
* @dev Overload {_revokeRole} to track enumerable memberships
*/
function _revokeRole(bytes32 role, address account) internal virtual override {
super._revokeRole(role, account);
_storageRoleMembers()[role].remove(account);
}
}
contracts/common/interfaces/ILidoLocator.sol
// SPDX-FileCopyrightText: 2023 Lido <info@lido.fi>
// SPDX-License-Identifier: GPL-3.0
// See contracts/COMPILERS.md
// solhint-disable-next-line
pragma solidity >=0.4.24 <0.9.0;
interface ILidoLocator {
function accountingOracle() external view returns(address);
function depositSecurityModule() external view returns(address);
function elRewardsVault() external view returns(address);
function legacyOracle() external view returns(address);
function lido() external view returns(address);
function oracleReportSanityChecker() external view returns(address);
function burner() external view returns(address);
function stakingRouter() external view returns(address);
function treasury() external view returns(address);
function validatorsExitBusOracle() external view returns(address);
function withdrawalQueue() external view returns(address);
function withdrawalVault() external view returns(address);
function postTokenRebaseReceiver() external view returns(address);
function oracleDaemonConfig() external view returns(address);
function coreComponents() external view returns(
address elRewardsVault,
address oracleReportSanityChecker,
address stakingRouter,
address treasury,
address withdrawalQueue,
address withdrawalVault
);
function oracleReportComponentsForLido() external view returns(
address accountingOracle,
address elRewardsVault,
address oracleReportSanityChecker,
address burner,
address withdrawalQueue,
address withdrawalVault,
address postTokenRebaseReceiver
);
}
Compiler Settings
{"outputSelection":{"*":{"*":["*"],"":["*"]}},"optimizer":{"runs":150,"enabled":true},"libraries":{},"evmVersion":"istanbul"}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"lidoLocator","internalType":"address"},{"type":"address","name":"lido","internalType":"address"},{"type":"address","name":"legacyOracle","internalType":"address"},{"type":"uint256","name":"secondsPerSlot","internalType":"uint256"},{"type":"uint256","name":"genesisTime","internalType":"uint256"}]},{"type":"error","name":"AddressCannotBeSame","inputs":[]},{"type":"error","name":"AddressCannotBeZero","inputs":[]},{"type":"error","name":"AdminCannotBeZero","inputs":[]},{"type":"error","name":"CannotSubmitExtraDataBeforeMainData","inputs":[]},{"type":"error","name":"ExtraDataAlreadyProcessed","inputs":[]},{"type":"error","name":"ExtraDataHashCannotBeZeroForNonEmptyData","inputs":[]},{"type":"error","name":"ExtraDataItemsCountCannotBeZeroForNonEmptyData","inputs":[]},{"type":"error","name":"ExtraDataListOnlySupportsSingleTx","inputs":[]},{"type":"error","name":"HashCannotBeZero","inputs":[]},{"type":"error","name":"IncorrectOracleMigration","inputs":[{"type":"uint256","name":"code","internalType":"uint256"}]},{"type":"error","name":"InitialRefSlotCannotBeLessThanProcessingOne","inputs":[{"type":"uint256","name":"initialRefSlot","internalType":"uint256"},{"type":"uint256","name":"processingRefSlot","internalType":"uint256"}]},{"type":"error","name":"InvalidContractVersionIncrement","inputs":[]},{"type":"error","name":"InvalidExitedValidatorsData","inputs":[]},{"type":"error","name":"InvalidExtraDataItem","inputs":[{"type":"uint256","name":"itemIndex","internalType":"uint256"}]},{"type":"error","name":"InvalidExtraDataSortOrder","inputs":[{"type":"uint256","name":"itemIndex","internalType":"uint256"}]},{"type":"error","name":"LegacyOracleCannotBeZero","inputs":[]},{"type":"error","name":"LidoCannotBeZero","inputs":[]},{"type":"error","name":"LidoLocatorCannotBeZero","inputs":[]},{"type":"error","name":"NoConsensusReportToProcess","inputs":[]},{"type":"error","name":"NonZeroContractVersionOnInit","inputs":[]},{"type":"error","name":"ProcessingDeadlineMissed","inputs":[{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"error","name":"RefSlotAlreadyProcessing","inputs":[]},{"type":"error","name":"RefSlotCannotDecrease","inputs":[{"type":"uint256","name":"refSlot","internalType":"uint256"},{"type":"uint256","name":"prevRefSlot","internalType":"uint256"}]},{"type":"error","name":"RefSlotMustBeGreaterThanProcessingOne","inputs":[{"type":"uint256","name":"refSlot","internalType":"uint256"},{"type":"uint256","name":"processingRefSlot","internalType":"uint256"}]},{"type":"error","name":"SecondsPerSlotCannotBeZero","inputs":[]},{"type":"error","name":"SenderIsNotTheConsensusContract","inputs":[]},{"type":"error","name":"SenderNotAllowed","inputs":[]},{"type":"error","name":"UnexpectedChainConfig","inputs":[]},{"type":"error","name":"UnexpectedConsensusVersion","inputs":[{"type":"uint256","name":"expectedVersion","internalType":"uint256"},{"type":"uint256","name":"receivedVersion","internalType":"uint256"}]},{"type":"error","name":"UnexpectedContractVersion","inputs":[{"type":"uint256","name":"expected","internalType":"uint256"},{"type":"uint256","name":"received","internalType":"uint256"}]},{"type":"error","name":"UnexpectedDataHash","inputs":[{"type":"bytes32","name":"consensusHash","internalType":"bytes32"},{"type":"bytes32","name":"receivedHash","internalType":"bytes32"}]},{"type":"error","name":"UnexpectedExtraDataFormat","inputs":[{"type":"uint256","name":"expectedFormat","internalType":"uint256"},{"type":"uint256","name":"receivedFormat","internalType":"uint256"}]},{"type":"error","name":"UnexpectedExtraDataHash","inputs":[{"type":"bytes32","name":"consensusHash","internalType":"bytes32"},{"type":"bytes32","name":"receivedHash","internalType":"bytes32"}]},{"type":"error","name":"UnexpectedExtraDataIndex","inputs":[{"type":"uint256","name":"expectedIndex","internalType":"uint256"},{"type":"uint256","name":"receivedIndex","internalType":"uint256"}]},{"type":"error","name":"UnexpectedExtraDataItemsCount","inputs":[{"type":"uint256","name":"expectedCount","internalType":"uint256"},{"type":"uint256","name":"receivedCount","internalType":"uint256"}]},{"type":"error","name":"UnexpectedRefSlot","inputs":[{"type":"uint256","name":"consensusRefSlot","internalType":"uint256"},{"type":"uint256","name":"dataRefSlot","internalType":"uint256"}]},{"type":"error","name":"UnsupportedExtraDataFormat","inputs":[{"type":"uint256","name":"format","internalType":"uint256"}]},{"type":"error","name":"UnsupportedExtraDataType","inputs":[{"type":"uint256","name":"itemIndex","internalType":"uint256"},{"type":"uint256","name":"dataType","internalType":"uint256"}]},{"type":"error","name":"VersionCannotBeSame","inputs":[]},{"type":"event","name":"ConsensusHashContractSet","inputs":[{"type":"address","name":"addr","internalType":"address","indexed":true},{"type":"address","name":"prevAddr","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"ConsensusVersionSet","inputs":[{"type":"uint256","name":"version","internalType":"uint256","indexed":true},{"type":"uint256","name":"prevVersion","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"ContractVersionSet","inputs":[{"type":"uint256","name":"version","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"ExtraDataSubmitted","inputs":[{"type":"uint256","name":"refSlot","internalType":"uint256","indexed":true},{"type":"uint256","name":"itemsProcessed","internalType":"uint256","indexed":false},{"type":"uint256","name":"itemsCount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"ProcessingStarted","inputs":[{"type":"uint256","name":"refSlot","internalType":"uint256","indexed":true},{"type":"bytes32","name":"hash","internalType":"bytes32","indexed":false}],"anonymous":false},{"type":"event","name":"ReportDiscarded","inputs":[{"type":"uint256","name":"refSlot","internalType":"uint256","indexed":true},{"type":"bytes32","name":"hash","internalType":"bytes32","indexed":false}],"anonymous":false},{"type":"event","name":"ReportSubmitted","inputs":[{"type":"uint256","name":"refSlot","internalType":"uint256","indexed":true},{"type":"bytes32","name":"hash","internalType":"bytes32","indexed":false},{"type":"uint256","name":"processingDeadlineTime","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"RoleAdminChanged","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"previousAdminRole","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"newAdminRole","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"RoleGranted","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RoleRevoked","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"WarnExtraDataIncompleteProcessing","inputs":[{"type":"uint256","name":"refSlot","internalType":"uint256","indexed":true},{"type":"uint256","name":"processedItemsCount","internalType":"uint256","indexed":false},{"type":"uint256","name":"itemsCount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"WarnProcessingMissed","inputs":[{"type":"uint256","name":"refSlot","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"DEFAULT_ADMIN_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"EXTRA_DATA_FORMAT_EMPTY","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"EXTRA_DATA_FORMAT_LIST","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"EXTRA_DATA_TYPE_EXITED_VALIDATORS","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"EXTRA_DATA_TYPE_STUCK_VALIDATORS","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"GENESIS_TIME","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"LEGACY_ORACLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"LIDO","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract ILidoLocator"}],"name":"LOCATOR","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"MANAGE_CONSENSUS_CONTRACT_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"MANAGE_CONSENSUS_VERSION_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"SECONDS_PER_SLOT","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"SUBMIT_DATA_ROLE","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"discardConsensusReport","inputs":[{"type":"uint256","name":"refSlot","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getConsensusContract","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"hash","internalType":"bytes32"},{"type":"uint256","name":"refSlot","internalType":"uint256"},{"type":"uint256","name":"processingDeadlineTime","internalType":"uint256"},{"type":"bool","name":"processingStarted","internalType":"bool"}],"name":"getConsensusReport","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getConsensusVersion","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getContractVersion","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getLastProcessingRefSlot","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"result","internalType":"struct AccountingOracle.ProcessingState","components":[{"type":"uint256","name":"currentFrameRefSlot","internalType":"uint256"},{"type":"uint256","name":"processingDeadlineTime","internalType":"uint256"},{"type":"bytes32","name":"mainDataHash","internalType":"bytes32"},{"type":"bool","name":"mainDataSubmitted","internalType":"bool"},{"type":"bytes32","name":"extraDataHash","internalType":"bytes32"},{"type":"uint256","name":"extraDataFormat","internalType":"uint256"},{"type":"bool","name":"extraDataSubmitted","internalType":"bool"},{"type":"uint256","name":"extraDataItemsCount","internalType":"uint256"},{"type":"uint256","name":"extraDataItemsSubmitted","internalType":"uint256"}]}],"name":"getProcessingState","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getRoleAdmin","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getRoleMember","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"uint256","name":"index","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getRoleMemberCount","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"address","name":"admin","internalType":"address"},{"type":"address","name":"consensusContract","internalType":"address"},{"type":"uint256","name":"consensusVersion","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initializeWithoutMigration","inputs":[{"type":"address","name":"admin","internalType":"address"},{"type":"address","name":"consensusContract","internalType":"address"},{"type":"uint256","name":"consensusVersion","internalType":"uint256"},{"type":"uint256","name":"lastProcessingRefSlot","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"revokeRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setConsensusContract","inputs":[{"type":"address","name":"addr","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setConsensusVersion","inputs":[{"type":"uint256","name":"version","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"submitConsensusReport","inputs":[{"type":"bytes32","name":"reportHash","internalType":"bytes32"},{"type":"uint256","name":"refSlot","internalType":"uint256"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"submitReportData","inputs":[{"type":"tuple","name":"data","internalType":"struct AccountingOracle.ReportData","components":[{"type":"uint256","name":"consensusVersion","internalType":"uint256"},{"type":"uint256","name":"refSlot","internalType":"uint256"},{"type":"uint256","name":"numValidators","internalType":"uint256"},{"type":"uint256","name":"clBalanceGwei","internalType":"uint256"},{"type":"uint256[]","name":"stakingModuleIdsWithNewlyExitedValidators","internalType":"uint256[]"},{"type":"uint256[]","name":"numExitedValidatorsByStakingModule","internalType":"uint256[]"},{"type":"uint256","name":"withdrawalVaultBalance","internalType":"uint256"},{"type":"uint256","name":"elRewardsVaultBalance","internalType":"uint256"},{"type":"uint256","name":"sharesRequestedToBurn","internalType":"uint256"},{"type":"uint256[]","name":"withdrawalFinalizationBatches","internalType":"uint256[]"},{"type":"uint256","name":"simulatedShareRate","internalType":"uint256"},{"type":"bool","name":"isBunkerMode","internalType":"bool"},{"type":"uint256","name":"extraDataFormat","internalType":"uint256"},{"type":"bytes32","name":"extraDataHash","internalType":"bytes32"},{"type":"uint256","name":"extraDataItemsCount","internalType":"uint256"}]},{"type":"uint256","name":"contractVersion","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"submitReportExtraDataEmpty","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"submitReportExtraDataList","inputs":[{"type":"bytes","name":"items","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"supportsInterface","inputs":[{"type":"bytes4","name":"interfaceId","internalType":"bytes4"}]}]
Contract Creation Code
0x6101206040523480156200001257600080fd5b50604051620041ed380380620041ed833981016040819052620000359162000155565b8181620000736000197f4dd0f6662ba1d6b081f08b350f5e9a6a7b15cf586926ba66f753594928fa64a66200013460201b62000ecd1790919060201c565b816200009257604051636ed243a560e01b815260040160405180910390fd5b60809190915260a0526001600160a01b038516620000c357604051637b3fe65f60e01b815260040160405180910390fd5b6001600160a01b038316620000eb57604051639417a57760e01b815260040160405180910390fd5b6001600160a01b03841662000113576040516332a828f760e21b815260040160405180910390fd5b50506001600160a01b0392831660e05290821660c0521661010052620001b2565b9055565b80516001600160a01b03811681146200015057600080fd5b919050565b600080600080600060a086880312156200016e57600080fd5b620001798662000138565b9450620001896020870162000138565b9350620001996040870162000138565b6060870151608090970151959894975095949392505050565b60805160a05160c05160e05161010051613f6a620002836000396000818161051e0152818161080601526122820152600081816103350152818161124f01528181611cbf0152818161219301528181612342015281816123d701528181612a4501526130fc0152600081816103b601526125b901526000818161056b01528181611ac8015281816124dd01528181612535015261261c0152600081816102c401528181611a9e015281816124b201528181612506015281816125e80152818161264501526130bd0152613f6a6000f3fe608060405234801561001057600080fd5b506004361061021b5760003560e01c80638b21f17011610125578063b74d4631116100ad578063d43812171161007c578063d438121714610540578063d547741f14610553578063f288246114610566578063fa565b051461058d578063fc7377cd1461059557600080fd5b8063b74d4631146104e0578063c469c307146104f3578063ca15c87314610506578063ce976fa91461051957600080fd5b80639010d07c116100f45780639010d07c1461046c57806391d148541461047f5780639cc23c7914610492578063a217fddf146103a1578063ad5cac4e146104b957600080fd5b80638b21f170146103b15780638d591474146103d85780638f55b571146103eb5780638f7797c2146103f357600080fd5b806336568abe116101a85780635be20425116101775780635be204251461036f57806360d64d3814610377578063672690b41461022057806374facb9b146103a15780638aa10435146103a957600080fd5b806336568abe146102ee57806346e1f57614610301578063560f97cb1461032857806357a782891461033057600080fd5b80631794bb3c116101ef5780631794bb3c14610286578063248a9ca3146102995780632f2ff15d146102ac578063304b9071146102bf5780633584d59c146102e657600080fd5b80625418e11461022057806301ffc9a71461023b578063063f36ad1461025e57806306c373da14610273575b600080fd5b610228600181565b6040519081526020015b60405180910390f35b61024e610249366004613664565b6105a8565b6040519015158152602001610232565b61027161026c36600461368e565b6105d3565b005b6102716102813660046136ba565b6107ca565b610271610294366004613740565b6107d8565b6102286102a7366004613781565b61083f565b6102716102ba36600461379a565b610861565b6102287f000000000000000000000000000000000000000000000000000000000000000081565b610228610883565b6102716102fc36600461379a565b6108a0565b6102287f65fa0c17458517c727737e4153dd477fa3e328cf706640b0f68b1a285c5990da81565b610228600281565b6103577f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610232565b61022861091a565b61037f610932565b6040805194855260208501939093529183015215156060820152608001610232565b610228600081565b6102286109d5565b6103577f000000000000000000000000000000000000000000000000000000000000000081565b6102716103e6366004613781565b6109ff565b610357610a33565b6103fb610a4b565b60405161023291906000610120820190508251825260208301516020830152604083015160408301526060830151151560608301526080830151608083015260a083015160a083015260c0830151151560c083015260e083015160e083015261010080840151818401525092915050565b61035761047a3660046137ca565b610c11565b61024e61048d36600461379a565b610c3d565b6102287fc31b1e4b732c5173dc51d519dfa432bad95550ecc4b0f9a61c2a558a2a8e434181565b6102287f04a0afbbd09d5ad397fc858789da4f8edd59f5ca5098d70faa490babee945c3b81565b6102716104ee3660046137ec565b610c75565b610271610501366004613832565b610ca8565b610228610514366004613781565b610cf2565b6103577f000000000000000000000000000000000000000000000000000000000000000081565b61027161054e366004613781565b610d16565b61027161056136600461379a565b610e46565b6102287f000000000000000000000000000000000000000000000000000000000000000081565b610271610e63565b6102716105a336600461384f565b610e6d565b60006001600160e01b03198216635a05180f60e01b14806105cd57506105cd82610ed1565b92915050565b6105db610f06565b60006105e5610f47565b600101546001600160401b03169050808310156106245760405163431d301760e11b815260048101849052602481018290526044015b60405180910390fd5b600061063c600080516020613ef58339815191525490565b9050808411610668576040516360a41e4960e01b8152600481018590526024810182905260440161061b565b8242111561068c5760405163537bacdf60e11b81526004810184905260240161061b565b81841415801561069c5750818114155b156106cd5760405182907f800b849c8bf80718cf786c99d1091c079fe2c5e420a3ba7ba9b0ef8179ef2c3890600090a25b846106eb57604051635b18a69f60e11b815260040160405180910390fd5b604080518681526020810185905285917faed7d1a7a1831158dcda1e4214f5862f450bd3eb5721a5f322bf8c9fe1790b0a910160405180910390a26000604051806060016040528087815260200161074287610f6b565b6001600160401b0316815260200161075986610f6b565b6001600160401b0316905290508061076f610f47565b815181556020820151600190910180546040909301516001600160401b03908116600160401b026fffffffffffffffffffffffffffffffff199094169216919091179190911790556107c2818484610fd7565b505050505050565b6107d482826110e7565b5050565b6001600160a01b0383166107ff57604051636b35b1b760e01b815260040160405180910390fd5b600061082b7f0000000000000000000000000000000000000000000000000000000000000000846114dd565b90506108398484848461178f565b50505050565b6000908152600080516020613ed5833981519152602052604090206001015490565b61086a8261083f565b61087481336117a5565b61087e8383611809565b505050565b600061089b600080516020613ef58339815191525490565b905090565b6001600160a01b03811633146109105760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840161061b565b6107d48282611838565b600061089b600080516020613f158339815191525490565b6000806000806000610942610f47565b60408051606081018252825481526001909201546001600160401b038082166020850152600160401b90910416908201529050600061098d600080516020613ef58339815191525490565b825160208401516040850151929350909182158015906109b957508385602001516001600160401b0316145b92996001600160401b0392831699509116965090945092505050565b600061089b7f4dd0f6662ba1d6b081f08b350f5e9a6a7b15cf586926ba66f753594928fa64a65490565b7fc31b1e4b732c5173dc51d519dfa432bad95550ecc4b0f9a61c2a558a2a8e4341610a2a81336117a5565b6107d482611867565b600061089b600080516020613e958339815191525490565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905290610a9c610f47565b60408051606081018252825481526001909201546001600160401b038082166020850152600160401b90910416908201529050610ad76118ea565b825280511580610af8575080602001516001600160401b0316826000015114155b15610b01575090565b6040808201516001600160401b031660208401528151908301526000610b33600080516020613ef58339815191525490565b60208301516001600160401b0316811460608501819052909150610b5657505090565b6000610b6061197f565b6040805160e0808201835283546001600160401b03808216845261ffff600160401b830481166020860190815260ff600160501b8504161515968601968752600160581b8404831660608701908152600160981b9094048316608080880191825260018a015460a0808a01919091526002909a015460c0988901819052908e01529051909116968b019690965293511515928901929092529051821690870152905116610100850152509192915050565b6000828152600080516020613eb583398151915260205260408120610c3690836119a3565b9392505050565b6000918252600080516020613ed5833981519152602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6001600160a01b038416610c9c57604051636b35b1b760e01b815260040160405180910390fd5b6108398484848461178f565b7f04a0afbbd09d5ad397fc858789da4f8edd59f5ca5098d70faa490babee945c3b610cd381336117a5565b6107d482610ced600080516020613ef58339815191525490565b6119af565b6000818152600080516020613eb5833981519152602052604081206105cd90611c08565b610d1e610f06565b6000610d28610f47565b60408051606081018252825481526001909201546001600160401b0380821660208501819052600160401b9092041691830191909152909150821015610d9957602081015160405163431d301760e11b8152600481018490526001600160401b03909116602482015260440161061b565b80602001516001600160401b0316821115610db2575050565b6000610dca600080516020613ef58339815191525490565b9050808311610deb576040516252e2c960e41b815260040160405180910390fd5b6000610df5610f47565b5581602001516001600160401b03167fe21266bc27ee721ac10034efaf7fd724656ef471c75b8402cd8f07850af6b6768360000151604051610e3991815260200190565b60405180910390a2505050565b610e4f8261083f565b610e5981336117a5565b61087e8383611838565b610e6b611c15565b565b610e75611e0e565b610e7e81611e6a565b610eb78260200135836000013584604051602001610e9c919061393c565b60405160208183030381529060405280519060200120611ea0565b6000610ec1611f93565b905061087e83826120ab565b9055565b60006001600160e01b03198216637965db0b60e01b14806105cd57506301ffc9a760e01b6001600160e01b03198316146105cd565b600080516020613e95833981519152546001600160a01b0316336001600160a01b031614610e6b5760405163fef4d83160e01b815260040160405180910390fd5b7f9d565e483b8608dc09e04eff85533859683d2eeaa6ebc28af53a92d7dba3eea690565b60006001600160401b03821115610fd35760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203660448201526534206269747360d01b606482015260840161061b565b5090565b6000610fe161197f565b6040805160e08101825282546001600160401b0380821680845261ffff600160401b840416602085015260ff600160501b840416151594840194909452600160581b820481166060840152600160981b909104166080820152600183015460a082015260029092015460c083015290915082148015611085575080604001511580611085575080606001516001600160401b031681608001516001600160401b0316105b1561083957817f801a93267f699b033e11b662b16b36c41b6f9a59a5b5ad967d4cb84232e523c2826080015183606001516040516110d99291906001600160401b0392831681529116602082015260400190565b60405180910390a250505050565b60006110f161197f565b6040805160e08101825282546001600160401b03808216835261ffff600160401b830416602084015260ff600160501b830416151593830193909352600160581b810483166060830152600160981b9004909116608082015260018083015460a083015260029092015460c0820152915061116d908290612831565b80606001516001600160401b031681608001516001600160401b031614156111a8576040516313f2ae7160e11b815260040160405180910390fd5b60808101516001600160401b0316156111d457604051631d07c31960e21b815260040160405180910390fd5b600083836040516111e6929190613a5f565b604051809103902090508160c0015181146112245760c082015160405163d2b3f3cf60e01b815260048101919091526024810182905260440161061b565b60006040518060a00160405280600081526020016000815260200160008152602001600081526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ef6c064c6040518163ffffffff1660e01b815260040160206040518083038186803b1580156112a657600080fd5b505afa1580156112ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112de9190613a6f565b6001600160a01b0316905290506112f6858583612901565b8051600090611306906001613aa2565b905083606001516001600160401b0316811461134d576060840151604051631c4de3e160e11b81526001600160401b0390911660048201526024810182905260440161061b565b600160408501526001600160401b0381166080850152606082015160a08501528361137661197f565b81518154602084015160408086015160608701516080808901516001600160401b03908116600160981b0267ffffffffffffffff60981b19938216600160581b0267ffffffffffffffff60581b19951515600160501b029590951668ffffffffffffffffff60501b1961ffff909816600160401b0269ffffffffffffffffffff199099169290991691909117969096179490941695909517179390931691909117835560a0840151600184015560c09093015160029092019190915590830151815163db3c7ba760e01b815291516001600160a01b039091169163db3c7ba791600480830192600092919082900301818387803b15801561147657600080fd5b505af115801561148a573d6000803e3d6000fd5b5050855160408051858152602081018690526001600160401b0390921693507f6d8abc91d336688c551c9bae92a74fa116852ac20bb9b2df4c12bd2fcf1cd46a92500160405180910390a2505050505050565b6000806000836001600160a01b0316636fb1bf666040518163ffffffff1660e01b8152600401604080518083038186803b15801561151a57600080fd5b505afa15801561152e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115529190613aba565b915091506000806000866001600160a01b031663606c0c946040518163ffffffff1660e01b815260040160606040518083038186803b15801561159457600080fd5b505afa1580156115a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115cc9190613ade565b9250925092506000806000808b6001600160a01b031663e547c77c6040518163ffffffff1660e01b815260040160806040518083038186803b15801561161157600080fd5b505afa158015611625573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116499190613b23565b6001600160401b031693506001600160401b031693506001600160401b031693506001600160401b0316935082871415806116845750818614155b8061168f5750808514155b156116b05760405163687571a560e01b81526000600482015260240161061b565b8388146116d35760405163687571a560e01b81526001600482015260240161061b565b505050506000886001600160a01b03166389896aef6040518163ffffffff1660e01b815260040160206040518083038186803b15801561171257600080fd5b505afa158015611726573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061174a9190613b77565b90506117568582613aa2565b86146117785760405163687571a560e01b81526002600482015260240161061b565b6117828482613b90565b9998505050505050505050565b61179a600085612b3d565b610839838383612b47565b6117af8282610c3d565b6107d4576117c7816001600160a01b03166014612bb3565b6117d2836020612bb3565b6040516020016117e3929190613bdb565b60408051601f198184030181529082905262461bcd60e51b825261061b91600401613c4a565b6118138282612d4e565b6000828152600080516020613eb58339815191526020526040902061087e9082612dc4565b6118428282612dd9565b6000828152600080516020613eb58339815191526020526040902061087e9082612e4d565b600061187f600080516020613f158339815191525490565b9050808214156118a257604051631d7c761b60e21b815260040160405180910390fd5b6118b9600080516020613f15833981519152839055565b604051819083907ffa5304972d4ec3e3207f0bbf91155a49d0dfa62488f9529403a2a49e4b29a89590600090a35050565b600080611903600080516020613e958339815191525490565b90506000816001600160a01b03166372f79b136040518163ffffffff1660e01b8152600401604080518083038186803b15801561193f57600080fd5b505afa158015611953573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119779190613aba565b509392505050565b7ff9f2bb418c2b91bec33476bd883cf719692d3c9eed6e03bb161098abe08fa63d90565b6000610c368383612e62565b6001600160a01b0382166119d6576040516303988b8160e61b815260040160405180910390fd5b60006119ee600080516020613e958339815191525490565b9050806001600160a01b0316836001600160a01b03161415611a23576040516321a55ce160e11b815260040160405180910390fd5b600080846001600160a01b031663606c0c946040518163ffffffff1660e01b815260040160606040518083038186803b158015611a5f57600080fd5b505afa158015611a73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a979190613ade565b92509250507f000000000000000000000000000000000000000000000000000000000000000082141580611aeb57507f00000000000000000000000000000000000000000000000000000000000000008114155b15611b0957604051635401d0a160e11b815260040160405180910390fd5b6000856001600160a01b0316636095012f6040518163ffffffff1660e01b815260040160206040518083038186803b158015611b4457600080fd5b505afa158015611b58573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b7c9190613b77565b905084811015611ba957604051631e779ad160e11b8152600481018290526024810186905260440161061b565b611bc0600080516020613e95833981519152879055565b836001600160a01b0316866001600160a01b03167f25421480fb7f52d18947876279a213696b58d7e0e5416ce5e2c9f9942661c34c60405160405180910390a3505050505050565b60006105cd825490565b50565b6000611c1f61197f565b6040805160e08101825282546001600160401b03808216835261ffff600160401b830416602084015260ff600160501b830416151593830193909352600160581b810483166060830152600160981b90049091166080820152600182015460a082015260029091015460c08201529050611c9a816000612831565b806040015115611cbd576040516313f2ae7160e11b815260040160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ef6c064c6040518163ffffffff1660e01b815260040160206040518083038186803b158015611d1657600080fd5b505afa158015611d2a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d4e9190613a6f565b6001600160a01b031663db3c7ba76040518163ffffffff1660e01b8152600401600060405180830381600087803b158015611d8857600080fd5b505af1158015611d9c573d6000803e3d6000fd5b505050506001611daa61197f565b8054911515600160501b0260ff60501b19909216919091179055805160408051600080825260208201526001600160401b03909216917f6d8abc91d336688c551c9bae92a74fa116852ac20bb9b2df4c12bd2fcf1cd46a910160405180910390a250565b33611e397f65fa0c17458517c727737e4153dd477fa3e328cf706640b0f68b1a285c5990da82610c3d565b158015611e4c5750611e4a81612e8c565b155b15611c12576040516323dada5360e01b815260040160405180910390fd5b6000611e746109d5565b90508082146107d4576040516303abe78360e21b8152600481018290526024810183905260440161061b565b6000611eaa610f47565b60408051606081018252825481526001909201546001600160401b0380821660208501819052600160401b90920416918301919091529091508414611f1a57602081015160405163490b8d4560e11b81526001600160401b0390911660048201526024810185905260440161061b565b6000611f32600080516020613f158339815191525490565b9050808414611f5e57604051632a37dd3d60e11b8152600481018290526024810185905260440161061b565b81518314611f8c57815160405163642c75c760e11b815260048101919091526024810184905260440161061b565b5050505050565b600080611f9e610f47565b6040805160608101825282548082526001909301546001600160401b038082166020840152600160401b90910416918101919091529150611ff2576040516364dfc18f60e01b815260040160405180910390fd5b61200881604001516001600160401b0316612f22565b6000612020600080516020613ef58339815191525490565b905081602001516001600160401b031681141561204f576040516252e2c960e41b815260040160405180910390fd5b6020828101516001600160401b0316600080516020613ef5833981519152819055835160405190815290917ff73febded7d4502284718948a3e1d75406151c6326bde069424a584a4f6af87a910160405180910390a292915050565b61018082013561211e576101a0820135156120e75760405163d2b3f3cf60e01b8152600060048201526101a0830135602482015260440161061b565b6101c08201351561211957604051631c4de3e160e11b8152600060048201526101c0830135602482015260440161061b565b612191565b60018261018001351461214b5760405163396e5b8360e01b8152610180830135600482015260240161061b565b6101c082013561216e5760405163f1ff5c1760e01b815260040160405180910390fd5b6101a082013561219157604051630862a50360e31b815260040160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f5e6d50f6040518163ffffffff1660e01b815260040160206040518083038186803b1580156121ea57600080fd5b505afa1580156121fe573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122229190613a6f565b604051631a95535960e11b81526101c084013560048201526001600160a01b03919091169063352aa6b29060240160006040518083038186803b15801561226857600080fd5b505afa15801561227c573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166391d2247c83602001358460600135633b9aca006122c89190613b90565b604080516001600160e01b031960e086901b168152600481019390935260248301919091528501356044820152606401600060405180830381600087803b15801561231257600080fd5b505af1158015612326573d6000803e3d6000fd5b50505050600081836020013561233c9190613c7d565b905060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ef6c064c6040518163ffffffff1660e01b815260040160206040518083038186803b15801561239957600080fd5b505afa1580156123ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123d19190613a6f565b905060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166337d5fe996040518163ffffffff1660e01b815260040160206040518083038186803b15801561242e57600080fd5b505afa158015612442573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124669190613a6f565b905061248c826124796080880188613c94565b61248660a08a018a613c94565b88612f46565b6001600160a01b0381166396992fed6124ad61018088016101608901613cdd565b6124d77f000000000000000000000000000000000000000000000000000000000000000088613b90565b612501907f0000000000000000000000000000000000000000000000000000000000000000613aa2565b61252f7f000000000000000000000000000000000000000000000000000000000000000060208b0135613b90565b612559907f0000000000000000000000000000000000000000000000000000000000000000613aa2565b6040516001600160e01b031960e086901b168152921515600484015260248301919091526044820152606401600060405180830381600087803b15801561259f57600080fd5b505af11580156125b3573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663bac3f3c57f000000000000000000000000000000000000000000000000000000000000000087602001356126169190613b90565b612640907f0000000000000000000000000000000000000000000000000000000000000000613aa2565b61266a7f000000000000000000000000000000000000000000000000000000000000000087613b90565b604089013561268160608b0135633b9aca00613b90565b60c08b013560e08c01356101008d013561269f6101208f018f613c94565b8f61014001356040518b63ffffffff1660e01b81526004016126ca9a99989796959493929190613cfa565b600060405180830381600087803b1580156126e457600080fd5b505af11580156126f8573d6000803e3d6000fd5b505050506040518060e001604052806127148760200135610f6b565b6001600160401b031681526020016127308761018001356131f2565b61ffff1681526000602082015260400161274e6101c08801356131f2565b61ffff16815260006020820181905260408201526101a087013560609091015261277661197f565b8151815460208401516040850151606086015160808701516001600160401b0395861669ffffffffffffffffffff1990951694909417600160401b61ffff909416939093029290921768ffffffffffffffffff60501b1916600160501b9115159190910267ffffffffffffffff60581b191617600160581b918416919091021767ffffffffffffffff60981b1916600160981b929091169190910217815560a0820151600182015560c0909101516002909101555050505050565b612839611e0e565b6000612843610f47565b6040805160608101825282548082526001909301546001600160401b038082166020840152600160401b9091041691810191909152915015806128a0575080602001516001600160401b031683600001516001600160401b031614155b156128be5760405163a74cb4e560e01b815260040160405180910390fd5b6128c6613255565b81836020015161ffff161461087e576020830151604051630eb3232760e21b815261ffff90911660048201526024810183905260440161061b565b60408101516000805b84831015612a33576020840151600584019387013560e881901c9160d89190911c61ffff169061296257811561295d5760405163067db80560e31b8152600060048201526024810183905260440161061b565b6129a6565b855161296f906001613aa2565b82146129a6578551612982906001613aa2565b60405163067db80560e31b815260048101919091526024810183905260440161061b565b818652602086018190526040860185905260028114806129c65750600181145b156129ef5760006129d8898989613279565b9050848111156129e9578094508293505b50612a12565b604051634166218d60e11b8152600481018390526024810182905260440161061b565b84866040015111612a2557612a25613d52565b85604001519450505061290a565b60008211612a4357612a43613d52565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f5e6d50f6040518163ffffffff1660e01b815260040160206040518083038186803b158015612a9c57600080fd5b505afa158015612ab0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ad49190613a6f565b60405163057e0f6960e41b815260048101839052602481018490526001600160a01b0391909116906357e0f6909060440160006040518083038186803b158015612b1d57600080fd5b505afa158015612b31573d6000803e3d6000fd5b50505050505050505050565b6107d48282611809565b612b516001613494565b612b5b83826119af565b612b6482611867565b612b7b600080516020613ef5833981519152829055565b612b8481610f6b565b612b8c610f47565b600101805467ffffffffffffffff19166001600160401b0392909216919091179055505050565b60606000612bc2836002613b90565b612bcd906002613aa2565b6001600160401b03811115612be457612be4613d68565b6040519080825280601f01601f191660200182016040528015612c0e576020820181803683370190505b509050600360fc1b81600081518110612c2957612c29613d7e565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110612c5857612c58613d7e565b60200101906001600160f81b031916908160001a9053506000612c7c846002613b90565b612c87906001613aa2565b90505b6001811115612cff576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110612cbb57612cbb613d7e565b1a60f81b828281518110612cd157612cd1613d7e565b60200101906001600160f81b031916908160001a90535060049490941c93612cf881613d94565b9050612c8a565b508315610c365760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161061b565b612d588282610c3d565b6107d4576000828152600080516020613ed5833981519152602090815260408083206001600160a01b0385168085529252808320805460ff1916600117905551339285917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a45050565b6000610c36836001600160a01b0384166134c3565b612de38282610c3d565b156107d4576000828152600080516020613ed5833981519152602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000610c36836001600160a01b038416613512565b6000826000018281548110612e7957612e79613d7e565b9060005260206000200154905092915050565b600080612ea5600080516020613e958339815191525490565b604051631951c03760e01b81526001600160a01b03858116600483015291925090821690631951c0379060240160206040518083038186803b158015612eea57600080fd5b505afa158015612efe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c369190613dab565b80421115611c125760405163537bacdf60e11b81526004810182905260240161061b565b838214612f6657604051637540f08160e11b815260040160405180910390fd5b83612f70576107c2565b60015b84811015612fdd578585612f88600184613c7d565b818110612f9757612f97613d7e565b90506020020135868683818110612fb057612fb0613d7e565b9050602002013511612fd557604051637540f08160e11b815260040160405180910390fd5b600101612f73565b5060005b8481101561302b57838382818110612ffb57612ffb613d7e565b905060200201356000141561302357604051637540f08160e11b815260040160405180910390fd5b600101612fe1565b50604051632af5128960e21b81526000906001600160a01b0388169063abd44a2490613061908990899089908990600401613dc8565b602060405180830381600087803b15801561307b57600080fd5b505af115801561308f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130b39190613b77565b905060006130e1837f0000000000000000000000000000000000000000000000000000000000000000613b90565b6130ee8362015180613b90565b6130f89190613dfa565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f5e6d50f6040518163ffffffff1660e01b815260040160206040518083038186803b15801561315357600080fd5b505afa158015613167573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061318b9190613a6f565b6001600160a01b031663e72980f4826040518263ffffffff1660e01b81526004016131b891815260200190565b60006040518083038186803b1580156131d057600080fd5b505afa1580156131e4573d6000803e3d6000fd5b505050505050505050505050565b600061ffff821115610fd35760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201526536206269747360d01b606482015260840161061b565b610e6b613260610f47565b60010154600160401b90046001600160401b0316612f22565b6040810151600090818080368181818a613294896023613aa2565b11156132b9578951604051635d84060560e11b8152600481019190915260240161061b565b878c01358060e81c97506001600160401b038160a81c16965050600b88018c019350600886029250833560c01c945082840191506010860290508b8183010397508660001415613322578951604051635d84060560e11b8152600481019190915260240161061b565b600085604089901b60f08d60200151901b171790508a606001518111613361578a51604051630cf5139d60e11b8152600481019190915260240161061b565b60608b01528a881180613372575085155b15613396578951604051635d84060560e11b8152600481019190915260240161061b565b60018a6020015114156134125789608001516001600160a01b031663cb589b9a88868686866040518663ffffffff1660e01b81526004016133db959493929190613e45565b600060405180830381600087803b1580156133f557600080fd5b505af1158015613409573d6000803e3d6000fd5b5050505061347d565b89608001516001600160a01b031663c8ac498088868686866040518663ffffffff1660e01b815260040161344a959493929190613e45565b600060405180830381600087803b15801561346457600080fd5b505af1158015613478573d6000803e3d6000fd5b505050505b505050506040860193909352925050509392505050565b61349c6109d5565b156134ba5760405163184e52a160e21b815260040160405180910390fd5b611c1281613605565b600081815260018301602052604081205461350a575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556105cd565b5060006105cd565b600081815260018301602052604081205480156135fb576000613536600183613c7d565b855490915060009061354a90600190613c7d565b90508181146135af57600086600001828154811061356a5761356a613d7e565b906000526020600020015490508087600001848154811061358d5761358d613d7e565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806135c0576135c0613e7e565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506105cd565b60009150506105cd565b61362e7f4dd0f6662ba1d6b081f08b350f5e9a6a7b15cf586926ba66f753594928fa64a6829055565b6040518181527ffddcded6b4f4730c226821172046b48372d3cd963c159701ae1b7c3bcac541bb9060200160405180910390a150565b60006020828403121561367657600080fd5b81356001600160e01b031981168114610c3657600080fd5b6000806000606084860312156136a357600080fd5b505081359360208301359350604090920135919050565b600080602083850312156136cd57600080fd5b82356001600160401b03808211156136e457600080fd5b818501915085601f8301126136f857600080fd5b81358181111561370757600080fd5b86602082850101111561371957600080fd5b60209290920196919550909350505050565b6001600160a01b0381168114611c1257600080fd5b60008060006060848603121561375557600080fd5b83356137608161372b565b925060208401356137708161372b565b929592945050506040919091013590565b60006020828403121561379357600080fd5b5035919050565b600080604083850312156137ad57600080fd5b8235915060208301356137bf8161372b565b809150509250929050565b600080604083850312156137dd57600080fd5b50508035926020909101359150565b6000806000806080858703121561380257600080fd5b843561380d8161372b565b9350602085013561381d8161372b565b93969395505050506040820135916060013590565b60006020828403121561384457600080fd5b8135610c368161372b565b6000806040838503121561386257600080fd5b82356001600160401b0381111561387857600080fd5b83016101e0818603121561388b57600080fd5b946020939093013593505050565b6000808335601e198436030181126138b057600080fd5b83016020810192503590506001600160401b038111156138cf57600080fd5b8060051b36038313156138e157600080fd5b9250929050565b81835260006001600160fb1b0383111561390157600080fd5b8260051b8083602087013760009401602001938452509192915050565b8015158114611c1257600080fd5b80356139378161391e565b919050565b602081528135602082015260208201356040820152604082013560608201526060820135608082015260006139746080840184613899565b6101e08060a086015261398c610200860183856138e8565b925061399b60a0870187613899565b9250601f19808786030160c08801526139b58585846138e8565b945060c088013560e0880152610100935060e088013584880152610120915083880135828801526139e882890189613899565b94509150610140818887030181890152613a038686856138e8565b955061016094508089013585890152505050613a2082870161392c565b9150610180613a328187018415159052565b8601356101a0868101919091528601356101c0808701919091529095013594909301939093525090919050565b8183823760009101908152919050565b600060208284031215613a8157600080fd5b8151610c368161372b565b634e487b7160e01b600052601160045260246000fd5b60008219821115613ab557613ab5613a8c565b500190565b60008060408385031215613acd57600080fd5b505080516020909101519092909150565b600080600060608486031215613af357600080fd5b8351925060208401519150604084015190509250925092565b80516001600160401b038116811461393757600080fd5b60008060008060808587031215613b3957600080fd5b613b4285613b0c565b9350613b5060208601613b0c565b9250613b5e60408601613b0c565b9150613b6c60608601613b0c565b905092959194509250565b600060208284031215613b8957600080fd5b5051919050565b6000816000190483118215151615613baa57613baa613a8c565b500290565b60005b83811015613bca578181015183820152602001613bb2565b838111156108395750506000910152565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b815260008351613c0d816017850160208801613baf565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351613c3e816028840160208801613baf565b01602801949350505050565b6020815260008251806020840152613c69816040850160208701613baf565b601f01601f19169190910160400192915050565b600082821015613c8f57613c8f613a8c565b500390565b6000808335601e19843603018112613cab57600080fd5b8301803591506001600160401b03821115613cc557600080fd5b6020019150600581901b36038213156138e157600080fd5b600060208284031215613cef57600080fd5b8135610c368161391e565b60006101208c83528b60208401528a60408401528960608401528860808401528760a08401528660c08401528060e0840152613d3981840186886138e8565b915050826101008301529b9a5050505050505050505050565b634e487b7160e01b600052600160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600081613da357613da3613a8c565b506000190190565b600060208284031215613dbd57600080fd5b8151610c368161391e565b604081526000613ddc6040830186886138e8565b8281036020840152613def8185876138e8565b979650505050505050565b600082613e1757634e487b7160e01b600052601260045260246000fd5b500490565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b858152606060208201526000613e5f606083018688613e1c565b8281036040840152613e72818587613e1c565b98975050505050505050565b634e487b7160e01b600052603160045260246000fdfeb0e01b719c2c32a677822ce1584cb6a66e576ee3c2c506b9621dbe626355aa658f8c450dae5029cd48cd91dd9db65da48fb742893edfc7941250f6721d93cbbe9a627a5d4aa7c17f87ff26e3fe9a42c2b6c559e8b41a42282d0ecebb17c0e4d3c9bdcd6eb2e956ecf03d8d27bee4c163f9b5c078aa69020d618e76513b5d0a942767d6892477f8d2750fb44e817c9aed93d34d3c6be4101ed58bcac692c99e9ca2646970667358221220d52b9e9caa2c13b657cc805ae83ee728554e066ca239fd40c547751ff4e4252e64736f6c6343000809003300000000000000000000000022ae3d0b58dd75fcaedeb8ecde3c6a5a59599047000000000000000000000000a484daaeab44914d5f55712075e9be6983400eb10000000000000000000000000bb280df53da700b7f1bed5a126c32f949a0eb04000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000064377651
Deployed ByteCode
0x608060405234801561001057600080fd5b506004361061021b5760003560e01c80638b21f17011610125578063b74d4631116100ad578063d43812171161007c578063d438121714610540578063d547741f14610553578063f288246114610566578063fa565b051461058d578063fc7377cd1461059557600080fd5b8063b74d4631146104e0578063c469c307146104f3578063ca15c87314610506578063ce976fa91461051957600080fd5b80639010d07c116100f45780639010d07c1461046c57806391d148541461047f5780639cc23c7914610492578063a217fddf146103a1578063ad5cac4e146104b957600080fd5b80638b21f170146103b15780638d591474146103d85780638f55b571146103eb5780638f7797c2146103f357600080fd5b806336568abe116101a85780635be20425116101775780635be204251461036f57806360d64d3814610377578063672690b41461022057806374facb9b146103a15780638aa10435146103a957600080fd5b806336568abe146102ee57806346e1f57614610301578063560f97cb1461032857806357a782891461033057600080fd5b80631794bb3c116101ef5780631794bb3c14610286578063248a9ca3146102995780632f2ff15d146102ac578063304b9071146102bf5780633584d59c146102e657600080fd5b80625418e11461022057806301ffc9a71461023b578063063f36ad1461025e57806306c373da14610273575b600080fd5b610228600181565b6040519081526020015b60405180910390f35b61024e610249366004613664565b6105a8565b6040519015158152602001610232565b61027161026c36600461368e565b6105d3565b005b6102716102813660046136ba565b6107ca565b610271610294366004613740565b6107d8565b6102286102a7366004613781565b61083f565b6102716102ba36600461379a565b610861565b6102287f000000000000000000000000000000000000000000000000000000000000000a81565b610228610883565b6102716102fc36600461379a565b6108a0565b6102287f65fa0c17458517c727737e4153dd477fa3e328cf706640b0f68b1a285c5990da81565b610228600281565b6103577f00000000000000000000000022ae3d0b58dd75fcaedeb8ecde3c6a5a5959904781565b6040516001600160a01b039091168152602001610232565b61022861091a565b61037f610932565b6040805194855260208501939093529183015215156060820152608001610232565b610228600081565b6102286109d5565b6103577f000000000000000000000000a484daaeab44914d5f55712075e9be6983400eb181565b6102716103e6366004613781565b6109ff565b610357610a33565b6103fb610a4b565b60405161023291906000610120820190508251825260208301516020830152604083015160408301526060830151151560608301526080830151608083015260a083015160a083015260c0830151151560c083015260e083015160e083015261010080840151818401525092915050565b61035761047a3660046137ca565b610c11565b61024e61048d36600461379a565b610c3d565b6102287fc31b1e4b732c5173dc51d519dfa432bad95550ecc4b0f9a61c2a558a2a8e434181565b6102287f04a0afbbd09d5ad397fc858789da4f8edd59f5ca5098d70faa490babee945c3b81565b6102716104ee3660046137ec565b610c75565b610271610501366004613832565b610ca8565b610228610514366004613781565b610cf2565b6103577f0000000000000000000000000bb280df53da700b7f1bed5a126c32f949a0eb0481565b61027161054e366004613781565b610d16565b61027161056136600461379a565b610e46565b6102287f000000000000000000000000000000000000000000000000000000006437765181565b610271610e63565b6102716105a336600461384f565b610e6d565b60006001600160e01b03198216635a05180f60e01b14806105cd57506105cd82610ed1565b92915050565b6105db610f06565b60006105e5610f47565b600101546001600160401b03169050808310156106245760405163431d301760e11b815260048101849052602481018290526044015b60405180910390fd5b600061063c600080516020613ef58339815191525490565b9050808411610668576040516360a41e4960e01b8152600481018590526024810182905260440161061b565b8242111561068c5760405163537bacdf60e11b81526004810184905260240161061b565b81841415801561069c5750818114155b156106cd5760405182907f800b849c8bf80718cf786c99d1091c079fe2c5e420a3ba7ba9b0ef8179ef2c3890600090a25b846106eb57604051635b18a69f60e11b815260040160405180910390fd5b604080518681526020810185905285917faed7d1a7a1831158dcda1e4214f5862f450bd3eb5721a5f322bf8c9fe1790b0a910160405180910390a26000604051806060016040528087815260200161074287610f6b565b6001600160401b0316815260200161075986610f6b565b6001600160401b0316905290508061076f610f47565b815181556020820151600190910180546040909301516001600160401b03908116600160401b026fffffffffffffffffffffffffffffffff199094169216919091179190911790556107c2818484610fd7565b505050505050565b6107d482826110e7565b5050565b6001600160a01b0383166107ff57604051636b35b1b760e01b815260040160405180910390fd5b600061082b7f0000000000000000000000000bb280df53da700b7f1bed5a126c32f949a0eb04846114dd565b90506108398484848461178f565b50505050565b6000908152600080516020613ed5833981519152602052604090206001015490565b61086a8261083f565b61087481336117a5565b61087e8383611809565b505050565b600061089b600080516020613ef58339815191525490565b905090565b6001600160a01b03811633146109105760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840161061b565b6107d48282611838565b600061089b600080516020613f158339815191525490565b6000806000806000610942610f47565b60408051606081018252825481526001909201546001600160401b038082166020850152600160401b90910416908201529050600061098d600080516020613ef58339815191525490565b825160208401516040850151929350909182158015906109b957508385602001516001600160401b0316145b92996001600160401b0392831699509116965090945092505050565b600061089b7f4dd0f6662ba1d6b081f08b350f5e9a6a7b15cf586926ba66f753594928fa64a65490565b7fc31b1e4b732c5173dc51d519dfa432bad95550ecc4b0f9a61c2a558a2a8e4341610a2a81336117a5565b6107d482611867565b600061089b600080516020613e958339815191525490565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905290610a9c610f47565b60408051606081018252825481526001909201546001600160401b038082166020850152600160401b90910416908201529050610ad76118ea565b825280511580610af8575080602001516001600160401b0316826000015114155b15610b01575090565b6040808201516001600160401b031660208401528151908301526000610b33600080516020613ef58339815191525490565b60208301516001600160401b0316811460608501819052909150610b5657505090565b6000610b6061197f565b6040805160e0808201835283546001600160401b03808216845261ffff600160401b830481166020860190815260ff600160501b8504161515968601968752600160581b8404831660608701908152600160981b9094048316608080880191825260018a015460a0808a01919091526002909a015460c0988901819052908e01529051909116968b019690965293511515928901929092529051821690870152905116610100850152509192915050565b6000828152600080516020613eb583398151915260205260408120610c3690836119a3565b9392505050565b6000918252600080516020613ed5833981519152602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6001600160a01b038416610c9c57604051636b35b1b760e01b815260040160405180910390fd5b6108398484848461178f565b7f04a0afbbd09d5ad397fc858789da4f8edd59f5ca5098d70faa490babee945c3b610cd381336117a5565b6107d482610ced600080516020613ef58339815191525490565b6119af565b6000818152600080516020613eb5833981519152602052604081206105cd90611c08565b610d1e610f06565b6000610d28610f47565b60408051606081018252825481526001909201546001600160401b0380821660208501819052600160401b9092041691830191909152909150821015610d9957602081015160405163431d301760e11b8152600481018490526001600160401b03909116602482015260440161061b565b80602001516001600160401b0316821115610db2575050565b6000610dca600080516020613ef58339815191525490565b9050808311610deb576040516252e2c960e41b815260040160405180910390fd5b6000610df5610f47565b5581602001516001600160401b03167fe21266bc27ee721ac10034efaf7fd724656ef471c75b8402cd8f07850af6b6768360000151604051610e3991815260200190565b60405180910390a2505050565b610e4f8261083f565b610e5981336117a5565b61087e8383611838565b610e6b611c15565b565b610e75611e0e565b610e7e81611e6a565b610eb78260200135836000013584604051602001610e9c919061393c565b60405160208183030381529060405280519060200120611ea0565b6000610ec1611f93565b905061087e83826120ab565b9055565b60006001600160e01b03198216637965db0b60e01b14806105cd57506301ffc9a760e01b6001600160e01b03198316146105cd565b600080516020613e95833981519152546001600160a01b0316336001600160a01b031614610e6b5760405163fef4d83160e01b815260040160405180910390fd5b7f9d565e483b8608dc09e04eff85533859683d2eeaa6ebc28af53a92d7dba3eea690565b60006001600160401b03821115610fd35760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203660448201526534206269747360d01b606482015260840161061b565b5090565b6000610fe161197f565b6040805160e08101825282546001600160401b0380821680845261ffff600160401b840416602085015260ff600160501b840416151594840194909452600160581b820481166060840152600160981b909104166080820152600183015460a082015260029092015460c083015290915082148015611085575080604001511580611085575080606001516001600160401b031681608001516001600160401b0316105b1561083957817f801a93267f699b033e11b662b16b36c41b6f9a59a5b5ad967d4cb84232e523c2826080015183606001516040516110d99291906001600160401b0392831681529116602082015260400190565b60405180910390a250505050565b60006110f161197f565b6040805160e08101825282546001600160401b03808216835261ffff600160401b830416602084015260ff600160501b830416151593830193909352600160581b810483166060830152600160981b9004909116608082015260018083015460a083015260029092015460c0820152915061116d908290612831565b80606001516001600160401b031681608001516001600160401b031614156111a8576040516313f2ae7160e11b815260040160405180910390fd5b60808101516001600160401b0316156111d457604051631d07c31960e21b815260040160405180910390fd5b600083836040516111e6929190613a5f565b604051809103902090508160c0015181146112245760c082015160405163d2b3f3cf60e01b815260048101919091526024810182905260440161061b565b60006040518060a00160405280600081526020016000815260200160008152602001600081526020017f00000000000000000000000022ae3d0b58dd75fcaedeb8ecde3c6a5a595990476001600160a01b031663ef6c064c6040518163ffffffff1660e01b815260040160206040518083038186803b1580156112a657600080fd5b505afa1580156112ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112de9190613a6f565b6001600160a01b0316905290506112f6858583612901565b8051600090611306906001613aa2565b905083606001516001600160401b0316811461134d576060840151604051631c4de3e160e11b81526001600160401b0390911660048201526024810182905260440161061b565b600160408501526001600160401b0381166080850152606082015160a08501528361137661197f565b81518154602084015160408086015160608701516080808901516001600160401b03908116600160981b0267ffffffffffffffff60981b19938216600160581b0267ffffffffffffffff60581b19951515600160501b029590951668ffffffffffffffffff60501b1961ffff909816600160401b0269ffffffffffffffffffff199099169290991691909117969096179490941695909517179390931691909117835560a0840151600184015560c09093015160029092019190915590830151815163db3c7ba760e01b815291516001600160a01b039091169163db3c7ba791600480830192600092919082900301818387803b15801561147657600080fd5b505af115801561148a573d6000803e3d6000fd5b5050855160408051858152602081018690526001600160401b0390921693507f6d8abc91d336688c551c9bae92a74fa116852ac20bb9b2df4c12bd2fcf1cd46a92500160405180910390a2505050505050565b6000806000836001600160a01b0316636fb1bf666040518163ffffffff1660e01b8152600401604080518083038186803b15801561151a57600080fd5b505afa15801561152e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115529190613aba565b915091506000806000866001600160a01b031663606c0c946040518163ffffffff1660e01b815260040160606040518083038186803b15801561159457600080fd5b505afa1580156115a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115cc9190613ade565b9250925092506000806000808b6001600160a01b031663e547c77c6040518163ffffffff1660e01b815260040160806040518083038186803b15801561161157600080fd5b505afa158015611625573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116499190613b23565b6001600160401b031693506001600160401b031693506001600160401b031693506001600160401b0316935082871415806116845750818614155b8061168f5750808514155b156116b05760405163687571a560e01b81526000600482015260240161061b565b8388146116d35760405163687571a560e01b81526001600482015260240161061b565b505050506000886001600160a01b03166389896aef6040518163ffffffff1660e01b815260040160206040518083038186803b15801561171257600080fd5b505afa158015611726573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061174a9190613b77565b90506117568582613aa2565b86146117785760405163687571a560e01b81526002600482015260240161061b565b6117828482613b90565b9998505050505050505050565b61179a600085612b3d565b610839838383612b47565b6117af8282610c3d565b6107d4576117c7816001600160a01b03166014612bb3565b6117d2836020612bb3565b6040516020016117e3929190613bdb565b60408051601f198184030181529082905262461bcd60e51b825261061b91600401613c4a565b6118138282612d4e565b6000828152600080516020613eb58339815191526020526040902061087e9082612dc4565b6118428282612dd9565b6000828152600080516020613eb58339815191526020526040902061087e9082612e4d565b600061187f600080516020613f158339815191525490565b9050808214156118a257604051631d7c761b60e21b815260040160405180910390fd5b6118b9600080516020613f15833981519152839055565b604051819083907ffa5304972d4ec3e3207f0bbf91155a49d0dfa62488f9529403a2a49e4b29a89590600090a35050565b600080611903600080516020613e958339815191525490565b90506000816001600160a01b03166372f79b136040518163ffffffff1660e01b8152600401604080518083038186803b15801561193f57600080fd5b505afa158015611953573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119779190613aba565b509392505050565b7ff9f2bb418c2b91bec33476bd883cf719692d3c9eed6e03bb161098abe08fa63d90565b6000610c368383612e62565b6001600160a01b0382166119d6576040516303988b8160e61b815260040160405180910390fd5b60006119ee600080516020613e958339815191525490565b9050806001600160a01b0316836001600160a01b03161415611a23576040516321a55ce160e11b815260040160405180910390fd5b600080846001600160a01b031663606c0c946040518163ffffffff1660e01b815260040160606040518083038186803b158015611a5f57600080fd5b505afa158015611a73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a979190613ade565b92509250507f000000000000000000000000000000000000000000000000000000000000000a82141580611aeb57507f00000000000000000000000000000000000000000000000000000000643776518114155b15611b0957604051635401d0a160e11b815260040160405180910390fd5b6000856001600160a01b0316636095012f6040518163ffffffff1660e01b815260040160206040518083038186803b158015611b4457600080fd5b505afa158015611b58573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b7c9190613b77565b905084811015611ba957604051631e779ad160e11b8152600481018290526024810186905260440161061b565b611bc0600080516020613e95833981519152879055565b836001600160a01b0316866001600160a01b03167f25421480fb7f52d18947876279a213696b58d7e0e5416ce5e2c9f9942661c34c60405160405180910390a3505050505050565b60006105cd825490565b50565b6000611c1f61197f565b6040805160e08101825282546001600160401b03808216835261ffff600160401b830416602084015260ff600160501b830416151593830193909352600160581b810483166060830152600160981b90049091166080820152600182015460a082015260029091015460c08201529050611c9a816000612831565b806040015115611cbd576040516313f2ae7160e11b815260040160405180910390fd5b7f00000000000000000000000022ae3d0b58dd75fcaedeb8ecde3c6a5a595990476001600160a01b031663ef6c064c6040518163ffffffff1660e01b815260040160206040518083038186803b158015611d1657600080fd5b505afa158015611d2a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d4e9190613a6f565b6001600160a01b031663db3c7ba76040518163ffffffff1660e01b8152600401600060405180830381600087803b158015611d8857600080fd5b505af1158015611d9c573d6000803e3d6000fd5b505050506001611daa61197f565b8054911515600160501b0260ff60501b19909216919091179055805160408051600080825260208201526001600160401b03909216917f6d8abc91d336688c551c9bae92a74fa116852ac20bb9b2df4c12bd2fcf1cd46a910160405180910390a250565b33611e397f65fa0c17458517c727737e4153dd477fa3e328cf706640b0f68b1a285c5990da82610c3d565b158015611e4c5750611e4a81612e8c565b155b15611c12576040516323dada5360e01b815260040160405180910390fd5b6000611e746109d5565b90508082146107d4576040516303abe78360e21b8152600481018290526024810183905260440161061b565b6000611eaa610f47565b60408051606081018252825481526001909201546001600160401b0380821660208501819052600160401b90920416918301919091529091508414611f1a57602081015160405163490b8d4560e11b81526001600160401b0390911660048201526024810185905260440161061b565b6000611f32600080516020613f158339815191525490565b9050808414611f5e57604051632a37dd3d60e11b8152600481018290526024810185905260440161061b565b81518314611f8c57815160405163642c75c760e11b815260048101919091526024810184905260440161061b565b5050505050565b600080611f9e610f47565b6040805160608101825282548082526001909301546001600160401b038082166020840152600160401b90910416918101919091529150611ff2576040516364dfc18f60e01b815260040160405180910390fd5b61200881604001516001600160401b0316612f22565b6000612020600080516020613ef58339815191525490565b905081602001516001600160401b031681141561204f576040516252e2c960e41b815260040160405180910390fd5b6020828101516001600160401b0316600080516020613ef5833981519152819055835160405190815290917ff73febded7d4502284718948a3e1d75406151c6326bde069424a584a4f6af87a910160405180910390a292915050565b61018082013561211e576101a0820135156120e75760405163d2b3f3cf60e01b8152600060048201526101a0830135602482015260440161061b565b6101c08201351561211957604051631c4de3e160e11b8152600060048201526101c0830135602482015260440161061b565b612191565b60018261018001351461214b5760405163396e5b8360e01b8152610180830135600482015260240161061b565b6101c082013561216e5760405163f1ff5c1760e01b815260040160405180910390fd5b6101a082013561219157604051630862a50360e31b815260040160405180910390fd5b7f00000000000000000000000022ae3d0b58dd75fcaedeb8ecde3c6a5a595990476001600160a01b031663f5e6d50f6040518163ffffffff1660e01b815260040160206040518083038186803b1580156121ea57600080fd5b505afa1580156121fe573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122229190613a6f565b604051631a95535960e11b81526101c084013560048201526001600160a01b03919091169063352aa6b29060240160006040518083038186803b15801561226857600080fd5b505afa15801561227c573d6000803e3d6000fd5b505050507f0000000000000000000000000bb280df53da700b7f1bed5a126c32f949a0eb046001600160a01b03166391d2247c83602001358460600135633b9aca006122c89190613b90565b604080516001600160e01b031960e086901b168152600481019390935260248301919091528501356044820152606401600060405180830381600087803b15801561231257600080fd5b505af1158015612326573d6000803e3d6000fd5b50505050600081836020013561233c9190613c7d565b905060007f00000000000000000000000022ae3d0b58dd75fcaedeb8ecde3c6a5a595990476001600160a01b031663ef6c064c6040518163ffffffff1660e01b815260040160206040518083038186803b15801561239957600080fd5b505afa1580156123ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123d19190613a6f565b905060007f00000000000000000000000022ae3d0b58dd75fcaedeb8ecde3c6a5a595990476001600160a01b03166337d5fe996040518163ffffffff1660e01b815260040160206040518083038186803b15801561242e57600080fd5b505afa158015612442573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124669190613a6f565b905061248c826124796080880188613c94565b61248660a08a018a613c94565b88612f46565b6001600160a01b0381166396992fed6124ad61018088016101608901613cdd565b6124d77f000000000000000000000000000000000000000000000000000000000000000a88613b90565b612501907f0000000000000000000000000000000000000000000000000000000064377651613aa2565b61252f7f000000000000000000000000000000000000000000000000000000000000000a60208b0135613b90565b612559907f0000000000000000000000000000000000000000000000000000000064377651613aa2565b6040516001600160e01b031960e086901b168152921515600484015260248301919091526044820152606401600060405180830381600087803b15801561259f57600080fd5b505af11580156125b3573d6000803e3d6000fd5b505050507f000000000000000000000000a484daaeab44914d5f55712075e9be6983400eb16001600160a01b031663bac3f3c57f000000000000000000000000000000000000000000000000000000000000000a87602001356126169190613b90565b612640907f0000000000000000000000000000000000000000000000000000000064377651613aa2565b61266a7f000000000000000000000000000000000000000000000000000000000000000a87613b90565b604089013561268160608b0135633b9aca00613b90565b60c08b013560e08c01356101008d013561269f6101208f018f613c94565b8f61014001356040518b63ffffffff1660e01b81526004016126ca9a99989796959493929190613cfa565b600060405180830381600087803b1580156126e457600080fd5b505af11580156126f8573d6000803e3d6000fd5b505050506040518060e001604052806127148760200135610f6b565b6001600160401b031681526020016127308761018001356131f2565b61ffff1681526000602082015260400161274e6101c08801356131f2565b61ffff16815260006020820181905260408201526101a087013560609091015261277661197f565b8151815460208401516040850151606086015160808701516001600160401b0395861669ffffffffffffffffffff1990951694909417600160401b61ffff909416939093029290921768ffffffffffffffffff60501b1916600160501b9115159190910267ffffffffffffffff60581b191617600160581b918416919091021767ffffffffffffffff60981b1916600160981b929091169190910217815560a0820151600182015560c0909101516002909101555050505050565b612839611e0e565b6000612843610f47565b6040805160608101825282548082526001909301546001600160401b038082166020840152600160401b9091041691810191909152915015806128a0575080602001516001600160401b031683600001516001600160401b031614155b156128be5760405163a74cb4e560e01b815260040160405180910390fd5b6128c6613255565b81836020015161ffff161461087e576020830151604051630eb3232760e21b815261ffff90911660048201526024810183905260440161061b565b60408101516000805b84831015612a33576020840151600584019387013560e881901c9160d89190911c61ffff169061296257811561295d5760405163067db80560e31b8152600060048201526024810183905260440161061b565b6129a6565b855161296f906001613aa2565b82146129a6578551612982906001613aa2565b60405163067db80560e31b815260048101919091526024810183905260440161061b565b818652602086018190526040860185905260028114806129c65750600181145b156129ef5760006129d8898989613279565b9050848111156129e9578094508293505b50612a12565b604051634166218d60e11b8152600481018390526024810182905260440161061b565b84866040015111612a2557612a25613d52565b85604001519450505061290a565b60008211612a4357612a43613d52565b7f00000000000000000000000022ae3d0b58dd75fcaedeb8ecde3c6a5a595990476001600160a01b031663f5e6d50f6040518163ffffffff1660e01b815260040160206040518083038186803b158015612a9c57600080fd5b505afa158015612ab0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ad49190613a6f565b60405163057e0f6960e41b815260048101839052602481018490526001600160a01b0391909116906357e0f6909060440160006040518083038186803b158015612b1d57600080fd5b505afa158015612b31573d6000803e3d6000fd5b50505050505050505050565b6107d48282611809565b612b516001613494565b612b5b83826119af565b612b6482611867565b612b7b600080516020613ef5833981519152829055565b612b8481610f6b565b612b8c610f47565b600101805467ffffffffffffffff19166001600160401b0392909216919091179055505050565b60606000612bc2836002613b90565b612bcd906002613aa2565b6001600160401b03811115612be457612be4613d68565b6040519080825280601f01601f191660200182016040528015612c0e576020820181803683370190505b509050600360fc1b81600081518110612c2957612c29613d7e565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110612c5857612c58613d7e565b60200101906001600160f81b031916908160001a9053506000612c7c846002613b90565b612c87906001613aa2565b90505b6001811115612cff576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110612cbb57612cbb613d7e565b1a60f81b828281518110612cd157612cd1613d7e565b60200101906001600160f81b031916908160001a90535060049490941c93612cf881613d94565b9050612c8a565b508315610c365760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161061b565b612d588282610c3d565b6107d4576000828152600080516020613ed5833981519152602090815260408083206001600160a01b0385168085529252808320805460ff1916600117905551339285917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a45050565b6000610c36836001600160a01b0384166134c3565b612de38282610c3d565b156107d4576000828152600080516020613ed5833981519152602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000610c36836001600160a01b038416613512565b6000826000018281548110612e7957612e79613d7e565b9060005260206000200154905092915050565b600080612ea5600080516020613e958339815191525490565b604051631951c03760e01b81526001600160a01b03858116600483015291925090821690631951c0379060240160206040518083038186803b158015612eea57600080fd5b505afa158015612efe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c369190613dab565b80421115611c125760405163537bacdf60e11b81526004810182905260240161061b565b838214612f6657604051637540f08160e11b815260040160405180910390fd5b83612f70576107c2565b60015b84811015612fdd578585612f88600184613c7d565b818110612f9757612f97613d7e565b90506020020135868683818110612fb057612fb0613d7e565b9050602002013511612fd557604051637540f08160e11b815260040160405180910390fd5b600101612f73565b5060005b8481101561302b57838382818110612ffb57612ffb613d7e565b905060200201356000141561302357604051637540f08160e11b815260040160405180910390fd5b600101612fe1565b50604051632af5128960e21b81526000906001600160a01b0388169063abd44a2490613061908990899089908990600401613dc8565b602060405180830381600087803b15801561307b57600080fd5b505af115801561308f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130b39190613b77565b905060006130e1837f000000000000000000000000000000000000000000000000000000000000000a613b90565b6130ee8362015180613b90565b6130f89190613dfa565b90507f00000000000000000000000022ae3d0b58dd75fcaedeb8ecde3c6a5a595990476001600160a01b031663f5e6d50f6040518163ffffffff1660e01b815260040160206040518083038186803b15801561315357600080fd5b505afa158015613167573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061318b9190613a6f565b6001600160a01b031663e72980f4826040518263ffffffff1660e01b81526004016131b891815260200190565b60006040518083038186803b1580156131d057600080fd5b505afa1580156131e4573d6000803e3d6000fd5b505050505050505050505050565b600061ffff821115610fd35760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201526536206269747360d01b606482015260840161061b565b610e6b613260610f47565b60010154600160401b90046001600160401b0316612f22565b6040810151600090818080368181818a613294896023613aa2565b11156132b9578951604051635d84060560e11b8152600481019190915260240161061b565b878c01358060e81c97506001600160401b038160a81c16965050600b88018c019350600886029250833560c01c945082840191506010860290508b8183010397508660001415613322578951604051635d84060560e11b8152600481019190915260240161061b565b600085604089901b60f08d60200151901b171790508a606001518111613361578a51604051630cf5139d60e11b8152600481019190915260240161061b565b60608b01528a881180613372575085155b15613396578951604051635d84060560e11b8152600481019190915260240161061b565b60018a6020015114156134125789608001516001600160a01b031663cb589b9a88868686866040518663ffffffff1660e01b81526004016133db959493929190613e45565b600060405180830381600087803b1580156133f557600080fd5b505af1158015613409573d6000803e3d6000fd5b5050505061347d565b89608001516001600160a01b031663c8ac498088868686866040518663ffffffff1660e01b815260040161344a959493929190613e45565b600060405180830381600087803b15801561346457600080fd5b505af1158015613478573d6000803e3d6000fd5b505050505b505050506040860193909352925050509392505050565b61349c6109d5565b156134ba5760405163184e52a160e21b815260040160405180910390fd5b611c1281613605565b600081815260018301602052604081205461350a575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556105cd565b5060006105cd565b600081815260018301602052604081205480156135fb576000613536600183613c7d565b855490915060009061354a90600190613c7d565b90508181146135af57600086600001828154811061356a5761356a613d7e565b906000526020600020015490508087600001848154811061358d5761358d613d7e565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806135c0576135c0613e7e565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506105cd565b60009150506105cd565b61362e7f4dd0f6662ba1d6b081f08b350f5e9a6a7b15cf586926ba66f753594928fa64a6829055565b6040518181527ffddcded6b4f4730c226821172046b48372d3cd963c159701ae1b7c3bcac541bb9060200160405180910390a150565b60006020828403121561367657600080fd5b81356001600160e01b031981168114610c3657600080fd5b6000806000606084860312156136a357600080fd5b505081359360208301359350604090920135919050565b600080602083850312156136cd57600080fd5b82356001600160401b03808211156136e457600080fd5b818501915085601f8301126136f857600080fd5b81358181111561370757600080fd5b86602082850101111561371957600080fd5b60209290920196919550909350505050565b6001600160a01b0381168114611c1257600080fd5b60008060006060848603121561375557600080fd5b83356137608161372b565b925060208401356137708161372b565b929592945050506040919091013590565b60006020828403121561379357600080fd5b5035919050565b600080604083850312156137ad57600080fd5b8235915060208301356137bf8161372b565b809150509250929050565b600080604083850312156137dd57600080fd5b50508035926020909101359150565b6000806000806080858703121561380257600080fd5b843561380d8161372b565b9350602085013561381d8161372b565b93969395505050506040820135916060013590565b60006020828403121561384457600080fd5b8135610c368161372b565b6000806040838503121561386257600080fd5b82356001600160401b0381111561387857600080fd5b83016101e0818603121561388b57600080fd5b946020939093013593505050565b6000808335601e198436030181126138b057600080fd5b83016020810192503590506001600160401b038111156138cf57600080fd5b8060051b36038313156138e157600080fd5b9250929050565b81835260006001600160fb1b0383111561390157600080fd5b8260051b8083602087013760009401602001938452509192915050565b8015158114611c1257600080fd5b80356139378161391e565b919050565b602081528135602082015260208201356040820152604082013560608201526060820135608082015260006139746080840184613899565b6101e08060a086015261398c610200860183856138e8565b925061399b60a0870187613899565b9250601f19808786030160c08801526139b58585846138e8565b945060c088013560e0880152610100935060e088013584880152610120915083880135828801526139e882890189613899565b94509150610140818887030181890152613a038686856138e8565b955061016094508089013585890152505050613a2082870161392c565b9150610180613a328187018415159052565b8601356101a0868101919091528601356101c0808701919091529095013594909301939093525090919050565b8183823760009101908152919050565b600060208284031215613a8157600080fd5b8151610c368161372b565b634e487b7160e01b600052601160045260246000fd5b60008219821115613ab557613ab5613a8c565b500190565b60008060408385031215613acd57600080fd5b505080516020909101519092909150565b600080600060608486031215613af357600080fd5b8351925060208401519150604084015190509250925092565b80516001600160401b038116811461393757600080fd5b60008060008060808587031215613b3957600080fd5b613b4285613b0c565b9350613b5060208601613b0c565b9250613b5e60408601613b0c565b9150613b6c60608601613b0c565b905092959194509250565b600060208284031215613b8957600080fd5b5051919050565b6000816000190483118215151615613baa57613baa613a8c565b500290565b60005b83811015613bca578181015183820152602001613bb2565b838111156108395750506000910152565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b815260008351613c0d816017850160208801613baf565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351613c3e816028840160208801613baf565b01602801949350505050565b6020815260008251806020840152613c69816040850160208701613baf565b601f01601f19169190910160400192915050565b600082821015613c8f57613c8f613a8c565b500390565b6000808335601e19843603018112613cab57600080fd5b8301803591506001600160401b03821115613cc557600080fd5b6020019150600581901b36038213156138e157600080fd5b600060208284031215613cef57600080fd5b8135610c368161391e565b60006101208c83528b60208401528a60408401528960608401528860808401528760a08401528660c08401528060e0840152613d3981840186886138e8565b915050826101008301529b9a5050505050505050505050565b634e487b7160e01b600052600160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600081613da357613da3613a8c565b506000190190565b600060208284031215613dbd57600080fd5b8151610c368161391e565b604081526000613ddc6040830186886138e8565b8281036020840152613def8185876138e8565b979650505050505050565b600082613e1757634e487b7160e01b600052601260045260246000fd5b500490565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b858152606060208201526000613e5f606083018688613e1c565b8281036040840152613e72818587613e1c565b98975050505050505050565b634e487b7160e01b600052603160045260246000fdfeb0e01b719c2c32a677822ce1584cb6a66e576ee3c2c506b9621dbe626355aa658f8c450dae5029cd48cd91dd9db65da48fb742893edfc7941250f6721d93cbbe9a627a5d4aa7c17f87ff26e3fe9a42c2b6c559e8b41a42282d0ecebb17c0e4d3c9bdcd6eb2e956ecf03d8d27bee4c163f9b5c078aa69020d618e76513b5d0a942767d6892477f8d2750fb44e817c9aed93d34d3c6be4101ed58bcac692c99e9ca2646970667358221220d52b9e9caa2c13b657cc805ae83ee728554e066ca239fd40c547751ff4e4252e64736f6c63430008090033