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

Switch from callcode to delegatecall #222

Merged
merged 1 commit into from
Oct 16, 2024
Merged

Conversation

kevincheng96
Copy link
Collaborator

Now that we use tstore/tload for reentrancy guards, the onlyWallet modifier is no longer needed. This is was pretty much the only remaining reason for using callcode over delegatecall to execute a Quark script. Since callcode is a deprecated opcode, it is better to switch over to delegatecall.

The one side effect of this switch-over is that scripts have to use address(this) instead of msg.sender to refer to the Quark wallet's address. Surprisingly, all our existing core scripts were already using address(this), so the only changes we have to make are to the test scripts.

@@ -137,32 +137,3 @@ sequenceDiagram title: Execute Quark Operation with Callback
S -->> S: [14] Run Script
S -->> T: [15] Erc20 Transfer "Repay" [sender=User Wallet]
```

## Upgrade Quark Wallet
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Interesting to see this. I guess there was a point in time when we were using a fully upgradeable proxy for the Quark wallet.

Base automatically changed from kevin/tstore-callback to kevin/quark-v2 September 30, 2024 17:55
Base automatically changed from kevin/quark-v2 to main September 30, 2024 17:59
Copy link
Contributor

@hayesgm hayesgm left a comment

Choose a reason for hiding this comment

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

looks good. trying to think if this could break anything, but generally, it seems like a safer alternative to the previous strategy.

// Note: CALLCODE is used to set the QuarkWallet as the `msg.sender`
success :=
callcode(gas(), scriptAddress, /* value */ 0, add(scriptCalldata, 0x20), scriptCalldataLen, 0x0, 0)
success := delegatecall(gas(), scriptAddress, add(scriptCalldata, 0x20), scriptCalldataLen, 0x0, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

To be clear, we don't want to use msg.value here still, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

msg.value will always be 0 because none of the executeQuarkOperation functions are payable.

@kevincheng96 kevincheng96 merged commit 6164229 into main Oct 16, 2024
4 checks passed
@kevincheng96 kevincheng96 deleted the kevin/delegatecall branch October 16, 2024 18:29
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