Putty contest - Picodes'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: 38/133

Findings: 4

Award: $153.74

🌟 Selected for report: 1

πŸš€ Solo Findings: 0

Findings Information

🌟 Selected for report: horsefacts

Also found by: 0xc0ffEE, IllIllI, Picodes, Sm4rty, berndartmueller, csanuragjain, shenwilly, unforgiven

Labels

bug
duplicate
2 (Med Risk)
sponsor acknowledged

Awards

35.1904 USDC - $35.19

External Links

Lines of code

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

Vulnerability details

Impact

In the EIP721, onERC721Received is a safeguard to avoid NFTs to be stuck on contracts. But here it could turn out to actually create this situation: it may happen that the NFTs are stuck on PuttyV2 if a user uses a contract not suited to receive NFTs to create and fill orders.

Proof of Concept

An example scenario would be:

  • Alice uses a contract to create a short put option.
  • Bob fills the order. A long NFT is minted to Alice's contract but there is no check
  • Bob exercise the option
  • Alice cannot withdraw: here contract cannot receive NFTs

Check in the appropriate case if the maker or msg.sender is a contract and if it is the case, if they can receive NFTs

#0 - GalloDaSballo

2022-07-05T01:17:56Z

The finding implies that the caller is a contract, and that the contract was programmed to handle all operations but somehow wouldn't be able to handle the NFTs

#1 - outdoteth

2022-07-05T12:37:57Z

echo what @GalloDaSballo said. It's unlikely a contract will have all the setup required to interact with PuttyV2 but not be able to handle ERC721 tokens. Adding a check via safeMint adds a gas overhead as well as another re-entrancy attack vector so there is a tradeoff.

#2 - outdoteth

2022-07-06T19:37:09Z

Duplicate: Contracts that can’t handle ERC721 tokens will lose their Putty ERC721 position tokens: https://github.com/code-423n4/2022-06-putty-findings/issues/327

Findings Information

🌟 Selected for report: Picodes

Also found by: 0xNineDec, 0xsanson, Metatron, antonttc, berndartmueller, catchup, dirk_y, sseefried, unforgiven

Labels

bug
2 (Med Risk)
resolved
sponsor confirmed

Awards

50.1287 USDC - $50.13

External Links

Lines of code

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

Vulnerability details

Impact

Fees are applied during withdraw, but can change between the time the order is filled and its terms are agreed upon and the withdrawal time, leading to a loss of the expected funds for the concerned users.

Proof of Concept

The scenario would be:

  • Alice and Bob agrees to fill an order at a time fees are 0.1%
  • During the duration of the option, fees are increased to 3%
  • At withdrawal they'll pay 3% of the strike, although they wouldn't have created the order in the first place with such fees

Mitigation could be:

  • Store the fees in Order and verify that they are correct when the order is filled, so they are hardcoded in the struct
  • Add a timestamp: this wouldn't fully mitigate but would still be better than the current setup
  • Keep past fees and fee change timestamps in memory (for example in an array) to be able to retrieve the creation time fees at withdrawal

#0 - outdoteth

2022-07-08T13:26:19Z

Report: Admin can change fee at any time for existing orders

#1 - outdoteth

2022-07-15T10:34:58Z

[Low - 01] - Incorrect comment

Here it says:

"It fills the counter offer, and then cancels the original order that the counter offer was made for”.

In the code it's actually the opposite:

"It cancels the original order the counter offer was made for, and then fills the counter offer.”.

[Gas - 01] - Use Custom Errors

Instead of using error strings, to reduce deployment and runtime cost, you should use Custom Errors: see https://blog.soliditylang.org/2021/04/21/custom-errors/. This would save both deployment and runtime cost.

[Gas - 02] - Directly settle short orders in exercise

In exercise, why not directly settling the deal ?

The gas overhead would be minimal has the transfers are already done, and you’d save a ton of gas in the overall flow. Instead of doing a 2 time transfer msg.sender -> contract during exercise and then contract -> maker or taker during withdraw, you could directly do the accounting, burn the position and do the correct transfers in exercise. There would still be a withdraw function, but only for non-exercised options.

Especially as the order is immutable, we already know during exercise than withdraw will be called, so this optimisation is worth doing to me, although it requires some work.

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