Canto Application Specific Dollars and Bonding Curves for 1155s - clara's results

Tokenizable bonding curves using a Stablecoin-as-a-Service token

General Information

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

Canto

Findings Distribution

Researcher Performance

Rank: 51/120

Findings: 1

Award: $19.04

Analysis:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

19.0443 USDC - $19.04

Labels

analysis-advanced
grade-b
A-02

External Links

Approach Taken in Evaluating the Codebase:

I thoroughly examined the provided Solidity contracts—Market.sol, LinearBondingCurve.sol, asD.sol, and asDFactory.sol. My evaluation involved scrutinizing the code structure, identifying potential security flaws, and considering adherence to best practices. I focused on understanding the functionality of each contract, potential vulnerabilities, and the overall security architecture.

Architecture Recommendations:

  1. Market.sol:

    • Strengths:
      • Well-structured with established libraries and patterns.
      • Utilizes SafeERC20 for secure interaction with ERC20 tokens.
    • Recommendations:
      • Consider adding additional access control mechanisms to enhance security.
      • Perform a thorough security audit to identify and address any hidden vulnerabilities.
  2. LinearBondingCurve.sol:

    • Strengths:
      • Implements a linear bonding curve model for determining the relationship between price and supply.
    • Recommendations:
      • Address potential gas limit issues in the getPriceAndFee function, especially if the amount parameter is excessively large.
      • Consider using high-level Solidity code instead of inline assembly for better readability.
  3. asD.sol:

    • Strengths:
      • Implements an ERC20 token contract with ownership functionality.
      • Enforces a 1:1 cNote:asD exchange rate.
    • Recommendations:
      • Add checks to ensure the legitimacy and safety of the cNote token contract.
      • Implement a pause or emergency stop functionality in case of discovered bugs or security vulnerabilities.
  4. asDFactory.sol:

    • Strengths:
      • Uses Ownable2Step for basic access control mechanisms.
      • Creates new asD tokens and maintains a record of them.
    • Recommendations:
      • Avoid using tx.origin in the constructor; consider using msg.sender for better security practices.
      • Reevaluate the use of the hard-coded address of the Turnstile contract and assess potential risks.

Codebase Quality Analysis:

let's dive into the Codebase Quality Analysis section for each contract:

Market.sol:

How it Works:

  • The Market contract facilitates the trading of shares and NFTs represented as ERC1155 tokens.
  • A bonding curve determines share prices, and users can buy/sell shares, convert them into NFTs, and burn NFTs to reclaim shares.
  • Fee mechanism charges fees on share transactions, distributed among the platform, share creators, and holders.
  • Access controls restrict new share creation to the contract owner and whitelisted addresses.

Security Issues:

  • No major security issues identified.

Recommendations:

  • Enhance access controls for critical functions.
  • Perform a comprehensive security audit to uncover potential vulnerabilities.

LinearBondingCurve.sol:

How it Works:

  • Implements a linear bonding curve model where share prices increase linearly with the number of shares.
  • getPriceAndFee calculates the price and fee for a given number of shares using a loop.
  • getFee calculates fees based on a logarithmic function.

Security Issues:

  • Potential gas limit issue in getPriceAndFee due to the use of a loop.
  • Inline assembly in log2 might reduce code readability.

Recommendations:

  • Address gas limit concerns in getPriceAndFee.
  • Consider refactoring inline assembly for better readability.

asD.sol:

How it Works:

  • asD is an ERC20 token with ownership functionality.
  • It interacts with cNote for a 1:1 mint/burn exchange rate.
  • The contract owner can withdraw accrued interest ("carry") with limitations.

Security Issues:

  • Lack of checks for the legitimacy of the cNote token contract.
  • Missing emergency stop functionality.

Recommendations:

  • Implement checks for the legitimacy of the cNote token contract.
  • Add an emergency stop mechanism to handle unforeseen circumstances.

asDFactory.sol:

How it Works:

  • asDFactory creates and tracks asD tokens.
  • Uses Ownable2Step for access control.
  • Registers the contract creator with a Turnstile contract based on the chain ID.

Security Issues:

  • Use of tx.origin in the constructor.
  • Potential risks associated with the hard-coded Turnstile contract address.

Recommendations:

  • Replace tx.origin with msg.sender.
  • Reevaluate the necessity of hard-coding Turnstile contract addresses.

Centralization Risks:

Market.sol:

  • Observation: The contract allows only the owner and whitelisted addresses to create new shares.
  • Risk: Centralized control over new share creation can introduce a single point of failure and dependency on the owner.
  • Recommendation: Consider implementing a decentralized governance mechanism for new share creation, reducing centralization risks.

asDFactory.sol:

  • Observation: Registration of the contract creator (tx.origin) with a Turnstile contract is hard-coded based on the chain ID.
  • Risk: Hard-coded addresses may pose security risks if the Turnstile contract is untrusted or vulnerable.
  • Recommendation: Enhance decentralization by making the registration process more dynamic and adaptable.

Mechanism Review:

Market.sol:

  • Observation: The bonding curve mechanism determines share prices and fees for transactions.
  • Review: The bonding curve and fee distribution mechanisms appear effective.
  • Recommendation: Continuous monitoring and potential adjustments based on market conditions.

LinearBondingCurve.sol:

  • Observation: Implements a linear bonding curve model with a logarithmic fee calculation.
  • Review: Linear bonding curve and fee calculation mechanisms are straightforward.
  • Recommendation: Consider extending bonding curve options for future flexibility.

asD.sol:

  • Observation: Implements a 1:1 mint/burn exchange rate with cNote tokens and controlled interest withdrawal.
  • Review: The mint/burn mechanism and interest withdrawal restrictions are well-structured.
  • Recommendation: Continue monitoring for potential refinements based on changing market conditions.

asDFactory.sol:

  • Observation: Creates and tracks asD tokens with basic access controls.
  • Review: The token creation mechanism and access controls are reasonable.
  • Recommendation: Consider adding more sophisticated access control mechanisms as the platform evolves.

Systemic Risks:

Market.sol:

  • Observation: The contract includes a variety of events and modifiers for various actions.
  • Risk: Complex event handling and modifier usage could introduce unforeseen systemic risks.
  • Recommendation: Conduct extensive testing, including stress tests, to identify and mitigate potential systemic risks.

LinearBondingCurve.sol:

  • Observation: Gas limit issue in getPriceAndFee and the use of inline assembly in log2.
  • Risk: Gas limit issues could render functions uncallable; inline assembly may reduce code readability.
  • Recommendation: Optimize getPriceAndFee to handle potential gas limit concerns; evaluate alternatives to improve inline assembly readability.

asD.sol:

  • Observation: Lack of checks for the legitimacy of the cNote token contract.
  • Risk: Interacting with untrusted or malicious cNote contracts could result in potential fund loss.
  • Recommendation: Implement thorough checks to ensure the legitimacy and safety of cNote token contracts.

asDFactory.sol:

  • Observation: Uses tx.origin in the constructor.
  • Risk: Security risks associated with tx.origin usage.
  • Recommendation: Replace tx.origin with msg.sender to enhance security.

Conclusion:

The analyzed contracts demonstrate a solid foundation, but careful consideration is needed for potential security risks, especially in handling external token contracts and access controls. Implementing suggested recommendations and conducting a detailed security audit will contribute to a more robust and secure smart contract application.

Time spent:

10 hours

#0 - c4-judge

2023-11-29T20:44:03Z

MarioPoneder marked the issue as grade-b

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