Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(zkevm-integration): implement draft-impl #140

Open
wants to merge 4 commits into
base: feature/zkevm-integration
Choose a base branch
from

Conversation

github-actions[bot]
Copy link

@TuDo1403 TuDo1403 force-pushed the implement-feature/zkevm-integration/draft-impl branch from 9d49a13 to 218c373 Compare October 25, 2024 07:53
Copy link
Author

github-actions bot commented Oct 25, 2024

Slither report

THIS CHECKLIST IS NOT COMPLETE. Use --show-ignored-findings to show all the results.
Summary

reentrancy-eth

Impact: High
Confidence: Medium

function _distributeRewardToTreasuriesAndCalculateTotalDelegatorsReward(
uint256 lastPeriod,
address[] memory cids
)
private
returns (
uint256[] memory delegatorBlockMiningRewards,
uint256[] memory delegatorL2BlockMiningRewards,
uint256[] memory delegatorFastFinalityRewards
)
{
address vId; // validator id
address payable treasury;
uint256 length = cids.length;
delegatorBlockMiningRewards = new uint256[](length);
delegatorL2BlockMiningRewards = new uint256[](length);
delegatorFastFinalityRewards = new uint256[](length);
(uint256 minRate, uint256 maxRate) = IStaking(getContract(ContractType.STAKING)).getCommissionRateRange();
for (uint256 i; i < length; ++i) {
vId = cids[i];
treasury = _candidateInfo[vId].__shadowedTreasury;
// Distribute the L2 mining reward to the treasury address of the validator regardless of the jail status.
delegatorL2BlockMiningRewards[i] = _delegatorL2MiningReward[vId];
_distributeL2MiningReward(vId, treasury);
if (!_isJailedById(vId) && !_miningRewardDeprecatedById(vId, lastPeriod)) {
(uint256 validatorFFReward, uint256 delegatorFFReward) = _calcCommissionReward({
vId: vId,
totalReward: _fastFinalityReward[vId],
maxCommissionRate: maxRate,
minCommissionRate: minRate
});
delegatorBlockMiningRewards[i] = _delegatorMiningReward[vId];
delegatorFastFinalityRewards[i] = delegatorFFReward;
_distributeMiningReward(vId, treasury);
_distributeFastFinalityReward(vId, treasury, validatorFFReward);
} else {
_totalDeprecatedReward += _validatorMiningReward[vId] + _delegatorMiningReward[vId] + _fastFinalityReward[vId];
}
delete _delegatorMiningReward[vId];
delete _validatorMiningReward[vId];
delete _fastFinalityReward[vId];
delete _delegatorL2MiningReward[vId];
delete _validatorL2MiningReward[vId];
}
}

