Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas Optimizations #115

Open
code423n4 opened this issue Aug 3, 2022 · 2 comments
Open

Gas Optimizations #115

code423n4 opened this issue Aug 3, 2022 · 2 comments
Labels
bug Something isn't working G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons

Comments

@code423n4
Copy link
Contributor

Title: Gas savings for using solidity 0.8.10

Proof of Concept:
all contract

Recommended Mitigation Steps:
Consider to upgrade pragma to at least 0.8.10.

Solidity 0.8.10 has a useful change which reduced gas costs of external calls
Reference: here


Title: abi.encode() is less efficient than abi.encodePacked()

Proof of Concept:
AxelarAuthWeighted.sol#L32


Title: Default value initialization

Impact:
If a variable is not set/initialized, it is assumed to have the default value (0, false, 0x0 etc depending on the data type). Explicitly initializing it with its default value is an anti-pattern and wastes gas.

Proof of Concept:
AxelarAuthWeighted.sol#L68-L69
AxelarAuthWeighted.sol#L94-L98

Recommended Mitigation Steps:
Remove explicit initialization for default values.


Title: Using unchecked and prefix increment is more effective for gas saving:

Proof of Concept:
AxelarAuthWeighted.sol#L69
AxelarAuthWeighted.sol#L98
AxelarDepositService.sol#L114
AxelarDepositService.sol#L168
AxelarDepositService.sol#L204
AxelarGasService.sol#L123

Recommended Mitigation Steps:
Change to:

    for (uint256 i = 0; i < weightsLength;) {
          // ... 
    unchecked { ++i; }
      }

Title: Cheaper to use ++ instead + 1

Proof of Concept:
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L636

Recommended Mitigation Steps:

        uint256 epoch = ++currentEpoch;


Title: Caching length for loop can save gas

Proof of Concept:
AxelarDepositService.sol#L114
AxelarDepositService.sol#L168
AxelarDepositService.sol#L204
AxelarAuthWeighted.sol#L116
AxelarGasService.sol#L123

Recommended Mitigation Steps:
Change to:

	uint256 Length = refundTokens.length;
	for (uint256 i; i < Length; i++) {

Title: Comparison operators

Proof of Concept:
AxelarAuthWeighted.sol#L117

Recommended Mitigation Steps:
Replace <= with <, and >= with > for gas optimization


Title: Expression for constant values such as a call to keccak256(), should use immutable rather than constant

Proof of Concept:
AxelarGateway.sol#L27-L43

Recommended Mitigation Steps:
Change from constant to immutable
reference: here


@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Aug 3, 2022
code423n4 added a commit that referenced this issue Aug 3, 2022
@re1ro
Copy link
Member

re1ro commented Aug 5, 2022

1

Good spot

2

Not applicable
abi.encode() is less secure than abi.encodePacked()

3 - 7

Dup #2

8

Dup #113

@GalloDaSballo
Copy link
Collaborator

Title: Expression for constant values such as a call to keccak256(), should use immutable rather than constant

Nope, constant / immutable save the same gas (except minor gas during deployment)
https://twitter.com/GalloDaSballo/status/1543729080926871557

Rest will save less than 300 gas

@re1ro re1ro added the sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons label Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Projects
None yet
Development

No branches or pull requests

3 participants