Open code423n4 opened 2 years ago
This is a straightforward recommendation that has a non-trivial impact on the core functions. It's also well explained. I ran the recommended change and confirmed decent gas savings across the board. This seems to be a worthwhile change to consider including.
This gas report is about a single issue and is ranked 85. This same exact issue, as well as many more instances the same issue are flagged in https://github.com/code-423n4/2022-05-opensea-seaport-findings/issues/144 as the third item "Multiple accesses of a mapping/array should use a local variable cache" which has a proof of concept showing the gas savings in a concise example, along with many other gas savings but is only ranked 60. @HardlyDifficult @0xleastwood can you provide more clarity on how the ranking has been performed?
This gas report is about a single issue and is ranked 85. This same exact issue, as well as many more instances the same issue are flagged in #144 as the third item "Multiple accesses of a mapping/array should use a local variable cache" which has a proof of concept showing the gas savings in a concise example, along with many other gas savings but is only ranked 60. @HardlyDifficult @0xleastwood can you provide more clarity on how the ranking has been performed?
They are similar, but this report is more useful. In 144 the report is focused on the access costs to save 42 gas per instance and dumps every instance where that may apply. This report zoomed into a specific change that results in a sizeable gas savings in total for critical functions in a way that is easy to confirm.
This report scores higher for focusing on just the most impactful changes, providing an easy to follow diff of the recommended changes, and highlighting the expected total benefit. The approach used here makes it easy to conclude the recommendation provided is worth close consideration. The sponsor's time should be respected so we scored reports which read like static analysis reports lower (and if they offered no targeted insights they were closed as invalid).
Gas Report
Inefficient struct utilization
Functions in
OrderValidator
retreive_orderStatus[]
using a memory location. This necessiates inefficient mapping lookup operations when writing to the storage. For example, the following block performs the same offset calculation four times.I suggest using a storage pointer instead of memory location when retreiving
_orderStatus[]
.Reference diff
Below is a diff file that applies the suggested change. This is for reference only.
Gas savings table
I have ran the provided
yarn profile
script to compare the gas costs before and after applying the reference diff. All external mutativeSeaport
functions showed considerable gas savings, exceptincrementNonce()
, which has nothing to do with order validation. Below is a table comparing minimum and maximum gas costs of all external mutativeSeaport
functions, exceptincrementNonce()
, before and after applying the diff.cancel
fulfillAdvancedOrder
fulfillAvailableAdvancedOrders
fulfillAvailableOrders
fulfillBasicOrder
fulfillOrder
matchAdvancedOrders
matchOrders
validate