-
Notifications
You must be signed in to change notification settings - Fork 68
feat: add common address execution mode support to ERC7821 #341
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
Open
legion2002
wants to merge
4
commits into
main
Choose a base branch
from
tanishk/calldata-optimized-call
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4cfe350
feat: add callSansTo support to ERC7821 execute
legion2002 1480976
chore: improvements and fixes to ERC7821Ithaca
legion2002 c10df35
chore: add address(0) replacement to new compute digest
legion2002 791337a
fix: sanitize upper bits before checking replacement + tests
legion2002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -485,6 +485,38 @@ contract IthacaAccount is IIthacaAccount, EIP712, GuardedExecutor { | |
| return isMultichain ? _hashTypedDataSansChainId(structHash) : _hashTypedData(structHash); | ||
| } | ||
|
|
||
| function computeDigest(CallSansTo[] calldata calls, address to, uint256 nonce) | ||
| public | ||
| view | ||
| virtual | ||
| returns (bytes32 result) | ||
| { | ||
| // If to is 0, it will be replaced with address(this) | ||
| assembly ("memory-safe") { | ||
| let t := shr(96, shl(96, to)) | ||
| to := or(mul(address(), iszero(t)), t) | ||
| } | ||
|
|
||
| bytes32[] memory a = EfficientHashLib.malloc(calls.length); | ||
| for (uint256 i; i < calls.length; ++i) { | ||
| (uint256 value, bytes calldata data) = _get(calls, i); | ||
| a.set( | ||
| i, | ||
| EfficientHashLib.hash( | ||
| CALL_TYPEHASH, | ||
| bytes32(uint256(uint160(to))), | ||
| bytes32(value), | ||
| EfficientHashLib.hashCalldata(data) | ||
| ) | ||
| ); | ||
| } | ||
| bool isMultichain = nonce >> 240 == MULTICHAIN_NONCE_PREFIX; | ||
| bytes32 structHash = EfficientHashLib.hash( | ||
| uint256(EXECUTE_TYPEHASH), LibBit.toUint(isMultichain), uint256(a.hash()), nonce | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ); | ||
| return isMultichain ? _hashTypedDataSansChainId(structHash) : _hashTypedData(structHash); | ||
| } | ||
|
|
||
| /// @dev Returns if the signature is valid, along with its `keyHash`. | ||
| /// The `signature` is a wrapped signature, given by | ||
| /// `abi.encodePacked(bytes(innerSignature), bytes32(keyHash), bool(prehash))`. | ||
|
|
@@ -675,6 +707,49 @@ contract IthacaAccount is IIthacaAccount, EIP712, GuardedExecutor { | |
| // ERC7821 | ||
| //////////////////////////////////////////////////////////////////////// | ||
|
|
||
| function _execute( | ||
| bytes32, | ||
| bytes calldata, | ||
| address to, | ||
| CallSansTo[] calldata calls, | ||
| bytes calldata opData | ||
| ) internal virtual override { | ||
| // Orchestrator workflow. | ||
| if (msg.sender == ORCHESTRATOR) { | ||
| // opdata | ||
| // 0x00: keyHash | ||
| if (opData.length != 0x20) revert OpDataError(); | ||
| bytes32 _keyHash = LibBytes.loadCalldata(opData, 0x00); | ||
|
|
||
| LibTStack.TStack(_KEYHASH_STACK_TRANSIENT_SLOT).push(_keyHash); | ||
| _execute(calls, to, _keyHash); | ||
| LibTStack.TStack(_KEYHASH_STACK_TRANSIENT_SLOT).pop(); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| // Simple workflow without `opData`. | ||
| if (opData.length == uint256(0)) { | ||
| if (msg.sender != address(this)) revert Unauthorized(); | ||
| return _execute(calls, to, bytes32(0)); | ||
| } | ||
|
|
||
| // Simple workflow with `opData`. | ||
| if (opData.length < 0x20) revert OpDataError(); | ||
| uint256 nonce = uint256(LibBytes.loadCalldata(opData, 0x00)); | ||
| LibNonce.checkAndIncrement(_getAccountStorage().nonceSeqs, nonce); | ||
| emit NonceInvalidated(nonce); | ||
|
|
||
| (bool isValid, bytes32 keyHash) = unwrapAndValidateSignature( | ||
| computeDigest(calls, to, nonce), LibBytes.sliceCalldata(opData, 0x20) | ||
| ); | ||
|
|
||
| if (!isValid) revert Unauthorized(); | ||
| LibTStack.TStack(_KEYHASH_STACK_TRANSIENT_SLOT).push(keyHash); | ||
| _execute(calls, to, keyHash); | ||
| LibTStack.TStack(_KEYHASH_STACK_TRANSIENT_SLOT).pop(); | ||
| } | ||
|
|
||
| /// @dev For ERC7821. | ||
| function _execute(bytes32, bytes calldata, Call[] calldata calls, bytes calldata opData) | ||
| internal | ||
|
|
@@ -711,8 +786,6 @@ contract IthacaAccount is IIthacaAccount, EIP712, GuardedExecutor { | |
| computeDigest(calls, nonce), LibBytes.sliceCalldata(opData, 0x20) | ||
| ); | ||
| if (!isValid) revert Unauthorized(); | ||
|
|
||
| // TODO: Figure out where else to add these operations, after removing delegate call. | ||
| LibTStack.TStack(_KEYHASH_STACK_TRANSIENT_SLOT).push(keyHash); | ||
| _execute(calls, keyHash); | ||
| LibTStack.TStack(_KEYHASH_STACK_TRANSIENT_SLOT).pop(); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This means that someone can take a valid
CallSansToexecution bundle and submit with theCallmodeWould prefer if we hash this a little differently to prevent that, its good design to only allow 1 possible way things can be executed with the same sig
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.
Yeah good point, but does it matter if they are used interchangeably?
the nonce already does replay protection.
But yes maybe we should hash it separately, just to prevent footguns in the future
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.
nothing obvious, but yep best to not have hanging things like this, there are attacks that could happen when you combine a bunch of hanging things