Insrt-Finance / insrt-v2-contracts

0 stars 3 forks source link

Ext 11 for multiple spin games ensure multiple vrf calls are used #234

Closed giovannifranchi closed 3 months ago

giovannifranchi commented 3 months ago

Changes implemented:

    1. _attemptBatchMintForEthWithEth()
    2. _processMintForEthWithEthAttemptSupra()
    3. _attemptBatchMintForEthWithMint()
    4. _attemptBatchMintForEthWithMintSupra_requestRandomWordsSupra()
    5. _attemptBatchMintForMintWithEth()
    6. _attemptBatchMintForMintWithEthSupra()
    7. _attemptBatchMintForMintWithMint()
    8. _attemptBatchMintForMintWithMintSupra()
    9. _attemptBatchMintWithEth()
    10. _attemptBatchMintWithEthSupra()
    11. _attemptBatchMintWithMint()
    12. _attemptBatchMintWithMintSupra()
giovannifranchi commented 3 months ago

Variables in memory use 32 bytes in any case because of how Solidity works. Using a uint8 instead of a uint256 actually increases the cost of operations since under the hood solidity converts the uint8 in uint256. As an example a made a dummy contract which performs a for loop of 50 iterations.

test contract

As we can see the transaction cost of the loop performed with uint256 is 46538

uint256

while for uint8 is 46822

uint8

For what concerns ++i instead of i++ I can confirm there is a small gas saving (46538 - 46310 = 228) which could be considered negligible, especially considering contracts operate on L2s and the contract I made performs 50 iterations. Nonetheless I will apply this change.

incremental