function wrapUpEpoch() external payable virtual override onlyCoinbase whenEpochEnding oncePerEpoch {
unchecked {
uint256 newPeriod = _computePeriod(block.timestamp);
bool periodEnding = _isPeriodEnding(newPeriod);
uint256 lastPeriod = currentPeriod();
uint256 epoch = epochOf(block.number);
uint256 nextEpoch = epoch + 1;
IRandomBeacon randomBeacon = IRandomBeacon(getContract(ContractType.RANDOM_BEACON));
// This request is actually only invoked at the first epoch of the period.
randomBeacon.execRequestRandomSeedForNextPeriod(lastPeriod, newPeriod);
// Get all candidate ids
address[] memory allCids = _candidateIds;
_syncFastFinalityReward({ epoch: epoch, validatorIds: allCids });
if (periodEnding) {
ISlashIndicator slashIndicatorContract = ISlashIndicator(getContract(ContractType.SLASH_INDICATOR));
// Slash submit random beacon proof unavailability first, then update credit scores.
randomBeacon.execRecordAndSlashUnavailability(lastPeriod, newPeriod, address(slashIndicatorContract), allCids);
slashIndicatorContract.execUpdateCreditScores(allCids, lastPeriod);
(
uint256[] memory delegatorBlockMiningRewards,
uint256[] memory delegatorL2BlockMiningRewards,
uint256[] memory delegatorFastFinalityRewards
) = _distributeRewardToTreasuriesAndCalculateTotalDelegatorsReward(lastPeriod, allCids);
_settleAndTransferDelegatingRewards(
lastPeriod, allCids, delegatorBlockMiningRewards, delegatorL2BlockMiningRewards, delegatorFastFinalityRewards
);
_tryRecycleLockedFundsFromEmergencyExits();
_recycleDeprecatedRewards();
address[] memory revokedCandidateIds = _syncCandidateSet(newPeriod);
if (revokedCandidateIds.length > 0) {
// Re-update `allCids` after unsatisfied candidates get removed.
allCids = _candidateIds;
slashIndicatorContract.execResetCreditScores(revokedCandidateIds);
}
// Wrap up the beacon period includes (1) finalizing the beacon proof, and (2) determining the validator list for the next period by new proof.
// Should wrap up the beacon after unsatisfied candidates get removed.
randomBeacon.execFinalizeBeaconAndPendingCids(lastPeriod, newPeriod, allCids);
_periodEndBlock[lastPeriod] = block.number;
_currentPeriodStartAtBlock = block.number + 1;
}
// Clear the previous validator set and block producer set before sync the new set from beacon.
_clearPreviousValidatorSetAndBlockProducerSet();
// Query the new validator set for upcoming epoch from the random beacon contract.
// Save new set into the contract storage.
address[] memory newValidatorIds = _syncValidatorSet(randomBeacon, newPeriod, nextEpoch);
// Activate applicable validators into the block producer set.
_updateApplicableValidatorToBlockProducerSet(newPeriod, nextEpoch, newValidatorIds);
emit WrappedUpEpoch(lastPeriod, epoch, periodEnding);
_periodOf[nextEpoch] = newPeriod;
_lastUpdatedPeriod = newPeriod;
}
}

function wrapUpEpoch() external payable virtual override onlyCoinbase whenEpochEnding oncePerEpoch {
unchecked {
uint256 newPeriod = _computePeriod(block.timestamp);
bool periodEnding = _isPeriodEnding(newPeriod);
uint256 lastPeriod = currentPeriod();
uint256 epoch = epochOf(block.number);
uint256 nextEpoch = epoch + 1;
IRandomBeacon randomBeacon = IRandomBeacon(getContract(ContractType.RANDOM_BEACON));
// This request is actually only invoked at the first epoch of the period.
randomBeacon.execRequestRandomSeedForNextPeriod(lastPeriod, newPeriod);
// Get all candidate ids
address[] memory allCids = _candidateIds;
_syncFastFinalityReward({ epoch: epoch, validatorIds: allCids });
if (periodEnding) {
ISlashIndicator slashIndicatorContract = ISlashIndicator(getContract(ContractType.SLASH_INDICATOR));
// Slash submit random beacon proof unavailability first, then update credit scores.
randomBeacon.execRecordAndSlashUnavailability(lastPeriod, newPeriod, address(slashIndicatorContract), allCids);
slashIndicatorContract.execUpdateCreditScores(allCids, lastPeriod);
(
uint256[] memory delegatorBlockMiningRewards,
uint256[] memory delegatorL2BlockMiningRewards,
uint256[] memory delegatorFastFinalityRewards
) = _distributeRewardToTreasuriesAndCalculateTotalDelegatorsReward(lastPeriod, allCids);
_settleAndTransferDelegatingRewards(
lastPeriod, allCids, delegatorBlockMiningRewards, delegatorL2BlockMiningRewards, delegatorFastFinalityRewards
);
_tryRecycleLockedFundsFromEmergencyExits();
_recycleDeprecatedRewards();
address[] memory revokedCandidateIds = _syncCandidateSet(newPeriod);
if (revokedCandidateIds.length > 0) {
// Re-update `allCids` after unsatisfied candidates get removed.
allCids = _candidateIds;
slashIndicatorContract.execResetCreditScores(revokedCandidateIds);
}
// Wrap up the beacon period includes (1) finalizing the beacon proof, and (2) determining the validator list for the next period by new proof.
// Should wrap up the beacon after unsatisfied candidates get removed.
randomBeacon.execFinalizeBeaconAndPendingCids(lastPeriod, newPeriod, allCids);
_periodEndBlock[lastPeriod] = block.number;
_currentPeriodStartAtBlock = block.number + 1;
}
// Clear the previous validator set and block producer set before sync the new set from beacon.
_clearPreviousValidatorSetAndBlockProducerSet();
// Query the new validator set for upcoming epoch from the random beacon contract.
// Save new set into the contract storage.
address[] memory newValidatorIds = _syncValidatorSet(randomBeacon, newPeriod, nextEpoch);
// Activate applicable validators into the block producer set.
_updateApplicableValidatorToBlockProducerSet(newPeriod, nextEpoch, newValidatorIds);
emit WrappedUpEpoch(lastPeriod, epoch, periodEnding);
_periodOf[nextEpoch] = newPeriod;
_lastUpdatedPeriod = newPeriod;
}
}

