You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.9 KiB
125 lines
3.9 KiB
4 years ago
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||
|
pragma solidity >=0.6.11;
|
||
|
|
||
3 years ago
|
// ============ Internal Imports ============
|
||
3 years ago
|
import {IValidatorManager} from "../interfaces/IValidatorManager.sol";
|
||
3 years ago
|
// ============ External Imports ============
|
||
3 years ago
|
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
||
|
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
||
4 years ago
|
|
||
4 years ago
|
/**
|
||
|
* @title Common
|
||
|
* @author Celo Labs Inc.
|
||
3 years ago
|
* @notice Shared utilities between Outbox and Inbox.
|
||
3 years ago
|
*/
|
||
3 years ago
|
abstract contract Common is OwnableUpgradeable {
|
||
3 years ago
|
// ============ Immutable Variables ============
|
||
|
|
||
|
// Domain of chain on which the contract is deployed
|
||
4 years ago
|
uint32 public immutable localDomain;
|
||
3 years ago
|
|
||
|
// ============ Public Variables ============
|
||
|
|
||
3 years ago
|
// Checkpoints of root => leaf index
|
||
|
mapping(bytes32 => uint256) public checkpoints;
|
||
|
// The latest checkpointed root
|
||
|
bytes32 public checkpointedRoot;
|
||
|
// Address of ValidatorManager contract.
|
||
|
IValidatorManager public validatorManager;
|
||
3 years ago
|
|
||
|
// ============ Upgrade Gap ============
|
||
|
|
||
3 years ago
|
// gap for upgrade safety
|
||
|
uint256[47] private __GAP;
|
||
4 years ago
|
|
||
3 years ago
|
// ============ Events ============
|
||
|
|
||
4 years ago
|
/**
|
||
3 years ago
|
* @notice Emitted when a root is checkpointed on Outbox or a signed
|
||
|
* checkpoint is relayed to a Inbox.
|
||
3 years ago
|
* @param root Merkle root
|
||
|
* @param index Leaf index
|
||
3 years ago
|
*/
|
||
3 years ago
|
event Checkpoint(bytes32 indexed root, uint256 indexed index);
|
||
4 years ago
|
|
||
3 years ago
|
/**
|
||
3 years ago
|
* @notice Emitted when the ValidatorManager contract is changed
|
||
|
* @param validatorManager The address of the new validatorManager
|
||
3 years ago
|
*/
|
||
3 years ago
|
event NewValidatorManager(address validatorManager);
|
||
3 years ago
|
|
||
3 years ago
|
// ============ Modifiers ============
|
||
|
|
||
|
// ============ Constructor ============
|
||
|
|
||
4 years ago
|
constructor(uint32 _localDomain) {
|
||
|
localDomain = _localDomain;
|
||
|
}
|
||
4 years ago
|
|
||
3 years ago
|
// ============ Initializer ============
|
||
|
|
||
3 years ago
|
function __Common_initialize(address _validatorManager)
|
||
|
internal
|
||
|
initializer
|
||
|
{
|
||
|
// initialize owner
|
||
|
__Ownable_init();
|
||
|
_setValidatorManager(IValidatorManager(_validatorManager));
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
// ============ External Functions ============
|
||
4 years ago
|
|
||
4 years ago
|
/**
|
||
3 years ago
|
* @notice Set a new ValidatorManager contract
|
||
3 years ago
|
* @dev Outbox(es) will initially be initialized using a trusted ValidatorManager contract;
|
||
3 years ago
|
* we will progressively decentralize by swapping the trusted contract with a new implementation
|
||
|
* that implements Validator bonding & slashing, and rules for Validator selection & rotation
|
||
|
* @param _validatorManager the new ValidatorManager contract
|
||
3 years ago
|
*/
|
||
3 years ago
|
function setValidatorManager(address _validatorManager) external onlyOwner {
|
||
|
_setValidatorManager(IValidatorManager(_validatorManager));
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
3 years ago
|
/**
|
||
3 years ago
|
* @notice Returns the latest checkpoint for the Validators to sign.
|
||
|
* @return root Latest checkpointed root
|
||
|
* @return index Latest checkpointed index
|
||
3 years ago
|
*/
|
||
3 years ago
|
function latestCheckpoint()
|
||
|
external
|
||
|
view
|
||
|
returns (bytes32 root, uint256 index)
|
||
|
{
|
||
|
root = checkpointedRoot;
|
||
|
index = checkpoints[root];
|
||
|
}
|
||
4 years ago
|
|
||
3 years ago
|
// ============ Internal Functions ============
|
||
|
|
||
|
/**
|
||
3 years ago
|
* @notice Set the ValidatorManager
|
||
|
* @param _validatorManager Address of the ValidatorManager
|
||
3 years ago
|
*/
|
||
3 years ago
|
function _setValidatorManager(IValidatorManager _validatorManager)
|
||
4 years ago
|
internal
|
||
|
{
|
||
3 years ago
|
require(
|
||
|
Address.isContract(address(_validatorManager)),
|
||
|
"!contract validatorManager"
|
||
3 years ago
|
);
|
||
3 years ago
|
validatorManager = _validatorManager;
|
||
|
emit NewValidatorManager(address(_validatorManager));
|
||
4 years ago
|
}
|
||
3 years ago
|
|
||
|
/**
|
||
3 years ago
|
* @notice Store the provided checkpoint.
|
||
|
* @param _root The merkle root
|
||
|
* @param _index The next available leaf index of the merkle tree.
|
||
3 years ago
|
*/
|
||
3 years ago
|
function _checkpoint(bytes32 _root, uint256 _index) internal {
|
||
|
checkpoints[_root] = _index;
|
||
|
checkpointedRoot = _root;
|
||
|
emit Checkpoint(_root, _index);
|
||
3 years ago
|
}
|
||
4 years ago
|
}
|