cryptokitties-bounty icon indicating copy to clipboard operation
cryptokitties-bounty copied to clipboard

Gas inefficiencies in `KittyMinting`

Open Arachnid opened this issue 7 years ago • 3 comments

Description

There are a couple of gas inefficiencies in KittyMinting that could be resolved for significantly lower gas consumption:

  • promoCreationLimit and gen0CreationLimit are both defined as variables. Making them constant would allow the compiler to optimise them out, saving 40k of deployment-time gas, and ~200 gas each time they are read.
  • createPromoKitty increments both variables, costing ~10k. Incrementing only promoCreatedCount, and checking the sum of the two variables instead of each separately, would save ~5k gas at update time.

Arachnid avatar Nov 16 '17 15:11 Arachnid

promoCreationLimit and gen0CreationLimit are both defined as variables

Weirdly, I just learned about constant Solidity variables just this morning, I think there some others we can probably fix, also.

createPromoKitty increments both variables

Your suggestion would result in two reads (instead of one) in createGen0Auction, but it's still a net gas savings. We'll definitely look at this!

Thanks again, @Arachnid! Love these reports!

dete avatar Nov 16 '17 19:11 dete

@dete As you suspected, here are two more than can be constant https://github.com/axiomzen/cryptokitties-bounty/blob/03b51a8872d2438851d0ef77cfe29c74a079d26a/contracts/KittyOwnership.sol#L13 https://github.com/axiomzen/cryptokitties-bounty/blob/03b51a8872d2438851d0ef77cfe29c74a079d26a/contracts/KittyOwnership.sol#L14

MacroChip avatar Nov 17 '17 03:11 MacroChip

Thanks for your participation, @Arachnid! Our team has reviewed your submission, and we are pleased to reward you for your report.

Impact: Low Likelihood: Low Points: 50

Please see the final leaderboard here.

kimcope avatar Nov 21 '17 22:11 kimcope