Canto Application Specific Dollars and Bonding Curves for 1155s - deepkin'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: 93/120

Findings: 1

Award: $1.37

🌟 Selected for report: 0

🚀 Solo Findings: 0

Lines of code

https://github.com/code-423n4/2023-11-canto/blob/main/1155tech-contracts/src/bonding_curve/LinearBondingCurve.sol#L14-L25 https://github.com/code-423n4/2023-11-canto/blob/main/1155tech-contracts/src/Market.sol#L150-L169 https://github.com/code-423n4/2023-11-canto/blob/main/1155tech-contracts/src/Market.sol#L174-L189

Vulnerability details

Impact

Because of the linear price increase(LinearBondingCurve) it can be really easy to manipulate the price for next buyer of the shares in the Market.

While sandwich attack is not a problem since the contracts will be deployed to Canto(l2 based on Polygon) there still a possibility of price manipulation attack which will affect user expenses and can be profitable for the malefactor.

**It also worth to mention that during the audit representative of the Canto team - Roman, mentioned that it is possible that this contract will be deployed on other chains. So potential sandwich attack vulnerability is also possible and should be addressed. https://discord.com/channels/810916927919620096/1172195122230853723/1173936821479161866 Roman(c) >> Application specific dollars will only be deployed on Canto. 1155tech may be deployed on other chains in the future (with a different payment token), but the current focus / plan is also the deployment on Canto

Proof of Concept

The simplest flow is an example where the shares creator is malefactor contract.

  1. Creator creating new share via the Market. https://github.com/code-423n4/2023-11-canto/blob/main/1155tech-contracts/src/Market.sol#L114-L127 Per documentation Market.createNewShare is used to create a new share. Share creation can be completely permissionless or it can be restricted to whitelisted addresses only. No fee is charged for the creation of new shares.
require(whitelistedBondingCurves[_bondingCurve], "Bonding curve not whitelisted"); require(shareIDs[_shareName] == 0, "Share already exists"); id = ++shareCount; shareIDs[_shareName] = id; shareData[id].bondingCurve = _bondingCurve; shareData[id].creator = msg.sender; shareData[id].metadataURI = _metadataURI; emit ShareCreated(id, _shareName, _bondingCurve, msg.sender);
  1. During same transaction malicious contract can buy tokens from newly created share by changing msg.sender. For example he takes 100 tokens. The price paid will be: (1..100)*priceIncrease https://github.com/code-423n4/2023-11-canto/blob/main/1155tech-contracts/src/Market.sol#L150-L169
require(shareData[_id].creator != msg.sender, "Creator cannot buy"); //@audit this check is nor enough for protection from current attack
  1. Prices for this share will be increased. By the algorithm token for new user will cost: (100+1)*priceIncrease https://github.com/code-423n4/2023-11-canto/blob/main/1155tech-contracts/src/bonding_curve/LinearBondingCurve.sol#L14-L25
for (uint256 i = shareCount; i < shareCount + amount; i++) { uint256 tokenPrice = priceIncrease * i; price += tokenPrice; fee += (getFee(i) * tokenPrice) / 1e18; }
  1. After other users of the Market will buy enough shares the attacker will just sell everything and get a profit. Users buy next 100 tokens with price (100+1..100)*priceIncrease. Attacker sell 100 tokens with price (200-1..100)*priceIncrease. Profit will be the difference between price of last 100 tokens and first 100 tokens.

  2. Because this early-start manipulation is possible for multiple shares it can be replicated many times.

Tools Used

Manual audit

  1. Make some protection/pause logic for malicious shares to protect users from buy/sell.
  2. Make pricing logic a bit smarter with snapshot pricing.

Assessed type

Other

#0 - c4-pre-sort

2023-11-18T10:07:35Z

minhquanym marked the issue as duplicate of #12

#1 - c4-judge

2023-11-28T23:32:15Z

MarioPoneder marked the issue as satisfactory

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