hats-finance / Safe-0x2909fdefd24a1ced675cb1444918fa766d76bdac

A collection of modules that can be used with the Safe contract
GNU Lesser General Public License v3.0
0 stars 1 forks source link

SafeWebAuthnSignerFactory.sol is prone to reorg issues. #29

Open hats-bug-reporter[bot] opened 3 months ago

hats-bug-reporter[bot] commented 3 months ago

Github username: @shealtielanz Twitter username: shealtielanz Submission hash (on-chain): 0x470e5d8ee1810a0dd7ff7bb7efe2c0a1778eb523764646cdf77811214855578e Severity: medium

Description: Description\ In the constructor of the factory contract during deployment, it uses the non-deterministic create method to deploy the SINGLETON allowing for reorg issues during creations of signers.

Bug Scenario

Severity

Low Likelihood - High Impact. I think a medium severity justifiable. Mitigation use create2 for the creation of the SINGLETON in the constructor.

nlordell commented 3 months ago

I don't think your described issue is possible. If I understand correctly, you are saying that, in case of a reorg, SINGLETON would end up at a different address? Can you please explain this more thoroughly?

shealtielanz commented 3 months ago

Hi @nlordell Good day, thanks for taking the time to review this. You're right! In the case of a reorg attack on the underlying blockchain the contract will be deployed in, the address will change due to the use of create because the address is created non-deterministically with the nonce of the contract. Example of an issue like this? take a look at this.

Point being, reorgs occur usually and that in such a case the nonce used will be different causing the address of the SINGLETON to change for future signers to be created, this is a common issue with create method and it is always advised to use create2 instead.

0xEricTee commented 3 months ago

@shealtielanz @nlordell Reorg is not possible here as the create opcode is in constructor and createSigner function cannot be called when the contract is not yet deployed.

nlordell commented 3 months ago

I don't see a security issue in this case. CREATE opcode and reorgs typically have issues when there are more than one contracts being deployed this way (in which case, reorgs can cause the contracts to not be on expected addresses). However, here, only the Singleton is deployed this way so I don't see an issue.

The only way I can see a reorg causing issues with the Singleton would be for an attacker to see the factory contract deployment being reorged, and have mined a CREATE2 address collision with the factory contract in order to deploy another contract first (this incrementing the nonce of the factory contract and causing the Singleton to land on a separate address). I don't think this is a possible attack and will mark this issue as invalid.

shealtielanz commented 3 months ago

Hey @nlordell Reorgs can occur in multiple blocks making the attack very feasible, I don’t see why this issue is marked invalid for any reason. I appeal a low severity atleast.

nlordell commented 3 months ago

Reorgs can occur in multiple blocks making the attack very feasible

I still don't understand how reorgs can be abused by bad actors. A CREATE address is computed based on two things: the address of the creator (which is the SafeWebAuthnSignerFactory contract, deployed with CREATE2 with a deterministic address) and its nonce.

All in all, this means that the SINGLETON will end up on the same address.

Furthermore, I believe that your statement here is false:

now future signers created will have a different SINGLETON used during that creation making the first signers created before the reorg occurred to be outdated.

Either the reorg will cause the transaction to play before the factory contract is created, in which case the reorg will cause the signer to no longer exist, or it will play after the factory contract is created, which would cause it to be deployed to a different address, but use the correct singleton, so, AFAIU, the signers will not "be outdated". Note that this is assuming that a reorg could be used to change the value of the SINGLETON address (which we argued above that it can't).

I believe this issue to be invalid.