Skip to content

Commit

Permalink
feat: set-up pause enforcer
Browse files Browse the repository at this point in the history
  • Loading branch information
huyhuynh3103 committed Jan 25, 2024
1 parent 7e8dbae commit d34969d
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

- name: Run Forge tests
run: |
anvil --chain-id 2024 --port 8546 &
anvil --chain-id 2 --port 8547 &
anvil --chain-id 2024 --port 8546 --block-time 1 &
anvil --chain-id 2 --port 8547 --block-time 1 &
forge test -vvv
id: test
3 changes: 3 additions & 0 deletions script/GeneralConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ contract GeneralConfig is BaseGeneralConfig, Utils {
_contractNameMap[Contract.AXS.key()] = "MockERC20";
_contractNameMap[Contract.SLP.key()] = "MockERC20";
_contractNameMap[Contract.USDC.key()] = "MockERC20";

_contractNameMap[Contract.RoninPauseEnforcer.key()] = "PauseEnforcer";
_contractNameMap[Contract.MainchainPauseEnforcer.key()] = "PauseEnforcer";
}

function _mapContractName(Contract contractEnum) internal {
Expand Down
97 changes: 54 additions & 43 deletions script/Migration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,57 @@ contract Migration is BaseMigrationV2, Utils {

function _sharedArguments() internal virtual override returns (bytes memory rawArgs) {
ISharedArgument.SharedParameter memory param;
param.test.numberOfBlocksInEpoch = 600;
param.test.proxyAdmin = makeAddr("proxy-admin");
param.test.dposGA = makeAddr("governance-admin");
param.test.mainchainChainId = Network.EthLocal.chainId();
param.test.roninChainId = Network.RoninLocal.chainId();

// tokens
param.weth.name = "Wrapped WETH";
param.weth.symbol = "WETH";
param.wron.name = "Wrapped RON";
param.wron.symbol = "WRON";
param.axs.name = "Axie Infinity Shard";
param.axs.symbol = "AXS";
param.slp.name = "Smooth Love Potion";
param.slp.symbol = "SLP";
param.usdc.name = "USD Coin";
param.usdc.symbol = "USDC";

uint256 num = 6;
address[] memory operatorAddrs = new address[](num);
address[] memory governorAddrs = new address[](num);
uint256[] memory operatorPKs = new uint256[](num);
uint256[] memory governorPKs = new uint256[](num);
uint96[] memory voteWeights = new uint96[](num);
GlobalProposal.TargetOption[] memory options = new GlobalProposal.TargetOption[](0);
address[] memory targets = new address[](0);

for (uint256 i; i < num; i++) {
(address addrOperator, uint256 pkOperator) = makeAddrAndKey(string.concat("operator-", vm.toString(i + 1)));
(address addrGovernor, uint256 pkGovernor) = makeAddrAndKey(string.concat("governor-", vm.toString(i + 1)));

operatorAddrs[i] = addrOperator;
governorAddrs[i] = addrGovernor;
operatorPKs[i] = pkOperator;
governorPKs[i] = pkGovernor;
voteWeights[i] = 100;
}

LibArray.inlineSortByValue(operatorPKs, LibArray.toUint256s(operatorAddrs));
LibArray.inlineSortByValue(governorPKs, LibArray.toUint256s(governorAddrs));

param.test.operatorPKs = operatorPKs;
param.test.governorPKs = governorPKs;

if (network() == Network.Goerli.key()) {
// Undefined
} else if (network() == DefaultNetwork.RoninTestnet.key()) {
// Undefined
} else if (network() == Network.RoninLocal.key() || network() == Network.EthLocal.key()) {
// test
param.test.numberOfBlocksInEpoch = 600;
param.test.proxyAdmin = makeAddr("proxy-admin");
param.test.dposGA = makeAddr("governance-admin");
param.test.mainchainChainId = Network.EthLocal.chainId();
param.test.roninChainId = Network.RoninLocal.chainId();

// tokens
param.weth.name = "Wrapped WETH";
param.weth.symbol = "WETH";
param.wron.name = "Wrapped RON";
param.wron.symbol = "WRON";
param.axs.name = "Axie Infinity Shard";
param.axs.symbol = "AXS";
param.slp.name = "Smooth Love Potion";
param.slp.symbol = "SLP";
param.usdc.name = "USD Coin";
param.usdc.symbol = "USDC";

uint256 num = 6;
address[] memory operatorAddrs = new address[](num);
address[] memory governorAddrs = new address[](num);
uint256[] memory operatorPKs = new uint256[](num);
uint256[] memory governorPKs = new uint256[](num);
uint96[] memory voteWeights = new uint96[](num);
GlobalProposal.TargetOption[] memory options = new GlobalProposal.TargetOption[](0);
address[] memory targets = new address[](0);

for (uint256 i; i < num; i++) {
(address addrOperator, uint256 pkOperator) = makeAddrAndKey(string.concat("operator-", vm.toString(i + 1)));
(address addrGovernor, uint256 pkGovernor) = makeAddrAndKey(string.concat("governor-", vm.toString(i + 1)));

operatorAddrs[i] = addrOperator;
governorAddrs[i] = addrGovernor;
operatorPKs[i] = pkOperator;
governorPKs[i] = pkGovernor;
voteWeights[i] = 100;
}

LibArray.inlineSortByValue(operatorPKs, LibArray.toUint256s(operatorAddrs));
LibArray.inlineSortByValue(governorPKs, LibArray.toUint256s(governorAddrs));

param.test.operatorPKs = operatorPKs;
param.test.governorPKs = governorPKs;

// Bridge rewards
param.bridgeReward.dposGA = param.test.dposGA;
param.bridgeReward.rewardPerPeriod = 5_000;
Expand All @@ -79,6 +81,10 @@ contract Migration is BaseMigrationV2, Utils {

// Bridge Tracking

// Ronin Gateway Pause Enforcer
param.roninPauseEnforcer.admin = makeAddr("pause-enforcer-admin");
param.roninPauseEnforcer.sentries = wrapAddress(makeAddr("pause-enforcer-sentry"));

// Ronin Gateway V3
param.roninGatewayV3.numerator = 3;
param.roninGatewayV3.denominator = 6;
Expand All @@ -96,6 +102,11 @@ contract Migration is BaseMigrationV2, Utils {
param.roninBridgeManager.voteWeights = voteWeights;
param.roninBridgeManager.targetOptions = options;
param.roninBridgeManager.targets = targets;

// Mainchain Gateway Pause Enforcer
param.mainchainPauseEnforcer.admin = makeAddr("pause-enforcer-admin");
param.mainchainPauseEnforcer.sentries = wrapAddress(makeAddr("pause-enforcer-sentry"));

// Mainchain Gateway V3
param.mainchainGatewayV3.roninChainId = param.test.roninChainId;
param.mainchainGatewayV3.numerator = 1;
Expand Down
1 change: 0 additions & 1 deletion script/contracts/MainchainGatewayV3Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.19;

import { MainchainGatewayV3 } from "@ronin/contracts/mainchain/MainchainGatewayV3.sol";
import { IWETH } from "src/interfaces/IWETH.sol";
import { Contract } from "../utils/Contract.sol";
import { ISharedArgument } from "../interfaces/ISharedArgument.sol";
import { Migration } from "../Migration.s.sol";
Expand Down
13 changes: 13 additions & 0 deletions script/contracts/MainchainPauseEnforcerDeploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { PauseEnforcer } from "@ronin/contracts/ronin/gateway/PauseEnforcer.sol";
import { Contract } from "../utils/Contract.sol";
import { ISharedArgument } from "../interfaces/ISharedArgument.sol";
import { Migration } from "../Migration.s.sol";

contract MainchainPauseEnforcerDeploy is Migration {
function run() public virtual returns (PauseEnforcer) {
return PauseEnforcer(_deployProxy(Contract.MainchainPauseEnforcer.key(), EMPTY_ARGS));
}
}
13 changes: 13 additions & 0 deletions script/contracts/RoninPauseEnforcerDeploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { PauseEnforcer } from "@ronin/contracts/ronin/gateway/PauseEnforcer.sol";
import { Contract } from "../utils/Contract.sol";
import { ISharedArgument } from "../interfaces/ISharedArgument.sol";
import { Migration } from "../Migration.s.sol";

contract RoninPauseEnforcerDeploy is Migration {
function run() public virtual returns (PauseEnforcer) {
return PauseEnforcer(_deployProxy(Contract.RoninPauseEnforcer.key(), EMPTY_ARGS));
}
}
11 changes: 11 additions & 0 deletions script/interfaces/ISharedArgument.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ interface ISharedArgument is IGeneralConfig {
uint256 rewardPerPeriod;
}

struct PauseEnforcerParam {
address target;
address admin;
address[] sentries;
}

struct MockWrappedTokenParam {
string name;
string symbol;
Expand All @@ -98,13 +104,18 @@ interface ISharedArgument is IGeneralConfig {
}

struct SharedParameter {
// mainchain
BridgeManagerParam mainchainBridgeManager;
MainchainGatewayV3Param mainchainGatewayV3;
PauseEnforcerParam mainchainPauseEnforcer;
// ronin
BridgeManagerParam roninBridgeManager;
RoninGatewayV3Param roninGatewayV3;
PauseEnforcerParam roninPauseEnforcer;
BridgeSlashParam bridgeSlash;
BridgeTrackingParam bridgeTracking;
BridgeRewardParam bridgeReward;
// tokens
MockWrappedTokenParam weth;
MockWrappedTokenParam wron;
MockERC20Param axs;
Expand Down
5 changes: 5 additions & 0 deletions script/utils/Contract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ enum Contract {
BridgeTracking,
BridgeSlash,
BridgeReward,
RoninPauseEnforcer,
RoninGatewayV3,
RoninBridgeManager,
MainchainPauseEnforcer,
MainchainGatewayV3,
MainchainBridgeManager
}
Expand All @@ -34,8 +36,11 @@ function name(Contract contractEnum) pure returns (string memory) {
if (contractEnum == Contract.BridgeTracking) return "BridgeTracking";
if (contractEnum == Contract.BridgeSlash) return "BridgeSlash";
if (contractEnum == Contract.BridgeReward) return "BridgeReward";
if (contractEnum == Contract.RoninPauseEnforcer) return "PauseEnforcer";
if (contractEnum == Contract.RoninGatewayV3) return "RoninGatewayV3";
if (contractEnum == Contract.RoninBridgeManager) return "RoninBridgeManager";

if (contractEnum == Contract.MainchainPauseEnforcer) return "PauseEnforcer";
if (contractEnum == Contract.MainchainGatewayV3) return "MainchainGatewayV3";
if (contractEnum == Contract.MainchainBridgeManager) return "MainchainBridgeManager";

Expand Down
63 changes: 63 additions & 0 deletions test/bridge/integration/BaseIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ import { ContractType } from "@ronin/contracts/utils/ContractType.sol";
import { TransparentUpgradeableProxyV2 } from "@ronin/contracts/extensions/TransparentUpgradeableProxyV2.sol";
import { MockValidatorContract_OnlyTiming_ForHardhatTest } from
"@ronin/contracts/mocks/ronin/MockValidatorContract_OnlyTiming_ForHardhatTest.sol";
import { PauseEnforcer } from "@ronin/contracts/ronin/gateway/PauseEnforcer.sol";
import { IPauseTarget } from "@ronin/contracts/interfaces/IPauseTarget.sol";
import { GatewayV3 } from "@ronin/contracts/extensions/GatewayV3.sol";

import { RoninBridgeManagerDeploy } from "@ronin/script/contracts/RoninBridgeManagerDeploy.s.sol";
import { RoninGatewayV3Deploy } from "@ronin/script/contracts/RoninGatewayV3Deploy.s.sol";
import { BridgeTrackingDeploy } from "@ronin/script/contracts/BridgeTrackingDeploy.s.sol";
import { BridgeSlashDeploy } from "@ronin/script/contracts/BridgeSlashDeploy.s.sol";
import { BridgeRewardDeploy } from "@ronin/script/contracts/BridgeRewardDeploy.s.sol";
import { RoninPauseEnforcerDeploy } from "@ronin/script/contracts/RoninPauseEnforcerDeploy.s.sol";

import { MainchainGatewayV3Deploy } from "@ronin/script/contracts/MainchainGatewayV3Deploy.s.sol";
import { MainchainBridgeManagerDeploy } from "@ronin/script/contracts/MainchainBridgeManagerDeploy.s.sol";
import { MainchainPauseEnforcerDeploy } from "@ronin/script/contracts/MainchainPauseEnforcerDeploy.s.sol";
import { WETHDeploy } from "@ronin/script/contracts/token/WETHDeploy.s.sol";
import { WRONDeploy } from "@ronin/script/contracts/token/WRONDeploy.s.sol";
import { AXSDeploy } from "@ronin/script/contracts/token/AXSDeploy.s.sol";
Expand All @@ -50,11 +56,14 @@ contract BaseIntegration_Test is Base_Test {
IGeneralConfig _config;
ISharedArgument.SharedParameter _param;

PauseEnforcer _roninPauseEnforcer;
RoninBridgeManager _roninBridgeManager;
RoninGatewayV3 _roninGatewayV3;
BridgeTracking _bridgeTracking;
BridgeSlash _bridgeSlash;
BridgeReward _bridgeReward;

PauseEnforcer _mainchainPauseEnforcer;
MainchainGatewayV3 _mainchainGatewayV3;
MainchainBridgeManager _mainchainBridgeManager;

Expand Down Expand Up @@ -89,6 +98,9 @@ contract BaseIntegration_Test is Base_Test {

_changeAdminOnRonin();
_changeAdminOnMainchain();

_configEmergencyPauserForRoninGateway();
_configEmergencyPauserForMainchainGateway();
}

function _deployContractsOnRonin() internal {
Expand All @@ -99,6 +111,7 @@ contract BaseIntegration_Test is Base_Test {
_bridgeTracking = new BridgeTrackingDeploy().run();
_bridgeSlash = new BridgeSlashDeploy().run();
_bridgeReward = new BridgeRewardDeploy().run();
_roninPauseEnforcer = new RoninPauseEnforcerDeploy().run();
_roninBridgeManager = new RoninBridgeManagerDeploy().run();

_roninWeth = new WETHDeploy().run();
Expand All @@ -118,6 +131,7 @@ contract BaseIntegration_Test is Base_Test {
_config.createFork(Network.EthLocal.key());
_config.switchTo(Network.EthLocal.key());

_mainchainPauseEnforcer = new MainchainPauseEnforcerDeploy().run();
_mainchainGatewayV3 = new MainchainGatewayV3Deploy().run();
_mainchainBridgeManager = new MainchainBridgeManagerDeploy().run();

Expand All @@ -137,13 +151,15 @@ contract BaseIntegration_Test is Base_Test {
_bridgeRewardInitialize();
_bridgeTrackingInitialize();
_bridgeSlashInitialize();
_roninPauseEnforcerInitialize();
_roninGatewayV3Initialize();
_constructForRoninBridgeManager();
}

function _initializeMainchain() internal {
_config.switchTo(Network.EthLocal.key());

_mainchainPauseEnforcerInitialize();
_constructForMainchainBridgeManager();
_mainchainGatewayV3Initialize();
}
Expand Down Expand Up @@ -225,6 +241,14 @@ contract BaseIntegration_Test is Base_Test {
_bridgeSlash.initializeREP2();
}

function _roninPauseEnforcerInitialize() internal {
_param.roninPauseEnforcer.target = address(_roninGatewayV3);

ISharedArgument.PauseEnforcerParam memory param = _param.roninPauseEnforcer;

_roninPauseEnforcer.initialize(IPauseTarget(param.target), param.admin, param.sentries);
}

function _roninGatewayV3Initialize() internal {
(address[] memory mainchainTokens, address[] memory roninTokens) = _getMainchainAndRoninTokens();
uint256 tokenNum = mainchainTokens.length;
Expand Down Expand Up @@ -426,6 +450,14 @@ contract BaseIntegration_Test is Base_Test {
_mainchainGatewayV3.initializeV2(address(_mainchainBridgeManager));
}

function _mainchainPauseEnforcerInitialize() internal {
_param.mainchainPauseEnforcer.target = address(_mainchainGatewayV3);

ISharedArgument.PauseEnforcerParam memory param = _param.mainchainPauseEnforcer;

_mainchainPauseEnforcer.initialize(IPauseTarget(param.target), param.admin, param.sentries);
}

function _changeAdminOnRonin() internal {
_config.switchTo(Network.RoninLocal.key());

Expand All @@ -445,6 +477,37 @@ contract BaseIntegration_Test is Base_Test {
vm.stopPrank();
}

function _configEmergencyPauserForRoninGateway() internal {
_config.switchTo(Network.RoninLocal.key());

bytes memory calldata_ = abi.encodeCall(GatewayV3.setEmergencyPauser, (address(_roninPauseEnforcer)));
_roninProposalUtils.functionDelegateCall(address(_roninGatewayV3), calldata_);
}

function _configEmergencyPauserForMainchainGateway() internal {
_config.switchTo(Network.EthLocal.key());

bytes memory calldata_ = abi.encodeCall(GatewayV3.setEmergencyPauser, (address(_mainchainPauseEnforcer)));
Proposal.ProposalDetail memory proposal = _mainchainProposalUtils.createProposal({
expiryTimestamp: block.timestamp + 1 minutes,
target: address(_mainchainGatewayV3),
value: 0,
calldata_: calldata_,
gasAmount: 1_000_000,
nonce: _mainchainBridgeManager.round(_param.test.mainchainChainId) + 1
});

SignatureConsumer.Signature[] memory signatures = _mainchainProposalUtils.generateSignatures(proposal);

Ballot.VoteType[] memory voteTypes = new Ballot.VoteType[](signatures.length);
for (uint256 i; i < signatures.length; i++) {
voteTypes[i] = Ballot.VoteType.For;
}

vm.prank(_param.mainchainBridgeManager.governors[0]);
_mainchainBridgeManager.relayProposal(proposal, voteTypes, signatures);
}

function _deployGeneralConfig() internal {
vm.makePersistent(LibSharedAddress.CONFIG);
vm.allowCheatcodes(LibSharedAddress.CONFIG);
Expand Down

0 comments on commit d34969d

Please sign in to comment.