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

Add immutable wallet proxy hook #632

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/abi/src/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import * as erc6492 from './erc6492'
import * as factory from './factory'
import * as mainModule from './mainModule'
import * as mainModuleUpgradable from './mainModuleUpgradable'
import * as moduleHooks from './moduleHooks'
import * as sequenceUtils from './sequenceUtils'
import * as requireFreshSigner from './libs/requireFreshSigners'
import * as walletProxyHook from './walletProxyHook'

export const walletContracts = {
erc6492,
Expand All @@ -14,6 +16,8 @@ export const walletContracts = {
factory,
mainModule,
mainModuleUpgradable,
moduleHooks,
sequenceUtils,
requireFreshSigner
requireFreshSigner,
walletProxyHook
}
248 changes: 248 additions & 0 deletions packages/abi/src/wallet/moduleHooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
export const abi = [
{
inputs: [
{
internalType: 'bytes4',
name: '_signature',
type: 'bytes4'
}
],
name: 'HookAlreadyExists',
type: 'error'
},
{
inputs: [
{
internalType: 'bytes4',
name: '_signature',
type: 'bytes4'
}
],
name: 'HookDoesNotExist',
type: 'error'
},
{
inputs: [
{
internalType: 'address',
name: '_sender',
type: 'address'
},
{
internalType: 'address',
name: '_self',
type: 'address'
}
],
name: 'OnlySelfAuth',
type: 'error'
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'bytes4',
name: '_signature',
type: 'bytes4'
},
{
indexed: false,
internalType: 'address',
name: '_implementation',
type: 'address'
}
],
name: 'DefinedHook',
type: 'event'
},
{
stateMutability: 'payable',
type: 'fallback'
},
{
inputs: [
{
internalType: 'bytes4',
name: '_signature',
type: 'bytes4'
},
{
internalType: 'address',
name: '_implementation',
type: 'address'
}
],
name: 'addHook',
outputs: [],
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [
{
internalType: 'address',
name: '',
type: 'address'
},
{
internalType: 'address',
name: '',
type: 'address'
},
{
internalType: 'uint256[]',
name: '',
type: 'uint256[]'
},
{
internalType: 'uint256[]',
name: '',
type: 'uint256[]'
},
{
internalType: 'bytes',
name: '',
type: 'bytes'
}
],
name: 'onERC1155BatchReceived',
outputs: [
{
internalType: 'bytes4',
name: '',
type: 'bytes4'
}
],
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [
{
internalType: 'address',
name: '',
type: 'address'
},
{
internalType: 'address',
name: '',
type: 'address'
},
{
internalType: 'uint256',
name: '',
type: 'uint256'
},
{
internalType: 'uint256',
name: '',
type: 'uint256'
},
{
internalType: 'bytes',
name: '',
type: 'bytes'
}
],
name: 'onERC1155Received',
outputs: [
{
internalType: 'bytes4',
name: '',
type: 'bytes4'
}
],
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [
{
internalType: 'address',
name: '',
type: 'address'
},
{
internalType: 'address',
name: '',
type: 'address'
},
{
internalType: 'uint256',
name: '',
type: 'uint256'
},
{
internalType: 'bytes',
name: '',
type: 'bytes'
}
],
name: 'onERC721Received',
outputs: [
{
internalType: 'bytes4',
name: '',
type: 'bytes4'
}
],
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [
{
internalType: 'bytes4',
name: '_signature',
type: 'bytes4'
}
],
name: 'readHook',
outputs: [
{
internalType: 'address',
name: '',
type: 'address'
}
],
stateMutability: 'view',
type: 'function'
},
{
inputs: [
{
internalType: 'bytes4',
name: '_signature',
type: 'bytes4'
}
],
name: 'removeHook',
outputs: [],
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [
{
internalType: 'bytes4',
name: '_interfaceID',
type: 'bytes4'
}
],
name: 'supportsInterface',
outputs: [
{
internalType: 'bool',
name: '',
type: 'bool'
}
],
stateMutability: 'pure',
type: 'function'
},
{
stateMutability: 'payable',
type: 'receive'
}
] as const
9 changes: 9 additions & 0 deletions packages/abi/src/wallet/walletProxyHook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const abi = [
{
type: 'function',
name: 'PROXY_getImplementation',
inputs: [],
outputs: [{ name: '', type: 'address', internalType: 'address' }],
stateMutability: 'view'
}
] as const
35 changes: 34 additions & 1 deletion packages/account/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,46 @@ export class Account {
status: AccountStatus,
chainId: ethers.BigNumberish
): Promise<commons.transaction.Transactionish> {
txs = Array.isArray(txs) ? txs : [txs]
// if onchain wallet config is not up to date
// then we should append an extra transaction that updates it
// to the latest "lazy" state
if (status.onChain.imageHash !== status.imageHash) {
const wallet = this.walletForStatus(chainId, status)
const updateConfig = await wallet.buildUpdateConfigurationTransaction(status.config)
return [Array.isArray(txs) ? txs : [txs], updateConfig.transactions].flat()
txs = [...txs, ...updateConfig.transactions]
}

// On immutable chains, we add the WalletProxyHook
const { proxyImplementationHook } = this.contexts[status.config.version]
if (proxyImplementationHook && (chainId === ChainId.IMMUTABLE_ZKEVM || chainId === ChainId.IMMUTABLE_ZKEVM_TESTNET)) {
const provider = this.providerFor(chainId)
if (provider) {
const hook = new ethers.Contract(this.address, walletContracts.walletProxyHook.abi, provider)
let implementation
try {
implementation = await hook.PROXY_getImplementation()
} catch (e) {
// Handle below
console.log('Error getting implementation address', e)
}
if (!implementation || implementation === ethers.ZeroAddress) {
console.log('Adding wallet proxy hook')
const hooksInterface = new ethers.Interface(walletContracts.moduleHooks.abi)
const tx: commons.transaction.Transaction = {
to: this.address,
data: hooksInterface.encodeFunctionData(hooksInterface.getFunction('addHook')!, [
'0x90611127',
proxyImplementationHook,
]),
gasLimit: 50000, // Expected ~28k gas. Buffer added
delegateCall: false,
revertOnError: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

revertOnError: false, is intentional. We don't want a failure adding the hook to prevent whatever the user's intended transaction is.

value: 0
}
txs = [tx, ...txs]
}
}
}

return txs
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/commons/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export type WalletContext = {
guestModule: string

walletCreationCode: string

proxyImplementationHook?: string;
}

export function addressOf(context: WalletContext, imageHash: ethers.BytesLike) {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ export const DeployedWalletContext: WalletContext = {
guestModule: '0xfea230Ee243f88BC698dD8f1aE93F8301B6cdfaE',
mainModule: '0xfBf8f1A5E00034762D928f46d438B947f5d4065d',
mainModuleUpgradable: '0x4222dcA3974E39A8b41c411FeDDE9b09Ae14b911',
walletCreationCode: '0x603a600e3d39601a805130553df3363d3d373d3d3d363d30545af43d82803e903d91601857fd5bf3'
walletCreationCode: '0x603a600e3d39601a805130553df3363d3d373d3d3d363d30545af43d82803e903d91601857fd5bf3',
proxyImplementationHook: '0x1f56dbAD5e8319F0DE9a323E24A31b5077dEB1a4',
}
3 changes: 2 additions & 1 deletion packages/tests/src/context/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export async function deployV2Context(signer: ethers.Signer): Promise<coreV2.con
guestModule: await guestModule.getAddress(),
universalSigValidator: await universalSigValidator.getAddress(),

walletCreationCode: '0x603a600e3d39601a805130553df3363d3d373d3d3d363d30545af43d82803e903d91601857fd5bf3'
walletCreationCode: '0x603a600e3d39601a805130553df3363d3d373d3d3d363d30545af43d82803e903d91601857fd5bf3',
proxyImplementationHook: '0x1f56dbAD5e8319F0DE9a323E24A31b5077dEB1a4'
}
}
Loading