Beginner FriendlyFoundryGameFi
100 EXP
View results
Submission Details
Severity: low
Invalid

All gas related reports

In MartenitsaVoting::announceWinner use variables insted of _tokenIds.length

Description: In MartenitsaVoting::announceWinner use tokenIdLength = _tokenIds.length instead of _tokenIds.length with this, you can save 300 gas. if thousands or hundreds of users participate in voting you can save more gas.

  • Total gas spend with _tokenIds.length: 519603

  • Total gas spend with tokenIdLength = _tokenIds.length: 519303

Proof Of Concept:

function test_gasAnnounceWinner() public {
uint256 startGas = gasleft();
vm.startPrank(chasy);
martenitsaToken.createMartenitsa("bracelet");
marketplace.listMartenitsaForSale(0, 1 wei);
vm.stopPrank();
vm.startPrank(chasy);
voting.voteForMartenitsa(0);
vm.stopPrank();
vm.startPrank(bob);
voting.voteForMartenitsa(0);
vm.stopPrank();
vm.warp(block.timestamp + 1 days + 1);
vm.recordLogs();
voting.announceWinner();
uint256 endGas = gasleft();
uint256 totalGas = startGas - endGas;
console.log("Total gas spend:", totalGas);

Recommendation: Use tokenIdLength = _tokenIds.length instead of _tokenIds.length

function announceWinner() external onlyOwner {
require(block.timestamp >= startVoteTime + duration, "The voting is active");
uint256 winnerTokenId;
uint256 maxVotes = 0;
+ uint256 tokenIdLength = _tokenIds.length;
+ for (uint256 i = 0; i < tokenIdLength; i++) {
- for (uint256 i = 0; i < _tokenIds.length; i++) {
if (voteCounts[_tokenIds[i]] > maxVotes) {
maxVotes = voteCounts[_tokenIds[i]];
winnerTokenId = _tokenIds[i];
}
}
.
.
.
}

Unused variable

Description: In MartenitsaEvent::startEvent the eventDuration = duration; variable is unused. it's unnecessarily wasting gas.

function startEvent(uint256 duration) external onlyOwner {
eventStartTime = block.timestamp;
eventDuration = duration;
eventEndTime = eventStartTime + duration;
emit EventStarted(eventStartTime, eventEndTime);
}

In MartenitsaToken use variables instead of _tokenIds.length

Description: In MartenitsaToken::joinEvent Use tokenIdLength = _tokenIds.length insted of _tokenIds.length. for example: if the owner makes 10 producers with this you can save 25 gas. if the owner wants to make more producers with this you can save more gas.

  • Total gas spend with _tokenIds.length: 288311

  • Total gas spend with tokenIdLength = _tokenIds.length: 288286

Proof Of Concept:

function test_gasSetProducer() public {
uint256 startGas = gasleft();
martenitsaToken.setProducers(producers);
uint256 endGas = gasleft();
uint256 totalGas = startGas - endGas;
console.log("Total gas spend:", totalGas);
}

Recomendation: use uint256 ProducerLength = _producersList.length instead of _tokenIds.length

function setProducers(address[] memory _producersList) public onlyOwner {
+ uint256 ProducerLength = _producersList.length;
+ for (uint256 i = 0; i < ProducerLength; i++) {
- for (uint256 i = 0; i < _producersList.length; i++) {
isProducer[_producersList[i]] = true;
producers.push(_producersList[i]);
}
}

In MartenitsaEvent::stopEvent use variables insted of _tokenIds.length

Description: InMartenitsaEvent::stopEvent use tokenIdLength = _tokenIds.length insted of _tokenIds.length. It will save a lot of gas.

function stopEvent() external onlyOwner {
require(block.timestamp >= eventEndTime, "Event is not ended");
+ uint256 participantsLength = participants.length;
+ for (uint256 i = 0; i < participantsLength; i++) {
- for (uint256 i = 0; i < participants.length; i++) {
isProducer[participants[i]] = false;
}
}
Updates

Lead Judging Commences

bube Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.