function execDeprecatePools(
address[] calldata poolIds,
uint256 newPeriod
) external override onlyContract(ContractType.VALIDATOR) {
if (poolIds.length == 0) {
return;
}
for (uint256 i = 0; i < poolIds.length;) {
address poolId = poolIds[i];
PoolDetail storage _pool = _poolDetail[poolId];
// Deactivate the pool admin in the active mapping.
delete _adminOfActivePoolMapping[_pool.__shadowedPoolAdmin];
// Deduct and transfer the self staking amount to the pool admin.
uint256 deductingAmount = _pool.stakingAmount;
if (deductingAmount > 0) {
_deductStakingAmount(_pool, deductingAmount);
if (!_unsafeSendRONLimitGas(payable(_pool.__shadowedPoolAdmin), deductingAmount, DEFAULT_ADDITION_GAS)) {
emit StakingAmountTransferFailed(_pool.pid, _pool.__shadowedPoolAdmin, deductingAmount, address(this).balance);
}
}
// Settle the unclaimed reward and transfer to the pool admin.
uint256 lastRewardAmount = _claimReward(poolId, _pool.__shadowedPoolAdmin, newPeriod);
if (lastRewardAmount > 0) {
_unsafeSendRONLimitGas(payable(_pool.__shadowedPoolAdmin), lastRewardAmount, DEFAULT_ADDITION_GAS);
}
unchecked {
++i;
}
}
emit PoolsDeprecated(poolIds);
}

function wrapUpEpoch() external payable virtual override onlyCoinbase whenEpochEnding oncePerEpoch {
unchecked {
uint256 newPeriod = _computePeriod(block.timestamp);
bool periodEnding = _isPeriodEnding(newPeriod);
uint256 lastPeriod = currentPeriod();
uint256 epoch = epochOf(block.number);
uint256 nextEpoch = epoch + 1;
IRandomBeacon randomBeacon = IRandomBeacon(getContract(ContractType.RANDOM_BEACON));
// This request is actually only invoked at the first epoch of the period.
randomBeacon.execRequestRandomSeedForNextPeriod(lastPeriod, newPeriod);
// Get all candidate ids
address[] memory allCids = _candidateIds;
_syncFastFinalityReward({ epoch: epoch, validatorIds: allCids });
if (periodEnding) {
ISlashIndicator slashIndicatorContract = ISlashIndicator(getContract(ContractType.SLASH_INDICATOR));
// Slash submit random beacon proof unavailability first, then update credit scores.
randomBeacon.execRecordAndSlashUnavailability(lastPeriod, newPeriod, address(slashIndicatorContract), allCids);
slashIndicatorContract.execUpdateCreditScores(allCids, lastPeriod);
(
uint256[] memory delegatorBlockMiningRewards,
uint256[] memory delegatorL2BlockMiningRewards,
uint256[] memory delegatorFastFinalityRewards
) = _distributeRewardToTreasuriesAndCalculateTotalDelegatorsReward(lastPeriod, allCids);
_settleAndTransferDelegatingRewards(
lastPeriod, allCids, delegatorBlockMiningRewards, delegatorL2BlockMiningRewards, delegatorFastFinalityRewards
);
_tryRecycleLockedFundsFromEmergencyExits();
_recycleDeprecatedRewards();
address[] memory revokedCandidateIds = _syncCandidateSet(newPeriod);
if (revokedCandidateIds.length > 0) {
// Re-update `allCids` after unsatisfied candidates get removed.
allCids = _candidateIds;
slashIndicatorContract.execResetCreditScores(revokedCandidateIds);
}
// Wrap up the beacon period includes (1) finalizing the beacon proof, and (2) determining the validator list for the next period by new proof.
// Should wrap up the beacon after unsatisfied candidates get removed.
randomBeacon.execFinalizeBeaconAndPendingCids(lastPeriod, newPeriod, allCids);
_periodEndBlock[lastPeriod] = block.number;
_currentPeriodStartAtBlock = block.number + 1;
}
// Clear the previous validator set and block producer set before sync the new set from beacon.
_clearPreviousValidatorSetAndBlockProducerSet();
// Query the new validator set for upcoming epoch from the random beacon contract.
// Save new set into the contract storage.
address[] memory newValidatorIds = _syncValidatorSet(randomBeacon, newPeriod, nextEpoch);
// Activate applicable validators into the block producer set.
_updateApplicableValidatorToBlockProducerSet(newPeriod, nextEpoch, newValidatorIds);
emit WrappedUpEpoch(lastPeriod, epoch, periodEnding);
_periodOf[nextEpoch] = newPeriod;
_lastUpdatedPeriod = newPeriod;
}
}

