-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
createNewShare and asDFactory#create are vulnerable to chain reorganizations #313
Comments
minhquanym marked the issue as primary issue |
OpenCoreCH marked the issue as disagree with severity |
OpenCoreCH (sponsor) acknowledged |
These are extremely improbable, constructed examples. You could probably create such an example for most protocols, especially the one with the consecutive IDs because many smart contracts use them. If a user wants to be really sure that they are on the canonical chain and this does not happen, they can simply wait a few blocks. |
According to our guidelines:
Also reorg-attacks are part of this category, therefore QA seems most appropriate. |
MarioPoneder changed the severity to QA (Quality Assurance) |
MarioPoneder marked the issue as grade-c |
Hi @MarioPoneder I acknowledge these kind of issues are related to blockchain itself, and a person could create such an example for most protocols as the sponsor mentioned. However, the upscaling factor related to this protocol is that contract creations are totally permissionless here, which makes this protocol much more vulnerable to this issue. Based on that sentence in the guideline, frontrunning or MEV issues too would be invalid. However these issues still valid because protocols should take precautions to protect their users. Similar to that, if a protocol allows any user to create contracts permissionlessly, that protocol should also implement protections against the creation mechanism. The problem here is not reorg itself, it is the protocol not taking necessary precautions while allowing everyone to deploy contracts. I also would like to point out similar submissions related to permissionless contract creations and reorgs are historically judged as medium. I would appreciate if you could reconsider the severity of this issue and its duplicates. |
Hi and thank you for your comment and the referenced findings! After not finding a suitable answer in the org repo, I did some additional research on the C4 Judges Discord channel. According to the README:
Looking at Cantoscan there is a
I see it as the user's / front-end's responsibility to wait for the Therefore, I will finalize my decision after the sponsor has provided additional input about their definition of |
Hi @MarioPoneder , thanks for the judging. My report at the #405 duplicate can contribute to the ongoing discussion in several ways:
|
Good question, had to look it up, but it looks like these reorgs are not possible. Canto is a fork of Evmos/Ethermint and also uses Tendermint Core BFT consensus. This provides 1-block finality and not probabilisitic finality like other chains: https://docs.ethermint.zone/core/pending_state.html |
Thanks everyone for their input on this! Considering the 1-block finality on Canto, QA will be maintained.
According to the README (source of truth of this contest), the protocol will be deployed on Canto and I cannot take potential future deployments into consideration for judgement, especially when we don't know exactly which chain it's going to be. Further info regarding 1-block finality: |
MarioPoneder marked the issue as grade-b |
Lines of code
https://github.com/code-423n4/2023-11-canto/blob/335930cd53cf9a137504a57f1215be52c6d67cb3/1155tech-contracts/src/Market.sol#L114-L118
https://github.com/code-423n4/2023-11-canto/blob/335930cd53cf9a137504a57f1215be52c6d67cb3/asD/src/asDFactory.sol#L34
Vulnerability details
Impact
After calling createNewShare and asDFactory#create, users will usually deposit funds into the contracts. In events of chain reorganization, users who createdNewShare / createdAsD and shortly bought a share / minted asD, may lose some of their funds.
This is possible particulatly due to asDFactory#create using CREATE, which does not depend on the inputs nor the caller; similarly, createNewShare depends only on how many shares have been previously created.
createNewShare
Share creation is restricted at deployment, but, per README, it could be unrestricted as well. This example assumes that it is unrestricted.
Alice createsNewShare with id == x
Bob notices the ongoing reorg (or just does it by coincidence), and createsNewShare with the same id = x at the same time
Alice tries to buy one share.
Reorg is resolved. The chain where Bob created share with id == x becomes canonical. Alice's createNewShare txn is discarded.
Alice
buy
txn is mined. She ends up buying Bob's share. Even if she sells it, she would still lose funds because of buying/selling fees.In the worst case, Bob could set such bonding curve that would make Alice spend her whole allowance for Market contract. Considering she pays 10% fee two times (buying and selling), this would make her lose 1/5 of whatever her initial allowance was before the reorg.
asDFactory#create
Alice creates asD "ALICE" on address 0xabcd, derived from asFactory's address and its nonce.
At the same time, Bob creates asD "BOB" on the same address 0xabcd.
Alice shortly deposits her NOTE into what she thinks is her own contract, to mint asD "ALICE".
Reorg is resolved in Bob's favor.
Few weeks later, Alice finds out that her NOTE has been generating yield for Bob and not for herself.
Recommended Mitigation Steps
For asDFactory#create, use create2 with salt derived from msg.sender and user-provided salt.
For createNewShare, derive id from the hash of parameters and msg.sender.
Assessed type
Timing
The text was updated successfully, but these errors were encountered: