Closed sherlock-admin closed 1 year ago
Escalate for 5 USDC
This is an exact duplicate of https://github.com/sherlock-audit/2022-11-bullvbear-judging/issues/147 https://github.com/sherlock-audit/2022-11-bullvbear-judging/issues/142 https://github.com/sherlock-audit/2022-11-bullvbear-judging/issues/18
Consider including this for rewards as well.
Hmm, I see my first recommendation is incorrect; the second recommendation of pull vs push is more ideal. I am okay if my escalation gets rejected. :) However, please note for all of the above 147, 142,18, the recommendation is incorrect as well; you can not mitigate this threat by limiting gas sent only; a malicious bull can still cause out of gas through return bombing (memory expansion). Ideally, you would also need to limit the memory bytes one can return. More on it here https://github.com/nomad-xyz/ExcessivelySafeCall
Escalate for 5 USDC
This is an exact duplicate of https://github.com/sherlock-audit/2022-11-bullvbear-judging/issues/147 https://github.com/sherlock-audit/2022-11-bullvbear-judging/issues/142 https://github.com/sherlock-audit/2022-11-bullvbear-judging/issues/18
Consider including this for rewards as well.
Hmm, I see my first recommendation is incorrect; the second recommendation of pull vs push is more ideal. I am okay if my escalation gets rejected. :) However, please note for all of the above 147, 142,18, the recommendation is incorrect as well; you can not mitigate this threat by limiting gas sent only; a malicious bull can still cause out of gas through return bombing (memory expansion). Ideally, you would also need to limit the memory bytes one can return. More on it here https://github.com/nomad-xyz/ExcessivelySafeCall
You've created a valid escalation for 5 USDC!
To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
Escalation accepted
Escalation accepted
This issue's escalations have been accepted!
Contestants' payouts and scores will be updated according to the changes made on this issue.
curiousapple
medium
[Medium-1] Due to external call done before state updates, bulls can add extra gas overhead for bears to settle.
Summary
Due to external calls done before state updates, bulls can add extra gas overhead for bears to settle.
Vulnerability Detail
Bears can settle contracts through
settleContract()
, by doing the safe transfer of the NFT to the bull.BullVsBear
is protected against the vanilla denial of service by malicious bulls where they revert to the hook ofonERC721Received
, but clever bulls can still take advantage of this hook to make bears pay extra gas to settle.settleContract
looks something like thisOur focus is on the try-catch block. Try tries to do a
safeTrasnfer
, and if failed, it goes to catch. Now please note from EIP-150 a caller can actually only give to a callee, an amount of gas no greater than:gas available - (1/64* gas available)
Hence if
63/64 * gas
is passed toIERC721(order.collection).safeTransferFrom(bear, bull, tokenId)
and it reverts or goes out of gas the remaining 1/64 should be able to execute the code from the catch block to settle.That is, if malicious bull implements an infinite loop inside
onERC721Received
hook and consumes a total of 63/64 gas passed, the remaining 1/64 should be enough to execute the above block.Due to this, no matter what amount of gas cost is needed until the catch block, one must pass approximately
63 * (gas needed from the catch block)
.As per my tests, the gas costs needed from the catch block are 107483
Verification
The output comes something like this
63 * 107483
its 6771429 If we consider the following market condition its Gas PriceThis adds extra overhead for bears to settle the contract, which could be substantial depending on the gas market and the profit amount.
bvb.settleContract{gas: 6371429}(order, tokenId);
Impact: Medium
Adds extra overhead for bears to close the contract, which could be substantial depending on the gas market and the profit amount.
Code Snippet
https://github.com/sherlock-audit/2022-11-bullvbear/blob/main/bvb-protocol/src/BvbProtocol.sol#L394
Tool used
Manual Review
Recommendation
Consider moving to try-catch block and thereby external calls to the end, making this attack less attractive. Or better refractor to pull pattern instead of push, where bull needs to pull nft by themselves.
Duplicate of #111