Skip to content

Commit

Permalink
v0.6.2-testnet (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
nxqbao authored Sep 12, 2023
2 parents 3ea46d4 + 9ec990c commit 89b56d7
Show file tree
Hide file tree
Showing 181 changed files with 9,930 additions and 770 deletions.
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/prb-test"]
branch = release-v0
path = lib/prb-test
url = https://github.com/PaulRBerg/prb-test
[submodule "lib/prb-math"]
path = lib/prb-math
url = https://github.com/PaulRBerg/prb-math
branch = release-v4
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ The collections of smart contracts that power the Ronin Delegated Proof of Stake
$ yarn --frozen-lockfile
```

- Install foundry libs

```
$ git submodule add -b release-v0 https://github.com/PaulRBerg/prb-test lib/prb-test
$ git submodule add -b release-v4 https://github.com/PaulRBerg/prb-math lib/prb-math
```
- Compile contracts
```shell
Expand Down
4 changes: 2 additions & 2 deletions contracts/extensions/GovernanceAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ abstract contract GovernanceAdmin is
/**
* @dev Override `CoreGovernance-_getTotalWeights`.
*/
function _getTotalWeights() internal view virtual override returns (uint256) {
bytes4 _selector = IRoninTrustedOrganization.totalWeights.selector;
function _getTotalWeight() internal view virtual override returns (uint256) {
bytes4 _selector = IRoninTrustedOrganization.totalWeight.selector;
(bool _success, bytes memory _returndata) = getContract(ContractType.RONIN_TRUSTED_ORGANIZATION).staticcall(
abi.encodeWithSelector(
// TransparentUpgradeableProxyV2.functionDelegateCall.selector,
Expand Down
24 changes: 11 additions & 13 deletions contracts/extensions/bridge-operator-governance/BridgeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
uint96[] memory voteWeights
) payable BridgeManagerCallbackRegister(callbackRegisters) {
NONCE_SLOT.store(1);
NUMERATOR_SLOT.store(num);
DENOMINATOR_SLOT.store(denom);

_setThreshold(num, denom);
_setContract(ContractType.BRIDGE, bridgeContract);

DOMAIN_SEPARATOR = keccak256(
Expand Down Expand Up @@ -167,21 +166,21 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
/**
* @inheritdoc IBridgeManager
*/
function getTotalWeights() public view returns (uint256) {
function getTotalWeight() public view returns (uint256) {
return TOTAL_WEIGHTS_SLOT.load();
}

/**
* @inheritdoc IBridgeManager
*/
function getGovernorWeights(address[] calldata governors) external view returns (uint256[] memory weights) {
function getGovernorWeights(address[] calldata governors) external view returns (uint96[] memory weights) {
weights = _getGovernorWeights(governors);
}

/**
* @inheritdoc IBridgeManager
*/
function getGovernorWeight(address governor) external view returns (uint256 weight) {
function getGovernorWeight(address governor) external view returns (uint96 weight) {
weight = _getGovernorWeight(governor);
}

Expand All @@ -197,7 +196,7 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
/**
* @inheritdoc IBridgeManager
*/
function totalBridgeOperators() external view returns (uint256) {
function totalBridgeOperator() external view returns (uint256) {
return _getBridgeOperatorSet().length();
}

Expand Down Expand Up @@ -260,7 +259,7 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
function getFullBridgeOperatorInfos()
external
view
returns (address[] memory governors, address[] memory bridgeOperators, uint256[] memory weights)
returns (address[] memory governors, address[] memory bridgeOperators, uint96[] memory weights)
{
governors = _getGovernors();
bridgeOperators = getBridgeOperatorOf(governors);
Expand All @@ -270,7 +269,7 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
/**
* @inheritdoc IBridgeManager
*/
function getBridgeOperatorWeight(address bridgeOperator) external view returns (uint256 weight) {
function getBridgeOperatorWeight(address bridgeOperator) external view returns (uint96 weight) {
mapping(address => address) storage _governorOf = _getGovernorOf();
mapping(address => BridgeOperatorInfo) storage _governorToBridgeOperatorInfo = _getGovernorToBridgeOperatorInfo();
weight = _governorToBridgeOperatorInfo[_governorOf[bridgeOperator]].voteWeight;
Expand Down Expand Up @@ -467,9 +466,9 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
* @param governors An array containing the addresses of governors.
* @return weights An array containing the vote weights of the corresponding governors.
*/
function _getGovernorWeights(address[] memory governors) internal view returns (uint256[] memory weights) {
function _getGovernorWeights(address[] memory governors) internal view returns (uint96[] memory weights) {
uint256 length = governors.length;
weights = new uint256[](length);
weights = new uint96[](length);
mapping(address => BridgeOperatorInfo) storage _governorToBridgeOperatorInfo = _getGovernorToBridgeOperatorInfo();
for (uint256 i; i < length; ) {
weights[i] = _governorToBridgeOperatorInfo[governors[i]].voteWeight;
Expand All @@ -486,10 +485,9 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
* @notice The input array `governors` must contain unique addresses to avoid duplicate calculations.
*/
function _sumGovernorsWeight(address[] memory governors) internal view nonDuplicate(governors) returns (uint256 sum) {
uint256 length = _getBridgeOperatorSet().length();
mapping(address => BridgeOperatorInfo) storage _governorToBridgeOperatorInfo = _getGovernorToBridgeOperatorInfo();

for (uint256 i; i < length; ) {
for (uint256 i; i < governors.length; ) {
sum += _governorToBridgeOperatorInfo[governors[i]].voteWeight;

unchecked {
Expand All @@ -514,7 +512,7 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
* @param governor The address of the governor to get the vote weight for.
* @return voteWeight The vote weight of the specified governor.
*/
function _getGovernorWeight(address governor) internal view returns (uint256) {
function _getGovernorWeight(address governor) internal view returns (uint96) {
return _getGovernorToBridgeOperatorInfo()[governor].voteWeight;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import { IBridgeManagerCallbackRegister } from "../../interfaces/bridge/IBridgeManagerCallbackRegister.sol";
import { IBridgeManagerCallback } from "../../interfaces/bridge/IBridgeManagerCallback.sol";
import { IdentityGuard } from "../../utils/IdentityGuard.sol";
import { TransparentUpgradeableProxyV2, IdentityGuard } from "../../utils/IdentityGuard.sol";

/**
* @title BridgeManagerCallbackRegister
Expand Down Expand Up @@ -107,19 +107,23 @@ abstract contract BridgeManagerCallbackRegister is IdentityGuard, IBridgeManager
uint256 length = registers.length;
if (length == 0) return;

bool[] memory statuses = new bool[](length);
bool[] memory successes = new bool[](length);
bytes[] memory returnDatas = new bytes[](length);
bytes memory callData = abi.encodePacked(callbackFnSig, inputs);
bytes memory proxyCallData = abi.encodeCall(TransparentUpgradeableProxyV2.functionDelegateCall, (callData));

for (uint256 i; i < length; ) {
(statuses[i], returnDatas[i]) = registers[i].call(callData);
(successes[i], returnDatas[i]) = registers[i].call(callData);
if (!successes[i]) {
(successes[i], returnDatas[i]) = registers[i].call(proxyCallData);
}

unchecked {
++i;
}
}

emit Notified(callData, registers, statuses, returnDatas);
emit Notified(callData, registers, successes, returnDatas);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions contracts/extensions/collections/HasProxyAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "../../utils/CommonErrors.sol";

abstract contract HasProxyAdmin {
// bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1));
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
bytes32 private constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

modifier onlyAdmin() {
_requireAdmin();
Expand All @@ -16,7 +16,7 @@ abstract contract HasProxyAdmin {
/**
* @dev Returns proxy admin.
*/
function _getAdmin() internal view returns (address) {
function _getAdmin() internal view virtual returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ abstract contract CoreGovernance is SignatureConsumer, VoteStatusConsumer, Chain
/**
* @dev Returns total weight from validators.
*/
function _getTotalWeights() internal view virtual returns (uint256);
function _getTotalWeight() internal view virtual returns (uint256);

/**
* @dev Returns minimum vote to pass a proposal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract contract CommonGovernanceProposal is CoreGovernance {
if (!(_supports.length != 0 && _supports.length == _signatures.length)) revert ErrLengthMismatch(msg.sig);

uint256 _minimumForVoteWeight = _getMinimumVoteWeight();
uint256 _minimumAgainstVoteWeight = _getTotalWeights() - _minimumForVoteWeight + 1;
uint256 _minimumAgainstVoteWeight = _getTotalWeight() - _minimumForVoteWeight + 1;

address _lastSigner;
address _signer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ abstract contract GovernanceProposal is CoreGovernance, CommonGovernanceProposal
revert ErrInvalidProposal(proposalHash, vote[_proposal.chainId][_proposal.nonce].hash);

uint256 _minimumForVoteWeight = _getMinimumVoteWeight();
uint256 _minimumAgainstVoteWeight = _getTotalWeights() - _minimumForVoteWeight + 1;
uint256 _minimumAgainstVoteWeight = _getTotalWeight() - _minimumForVoteWeight + 1;
Signature memory _emptySignature;
_castVote(
_proposal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ abstract contract CommonGovernanceRelay is CoreGovernance {

ProposalVote storage _vote = vote[_proposal.chainId][_proposal.nonce];
uint256 _minimumForVoteWeight = _getMinimumVoteWeight();
uint256 _totalForVoteWeight = _sumWeights(_forVoteSigners);
uint256 _totalForVoteWeight = _sumWeight(_forVoteSigners);
if (_totalForVoteWeight >= _minimumForVoteWeight) {
if (_totalForVoteWeight == 0) revert ErrInvalidVoteWeight(msg.sig);
_vote.status = VoteStatus.Approved;
Expand All @@ -70,8 +70,8 @@ abstract contract CommonGovernanceRelay is CoreGovernance {
return;
}

uint256 _minimumAgainstVoteWeight = _getTotalWeights() - _minimumForVoteWeight + 1;
uint256 _totalAgainstVoteWeight = _sumWeights(_againstVoteSigners);
uint256 _minimumAgainstVoteWeight = _getTotalWeight() - _minimumForVoteWeight + 1;
uint256 _totalAgainstVoteWeight = _sumWeight(_againstVoteSigners);
if (_totalAgainstVoteWeight >= _minimumAgainstVoteWeight) {
if (_totalAgainstVoteWeight == 0) revert ErrInvalidVoteWeight(msg.sig);
_vote.status = VoteStatus.Rejected;
Expand All @@ -85,5 +85,5 @@ abstract contract CommonGovernanceRelay is CoreGovernance {
/**
* @dev Returns the weight of the governor list.
*/
function _sumWeights(address[] memory _governors) internal view virtual returns (uint256);
function _sumWeight(address[] memory _governors) internal view virtual returns (uint256);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { ERC1967Upgrade } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol";
import { IConditionalImplementControl } from "../../interfaces/version-control/IConditionalImplementControl.sol";
import { ErrorHandler } from "../../libraries/ErrorHandler.sol";
import { AddressArrayUtils } from "../../libraries/AddressArrayUtils.sol";
Expand All @@ -11,10 +10,17 @@ 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, ERC1967Upgrade {
abstract contract ConditionalImplementControl is IConditionalImplementControl, IdentityGuard {
using ErrorHandler for bool;
using AddressArrayUtils for address[];

/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

/**
* @dev address of the proxy that delegates to this contract.
* @notice immutable variables are directly stored in contract code.
Expand Down Expand Up @@ -50,26 +56,17 @@ abstract contract ConditionalImplementControl is IConditionalImplementControl, I
_;
}

/**
* @dev Modifier that only allows contracts with code.
* @param addr The address of the contract to check.
*/
modifier onlyContract(address addr) {
_requireHasCode(addr);
_;
}

/**
* @dev Constructs the ConditionalImplementControl contract.
* @param proxyStorage The address of the proxy that is allowed to delegate to this contract.
* @param prevImpl The address of the current contract implementation.
* @param newImpl The address of the new contract implementation.
*/
constructor(
address proxyStorage,
address prevImpl,
address newImpl
) onlyContract(proxyStorage) onlyContract(prevImpl) onlyContract(newImpl) {
constructor(address proxyStorage, address prevImpl, address newImpl) {
_requireHasCode(newImpl);
_requireHasCode(prevImpl);
_requireHasCode(proxyStorage);

address[] memory addrs = new address[](3);
addrs[0] = proxyStorage;
addrs[1] = prevImpl;
Expand Down Expand Up @@ -98,11 +95,17 @@ abstract contract ConditionalImplementControl is IConditionalImplementControl, I
/**
* @dev See {IConditionalImplementControl-selfUpgrade}.
*/

function selfUpgrade() external onlyDelegateFromProxyStorage onlySelfCall {
function selfUpgrade() external virtual onlyDelegateFromProxyStorage onlySelfCall {
_upgradeTo(NEW_IMPL);
}

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

/**
* @dev Internal function to get the current version of the contract implementation.
* @return The address of the current version.
Expand Down Expand Up @@ -156,7 +159,7 @@ abstract contract ConditionalImplementControl is IConditionalImplementControl, I
* - The method caller must be this contract.
*
*/
function _requireSelfCall() internal view override {
function _requireSelfCall() internal view virtual override {
if (msg.sender != PROXY_STORAGE) revert ErrOnlySelfCall(msg.sig);
}

Expand Down
22 changes: 22 additions & 0 deletions contracts/interfaces/IFastFinalityTracking.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.9;

interface IFastFinalityTracking {
/**
* @dev Submit list of `voters` who vote for fast finality in the current block.
*
* Requirements:
* - Only called once per block
* - Only coinbase can call this method
*/
function recordFinality(address[] calldata voters) external;

/**
* @dev Returns vote count of `addrs` in the `period`.
*/
function getManyFinalityVoteCounts(
uint256 period,
address[] calldata addrs
) external view returns (uint256[] memory voteCounts);
}
6 changes: 3 additions & 3 deletions contracts/interfaces/IMaintenance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ interface IMaintenance {
/**
* @dev Returns whether the validator `_consensusAddr`
*/
function checkCooldownEnds(address _consensusAddr) external view returns (bool);
function checkCooldownEnded(address _consensusAddr) external view returns (bool);

/**
* @dev Returns the detailed schedule of the validator `_consensusAddr`.
Expand All @@ -120,7 +120,7 @@ interface IMaintenance {
/**
* @dev Returns the total of current schedules.
*/
function totalSchedules() external view returns (uint256 _count);
function totalSchedule() external view returns (uint256 _count);

/**
* @dev Sets the duration restriction, start time restriction, and max allowed for maintenance.
Expand Down Expand Up @@ -165,7 +165,7 @@ interface IMaintenance {
/**
* @dev Returns the max number of scheduled maintenances.
*/
function maxSchedules() external view returns (uint256);
function maxSchedule() external view returns (uint256);

/**
* @dev Schedules for maintenance from `_startedAtBlock` to `_startedAtBlock`.
Expand Down
Loading

0 comments on commit 89b56d7

Please sign in to comment.