function wrapUpEpoch() external payable virtual override onlyCoinbase whenEpochEnding oncePerEpoch {
unchecked {
uint256 newPeriod = _computePeriod(block.timestamp);
bool periodEnding = _isPeriodEnding(newPeriod);
uint256 lastPeriod = currentPeriod();
uint256 epoch = epochOf(block.number);
uint256 nextEpoch = epoch + 1;
IRandomBeacon randomBeacon = IRandomBeacon(getContract(ContractType.RANDOM_BEACON));
// This request is actually only invoked at the first epoch of the period.
randomBeacon.execRequestRandomSeedForNextPeriod(lastPeriod, newPeriod);
// Get all candidate ids
address[] memory allCids = _candidateIds;
_syncFastFinalityReward({ epoch: epoch, validatorIds: allCids });
if (periodEnding) {
ISlashIndicator slashIndicatorContract = ISlashIndicator(getContract(ContractType.SLASH_INDICATOR));
// Slash submit random beacon proof unavailability first, then update credit scores.
randomBeacon.execRecordAndSlashUnavailability(lastPeriod, newPeriod, address(slashIndicatorContract), allCids);
slashIndicatorContract.execUpdateCreditScores(allCids, lastPeriod);
(
uint256[] memory delegatorBlockMiningRewards,
uint256[] memory delegatorL2BlockMiningRewards,
uint256[] memory delegatorFastFinalityRewards
) = _distributeRewardToTreasuriesAndCalculateTotalDelegatorsReward(lastPeriod, allCids);
_settleAndTransferDelegatingRewards(
lastPeriod, allCids, delegatorBlockMiningRewards, delegatorL2BlockMiningRewards, delegatorFastFinalityRewards
);
_tryRecycleLockedFundsFromEmergencyExits();
_recycleDeprecatedRewards();
address[] memory revokedCandidateIds = _syncCandidateSet(newPeriod);
if (revokedCandidateIds.length > 0) {
// Re-update `allCids` after unsatisfied candidates get removed.
allCids = _candidateIds;
slashIndicatorContract.execResetCreditScores(revokedCandidateIds);
}
// Wrap up the beacon period includes (1) finalizing the beacon proof, and (2) determining the validator list for the next period by new proof.
// Should wrap up the beacon after unsatisfied candidates get removed.
randomBeacon.execFinalizeBeaconAndPendingCids(lastPeriod, newPeriod, allCids);
_periodEndBlock[lastPeriod] = block.number;
_currentPeriodStartAtBlock = block.number + 1;
}
// Clear the previous validator set and block producer set before sync the new set from beacon.
_clearPreviousValidatorSetAndBlockProducerSet();
// Query the new validator set for upcoming epoch from the random beacon contract.
// Save new set into the contract storage.
address[] memory newValidatorIds = _syncValidatorSet(randomBeacon, newPeriod, nextEpoch);
// Activate applicable validators into the block producer set.
_updateApplicableValidatorToBlockProducerSet(newPeriod, nextEpoch, newValidatorIds);
emit WrappedUpEpoch(lastPeriod, epoch, periodEnding);
_periodOf[nextEpoch] = newPeriod;
_lastUpdatedPeriod = newPeriod;
}
}

