Verified contractPartialGPL-3.0-only
RocketDAOProtocolVerifier
Address0xc4d85aa3e318c38005f6d73cc53e5a2b4223723a
- Balance
0 ETH
- Transactions
13
- Compiler
solc 0.8.30
- Same code
Only this contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 15,000 runs
- EVM version
- paris
- Via IR
- yes
- License
- GPL-3.0-only
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,843,914
- Creation transaction
- 0x437da127dd…a6735ab17a
16 files
- contracts/contract/dao/protocol/RocketDAOProtocolVerifier.solmain41.68 KB
- @openzeppelin4/contracts/utils/math/Math.sol12.79 KB
- contracts/contract/RocketBase.sol9.06 KB
- contracts/interface/RocketStorageInterface.sol3.34 KB
- contracts/interface/dao/RocketDAOProposalInterface.sol3.26 KB
- contracts/interface/dao/protocol/RocketDAOProtocolProposalInterface.sol4.39 KB
- contracts/interface/dao/protocol/RocketDAOProtocolProposalsInterface.sol2.97 KB
- contracts/interface/dao/protocol/RocketDAOProtocolVerifierInterface.sol2.79 KB
- contracts/interface/dao/protocol/settings/RocketDAOProtocolSettingsProposalsInterface.sol1.9 KB
- contracts/interface/network/RocketNetworkVotingInterface.sol1.64 KB
- contracts/interface/node/RocketNodeManagerInterface.sol4.43 KB
- contracts/interface/node/RocketNodeStakingInterface.sol4.05 KB
- contracts/interface/token/RocketTokenRPLInterface.sol1.89 KB
- contracts/interface/util/IERC20.sol3.86 KB
- contracts/types/NodeDetails.sol2.04 KB
- contracts/types/SettingType.sol1.28 KB
contracts/contract/dao/protocol/RocketDAOProtocolVerifier.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.30;
import "../../RocketBase.sol";
import "../../../interface/dao/protocol/RocketDAOProtocolVerifierInterface.sol";
import "../../../interface/network/RocketNetworkVotingInterface.sol";
import "../../../interface/node/RocketNodeManagerInterface.sol";
import "@openzeppelin4/contracts/utils/math/Math.sol";
import "../../../interface/token/RocketTokenRPLInterface.sol";
import "../../../interface/dao/protocol/RocketDAOProtocolProposalsInterface.sol";
import "../../../interface/dao/RocketDAOProposalInterface.sol";
import "../../../interface/node/RocketNodeStakingInterface.sol";
import "../../../interface/dao/protocol/settings/RocketDAOProtocolSettingsProposalsInterface.sol";
import "../../../interface/dao/protocol/RocketDAOProtocolProposalInterface.sol";
/// @notice Implements the protocol DAO optimistic fraud proof proposal system
contract RocketDAOProtocolVerifier is RocketBase, RocketDAOProtocolVerifierInterface {
uint256 constant internal depthPerRound = 5;
// Packing constants for packing challenge data into a single uint256
uint256 constant internal stateOffset = (256 - 8);
uint256 constant internal timestampOffset = (256 - 8 - 64);
uint256 constant internal addressOffset = (256 - 8 - 64 - 160);
// Offsets into storage for proposal details
uint256 constant internal proposerOffset = 0;
uint256 constant internal blockNumberOffset = 1;
uint256 constant internal nodeCountOffset = 2;
uint256 constant internal defeatIndexOffset = 3;
uint256 constant internal proposalBondOffset = 4;
uint256 constant internal challengeBondOffset = 5;
uint256 constant internal challengePeriodOffset = 6;
// Offsets into storage for challenge details
uint256 constant internal challengeStateOffset = 0;
uint256 constant internal sumOffset = 1;
uint256 constant internal hashOffset = 2;
// Burn rate
uint256 constant internal bondBurnPercent = 0.2 ether;
// Events
event RootSubmitted(uint256 indexed proposalID, address indexed proposer, uint32 blockNumber, uint256 index, Types.Node root, Types.Node[] treeNodes, uint256 timestamp);
event ChallengeSubmitted(uint256 indexed proposalID, address indexed challenger, uint256 index, uint256 timestamp);
event ProposalBondBurned(uint256 indexed proposalID, address indexed proposer, uint256 amount, uint256 timestamp);
// Construct
constructor(RocketStorageInterface _rocketStorageAddress) RocketBase(_rocketStorageAddress) {
// Version
version = 3;
}
/// @notice Returns the depth per round
function getDepthPerRound() override external pure returns (uint256) {
return depthPerRound;
}
/// @notice Returns the defeat index for this proposal
/// @param _proposalID The proposal to fetch details
function getDefeatIndex(uint256 _proposalID) override external view returns (uint256) {
// Fetch the proposal key
uint256 proposalKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)));
return getUint(bytes32(proposalKey + defeatIndexOffset));
}
/// @notice Returns the proposal bond for this proposal
/// @param _proposalID The proposal to fetch details
function getProposalBond(uint256 _proposalID) override external view returns (uint256) {
// Fetch the proposal key
uint256 proposalKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)));
return getUint(bytes32(proposalKey + proposalBondOffset));
}
/// @notice Returns the challenge bond for this proposal
/// @param _proposalID The proposal to fetch details
function getChallengeBond(uint256 _proposalID) override external view returns (uint256) {
// Fetch the proposal key
uint256 proposalKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)));
return getUint(bytes32(proposalKey + challengeBondOffset));
}
/// @notice Returns the duration of the challenge period for this proposal
/// @param _proposalID The proposal to fetch details
function getChallengePeriod(uint256 _proposalID) override external view returns (uint256) {
// Fetch the proposal key
uint256 proposalKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)));
return getUint(bytes32(proposalKey + challengePeriodOffset));
}
/// @dev Called during a proposal submission to calculate and store the proposal root so it is available for challenging
/// @param _proposalID The ID of the proposal
/// @param _proposer The node raising the proposal
/// @param _blockNumber The block number used to generate the voting power tree
/// @param _treeNodes A pollard of the voting power tree
function submitProposalRoot(uint256 _proposalID, address _proposer, uint32 _blockNumber, Types.Node[] calldata _treeNodes) external onlyLatestContract("rocketDAOProtocolProposal", msg.sender) onlyLatestContract("rocketDAOProtocolVerifier", address(this)) {
// Retrieve the node count at _blockNumber
uint256 nodeCount;
{
RocketNetworkVotingInterface rocketNetworkVoting = RocketNetworkVotingInterface(getContractAddress("rocketNetworkVoting"));
nodeCount = rocketNetworkVoting.getNodeCount(_blockNumber);
}
// Verify proposer supplied correct number of nodes for the pollard
{
uint256 maxDepth = getMaxDepth(nodeCount);
if (maxDepth < depthPerRound) {
uint256 leafCount = 2 ** maxDepth;
require(_treeNodes.length == leafCount, "Invalid node count");
} else {
require(_treeNodes.length == 2 ** depthPerRound, "Invalid node count");
}
}
// Compute the proposal root from the supplied nodes
Types.Node memory root = computeRootFromNodes(_treeNodes);
{
RocketDAOProtocolSettingsProposalsInterface rocketDAOProtocolSettingsProposals = RocketDAOProtocolSettingsProposalsInterface(getContractAddress("rocketDAOProtocolSettingsProposals"));
// Get the current proposal bond amount
uint256 proposalBond = rocketDAOProtocolSettingsProposals.getProposalBond();
// Lock the proposal bond (will revert if proposer doesn't have enough effective RPL staked)
RocketNodeStakingInterface rocketNodeStaking = RocketNodeStakingInterface(getContractAddress("rocketNodeStaking"));
rocketNodeStaking.lockRPL(_proposer, proposalBond);
// Store proposal details
uint256 proposalKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)));
setAddress(bytes32(proposalKey + proposerOffset), _proposer);
setUint(bytes32(proposalKey + blockNumberOffset), _blockNumber);
setUint(bytes32(proposalKey + nodeCountOffset), nodeCount);
setUint(bytes32(proposalKey + proposalBondOffset), proposalBond);
setUint(bytes32(proposalKey + challengeBondOffset), rocketDAOProtocolSettingsProposals.getChallengeBond());
setUint(bytes32(proposalKey + challengePeriodOffset), rocketDAOProtocolSettingsProposals.getChallengePeriod());
}
// The root was supplied so mark that index (1) as responded and store the node
setNode(_proposalID, 1, root);
uint256 state = uint256(Types.ChallengeState.Responded) << stateOffset;
state |= block.timestamp << timestampOffset;
setUint(keccak256(abi.encodePacked("dao.protocol.proposal.challenge", _proposalID, uint256(1))), state);
// Emit event
emit RootSubmitted(_proposalID, _proposer, _blockNumber, 1, root, _treeNodes, block.timestamp);
}
/// @dev Called by proposal contract to burn the bond of the proposer after a successful veto
/// @param _proposalID the proposal ID that will have the bond burnt
function burnProposalBond(uint256 _proposalID) override external onlyLatestContract("rocketDAOProtocolProposal", address(msg.sender)) onlyLatestContract("rocketDAOProtocolVerifier", address(this)) {
// Retrieved required inputs from storage
uint256 proposalKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)));
address proposer = getAddress(bytes32(proposalKey + proposerOffset));
uint256 proposalBond = getUint(bytes32(proposalKey + proposalBondOffset));
// Unlock and burn
RocketNodeStakingInterface rocketNodeStaking = RocketNodeStakingInterface(getContractAddress("rocketNodeStaking"));
rocketNodeStaking.unlockRPL(proposer, proposalBond);
rocketNodeStaking.burnRPL(proposer, proposalBond);
// Log it
emit ProposalBondBurned(_proposalID, proposer, proposalBond, block.timestamp);
}
/// @notice Used by a verifier to challenge a specific index of a proposal's voting power tree
/// @param _proposalID The ID of the proposal being challenged
/// @param _index The global index of the node being challenged
/// @param _node The node that is being challenged as submitted by the proposer
/// @param _witness A merkle proof of the challenged node (using the previously challenged index as a root)
function createChallenge(uint256 _proposalID, uint256 _index, Types.Node calldata _node, Types.Node[] calldata _witness) external onlyLatestContract("rocketDAOProtocolVerifier", address(this)) onlyRegisteredNode(msg.sender) {
{ // Scope to prevent stack too deep
// Check whether the proposal is on the Pending state
RocketDAOProtocolProposalInterface daoProposal = RocketDAOProtocolProposalInterface(getContractAddress("rocketDAOProtocolProposal"));
RocketDAOProtocolProposalInterface.ProposalState proposalState = daoProposal.getState(_proposalID);
require(proposalState == RocketDAOProtocolProposalInterface.ProposalState.Pending, "Can only challenge while proposal is Pending");
}
// Precompute the proposal key
uint256 proposalKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)));
// Retrieve the node count of this proposal
uint256 nodeCount = getUint(bytes32(proposalKey + nodeCountOffset));
uint256 maxDepth = getMaxDepth(nodeCount);
{
// Check depth doesn't exceed the extended tree
uint256 depth = getDepthFromIndex(_index);
require(depth < maxDepth * 2, "Invalid index depth");
}
// Check for existing challenge against this index
{
bytes32 challengeKey = keccak256(abi.encodePacked("dao.protocol.proposal.challenge", _proposalID, _index));
uint256 challengeData = getUint(challengeKey);
require(challengeData == 0, "Index already challenged");
// Write challenge
challengeData = uint256(Types.ChallengeState.Challenged) << stateOffset;
challengeData |= block.timestamp << timestampOffset;
challengeData |= uint256(uint160(msg.sender)) << addressOffset;
setUint(challengeKey, challengeData);
}
// Check the proposal hasn't already been defeated
require(getUint(bytes32(proposalKey+defeatIndexOffset)) == 0, "Proposal already defeated");
// Verify the validity of the challenge proof
{
// Check depth is exactly one round deeper than a previous challenge (or the proposal root)
uint256 previousIndex = getPollardRootIndex(_index, nodeCount);
require(_getChallengeState(getUint(keccak256(abi.encodePacked("dao.protocol.proposal.challenge", _proposalID, previousIndex)))) == Types.ChallengeState.Responded, "Invalid challenge depth");
// Check the proof contains the expected number of nodes
require(_witness.length == getDepthFromIndex(_index) - getDepthFromIndex(previousIndex), "Invalid proof length");
// Get expected node and compute provided root node then compare
Types.Node memory _expected = getNode(_proposalID, previousIndex);
Types.Node memory rootFromWitness = computeRootFromWitness(_index, _node, _witness);
require(rootFromWitness.hash == _expected.hash, "Invalid hash");
require(rootFromWitness.sum == _expected.sum, "Invalid sum");
// Store the node
setNode(_proposalID, _index, _node);
}
// Lock the challenger's bond (reverts if not enough effective RPL)
{
uint256 challengeBond = getUint(bytes32(proposalKey + challengeBondOffset));
RocketNodeStakingInterface rocketNodeStaking = RocketNodeStakingInterface(getContractAddress("rocketNodeStaking"));
rocketNodeStaking.lockRPL(msg.sender, challengeBond);
}
// Emit event
emit ChallengeSubmitted(_proposalID, msg.sender, _index, block.timestamp);
}
/// @notice Can be called if proposer fails to respond to a challenge within the required time limit. Destroys the proposal if successful
/// @param _proposalID The ID of the challenged proposal
/// @param _index The index which was failed to respond to
function defeatProposal(uint256 _proposalID, uint256 _index) external onlyLatestContract("rocketDAOProtocolVerifier", address(this)) onlyRegisteredNode(msg.sender) {
{ // Scope to prevent stack too deep
// Check whether the proposal is in the Pending state
RocketDAOProtocolProposalInterface daoProposal = RocketDAOProtocolProposalInterface(getContractAddress("rocketDAOProtocolProposal"));
RocketDAOProtocolProposalInterface.ProposalState proposalState = daoProposal.getState(_proposalID);
require(proposalState == RocketDAOProtocolProposalInterface.ProposalState.Pending, "Can not defeat a valid proposal");
}
// Check the challenge at the given index has not been responded to
bytes32 challengeKey = keccak256(abi.encodePacked("dao.protocol.proposal.challenge", _proposalID, _index));
uint256 data = getUint(challengeKey);
Types.ChallengeState state = _getChallengeState(data);
require(state == Types.ChallengeState.Challenged, "Invalid challenge state");
uint256 proposalKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)));
// Precompute defeat index key
bytes32 defeatIndexKey = bytes32(proposalKey+defeatIndexOffset);
uint256 challengePeriod = getUint(bytes32(proposalKey + challengePeriodOffset));
// Check the proposal hasn't already been defeated
uint256 defeatIndex = getUint(defeatIndexKey);
require(defeatIndex == 0, "Proposal already defeated");
// Check enough time has passed
uint256 timestamp = getChallengeTimestamp(data);
require(block.timestamp > timestamp + challengePeriod, "Not enough time has passed");
// Destroy the proposal
RocketDAOProtocolProposalInterface rocketDAOProtocolProposal = RocketDAOProtocolProposalInterface(getContractAddress("rocketDAOProtocolProposal"));
rocketDAOProtocolProposal.destroy(_proposalID);
// Record the winning index for reward payments
setUint(defeatIndexKey, _index);
}
/// @notice Called by a challenger to claim bonds (both refunded bonds and any rewards paid minus the 20% bond burn)
/// @param _proposalID The ID of the proposal
/// @param _indices An array of indices which the challenger has a claim against
function claimBondChallenger(uint256 _proposalID, uint256[] calldata _indices) external onlyLatestContract("rocketDAOProtocolVerifier", address(this)) onlyRegisteredNode(msg.sender) {
{ // Scope to prevent stack too deep
// Check whether the proposal is NOT on the Pending state
RocketDAOProtocolProposalInterface daoProposal = RocketDAOProtocolProposalInterface(getContractAddress("rocketDAOProtocolProposal"));
RocketDAOProtocolProposalInterface.ProposalState proposalState = daoProposal.getState(_proposalID);
require(proposalState != RocketDAOProtocolProposalInterface.ProposalState.Pending, "Can not claim bond while proposal is Pending");
}
// Check whether the proposal was defeated
uint256 defeatIndex = getUint(bytes32(uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)))+defeatIndexOffset));
bool defeated = defeatIndex != 0;
// Keep track of the number of indices the claimer had which were involved in defeating the proposal
uint256 rewardedIndices = 0;
for (uint256 i = 0; i < _indices.length; ++i) {
bytes32 challengeKey = keccak256(abi.encodePacked("dao.protocol.proposal.challenge", _proposalID, _indices[i]));
uint256 challengeData = getUint(challengeKey);
Types.ChallengeState challengeState = _getChallengeState(challengeData);
if (defeated) {
// Refund all challenges if the proposal was defeated
require(challengeState == Types.ChallengeState.Responded || challengeState == Types.ChallengeState.Challenged, "Invalid challenge state");
} else {
// Only refund non-responded challenges if the proposal wasn't defeated
require(challengeState == Types.ChallengeState.Challenged, "Invalid challenge state");
}
// Check the challenger is the caller
address challenger = address(uint160(challengeData >> addressOffset));
require(msg.sender == challenger, "Invalid challenger");
// Increment reward indices if required
if (isRewardedIndex(defeatIndex, _indices[i])) {
rewardedIndices++;
}
// Mark index as paid
challengeData = setChallengeState(challengeData, Types.ChallengeState.Paid);
setUint(challengeKey, challengeData);
}
// Get staking contract
RocketNodeStakingInterface rocketNodeStaking = RocketNodeStakingInterface(getContractAddress("rocketNodeStaking"));
// Unlock challenger bond
uint256 proposalKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)));
uint256 challengeBond = getUint(bytes32(proposalKey + challengeBondOffset));
uint256 totalBond = _indices.length * challengeBond;
rocketNodeStaking.unlockRPL(msg.sender, totalBond);
// Pay challenger their reward
if (rewardedIndices > 0) {
uint256 proposalBond = getUint(bytes32(proposalKey + proposalBondOffset));
// Calculate the number of challenges involved in defeating the proposal
uint256 nodeCount = getUint(bytes32(proposalKey + nodeCountOffset));
uint256 totalDefeatingIndices = getRoundsFromIndex(defeatIndex, nodeCount);
uint256 totalReward = proposalBond * rewardedIndices / totalDefeatingIndices;
uint256 burnAmount = totalReward * bondBurnPercent / calcBase;
// Unlock the reward amount from the proposer and transfer it to the challenger
address proposer = getAddress(bytes32(proposalKey + proposerOffset));
rocketNodeStaking.unlockRPL(proposer, totalReward);
rocketNodeStaking.burnRPL(proposer, burnAmount);
rocketNodeStaking.transferRPL(proposer, msg.sender, totalReward - burnAmount);
}
}
/// @notice Called by a proposer to claim bonds (both refunded bond and any rewards paid minus the 20% bond burn)
/// @param _proposalID The ID of the proposal
/// @param _indices An array of indices which the proposer has a claim against
function claimBondProposer(uint256 _proposalID, uint256[] calldata _indices) external onlyLatestContract("rocketDAOProtocolVerifier", address(this)) onlyRegisteredNode(msg.sender) {
uint256 defeatIndex = getUint(bytes32(uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)))+defeatIndexOffset));
// Proposer has nothing to claim if their proposal was defeated
require(defeatIndex == 0, "Proposal defeated");
// Check the proposal has passed the waiting period and the voting period and wasn't cancelled
{
RocketDAOProtocolProposalInterface daoProposal = RocketDAOProtocolProposalInterface(getContractAddress("rocketDAOProtocolProposal"));
RocketDAOProtocolProposalInterface.ProposalState proposalState = daoProposal.getState(_proposalID);
require(proposalState >= RocketDAOProtocolProposalInterface.ProposalState.QuorumNotMet, "Invalid proposal state");
}
address proposer;
uint256 challengeBond;
uint256 proposalBond;
{
uint256 proposalKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)));
proposer = getAddress(bytes32(proposalKey + proposerOffset));
// Only the proposer can call
require(msg.sender == proposer, "Not proposer");
// Query proposal bond params
challengeBond = getUint(bytes32(proposalKey + challengeBondOffset));
proposalBond = getUint(bytes32(proposalKey + proposalBondOffset));
}
// Get staking contract
RocketNodeStakingInterface rocketNodeStaking = RocketNodeStakingInterface(getContractAddress("rocketNodeStaking"));
uint256 burnPerChallenge = challengeBond * bondBurnPercent / calcBase;
for (uint256 i = 0; i < _indices.length; ++i) {
// Check the challenge of the given index was responded to
bytes32 challengeKey = keccak256(abi.encodePacked("dao.protocol.proposal.challenge", _proposalID, _indices[i]));
uint256 state = getUint(challengeKey);
// Proposer can only claim the reward on indices they responded to
require(_getChallengeState(state) == Types.ChallengeState.Responded, "Invalid challenge state");
// Mark index as paid
state = setChallengeState(state, Types.ChallengeState.Paid);
setUint(challengeKey, state);
// If claiming the root at this stage, then we return the proposal bond
if (_indices[i] == 1) {
rocketNodeStaking.unlockRPL(proposer, proposalBond);
} else {
// Unlock the challenger bond and pay to proposer
address challenger = getChallengeAddress(state);
rocketNodeStaking.unlockRPL(challenger, challengeBond);
rocketNodeStaking.transferRPL(challenger, proposer, challengeBond - burnPerChallenge);
rocketNodeStaking.burnRPL(challenger, burnPerChallenge);
}
}
}
/// @notice Used by a proposer to defend a challenged index
/// @param _proposalID The ID of the proposal
/// @param _index The global index of the node for which the proposer is submitting a new pollard
/// @param _nodes A list of nodes making up the new pollard
function submitRoot(uint256 _proposalID, uint256 _index, Types.Node[] calldata _nodes) external onlyLatestContract("rocketDAOProtocolVerifier", address(this)) onlyRegisteredNode(msg.sender) {
uint256 proposalKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)));
{ // Scope to prevent stack too deep
// Check whether the proposal is in the Pending state
RocketDAOProtocolProposalInterface daoProposal = RocketDAOProtocolProposalInterface(getContractAddress("rocketDAOProtocolProposal"));
RocketDAOProtocolProposalInterface.ProposalState proposalState = daoProposal.getState(_proposalID);
require(proposalState == RocketDAOProtocolProposalInterface.ProposalState.Pending, "Can not submit root for a valid proposal");
address proposer = getAddress(bytes32(proposalKey + proposerOffset));
require(msg.sender == proposer, "Not proposer");
}
{ // Scope to prevent stack too deep
// Get challenge state
bytes32 challengeKey = keccak256(abi.encodePacked("dao.protocol.proposal.challenge", _proposalID, _index));
uint256 state = getUint(challengeKey);
// Make sure this index was actually challenged
require(_getChallengeState(state) == Types.ChallengeState.Challenged, "Challenge does not exist");
// Mark the index as responded
state = setChallengeState(state, Types.ChallengeState.Responded);
setUint(challengeKey, state);
}
// Check the proposal hasn't already been defeated
require(getUint(bytes32(proposalKey + defeatIndexOffset)) == 0, "Proposal already defeated");
// Verify correct number of nodes in the pollard
uint256 nodeCount = getUint(bytes32(proposalKey + nodeCountOffset));
uint256 indexDepth = Math.log2(_index, Math.Rounding.Down);
require(_nodes.length == 2 ** (getNextDepth(_index, nodeCount) - indexDepth), "Invalid node count");
Types.Node memory expected = getNode(_proposalID, _index);
Types.Node memory actual = computeRootFromNodes(_nodes);
// Check that the supplied nodes sum to the expected value
require(expected.sum == actual.sum, "Invalid sum");
// Determine if this index is a leaf node of the primary tree or sub tree
{
uint256 treeDepth = Math.log2(nodeCount, Math.Rounding.Up);
// Verify sub-tree leaves with known values
if (indexDepth + depthPerRound >= treeDepth * 2) {
// Calculate the offset into the leaf nodes in the final tree that match the supplied nodes
uint256 offset = (_index * (2 ** (getNextDepth(_index, nodeCount) - indexDepth))) - (2 ** (treeDepth * 2));
// Verify the leaves match the values we know on chain
require(verifyLeaves(getUint(bytes32(proposalKey + blockNumberOffset)), nodeCount, offset, _nodes), "Invalid leaves");
}
if (indexDepth == treeDepth) {
// The leaf node of the primary tree is just a hash of the sum
bytes32 actualHash = keccak256(abi.encodePacked(actual.sum));
require(expected.hash == actualHash, "Invalid hash");
// Update the node to include the root hash of the sub tree
setNode(_proposalID, _index, actual);
} else {
require(expected.hash == actual.hash, "Invalid hash");
}
}
// Emit event
emit RootSubmitted(_proposalID, getAddress(bytes32(proposalKey + proposerOffset)), uint32(getUint(bytes32(proposalKey + blockNumberOffset))), _index, actual, _nodes, block.timestamp);
}
/// @dev Checks a slice of the final nodes in a tree with the correct known on-chain values
/// @param _blockNumber The block number used to generate the voting power tree
/// @param _nodeCount The number of nodes that existed at the proposal block
/// @param _offset The pollard's offset into the leaves
/// @param _leaves The pollard's leaves
/// @return True if the leaves match what is known on chain
function verifyLeaves(uint256 _blockNumber, uint256 _nodeCount, uint256 _offset, Types.Node[] calldata _leaves) internal view returns (bool) {
// Get contracts
RocketNetworkVotingInterface rocketNetworkVoting = RocketNetworkVotingInterface(getContractAddress("rocketNetworkVoting"));
RocketNodeManagerInterface rocketNodeManager = RocketNodeManagerInterface(getContractAddress("rocketNodeManager"));
// Calculate the closest power of 2 of the node count
uint256 nodeCount = 2 ** Math.log2(_nodeCount, Math.Rounding.Up);
uint32 blockNumber32 = uint32(_blockNumber);
// Iterate over the leaves
for (uint256 i = 0; i < _leaves.length; ++i) {
// The leaf nodes are a 2d array of voting power in the form of [delegateIndex][nodeIndex] where both
// arrays are padded out to the closest power of 2 with zeros
uint256 nodeIndex = (_offset + i) % nodeCount;
uint256 delegateIndex = (_offset + i) / nodeCount;
// Determine the correct voting power for this leaf (fill with zero if > node count)
uint256 actual = 0;
if (nodeIndex < _nodeCount && delegateIndex < _nodeCount) {
// Calculate the node and the delegate referred to by this leaf node
address nodeAddress = rocketNodeManager.getNodeAt(nodeIndex);
address actualDelegate = rocketNetworkVoting.getDelegate(nodeAddress, blockNumber32);
// If a delegation exists, retrieve the node's voting power
if (actualDelegate == rocketNodeManager.getNodeAt(delegateIndex)) {
actual = rocketNetworkVoting.getVotingPower(nodeAddress, blockNumber32);
}
}
// Check provided leaves against actual sum
if (_leaves[i].sum != actual) {
return false;
}
// Check provided leaves against hash
if (_leaves[i].hash != keccak256(abi.encodePacked(actual))) {
return false;
}
}
return true;
}
/// @notice Check if a vote is valid using a provided proof
/// @param _voter address of the node operator casting the vote
/// @param _nodeIndex index of the voting node
/// @param _proposalID ID of the proposal being voted
/// @param _votingPower VP being used with this vote
/// @param _witness A merkle proof that will be verified
function verifyVote(address _voter, uint256 _nodeIndex, uint256 _proposalID, uint256 _votingPower, Types.Node[] calldata _witness) external view returns (bool) {
// Get contracts
RocketNodeManagerInterface rocketNodeManager = RocketNodeManagerInterface(getContractAddress("rocketNodeManager"));
// Verify voter
if(rocketNodeManager.getNodeAt(_nodeIndex) != _voter) {
return false;
}
// Load the proposal
uint256 proposalKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal", _proposalID)));
// Calculate the network tree index for this voter
uint256 nodeCount = getUint(bytes32(proposalKey + nodeCountOffset));
uint256 depth = getMaxDepth(nodeCount);
uint256 treeIndex = (2 ** depth) + _nodeIndex;
// Validate input
require(_nodeIndex < nodeCount, "Node was not present at snapshot");
require(_witness.length == depth, "Invalid witness length");
// Reconstruct leaf node
Types.Node memory leaf;
leaf.sum = _votingPower;
leaf.hash = keccak256(abi.encodePacked(_votingPower));
// Retrieve the expected root node
Types.Node memory expected = getNode(_proposalID, 1);
// Compute a root from the supplied proof
Types.Node memory actual = computeRootFromWitness(treeIndex, leaf, _witness);
// Equality check
return (actual.sum == expected.sum && actual.hash == expected.hash);
}
/// @dev Computes the root node given a witness
/// @param _index The global index the proof is for
/// @param _leaf The node at the global index `_index`
/// @param _witness A merkle proof starting at the global index `_index`
/// @return The computed root node for the given witness
function computeRootFromWitness(uint256 _index, Types.Node memory _leaf, Types.Node[] calldata _witness) internal pure returns (Types.Node memory) {
Types.Node memory root = _leaf;
for (uint256 i = 0; i < _witness.length; ++i) {
if (_index % 2 == 1) {
root.hash = keccak256(abi.encodePacked(
_witness[i].hash, _witness[i].sum,
root.hash, root.sum
));
} else {
root.hash = keccak256(abi.encodePacked(
root.hash, root.sum,
_witness[i].hash, _witness[i].sum
));
}
root.sum += _witness[i].sum;
_index = _index / 2;
}
return root;
}
/// @dev Computes the root node given a pollard
/// @param _nodes An array of nodes to compute a root node for
/// @return The computed root node
function computeRootFromNodes(Types.Node[] calldata _nodes) internal pure returns (Types.Node memory) {
uint256 len = _nodes.length / 2;
// Perform first step into a new temporary memory buffer to leave original intact
Types.Node[] memory temp = new Types.Node[](len);
for (uint256 i = 0; i < len; ++i) {
temp[i].hash = keccak256(abi.encodePacked(
_nodes[i * 2].hash, _nodes[i * 2].sum,
_nodes[i * 2 + 1].hash, _nodes[i * 2 + 1].sum
));
temp[i].sum = _nodes[i * 2].sum + _nodes[i * 2 + 1].sum;
}
// Compute the remainder within the temporary buffer
while (len > 1) {
len /= 2;
for (uint256 i = 0; i < len; ++i) {
temp[i].hash = keccak256(abi.encodePacked(
temp[i * 2].hash, temp[i * 2].sum,
temp[i * 2 + 1].hash, temp[i * 2 + 1].sum
));
temp[i].sum = temp[i * 2].sum + temp[i * 2 + 1].sum;
}
}
return temp[0];
}
/// @dev Calculates the depth of a given index
/// @param _index The global index to calculate a depth for
/// @return The depth of the global index `_index`
function getDepthFromIndex(uint256 _index) internal pure returns (uint256) {
return Math.log2(_index, Math.Rounding.Down);
}
/// @dev Calculates the number of rounds required to get to given index
/// @param _index The global index to calculate number of rounds for
/// @return The number of rounds it takes to get to the global index `_index`
function getRoundsFromIndex(uint256 _index, uint256 _nodeCount) internal pure returns (uint256) {
uint256 subTreeDepth = Math.log2(_nodeCount, Math.Rounding.Up);
uint256 indexDepth = Math.log2(_index, Math.Rounding.Down);
if (indexDepth <= subTreeDepth) {
return (indexDepth - 1) / depthPerRound + 1;
} else {
uint256 phase2Depth = indexDepth - subTreeDepth;
uint256 phase1Rounds = (subTreeDepth - 1) / depthPerRound + 1;
uint256 phase2Rounds = (phase2Depth - 1) / depthPerRound + 1;
return phase1Rounds + phase2Rounds;
}
}
/// @dev Calculates the max depth of a tree containing specified number of nodes
/// @param _nodeCount The number of nodes
/// @return The max depth of a tree with `_nodeCount` many nodes
function getMaxDepth(uint256 _nodeCount) internal pure returns (uint256) {
return Math.log2(_nodeCount, Math.Rounding.Up);
}
/// @dev Calculates the depth of the next round taking into account the max depth
/// @param _currentIndex The index to calculate the next depth for
/// @param _nodeCount The number of nodes
/// @return The next depth for a challenge
function getNextDepth(uint256 _currentIndex, uint256 _nodeCount) internal pure returns (uint256) {
uint256 currentDepth = getDepthFromIndex(_currentIndex);
uint256 maxDepth = getMaxDepth(_nodeCount);
uint256 nextDepth = currentDepth + depthPerRound;
if (nextDepth > maxDepth * 2) {
return maxDepth * 2;
} else if (nextDepth > maxDepth) {
if (currentDepth < maxDepth) {
return maxDepth;
}
}
return nextDepth;
}
/// @dev Calculates the root index of a pollard given the index of of one of its nodes
/// @param _index The index to calculate a pollard root index from
/// @return The pollard root index for node with global index of `_index`
function getPollardRootIndex(uint256 _index, uint256 _nodeCount) internal pure returns (uint256) {
require(_index > 1, "Invalid index");
uint256 indexDepth = Math.log2(_index, Math.Rounding.Down);
uint256 maxDepth = Math.log2(_nodeCount, Math.Rounding.Up);
if (indexDepth < maxDepth) {
// Index is leaf of phase 1 tree
uint256 remainder = indexDepth % depthPerRound;
require(remainder == 0, "Invalid index");
return _index / (2 ** depthPerRound);
} else if (indexDepth == maxDepth) {
// Index is a network tree leaf
uint256 remainder = indexDepth % depthPerRound;
return _index / (2 ** (remainder == 0 ? depthPerRound : remainder));
} else if (indexDepth < maxDepth * 2) {
// Index is phase 2 pollard
uint256 subIndexDepth = indexDepth - maxDepth;
uint256 remainder = subIndexDepth % depthPerRound;
require(remainder == 0, "Invalid index");
return _index / (2 ** depthPerRound);
}
revert("Invalid index");
}
/// @dev Returns true if the given `_index` is in the path from the proposal root down to `_defeatIndex`
/// @param _defeatIndex The index which resulted in the defeat of the proposal
/// @param _index The index to check if it's within the defeat path
/// @return True if `_index` was part of the path which defeated the proposal
function isRewardedIndex(uint256 _defeatIndex, uint256 _index) internal pure returns (bool) {
for (uint256 i = _defeatIndex; i > 1; i /= 2) {
if (_index == i) {
return true;
}
}
return false;
}
/// @notice Returns the state of the given challenge
/// @param _proposalID The ID of the proposal the challenge is for
/// @param _index The global index of the node that is challenged
/// @return The state of the challenge for the given proposal and node
function getChallengeState(uint256 _proposalID, uint256 _index) override external view returns (Types.ChallengeState) {
bytes32 challengeKey = keccak256(abi.encodePacked("dao.protocol.proposal.challenge", _proposalID, _index));
uint256 data = getUint(challengeKey);
return _getChallengeState(data);
}
/// @dev Extracts the packed challenge state from the given uint256
function _getChallengeState(uint256 _data) internal pure returns (Types.ChallengeState) {
return Types.ChallengeState(uint8(_data >> stateOffset));
}
/// @dev Extracts the packed timestamp from the given uint256
function getChallengeTimestamp(uint256 _data) internal pure returns (uint64) {
return uint64(_data >> timestampOffset);
}
/// @dev Extracts the packed address of the challenger from the given uint256
function getChallengeAddress(uint256 _data) internal pure returns (address) {
return address(uint160(_data >> addressOffset));
}
/// @dev Modifies the packed challenge state of a given uint256
function setChallengeState(uint256 _data, Types.ChallengeState _newState) internal pure returns (uint256) {
_data &= ~(uint256(~uint8(0)) << stateOffset);
_data |= uint256(_newState) << stateOffset;
return _data;
}
/// @notice Retrieves the sum and hash of the node at the given global index
function getNode(uint256 _proposalID, uint256 _index) public view returns (Types.Node memory) {
uint256 challengeKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal.challenge", _proposalID, _index)));
Types.Node memory node;
node.sum = getUint(bytes32(challengeKey + sumOffset));
node.hash = getBytes32(bytes32(challengeKey + hashOffset));
return node;
}
/// @dev Sets the sum and hash of the node at the given global index
function setNode(uint256 _proposalID, uint256 _index, Types.Node memory _node) internal {
uint256 challengeKey = uint256(keccak256(abi.encodePacked("dao.protocol.proposal.challenge", _proposalID, _index)));
setUint(bytes32(challengeKey + sumOffset), _node.sum);
setBytes32(bytes32(challengeKey + hashOffset), _node.hash);
}
}
@openzeppelin4/contracts/utils/math/Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
contracts/contract/RocketBase.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
pragma solidity >0.5.0 <0.9.0;
// SPDX-License-Identifier: GPL-3.0-only
import "../interface/RocketStorageInterface.sol";
/// @title Base settings / modifiers for each contract in Rocket Pool
/// @author David Rugendyke
abstract contract RocketBase {
// Calculate using this as the base
uint256 constant calcBase = 1 ether;
// Version of the contract
uint8 public version;
// The main storage contract where primary persistant storage is maintained
RocketStorageInterface rocketStorage = RocketStorageInterface(address(0));
/*** Modifiers **********************************************************/
/**
* @dev Throws if called by any sender that doesn't match a Rocket Pool network contract
*/
modifier onlyLatestNetworkContract() {
require(getBool(keccak256(abi.encodePacked("contract.exists", msg.sender))), "Invalid or outdated network contract");
_;
}
/**
* @dev Throws if called by any sender that doesn't match one of the supplied contract or is the latest version of that contract
*/
modifier onlyLatestContract(string memory _contractName, address _contractAddress) {
require(_contractAddress == getAddress(keccak256(abi.encodePacked("contract.address", _contractName))), "Invalid or outdated contract");
_;
}
/**
* @dev Throws if called by any sender that isn't a registered node
*/
modifier onlyRegisteredNode(address _nodeAddress) {
require(getBool(keccak256(abi.encodePacked("node.exists", _nodeAddress))), "Invalid node");
_;
}
/**
* @dev Throws if called by any sender that isn't a trusted node DAO member
*/
modifier onlyTrustedNode(address _nodeAddress) {
require(getBool(keccak256(abi.encodePacked("dao.trustednodes.", "member", _nodeAddress))), "Invalid trusted node");
_;
}
/**
* @dev Throws if called by any sender that isn't a registered minipool
*/
modifier onlyRegisteredMinipool(address _minipoolAddress) {
require(getBool(keccak256(abi.encodePacked("minipool.exists", _minipoolAddress))), "Invalid minipool");
_;
}
/**
* @dev Throws if called by any sender that isn't a registered megapool
*/
modifier onlyRegisteredMegapool(address _megapoolAddress) {
require(getBool(keccak256(abi.encodePacked("megapool.exists", _megapoolAddress))), "Invalid megapool");
_;
}
/**
* @dev Throws if called by any sender that isn't a registered minipool or megapool
*/
modifier onlyRegisteredMinipoolOrMegapool(address _caller) {
require(
getBool(keccak256(abi.encodePacked("megapool.exists", _caller))) ||
getBool(keccak256(abi.encodePacked("minipool.exists", _caller)))
, "Invalid caller");
_;
}
/**
* @dev Throws if called by any account other than a guardian account (temporary account allowed access to settings before DAO is fully enabled)
*/
modifier onlyGuardian() {
require(msg.sender == rocketStorage.getGuardian(), "Account is not a temporary guardian");
_;
}
/*** Methods **********************************************************/
/// @dev Set the main Rocket Storage address
constructor(RocketStorageInterface _rocketStorageAddress) {
// Update the contract address
rocketStorage = RocketStorageInterface(_rocketStorageAddress);
}
/// @dev Get the address of a network contract by name
function getContractAddress(string memory _contractName) internal view returns (address) {
// Get the current contract address
address contractAddress = getAddress(keccak256(abi.encodePacked("contract.address", _contractName)));
// Check it
require(contractAddress != address(0x0), "Contract not found");
// Return
return contractAddress;
}
/// @dev Get the address of a network contract by name (returns address(0x0) instead of reverting if contract does not exist)
function getContractAddressUnsafe(string memory _contractName) internal view returns (address) {
// Get the current contract address
address contractAddress = getAddress(keccak256(abi.encodePacked("contract.address", _contractName)));
// Return
return contractAddress;
}
/// @dev Get the name of a network contract by address
function getContractName(address _contractAddress) internal view returns (string memory) {
// Get the contract name
string memory contractName = getString(keccak256(abi.encodePacked("contract.name", _contractAddress)));
// Check it
require(bytes(contractName).length > 0, "Contract not found");
// Return
return contractName;
}
/// @dev Get revert error message from a .call method
function getRevertMsg(bytes memory _returnData) internal pure returns (string memory) {
// If the _res length is less than 68, then the transaction failed silently (without a revert message)
if (_returnData.length < 68) return "Transaction reverted silently";
assembly {
// Slice the sighash.
_returnData := add(_returnData, 0x04)
}
return abi.decode(_returnData, (string)); // All that remains is the revert string
}
/*** Rocket Storage Methods ****************************************/
// Note: Unused helpers have been removed to keep contract sizes down
/// @dev Storage get methods
function getAddress(bytes32 _key) internal view returns (address) { return rocketStorage.getAddress(_key); }
function getUint(bytes32 _key) internal view returns (uint) { return rocketStorage.getUint(_key); }
function getString(bytes32 _key) internal view returns (string memory) { return rocketStorage.getString(_key); }
function getBytes(bytes32 _key) internal view returns (bytes memory) { return rocketStorage.getBytes(_key); }
function getBool(bytes32 _key) internal view returns (bool) { return rocketStorage.getBool(_key); }
function getInt(bytes32 _key) internal view returns (int) { return rocketStorage.getInt(_key); }
function getBytes32(bytes32 _key) internal view returns (bytes32) { return rocketStorage.getBytes32(_key); }
/// @dev Storage set methods
function setAddress(bytes32 _key, address _value) internal { rocketStorage.setAddress(_key, _value); }
function setUint(bytes32 _key, uint _value) internal { rocketStorage.setUint(_key, _value); }
function setString(bytes32 _key, string memory _value) internal { rocketStorage.setString(_key, _value); }
function setBytes(bytes32 _key, bytes memory _value) internal { rocketStorage.setBytes(_key, _value); }
function setBool(bytes32 _key, bool _value) internal { rocketStorage.setBool(_key, _value); }
function setInt(bytes32 _key, int _value) internal { rocketStorage.setInt(_key, _value); }
function setBytes32(bytes32 _key, bytes32 _value) internal { rocketStorage.setBytes32(_key, _value); }
/// @dev Storage delete methods
function deleteAddress(bytes32 _key) internal { rocketStorage.deleteAddress(_key); }
function deleteUint(bytes32 _key) internal { rocketStorage.deleteUint(_key); }
function deleteString(bytes32 _key) internal { rocketStorage.deleteString(_key); }
function deleteBytes(bytes32 _key) internal { rocketStorage.deleteBytes(_key); }
function deleteBool(bytes32 _key) internal { rocketStorage.deleteBool(_key); }
function deleteInt(bytes32 _key) internal { rocketStorage.deleteInt(_key); }
function deleteBytes32(bytes32 _key) internal { rocketStorage.deleteBytes32(_key); }
/// @dev Storage arithmetic methods
function addUint(bytes32 _key, uint256 _amount) internal { rocketStorage.addUint(_key, _amount); }
function subUint(bytes32 _key, uint256 _amount) internal { rocketStorage.subUint(_key, _amount); }
}
contracts/interface/RocketStorageInterface.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >0.5.0 <0.9.0;
interface RocketStorageInterface {
// Deploy status
function getDeployedStatus() external view returns (bool);
// Guardian
function getGuardian() external view returns(address);
function setGuardian(address _newAddress) external;
function confirmGuardian() external;
// Getters
function getAddress(bytes32 _key) external view returns (address);
function getUint(bytes32 _key) external view returns (uint);
function getString(bytes32 _key) external view returns (string memory);
function getBytes(bytes32 _key) external view returns (bytes memory);
function getBool(bytes32 _key) external view returns (bool);
function getInt(bytes32 _key) external view returns (int);
function getBytes32(bytes32 _key) external view returns (bytes32);
// Setters
function setAddress(bytes32 _key, address _value) external;
function setUint(bytes32 _key, uint _value) external;
function setString(bytes32 _key, string calldata _value) external;
function setBytes(bytes32 _key, bytes calldata _value) external;
function setBool(bytes32 _key, bool _value) external;
function setInt(bytes32 _key, int _value) external;
function setBytes32(bytes32 _key, bytes32 _value) external;
// Deleters
function deleteAddress(bytes32 _key) external;
function deleteUint(bytes32 _key) external;
function deleteString(bytes32 _key) external;
function deleteBytes(bytes32 _key) external;
function deleteBool(bytes32 _key) external;
function deleteInt(bytes32 _key) external;
function deleteBytes32(bytes32 _key) external;
// Arithmetic
function addUint(bytes32 _key, uint256 _amount) external;
function subUint(bytes32 _key, uint256 _amount) external;
// Protected storage
function getNodeWithdrawalAddress(address _nodeAddress) external view returns (address);
function getNodePendingWithdrawalAddress(address _nodeAddress) external view returns (address);
function setWithdrawalAddress(address _nodeAddress, address _newWithdrawalAddress, bool _confirm) external;
function confirmWithdrawalAddress(address _nodeAddress) external;
}
contracts/interface/dao/RocketDAOProposalInterface.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
pragma solidity >0.5.0 <0.9.0;
// SPDX-License-Identifier: GPL-3.0-only
interface RocketDAOProposalInterface {
// Possible states that a proposal may be in
enum ProposalState {
Pending,
Active,
Cancelled,
Defeated,
Succeeded,
Expired,
Executed
}
function getTotal() external view returns (uint256);
function getDAO(uint256 _proposalID) external view returns (string memory);
function getProposer(uint256 _proposalID) external view returns (address);
function getMessage(uint256 _proposalID) external view returns (string memory);
function getStart(uint256 _proposalID) external view returns (uint256);
function getEnd(uint256 _proposalID) external view returns (uint256);
function getExpires(uint256 _proposalID) external view returns (uint256);
function getCreated(uint256 _proposalID) external view returns (uint256);
function getVotesFor(uint256 _proposalID) external view returns (uint256);
function getVotesAgainst(uint256 _proposalID) external view returns (uint256);
function getVotesRequired(uint256 _proposalID) external view returns (uint256);
function getCancelled(uint256 _proposalID) external view returns (bool);
function getExecuted(uint256 _proposalID) external view returns (bool);
function getPayload(uint256 _proposalID) external view returns (bytes memory);
function getReceiptHasVoted(uint256 _proposalID, address _nodeAddress) external view returns (bool);
function getReceiptSupported(uint256 _proposalID, address _nodeAddress) external view returns (bool);
function getState(uint256 _proposalID) external view returns (ProposalState);
function add(address _member, string memory _dao, string memory _message, uint256 _startBlock, uint256 _durationBlocks, uint256 _expiresBlocks, uint256 _votesRequired, bytes memory _payload) external returns (uint256);
function vote(address _member, uint256 _votes, uint256 _proposalID, bool _support) external;
function cancel(address _member, uint256 _proposalID) external;
function execute(uint256 _proposalID) external;
}
contracts/interface/dao/protocol/RocketDAOProtocolProposalInterface.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >0.5.0 <0.9.0;
pragma abicoder v2;
import "../../../types/SettingType.sol";
import "./RocketDAOProtocolVerifierInterface.sol";
interface RocketDAOProtocolProposalInterface {
// Possible states that a proposal may be in
enum ProposalState {
Pending,
ActivePhase1,
ActivePhase2,
Destroyed,
Vetoed,
QuorumNotMet,
Defeated,
Succeeded,
Expired,
Executed
}
enum VoteDirection {
NoVote,
Abstain,
For,
Against,
AgainstWithVeto
}
function getTotal() external view returns (uint256);
function getProposer(uint256 _proposalID) external view returns (address);
function getMessage(uint256 _proposalID) external view returns (string memory);
function getStart(uint256 _proposalID) external view returns (uint256);
function getPhase1End(uint256 _proposalID) external view returns (uint256);
function getPhase2End(uint256 _proposalID) external view returns (uint256);
function getExpires(uint256 _proposalID) external view returns (uint256);
function getCreated(uint256 _proposalID) external view returns (uint256);
function getVotingPowerFor(uint256 _proposalID) external view returns (uint256);
function getVotingPowerAgainst(uint256 _proposalID) external view returns (uint256);
function getVotingPowerVeto(uint256 _proposalID) external view returns (uint256);
function getVotingPowerAbstained(uint256 _proposalID) external view returns (uint256);
function getVotingPowerRequired(uint256 _proposalID) external view returns (uint256);
function getDestroyed(uint256 _proposalID) external view returns (bool);
function getFinalised(uint256 _proposalID) external view returns (bool);
function getExecuted(uint256 _proposalID) external view returns (bool);
function getVetoQuorum(uint256 _proposalID) external view returns (uint256);
function getVetoed(uint256 _proposalID) external view returns (bool);
function getPayload(uint256 _proposalID) external view returns (bytes memory);
function getReceiptHasVoted(uint256 _proposalID, address _nodeAddress) external view returns (bool);
function getReceiptHasVotedPhase1(uint256 _proposalID, address _nodeAddress) external view returns (bool);
function getReceiptDirection(uint256 _proposalID, address _nodeAddress) external view returns (VoteDirection);
function getState(uint256 _proposalID) external view returns (ProposalState);
function getProposalBlock(uint256 _proposalID) external view returns (uint256);
function getProposalVetoQuorum(uint256 _proposalID) external view returns (uint256);
function propose(string memory _proposalMessage, bytes memory _payload, uint32 _blockNumber, Types.Node[] calldata _treeNodes) external returns (uint256);
function vote(uint256 _proposalID, VoteDirection _vote, uint256 _votingPower, uint256 _nodeIndex, Types.Node[] calldata _witness) external;
function overrideVote(uint256 _proposalID, VoteDirection _voteDirection) external;
function finalise(uint256 _proposalID) external;
function execute(uint256 _proposalID) external;
function destroy(uint256 _proposalID) external;
}
contracts/interface/dao/protocol/RocketDAOProtocolProposalsInterface.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >0.5.0 <0.9.0;
pragma abicoder v2;
import "../../../types/SettingType.sol";
interface RocketDAOProtocolProposalsInterface {
function proposalSettingMulti(string[] memory _settingContractNames, string[] memory _settingPaths, SettingType[] memory _types, bytes[] memory _data) external;
function proposalSettingUint(string memory _settingContractName, string memory _settingPath, uint256 _value) external;
function proposalSettingBool(string memory _settingContractName, string memory _settingPath, bool _value) external;
function proposalSettingAddress(string memory _settingContractName, string memory _settingPath, address _value) external;
function proposalSettingAddressList(string memory _settingContractName, string memory _settingPath, address[] calldata _value) external;
function proposalSettingRewardsClaimers(uint256 _trustedNodePercent, uint256 _protocolPercent, uint256 _nodePercent) external;
function proposalTreasuryOneTimeSpend(string memory _invoiceID, address _recipientAddress, uint256 _amount) external;
function proposalTreasuryNewContract(string memory _contractName, address _recipientAddress, uint256 _amountPerPeriod, uint256 _periodLength, uint256 _startTime, uint256 _numPeriods) external;
function proposalTreasuryUpdateContract(string memory _contractName, address _recipientAddress, uint256 _amountPerPeriod, uint256 _periodLength, uint256 _numPeriods) external;
function proposalSecurityInvite(string memory _id, address _memberAddress) external;
function proposalSecurityKick(address _memberAddress) external;
function proposalSecurityKickMulti(address[] calldata _memberAddresses) external;
function proposalSecurityReplace(address _existingMemberAddress, string calldata _id, address _newMemberAddress) external;
}
contracts/interface/dao/protocol/RocketDAOProtocolVerifierInterface.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >0.5.0 <0.9.0;
pragma abicoder v2;
interface Types {
enum ChallengeState {
Unchallenged,
Challenged,
Responded,
Paid
}
struct Proposal {
address proposer;
uint32 blockNumber;
uint128 nodeCount;
bytes32 hash;
uint256 sum;
}
struct Node {
uint256 sum;
bytes32 hash;
}
struct Leaf {
address nodeAddress;
uint256 effectiveRpl;
}
}
interface RocketDAOProtocolVerifierInterface {
function getDefeatIndex(uint256 _proposalID) external view returns (uint256);
function getProposalBond(uint256 _proposalID) external view returns (uint256);
function getChallengeBond(uint256 _proposalID) external view returns (uint256);
function getChallengePeriod(uint256 _proposalID) external view returns (uint256);
function getDepthPerRound() external pure returns (uint256);
function submitProposalRoot(uint256 _proposalId, address _proposer, uint32 _blockNumber, Types.Node[] memory _treeNodes) external;
function burnProposalBond(uint256 _proposalID) external;
function createChallenge(uint256 _proposalID, uint256 _index, Types.Node calldata _node, Types.Node[] calldata _witness) external;
function submitRoot(uint256 propId, uint256 index, Types.Node[] memory nodes) external;
function getChallengeState(uint256 _proposalID, uint256 _index) external view returns (Types.ChallengeState);
function verifyVote(address _voter, uint256 _nodeIndex, uint256 _proposalID, uint256 _votingPower, Types.Node[] calldata _witness) external view returns (bool);
}
contracts/interface/dao/protocol/settings/RocketDAOProtocolSettingsProposalsInterface.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
pragma solidity >0.5.0 <0.9.0;
// SPDX-License-Identifier: GPL-3.0-only
interface RocketDAOProtocolSettingsProposalsInterface {
function getVotePhase1Time() external view returns(uint256);
function getVotePhase2Time() external view returns(uint256);
function getVoteDelayTime() external view returns(uint256);
function getExecuteTime() external view returns(uint256);
function getProposalBond() external view returns(uint256);
function getChallengeBond() external view returns(uint256);
function getChallengePeriod() external view returns(uint256);
function getProposalQuorum() external view returns (uint256);
function getProposalVetoQuorum() external view returns (uint256);
function getProposalMaxBlockAge() external view returns (uint256);
}
contracts/interface/network/RocketNetworkVotingInterface.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >0.5.0 <0.9.0;
interface RocketNetworkVotingInterface {
function getNodeCount(uint32 _block) external view returns (uint256);
function getVotingPower(address _nodeAddress, uint32 _block) external view returns (uint256);
function setDelegate(address _newDelegate) external;
function getDelegate(address _nodeAddress, uint32 _block) external view returns (address);
function getCurrentDelegate(address _nodeAddress) external view returns (address);
}contracts/interface/node/RocketNodeManagerInterface.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >0.5.0 <0.9.0;
pragma abicoder v2;
import "../../types/NodeDetails.sol";
interface RocketNodeManagerInterface {
// Structs
struct TimezoneCount {
string timezone;
uint256 count;
}
function getNodeCount() external view returns (uint256);
function getNodeCountPerTimezone(uint256 offset, uint256 limit) external view returns (TimezoneCount[] memory);
function getNodeAt(uint256 _index) external view returns (address);
function getNodeExists(address _nodeAddress) external view returns (bool);
function getNodeWithdrawalAddress(address _nodeAddress) external view returns (address);
function getNodePendingWithdrawalAddress(address _nodeAddress) external view returns (address);
function getNodeRPLWithdrawalAddress(address _nodeAddress) external view returns (address);
function getNodeRPLWithdrawalAddressIsSet(address _nodeAddress) external view returns (bool);
function unsetRPLWithdrawalAddress(address _nodeAddress) external;
function setRPLWithdrawalAddress(address _nodeAddress, address _newRPLWithdrawalAddress, bool _confirm) external;
function confirmRPLWithdrawalAddress(address _nodeAddress) external;
function getNodePendingRPLWithdrawalAddress(address _nodeAddress) external view returns (address);
function getNodeTimezoneLocation(address _nodeAddress) external view returns (string memory);
function registerNode(string calldata _timezoneLocation) external;
function getNodeRegistrationTime(address _nodeAddress) external view returns (uint256);
function setTimezoneLocation(string calldata _timezoneLocation) external;
function setRewardNetwork(address _nodeAddress, uint256 network) external;
function getRewardNetwork(address _nodeAddress) external view returns (uint256);
function getFeeDistributorInitialised(address _nodeAddress) external view returns (bool);
function initialiseFeeDistributor() external;
function getAverageNodeFee(address _nodeAddress) external view returns (uint256);
function setSmoothingPoolRegistrationState(bool _state) external;
function getSmoothingPoolRegistrationState(address _nodeAddress) external returns (bool);
function getSmoothingPoolRegistrationChanged(address _nodeAddress) external returns (uint256);
function getSmoothingPoolRegisteredNodeCount(uint256 _offset, uint256 _limit) external view returns (uint256);
function getNodeAddresses(uint256 _offset, uint256 _limit) external view returns (address[] memory);
function deployMegapool() external returns (address);
function getExpressTicketCount(address _nodeAddress) external view returns (uint256);
function useExpressTicket(address _nodeAddress) external;
function provisionExpressTickets(address _nodeAddress) external;
function getExpressTicketsProvisioned(address _nodeAddress) external view returns (bool);
function refundExpressTicket(address _nodeAddress) external;
function getMegapoolAddress(address _nodeAddress) external view returns (address);
function getUnclaimedRewards(address _nodeAddress) external view returns (uint256);
function addUnclaimedRewards(address _nodeAddress) external payable;
function claimUnclaimedRewards(address _nodeAddress) external;
}
contracts/interface/node/RocketNodeStakingInterface.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >0.5.0 <0.9.0;
interface RocketNodeStakingInterface {
function getTotalStakedRPL() external view returns (uint256);
function getTotalMegapoolStakedRPL() external view returns (uint256);
function getTotalLegacyStakedRPL() external view returns (uint256);
function getNodeStakedRPL(address _nodeAddress) external view returns (uint256);
function getNodeMegapoolStakedRPL(address _nodeAddress) external view returns (uint256);
function getNodeLegacyStakedRPL(address _nodeAddress) external view returns (uint256);
function getNodeUnstakingRPL(address _nodeAddress) external view returns (uint256);
function getNodeLockedRPL(address _nodeAddress) external view returns (uint256);
function stakeRPLFor(address _nodeAddress, uint256 _amount) external;
function stakeRPL(uint256 _amount) external;
function unstakeRPL(uint256 _amount) external;
function unstakeRPLFor(address _nodeAddress, uint256 _amount) external;
function withdrawRPL() external;
function withdrawRPLFor(address _nodeAddress) external;
function unstakeLegacyRPL(uint256 _amount) external;
function unstakeLegacyRPLFor(address _nodeAddress, uint256 _amount) external;
function getNodeRPLStakedTime(address _nodeAddress) external view returns (uint256);
function getNodeLastUnstakeTime(address _nodeAddress) external view returns (uint256);
function setStakeRPLForAllowed(address _caller, bool _allowed) external;
function setStakeRPLForAllowed(address _nodeAddress, address _caller, bool _allowed) external;
function getRPLLockingAllowed(address _nodeAddress) external view returns (bool);
function setRPLLockingAllowed(address _nodeAddress, bool _allowed) external;
function getNodeETHBonded(address _nodeAddress) external view returns (uint256);
function getNodeMegapoolETHBonded(address _nodeAddress) external view returns (uint256);
function getNodeMinipoolETHBonded(address _nodeAddress) external view returns (uint256);
function getNodeETHBorrowed(address _nodeAddress) external view returns (uint256);
function getNodeMegapoolETHBorrowed(address _nodeAddress) external view returns (uint256);
function getNodeMinipoolETHBorrowed(address _nodeAddress) external view returns (uint256);
function getNodeMinimumLegacyRPLStake(address _nodeAddress) external view returns (uint256);
function getNodeETHCollateralisationRatio(address _nodeAddress) external view returns (uint256);
// Internal (not callable by users)
function lockRPL(address _nodeAddress, uint256 _amount) external;
function unlockRPL(address _nodeAddress, uint256 _amount) external;
function transferRPL(address _from, address _to, uint256 _amount) external;
function burnRPL(address _from, uint256 _amount) external;
function slashRPL(address _nodeAddress, uint256 _ethSlashAmount) external;
}contracts/interface/token/RocketTokenRPLInterface.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
pragma solidity >0.5.0 <0.9.0;
// SPDX-License-Identifier: GPL-3.0-only
import "../util/IERC20.sol";
interface RocketTokenRPLInterface is IERC20 {
function getInflationCalcTime() external view returns(uint256);
function getInflationIntervalTime() external view returns(uint256);
function getInflationIntervalRate() external view returns(uint256);
function getInflationIntervalsPassed() external view returns(uint256);
function getInflationIntervalStartTime() external view returns(uint256);
function getInflationRewardsContractAddress() external view returns(address);
function inflationCalculate() external view returns (uint256);
function inflationMintTokens() external returns (uint256);
function swapTokens(uint256 _amount) external;
}
contracts/interface/util/IERC20.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity >0.5.0 <0.9.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
contracts/types/NodeDetails.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
pragma solidity >0.5.0 <0.9.0;
// SPDX-License-Identifier: GPL-3.0-only
// A struct containing all the information on-chain about a specific node
struct NodeDetails {
bool exists;
uint256 registrationTime;
string timezoneLocation;
bool feeDistributorInitialised;
address feeDistributorAddress;
uint256 rewardNetwork;
uint256 rplStake;
uint256 effectiveRPLStake;
uint256 minimumRPLStake;
uint256 maximumRPLStake;
uint256 ethMatched;
uint256 ethMatchedLimit;
uint256 minipoolCount;
uint256 balanceETH;
uint256 balanceRETH;
uint256 balanceRPL;
uint256 balanceOldRPL;
uint256 depositCreditBalance;
uint256 distributorBalanceUserETH;
uint256 distributorBalanceNodeETH;
address withdrawalAddress;
address pendingWithdrawalAddress;
bool smoothingPoolRegistrationState;
uint256 smoothingPoolRegistrationChanged;
address nodeAddress;
}
contracts/types/SettingType.sol
/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/
pragma solidity >0.5.0 <0.9.0;
// SPDX-License-Identifier: GPL-3.0-only
enum SettingType {
UINT256,
BOOL,
ADDRESS,
STRING,
BYTES,
BYTES32,
INT256
}
Compiler settingsShow
{
"viaIR": true,
"optimizer": {
"runs": 15000,
"enabled": true
},
"evmVersion": "paris"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.