fix(contracts-bedrock): xDomainMsgSender Reset on Nested/Re-entered Calls#5440
Closed
fix(contracts-bedrock): xDomainMsgSender Reset on Nested/Re-entered Calls#5440
Conversation
|
✅ Deploy Preview for opstack-docs canceled.
|
Contributor
Author
|
Closing since solution implemented in #5444 is preferred. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This test introduces the sherlock-identified issue in the
CrossDomainMessagerwherebyrelayMessagenaively reset thexDomainMsgSenderafter a call. The issue here was that a nested call would reset this value to theConstants.DEFAULT_L2_SENDERwhich deviates from the expected behavior that thexDomainMsgSenderis set to the_senderfor the entirety of the subcall.The minimal solution here is to cache the
xDomainMsgSender. ie@clabby created a neat diagram to demonstrate the constructed stack:
To break this down further, we can demonstrate a scenario where a victim contract may be exploited by using the
xDomainMsgSender.Suppose a
relayMessagetargets the functionvictim()on external contract Victim. This looks like:The
exploiteris another external contract that unfortunately re-enters the XDMrelayMessagefunction, reseting thexDomainMsgSender(returned byxdm.xDomainMessageSender()). This can simply be:So, when the
exploit()function bubble back up in thevictim()function, the value returned byxdm.xDomainMessageSender()will not be the expected_sender, but instead reset to theConstants.DEFAULT_L2_SENDER. This will result in theVictimsending ether to the unintended address.You can now image if any external contract called by the
relayMessagecalls external logic and relies on the value of thexDomainMsgSenderreturned by thexDomainMessageSender()function, it would not be the intended address.In the implemented solution, this issue is fixed since inside the
exploit()function, the previousxDomainMsgSenderis used as opposed to the hardcodedConstants.DEFAULT_L2_SENDERso thevictim()function will get the expected_senderfrom thexdm.xDomainMessageSender()call.Metadata
Fixes CLI-3834