code-423n4 / 2021-09-defiprotocol-findings

1 stars 0 forks source link

Pack together bool variables in Auction #38

Closed code423n4 closed 2 years ago

code423n4 commented 3 years ago

Handle

kenzo

Vulnerability details

By putting the bool variables declared in Auction one after the other, solidity will pack them and save gas in deployment.

Impact

Around 13000 gas can be saved.

Proof of Concept

Relevant lines: https://github.com/code-423n4/2021-09-defiProtocol/blob/52b74824c42acbcd64248f68c40128fe3a82caf6/contracts/contracts/Auction.sol#L16:#L21 Running hardhat with a test file, for deployment of Auction I see normal price of 1547504, and after packing together 1534543.

Tools Used

Manual analysis, hardhat, hardhat-gas-reporter.

Recommended Mitigation Steps

Declare the bool variables together:

    bool public override initialized;
    bool public override auctionOngoing;
    bool public override hasBonded;
GalloDaSballo commented 2 years ago

Duplicate of #109