Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

Add nonReentrant to relayMessage() #172

Merged
merged 5 commits into from
Jan 12, 2021
Merged

Add nonReentrant to relayMessage() #172

merged 5 commits into from
Jan 12, 2021

Conversation

maurelian
Copy link
Collaborator

Description

This is a fix to Sam's bug.

Questions

Additionally, @karlfloersch pointed out that another way to address this would be checking that the msg.sender == address(0), because this condition can only be satisfied at the first contract ovmCALLed by run.

Metadata

Fixes

Contributing Agreement

ben-chain
ben-chain previously approved these changes Jan 9, 2021
Copy link
Collaborator

@ben-chain ben-chain left a comment

Choose a reason for hiding this comment

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

Lookin' good! I see the question above -- to clarify, this will only work in the OVM_L2CrossDomainMessenger. The reason is because of account abstraction, OVM state transitions do not include a from, just a to, meaning that the entrypoint contract will get address(0) for ovmCALLER, during the very first ovmCALL only. Since the contract uses the compiler (+build ovm), we can easily access ovmCALLER with a normal msg.sender.

It strikes me that this property could be worth explicitly adding to our Execution Manager tests which use the ExecutionManagerTestRunner. I think we want to merge this ASAP though, so I'm gonna approve this one and create another ticket for that.

Copy link
Collaborator

@ben-chain ben-chain left a comment

Choose a reason for hiding this comment

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

Requested a couple small changes but lookin' good!

@@ -140,6 +143,7 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros
)
override
public
nonReentrant
Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW, this code path speaks directly to the rollup contracts (OVM_CanonicalTransactionChain.enqueue specifically) so it should not be re-enterable based on the behavior of that target, so it should not be needed.

I'd recommend removing it, because the L1 SSTORE is gonna be expensive. If you think that it's worth keeping, we can, but we should also add it to sendMessage, since the functions serve similar purposes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OVM_BaseCrossDomainMessenger.sendMessage() already has the nonReentrant modifier on it. You can see above that I moved it down a couple lines to improve the style. But looking at both sendMessage and replayMessage more closely, I agree that it looks pretty safe to remove them.

maurelian and others added 2 commits January 11, 2021 19:38
Co-authored-by: ben-chain <ben@pseudonym.party>
Copy link
Collaborator

@ben-chain ben-chain left a comment

Choose a reason for hiding this comment

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

Beautiful, LGTM!

@maurelian maurelian removed the request for review from smartcontracts January 12, 2021 01:25
@maurelian maurelian changed the title [WIP] Add nonReentrant to all public functions on CrossDomainMessengers Add nonReentrant to all public functions on CrossDomainMessengers Jan 12, 2021
@maurelian maurelian changed the title Add nonReentrant to all public functions on CrossDomainMessengers Add nonReentrant to relayMessage() Jan 12, 2021
@maurelian maurelian merged commit d75fd8c into master Jan 12, 2021
@maurelian maurelian deleted the fix/reentryOnBridge branch January 12, 2021 01:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants