Maia DAO - Ulysses - Myd'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: 149/175

Findings: 1

Award: $11.47

QA:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Lines of code

https://github.com/code-423n4/2023-09-maia/blob/f5ba4de628836b2a29f9b5fff59499690008c463/src/RootBridgeAgent.sol#L966-L978 https://github.com/code-423n4/2023-09-maia/blob/f5ba4de628836b2a29f9b5fff59499690008c463/src/RootBridgeAgent.sol#L1045-L1064

Vulnerability details

Impact

The _createSettlement and _createSettlementMultiple functions increment the settlementNonce state variable using a simple addition. This can cause an integer overflow when the nonce reaches the maximum uint32 value.

  • Will result in nonce resetting from very high values to 0.
  • Can lead to nonce collisions between settlements.
  • Causes errors and failures in settlement handling.

Proof of Concept

The settlement nonce increment in _createSettlement is done using a simple increment. This could overflow eventually. https://github.com/code-423n4/2023-09-maia/blob/f5ba4de628836b2a29f9b5fff59499690008c463/src/RootBridgeAgent.sol#L966-L978

The settlement nonce increment in _createSettlementMultiple is done using a simple increment. This could overflow eventually. https://github.com/code-423n4/2023-09-maia/blob/f5ba4de628836b2a29f9b5fff59499690008c463/src/RootBridgeAgent.sol#L1045-L1064

The nonce increment logic occurs at these lines:

// RootBridgeAgent.sol

function _createSettlement(...) internal returns (bytes memory) {

  // ...

  // Issue is here:
  settlementNonce = settlementNonce + 1;

  // ...

}

function _createSettlementMultiple(...) internal returns (bytes memory) {
  
  // ...

  // Issue is also here:
  settlementNonce = settlementNonce + 1;  

  // ...

}

The settlementNonce is incremented using a simple addition.

This could eventually overflow, especially if the contract is long-lived.

A more in-depth of how the settlement nonce increment can overflow.

The nonce increment logic:

uint32 public settlementNonce;

function _createSettlement

function _createSettlement() internal {
  // Increment 
  settlementNonce = settlementNonce + 1; 
}

The settlementNonce variable is a uint32.

This means it can hold values between 0 and 2^32 - 1.

When it reaches the max value 2^32 - 1, incrementing will overflow.

  • For example:

    • If settlementNonce is 4294967295 (2^32 - 1)

    • settlementNonce + 1 overflows to 0

Proof of overflow:

Let's assume settlementNonce = 4294967295  (2^32 - 1)

settlementNonce + 1 

= 4294967295 + 1
= 4294967296

But uint32 can only hold values up to 2^32 - 1.

So 4294967296 overflows and loops back to 0.

Impact of overflow:

  • This causes the nonce to reset from very high values to 0.

  • Could result in nonce collisions.

  • Two settlements end up with the same nonce, leading to errors.

Tools Used

Manual Inspection

A better approach would be to use the SafeMath library's add function:

settlementNonce = settlementNonce.add(1); 

This prevents overflow issues.

Assessed type

Under/Overflow

#0 - c4-pre-sort

2023-10-10T06:33:46Z

0xA5DF marked the issue as duplicate of #834

#1 - c4-pre-sort

2023-10-10T06:33:54Z

0xA5DF marked the issue as sufficient quality report

#2 - c4-judge

2023-10-25T13:37:13Z

alcueca changed the severity to QA (Quality Assurance)

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