Platform: Code4rena
Start Date: 05/07/2023
Pot Size: $390,000 USDC
Total HM: 136
Participants: 132
Period: about 1 month
Judge: LSDan
Total Solo HM: 56
Id: 261
League: ETH
Rank: 96/132
Findings: 2
Award: $71.21
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xadrii
Also found by: 0xWaitress, KIntern_NA, Kaysoft, Madalad, chaduke, dontonka, rvierdiiev, vagrant, wangxx2026
30.0503 USDC - $30.05
https://github.com/Tapioca-DAO/YieldBox/blob/f5ad271b2dcab8b643b7cf622c2d6a128e109999/contracts/YieldBox.sol#L196-L215 https://github.com/Tapioca-DAO/YieldBox/blob/f5ad271b2dcab8b643b7cf622c2d6a128e109999/contracts/YieldBox.sol#L49
The function depositETHAsset
allows the caller to provide Ether, but does not refund the amount in excess of what's required, leaving funds stranded in the contract and the excess sent become essentially a loss for the user.
Add this test in YieldBox.ts
and run it.
describe("depositETH", () => { //... // NEW TEST POC it.only("handles deposit of ETH (msg.values > amount), ", async function () { // send an higher ETH amount then the amount specified in parameter await yieldBox.depositETH(ethStrategy.address, Alice, 1000, { value: 10000 }) // value held for the user is 1000, not 10000, so 9000 become essentially a loss for the user expect(await yieldBox.balanceOf(Alice, 2)).equals(1000_00000000) }) //... })
Test suite, VC Code
Minimal change would be to ensure amount
and msg.value
match with a require statement.
diff --git a/contracts/YieldBox.sol b/contracts/YieldBox.sol index 4cf3d71..f7023d8 100644 --- a/contracts/YieldBox.sol +++ b/contracts/YieldBox.sol @@ -196,6 +196,7 @@ contract YieldBox is YieldBoxPermit, BoringBatchable, NativeTokenFactory, ERC721 function depositETHAsset(uint256 assetId, address to, uint256 amount) public payable returns (uint256 amountOut, uint256 shareOut) { // Checks Asset storage asset = assets[assetId]; + require(amount == msg.value, "!diff amount"); require(asset.tokenType == TokenType.ERC20 && asset.contractAddress == address(wrappedNative), "YieldBox: not wrappedNative"); // Effects
Payable
#0 - c4-pre-sort
2023-08-05T02:38:07Z
minhquanym marked the issue as duplicate of #983
#1 - c4-judge
2023-09-12T19:43:49Z
dmvt marked the issue as unsatisfactory: Out of scope
#2 - c4-judge
2023-09-12T19:50:53Z
dmvt marked the issue as satisfactory