Skip to content
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

asDinstances are vulnerable to reorg attack #312

Closed
c4-submissions opened this issue Nov 17, 2023 · 4 comments
Closed

asDinstances are vulnerable to reorg attack #312

c4-submissions opened this issue Nov 17, 2023 · 4 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-313 edited-by-warden grade-b QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax

Comments

@c4-submissions
Copy link
Contributor

c4-submissions commented Nov 17, 2023

Lines of code

https://github.com/code-423n4/2023-11-canto/blob/335930cd53cf9a137504a57f1215be52c6d67cb3/asD/src/asDFactory.sol#L34

Vulnerability details

Impact

asDcontract instances can be hijacked by attackers in case of a reorg and the interests earned in these contracts will be claimed by the attacker.

Proof of Concept

This protocol allows anyone to create asD contract instances with the asDFactory.sol. These instances are created with the new keyword without adding a salt, which means they are built with the create opcode and the deployed addresses only depend on the nonce of the factory.
https://github.com/code-423n4/2023-11-canto/blob/335930cd53cf9a137504a57f1215be52c6d67cb3/asD/src/asDFactory.sol#L33C1-L38C6

file: asDFactory.sol
    function create(string memory _name, string memory _symbol) external returns (address) {
-->     asD createdToken = new asD(_name, _symbol, msg.sender, cNote, owner()); //@audit it doesn't use a salt. "_name" and "_symbol" also doesn't have to be uniqe.
        isAsD[address(createdToken)] = true;
        emit CreatedToken(address(createdToken), _symbol, _name, msg.sender);
        return address(createdToken);
    }

The second thing I would like to point out is that the _name and the _symbol don't have to be unique when creating asD's. Reference in the Code4rena contest page:
"The asDFactory is used to create a new asD tokens. It only exposes a function create that accepts the name and symbol of the token to create. These do not have to be unique."

These two situations combined make the protocol vulnerable to reorgs, which can happen in any EVM chain.

  1. Alice is an artist who plans to use ERC1155tech of this protocol for her NFT art project (note: ERC1155tech protocol uses asD as currency).

  2. Alice creates an asD contract, and uses this newly deployed contract's address in her art project as payment currency.

  3. Bob sees a network reorg happens and creates an asD token with the same name and the same symbol.

  4. Bob's transaction is executed first, and now Bob is the owner of the asD contract, which is deployed in the same address that Alice already started to use.

  5. Alice's transaction to create asD executes after Bob's but does not revert as the name and the symbol doesn't have to be unique.

  6. Alice's asD instance is different than her previous one, but she can't be aware of this because
    - Her transaction didn't revert and she didn't get alarmed
    - Everything is the same except the owner. The same asD address, the same _name, and the same _symbol. There is nothing to be suspicious about.

  7. Alice's art collection reaches good volumes and her asD contract earns interest. However, she can not withdraw these as she is not the actual owner of that asD contract.

Tools Used

Manual review

Recommended Mitigation Steps

I would recommend using the new keyword with a salt derived from the msg.sender

For example:

function create(string memory _name, string memory _symbol) external returns (address) {
+       bytes32 salt = keccak256(abi.encode(msg.sender));
        // Added salt during creation
+       asD createdToken = new asD{salt: salt}(_name, _symbol, msg.sender, cNote, owner());
        isAsD[address(createdToken)] = true;
        emit CreatedToken(address(createdToken), _symbol, _name, msg.sender);
        return address(createdToken);
    }

Assessed type

Other

@c4-submissions c4-submissions added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Nov 17, 2023
c4-submissions added a commit that referenced this issue Nov 17, 2023
@c4-pre-sort
Copy link

minhquanym marked the issue as duplicate of #313

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Nov 29, 2023
@c4-judge
Copy link

MarioPoneder changed the severity to QA (Quality Assurance)

@c4-judge c4-judge added grade-c unsatisfactory does not satisfy C4 submission criteria; not eligible for awards labels Nov 29, 2023
@c4-judge
Copy link

MarioPoneder marked the issue as grade-c

@c4-judge c4-judge added grade-b and removed grade-c unsatisfactory does not satisfy C4 submission criteria; not eligible for awards labels Dec 4, 2023
@c4-judge
Copy link

c4-judge commented Dec 4, 2023

MarioPoneder marked the issue as grade-b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-313 edited-by-warden grade-b QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Projects
None yet
Development

No branches or pull requests

4 participants