Skip to content

Commit

Permalink
feat(IProfile, ICandidateManager, ICoinbaseExecution, IRoninValidator…
Browse files Browse the repository at this point in the history
…Set): add related function to support zk-evm integration (#139)

Co-authored-by: TuDo1403 <[email protected]>
  • Loading branch information
github-actions[bot] and TuDo1403 committed Oct 25, 2024
1 parent 4b47075 commit 8f3de79
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 17 deletions.
79 changes: 79 additions & 0 deletions src/interfaces/IProfile.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ interface IProfile {
bytes32 vrfKeyHash;
/// @dev Timestamp of last change of VRF key hash. Only used in the logic of Beacon. Not used for checking for cooldown of updating the profile.
uint256 vrfKeyHashLastChange;
/////////////////// ZkEVM Related Variables //////////////////////
/// @dev The rollup id of the candidate.
uint32 rollupId;
/// @dev The trusted aggregator to verify the zk proof.
address aggregator;
/// @dev The trusted sequencer to sequence batch of L2 transactions.
address sequencer;
}

/// @dev Event emitted when a profile with `id` is added.
Expand All @@ -53,6 +60,12 @@ interface IProfile {
event VRFKeyHashChanged(address indexed id, bytes32 vrfKeyHash);
/// @dev Event emitted when the pubkey is verified successfully.
event PubkeyVerified(bytes pubkey, bytes proofOfPossession);
/// @dev Event emitted when the validator create new rollup contract.
event RollupCreated(address indexed id, uint32 indexed rollupId);
/// @dev Event emitted when the validator change the trusted aggregator.
event AggregatorChanged(address indexed id, address indexed aggregator);
/// @dev Event emitted when the validator change the trusted sequencer.
event SequencerChanged(address indexed id, address indexed sequencer);

/// @dev Error of already existed profile.
error ErrExistentProfile();
Expand All @@ -74,7 +87,11 @@ interface IProfile {
error ErrInvalidProofOfPossession(bytes pubkey, bytes proofOfPossession);
error ErrLookUpIdFailed(TConsensus consensus);
error ErrLookUpIdFromVRFKeyFailed(bytes32 vrfKeyHash);
error ErrLookUpIdFromRollupIdFailed(uint32 rollupId);
error ErrValidatorOnRenunciation(address cid);
error ErrExistentRollup(address cid, uint32 createdRollupId);
error ErrZeroRollupId(address cid);
error ErrRollupIdAlreadyRegistered(uint32 rollupId);

function initialize(
address validatorContract
Expand All @@ -86,6 +103,43 @@ interface IProfile {
uint256 cooldown
) external;

function initializeV4(
address rollupManager
) external;

/// @dev Getter to query `id` from `rollupId`.
function getRollupId2Id(
uint32 rollupId
) external view returns (address id);

/// @dev Getter to query `rollupId` from `id` address.
function getId2RollupId(
address id
) external view returns (uint32);

/// @dev Getter to query `aggregator` from `id` address.
function getId2Aggregator(
address id
) external view returns (address);

/// @dev Getter to query `sequencer` from `id` address.
function getId2Sequencer(
address id
) external view returns (address);

/*
* @dev Cross-contract function to add new rollup contract of a candidate.
*
* Requirements:
* - Only `rollupManager` can call this method.
* - On renounce, the candidate cannot create a new rollup contract.
* - `id` must be a valid candidate.
* - `rollupId` must be unique.
* - `rollupId` must be greater than 0.
* - Candidate must not have any rollup id before.
*/
function execCreateRollup(address id, uint32 rollupId) external;

/// @dev Getter to query full `profile` from `id` address.
function getId2Profile(
address id
Expand Down Expand Up @@ -186,6 +240,11 @@ interface IProfile {
bytes32 vrfKeyHash
) external view returns (bool found, address id);

/// @dev Getter to backward query from `rollupId` to `id` address.
function tryGetRollupId2Id(
uint32 rollupId
) external view returns (bool found, address id);

/// @dev Getter to backward batch query from `consensus` address to `id` address.
function getManyConsensus2Id(
TConsensus[] memory consensus
Expand All @@ -206,6 +265,26 @@ interface IProfile {
bytes calldata proofOfPossession
) external;

/**
* @dev Updated the `sequencer` address of candidate id `id` immediately without waiting time.
* Requirements:
* - Only admin can call this method.
* - The profile must be existed.
* - The new sequencer address must not be duplicated or zero.
* - Must have created rollup contract before.
*/
function changeSequencerAddr(address id, address newSequencer) external;

/**
* @dev Updated the `aggregator` address of candidate id `id` immediately without waiting time.
* Requirements:
* - Only admin can call this method.
* - The profile must be existed.
* - The new aggregator address must not be duplicated or zero.
* - Must have created rollup contract before.
*/
function changeAggregatorAddr(address id, address newAggregator) external;

/**
* @dev Updated the treasury address of candidate id `id` immediately without waiting time.
*
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/validator/ICandidateManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ interface ICandidateManager {
error ErrInvalidCommissionRate();
/// @dev Error of invalid min effective days onwards.
error ErrInvalidMinEffectiveDaysOnwards();
/// @dev Error of validator who is rollup owner cannot renounce.
error ErrRollupOwnerCannotRenounce();

/**
* @dev Returns the maximum number of validator candidate.
Expand Down
46 changes: 29 additions & 17 deletions src/interfaces/validator/ICoinbaseExecution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,42 @@ interface ICoinbaseExecution is ISlashingExecution {
event EmptyValidatorSet(uint256 indexed period, uint256 indexed epoch, address[] fallbackCids);
/// @dev Emitted when the validator set is updated
event ValidatorSetUpdated(uint256 indexed period, uint256 indexed epoch, address[] cids);
/// @dev Emitted when the bridge operator set is updated, to mirror the in-jail and maintaining status of the validator.
/// @dev Emitted when the block producer operator set is updated, to mirror the in-jail and maintaining status of the validator.
event BlockProducerSetUpdated(uint256 indexed period, uint256 indexed epoch, address[] cids);
/// @dev Emitted when the bridge operator set is updated.
event BridgeOperatorSetUpdated(uint256 indexed period, uint256 indexed epoch, address[] bridgeOperators);

/// @dev Emitted when the reward of the block producer is deprecated.
event BlockRewardDeprecated(address indexed cid, uint256 rewardAmount, BlockRewardDeprecatedType deprecatedType);
/// @dev Emitted when the block reward is submitted.
event BlockRewardSubmitted(address indexed cid, uint256 submittedAmount, uint256 bonusAmount);
/// @dev Emitted when the L2 tx fee is submitted.
event L2BlockRewardSubmitted(address indexed cid, uint256 submittedAmount);

/// @dev Emitted when the mining reward of corresponding l2 is distributed.
event L2MiningRewardDistributed(address indexed cid, address indexed recipient, uint256 amount);
/// @dev Emitted when the contract fails when distributing the mining reward of corresponding l2.
event L2MiningRewardDistributionFailed(
address indexed cid, address indexed recipient, uint256 amount, uint256 contractBalance
);
/// @dev Emitted when the block producer reward is distributed.
event MiningRewardDistributed(address indexed cid, address indexed recipient, uint256 amount);
/// @dev Emitted when the contract fails when distributing the block producer reward.
event MiningRewardDistributionFailed(
address indexed cid, address indexed recipient, uint256 amount, uint256 contractBalance
);

/// @dev Emitted when the bridge operator reward is distributed.
event BridgeOperatorRewardDistributed(
address indexed cid, address indexed bridgeOperator, address indexed recipientAddr, uint256 amount
);
/// @dev Emitted when the contract fails when distributing the bridge operator reward.
event BridgeOperatorRewardDistributionFailed(
address indexed cid,
address indexed bridgeOperator,
address indexed recipient,
uint256 amount,
uint256 contractBalance
);

/// @dev Emitted when the fast finality reward is distributed to validator.
event FastFinalityRewardDistributed(address indexed cid, address indexed recipient, uint256 amount);
/// @dev Emitted when the contract fails when distributing the fast finality reward to validator.
event FastFinalityRewardDistributionFailed(
address indexed cid, address indexed recipient, uint256 amount, uint256 contractBalance
);

/// @dev Emitted when the L2 tx fee is distributed to the delegator.
event L2MiningRewardDelegatorsDistributed(address[] cids, uint256[] delegatingAmounts);
/// @dev Emitted when the contract fails when distributing the L2 tx fee to the delegator.
event L2MiningRewardDelegatorsDistributionFailed(
address[] cids, uint256[] delegatingAmounts, uint256 contractBalance
);
/// @dev Emitted when the amount of block mining reward is distributed to staking contract for delegators.
event MiningRewardDelegatorsDistributed(address[] cids, uint256[] delegatingAmounts);
/// @dev Emitted when the contracts fails when distributing the amount of RON to the staking contract for delegators.
Expand Down Expand Up @@ -85,6 +84,20 @@ interface ICoinbaseExecution is ISlashingExecution {
*/
function submitBlockReward() external payable;

/**
* @dev Receives L2 tx fee from `ZkEVMFeePlazaL1` contract.
*
* - L2 fee will be distributed to both `validator` and their corresponding `delegator`.
* - L2 fee is shared among the validators and delegators based on `commissionRate`.
*
* Requirements:
* - The method caller is `ZkEVMFeePlazaL1` contract.
* @param cid The candidate id (owner) of the rollup contract.
*/
function onL2BlockRewardSubmitted(
address cid
) external payable;

/**
* @dev Wraps up the current epoch.
*
Expand All @@ -96,7 +109,6 @@ interface ICoinbaseExecution is ISlashingExecution {
* Emits the event `MiningRewardDistributed` when some validator has reward distributed.
* Emits the event `StakingRewardDistributed` when some staking pool has reward distributed.
* Emits the event `BlockProducerSetUpdated` when the epoch is wrapped up.
* Emits the event `BridgeOperatorSetUpdated` when the epoch is wrapped up at period ending.
* Emits the event `ValidatorSetUpdated` when the epoch is wrapped up at period ending, and the validator set gets updated.
* Emits the event `WrappedUpEpoch`.
*
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/validator/IRoninValidatorSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ interface IRoninValidatorSet is
function initializeV4(
address profileContract
) external;
function initializeV5(
address zkFeePlazaContract
) external;
}

0 comments on commit 8f3de79

Please sign in to comment.