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

CS5.3 - Prevent nested operations originating from outside contracts #231

Merged
merged 2 commits into from
Oct 17, 2024

Conversation

kevincheng96
Copy link
Collaborator

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.

@@ -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()))) {
Copy link
Collaborator Author

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).

Copy link
Contributor

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.

Copy link
Collaborator Author

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

@kevincheng96 kevincheng96 changed the title 5.3 - Prevent nested operations originating from outside contracts CS5.3 - Prevent nested operations originating from outside contracts Oct 16, 2024
@@ -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()))) {
Copy link
Contributor

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.

@kevincheng96 kevincheng96 merged commit aeb8681 into main Oct 17, 2024
4 checks passed
@kevincheng96 kevincheng96 deleted the kevin/nesting branch October 17, 2024 02:10
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.

2 participants