DoS: Attacker May Front-Run CoreFactory.createProject()
Or CoreFactory.addCollection()
With A collection.id
Causing Future Transactions With The Same collection.id
to Revert
#35
Labels
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
duplicate
This issue or pull request already exists
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2022-03-joyn/blob/c9297ccd925ebb2c44dbc6eaa3effd8db5d2368a/core-contracts/contracts/CoreFactory.sol#L147-L151
https://github.com/code-423n4/2022-03-joyn/blob/c9297ccd925ebb2c44dbc6eaa3effd8db5d2368a/core-contracts/contracts/CoreFactory.sol#L164
https://github.com/code-423n4/2022-03-joyn/blob/c9297ccd925ebb2c44dbc6eaa3effd8db5d2368a/core-contracts/contracts/CoreFactory.sol#L50-L56
Vulnerability details
Impact
A
_collection.id
may only be used once inCoreFactory._createCollection()
since the the contract is deployed using thecreate2
opcode with a repeated salt and contract bytecode will fail to deploy a contract. Furthermore, the modifieronlyAvailableCollection
will fail if a collection has already been made with that ID.The result is an attacker may front-run any
createProject()
oraddCollection()
transaction in the mem pool and create anothercreateProject()
oraddCollection()
transaction with a higher gas price that uses the same_collection.id
but changes the other fields such as themsg.sender
which will make them the owner of the contract that is deployed. The original transaction will revert and the user will not be able to send any more transaction with this_collection.id
.The user would therefore have to generate a new
_collection.id
. However, the attack is repeateable and there is no guarantee this new ID will be used to create a project successfully without the attacker front-running the transaction again.Proof of Concept
collections[_collection.id]
is set in_createCollection()
It also has the
onlyAvailableCollection
which will cause future transactions to revert.The use of
salt
will cause an repeated_collection.id
to fail.Recommended Mitigation Steps
One possible mitigation of this issue is to have the
collection.id
be a hash including themsg.sender
and asalt
where thesalt
is a parameter to the function.Another possible solution is to use an incrementing
collectionId
that is stored in the contract and incremented each time a user calls_createCollection()
. e.g. the first call to_createCollection()
will havecollectionId = 1
the second will havecollectionId = 2
and so on.Consider also removing the
salt
field from the creation of thecoreCollection
if the contract address is not required to be deterministic. This will use theCREATE
opcode rather thanCREATE2
.The text was updated successfully, but these errors were encountered: