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

quark-proxy subproject #125

Merged
merged 4 commits into from
Dec 12, 2023
Merged

quark-proxy subproject #125

merged 4 commits into from
Dec 12, 2023

Conversation

fluffywaffles
Copy link
Collaborator

No description provided.

@fluffywaffles fluffywaffles force-pushed the jordan/direct-proxy-subproject branch 2 times, most recently from e6e258d to 280b620 Compare December 8, 2023 23:47
@fluffywaffles fluffywaffles marked this pull request as ready for review December 8, 2023 23:50
@fluffywaffles fluffywaffles force-pushed the jordan/direct-proxy-subproject branch from 280b620 to f3c551e Compare December 8, 2023 23:51
Comment on lines 28 to 31
function signer() internal view returns (address) {
(bool success, bytes memory signer_) = address(this).staticcall(abi.encodeWithSignature("signer()"));
if (!success) revert("no signer");
return abi.decode(signer_, (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.

ideally these helpers in QuarkScript.sol should get inlined when called.
Moreover, I think we can probably remove the success variable and if (!success) code, seeing as if this call fails, the wallet is invalid anyway.

Comment on lines 115 to 130
/**
* @dev Internal getter for the signer immutable
*/
function getSigner() internal view returns (address) {
(bool success, bytes memory signer_) = address(this).staticcall(abi.encodeWithSignature("signer()"));
if (!success) revert("no signer");
return abi.decode(signer_, (address));
}

/**
* @dev Internal getter for the executor immutable
*/
function getExecutor() internal view returns (address) {
(bool success, bytes memory executor_) = address(this).staticcall(abi.encodeWithSignature("executor()"));
if (!success) revert("no executor");
return abi.decode(executor_, (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.

Similarly to QuarkScript.sol, in QuarkWallet.sol I think we can probably remove the success variables and if (!success) cases in the getters, seeing as if the calls fail, the wallet is invalid anyway.

/**
* @dev Internal getter for the signer immutable
*/
function getSigner() internal view returns (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.

I would rename this method signer() and getExecutor() to executor(), but to be backwards-compatible with a wallet deployed without a proxy, we cannot re-use these names.

ideally, the staticcalls should be inlined, anyway. hopefully, as internals, they will be -- but I am also considering moving them into the QuarkWalletMetadata library where I am fairly certain they'll be inlined.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think internal functions use a JUMP instead of being inlined. This is how we cut down on bytecode size sometimes, by moving inline code used in multiple places into a shared internal function. I think this is fine for now, we can optimize later.

Comment on lines +11 to +12
/// @notice Address of the QuarkWallet implementation contract
address public immutable walletImplementation;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe we can actually predict a valid wallet implementation address for use by the proxy: the "null wallet," or QuarkWallet{salt: 0}(address(0), address(0)). It can never execute code itself, but if it is delegatecalled its implementation can run in the context of the proxy.

The benefit here is that the address is deterministically predictable, which means we could replace this immutable with a constant, which would save on gas costs for both deployment and calls, since the constant will by definition be inlined by the compiler (and we can remove a line of code from the constructor).

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's only deterministic if deployed via CodeJar, but CodeJar doesn't support contracts with constructors right?

Comment on lines +42 to +63
function testSignerExecutor() public {
assertEq(walletImplementation.signer(), address(0));
assertEq(walletImplementation.executor(), address(0));

assertEq(aliceWalletProxy.signer(), aliceAccount);
assertEq(aliceWalletProxy.executor(), address(0xabc));

bytes memory testScript = new YulHelper().getDeployed("ProxyDirect.t.sol/TestHarness.json");
QuarkWallet.QuarkOperation memory op = new QuarkOperationHelper().newBasicOpWithCalldata(
QuarkWallet(payable(aliceWalletProxy)),
testScript,
abi.encodeWithSignature("getSignerAndExecutor()"),
ScriptType.ScriptAddress
);
(uint8 v, bytes32 r, bytes32 s) =
new SignatureHelper().signOp(alicePrivateKey, QuarkWallet(payable(aliceWalletProxy)), op);
bytes memory result = QuarkWallet(payable(aliceWalletProxy)).executeQuarkOperation(op, v, r, s);
(address signer, address executor) = abi.decode(result, (address, address));
assertEq(signer, aliceAccount);
assertEq(executor, address(0xabc));
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test demonstrates that the null wallet can be used as an implementation wallet for the proxy.

@fluffywaffles fluffywaffles changed the title Jordan/direct proxy subproject quark-proxy subproject Dec 9, 2023
@fluffywaffles fluffywaffles force-pushed the jordan/direct-proxy-subproject branch from a0ac662 to 656a685 Compare December 11, 2023 18:25
Copy link
Collaborator

@kevincheng96 kevincheng96 left a comment

Choose a reason for hiding this comment

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

Nice, LGTM 👍

/**
* @dev Internal getter for the signer immutable
*/
function getSigner() internal view returns (address) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think internal functions use a JUMP instead of being inlined. This is how we cut down on bytecode size sometimes, by moving inline code used in multiple places into a shared internal function. I think this is fine for now, we can optimize later.

Comment on lines +11 to +12
/// @notice Address of the QuarkWallet implementation contract
address public immutable walletImplementation;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's only deterministic if deployed via CodeJar, but CodeJar doesn't support contracts with constructors right?

assertEq(aliceWalletProxy.executor(), address(0xabc));

bytes memory testScript = new YulHelper().getDeployed("ProxyDirect.t.sol/TestHarness.json");
QuarkWallet.QuarkOperation memory op = new QuarkOperationHelper().newBasicOpWithCalldata(
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: pause gas metering for this

@fluffywaffles fluffywaffles force-pushed the jordan/direct-proxy-subproject branch from f428572 to ca46b29 Compare December 12, 2023 21:14
@fluffywaffles
Copy link
Collaborator Author

fluffywaffles commented Dec 12, 2023

had to rebase with main to get the gas snapshot diff to commit without conflicts.

@fluffywaffles fluffywaffles merged commit 3e46e98 into main Dec 12, 2023
4 checks passed
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