Skip to content

Commit

Permalink
script: update post check
Browse files Browse the repository at this point in the history
  • Loading branch information
TuDo1403 committed Aug 23, 2024
1 parent 6c3dbb1 commit 0b43ab3
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity ^0.8.19;

contract Migration__20240409_GovernorsKey {
function _loadGovernorPKs() internal pure returns (uint256[] memory res) {
res = new uint256[](1);
function _loadGovernors() internal pure returns (address[] memory res) {
res = new address[](1);

res[0] = 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef;
res[0] = address(0xdeadbeef);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
pragma solidity ^0.8.19;

contract Migration__20240409_GovernorsKey {
function _loadGovernorPKs() internal pure returns (uint256[] memory res) {
res = new uint256[](4);
function _loadGovernors() internal pure returns (address[] memory res) {
res = new address[](4);

res[3] = 0xe3c1c8220c4ee4a6532d633296c3301db5397cff8a89a920da28f8bec97fcfb6;
res[2] = 0xeb80bc77e3164b6bb3eebf7d5f96f2496eb292fab563377f247d2db5887395e0;
res[0] = 0xed79936f720ac50b7c06138c6fd2d70abc19935de0fb347b0d782bdb6630e5a4;
res[1] = 0x3b3eb1d442ea0d728bc069f9d6d47ba8dcc6c867800cdf42a12117cf231bba59;
res[3] = 0xd24D87DDc1917165435b306aAC68D99e0F49A3Fa;
res[2] = 0xb033ba62EC622dC54D0ABFE0254e79692147CA26;
res[0] = 0x087D08e3ba42e64E3948962dd1371F906D1278b9;
res[1] = 0x52ec2e6BBcE45AfFF8955Da6410bb13812F4289F;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ contract Migration__20240409_P3_UpgradeBridgeMainchain is Migration, Migration__
supports_[i] = Ballot.VoteType.For;
}

Signature[] memory signatures = _generateSignaturesFor(getDomain(), hashLegacyProposal(proposal), _loadGovernorPKs(), Ballot.VoteType.For);
Signature[] memory signatures = _generateSignaturesFor(getDomain(), hashLegacyProposal(proposal), _loadGovernors(), Ballot.VoteType.For);

vm.broadcast(_governor);
(bool success,) = address(_currMainchainBridgeManager).call{ gas: (proposal.targets.length + 1) * 1_000_000 }(
Expand All @@ -213,19 +213,19 @@ contract Migration__20240409_P3_UpgradeBridgeMainchain is Migration, Migration__
function _generateSignaturesFor(
bytes32 domain,
bytes32 proposalHash,
uint256[] memory signerPKs,
address[] memory signers,
Ballot.VoteType support
) public pure returns (Signature[] memory sigs) {
sigs = new Signature[](signerPKs.length);
sigs = new Signature[](signers.length);

for (uint256 i; i < signerPKs.length; i++) {
for (uint256 i; i < signers.length; i++) {
bytes32 digest = ECDSA.toTypedDataHash(domain, Ballot.hash(proposalHash, support));
sigs[i] = _sign(signerPKs[i], digest);
sigs[i] = _sign(signers[i], digest);
}
}

function _sign(uint256 pk, bytes32 digest) internal pure returns (Signature memory sig) {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk, digest);
function _sign(address signer, bytes32 digest) internal pure returns (Signature memory sig) {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(signer, digest);
sig.v = v;
sig.r = r;
sig.s = s;
Expand Down
12 changes: 6 additions & 6 deletions script/20240619-upgrade-sepolia/20240619-operators-key.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
pragma solidity ^0.8.19;

contract Migration__20240619_GovernorsKey {
function _loadGovernorPKs() internal pure returns (uint256[] memory res) {
res = new uint256[](4);
function _loadGovernors() internal pure returns (address[] memory res) {
res = new address[](4);

res[0] = 0x00;
res[1] = 0x00;
res[2] = 0x00;
res[3] = 0x00;
res[0] = address(0x0);
res[1] = address(0x0);
res[2] = address(0x0);
res[3] = address(0x0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ contract Migration__20240619_P3_UpgradeBridgeMainchain is Migration, Migration__
governors[0] = 0x087D08e3ba42e64E3948962dd1371F906D1278b9;
governors[1] = 0x52ec2e6BBcE45AfFF8955Da6410bb13812F4289F;

_mainchainProposalUtils = new MainchainBridgeAdminUtils(2021, _loadGovernorPKs(), IMainchainBridgeManager(_mainchainBridgeManager), governors[0]);

Proposal.ProposalDetail memory proposal = Proposal.ProposalDetail({
nonce: IMainchainBridgeManager(_mainchainBridgeManager).round(block.chainid) + 1,
chainId: block.chainid,
Expand All @@ -93,16 +91,90 @@ contract Migration__20240619_P3_UpgradeBridgeMainchain is Migration, Migration__
gasAmounts: gasAmounts
});

LegacyProposalDetail memory legacyProposal;
legacyProposal.nonce = proposal.nonce;
legacyProposal.chainId = proposal.chainId;
legacyProposal.expiryTimestamp = proposal.expiryTimestamp;
legacyProposal.targets = proposal.targets;
legacyProposal.values = proposal.values;
legacyProposal.calldatas = proposal.calldatas;
legacyProposal.gasAmounts = proposal.gasAmounts;

Ballot.VoteType[] memory supports_ = new Ballot.VoteType[](4);
supports_[0] = Ballot.VoteType.For;
supports_[1] = Ballot.VoteType.For;
supports_[2] = Ballot.VoteType.For;
supports_[3] = Ballot.VoteType.For;

Signature[] memory signatures = _mainchainProposalUtils.generateSignatures(proposal, _loadGovernorPKs());
bytes32 proposalHash = hashLegacyProposal(legacyProposal);
Signature[] memory signatures = _generateSignaturesFor(getDomain(), proposalHash, _loadGovernors(), supports_[0]);

vm.broadcast(governors[0]);
// 2_000_000 to assure tx.gasleft is bigger than the gas of the proposal.
IMainchainBridgeManager(_mainchainBridgeManager).relayProposal{ gas: 2_000_000 }(proposal, supports_, signatures);
}

function getDomain() public pure returns (bytes32) {
return keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,bytes32 salt)"),
keccak256("BridgeAdmin"), // name hash
keccak256("2"), // version hash
keccak256(abi.encode("BRIDGE_ADMIN", 2021)) // salt
)
);
}

function hashLegacyProposal(LegacyProposalDetail memory proposal) public pure returns (bytes32 digest_) {
bytes32 TYPE_HASH = 0xd051578048e6ff0bbc9fca3b65a42088dbde10f36ca841de566711087ad9b08a;

uint256[] memory values = proposal.values;
address[] memory targets = proposal.targets;
bytes32[] memory calldataHashList = new bytes32[](proposal.calldatas.length);
uint256[] memory gasAmounts = proposal.gasAmounts;

for (uint256 i; i < calldataHashList.length; ++i) {
calldataHashList[i] = keccak256(proposal.calldatas[i]);
}

assembly {
let ptr := mload(0x40)
mstore(ptr, TYPE_HASH)
mstore(add(ptr, 0x20), mload(proposal)) // _proposal.nonce
mstore(add(ptr, 0x40), mload(add(proposal, 0x20))) // _proposal.chainId
mstore(add(ptr, 0x60), mload(add(proposal, 0x40))) // expiry timestamp

let arrayHashed
arrayHashed := keccak256(add(targets, 32), mul(mload(targets), 32)) // targetsHash
mstore(add(ptr, 0x80), arrayHashed)
arrayHashed := keccak256(add(values, 32), mul(mload(values), 32)) // _valuesHash
mstore(add(ptr, 0xa0), arrayHashed)
arrayHashed := keccak256(add(calldataHashList, 32), mul(mload(calldataHashList), 32)) // _calldatasHash
mstore(add(ptr, 0xc0), arrayHashed)
arrayHashed := keccak256(add(gasAmounts, 32), mul(mload(gasAmounts), 32)) // _gasAmountsHash
mstore(add(ptr, 0xe0), arrayHashed)
digest_ := keccak256(ptr, 0x100)
}
}

function _generateSignaturesFor(
bytes32 domain,
bytes32 proposalHash,
address[] memory signers,
Ballot.VoteType support
) public pure returns (Signature[] memory sigs) {
sigs = new Signature[](signers.length);

for (uint256 i; i < signers.length; i++) {
bytes32 digest = ECDSA.toTypedDataHash(domain, Ballot.hash(proposalHash, support));
sigs[i] = _sign(signers[i], digest);
}
}

function _sign(address signer, bytes32 digest) internal pure returns (Signature memory sig) {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(signer, digest);
sig.v = v;
sig.r = r;
sig.s = s;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity ^0.8.19;

contract Migration__20240716_GovernorsKey {
function _loadGovernorPKs() internal pure returns (uint256[] memory res) {
res = new uint256[](1);
function _loadGovernors() internal pure returns (address[] memory res) {
res = new address[](1);

res[0] = 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef;
res[0] = address(0xdeadbeef);
}
}
1 change: 1 addition & 0 deletions script/operations/PostCheckCI.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ contract PostCheckCI is Migration {
(, uint256 prevForkId) = switchTo(companionNetwork);
address payable ethBM = loadContract(Contract.MainchainBridgeManager.key());
address payable ethGW = loadContract(Contract.MainchainGatewayV3.key());

_cheatChangePAIfNotSelf(ethBM);
_cheatUnpauseIfPaused(ethGW);

Expand Down
4 changes: 3 additions & 1 deletion script/post-check/gateway/PostCheck_Gateway.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
pragma solidity ^0.8.19;

import { PostCheck_Gateway_DepositAndWithdraw } from "./deposit-withdraw/PostCheck_Gateway_DepositAndWithdraw.s.sol";
import { PostCheck_Gateway_Quorum } from "./quorum/PostCheck_Gateway_Quorum.s.sol";

abstract contract PostCheck_Gateway is PostCheck_Gateway_DepositAndWithdraw {
abstract contract PostCheck_Gateway is PostCheck_Gateway_DepositAndWithdraw, PostCheck_Gateway_Quorum {
function _validate_Gateway() internal onPostCheck("_validate_Gateway") {
_validate_Gateway_Quorum();
_validate_Gateway_DepositAndWithdraw();
}
}
Loading

0 comments on commit 0b43ab3

Please sign in to comment.