shadowing-state

Impact: High
Confidence: High

uint256[49] private ______gap;

uint256[50] private ______gap;

uninitialized-state

Impact: High
Confidence: High

uint256 internal _firstTrackedPeriodEnd;

uint256 internal _numberOfBlocksInEpoch;

mapping(uint32 rollupId => address cid) internal _rollupId2Id;

mapping(uint256 epoch => uint256 period) internal _periodOf;

mapping(address => mapping(uint256 => bool)) internal _miningRewardDeprecatedAtPeriod;

uint256 internal _lastUpdatedPeriod;

mapping(address => uint256) internal _blockProducerJailedBlock;

mapping(address cid => bool isBlockProducer) internal _validatorMap;

mapping(uint256 period => uint256 endedAtBlock) internal _periodEndBlock;

mapping(uint256 idx => address cid) internal _validatorIds;

uint256 internal _currentPeriodStartAtBlock;

@TuDo1403 TuDo1403 force-pushed the implement-feature/zkevm-integration/draft-impl branch from 218c373 to 9acc56e Compare October 25, 2024 08:13
Copy link
Author

github-actions bot commented Oct 25, 2024

Storage Layout Change Report

Layout Changes for ProfileHandler

--- https://github.com/ronin-chain/dpos-contract/blob/8f3de799bd122622d3f96abb01db226cd4a58b31/src/ronin/profile/ProfileHandler.sol	.464099646 +0000
+++ https://github.com/ronin-chain/dpos-contract/blob/03b1613b9f1f9d6e7a224b30800677c2ebf39d1d/src/ronin/profile/ProfileHandler.sol	.464099646 +0000
@@ -3,4 +3,5 @@
     2          _consensus2Id                mapping(TConsensus => address)
     3          _profileChangeCooldown       uint256
     4          _vrfKeyHash2Id               mapping(bytes32 => address)
-    5          __gap                        bytes32[46]
+🏴  5          _rollupId2Id                 mapping(uint32 => address)
+🏴  6          __gap                        bytes32[45]

Layout Changes for ProfileStorage

--- https://github.com/ronin-chain/dpos-contract/blob/8f3de799bd122622d3f96abb01db226cd4a58b31/src/ronin/profile/ProfileStorage.sol	.533100945 +0000
+++ https://github.com/ronin-chain/dpos-contract/blob/03b1613b9f1f9d6e7a224b30800677c2ebf39d1d/src/ronin/profile/ProfileStorage.sol	.533100945 +0000
@@ -3,4 +3,5 @@
     2          _consensus2Id                mapping(TConsensus => address)
     3          _profileChangeCooldown       uint256
     4          _vrfKeyHash2Id               mapping(bytes32 => address)
-    5          __gap                        bytes32[46]
+🏴  5          _rollupId2Id                 mapping(uint32 => address)
+🏴  6          __gap                        bytes32[45]

Layout Changes for SlashingExecution

--- https://github.com/ronin-chain/dpos-contract/blob/8f3de799bd122622d3f96abb01db226cd4a58b31/src/ronin/validator/SlashingExecution.sol	.100262167 +0000
+++ https://github.com/ronin-chain/dpos-contract/blob/03b1613b9f1f9d6e7a224b30800677c2ebf39d1d/src/ronin/validator/SlashingExecution.sol	.100262167 +0000
@@ -32,5 +32,6 @@
     173        _lockedConsensusList         address[]
     174        _exitInfo                    mapping(address => struct ICommonInfo.EmergencyExitInfo)
     175        _lockedFundReleased          mapping(address => bool)
