From b191c18962509e09226990a68b986493870b017a Mon Sep 17 00:00:00 2001 From: Jan-Felix Date: Tue, 5 Mar 2024 23:22:22 +0100 Subject: [PATCH 1/2] fix a bug when submitting a single delegatecall --- extension/src/app.tsx | 2 +- extension/src/browser/Drawer/Remove.tsx | 7 ++++--- .../src/browser/Drawer/RolePermissionCheck.tsx | 10 ++++++++-- extension/src/browser/Drawer/Submit.tsx | 2 +- extension/src/browser/Drawer/Transaction.tsx | 2 +- extension/src/browser/Drawer/Translate.tsx | 5 +++-- extension/src/browser/Drawer/index.tsx | 13 +++++++++---- extension/src/browser/ProvideProvider.tsx | 9 ++++----- .../connections/ConnectionsDrawer/Edit/index.tsx | 2 +- .../connections/ConnectionsDrawer/List/index.tsx | 2 +- extension/src/encodeTransaction.ts | 9 +++++++++ extension/src/{browser => }/state/actions.ts | 0 extension/src/{browser => }/state/index.tsx | 0 extension/src/{browser => }/state/reducer.ts | 0 .../src/{browser => }/state/transactionHooks.ts | 4 ++-- 15 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 extension/src/encodeTransaction.ts rename extension/src/{browser => }/state/actions.ts (100%) rename extension/src/{browser => }/state/index.tsx (100%) rename extension/src/{browser => }/state/reducer.ts (100%) rename extension/src/{browser => }/state/transactionHooks.ts (87%) diff --git a/extension/src/app.tsx b/extension/src/app.tsx index ce545451..ec536be3 100644 --- a/extension/src/app.tsx +++ b/extension/src/app.tsx @@ -9,7 +9,7 @@ import './global.css' import Browser from './browser' import ConnectionsDrawer from './connections/ConnectionsDrawer' import ProvideProvider from './browser/ProvideProvider' -import { ProvideState } from './browser/state' +import { ProvideState } from './state' import ZodiacToastContainer from './components/Toast' import { pushLocation } from './location' import { ProvideMetaMask, ProvideTenderly } from './providers' diff --git a/extension/src/browser/Drawer/Remove.tsx b/extension/src/browser/Drawer/Remove.tsx index 984eed1b..40373665 100644 --- a/extension/src/browser/Drawer/Remove.tsx +++ b/extension/src/browser/Drawer/Remove.tsx @@ -1,13 +1,14 @@ import React from 'react' import { RiDeleteBinLine } from 'react-icons/ri' -import { encodeSingle, TransactionInput } from 'react-multisend' +import { TransactionInput } from 'react-multisend' import { IconButton } from '../../components' import { ForkProvider } from '../../providers' import { useProvider } from '../ProvideProvider' -import { useDispatch, useNewTransactions } from '../state' +import { useDispatch, useNewTransactions } from '../../state' import classes from './style.module.css' +import { encodeTransaction } from '../../encodeTransaction' type Props = { transaction: TransactionInput @@ -42,7 +43,7 @@ export const Remove: React.FC = ({ transaction, index }) => { // re-simulate all transactions after the removed one for (const transaction of laterTransactions) { - const encoded = encodeSingle(transaction.input) + const encoded = encodeTransaction(transaction) await provider.sendMetaTransaction(encoded) } } diff --git a/extension/src/browser/Drawer/RolePermissionCheck.tsx b/extension/src/browser/Drawer/RolePermissionCheck.tsx index 6e17f9e7..e06f8a4e 100644 --- a/extension/src/browser/Drawer/RolePermissionCheck.tsx +++ b/extension/src/browser/Drawer/RolePermissionCheck.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useMemo } from 'react' import { useEffect, useState } from 'react' import { RiGroupLine } from 'react-icons/ri' import { encodeSingle, TransactionInput } from 'react-multisend' @@ -64,7 +64,13 @@ const RolePermissionCheck: React.FC<{ const { connection } = useConnection() const tenderlyProvider = useTenderlyProvider() - const encodedTransaction = encodeSingle(transaction) + const encodedTransaction = useMemo( + () => ({ + ...encodeSingle(transaction), + operation: isDelegateCall ? 1 : 0, + }), + [transaction, isDelegateCall] + ) const translationAvailable = !!useApplicableTranslation(encodedTransaction) diff --git a/extension/src/browser/Drawer/Submit.tsx b/extension/src/browser/Drawer/Submit.tsx index bbcd4ba6..3f8a66e5 100644 --- a/extension/src/browser/Drawer/Submit.tsx +++ b/extension/src/browser/Drawer/Submit.tsx @@ -16,7 +16,7 @@ import { decodeRolesV2Error, } from '../../utils' import { useSubmitTransactions } from '../ProvideProvider' -import { useDispatch, useNewTransactions } from '../state' +import { useDispatch, useNewTransactions } from '../../state' import classes from './style.module.css' import { getReadOnlyProvider } from '../../providers/readOnlyProvider' diff --git a/extension/src/browser/Drawer/Transaction.tsx b/extension/src/browser/Drawer/Transaction.tsx index 39f086e0..c0379f28 100644 --- a/extension/src/browser/Drawer/Transaction.tsx +++ b/extension/src/browser/Drawer/Transaction.tsx @@ -8,7 +8,7 @@ import { Box, Flex } from '../../components' import ToggleButton from '../../components/Drawer/ToggleButton' import { CHAIN_CURRENCY } from '../../chains' import { useConnection } from '../../connections' -import { TransactionState } from '../state' +import { TransactionState } from '../../state' import CallContract from './CallContract' import ContractAddress from './ContractAddress' diff --git a/extension/src/browser/Drawer/Translate.tsx b/extension/src/browser/Drawer/Translate.tsx index d34c3b04..3d6cc25d 100644 --- a/extension/src/browser/Drawer/Translate.tsx +++ b/extension/src/browser/Drawer/Translate.tsx @@ -6,9 +6,10 @@ import { IconButton } from '../../components' import { ForkProvider } from '../../providers' import { useApplicableTranslation } from '../../transactionTranslations' import { useProvider } from '../ProvideProvider' -import { useDispatch, useNewTransactions } from '../state' +import { useDispatch, useNewTransactions } from '../../state' import classes from './style.module.css' +import { encodeTransaction } from '../../encodeTransaction' type Props = { transaction: TransactionInput @@ -44,7 +45,7 @@ export const Translate: React.FC = ({ const handleTranslate = async () => { const laterTransactions = transactions .slice(index + 1) - .map((t) => encodeSingle(t.input)) + .map(encodeTransaction) // remove the transaction and all later ones from the store dispatch({ type: 'REMOVE_TRANSACTION', payload: { id: transaction.id } }) diff --git a/extension/src/browser/Drawer/index.tsx b/extension/src/browser/Drawer/index.tsx index d7f71490..fbce6bfa 100644 --- a/extension/src/browser/Drawer/index.tsx +++ b/extension/src/browser/Drawer/index.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useRef, useState } from 'react' import { RiFileCopy2Line, RiRefreshLine } from 'react-icons/ri' -import { encodeMulti, encodeSingle } from 'react-multisend' +import { encodeMulti } from 'react-multisend' import { toast } from 'react-toastify' import { BlockButton, Button, Drawer, Flex, IconButton } from '../../components' @@ -8,12 +8,17 @@ import { ForkProvider } from '../../providers' import { wrapRequest } from '../../providers/WrappingProvider' import { useConnection } from '../../connections' import { useProvider } from '../ProvideProvider' -import { useAllTransactions, useDispatch, useNewTransactions } from '../state' +import { + useAllTransactions, + useDispatch, + useNewTransactions, +} from '../../state' import Submit from './Submit' import { Transaction, TransactionBadge } from './Transaction' import classes from './style.module.css' import { MULTI_SEND_ADDRESS } from '../../chains' +import { encodeTransaction } from '../../encodeTransaction' const TransactionsDrawer: React.FC = () => { const [expanded, setExpanded] = useState(true) @@ -53,14 +58,14 @@ const TransactionsDrawer: React.FC = () => { // re-simulate all new transactions (assuming the already submitted ones have already been mined on the fresh fork) for (const transaction of newTransactions) { - const encoded = encodeSingle(transaction.input) + const encoded = encodeTransaction(transaction) await provider.sendMetaTransaction(encoded) } } const copyTransactionData = () => { if (!connection.chainId) throw new Error('chainId is undefined') - const metaTransactions = newTransactions.map((tx) => encodeSingle(tx.input)) + const metaTransactions = newTransactions.map(encodeTransaction) const batchTransaction = metaTransactions.length === 1 ? metaTransactions[0] diff --git a/extension/src/browser/ProvideProvider.tsx b/extension/src/browser/ProvideProvider.tsx index 5720377a..3310e8a5 100644 --- a/extension/src/browser/ProvideProvider.tsx +++ b/extension/src/browser/ProvideProvider.tsx @@ -6,7 +6,7 @@ import React, { useContext, useMemo, } from 'react' -import { decodeSingle, encodeMulti, encodeSingle } from 'react-multisend' +import { decodeSingle, encodeMulti } from 'react-multisend' import { MULTI_SEND_ADDRESS } from '../chains' import { @@ -18,7 +18,8 @@ import { useConnection } from '../connections' import { Eip1193Provider } from '../types' import fetchAbi from './fetchAbi' -import { useDispatch, useNewTransactions } from './state' +import { useDispatch, useNewTransactions } from '../state' +import { encodeTransaction } from '../encodeTransaction' interface Props { simulate: boolean @@ -101,9 +102,7 @@ const ProvideProvider: React.FC = ({ simulate, children }) => { ) const submitTransactions = useCallback(async () => { - const metaTransactions = transactions.map((txState) => - encodeSingle(txState.input) - ) + const metaTransactions = transactions.map(encodeTransaction) console.log( transactions.length === 1 diff --git a/extension/src/connections/ConnectionsDrawer/Edit/index.tsx b/extension/src/connections/ConnectionsDrawer/Edit/index.tsx index 60b6b2d0..450490df 100644 --- a/extension/src/connections/ConnectionsDrawer/Edit/index.tsx +++ b/extension/src/connections/ConnectionsDrawer/Edit/index.tsx @@ -21,7 +21,7 @@ import { useSelectedConnectionId, } from '../../connectionHooks' import useConnectionDryRun from '../../useConnectionDryRun' -import { useClearTransactions } from '../../../browser/state/transactionHooks' +import { useClearTransactions } from '../../../state/transactionHooks' import classes from './style.module.css' import { decodeRoleKey, encodeRoleKey } from '../../../utils' diff --git a/extension/src/connections/ConnectionsDrawer/List/index.tsx b/extension/src/connections/ConnectionsDrawer/List/index.tsx index deccca6a..d07bd4a0 100644 --- a/extension/src/connections/ConnectionsDrawer/List/index.tsx +++ b/extension/src/connections/ConnectionsDrawer/List/index.tsx @@ -18,7 +18,7 @@ import { useSelectedConnectionId, } from '../../connectionHooks' import { Connection, ProviderType } from '../../../types' -import { useClearTransactions } from '../../../browser/state/transactionHooks' +import { useClearTransactions } from '../../../state/transactionHooks' import classes from './style.module.css' diff --git a/extension/src/encodeTransaction.ts b/extension/src/encodeTransaction.ts new file mode 100644 index 00000000..0b82b839 --- /dev/null +++ b/extension/src/encodeTransaction.ts @@ -0,0 +1,9 @@ +import { encodeSingle } from 'react-multisend' +import { TransactionState } from './state' + +export const encodeTransaction = (transaction: TransactionState) => { + return { + ...encodeSingle(transaction.input), + operation: transaction.isDelegateCall ? 1 : 0, + } +} diff --git a/extension/src/browser/state/actions.ts b/extension/src/state/actions.ts similarity index 100% rename from extension/src/browser/state/actions.ts rename to extension/src/state/actions.ts diff --git a/extension/src/browser/state/index.tsx b/extension/src/state/index.tsx similarity index 100% rename from extension/src/browser/state/index.tsx rename to extension/src/state/index.tsx diff --git a/extension/src/browser/state/reducer.ts b/extension/src/state/reducer.ts similarity index 100% rename from extension/src/browser/state/reducer.ts rename to extension/src/state/reducer.ts diff --git a/extension/src/browser/state/transactionHooks.ts b/extension/src/state/transactionHooks.ts similarity index 87% rename from extension/src/browser/state/transactionHooks.ts rename to extension/src/state/transactionHooks.ts index 907f4d7e..36f60fed 100644 --- a/extension/src/browser/state/transactionHooks.ts +++ b/extension/src/state/transactionHooks.ts @@ -1,7 +1,7 @@ import { useCallback } from 'react' -import { ForkProvider } from '../../providers' -import { useProvider } from '../ProvideProvider' +import { ForkProvider } from '../providers' +import { useProvider } from '../browser/ProvideProvider' import { useAllTransactions, useDispatch } from '.' From 645e429560164e28b7ffb601b511d1d2035f4312 Mon Sep 17 00:00:00 2001 From: Jan-Felix Date: Tue, 5 Mar 2024 23:22:51 +0100 Subject: [PATCH 2/2] fix an issue where signer is initialized with a wrong address --- extension/src/providers/WrappingProvider.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extension/src/providers/WrappingProvider.ts b/extension/src/providers/WrappingProvider.ts index da715ef6..f5a8a66b 100644 --- a/extension/src/providers/WrappingProvider.ts +++ b/extension/src/providers/WrappingProvider.ts @@ -78,7 +78,9 @@ class WrappingProvider extends EventEmitter { constructor(provider: Eip1193Provider, connection: Connection) { super() this.provider = provider - this.signer = new Web3Provider(provider).getSigner() + this.signer = new Web3Provider(this.provider).getUncheckedSigner( + connection.pilotAddress + ) this.connection = connection }