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

feat: add ReentrancyGuard #503

Merged
merged 4 commits into from
Apr 5, 2019
Merged

feat: add ReentrancyGuard #503

merged 4 commits into from
Apr 5, 2019

Conversation

sohkai
Copy link
Contributor

@sohkai sohkai commented Apr 3, 2019

Adds a reusable ReentrancyGuard working off of its own unstructured storage slot, and makes it available to AragonApps.

See aragon/aragon-apps#744 (comment) for context.


Bytecode comparison:

                     CODE DEPOSIT COST    DEPLOYED BYTES     INITIALIZATION BYTES
KeccakConstants.json 28400 more gas       +142               0

But the actual bytecode increase of adding the nonReentrant modifier is ~60k gas per use.

@sohkai sohkai requested review from izqui and facuspagnuolo April 3, 2019 17:06
Copy link
Contributor

@izqui izqui left a comment

Choose a reason for hiding this comment

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

LGTM. Good job with the test coverage 💪

@@ -49,6 +49,7 @@ contract KeccakConstants {
// Unstructured storage
bytes32 public constant initializationBlockPosition = keccak256(abi.encodePacked("aragonOS.initializable.initializationBlock"));
bytes32 public constant depositablePosition = keccak256(abi.encodePacked("aragonOS.depositableStorage.depositable"));
bytes32 public constant reentrancyGuardPosition = keccak256(abi.encodePacked("aragonOS.reentrancyGuard.mutex"));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not being used for testing. Maybe we could use it in ReentrancyGuardMock so we implicitly test that it is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, forgot to add this to the keccak constants test. Add now in cf07f35.

@coveralls
Copy link

coveralls commented Apr 3, 2019

Coverage Status

Coverage increased (+0.004%) to 99.544% when pulling 6d7be74 on reentrancy-guard into dca0b4b on dev.

Copy link
Contributor

@bingen bingen left a comment

Choose a reason for hiding this comment

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

This is really cool! It's going to make my life way happier! 😉

Copy link
Contributor

@facuspagnuolo facuspagnuolo left a comment

Choose a reason for hiding this comment

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

Great job @sohkai :)


it('allows entering non-entrant call from re-entrant call', async () => {
await reentrancyMock.reentrantCall(reentrantActor.address)
assert.equal((await reentrancyMock.callCounter()).toString(), 2, 'should have called twice')
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to ensure consistency I'd check that the mutex variable stays in false on successful calls when using the guard.

@sohkai sohkai force-pushed the reentrancy-guard branch from 070155c to 3cb559a Compare April 5, 2019 08:45
@sohkai sohkai force-pushed the reentrancy-guard branch from 3cb559a to 6d7be74 Compare April 5, 2019 08:45
@sohkai sohkai merged commit 6b56c93 into dev Apr 5, 2019
@sohkai sohkai deleted the reentrancy-guard branch April 5, 2019 09:26
sohkai added a commit that referenced this pull request Apr 5, 2019
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.

5 participants