Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuctionHouseV2: price feed, gas optimizations #799

Draft
wants to merge 88 commits into
base: master
Choose a base branch
from

Conversation

eladmallel
Copy link
Collaborator

No description provided.

many tests and refinements TODO
trying to assess auction house gas v1 vs v2
best to use what's used on mainnet now
taking a more tolerant appraoch since auction house can work fine
without the oracle
settleAuction is protected from re-entry by requiring `settled` to be false
and setting it to true first thing after the require statements
should make it clearer that this function can't be abused via reentry

msg.value is required to be higher than the previous amount + min increment

by setting `auction.amount` right after that requirement, it's clear the next
reentry will have to provide a higher amount and so on
created AuctionV2 that fits into 2 storage slots instead of 5 previously
added a migration contract between V1 and V2 that rewrites auction data for V2
in case the DAO wants to start the spend or burn sooner

/// @notice Whether this contract is paused or not
/// @dev Replaces the state variable from PausableUpgradeable, to bit pack this bool with `auction` and save gas
bool public __paused;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladmallel I don't this is actually packs it in storage:

Items following struct or array data always start a new storage slot.

from: https://docs.soliditylang.org/en/latest/internals/layout_in_storage.html

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can run the build with storage layout output to see it also:

      {
         "astId":50,
         "contract":"contracts/NounsAuctionHouseV2.sol:NounsAuctionHouseV2",
         "label":"auction",
         "offset":0,
         "slot":"202",
         "type":"t_struct(AuctionV2)1382_storage"
      },
      {
         "astId":53,
         "contract":"contracts/NounsAuctionHouseV2.sol:NounsAuctionHouseV2",
         "label":"__paused",
         "offset":0,
         "slot":"204",
         "type":"t_bool"
      },

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to pack it, I think it has to go into the auction struct

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(copy pasting comment from discord)
placing it after the AuctionV2 struct puts it in a new storage slot.
to gain gas savings, it needs to be in the same slot as the AuctionV2, because only that is accessed during settleCurrentAndCreateNewAuction.

I'm apprehensive to add it to the struct because:

  1. it's not logically part of that struct
  2. we'll need to change the auction() view function to return a struct without paused for backwards compatibility.

davidbrai and others added 9 commits October 10, 2023 11:04
it's not bit-packed when placed after the auction struct
and for now we prefer to not force it into the auction struct

esp. since bigger gas savings are coming from descriptor storage read optimizations
getPrices(n)
    - returns exactly `n` latest auction prices
    - skips auctions with no bids
    - skips nounder noun ids
    - reverts if auction should have data but doesn't
    - reverts if not enough items in history (not need to trim)
    -> either returns array of n-length or reverts

getSettlements(n, skipEmptyValues)
    - returns up to `n` latest settlement (in case we reach id 0)
    - includes auction with no bids (blockTimestamp will be > 1)
    - skips nounder noun ids if skipEmptyValues = true, otherwise return raw
    - skip unset data if skipEmptyValues = true, otherwise return raw

getSettlements(x, y, skipEmptyValues)
    - returns settlements for ids [x,y)
    - includes auction with no bids (blockTimestamp will be > 1)
    - skips nounder noun ids if skipEmptyValues = true, otherwise return raw
    - skip unset data if skipEmptyValues = true, otherwise return raw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants