Putty contest - Tomio'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: 107/133

Findings: 1

Award: $21.24

🌟 Selected for report: 0

🚀 Solo Findings: 0

Title: Expression for constant values such as a call to keccak256(), should use immutable rather than constant

Proof of Concept: https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L89-L101

Recommended Mitigation Steps: Change from constant to immutable reference: here


Title: abi.encode() is less efficient than abi.encodePacked()

Proof of Concept: https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L685 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L701 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L731 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L745


Title: Custom errors from Solidity 0.8.4 are cheaper than revert strings

Impact: Custom errors from Solidity 0.8.4 are cheaper than revert strings (cheaper deployment cost and runtime cost when the revert condition is met) while providing the same amount of information

Custom errors are defined using the error statement reference: here

Proof of Concept: (various lines) https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol
https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2Nft.sol

Recommended Mitigation Steps: Replace require statements with custom errors.


Title: calldata instead of memory for RO function parameters

Impact: If a reference type function parameter is read-only, it is cheaper in gas to use calldata instead of memory. Calldata is a non-modifiable, non-persistent area where function arguments are stored, and behaves mostly like memory.

Try to use calldata as a data location because it will avoid copies and also makes sure that the data cannot be modified.

Proof of Concept: (various lines) https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L269 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L389 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L526 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L547 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L593

Recommended Mitigation Steps: Replace memory with calldata


Title: Using != in require statement is more gas efficient

Proof of Concept: https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L293 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L598-L599

Recommended Mitigation Steps: Change > 0 to != 0


Title: Default value initialization

Impact: If a variable is not set/initialized, it is assumed to have the default value (0, false, 0x0 etc depending on the data type). Explicitly initializing it with its default value is an anti-pattern and wastes gas.

Proof of Concept: https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L556 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L594 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L611 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L627 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L742

Recommended Mitigation Steps: Remove explicit initialization for default values.


Title: Caching length for loop can save gas

Proof of Concept: https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L556 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L594 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L611 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L627 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L742

Recommended Mitigation Steps: Change to:

uint256 Length = orders.length; for (uint256 i = 0; i < Length; i++) {

Title: Using unchecked and prefix increment is more effective for gas saving:

Proof of Concept: https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L556 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L594 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L611 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L627 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L742

Recommended Mitigation Steps: Change to:

for (uint256 i = 0; i < orders.length;) { // ... unchecked { ++i; } }

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