Skip to content

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.

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

3 participants