BlockchainLabsNZ / mothership-sen

GNU General Public License v3.0
0 stars 0 forks source link

Gas costs can be reduced by using bytes32 instead of string in proxyMintTokens() #3

Open OperationNine opened 6 years ago

OperationNine commented 6 years ago

The proxyMintTokens function takes 2 parameters string _paidCurrency, string _paidTxID.

It is possible to save on gas costs each time this function is called by changing these parameters to bytes32 _paidCurrency, bytes32 _paidTxID.

This is because it is a cheaper form of storage in the EVM than by using strings.

The following simulation was taken on the Kovan test network using Parity with a gas price of 5 gwei and a simple minted transfer of 1 SEN token to an address.

Actual Tx Cost/Fee: 0.00111244 Ether using string https://kovan.etherscan.io/tx/0x44c7f293a71d59d8b1b484b3dcbcb59dc98a285afa9a765e3d3914c312312402

Actual Tx Cost/Fee: 0.001065065 Ether using bytes32 https://kovan.etherscan.io/tx/0x2ab0ebb8f2583a7e0682293f2cc09db36ace9e129125a9e3b068d941b4929c2b

This is a saving of 0.000047375 ETH each time tokens are minted.

If this is called 25,000 times for example this is a savings of 1.184375 ETH.

satyrius commented 6 years ago

I tried to follow your recomendation https://github.com/mothershipcx/sen-contracts/pull/2/commits/66159661b87857b8012a9aa514c081012f74d745, but got errors like

Error: The contract code couldn't be stored, please check your gas amount.
satyrius commented 6 years ago

Will optimize it here https://github.com/mothershipcx/sen-contracts/pull/4