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

1 stars 0 forks source link

packing of state variable #112

Closed code423n4 closed 2 years ago

code423n4 commented 3 years ago

Handle

JMukesh

Vulnerability details

Impact

bool public override auctionOngoing; uint256 public override auctionStart; bool public override hasBonded; uint256 public override bondAmount; uint256 public override bondTimestamp; bool public override initialized;

the above state variable use 6 slot of memory , if we declare same type of variable in a row then they can be packed in one slot

uint256 public override auctionStart; uint256 public override bondAmount; uint256 public override bondTimestamp; bool public override auctionOngoing; bool public override hasBonded; bool public override initialized;

now the above state variable will take only 4 slot of memory because all three bool variable can be packed in the single slot

Proof of Concept

https://github.com/code-423n4/2021-09-defiProtocol/blob/52b74824c42acbcd64248f68c40128fe3a82caf6/contracts/contracts/Auction.sol#L16

Tools Used

manual review

Recommended Mitigation Steps

GalloDaSballo commented 2 years ago

Duplicate of #109