Platform: Code4rena
Start Date: 13/11/2023
Pot Size: $24,500 USDC
Total HM: 3
Participants: 120
Period: 4 days
Judge: 0xTheC0der
Id: 306
League: ETH
Rank: 49/120
Findings: 1
Award: $19.04
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xSmartContract
Also found by: 0xbrett8571, 0xepley, Bauchibred, K42, Kose, MrPotatoMagic, Myd, Sathish9098, aariiif, cats, clara, emerald7017, fouzantanveer, hunter_w3b, invitedtea, unique
19.0443 USDC - $19.04
The system consists of two core components:
asD
Factory contract for creating ERC20 tokens pegged 1:1 to NOTE. Accrued interest goes to creator.
1155tech
ERC1155 contract for managing share tokens with bonded curves. Allows minting NFTs based on share ownership.
asD
The asD component provides a factory model for creating ERC20 tokens pegged 1:1 to NOTE. This allows anyone to launch their own "stablecoin" with the accrued interest going to the creator.
Some risks with this architecture:
Ideally access would be restricted only to a smart contract or DAO so supply cannot be arbitrarily manipulated. The contract would programmatically handle mint/burn/interest accrual.
An alternative would be to have a single asD token with governance control rather than a factory model. This provides more predictability for integrations.
1155tech
The bonding curve and NFT minting model provides an interesting way to tokenize shares with price discovery.
Some risks include:
Mitigations would be thoroughly auditing core accounting logic, restricting privileged roles, and evaluating bonding curve parameters. An overall risk is the untested nature of the incentive design.
Contract | Purpose | Key Risks |
---|---|---|
asD | Application specific stablecoin | Interest draining, peg breaking |
asDFactory | Token factory | Access control |
Market | Core 1155 logic | Accounting, access control |
LinearBondingCurve | Bonding curve contract | Price manipulation |
asD
withdrawInterest
could allow draining more than accrued interest, breaking 1:1 pegHighlighting the key risks.
asD
withdrawInterest
not checking maximum withdrawable amount
Root cause is lack of validation on the amount requested to withdraw
Could allow withdrawing more than accrued interest
Would drain reserve backing asD tokens
Breaks 1:1 peg invariant
No access controls
Root cause is lack of onlyOwner
or similar modifiers
Allows anyone to manipulate token supply
Attacker could mint unlimited tokens not backed 1:1
Same for burning/draining supply
Owner should be only one able to mint/burn/withdraw
Market
Buys not incrementing totals
Root cause is skipping the increment logic in buy
Allows buying shares without proper accounting
Impacts price and redemption amounts
Breaks outstanding tokens vs balance invariant
Sells not validating ownership
Root cause is lack of check against balanceOf
Allows selling/burning shares not owned
Impacts supply and enables value extraction
Excessive platform owner privileges
Root cause is overuse of Ownable
pattern
Gives centralized platform owner excessive control
Increases risk from compromise or malicious owner
Bonding Curves
Manipulated oracle input
Root cause is relying on untrusted oracles
Attacker can influence input to manipulate price
Can exploit arbitrage opportunities
Can profit at expense of users
Market
Bonding Curves
Component | Description |
---|---|
asDFactory | Factory contract for creating new asD ERC20 tokens |
asD | ERC20 token contract representing an application specific dollar |
Market | Core 1155tech contract for managing shares and bonding curves |
BondingCurve | Contracts defining bonding curve shapes, e.g. linear, exponential etc |
CLendingMarket | Compound lending market for supplying assets and accruing interest |
ERC20 | Standard interface for fungible tokens |
ERC1155 | Standard interface for semi-fungible tokens |
NOTE | Protocol's native stablecoin used for payments |
Key Interactions
asD - withdrawInterest
Overdrain
The issue arises in withdrawCarry()
function.
// @anlysis asD.sol function withdrawCarry(uint256 _amount) external onlyOwner { // ... if (_amount == 0) { _amount = maximumWithdrawable; } // ... }
By allowing _amount = maximumWithdrawable
, it could drain all reserves.
Market - Missing Buy Increments
The buy accounting is skipped here.
// @anlysis Market.sol function buy(uint256 _id, uint256 _amount) external { // ... // MISSING: // shareData[_id].tokenCount += _amount; // shareData[_id].tokensInCirculation += _amount; // ... }
The increments needed after transfer is missing.
BondingCurve - Manipulated Oracle
The manipulated price input.
// BondingCurve.sol function getPrice() external view returns (uint256) { // UNTRUSTED ORACLE return SomeOracle.getLatestPrice() }
By relying on the oracle without validation, manipulation can happen.
Drain asD Reserves
Attacker notices withdrawInterest
lacks proper validation
Attacker takes out a flash loan for 1,000,000 NOTE
Attacker mints 1,000,000 asD tokens with the loaned NOTE
Attacker calls withdrawInterest
with _amount
= 1,000,000
The full 1,000,000 NOTE is withdrawn without checking reserves
Attacker pays back flash loan, profiting from drained reserves
Frontrun Market Trades
Attacker sees a pending transaction with a buy for a large amount of shares
Attacker quickly executes transactions to purchase some shares prior to the large buy
The large buy goes through at the higher price due to the attacker's actions
Attacker sells their shares at the inflated price back to the market
Attacker profits from the price impact of their frontrunning
Severity
Market - Missing ownership validation in sells
Severity: Critical
Allows extracting value by selling/burning any amount of unowned tokens
asD - Interest draining vulnerability
Severity: High
Could break 1:1 peg backing assets
Market - Missing buy accounting
Severity: Medium
Impacts share price accuracy over time
BondingCurve - Manipulated oracle
Severity: Medium
Enables price manipulation and arbitrage
Likelihood
Market - Missing ownership validation
asD - Interest draining
BondingCurve - Manipulated oracle
Market - Missing buy accounting
In summary, the missing sell-side ownership validation in Market should be the top priority to address due to its high severity and likelihood. Interest draining in asD is also a key issue to resolve urgently due to severity, even if likelihood is lower.
ERC20/ERC1155 Compliance
asD correctly implements transfer
, transferFrom
, approve
, etc per ERC20.
Market implements safeTransferFrom
and other ERC1155 methods properly.
No major issues found with token standards compliance.
OWASP Top 10
A3: Injection - good use of SafeMath protects against overflows.
A5: Broken Access Controls - major issue identified in lack of ownership validation.
A7: XSS - No exposure to web transactions reduces this.
A10: Insufficient Logging & Monitoring - Lack of events for state changes is a risk.
Overall, the major gaps are around access controls and monitoring. The OWASP Top 10 highlights the lack of access restrictions in critical functions. More event emitting would help with monitoring.
Other Best Practices
Use of SafeMath is good where needed.
Lack of trust minimization mechanisms like rate limiting.
No emergency stop / circuit breaker logic.
Critical privilege concentration in owner roles.
Lack of reentrancy guards on external calls.
Additional work on access control segmentation, trust minimization, emergency controls, and authorizer role separation would bring the contracts more in line with industry best practices.
NatSpec Documentation
NatSpec used for some functions but not comprehensively.
Adding NatSpec comments to all functions would improve visibility into expected behavior.
Param and return tags should be added documenting the role and nature of all parameters and return values.
@dev tags should provide a concise explanation of the logic.
General Documentation
Additional documentation on architecture, flows, and authorization roles would be beneficial.
Spelling out example usage for end users would improve usability.
Known limitations and quirks could be documented to set expectations.
In the current Canto Application Specific Dollars and Bonding Curves for 1155s system architecture, there are notable points of centralization, and the concentration of trust primarily lies in the following aspects:
asDFactory Ownership:
asDFactory
contract is initially concentrated in a single entity. This entity has the ability to deploy new instances of the asD
contract. If this ownership is compromised or misused, it could lead to the unauthorized deployment of potentially malicious or flawed asD
contracts.Market Admin Functions:
Market
contract employs the Ownable pattern, concentrating ownership in a single address. This owner has significant control over critical administrative functions, such as withdrawing fees, toggling trading, and other platform-related operations. If the owner's private key is compromised, it poses a risk to the overall functionality and security of the Market
contract.Bonding Curve Oracles:
Market
contract relies on external oracles. The trust is concentrated in the accuracy and reliability of these oracles. If the oracles provide manipulated or inaccurate price data, it could lead to a mispricing of shares, affecting the entire system.To enhance decentralization and distribute trust more broadly, consider the following strategies:
asDFactory Governance:
asDFactory
contract. This could involve transitioning control to a DAO or a multi-signature scheme where key decisions, such as deploying new contracts, require the consensus of multiple participants.Market Admin Functions and RBAC:
Market
contract with a Role-Based Access Control (RBAC) system. Instead of a single owner, assign different roles with specific permissions. For example, roles could include an administrator for critical functions, a moderator for day-to-day operations, and a governance role for key decisions. RBAC distributes control and reduces the risk associated with a single point of compromise.Decentralized Oracle Networks:
Community Governance and Participation:
Smart Contract Upgradeability:
Transparency and Communication:
I believe by adopting these strategies, trust can be distributed more evenly among participants in the system, reducing the risk of central points of failure and enhancing the overall decentralization of the protocol.
Reduce Centralization Risks
Improve Validation
Harden Access Controls
Monitor Operations
10 hours
#0 - c4-judge
2023-11-29T20:34:33Z
MarioPoneder marked the issue as grade-c
#1 - c4-judge
2023-11-29T20:51:41Z
MarioPoneder marked the issue as grade-b