-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca25f8e
commit 0396760
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity 0.7.6; | ||
|
||
import "forge-std/Test.sol"; | ||
import "../../../contracts/Vault.sol"; | ||
import "../../../contracts/test/TestERC20.sol"; | ||
|
||
contract InvalidWithdrawalTest is Test { | ||
uint256 forkBlock = 105_302_472; // Optimiam mainnet @ Thu Jun 8 05:55:21 UTC 2023 | ||
|
||
Vault vault; | ||
TestERC20 usdc; | ||
TestERC20 weth; | ||
|
||
function setUp() public { | ||
vm.createSelectFork(vm.rpcUrl("optimism"), forkBlock); | ||
vault = Vault(0xAD7b4C162707E0B2b5f6fdDbD3f8538A5fbA0d60); | ||
usdc = TestERC20(vault.getSettlementToken()); | ||
weth = TestERC20(0x4200000000000000000000000000000000000006); | ||
|
||
deal(address(usdc), address(this), 1000 * 1e6, true); | ||
} | ||
|
||
function test_exploit() external payable { | ||
// Step 1: Deposit 1000 USDC into the Vault | ||
// Assume the attacker already has 1000 USDC | ||
usdc.approve(address(vault), 1000 * 1e6); // Approve Vault to spend USDC | ||
vault.deposit(address(usdc), 1000 * 1e6); // Deposit 1000 USDC | ||
assertEq(vault.getBalanceByToken(address(this), address(usdc)), 1000 * 1e6); | ||
assertEq(vault.getBalanceByToken(address(this), address(weth)), 0); | ||
|
||
// Step 2: Withdraw 1 wei | ||
vm.expectRevert("V_NEFC"); | ||
vault.withdrawEther(1); // Attempt to withdraw 1 wei | ||
} | ||
} |