You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
VotingEscrow.sol:309: for (uint256 i = 0; i < 255; i++) {
VotingEscrow.sol:717: for (uint256 i = 0; i < 128; i++) {
VotingEscrow.sol:739: for (uint256 i = 0; i < 128; i++) {
VotingEscrow.sol:834: for (uint256 i = 0; i < 255; i++) {
you are saving gas on solidity not checking on an overflow
VotingEscrow.sol:309: for (uint256 i = 0; i < 255; i++) {
VotingEscrow.sol:717: for (uint256 i = 0; i < 128; i++) {
VotingEscrow.sol:739: for (uint256 i = 0; i < 128; i++) {
VotingEscrow.sol:834: for (uint256 i = 0; i < 255; i++) {
The text was updated successfully, but these errors were encountered:
Using bools for storage incurs overhead
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
make i++ into ++i to save 3 gas on a copy
save gas by making
require (uint amount >0);
intorequire (!= 0);
because a uint is ether 0 or greater so it saves gas .
https://github.com/code-423n4/2022-08-fiatdao/blob/5a254ab15a387bd65a7dc50ac8371cb77de1e5d5/contracts/VotingEscrow.sol#L448
use custom errors instead require to save gas
make address(0) into long form to save gas
ex: 0x00000000000000
USE ASSEMBLY TO CHECK FOR ADDRESS(0)
ex: iszero
FUNCTIONS GUARANTEED TO REVERT WHEN CALLED BY NORMAL USERS CAN BE MARKED PAYABLE
If a function modifier such as onlyOwner is used, the function will revert if a normal user tries to pay the function. Marking the function as payable will lower the gas cost for legitimate callers because the compiler will not include checks for whether a payment was provided. The extra opcodes avoided are CALLVALUE(2),DUP1(3),ISZERO(3),PUSH2(3),JUMPI(10),PUSH1(3),DUP1(3),REVERT(0),JUMPDEST(1),POP(2), which costs an average of about 21 gas per call to the function, in addition to the extra deployment cost.
https://github.com/code-423n4/2022-08-fiatdao/blob/5a254ab15a387bd65a7dc50ac8371cb77de1e5d5/contracts/VotingEscrow.sol#L142
https://github.com/code-423n4/2022-08-fiatdao/blob/5a254ab15a387bd65a7dc50ac8371cb77de1e5d5/contracts/VotingEscrow.sol#L146
https://github.com/code-423n4/2022-08-fiatdao/blob/5a254ab15a387bd65a7dc50ac8371cb77de1e5d5/contracts/VotingEscrow.sol#L156
make i unchecked when it wont overflow
you are saving gas on solidity not checking on an overflow
The text was updated successfully, but these errors were encountered: