Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 300
fix: preserve Money Account EIP-7702 auths on same-chain pay batches#9765
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
e0660f510e82e395667f9c9dcd37be660d9258f45ece5f3aad87a891ad0302f14b425f10ffd51File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -36,6 +36,7 @@ import type { | ||
| import { projectLogger } from '../logger.js'; | ||
| import { TransactionEnvelopeType, TransactionType } from '../types.js'; | ||
| import type { | ||
| AuthorizationList, | ||
| NestedTransactionMetadata, | ||
| SecurityAlertResponse, | ||
| TransactionBatchSingleRequest, | ||
| @@ -282,6 +283,58 @@ async function getNestedTransactionMeta( | ||
| }; | ||
| } | ||
| /** | ||
| * Build the authorization list for an EIP-7702 batch transaction. | ||
| * | ||
| * When the batch payer (`from`) requires an upgrade, an unsigned upgrade | ||
| * authorization for that account is included first. Any caller-provided | ||
| * authorizations (e.g. a pre-signed Money Account upgrade) are appended so | ||
| * both can be submitted on the same type-4 transaction. | ||
| * | ||
| * @param options - Options bag. | ||
| * @param options.chainId - Chain ID of the batch. | ||
| * @param options.messenger - Controller messenger. | ||
| * @param options.providedAuthorizationList - Optional authorizations from the batch request. | ||
| * @param options.publicKeyEIP7702 - Public key used to resolve the upgrade contract. | ||
| * @param options.requiresUpgrade - Whether the batch payer requires an EIP-7702 upgrade. | ||
| * @returns The combined authorization list, or undefined when none are needed. | ||
| */ | ||
| function buildBatchAuthorizationList({ | ||
| chainId, | ||
| messenger, | ||
| providedAuthorizationList, | ||
| publicKeyEIP7702, | ||
| requiresUpgrade, | ||
| }: { | ||
| chainId: Hex; | ||
| messenger: TransactionControllerMessenger; | ||
| providedAuthorizationList?: AuthorizationList; | ||
| publicKeyEIP7702: Hex; | ||
| requiresUpgrade: boolean; | ||
| }): AuthorizationList | undefined { | ||
| const authorizationList: AuthorizationList = []; | ||
| if (requiresUpgrade) { | ||
| const upgradeContractAddress = getEIP7702UpgradeContractAddress( | ||
| chainId, | ||
| messenger, | ||
| publicKeyEIP7702, | ||
| ); | ||
| if (!upgradeContractAddress) { | ||
| throw rpcErrors.internal(ERROR_MESSAGE_NO_UPGRADE_CONTRACT); | ||
| } | ||
| authorizationList.push({ address: upgradeContractAddress }); | ||
| } | ||
| if (providedAuthorizationList?.length) { | ||
| authorizationList.push(...providedAuthorizationList); | ||
pedronfigueiredo marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| return authorizationList.length ? authorizationList : undefined; | ||
| } | ||
| /** | ||
| * Process a batch transaction using an EIP-7702 transaction. | ||
| * | ||
| @@ -300,6 +353,7 @@ async function addTransactionBatchWith7702( | ||
| const { | ||
| atomic, | ||
| authorizationList: providedAuthorizationList, | ||
| batchId: batchIdOverride, | ||
| disableUpgrade, | ||
| from, | ||
| @@ -382,22 +436,23 @@ async function addTransactionBatchWith7702( | ||
| maxPriorityFeePerGas: nestedTransactions[0]?.maxPriorityFeePerGas, | ||
| }; | ||
| if (requiresUpgrade) { | ||
| const upgradeContractAddress = getEIP7702UpgradeContractAddress( | ||
| chainId, | ||
| messenger, | ||
| publicKeyEIP7702, | ||
| ); | ||
| if (!upgradeContractAddress) { | ||
| throw rpcErrors.internal(ERROR_MESSAGE_NO_UPGRADE_CONTRACT); | ||
| } | ||
| const authorizationList = buildBatchAuthorizationList({ | ||
| chainId, | ||
| messenger, | ||
| providedAuthorizationList, | ||
| publicKeyEIP7702, | ||
| requiresUpgrade, | ||
| }); | ||
| if (authorizationList?.length) { | ||
| txParams.type = TransactionEnvelopeType.setCode; | ||
| txParams.authorizationList = [{ address: upgradeContractAddress }]; | ||
| txParams.authorizationList = authorizationList; | ||
jpuri marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| if (validateSecurity) { | ||
| // `delegationMock` applies to the batch payer (`from`) only. When | ||
| // `requiresUpgrade` is true, that upgrade authorization is always first in | ||
| // the list. Caller-provided auths for other accounts must not be used here. | ||
| const securityRequest: ValidateSecurityRequest = { | ||
| method: 'eth_sendTransaction', | ||
| params: [ | ||
| @@ -407,7 +462,9 @@ async function addTransactionBatchWith7702( | ||
| type: TransactionEnvelopeType.feeMarket, | ||
| }, | ||
| ], | ||
| delegationMock: txParams.authorizationList?.[0]?.address, | ||
| delegationMock: requiresUpgrade | ||
| ? authorizationList?.[0]?.address | ||
| : undefined, | ||
| origin, | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.