Skip to content

Latest commit

 

History

History
64 lines (42 loc) · 2.38 KB

File metadata and controls

64 lines (42 loc) · 2.38 KB

Fast Khaki Raccoon

Medium

System will stop working after a hard fork

Summary

Although they are rare, they happen about 2 or 3 times a year, with 2024 having Cancun + Deneb, 2023 with Shanghai + Capella, and so on...

However the current system is not made to work with these changes properly as around the codebase we check for if the chain is a specific ID, instead of having configurable mappings.

As we can see from the bellow code we check if the chainid is 1, and if not we use the other fee. https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/DecentralizedIndex.sol#L198

        uint256 _min = block.chainid == 1 
            ? _lpBal / 1000 
            : _lpBal / 4000; // 0.1%/0.025% LP bal

However after a hard fork on ETH, everything will be the same, but the chainId will change, meaning that we would pick a _min that is way smaller than the one that was used a few blocks back. This of course will spend enormous amounts of gas as now the min limit for swamping is less, meaning more swaps will occur.

Root Cause

The code snippet bellow that has a hard-coded check: https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/DecentralizedIndex.sol#L198

        uint256 _min = block.chainid == 1 
            ? _lpBal / 1000 
            : _lpBal / 4000; // 0.1%/0.025% LP bal

Internal Pre-conditions

No response

External Pre-conditions

No response

Attack Path

  1. ETH has a hard fork
  2. ChainId splits, new fork gets 1, old gets another number
  3. Old fork now has min set to 4 times less, performing 4x (or more) swaps, costing enormous amounts of gas for the users (eth is not cheap)

Impact

After a hard fork on ETH, everything will be the same, but the chainId will change, meaning that we would pick a _min that is way smaller than the one that was used a few blocks back. This of course will spend enormous amounts of gas as now the min limit for swamping is less, meaning more swaps will occur.

https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/DecentralizedIndex.sol#L198

        uint256 _min = block.chainid == 1 
            ? _lpBal / 1000 
            : _lpBal / 4000; // 0.1%/0.025% LP bal

PoC

No response

Mitigation

Use configurable mappings to set and manage the min amounts per contract.