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

1 stars 0 forks source link

Can change order of global variable declaration in Auction to save 2 storage slots #70

Closed code423n4 closed 2 years ago

code423n4 commented 3 years ago

Handle

loop

Vulnerability details

Variables smaller than 32 bytes can be grouped together in the same storage slot. The globally declared booleans auctionOngoing, hasBonded and initialized in Auction.sol can be packed together in the same slot considering booleans have a size of 1 byte. Currently they are split by uint256 variables and each take up a full storage slot.

Impact

Packing variables saves a bit of gas due to less storage slots used.

Proof of Concept

Auction.sol : line 16-21:

bool public override auctionOngoing; - slot 1 uint256 public override auctionStart; - slot 2 bool public override hasBonded; - slot 3 uint256 public override bondAmount; - slot 4 uint256 public override bondTimestamp; - slot 5 bool public override initialized; - slot 6

Could be changed into:

bool public override auctionOngoing; - slot 1 bool public override initialized; - slot 1 bool public override hasBonded; - slot 1 uint256 public override auctionStart; - slot 2 uint256 public override bondAmount; - slot 3 uint256 public override bondTimestamp; - slot 4

GalloDaSballo commented 2 years ago

Duplicate of #109