Skip to content

Commit 89b56d7

Browse files
authored
v0.6.2-testnet (#281)
2 parents 3ea46d4 + 9ec990c commit 89b56d7

File tree

181 files changed

+9930
-770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+9930
-770
lines changed

.gitmodules

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
[submodule "lib/forge-std"]
22
path = lib/forge-std
33
url = https://github.com/foundry-rs/forge-std
4+
[submodule "lib/prb-test"]
5+
branch = release-v0
6+
path = lib/prb-test
7+
url = https://github.com/PaulRBerg/prb-test
8+
[submodule "lib/prb-math"]
9+
path = lib/prb-math
10+
url = https://github.com/PaulRBerg/prb-math
11+
branch = release-v4

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ The collections of smart contracts that power the Ronin Delegated Proof of Stake
2424
$ yarn --frozen-lockfile
2525
```
2626

27+
- Install foundry libs
28+
29+
```
30+
$ git submodule add -b release-v0 https://github.com/PaulRBerg/prb-test lib/prb-test
31+
$ git submodule add -b release-v4 https://github.com/PaulRBerg/prb-math lib/prb-math
32+
```
33+
2734
- Compile contracts
2835
2936
```shell

contracts/extensions/GovernanceAdmin.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ abstract contract GovernanceAdmin is
144144
/**
145145
* @dev Override `CoreGovernance-_getTotalWeights`.
146146
*/
147-
function _getTotalWeights() internal view virtual override returns (uint256) {
148-
bytes4 _selector = IRoninTrustedOrganization.totalWeights.selector;
147+
function _getTotalWeight() internal view virtual override returns (uint256) {
148+
bytes4 _selector = IRoninTrustedOrganization.totalWeight.selector;
149149
(bool _success, bytes memory _returndata) = getContract(ContractType.RONIN_TRUSTED_ORGANIZATION).staticcall(
150150
abi.encodeWithSelector(
151151
// TransparentUpgradeableProxyV2.functionDelegateCall.selector,

contracts/extensions/bridge-operator-governance/BridgeManager.sol

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
7575
uint96[] memory voteWeights
7676
) payable BridgeManagerCallbackRegister(callbackRegisters) {
7777
NONCE_SLOT.store(1);
78-
NUMERATOR_SLOT.store(num);
79-
DENOMINATOR_SLOT.store(denom);
8078

79+
_setThreshold(num, denom);
8180
_setContract(ContractType.BRIDGE, bridgeContract);
8281

8382
DOMAIN_SEPARATOR = keccak256(
@@ -167,21 +166,21 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
167166
/**
168167
* @inheritdoc IBridgeManager
169168
*/
170-
function getTotalWeights() public view returns (uint256) {
169+
function getTotalWeight() public view returns (uint256) {
171170
return TOTAL_WEIGHTS_SLOT.load();
172171
}
173172

174173
/**
175174
* @inheritdoc IBridgeManager
176175
*/
177-
function getGovernorWeights(address[] calldata governors) external view returns (uint256[] memory weights) {
176+
function getGovernorWeights(address[] calldata governors) external view returns (uint96[] memory weights) {
178177
weights = _getGovernorWeights(governors);
179178
}
180179

181180
/**
182181
* @inheritdoc IBridgeManager
183182
*/
184-
function getGovernorWeight(address governor) external view returns (uint256 weight) {
183+
function getGovernorWeight(address governor) external view returns (uint96 weight) {
185184
weight = _getGovernorWeight(governor);
186185
}
187186

@@ -197,7 +196,7 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
197196
/**
198197
* @inheritdoc IBridgeManager
199198
*/
200-
function totalBridgeOperators() external view returns (uint256) {
199+
function totalBridgeOperator() external view returns (uint256) {
201200
return _getBridgeOperatorSet().length();
202201
}
203202

@@ -260,7 +259,7 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
260259
function getFullBridgeOperatorInfos()
261260
external
262261
view
263-
returns (address[] memory governors, address[] memory bridgeOperators, uint256[] memory weights)
262+
returns (address[] memory governors, address[] memory bridgeOperators, uint96[] memory weights)
264263
{
265264
governors = _getGovernors();
266265
bridgeOperators = getBridgeOperatorOf(governors);
@@ -270,7 +269,7 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
270269
/**
271270
* @inheritdoc IBridgeManager
272271
*/
273-
function getBridgeOperatorWeight(address bridgeOperator) external view returns (uint256 weight) {
272+
function getBridgeOperatorWeight(address bridgeOperator) external view returns (uint96 weight) {
274273
mapping(address => address) storage _governorOf = _getGovernorOf();
275274
mapping(address => BridgeOperatorInfo) storage _governorToBridgeOperatorInfo = _getGovernorToBridgeOperatorInfo();
276275
weight = _governorToBridgeOperatorInfo[_governorOf[bridgeOperator]].voteWeight;
@@ -467,9 +466,9 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
467466
* @param governors An array containing the addresses of governors.
468467
* @return weights An array containing the vote weights of the corresponding governors.
469468
*/
470-
function _getGovernorWeights(address[] memory governors) internal view returns (uint256[] memory weights) {
469+
function _getGovernorWeights(address[] memory governors) internal view returns (uint96[] memory weights) {
471470
uint256 length = governors.length;
472-
weights = new uint256[](length);
471+
weights = new uint96[](length);
473472
mapping(address => BridgeOperatorInfo) storage _governorToBridgeOperatorInfo = _getGovernorToBridgeOperatorInfo();
474473
for (uint256 i; i < length; ) {
475474
weights[i] = _governorToBridgeOperatorInfo[governors[i]].voteWeight;
@@ -486,10 +485,9 @@ abstract contract BridgeManager is IQuorum, IBridgeManager, BridgeManagerCallbac
486485
* @notice The input array `governors` must contain unique addresses to avoid duplicate calculations.
487486
*/
488487
function _sumGovernorsWeight(address[] memory governors) internal view nonDuplicate(governors) returns (uint256 sum) {
489-
uint256 length = _getBridgeOperatorSet().length();
490488
mapping(address => BridgeOperatorInfo) storage _governorToBridgeOperatorInfo = _getGovernorToBridgeOperatorInfo();
491489

492-
for (uint256 i; i < length; ) {
490+
for (uint256 i; i < governors.length; ) {
493491
sum += _governorToBridgeOperatorInfo[governors[i]].voteWeight;
494492

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

contracts/extensions/bridge-operator-governance/BridgeManagerCallbackRegister.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
44
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
55
import { IBridgeManagerCallbackRegister } from "../../interfaces/bridge/IBridgeManagerCallbackRegister.sol";
66
import { IBridgeManagerCallback } from "../../interfaces/bridge/IBridgeManagerCallback.sol";
7-
import { IdentityGuard } from "../../utils/IdentityGuard.sol";
7+
import { TransparentUpgradeableProxyV2, IdentityGuard } from "../../utils/IdentityGuard.sol";
88

99
/**
1010
* @title BridgeManagerCallbackRegister
@@ -107,19 +107,23 @@ abstract contract BridgeManagerCallbackRegister is IdentityGuard, IBridgeManager
107107
uint256 length = registers.length;
108108
if (length == 0) return;
109109

110-
bool[] memory statuses = new bool[](length);
110+
bool[] memory successes = new bool[](length);
111111
bytes[] memory returnDatas = new bytes[](length);
112112
bytes memory callData = abi.encodePacked(callbackFnSig, inputs);
113+
bytes memory proxyCallData = abi.encodeCall(TransparentUpgradeableProxyV2.functionDelegateCall, (callData));
113114

114115
for (uint256 i; i < length; ) {
115-
(statuses[i], returnDatas[i]) = registers[i].call(callData);
116+
(successes[i], returnDatas[i]) = registers[i].call(callData);
117+
if (!successes[i]) {
118+
(successes[i], returnDatas[i]) = registers[i].call(proxyCallData);
119+
}
116120

117121
unchecked {
118122
++i;
119123
}
120124
}
121125

122-
emit Notified(callData, registers, statuses, returnDatas);
126+
emit Notified(callData, registers, successes, returnDatas);
123127
}
124128

125129
/**

contracts/extensions/collections/HasProxyAdmin.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import "../../utils/CommonErrors.sol";
66

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

1111
modifier onlyAdmin() {
1212
_requireAdmin();
@@ -16,7 +16,7 @@ abstract contract HasProxyAdmin {
1616
/**
1717
* @dev Returns proxy admin.
1818
*/
19-
function _getAdmin() internal view returns (address) {
19+
function _getAdmin() internal view virtual returns (address) {
2020
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
2121
}
2222

contracts/extensions/sequential-governance/CoreGovernance.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ abstract contract CoreGovernance is SignatureConsumer, VoteStatusConsumer, Chain
293293
/**
294294
* @dev Returns total weight from validators.
295295
*/
296-
function _getTotalWeights() internal view virtual returns (uint256);
296+
function _getTotalWeight() internal view virtual returns (uint256);
297297

298298
/**
299299
* @dev Returns minimum vote to pass a proposal.

contracts/extensions/sequential-governance/governance-proposal/CommonGovernanceProposal.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract contract CommonGovernanceProposal is CoreGovernance {
2929
if (!(_supports.length != 0 && _supports.length == _signatures.length)) revert ErrLengthMismatch(msg.sig);
3030

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

3434
address _lastSigner;
3535
address _signer;

contracts/extensions/sequential-governance/governance-proposal/GovernanceProposal.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ abstract contract GovernanceProposal is CoreGovernance, CommonGovernanceProposal
6767
revert ErrInvalidProposal(proposalHash, vote[_proposal.chainId][_proposal.nonce].hash);
6868

6969
uint256 _minimumForVoteWeight = _getMinimumVoteWeight();
70-
uint256 _minimumAgainstVoteWeight = _getTotalWeights() - _minimumForVoteWeight + 1;
70+
uint256 _minimumAgainstVoteWeight = _getTotalWeight() - _minimumForVoteWeight + 1;
7171
Signature memory _emptySignature;
7272
_castVote(
7373
_proposal,

contracts/extensions/sequential-governance/governance-relay/CommonGovernanceRelay.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ abstract contract CommonGovernanceRelay is CoreGovernance {
6161

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

73-
uint256 _minimumAgainstVoteWeight = _getTotalWeights() - _minimumForVoteWeight + 1;
74-
uint256 _totalAgainstVoteWeight = _sumWeights(_againstVoteSigners);
73+
uint256 _minimumAgainstVoteWeight = _getTotalWeight() - _minimumForVoteWeight + 1;
74+
uint256 _totalAgainstVoteWeight = _sumWeight(_againstVoteSigners);
7575
if (_totalAgainstVoteWeight >= _minimumAgainstVoteWeight) {
7676
if (_totalAgainstVoteWeight == 0) revert ErrInvalidVoteWeight(msg.sig);
7777
_vote.status = VoteStatus.Rejected;
@@ -85,5 +85,5 @@ abstract contract CommonGovernanceRelay is CoreGovernance {
8585
/**
8686
* @dev Returns the weight of the governor list.
8787
*/
88-
function _sumWeights(address[] memory _governors) internal view virtual returns (uint256);
88+
function _sumWeight(address[] memory _governors) internal view virtual returns (uint256);
8989
}

0 commit comments

Comments
 (0)