Platform: Code4rena
Start Date: 27/11/2023
Pot Size: $36,500 USDC
Total HM: 0
Participants: 22
Period: 8 days
Judge: 0xA5DF
Id: 308
League: ETH
Rank: 11/22
Findings: 1
Award: $437.36
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: Sathish9098
Also found by: 0xSmartContract, 0xepley, LinKenji, Myd, ZanyBonzy, albahaca, alexbabits, clara, foxb868, invitedtea, oakcobalt, peanuts
437.363 USDC - $437.36
Contract | SLOC | Purpose | Libraries used |
---|---|---|---|
Ocean.sol | 561 | The accounting engine of the shell protocol | @openzeppelin/* |
Curve2PoolAdapter.sol | 139 | Adapter that enables integration with the curve 2 pool | @openzeppelin/* |
CurveTricryptoAdapter.sol | 199 | Adapter that enables integration with the curve tricrypto pool | @openzeppelin/* |
OceanAdapter.sol | 94 | Helper contract for the adapters | @openzeppelin/* |
Core Components
Ocean.sol
- Main protocol contract that handles all key logicOceanERC1155.sol
- Custom ERC-1155 ledger for accountingInteractions.sol
- Defines types of interoperability interactionsIOceanPrimitive.sol
- Interface for primitive contractsIOceanInteractions.sol
- User-facing interaction interfaceInteraction Execution
The Ocean
contract contains the main logic for managing end-to-end interactions. This includes:
Adapter Integration
OceanAdapter.sol
provides a standard interface and utilities for connecting external protocols as Ocean primitives via adaptersCurve2PoolAdapter
inherit this base functionalitywrapToken
, unwrapToken
etc. to bridge protocols into OceanManaging State
OceanERC1155
ledger maintains mapping from oceanIds to user balancesModular Framework
Core Accounting
Composable Balances
Modular Adapters
Ensuring Consistency
The Owner Privileges
The Ocean contract grants significant, unchecked privileges to the owner address which creates centralization risks:
Owner can update the unwrapping fee without any timelock or oversight via changeUnwrapFee. This could be abused to extract value from users.
Ownership is non-transferrable. The owner address is the only one able to exercise privileged functions. This presents availability and maintenance risks if the key is lost or compromised.
No recovery mechanisms are baked into the core protocol. There are no checkpoints or backstops that could reconstitute Ocean state in disastrous scenarios like critical bugs or ownership key loss.
Mitigations
Institute a reasonable timelock like 2 weeks for unwrapping fee changes
Build an ownership transfer mechanism to decentralize control. Require timelock and staged transfers.
Implement privileged roles using a multi-signature scheme rather than solo owner.
Add a pause mechanism to freeze critical logic if bugs are found.
Explore decentralized checkpoint schemes to enable state recovery if needed.
Wrap Flows
Unwrap Fee Math
Reentrancy Surface
Callbacks
Malicious Tokens/Adapters
Interleaved Call Risks
Lack of Upgradeability
Impacts across protocol from malicious tokens or adapters
Cascading failures if interleaved call assumptions violated
Lack of upgradeability limits ability to fix issues
Mitigations
Safety Through Reverting Callbacks
The Ocean protocol relies heavily on callbacks that are expected to revert when invalid states are detected.
A prime example is the checks on whether to accept/reject incoming token transfers during wrapping flows. The Ocean calls:
ERC1155.safeTransferFrom(userAddress, Ocean, ...) ERC721.safeTransferFrom(userAddress, Ocean, ...)
Risks from Callback Failures
However, any bugs or unexpected exceptions in these callback handlers could lead to disabled or bypassable checks.
For example, an ERC721 may have a bug that fails to validate ownership correctly and does not revert when expected. This would result in minting invalid Ocean balance for the user.
Similarly exception conditions may lead to disabled validation logic.
Mitigations
Every callback handler and integration point needs to undergo rigorous code review, fuzz testing and edge case enumeration before reliance.
Critical callback code should have formal verification if possible.
Wrapped token contracts must be evaluated for risks of buggy/exception-prone transfer logic.
Ocean Core Contract - Implements protocol logic for managing interactions, accounting etc.
OceanERC1155 Ledger - Custom ERC-1155 contract to track user balances
Adapters - Bridge external protocols into Ocean framework
Primitives - External protocols like AMMs exposed through adapters
Wrapping Assets
User calls Ocean contract to wrap an external asset (e.g. ERC20 token)
Ocean initiates a pull-payment style transfer from user's wallet
External token contract transfers tokens to Ocean
Ocean mints corresponding balances to user's account in OceanERC1155 ledger
Executing Interactions
User calls Ocean contract specifying an interaction (e.g. swap via adapter)
Ocean unpacks interaction details and makes external adapter call
Adapter executes transaction on target primitive (e.g. Curve)
Ocean updates user's balances based on interaction output
Unwrapping Assets
User calls Ocean to unwrap their wrapped balance
Ocean burns user's balance from OceanERC1155 ledger
Ocean pushes unwrapped amount back to user's wallet
User now has external asset balance again
Ocean.sol
OceanERC1155.sol
Interactions.sol
IOceanPrimitive.sol
IOceanInteractions.sol
Overall
41 hours
#0 - c4-pre-sort
2023-12-10T16:48:51Z
raymondfam marked the issue as sufficient quality report
#1 - c4-judge
2023-12-17T11:43:07Z
0xA5DF marked the issue as grade-a