-    176        ______gap                    uint256[44]
-
+🏴  176        _validatorL2MiningReward     mapping(address => uint256)
+🏴  177        _delegatorL2MiningReward     mapping(address => uint256)
+🏴  178        ______gap                    uint256[42]

Layout Changes for CoinbaseExecution

--- https://github.com/ronin-chain/dpos-contract/blob/8f3de799bd122622d3f96abb01db226cd4a58b31/src/ronin/validator/CoinbaseExecution.sol	.577271143 +0000
+++ https://github.com/ronin-chain/dpos-contract/blob/03b1613b9f1f9d6e7a224b30800677c2ebf39d1d/src/ronin/validator/CoinbaseExecution.sol	.577271143 +0000
@@ -42,5 +42,6 @@
     230        _lockedConsensusList         address[]
     231        _exitInfo                    mapping(address => struct ICommonInfo.EmergencyExitInfo)
     232        _lockedFundReleased          mapping(address => bool)
-    233        ______gap                    uint256[44]
-
+🏴  233        _validatorL2MiningReward     mapping(address => uint256)
+🏴  234        _delegatorL2MiningReward     mapping(address => uint256)
+🏴  235        ______gap                    uint256[42]

Layout Changes for EmergencyExit

--- https://github.com/ronin-chain/dpos-contract/blob/8f3de799bd122622d3f96abb01db226cd4a58b31/src/ronin/validator/EmergencyExit.sol	.214264312 +0000
+++ https://github.com/ronin-chain/dpos-contract/blob/03b1613b9f1f9d6e7a224b30800677c2ebf39d1d/src/ronin/validator/EmergencyExit.sol	.214264312 +0000
@@ -38,5 +38,6 @@
     226        _lockedConsensusList         address[]
     227        _exitInfo                    mapping(address => struct ICommonInfo.EmergencyExitInfo)
     228        _lockedFundReleased          mapping(address => bool)
-    229        ______gap                    uint256[44]
-
+🏴  229        _validatorL2MiningReward     mapping(address => uint256)
+🏴  230        _delegatorL2MiningReward     mapping(address => uint256)
+🏴  231        ______gap                    uint256[42]

Layout Changes for CoinbaseExecutionDependant

--- https://github.com/ronin-chain/dpos-contract/blob/8f3de799bd122622d3f96abb01db226cd4a58b31/src/ronin/validator/CoinbaseExecutionDependant.sol	.282265592 +0000
+++ https://github.com/ronin-chain/dpos-contract/blob/03b1613b9f1f9d6e7a224b30800677c2ebf39d1d/src/ronin/validator/CoinbaseExecutionDependant.sol	.282265592 +0000
@@ -42,5 +42,6 @@
     230        _lockedConsensusList         address[]
     231        _exitInfo                    mapping(address => struct ICommonInfo.EmergencyExitInfo)
     232        _lockedFundReleased          mapping(address => bool)
-    233        ______gap                    uint256[44]
-
+🏴  233        _validatorL2MiningReward     mapping(address => uint256)
+🏴  234        _delegatorL2MiningReward     mapping(address => uint256)
+🏴  235        ______gap                    uint256[42]

Layout Changes for RoninValidatorSetConstructor

--- https://github.com/ronin-chain/dpos-contract/blob/8f3de799bd122622d3f96abb01db226cd4a58b31/src/ronin/validator/RoninValidatorSetConstructor.sol	.897277165 +0000
+++ https://github.com/ronin-chain/dpos-contract/blob/03b1613b9f1f9d6e7a224b30800677c2ebf39d1d/src/ronin/validator/RoninValidatorSetConstructor.sol	.897277165 +0000
@@ -44,5 +44,6 @@
     231        _lockedConsensusList         address[]
     232        _exitInfo                    mapping(address => struct ICommonInfo.EmergencyExitInfo)
     233        _lockedFundReleased          mapping(address => bool)
