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
Handle
loop
Vulnerability details
Variables smaller than 32 bytes can be grouped together in the same storage slot. The globally declared booleans
auctionOngoing
,hasBonded
andinitialized
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 1uint256 public override auctionStart;
- slot 2bool public override hasBonded;
- slot 3uint256 public override bondAmount;
- slot 4uint256 public override bondTimestamp;
- slot 5bool public override initialized;
- slot 6Could be changed into:
bool public override auctionOngoing;
- slot 1bool public override initialized;
- slot 1bool public override hasBonded;
- slot 1uint256 public override auctionStart;
- slot 2uint256 public override bondAmount;
- slot 3uint256 public override bondTimestamp;
- slot 4