5 T Swap Audit Proof of Code / POC #364
-
hi there, been trying to make Proof of Code for slippage vulnerable on here is my code: function test_slippageVulnerable() public {
vm.startPrank(liquidityProvider);
weth.approve(address(pool), type(uint256).max);
poolToken.approve(address(pool), type(uint256).max);
pool.deposit(100e18, 100e18, 100e18, uint64(block.timestamp));
vm.stopPrank();
poolToken.mint(userLoseMoney, 100e18);
weth.mint(userLoseMoney, 1e18);
vm.startPrank(userLoseMoney);
poolToken.approve(address(pool), type(uint256).max);
weth.approve(address(pool), type(uint256).max);
vm.stopPrank();
vm.prank(liquidityProvider);
pool.deposit(100e18, 100e18, 100e18, uint64(block.timestamp));
//pool.deposit(1e18, 1e18, 1000e18, uint64(block.timestamp));
vm.prank(userLoseMoney);
pool.swapExactOutput(poolToken, weth, 1e18, uint64(block.timestamp + 1 days));
uint256 wethUserLoseMoneyEnd = weth.balanceOf(userLoseMoney);
uint256 poolTokenUserLoseMoneyEnd = poolToken.balanceOf(userLoseMoney);
uint256 wethPoolLP = weth.balanceOf(address(pool));
uint256 poolTokenLP = poolToken.balanceOf(address(pool));
console.log("wethLP: ", wethPoolLP);
console.log("poolTokenLP: ", poolTokenLP);
console.log("wethUserLoseMoneyEnd; ", wethUserLoseMoneyEnd);
console.log("poolTokenUserLoseMoneyEnd: ", poolTokenUserLoseMoneyEnd);
} In the report, Patrick said that:
the problem here is, i cannot make the swap from 1 weth = 1tokenpool into 1 weth = 1000 tokenpool.. Is there anyone can help? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
The best approach that comes to my mind is you should have a user that wants to make a swap then calculate what the user is supposed to get back/ pay when they make the swap but don't make the swap but instead make several other users make swaps and then make the first user swap and then compare what you had intitially calculated to the actual outcome/input of that user. Like that, you will be able to demonstrate that the lack of slippage protection caused the user to pay more than they actually wanted to pay. |
Beta Was this translation helpful? Give feedback.
I can't remember correctly if he wrote one because it has been a long time since I saw the content. The exact way you set up a user here to make a swap is the same way you will set up plenty user to make a swap oner after the other then make the intended user make the last swap and show the difference in the expected result against the actual result. But I realized there is an issue with incorrect fee as well when a user make a swap so maybe you should create a separate
swap
function that correctly account for fee so that thevulnerability
you want to show won't be disrupted by thatincorrect fee
accounting bugYou can set up the
intended user
for the swap by funding them with the tokens …