-    234        ______gap                    uint256[44]
-
+🏴  234        _validatorL2MiningReward     mapping(address => uint256)
+🏴  235        _delegatorL2MiningReward     mapping(address => uint256)
+🏴  236        ______gap                    uint256[42]

Layout Changes for SlashingExecutionDependant

--- https://github.com/ronin-chain/dpos-contract/blob/8f3de799bd122622d3f96abb01db226cd4a58b31/src/ronin/validator/SlashingExecutionDependant.sol	.315266213 +0000
+++ https://github.com/ronin-chain/dpos-contract/blob/03b1613b9f1f9d6e7a224b30800677c2ebf39d1d/src/ronin/validator/SlashingExecutionDependant.sol	.315266213 +0000
@@ -32,5 +32,6 @@
     173        _lockedConsensusList         address[]
     174        _exitInfo                    mapping(address => struct ICommonInfo.EmergencyExitInfo)
     175        _lockedFundReleased          mapping(address => bool)
-    176        ______gap                    uint256[44]
-
+🏴  176        _validatorL2MiningReward     mapping(address => uint256)
+🏴  177        _delegatorL2MiningReward     mapping(address => uint256)
+🏴  178        ______gap                    uint256[42]

Layout Changes for CommonStorage

--- https://github.com/ronin-chain/dpos-contract/blob/8f3de799bd122622d3f96abb01db226cd4a58b31/src/ronin/validator/storage-fragments/CommonStorage.sol	.351248071 +0000
+++ https://github.com/ronin-chain/dpos-contract/blob/03b1613b9f1f9d6e7a224b30800677c2ebf39d1d/src/ronin/validator/storage-fragments/CommonStorage.sol	.351248071 +0000
@@ -30,5 +30,6 @@
     171        _lockedConsensusList         address[]
     172        _exitInfo                    mapping(address => struct ICommonInfo.EmergencyExitInfo)
     173        _lockedFundReleased          mapping(address => bool)
-    174        ______gap                    uint256[44]
-
+🏴  174        _validatorL2MiningReward     mapping(address => uint256)
+🏴  175        _delegatorL2MiningReward     mapping(address => uint256)
+🏴  176        ______gap                    uint256[42]

uint32 rollupId
) external view returns (address) {
(bool found, address id) = _tryGetRollupId2Id(rollupId);
if (!found) revert ErrLookUpIdFromRollupIdFailed(rollupId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why dont we just return address zero when not found? Reverting in external view function doesn't make sense

Copy link
Collaborator

@TuDo1403 TuDo1403 Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have try function for that. This protects other contracts from querying null data

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which other contracts? And should we revert when not found in both methods getId2Aggregator and getId2Sequencer too?

function changeSequencerAddr(address id, address sequencer) external onlyAdmin {
CandidateProfile storage _profile = _getId2ProfileHelper(id);

_requireNonZeroAndNonDuplicated(RoleAccess.SEQUENCER, sequencer);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the logic, aggregator address must be differential from sequencer address. Is it as intended?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intended.

function execCreateRollup(address id, uint32 rollupId) external onlyContract(ContractType.ZK_ROLLUP_MANAGER) {
CandidateProfile storage _profile = _getId2ProfileHelper(id);

_requireNotOnRenunciation(id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to have: bring it to modifier

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will bring later


_requireNotOnRenunciation(id);

if (_registry[rollupId]) revert ErrRollupIdAlreadyRegistered(rollupId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the rollup ID does not exist but accidentally matches any registered address, this tx will be reverted. Is this as intended?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rollupId in range 2**32 so it cannot match

/**
* @dev Checks whether the candidate has created a rollup before.
*/
function _isRollupOwner(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function _isRollupOwner(
function _isRollupOwned(

Comment on lines -41 to -44
// TODO: remove this line in the next upgrade
if (_firstTrackedPeriodEnd == 0) {
_firstTrackedPeriodEnd = _lastUpdatedPeriod;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain the context for this change

Comment on lines +268 to +269
delete _delegatorL2MiningReward[vId];
delete _validatorL2MiningReward[vId];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change do not follow CEI pattern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants