Putty contest - minhquanym's results

An order-book based american options market for NFTs and ERC20s.

General Information

Platform: Code4rena

Start Date: 29/06/2022

Pot Size: $50,000 USDC

Total HM: 20

Participants: 133

Period: 5 days

Judge: hickuphh3

Total Solo HM: 1

Id: 142

League: ETH

Putty

Findings Distribution

Researcher Performance

Rank: 3/133

Findings: 5

Award: $2,830.87

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: kirk-baird

Also found by: Lambda, csanuragjain, hansfriese, minhquanym

Labels

bug
duplicate
3 (High Risk)

Awards

1009.2502 USDC - $1,009.25

External Links

Lines of code

https://github.com/code-423n4/2022-06-putty/blob/3b6b844bc39e897bd0bbb69897f2deff12dc3893/contracts/src/PuttyV2.sol#L573

Vulnerability details

Impact

  • Function PuttyV2.acceptCounterOffer() is used in case users see better deal and want to cancel their own order before filling the new one. But attacker can abuse this function by front-run calling fillOrder() before it is cancelled in acceptCounterOffer().

  • Attackers have motivation to do this (for example: premium). And users who willing to sell only 1 BAYC now may be forced to sell 2 BAYC

Proof of Concept

Scenario

  1. Alice posts short call order offchain
  2. Bob posts long call order offchain.
  3. Alice calls acceptCounterOffer() with Bob’s long call order. But Bob frontruns Alice by filling Alice’s short call order first.
  4. Now Alice has 2 short call positions (1 from her own order, 1 from accept Bob’s order) and Bob has 2 long call positions.
  5. Alice may be forced to sell more assets than she intended.

Tools Used

Manual Review

Make sure users cannot cancel() order when the position is minted.

#1 - outdoteth

2022-07-06T18:08:32Z

Duplicate: It’s possible to fill an order twice by accepting a counter offer for an already filled order: https://github.com/code-423n4/2022-06-putty-findings/issues/44

Findings Information

🌟 Selected for report: zzzitron

Also found by: Kenshin, Metatron, PwnedNoMore, danb, minhquanym

Labels

bug
duplicate
3 (High Risk)

Awards

756.9377 USDC - $756.94

External Links

Lines of code

https://github.com/code-423n4/2022-06-putty/blob/3b6b844bc39e897bd0bbb69897f2deff12dc3893/contracts/src/PuttyV2.sol#L367

Vulnerability details

Impact

Takers who fill short-call orders may unable to exercise their long-call position. Attackers can abuse it to take premium from takers for free.

In PuttyV2.fillOrder() function, when taker fill short-call order, order’s maker only has to transfer erc20Assets and erc721Assets in but floor assets is ignored.

After takers filled short-call orders, they will receive long-call position. And because maker didn’t transfer any floor assets in, positionFloorAssetTokenIds[orderHash] is empty, when takers call exercise() the TX will be reverted when trying to transfer floor assets out in this line

Proof of Concept

Scenario

  1. Alice posts short call order offchain with floorAssets = [BAYC]
  2. Bob calls fillOrder() to fill Alice’s order. In this step, Bob get long call position which should allow him to buy a BAYC from Alice so Bob has to pay Alice premium.
  3. Bob calls exercise() to exercise his right but the TX is always reverted.

Tools Used

Manual Review

In case fillOrder() with short call order, should make sure this order do not use floorAssets

if (!order.isLong && order.isCall) { require(order.floorTokens.length == 0); }

#0 - 0xlgtm

2022-07-05T08:20:21Z

#1 - outdoteth

2022-07-06T18:06:02Z

Short call with floorTokens will result in a revert when exercising: https://github.com/code-423n4/2022-06-putty-findings/issues/369

Findings Information

🌟 Selected for report: cccz

Also found by: IllIllI, minhquanym

Labels

bug
duplicate
2 (Med Risk)
upgraded by judge

Awards

622.994 USDC - $622.99

External Links

Judge has assessed an item in Issue #253 as Medium risk. The relevant finding follows:

#0 - HickupHH3

2022-07-16T00:49:01Z

  1. Not Support Cryptopunk or Cryptokitties Tokens While the PuttyV2 contract is compatible with standard ERC20 and ERC721 tokens, it is not able to handle popular non-standard ERC721 tokens such as cryptopunks. The typical transferFrom() call will fail.

Recommended Mitigation Steps NFTX protocol has implemented a way to handle the transfer of both standard and non-standard ERC721 tokens. The relevant implementation can be found here.

dup of #16

Findings Information

🌟 Selected for report: hyh

Also found by: Treasure-Seeker, csanuragjain, minhquanym

Labels

bug
duplicate
2 (Med Risk)
upgraded by judge

Awards

420.5209 USDC - $420.52

External Links

Judge has assessed an item in Issue #253 as Medium risk. The relevant finding follows:

#0 - HickupHH3

2022-07-16T00:47:44Z

  1. When call is expired, fee send to admin/DAO may even higher than premium, cause short call position is in loss. When short call position expired, owners might want to withdraw their funds back. But they have to pay an amount of fee to admin/DAO which is calculated using strike amount even though the order is not exercised.

The result is in some case, the fee to admin may even higher than premium, cause owners of short call position in loss.

dup of #373

1. Save gas with short-circuit optimization

When evaluating boolean expressions (logical AND and OR) you can stop as soon as you find the first condition which satisfies or negates the expression.

This can be used to optimize gas by reordering conditions in expressions. For example, this expression has 2 conditions

block.timestamp > positionExpirations[longPositionId] || isExercised

First condition reading from storage obviously cost more gas than second condition which simply a boolean variable in stack. We can swap their orders to optimize gas like

isExercised || block.timestamp > positionExpirations[longPositionId]

Affected Codes

https://github.com/code-423n4/2022-06-putty/blob/3b6b844bc39e897bd0bbb69897f2deff12dc3893/contracts/src/PuttyV2.sol#L481

https://github.com/code-423n4/2022-06-putty/blob/3b6b844bc39e897bd0bbb69897f2deff12dc3893/contracts/src/PuttyV2.sol#L327

https://github.com/code-423n4/2022-06-putty/blob/3b6b844bc39e897bd0bbb69897f2deff12dc3893/contracts/src/PuttyV2.sol#L351

https://github.com/code-423n4/2022-06-putty/blob/3b6b844bc39e897bd0bbb69897f2deff12dc3893/contracts/src/PuttyV2.sol#L427

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter