Skip to content

Commit

Permalink
fix(contracts): OZ-L2-M02 WETH9 Approval Can Be Front-Run (#632)
Browse files Browse the repository at this point in the history
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
  • Loading branch information
zimpha and HAOYUatHZ committed Jul 24, 2023
1 parent 0ce3b18 commit 0fc6d2a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 801 deletions.
2 changes: 1 addition & 1 deletion contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const config: HardhatUserConfig = {
"IL2ERC1155Gateway",
"IScrollStandardERC20Factory",
"IZKRollup",
"WETH9",
"WrappedEther",
],
},
};
Expand Down
4 changes: 2 additions & 2 deletions contracts/scripts/deploy_weth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ async function main() {

if (!addressFile.get("WETH")) {
console.log(">> Deploy WETH");
const WETH9 = await ethers.getContractFactory("WETH9", deployer);
const weth = await WETH9.deploy();
const WrappedEther = await ethers.getContractFactory("WrappedEther", deployer);
const weth = await WrappedEther.deploy();
console.log(`>> waiting for transaction: ${weth.deployTransaction.hash}`);
await weth.deployed();
console.log(`✅ WETH deployed at ${weth.address}`);
Expand Down
40 changes: 20 additions & 20 deletions contracts/scripts/foundry/DeployWeth.s.sol
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.10;

import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import {Script} from "forge-std/Script.sol";
import {console} from "forge-std/console.sol";

import { WETH9 } from "../../src/L2/predeploys/WETH9.sol";
import {WrappedEther} from "../../src/L2/predeploys/WrappedEther.sol";

contract DeployWeth is Script {
address L1_WETH_ADDR = vm.envAddress("L1_WETH_ADDR");
address L2_WETH_ADDR = vm.envAddress("L2_WETH_ADDR");
address L1_WETH_ADDR = vm.envAddress("L1_WETH_ADDR");
address L2_WETH_ADDR = vm.envAddress("L2_WETH_ADDR");

function run() external {
// deploy weth only if we're running a private L1 network
if (L1_WETH_ADDR == address(0)) {
uint256 L1_WETH_DEPLOYER_PRIVATE_KEY = vm.envUint("L1_WETH_DEPLOYER_PRIVATE_KEY");
vm.startBroadcast(L1_WETH_DEPLOYER_PRIVATE_KEY);
WETH9 weth = new WETH9();
L1_WETH_ADDR = address(weth);
vm.stopBroadcast();
}
function run() external {
// deploy weth only if we're running a private L1 network
if (L1_WETH_ADDR == address(0)) {
uint256 L1_WETH_DEPLOYER_PRIVATE_KEY = vm.envUint("L1_WETH_DEPLOYER_PRIVATE_KEY");
vm.startBroadcast(L1_WETH_DEPLOYER_PRIVATE_KEY);
WrappedEther weth = new WrappedEther();
L1_WETH_ADDR = address(weth);
vm.stopBroadcast();
}

logAddress("L1_WETH_ADDR", L1_WETH_ADDR);
logAddress("L2_WETH_ADDR", L2_WETH_ADDR);
}
logAddress("L1_WETH_ADDR", L1_WETH_ADDR);
logAddress("L2_WETH_ADDR", L2_WETH_ADDR);
}

function logAddress(string memory name, address addr) internal view {
console.log(string(abi.encodePacked(name, "=", vm.toString(address(addr)))));
}
function logAddress(string memory name, address addr) internal view {
console.log(string(abi.encodePacked(name, "=", vm.toString(address(addr)))));
}
}

0 comments on commit 0fc6d2a

Please sign in to comment.