Skip to content

Commit

Permalink
script: fix post check
Browse files Browse the repository at this point in the history
  • Loading branch information
TuDo1403 committed Aug 25, 2024
1 parent 5b64d3b commit 49cf228
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 37 deletions.
2 changes: 1 addition & 1 deletion script/GeneralConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ contract GeneralConfig is BaseGeneralConfig, Utils {
_mapContractName(Contract.RoninBridgeManagerConstructor);
_mapContractName(Contract.WBTC);
_mapContractName(Contract.PostChecker);
_mapContractName(Contract.WETH);

_contractNameMap[Contract.AXS.key()] = "MockERC20";
_contractNameMap[Contract.SLP.key()] = "MockSLP";
Expand All @@ -68,7 +69,6 @@ contract GeneralConfig is BaseGeneralConfig, Utils {
_contractNameMap[Contract.MainchainPauseEnforcer.key()] = "PauseEnforcer";

_contractAddrMap[Network.Goerli.key()][Contract.WETH.name()] = 0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6;
_contractAddrMap[Network.Sepolia.key()][Contract.WETH.name()] = 0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9;
_contractAddrMap[Network.EthMainnet.key()][Contract.WETH.name()] = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

_contractAddrMap[DefaultNetwork.RoninTestnet.key()][Contract.AXS.name()] = 0x0eD7e52944161450477ee417DE9Cd3a859b14fD0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ abstract contract PostCheck_Gateway_DepositAndWithdraw is BasePostCheck {
withdrawReq.tokenAddr = address(ronWETH);
withdrawReq.info.erc = TokenStandard.ERC20;
withdrawReq.info.id = 0;
withdrawReq.info.quantity = 100 ether;
withdrawReq.info.quantity = 1 ether;

deal(address(ronWETH), user, withdrawReq.info.quantity);
vm.prank(user);
Expand Down Expand Up @@ -195,7 +195,7 @@ abstract contract PostCheck_Gateway_DepositAndWithdraw is BasePostCheck {
withdrawReq.tokenAddr = address(ronERC20);
withdrawReq.info.erc = TokenStandard.ERC20;
withdrawReq.info.id = 0;
withdrawReq.info.quantity = 100 ether;
withdrawReq.info.quantity = 1 ether;

vm.prank(user);
ronERC20.approve(ronGW, withdrawReq.info.quantity);
Expand All @@ -219,15 +219,14 @@ abstract contract PostCheck_Gateway_DepositAndWithdraw is BasePostCheck {
// Sign first to get renounced operator signatures
Signature[] memory sigs = _bulkSignReceipt(mockOps, receiptDigest);

// Renounce operators
vm.prank(address(ethBM));
ITransparentUpgradeableProxyV2(ethBM).functionDelegateCall(
abi.encodeCall(IBridgeManager.removeBridgeOperators, (mockOps.slice(unmetSigCount, mockOps.length)))
);
// Cache to be renounced operators
address[] memory gvsToRemove = mockOps.slice(unmetSigCount, mockOps.length);

uint256 reAddOpCount = mockOps.length - unmetSigCount;

mockOps = mockOps.slice(0, unmetSigCount);
mockGvs = mockGvs.slice(0, unmetSigCount);

uint256 reAddOpCount = mockOps.length - unmetSigCount;
address[] memory newOps = new address[](reAddOpCount);
address[] memory newGvs = new address[](reAddOpCount);
uint96[] memory newVWs = new uint96[](reAddOpCount);
Expand All @@ -251,13 +250,13 @@ abstract contract PostCheck_Gateway_DepositAndWithdraw is BasePostCheck {
vm.prank(address(ethBM));
ITransparentUpgradeableProxyV2(ethBM).functionDelegateCall(abi.encodeCall(IBridgeManager.addBridgeOperators, (newVWs, newGvs, newOps)));

// Renounce operators
vm.prank(address(ethBM));
ITransparentUpgradeableProxyV2(ethBM).functionDelegateCall(abi.encodeCall(IBridgeManager.removeBridgeOperators, (gvsToRemove)));

vm.expectRevert();
IMainchainGatewayV3(ethGW).submitWithdrawal(receipt, sigs);

Signature[] memory newSig = _bulkSignReceipt(newOps[0].toSingletonArray(), receiptDigest);

IMainchainGatewayV3(ethGW).submitWithdrawal(receipt, _concat(sigs, newSig));

switchBack(prevNetwork, prevForkId);
}

Expand All @@ -270,7 +269,7 @@ abstract contract PostCheck_Gateway_DepositAndWithdraw is BasePostCheck {
depositReq.tokenAddr = address(0x0);
depositReq.info.erc = TokenStandard.ERC20;
depositReq.info.id = 0;
depositReq.info.quantity = 100 ether;
depositReq.info.quantity = 1 ether;

(TNetwork prevNetwork, uint256 prevForkId) = switchTo(companionNetwork);

Expand All @@ -287,7 +286,7 @@ abstract contract PostCheck_Gateway_DepositAndWithdraw is BasePostCheck {
depositReq.tokenAddr = address(ethWETH);
depositReq.info.erc = TokenStandard.ERC20;
depositReq.info.id = 0;
depositReq.info.quantity = 100 ether;
depositReq.info.quantity = 1 ether;

(TNetwork prevNetwork, uint256 prevForkId) = switchTo(companionNetwork);

Expand Down Expand Up @@ -328,7 +327,7 @@ abstract contract PostCheck_Gateway_DepositAndWithdraw is BasePostCheck {
depositReq.tokenAddr = address(0x0);
depositReq.info.erc = TokenStandard.ERC20;
depositReq.info.id = 0;
depositReq.info.quantity = 100 ether;
depositReq.info.quantity = 1 ether;

(TNetwork prevNetwork, uint256 prevForkId) = switchTo(companionNetwork);

Expand Down Expand Up @@ -377,7 +376,7 @@ abstract contract PostCheck_Gateway_DepositAndWithdraw is BasePostCheck {
withdrawReq.tokenAddr = address(ronERC20);
withdrawReq.info.erc = TokenStandard.ERC20;
withdrawReq.info.id = 0;
withdrawReq.info.quantity = 100 ether;
withdrawReq.info.quantity = 1 ether;

vm.prank(user);
ronERC20.approve(ronGW, withdrawReq.info.quantity);
Expand Down Expand Up @@ -416,7 +415,7 @@ abstract contract PostCheck_Gateway_DepositAndWithdraw is BasePostCheck {
withdrawReq.tokenAddr = address(ronERC20);
withdrawReq.info.erc = TokenStandard.ERC20;
withdrawReq.info.id = 0;
withdrawReq.info.quantity = 100 ether;
withdrawReq.info.quantity = 1 ether;

vm.prank(user);
ronERC20.approve(ronGW, withdrawReq.info.quantity);
Expand Down Expand Up @@ -466,7 +465,7 @@ abstract contract PostCheck_Gateway_DepositAndWithdraw is BasePostCheck {
depositReq.tokenAddr = address(ethERC20);
depositReq.info.erc = TokenStandard.ERC20;
depositReq.info.id = 0;
depositReq.info.quantity = 100 ether;
depositReq.info.quantity = 1 ether;

(TNetwork prevNetwork, uint256 prevForkId) = switchTo(companionNetwork);

Expand Down Expand Up @@ -503,7 +502,7 @@ abstract contract PostCheck_Gateway_DepositAndWithdraw is BasePostCheck {
depositReq.tokenAddr = address(ethERC20);
depositReq.info.erc = TokenStandard.ERC20;
depositReq.info.id = 0;
depositReq.info.quantity = 100 ether;
depositReq.info.quantity = 1 ether;

(TNetwork prevNetwork, uint256 prevForkId) = switchTo(companionNetwork);

Expand Down Expand Up @@ -543,7 +542,7 @@ abstract contract PostCheck_Gateway_DepositAndWithdraw is BasePostCheck {
withdrawReq.tokenAddr = address(ronERC20);
withdrawReq.info.erc = TokenStandard.ERC20;
withdrawReq.info.id = 0;
withdrawReq.info.quantity = 100 ether;
withdrawReq.info.quantity = 1 ether;

vm.prank(user);
ronERC20.approve(ronGW, withdrawReq.info.quantity);
Expand Down Expand Up @@ -579,7 +578,7 @@ abstract contract PostCheck_Gateway_DepositAndWithdraw is BasePostCheck {
withdrawReq.tokenAddr = address(ronERC20);
withdrawReq.info.erc = TokenStandard.ERC20;
withdrawReq.info.id = 0;
withdrawReq.info.quantity = 100 ether;
withdrawReq.info.quantity = 1 ether;

vm.prank(user);
ronERC20.approve(ronGW, withdrawReq.info.quantity);
Expand Down Expand Up @@ -617,7 +616,7 @@ abstract contract PostCheck_Gateway_DepositAndWithdraw is BasePostCheck {
withdrawReq.tokenAddr = address(ronERC20);
withdrawReq.info.erc = TokenStandard.ERC20;
withdrawReq.info.id = 0;
withdrawReq.info.quantity = 100 ether;
withdrawReq.info.quantity = 1 ether;

vm.prank(user);
ronERC20.approve(ronGW, withdrawReq.info.quantity);
Expand Down
13 changes: 0 additions & 13 deletions script/post-check/gateway/quorum/PostCheck_Gateway_Quorum.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ abstract contract PostCheck_Gateway_Quorum is BasePostCheck {
function _validate_Gateway_Quorum() internal {
// -------------- Gateway Quorum --------------
validate_NonZero_MinimumVoteWeight_Gateway();
validate_NonZero_TotalWeight_Gateway();
validate_Valid_Threshold_Gateway();
}

Expand All @@ -37,18 +36,6 @@ abstract contract PostCheck_Gateway_Quorum is BasePostCheck {
switchBack(prevNetwork, prevForkId);
}

function validate_NonZero_TotalWeight_Gateway() private onlyOnRoninNetworkOrLocal onPostCheck("validate_NonZero_TotalWeight_Gateway") {
assertTrue(IBridgeManager(ronGW).getTotalWeight() > 0, "Ronin: Gateway's Total weight must be greater than 0");
TNetwork currNetwork = network();

(, TNetwork companionNetwork) = currNetwork.companionNetworkData();
(TNetwork prevNetwork, uint256 prevForkId) = switchTo(companionNetwork);

assertTrue(IBridgeManager(ethGW).getTotalWeight() > 0, "Mainchain: Gateway's Total weight must be greater than 0");

switchBack(prevNetwork, prevForkId);
}

function validate_NonZero_MinimumVoteWeight_Gateway() private onlyOnRoninNetworkOrLocal onPostCheck("validate_NonZero_Threshold_Gateway") {
assertTrue(IQuorum(ronGW).minimumVoteWeight() > 0, "Ronin: Gateway's Minimum vote weight must be greater than 0");
TNetwork currNetwork = network();
Expand Down
32 changes: 31 additions & 1 deletion script/shared/libraries/LibProposal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ library LibProposal {
if (totalGas < DEFAULT_PROPOSAL_GAS) totalGas = DEFAULT_PROPOSAL_GAS * 120_00 / 100_00;

for (uint256 i = 1; i < governors.length; ++i) {
(VoteStatusConsumer.VoteStatus status,,,,) = bm.vote(block.chainid, proposal.nonce);
(VoteStatusConsumer.VoteStatus status,,,,) = bm.vote(proposal.chainId, proposal.nonce);
if (status != VoteStatusConsumer.VoteStatus.Pending) break;

address governor = governors[i];
Expand All @@ -155,6 +155,36 @@ library LibProposal {
}
}

function voteForBySignature(IRoninBridgeManager bm, Proposal.ProposalDetail memory proposal, Ballot.VoteType support) internal {
Ballot.VoteType[] memory supports_ = new Ballot.VoteType[](1);
supports_[0] = support;

address[] memory governors = bm.getGovernors();
bool shouldPrankOnly = vme.isPostChecking();

uint256 totalGas = proposal.gasAmounts.sum();
// 20% more gas for each governor
totalGas += totalGas * 20_00 / 100_00;
// if totalGas is less than DEFAULT_PROPOSAL_GAS, set it to 120% of DEFAULT_PROPOSAL_GAS
if (totalGas < DEFAULT_PROPOSAL_GAS) totalGas = DEFAULT_PROPOSAL_GAS * 120_00 / 100_00;

for (uint256 i = 1; i < governors.length; ++i) {
(VoteStatusConsumer.VoteStatus status,,,,) = bm.vote(proposal.chainId, proposal.nonce);
if (status != VoteStatusConsumer.VoteStatus.Pending) break;

address governor = governors[i];
SignatureConsumer.Signature[] memory sig = generateSignatures(proposal, governor.toSingletonArray(), support);

if (shouldPrankOnly) {
vm.prank(governor);
} else {
vm.prank(governor);
}

bm.castProposalBySignatures{ gas: totalGas }(proposal, supports_, sig);
}
}

function verifyGlobalProposalGasAmount(
uint256[] memory values,
bytes[] memory callDatas,
Expand Down

0 comments on commit 49cf228

Please sign in to comment.