Superposition

Longtail, Arbitrum's cheapest most rewarding AMM, is the first AMM that pays you to use it, built on concepts like payment for orderflow.

  • Start date23 Aug 2024
  • End date13 Sep 2024
  • Total awards$60,750 in USDC
  • Duration21 days

Superposition audit details

  • Total Prize Pool: $60,750 in USDC
    • HM awards: $38,880 in USDC
    • QA awards: $1,620 in USDC
    • Judge awards: $7,000 in USDC
    • Scout awards: $750 in USDC
    • Validator awards: $3,500 USDC
    • Mitigation Review: $9,000 USDC (Opportunity goes to top 3 backstage wardens based on placement in this audit who RSVP.)
  • Read our guidelines for more details
  • Starts August 23, 2024 20:00 UTC
  • Ends September 13, 2024 20:00 UTC

Automated Findings / Publicly Known Issues

The 4naly3er report can be found here.

Note for C4 wardens: Anything included in this Automated Findings / Publicly Known Issues section is considered a publicly known issue and is ineligible for awards.

  • It is possible for someone to grief the protocol by creating a pool with bad configuration.
  • It is possible for the permissioned account to do things to grief the protocol.

Overview

Longtail is a concentrated liquidity AMM powered by Arbitrum Stylus. Arbitrum Stylus is a WASM frontend to the EVM on Arbitrum.

Longtail differs from a traditional V3 AMM in the following ways:

  1. One contract for everything: Liquidity is centralised in one contract.
  2. One shared asset between every pool: fUSDC is shared between every pool.
  3. Contract addresses are embedded in the compiled code: Contract addresses are set using environment variables.
  4. Native support for permit2: Permit2 is natively supported for a better UX.
  5. Diamond-like proxy for dispatch: A Solidity contract is used to delegatecall to different facets of the contract.

Links


Scope

See scope.txt

Files in scope

FileSLOC
pkg/sol/SeawaterAMM.sol396
pkg/sol/OwnershipNFTs.sol117
pkg/seawater/src/maths/sqrt_price_math.rs1239
pkg/seawater/src/lib.rs925
pkg/seawater/src/pool.rs490
pkg/seawater/src/wasm_erc20.rs332
pkg/seawater/src/maths/swap_math.rs316
pkg/seawater/src/tick.rs220
pkg/seawater/src/eth_serde.rs219
pkg/seawater/src/maths/tick_math.rs191
pkg/seawater/src/maths/bit_math.rs138
pkg/seawater/src/error.rs133
pkg/seawater/src/types.rs112
pkg/seawater/src/maths/full_math.rs106
pkg/seawater/src/position.rs91
pkg/seawater/src/host_erc20.rs58
pkg/seawater/src/maths/tick_bitmap.rs52
pkg/seawater/src/maths/liquidity_math.rs37
pkg/seawater/src/immutables.rs23
pkg/seawater/src/maths/utils.rs11
pkg/seawater/src/maths/mod.rs9
pkg/seawater/src/maths/unsafe_math.rs9
pkg/seawater/src/main.rs8
pkg/seawater/src/permit2_types.rs8
pkg/seawater/src/erc20.rs5
pkg/seawater/src/events.rs3
Total5248

Files out of scope

Any file not listed in the table above.

See also out_of_scope.txt

Scoping Q & A

General questions

QuestionAnswer
ERC20 used by the protocolModern USDC (Arbitrum deployed)
Test coverageN/A
ERC721 used by the protocolNone
ERC777 used by the protocolNone
ERC1155 used by the protocolNone
Chains the protocol will be deployed onSuperposition (Arbitrum Orbit chain)

ERC20 token behaviors in scope

External integrations (e.g., Uniswap) behavior in scope:

QuestionAnswer
Enabling/disabling fees (e.g. Blur disables/enables fees)No
Pausability (e.g. Uniswap pool gets paused)No
Upgradeability (e.g. Uniswap gets upgraded)No

EIP compliance checklist

N/A

Additional context

Main invariants

  • Only the owner can modify their positions.
  • Only valid tick ranges, and fee structures, are accessible.
  • Users should be able to swap a reasonable amount determined by the appropriate conversion function.
  • Users should receive a correct fee amount.
  • We should follow Uniswap V3's math faithfully.

Attack ideas (where to focus for bugs)

  • Fee taking for ticks is possibly incorrect. We have a deployment that initially had bad behaviour with delta that we suspect is the cause of the issue that we replicated locally, but we haven't verified if that's not the case.
  • Can people swap more than they should be able?
  • Does the position taking function take more than it should?
  • Is it possible to brick a pool with low liquidity?
  • Are our ticks correct?

All trusted roles in the protocol

RoleDescription
OperatorControls access to the repo, and implementation addresses.
Emergency CouncilCan shut the dapp down if needed.
NFT managerAllows addresses to control their ownership of assets as a NFT.

Describe any novel or unique curve logic or mathematical models implemented in the contracts:

Concentrated liquidity algorithms based on Uniswap.

Running tests

See pkg/README for a detailed explanation

Then run the following command:

https://github.com/code-423n4/2024-08-superposition
cd 2024-08-superposition/pkg
rustup target add wasm32-unknown-unknown
cargo install cargo-stylus
./tests.sh # this would test the rust files from the files in `tests`.

Some of the tests are expected to fail:

  1. eli_incr_position and incr_position_fee_growth_tick are issues that cropped up in production that we isolated by reproducing the remote state into our contracts. the production contract was deployed at one point with a change from the current version of this code that we believe may have contributed to causing this to happen.
  2. ethers_suite_uniswap_orchestrated_uniswap_two is possibly indicative of an issue. it needs investigation whether this is correct behaviour
  3. We left these tests for researchers to pore through and hopefully identify the root cause, the team hasn't succeeded so far.

Miscellaneous

Employees of Superposition and employees' family members are ineligible to participate in this audit.

Code4rena's rules cannot be overridden by the contents of this README. In case of doubt, please check with C4 staff.