From 7d26410e5d99ddc86a393faffe3c32b9d577ad89 Mon Sep 17 00:00:00 2001 From: zkcarter Date: Fri, 26 Apr 2024 15:21:20 +0800 Subject: [PATCH 1/5] fix upgrade facets gas limit too big --- l1-contracts/upgrade-system/facets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l1-contracts/upgrade-system/facets.ts b/l1-contracts/upgrade-system/facets.ts index d6b554d78..3ad0f4d95 100644 --- a/l1-contracts/upgrade-system/facets.ts +++ b/l1-contracts/upgrade-system/facets.ts @@ -21,7 +21,7 @@ async function deployFacetCut( ) { create2Salt = create2Salt ?? ethers.constants.HashZero; - ethTxOptions["gasLimit"] = 10_000_000; + ethTxOptions["gasLimit"] = 3_000_000; const [address, txHash] = await deployViaCreate2(wallet, name, [], create2Salt, ethTxOptions, create2Address, true); console.log(`Deployed ${name} at ${address} with txHash ${txHash}`); From 659d93640f479e2c178b18f87329529e5bf14c49 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Mon, 6 May 2024 11:24:36 +0800 Subject: [PATCH 2/5] fix: abdk_audit_6_cvf_3 --- .../contracts/zksync/facets/Mailbox.sol | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/l1-contracts/contracts/zksync/facets/Mailbox.sol b/l1-contracts/contracts/zksync/facets/Mailbox.sol index 4041692d9..78f9fa23e 100644 --- a/l1-contracts/contracts/zksync/facets/Mailbox.sol +++ b/l1-contracts/contracts/zksync/facets/Mailbox.sol @@ -240,30 +240,28 @@ contract MailboxFacet is Base, IMailbox { uint256 gatewayLength = _secondaryChainGateways.length; bytes[] memory gatewayDataList = new bytes[](gatewayLength); uint256 totalForwardEthAmount = 0; - unchecked { - for (uint256 i = 0; i < gatewayLength; ++i) { - // Secondary chain should be registered - address _secondaryChainGateway = _secondaryChainGateways[i]; - SecondaryChain memory secondaryChain = s.secondaryChains[_secondaryChainGateway]; - require(secondaryChain.valid, "bsc"); - uint256 _forwardEthAmount = s.secondaryChains[_secondaryChainGateway].totalPendingWithdraw; - // Withdraw eth amount impossible overflow - totalForwardEthAmount += _forwardEthAmount; - s.secondaryChains[_secondaryChainGateway].totalPendingWithdraw = 0; - // Send range batch root to secondary chain - bytes memory gatewayCallData = abi.encodeCall( - IZkLink.syncRangeBatchRoot, - (_fromBatchNumber, _toBatchNumber, rangeBatchRootHash, _forwardEthAmount) - ); - gatewayDataList[i] = abi.encode(_secondaryChainGateway, _forwardEthAmount, gatewayCallData); - emit SyncRangeBatchRoot( - _secondaryChainGateway, - _fromBatchNumber, - _toBatchNumber, - rangeBatchRootHash, - _forwardEthAmount - ); - } + for (uint256 i = 0; i < gatewayLength; i = i.uncheckedInc()) { + // Secondary chain should be registered + address _secondaryChainGateway = _secondaryChainGateways[i]; + SecondaryChain memory secondaryChain = s.secondaryChains[_secondaryChainGateway]; + require(secondaryChain.valid, "bsc"); + uint256 _forwardEthAmount = s.secondaryChains[_secondaryChainGateway].totalPendingWithdraw; + // Withdraw eth amount impossible overflow + totalForwardEthAmount += _forwardEthAmount; + s.secondaryChains[_secondaryChainGateway].totalPendingWithdraw = 0; + // Send range batch root to secondary chain + bytes memory gatewayCallData = abi.encodeCall( + IZkLink.syncRangeBatchRoot, + (_fromBatchNumber, _toBatchNumber, rangeBatchRootHash, _forwardEthAmount) + ); + gatewayDataList[i] = abi.encode(_secondaryChainGateway, _forwardEthAmount, gatewayCallData); + emit SyncRangeBatchRoot( + _secondaryChainGateway, + _fromBatchNumber, + _toBatchNumber, + rangeBatchRootHash, + _forwardEthAmount + ); } // Forward fee to gateway From 8d52ef8ae3c28af6a5a5f954eee89bc2028776f9 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Mon, 6 May 2024 14:19:31 +0800 Subject: [PATCH 3/5] fix: abdk_audit_6_cvf_5 --- l1-contracts/contracts/zksync/facets/Mailbox.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l1-contracts/contracts/zksync/facets/Mailbox.sol b/l1-contracts/contracts/zksync/facets/Mailbox.sol index 78f9fa23e..f6c16b231 100644 --- a/l1-contracts/contracts/zksync/facets/Mailbox.sol +++ b/l1-contracts/contracts/zksync/facets/Mailbox.sol @@ -245,7 +245,7 @@ contract MailboxFacet is Base, IMailbox { address _secondaryChainGateway = _secondaryChainGateways[i]; SecondaryChain memory secondaryChain = s.secondaryChains[_secondaryChainGateway]; require(secondaryChain.valid, "bsc"); - uint256 _forwardEthAmount = s.secondaryChains[_secondaryChainGateway].totalPendingWithdraw; + uint256 _forwardEthAmount = secondaryChain.totalPendingWithdraw; // Withdraw eth amount impossible overflow totalForwardEthAmount += _forwardEthAmount; s.secondaryChains[_secondaryChainGateway].totalPendingWithdraw = 0; From 17bba7a6a57004725a1fd9990771da5bb1fddd89 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Sun, 19 May 2024 16:06:13 +0800 Subject: [PATCH 4/5] feat: add replace tx script --- l1-contracts/package.json | 3 +- l1-contracts/scripts/replace-tx.ts | 52 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 l1-contracts/scripts/replace-tx.ts diff --git a/l1-contracts/package.json b/l1-contracts/package.json index 7f383136b..eaf9cfc12 100644 --- a/l1-contracts/package.json +++ b/l1-contracts/package.json @@ -84,7 +84,8 @@ "upgrade-system": "ts-node upgrade-system/index.ts", "set-gateway": "ts-node scripts/set-gateway.ts", "set-admin": "ts-node scripts/set-admin.ts", - "deploy-l1-erc20-bridge-imple": "ts-node scripts/deploy-l1-erc20-bridge-impl.ts" + "deploy-l1-erc20-bridge-imple": "ts-node scripts/deploy-l1-erc20-bridge-impl.ts", + "replace-tx": "ts-node scripts/replace-tx.ts" }, "dependencies": { "dotenv": "^16.0.3" diff --git a/l1-contracts/scripts/replace-tx.ts b/l1-contracts/scripts/replace-tx.ts new file mode 100644 index 000000000..db3a01401 --- /dev/null +++ b/l1-contracts/scripts/replace-tx.ts @@ -0,0 +1,52 @@ +import { Command } from "commander"; +import { Wallet } from "ethers"; +import { formatUnits } from "ethers/lib/utils"; +import { web3Provider } from "./utils"; + +const provider = web3Provider(); + +async function main() { + const program = new Command(); + + program.version("0.1.0").name("replace-tx").description("replace a tx"); + + program + .requiredOption("--private-key ") + .requiredOption("--to ") + .requiredOption("--value ") + .requiredOption("--data ") + .requiredOption("--nonce ") + .requiredOption("--gas-price ") + .requiredOption("--gas-limit ") + .action(async (cmd) => { + const deployWallet = new Wallet(cmd.privateKey, provider); + console.log(`Using deployer wallet: ${deployWallet.address}`); + + const nonce = cmd.nonce; + console.log(`Using nonce: ${nonce}`); + + const gasPrice = cmd.gasPrice; + console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`); + + const gasLimit = cmd.gasLimit; + console.log(`Using gas limit: ${gasLimit}`); + + await deployWallet.sendTransaction({ + to: cmd.to, + value: cmd.value, + data: cmd.data, + nonce, + gasPrice, + gasLimit, + }); + }); + + await program.parseAsync(process.argv); +} + +main() + .then(() => process.exit(0)) + .catch((err) => { + console.error("Error:", err); + process.exit(1); + }); From 3a96ec9c5ceae8cd5785a998851104cb275a0a43 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Wed, 19 Jun 2024 14:27:44 +0800 Subject: [PATCH 5/5] fix: abdk_audit_5_cvf_11 --- l2-contracts/contracts/bridge/interfaces/IMergeTokenPortal.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/l2-contracts/contracts/bridge/interfaces/IMergeTokenPortal.sol b/l2-contracts/contracts/bridge/interfaces/IMergeTokenPortal.sol index aa2894d8c..de09d2ca9 100644 --- a/l2-contracts/contracts/bridge/interfaces/IMergeTokenPortal.sol +++ b/l2-contracts/contracts/bridge/interfaces/IMergeTokenPortal.sol @@ -5,6 +5,7 @@ interface IMergeTokenPortal { /// @notice Source token info /// @param isSupported Is the source token supported /// @param isLocked Is the source token locked + /// @param mergeToken Deposit source token will receive the merge token /// @param balance Source token balance /// @param depositLimit Source token deposit limit struct SourceTokenInfo {