-
Notifications
You must be signed in to change notification settings - Fork 0
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
CS5.3 - Prevent nested operations originating from outside contracts #231
Conversation
@@ -455,6 +456,15 @@ contract QuarkWallet is IERC1271 { | |||
oldActiveSubmissionToken := tload(activeSubmissionTokenSlot) | |||
oldCallback := tload(callbackSlot) | |||
|
|||
// Prevent nested operations coming from an outside caller (i.e. not the Quark wallet itself) | |||
if and(iszero(eq(oldActiveScript, 0)), iszero(eq(caller(), address()))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We check against the activeScript
here, but we really could also check against submissionToken
since that is guaranteed to be non-zero during a nested operation. activeScript
should also be non-zero during a nested operation since the zero address has empty code and will revert from the check above (L437).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Embrace the YUL.
and(iszero(eq(oldActiveScript, 0)), iszero(eq(caller(), address())))
if ( ( oldActiveScript == 0 ) == FALSE ) AND ( ( msg.sender == address[this] ) == FALSE )
if oldActiveScript != 0 and msg.sender != address[this]
DeMorgan's Law:
unless (oldActiveScript == 0 or msg.sender == address[this]) {
revert()
}
My work through of the logic there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, that logic checks out
@@ -455,6 +456,15 @@ contract QuarkWallet is IERC1271 { | |||
oldActiveSubmissionToken := tload(activeSubmissionTokenSlot) | |||
oldCallback := tload(callbackSlot) | |||
|
|||
// Prevent nested operations coming from an outside caller (i.e. not the Quark wallet itself) | |||
if and(iszero(eq(oldActiveScript, 0)), iszero(eq(caller(), address()))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Embrace the YUL.
and(iszero(eq(oldActiveScript, 0)), iszero(eq(caller(), address())))
if ( ( oldActiveScript == 0 ) == FALSE ) AND ( ( msg.sender == address[this] ) == FALSE )
if oldActiveScript != 0 and msg.sender != address[this]
DeMorgan's Law:
unless (oldActiveScript == 0 or msg.sender == address[this]) {
revert()
}
My work through of the logic there.
This disallows contracts that are not the wallet itself from executing a nested Quark operation within the context of a parent Quark operation. This offers some protection for scripts that are making external calls. We still allow for nesting of Quark operations, with the caveat that the nested call must come from the Quark wallet itself.