// Reverts if payment amount does not equal price of fractional amount
if (msg.value != fractionPrice * _amount) revert InvalidPayment();
//3589182 before
can be saving lot gas by doing this :
uint256 ethAmount = fractionPrice * _amount;
// Reverts if payment amount does not equal price of fractional amount
if (msg.value != fractionPrice * _amount) revert InvalidPayment();
//3587236 after
This can be saving a lot of gas consumtion.
Tool Used
Remix
Caching in calldata than memory for saving more gas
Using i++ instead ++i for all the loops, the variable i is incremented using i++. It is known that implementation by using ++i costs less gas per iteration than i++.
src/Vault.sol#L78 for (uint256 i = 0; i < length; i++) {
src/Vault.sol#L104 for (uint256 i = 0; i < length; i++) {
change uint256 i = 0 into uint i for saving more gas
using this implementation can saving more gas for each loops.
src/Vault.sol#L78 for (uint256 i = 0; i < length; i++) {
src/Vault.sol#L104 for (uint256 i = 0; i < length; i++) {
src/utils/MerkleBase.sol#L51 for (uint256 i = 0; i < _proof.length; ++i) {
src/modules/protoforms/BaseVault.sol#L83 for (uint256 i = 0; i < _tokens.length; ) {
src/modules/protoforms/BaseVault.sol#L107 for (uint256 i = 0; i < _tokens.length; ++i) {
/// @notice Address of VaultRegistry contract
address public registry;
/// @notice Address of Supply target contract
address public supply;
Saving gas by removing = 0
This implementation code can be saving more gas by removing = 0, it because If a variable was not set/initialized, it is assumed to have default value to 0
fractionPrice * _amount
can saving more gashttps://github.com/code-423n4/2022-07-fractional/blob/e2c5a962a94106f9495eb96769d7f60f7d5b14c9/src/modules/Buyout.sol#L165
can be saving lot gas by doing this :
This can be saving a lot of gas consumtion.
Tool Used
Remix
calldata
thanmemory
for saving more gas1) File : Metadata.sol Line.24
2) MerkleBase.sol Line.45
++i
thani++
for cost less gasUsing
i++
instead++i
for all the loops, the variable i is incremented using i++. It is known that implementation by using++i
costs less gas per iteration thani++
.uint256 i = 0
intouint i
for saving more gasusing this implementation can saving more gas for each loops.
1) File : Minter.sol Line.14
2) File : Migration.sol Line.39
3) File : Buyout.sol Line.28-31
= 0
This implementation code can be saving more gas by removing = 0, it because If a variable was not set/initialized, it is assumed to have default value to 0
1) File : Migration.sol Line.157
2) File : Migration.sol Line.161
3) File : Migration.sol Line.310
4) File : Migration.sol Line.323
https://github.com/code-423n4/2022-07-fractional/blob/e2c5a962a94106f9495eb96769d7f60f7d5b14c9/src/interfaces/IBuyout.sol
packing struct order by doing an practice down below :
this can be gas saving if this contract called mutiple times.
7.) Short reason string can be used for saving more gas
Every reason string takes at least 32 bytes. Use short reason strings that fits in 32 bytes or it will become more expensive.