When the event finishes, the owner of the contract has to call the function MartenitsaEvent::stopEvent
to remove the producer role from each participant. This is done by iterating in a for loop through each particpant and setting the value of the mapping MartenitsaEvent::isProducer
to false. Since the array MartenitsaEvent::participants
used in the for loop is not emptied after the event finishes it can become too expensive in the future to call this function.
Every time a participant joins the event, its address is added to the array MartenitsaEvent::participants
. When the deadline is met and the owner calls MartenitsaEvent::stopEvent
to set back to the previous state the roles of the users, it forgets to empty this array. Since the rolling back to the previous role is performed using a for loop, as the array becomes bigger, calling this function may become economically inviable. This is worsened by the poor gas optimization techniques being used such as not caching the array length in memory.
As a consequence of not emptying the array, the gas consumed in a function call to MartenitsaEvent::stopEvent
will become more and more expensive. To get an estimate of the magnitude, the test below is executed for different number of particpants, determined by the iterations in the for loops.
Place this into MartenitsaEvent.t.sol
.
The gas consumed in the test for the different iterations are:
1,000 iterations: 780,180 gas
10,000 iterations: 7,791,180 gas
100,000 iterations: 77,901,180 gas
It can be observed that the gas increases at a rate of approximately 779 gas per particpant joining the event. Considering that Ethereum is the chosen network to deploy the protocol, it can be something very problematic during periods of high network congestion as the gas price will be considerably high.
Foundry and manual review.
Implement an optimized code that deletes the participants array and caches the array length in memory to avoid reading from storage in every iteration.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.