Maia DAO - Ulysses - sivanesh_808's results

Harnessing the power of Arbitrum, Ulysses Omnichain specializes in Virtualized Liquidity Management.

General Information

Platform: Code4rena

Start Date: 22/09/2023

Pot Size: $100,000 USDC

Total HM: 15

Participants: 175

Period: 14 days

Judge: alcueca

Total Solo HM: 4

Id: 287

League: ETH

Maia DAO

Findings Distribution

Researcher Performance

Rank: 125/175

Findings: 1

Award: $17.71

Gas:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

17.7101 USDC - $17.71

Labels

bug
G (Gas Optimization)
grade-b
sufficient quality report
G-07

External Links

[G-1] State Variable Packing for Gas Optimization

Saves 10000

The _unlocked variable utilizes the value 1 to represent the state of the re-entrancy lock modifier. By employing uint96 for _unlocked, we can efficiently store it in a single slot, conserving gas.

FILE: src/BaseBranchRouter.sol

/// @notice Re-entrancy lock modifier state.
  -  uint256 internal _unlocked = 1;
  +  uint96 internal _unlocked = 1;

https://github.com/code-423n4/2023-09-maia/blob/main/src/BaseBranchRouter.sol#L42C36-L42C36

FILE: src/BranchPort.sol

/// @notice Reentrancy lock guard state.
  -  uint256 internal _unlocked = 1;
  + uint96 internal _unlocked = 1;

https://github.com/code-423n4/2023-09-maia/blob/main/src/BranchPort.sol#L91

FILE: src/MulticallRootRouter.sol

/// @notice Reentrancy lock guard state.
  -  uint256 internal _unlocked = 1;
  + uint96 internal _unlocked = 1;

https://github.com/code-423n4/2023-09-maia/blob/main/src/MulticallRootRouter.sol#L80

FILE: src/BranchBridgeAgent.sol

/// @notice Reentrancy lock guard state.
  -  uint256 internal _unlocked = 1;
  + uint96 internal _unlocked = 1;

https://github.com/code-423n4/2023-09-maia/blob/main/src/BranchBridgeAgent.sol#L101

FILE: src/RootBridgeAgent.sol

/// @notice Reentrancy lock guard state.
  -  uint256 internal _unlocked = 1;
  + uint96 internal _unlocked = 1;

https://github.com/code-423n4/2023-09-maia/blob/main/src/RootBridgeAgent.sol#L92

[G-2] Optimizing Loop Operations with Assembly

Employing inline assembly for loop operations in Solidity can lead to enhanced gas efficiency. Below is a demonstrative contract showcasing the conventional loop structure juxtaposed against its assembly-optimized counterpart.

Here is the example simulated using " for (uint256 i = 0; i < outputParams.outputTokens.length;)".

contract LoopSimulation { struct OutputParams { address[] outputTokens; } OutputParams public outputParams; uint256 public counter = 0; // Adding some dummy tokens for the simulation constructor() { outputParams.outputTokens.push(0x1111111111111111111111111111111111111111); outputParams.outputTokens.push(0x2222222222222222222222222222222222222222); // Add more if you want... } function loopSolidity() public { for (uint256 i = 0; i < outputParams.outputTokens.length;) { counter++; // dummy operation i++; } } function loopAssembly() public { assembly { let length := sload(outputParams.slot) // get the length of outputTokens array let i := 0 for { } lt(i, length) { } { // Increase the counter (assuming counter is the next slot in storage after outputParams) let currentCounterValue := sload(add(outputParams.slot, 1)) sstore(add(outputParams.slot, 1), add(currentCounterValue, 1)) // Increment i i := add(i, 1) } } } }

https://github.com/code-423n4/2023-09-maia/blob/main/src/MulticallRootRouter.sol#L278C13-L278C73

https://github.com/code-423n4/2023-09-maia/blob/main/src/RootBridgeAgentExecutor.sol#L281

https://github.com/code-423n4/2023-09-maia/blob/main/src/RootBridgeAgent.sol#L318

https://github.com/code-423n4/2023-09-maia/blob/main/src/BranchBridgeAgent.sol#L447

[G-3] <x> += <y> costs more gas than <x> = <x> + <y> for state variables

For state variables in Solidity, utilizing the compound assignment operator (e.g., +=) incurs a higher gas cost compared to explicitly reassigning the value with a standard operation (e.g., = <x> + <y>). This inefficiency stems from the EVM's underlying operations when handling compound assignments. Developers aiming for gas optimization should be cautious of this behavior and prefer direct assignments when updating state variables.

FILE: src/BranchPort.sol


         getPortStrategyTokenDebt[msg.sender][_token] += _amount;

https://github.com/code-423n4/2023-09-maia/blob/main/src/BranchPort.sol#L157

FILE: src/BranchPort.sol

 getTokenBalance[chainId] += amount;

https://github.com/code-423n4/2023-09-maia/blob/main/src/token/ERC20hTokenRoot.sol#L58

FILE: src/BranchPort.sol

 getStrategyTokenDebt[_token] -= _amount;
 

https://github.com/code-423n4/2023-09-maia/blob/main/src/BranchPort.sol#L172

FILE: src/BranchPort.sol

    getPortStrategyTokenDebt[msg.sender][_token] -= _amount;
 

https://github.com/code-423n4/2023-09-maia/blob/main/src/BranchPort.sol#L169

FILE: src/token/ERC20hTokenRoot.sol

           getTokenBalance[chainId] -= amount;
 

https://github.com/code-423n4/2023-09-maia/blob/main/src/token/ERC20hTokenRoot.sol#L70

[G-4] Dont catch immutables

The rationale behind this principle is that the Solidity compiler optimizes access to immutable state variables by embedding their values directly into the bytecode at deployment time

FILE: src/ArbitrumBranchPort.sol

        57.   address _rootPortAddress = rootPortAddress;

https://github.com/code-423n4/2023-09-maia/blob/main/src/ArbitrumBranchPort.sol#L57

FILE: src/ArbitrumBranchPort.sol

        80.   address _rootPortAddress = rootPortAddress;

https://github.com/code-423n4/2023-09-maia/blob/main/src/ArbitrumBranchPort.sol#L80

#0 - c4-pre-sort

2023-10-15T16:56:45Z

0xA5DF marked the issue as sufficient quality report

#1 - 0xA5DF

2023-10-15T16:56:47Z

G3 in bot report

#2 - c4-judge

2023-10-26T13:47:53Z

alcueca marked the issue as grade-b

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter