Skip to content

Commit

Permalink
Deploy: v0.6.4 mainnet (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
nxqbao authored Oct 21, 2023
2 parents 1208da9 + bb1d310 commit aa272d3
Show file tree
Hide file tree
Showing 145 changed files with 35,262 additions and 8,103 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ remix-compiler.config.js
.yarnrc.yml
logs/storage_layout_table.log
cache_foundry
out
out
.DS_Store

dry-run/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
path = lib/prb-math
url = https://github.com/PaulRBerg/prb-math
branch = release-v4
[submodule "lib/solady"]
path = lib/solady
url = https://github.com/vectorized/solady
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ This repo contains source code of contracts that will be either deployed on the

- On mainchains:
- Governance contract: `MainchainGovernanceAdmin`
- Bridge contract: `MainchainGatewayV2`
- Bridge contract: `MainchainGatewayV3`
- Trusted orgs contract: `RoninTrustedOrganization`
- On Ronin chain:
- Governance contract: `RoninGovernanceAdmin`
- Bridge operation: `RoninGatewayV2`
- Bridge operation: `RoninGatewayV3`
- Trusted orgs contract: `RoninTrustedOrganization`
- DPoS contracts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "@openzeppelin/contracts/security/Pausable.sol";
import "../interfaces/IQuorum.sol";
import "./collections/HasProxyAdmin.sol";

abstract contract GatewayV2 is HasProxyAdmin, Pausable, IQuorum {
abstract contract GatewayV3 is HasProxyAdmin, Pausable, IQuorum {
uint256 internal _num;
uint256 internal _denom;

Expand Down
6 changes: 3 additions & 3 deletions contracts/extensions/WithdrawalLimitation.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./GatewayV2.sol";
import "./GatewayV3.sol";

abstract contract WithdrawalLimitation is GatewayV2 {
abstract contract WithdrawalLimitation is GatewayV3 {
/// @dev Error of invalid percentage.
error ErrInvalidPercentage();

Expand Down Expand Up @@ -50,7 +50,7 @@ abstract contract WithdrawalLimitation is GatewayV2 {
uint256[50] private ______gap;

/**
* @dev Override `GatewayV2-setThreshold`.
* @dev Override `GatewayV3-setThreshold`.
*
* Requirements:
* - The high-tier vote weight threshold must equal to or larger than the normal threshold.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { HasContracts } from "../collections/HasContracts.sol";
import { IConditionalImplementControl } from "../../interfaces/version-control/IConditionalImplementControl.sol";
import { ErrorHandler } from "../../libraries/ErrorHandler.sol";
import { AddressArrayUtils } from "../../libraries/AddressArrayUtils.sol";
Expand All @@ -10,7 +11,7 @@ import { ErrOnlySelfCall, IdentityGuard } from "../../utils/IdentityGuard.sol";
* @title ConditionalImplementControl
* @dev A contract that allows conditional version control of contract implementations.
*/
abstract contract ConditionalImplementControl is IConditionalImplementControl, IdentityGuard {
abstract contract ConditionalImplementControl is IConditionalImplementControl, IdentityGuard, HasContracts {
using ErrorHandler for bool;
using AddressArrayUtils for address[];

Expand All @@ -21,6 +22,9 @@ abstract contract ConditionalImplementControl is IConditionalImplementControl, I
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

/// @dev value is equal to keccak256("@ronin.extensions.version-control.ConditionalImplementControl.calldatas.slot") - 1
bytes32 internal constant CALLDATAS_SLOT = 0x330d87be17f5b23d41285647e0e9b0e7124a778feb3f952590ed6a023ae02633;

/**
* @dev address of the proxy that delegates to this contract.
* @notice immutable variables are directly stored in contract code.
Expand Down Expand Up @@ -99,11 +103,49 @@ abstract contract ConditionalImplementControl is IConditionalImplementControl, I
_upgradeTo(NEW_IMPL);
}

/**
* @dev See {IConditionalImplementControl-setCallDatas}.
*/
function setCallDatas(bytes[] calldata args) external onlyAdmin onlyDelegateFromProxyStorage {
bytes[] storage callDatas = _callDatas();
uint256 length = args.length;
for (uint256 i; i < length; ) {
callDatas.push(args[i]);

unchecked {
++i;
}
}
}

/**
* @dev Internal function to access the array of calldatas.
* @return callDatas the storage array of calldatas.
*/
function _callDatas() internal pure returns (bytes[] storage callDatas) {
assembly ("memory-safe") {
callDatas.slot := CALLDATAS_SLOT
}
}

function _upgradeTo(address newImplementation) internal {
assembly ("memory-safe") {
sstore(_IMPLEMENTATION_SLOT, newImplementation)
}
emit Upgraded(newImplementation);

bytes[] storage callDatas = _callDatas();
uint256 length = callDatas.length;
bool success;
bytes memory returnOrRevertData;
for (uint256 i; i < length; ) {
(success, returnOrRevertData) = newImplementation.delegatecall(callDatas[i]);
success.handleRevert(bytes4(callDatas[i]), returnOrRevertData);

unchecked {
++i;
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "./consumers/SignatureConsumer.sol";
import "./consumers/MappedTokenConsumer.sol";
import "../libraries/Transfer.sol";

interface IMainchainGatewayV2 is SignatureConsumer, MappedTokenConsumer {
interface IMainchainGatewayV3 is SignatureConsumer, MappedTokenConsumer {
/**
* @dev Error indicating that a query was made for an approved withdrawal.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
import "../libraries/Transfer.sol";
import "./consumers/MappedTokenConsumer.sol";

interface IRoninGatewayV2 is MappedTokenConsumer {
interface IRoninGatewayV3 is MappedTokenConsumer {
/**
* @dev Error thrown when attempting to withdraw funds that have already been migrated.
*/
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/bridge/IBridgeSlash.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface IBridgeSlash is IBridgeSlashEvents {
uint256 totalBallot,
uint256 totalVote,
uint256 period
) external returns (bool slashed);
) external;

/**
* @dev Returns the penalize durations for the specified bridge operators.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ interface IConditionalImplementControl {
* @dev Executes the selfUpgrade function, upgrading to the new contract implementation.
*/
function selfUpgrade() external;

/**
* @dev Set additional calldata to call when upgrading via `selfUpgrade`.
*/
function setCallDatas(bytes[] calldata args) external;
}
3 changes: 2 additions & 1 deletion contracts/libraries/GlobalProposal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ library GlobalProposal {
/* 0 */ BridgeManager,
/* 1 */ GatewayContract,
/* 2 */ BridgeReward,
/* 3 */ BridgeSlash
/* 3 */ BridgeSlash,
/* 4 */ BridgeTracking
}

struct GlobalProposalDetail {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { IBridgeManagerCallback } from "../interfaces/bridge/IBridgeManagerCallb
import { HasContracts, ContractType } from "../extensions/collections/HasContracts.sol";
import "../extensions/WithdrawalLimitation.sol";
import "../libraries/Transfer.sol";
import "../interfaces/IMainchainGatewayV2.sol";
import "../interfaces/IMainchainGatewayV3.sol";

contract MainchainGatewayV2 is
contract MainchainGatewayV3 is
WithdrawalLimitation,
Initializable,
AccessControlEnumerable,
IMainchainGatewayV2,
IMainchainGatewayV3,
HasContracts
{
using Token for Token.Info;
Expand Down Expand Up @@ -112,28 +112,28 @@ contract MainchainGatewayV2 is
function receiveEther() external payable {}

/**
* @inheritdoc IMainchainGatewayV2
* @inheritdoc IMainchainGatewayV3
*/
function DOMAIN_SEPARATOR() external view virtual returns (bytes32) {
return _domainSeparator;
}

/**
* @inheritdoc IMainchainGatewayV2
* @inheritdoc IMainchainGatewayV3
*/
function setWrappedNativeTokenContract(IWETH _wrappedToken) external virtual onlyAdmin {
_setWrappedNativeTokenContract(_wrappedToken);
}

/**
* @inheritdoc IMainchainGatewayV2
* @inheritdoc IMainchainGatewayV3
*/
function requestDepositFor(Transfer.Request calldata _request) external payable virtual whenNotPaused {
_requestDepositFor(_request, msg.sender);
}

/**
* @inheritdoc IMainchainGatewayV2
* @inheritdoc IMainchainGatewayV3
*/
function submitWithdrawal(
Transfer.Receipt calldata _receipt,
Expand All @@ -143,7 +143,7 @@ contract MainchainGatewayV2 is
}

/**
* @inheritdoc IMainchainGatewayV2
* @inheritdoc IMainchainGatewayV3
*/
function unlockWithdrawal(Transfer.Receipt calldata _receipt) external onlyRole(WITHDRAWAL_UNLOCKER_ROLE) {
bytes32 _receiptHash = _receipt.hash();
Expand Down Expand Up @@ -173,7 +173,7 @@ contract MainchainGatewayV2 is
}

/**
* @inheritdoc IMainchainGatewayV2
* @inheritdoc IMainchainGatewayV3
*/
function mapTokens(
address[] calldata _mainchainTokens,
Expand All @@ -185,7 +185,7 @@ contract MainchainGatewayV2 is
}

/**
* @inheritdoc IMainchainGatewayV2
* @inheritdoc IMainchainGatewayV3
*/
function mapTokensAndThresholds(
address[] calldata _mainchainTokens,
Expand All @@ -206,7 +206,7 @@ contract MainchainGatewayV2 is
}

/**
* @inheritdoc IMainchainGatewayV2
* @inheritdoc IMainchainGatewayV3
*/
function getRoninToken(address _mainchainToken) public view returns (MappedToken memory _token) {
_token = _roninToken[_mainchainToken];
Expand Down Expand Up @@ -444,7 +444,7 @@ contract MainchainGatewayV2 is
}

/**
* @inheritdoc GatewayV2
* @inheritdoc GatewayV3
*/
function _getTotalWeight() internal view override returns (uint256) {
return IBridgeManager(getContract(ContractType.BRIDGE_MANAGER)).getTotalWeight();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../../ronin/gateway/RoninGatewayV2.sol";
import "../../ronin/gateway/RoninGatewayV3.sol";

contract MockRoninGatewayV2Extended is RoninGatewayV2 {
contract MockRoninGatewayV3Extended is RoninGatewayV3 {
/*
* @dev Returns the vote weight for a deposit based on its corressponding hash.
*/
Expand Down
28 changes: 16 additions & 12 deletions contracts/ronin/gateway/BridgeReward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,29 @@ contract BridgeReward is IBridgeReward, BridgeTrackingHelper, HasContracts, RONT
address bridgeTrackingContract,
address bridgeSlashContract,
address validatorSetContract,
address dposGA,
uint256 rewardPerPeriod
) external payable initializer {
_setContract(ContractType.BRIDGE_MANAGER, bridgeManagerContract);
_setContract(ContractType.BRIDGE_TRACKING, bridgeTrackingContract);
_setContract(ContractType.BRIDGE_SLASH, bridgeSlashContract);
_setContract(ContractType.VALIDATOR, validatorSetContract);
_setContract(ContractType.GOVERNANCE_ADMIN, dposGA);
LATEST_REWARDED_PERIOD_SLOT.store(type(uint256).max);
_setRewardPerPeriod(rewardPerPeriod);
_syncLatestRewardedPeriod();
_receiveRON();
}

/**
* @dev Helper for running upgrade script, required to only revoked once by the DPoS's governance admin.
* The following must be assured after initializing REP2: `_lastSyncPeriod` == `{BridgeReward}.latestRewardedPeriod` == `currentPeriod()`
*/
function initializeREP2() external onlyContract(ContractType.GOVERNANCE_ADMIN) {
require(getLatestRewardedPeriod() == type(uint256).max, "already init rep 2");
LATEST_REWARDED_PERIOD_SLOT.store(IRoninValidatorSet(getContract(ContractType.VALIDATOR)).currentPeriod() - 1);
_setContract(ContractType.GOVERNANCE_ADMIN, address(0));
}

/**
* @inheritdoc IBridgeReward
*/
Expand Down Expand Up @@ -95,6 +107,8 @@ contract BridgeReward is IBridgeReward, BridgeTrackingHelper, HasContracts, RONT

/**
* @inheritdoc IBridgeReward
*
* @dev The `period` a.k.a. `latestSyncedPeriod` must equal to `latestRewardedPeriod` + 1.
*/
function execSyncReward(
address[] calldata operators,
Expand All @@ -106,7 +120,7 @@ contract BridgeReward is IBridgeReward, BridgeTrackingHelper, HasContracts, RONT
if (operators.length != ballots.length) revert ErrLengthMismatch(msg.sig);
if (operators.length == 0) return;

// Only sync the period that is after the latest rewarded period.
// Only sync the period that is after the latest rewarded period, i.e. `latestSyncedPeriod == latestRewardedPeriod + 1`.
unchecked {
uint256 latestRewardedPeriod = getLatestRewardedPeriod();
if (period < latestRewardedPeriod + 1) revert ErrInvalidArguments(msg.sig);
Expand Down Expand Up @@ -195,16 +209,6 @@ contract BridgeReward is IBridgeReward, BridgeTrackingHelper, HasContracts, RONT
TOTAL_REWARDS_SCATTERED_SLOT.addAssign(sumRewards);
}

/**
* @dev Internal function to synchronize the latest rewarded period based on the current period of the validator set contract.
* @notice This function is used internally to synchronize the latest rewarded period with the current period of the validator set contract.
* @notice The `currentPeriod` of the validator set contract is retrieved and stored in the `LATEST_REWARDED_PERIOD_SLOT`.
* @notice This function ensures that the latest rewarded period is updated to reflect the current period in the validator set contract.
*/
function _syncLatestRewardedPeriod() internal {
LATEST_REWARDED_PERIOD_SLOT.store(IRoninValidatorSet(getContract(ContractType.VALIDATOR)).currentPeriod());
}

/**
* @dev Returns whether should share the reward equally, in case of bridge tracking returns
* informed data or there is no ballot in a day.
Expand Down
Loading

0 comments on commit aa272d3

Please sign in to comment.