code-423n4 / 2024-04-coinbase-mitigation-findings

0 stars 0 forks source link

ADD-02 MitigationConfirmed #17

Open c4-bot-8 opened 7 months ago

c4-bot-8 commented 7 months ago

Lines of code

Vulnerability details

Issue Report

ADD-02: Gas Fixes 2

Details

Issue#195

Issue#38

Gas optimizations:

[Issue#38] unchecked loop increments no valid in solidity > v0.8.22

[G-01] Update storage variable once outside of the loop instead of updating it every time in loop it saves 1 SSTORE, 1 SLOAD per iteration(Saves ~2200 Gas per iteration)

[G-03] Call _getMultiOwnableStorage() one time to fetch storage pointer and avoid extra internal function call

[G-09] Do not assign a variable with its default value

Mitigation

PR#45

Loc:

function executeBatch(Call[] calldata calls) public payable virtual onlyEntryPointOrOwner {
        for (uint256 i; i < calls.length; i++) {
            _call(calls[i].target, calls[i].value, calls[i].data);
        }
    }

Loc:

function _initializeOwners(bytes[] memory owners) internal virtual {
        uint256 nextOwnerIndex_ = _getMultiOwnableStorage().nextOwnerIndex;
        for (uint256 i; i < owners.length; i++) {
            if (owners[i].length != 32 && owners[i].length != 64) {
                revert InvalidOwnerBytesLength(owners[i]);
            }

            if (owners[i].length == 32 && uint256(bytes32(owners[i])) > type(uint160).max) {
                revert InvalidEthereumAddressOwner(owners[i]);
            }

            _addOwnerAtIndex(owners[i], nextOwnerIndex_++);
        }
        _getMultiOwnableStorage().nextOwnerIndex = nextOwnerIndex_;
    }

Loc:

function _initializeOwners(bytes[] memory owners) internal virtual {
        MultiOwnableStorage storage $ = _getMultiOwnableStorage();
        uint256 nextOwnerIndex_ = $.nextOwnerIndex;
        for (uint256 i; i < owners.length; i++) {
            if (owners[i].length != 32 && owners[i].length != 64) {
                revert InvalidOwnerBytesLength(owners[i]);
            }

            if (owners[i].length == 32 && uint256(bytes32(owners[i])) > type(uint160).max) {
                revert InvalidEthereumAddressOwner(owners[i]);
            }

            _addOwnerAtIndex(owners[i], nextOwnerIndex_++);
        }
        $.nextOwnerIndex = nextOwnerIndex_;
    }

Loc:

(name, version) = _domainNameAndVersion();
        chainId = block.chainid;
        verifyingContract = address(this);
        salt = salt; // `bytes32(0)`.
        extensions = extensions; // `new uint256[](0)`.

Conclusion

Gas optimizations identified have been applied successfully.

c4-judge commented 7 months ago

3docSec marked the issue as confirmed for report

c4-judge commented 7 months ago

3docSec marked the issue as satisfactory