AbraNFT contest - 0xNazgul's results

A peer to peer lending platform, using NFTs as collateral.

General Information

Platform: Code4rena

Start Date: 27/04/2022

Pot Size: $50,000 MIM

Total HM: 6

Participants: 59

Period: 5 days

Judge: 0xean

Id: 113

League: ETH

Abracadabra Money

Findings Distribution

Researcher Performance

Rank: 52/59

Findings: 1

Award: $48.92

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

48.9194 MIM - $48.92

Labels

bug
G (Gas Optimization)

External Links

Functions Visibility Can Be Declared External

Context: NFTPair.sol#L181-L203, NFTPair.sol#L713-L723, NFTPair.sol#L728-L731, NFTPairWithOracle.sol#L198-L223, NFTPairWithOracle.sol#L735-L745, NFTPairWithOracle.sol#L750-L753

Description: Several functions across multiple contracts have a public visibility and can be marked with external visibility to save gas.

Recommendation: Change the functions visibility to external to save gas.

Catching The Array Length Prior To Loop

Context: NFTPair.sol#L636-L710, NFTPairWithOracle.sol#L669-L732

Description: One can save gas by caching the array length (in stack) and using that set variable in the loop. Replace state variable reads and writes within loops with local variable reads and writes. This is done by assigning state variable values to new local variables, reading and/or writing the local variables in a loop, then after the loop assigning any changed local variables to their equivalent state variables.

Recommendation: Simply do something like so before the for loop: uint length = variable.length. Then add length in place of variable.length in the for loop.

Use ++index instead of index++ to increment a loop counter

Context: NFTPair.sol#L441-L502, NFTPair.sol#L636-L710, NFTPairWithOracle.sol#L474-L535, NFTPairWithOracle.sol#L669-L732

Description: Due to reduced stack operations, using ++index saves 5 gas per iteration.

Recommendation: Use ++index to increment a loop counter.

Setting The Constructor To Payable

Context: NFTPair.sol#L169-L172, NFTPairWithOracle.sol#L192-L196

Description: You can cut out 10 opcodes in the creation-time EVM bytecode if you declare a constructor payable. Making the constructor payable eliminates the need for an initial check of msg.value == 0 and saves 21 gas on deployment with no security risks.

Recommendation: Set the constructor to payable.

uint256 Is Cheaper Than uint8

Context: NFTPair.sol#L96, NFTPair.sol#L97, NFTPair.sol#L98, NFTPair.sol#L162, NFTPairWithOracle.sol#L114, NFTPairWithOracle.sol#L115

Description: The EVM reads in 32 byte words if your data is smaller, further operations are needed to downscale from 256 bits to 8 bit. Since these uint8s are not packed with others to be read from the same slot it's cheaper to just use uint256 from them.

Recommendation: use uint256 instead of uint8.

Function Ordering via Method ID

Context: All Contracts

Description: Contracts most called functions could simply save gas by function ordering via Method ID. Calling a function at runtime will be cheaper if the function is positioned earlier in the order (has a relatively lower Method ID) because 22 gas are added to the cost of a function for every position that came before it. The caller can save on gas if you prioritize most called functions. One could use This tool to help find alternative function names with lower Method IDs while keeping the original name intact.

Recommendation: Find a lower method ID name for the most called functions for example mostCalled() vs. mostCalled_41q() is cheaper by 44 gas.

#0 - cryptolyndon

2022-05-14T01:14:59Z

Seen, thanks.

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