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

Add reentrancy guard #11

Merged
merged 1 commit into from
Sep 1, 2022
Merged

Add reentrancy guard #11

merged 1 commit into from
Sep 1, 2022

Conversation

fedgiac
Copy link
Contributor

@fedgiac fedgiac commented Aug 31, 2022

This PR makes order creation and deletion non reentrant using OpenZeppelin's dedicated contract.

This allows us to send ETH to users without worrying about reentrancy attacks without worrying about keeping all existing function reentrancy safe.
The drawback is a very high extra execution cost of about 2500 gas (details).
The code that is being replaced by this PR is reentrancy safe but a user could lose funds if creating an order from a smart contract that has a complicated receive function.

Context: discussion in #7, especially this thread and this thread.

Before auditing starts I plan to remove the reentrancy guard by auditing the contract's reentrancy risks ourselves.

Test plan

Unit tests.

@fedgiac fedgiac requested a review from a team August 31, 2022 17:21
Copy link
Contributor

@josojo josojo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

Sorry, I hope there was no miss communication from my side. Since we reevaluate this later, it would have been fine for me to switch that all out later, and only come up with the nice testing - that probably required some time to write - when we actually wanna go for it.

@nlordell
Copy link
Contributor

nlordell commented Sep 1, 2022

Since we reevaluate this later, it would have been fine for me to switch that all out later

Personally, I kind of prefer having it in now 😛. IMO, its better to be safe now, forget about the issue later, and then deploy a slightly less gas efficient contract than not include it now, forget to get back and check this later, and deploy a contract with a potential bug that can be exploited.

@fedgiac fedgiac merged commit 1bcae19 into main Sep 1, 2022
@fedgiac fedgiac deleted the disable-reentrancy branch September 1, 2022 17:48
@fedgiac
Copy link
Contributor Author

fedgiac commented Sep 1, 2022

I also prefer the piece of mind of not leaving the code in a potentially unsafe state. The test did take more than expected to write however. 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants