Skip to content

fix: signMessage for Kernel 0.2.3 and 0.2.4 #324

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

Merged
merged 7 commits into from
Nov 9, 2024
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
5 changes: 5 additions & 0 deletions .changeset/smooth-countries-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"permissionless": patch
---

Fixed signMessage & signTypeData for Kernel version 0.2.3 and 0.2.4
9 changes: 9 additions & 0 deletions packages/permissionless-test/mock-aa-infra/alto/constants.ts

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions packages/permissionless-test/mock-aa-infra/alto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {
ENTRY_POINT_V06_CREATECALL,
ENTRY_POINT_V07_CREATECALL,
ERC_7579_TEST_MODULE_CREATECALL,
KERNEL_V06_ACCOUNT_V2_1_LOGIC_CREATECALL,
KERNEL_V06_ACCOUNT_V2_2_LOGIC_CREATECALL,
KERNEL_V06_ACCOUNT_V2_3_LOGIC_CREATECALL,
KERNEL_V06_ACCOUNT_V2_4_LOGIC_CREATECALL,
KERNEL_V06_ECDSA_VALIDATOR_V2_2_CREATECALL,
KERNEL_V06_FACTORY_CREATECALL,
KERNEL_V07_ACCOUNT_V3_LOGIC_CREATECALL,
Expand Down Expand Up @@ -186,6 +189,24 @@ export const setupContracts = async (rpc: string) => {
gas: 15_000_000n,
nonce: nonce++
}),
walletClient.sendTransaction({
to: DETERMINISTIC_DEPLOYER,
data: KERNEL_V06_ACCOUNT_V2_3_LOGIC_CREATECALL,
gas: 15_000_000n,
nonce: nonce++
}),
walletClient.sendTransaction({
to: DETERMINISTIC_DEPLOYER,
data: KERNEL_V06_ACCOUNT_V2_4_LOGIC_CREATECALL,
gas: 15_000_000n,
nonce: nonce++
}),
walletClient.sendTransaction({
to: DETERMINISTIC_DEPLOYER,
data: KERNEL_V06_ACCOUNT_V2_1_LOGIC_CREATECALL,
gas: 15_000_000n,
nonce: nonce++
}),
walletClient.sendTransaction({
to: DETERMINISTIC_DEPLOYER,
data: KERNEL_V06_FACTORY_CREATECALL,
Expand Down Expand Up @@ -496,6 +517,27 @@ export const setupContracts = async (rpc: string) => {
data: "0xbb30a9740000000000000000000000000da6a956b9488ed4dd761e59f52fdc6c8068e6b50000000000000000000000000000000000000000000000000000000000000001" /* setImplementation(address _implementation,bool _allow) */
})

// register 0xf048AD83CB2dfd6037A43902a2A5Be04e53cd2Eb
await sendTransaction(walletClient, {
account: kernelFactoryOwner,
to: "0x5de4839a76cf55d0c90e2061ef4386d962E15ae3" /* kernel factory v0.6 */,
data: "0xbb30a974000000000000000000000000f048ad83cb2dfd6037a43902a2a5be04e53cd2eb0000000000000000000000000000000000000000000000000000000000000001" /* setImplementation(address _implementation,bool _allow) */
})

// register 0xD3F582F6B4814E989Ee8E96bc3175320B5A540ab
await sendTransaction(walletClient, {
account: kernelFactoryOwner,
to: "0x5de4839a76cf55d0c90e2061ef4386d962E15ae3" /* kernel factory v0.6 */,
data: "0xbb30a974000000000000000000000000d3f582f6b4814e989ee8e96bc3175320b5a540ab0000000000000000000000000000000000000000000000000000000000000001" /* setImplementation(address _implementation,bool _allow) */
})

// register 0xd3082872F8B06073A021b4602e022d5A070d7cfC
await sendTransaction(walletClient, {
account: kernelFactoryOwner,
to: "0x5de4839a76cf55d0c90e2061ef4386d962E15ae3" /* kernel factory v0.6 */,
data: "0xbb30a974000000000000000000000000d3082872f8b06073a021b4602e022d5a070d7cfc0000000000000000000000000000000000000000000000000000000000000001" /* setImplementation(address _implementation,bool _allow) */
})

// register 0x6723b44Abeec4E71eBE3232BD5B455805baDD22f
await sendTransaction(walletClient, {
account: kernelFactoryOwner,
Expand Down Expand Up @@ -566,9 +608,12 @@ export const setupContracts = async (rpc: string) => {
"0x0000002512019Dafb59528B82CB92D3c5D2423ac", // Biconomy Account Logic V0.2
"0x000000a56Aaca3e9a4C479ea6b6CD0DbcB6634F5", // Biconomy Factory Address
"0x0bBa6d96BD616BedC6BFaa341742FD43c60b83C1", // Biconomy Default Fallback Handler
"0xf048AD83CB2dfd6037A43902a2A5Be04e53cd2Eb", // Kernel 0.2.1 Account Logic
"0xd9AB5096a832b9ce79914329DAEE236f8Eea0390", // Kernel v0.2.2 ECDSA Valdiator
"0x0DA6a956B9488eD4dd761E59f52FDc6c8068E6B5", // Kernel v0.2.2 Account Logic
"0xD3F582F6B4814E989Ee8E96bc3175320B5A540ab", // Kernel v0.2.3 Account Logic
"0x5de4839a76cf55d0c90e2061ef4386d962E15ae3", // Kernel v0.2.2 Factory
"0xd3082872F8B06073A021b4602e022d5A070d7cfC", // Kernel v0.2.4 Factory
"0x8104e3Ad430EA6d354d013A6789fDFc71E671c43", // Kernel v0.3.0 ECDSA Valdiator
"0x94F097E1ebEB4ecA3AAE54cabb08905B239A7D27", // Kernel v0.3.0 Account Logic
"0x6723b44Abeec4E71eBE3232BD5B455805baDD22f", // Kernel v0.3.0 Factory
Expand Down
57 changes: 54 additions & 3 deletions packages/permissionless-test/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,67 @@ export const getCoreSmartAccounts = () => [
isEip1271Compliant: false
},
{
name: "Kernel",
name: "Kernel 0.2.1",
getSmartAccountClient: async <entryPointVersion extends "0.6" | "0.7">(
conf: AAParamType<entryPointVersion>
) =>
getBundlerClient({
account: await getKernelEcdsaClient(conf),
account: await getKernelEcdsaClient({
...conf,
version: "0.2.1" as KernelVersion<entryPointVersion>
}),
...conf
}),
supportsEntryPointV06: true,
supportsEntryPointV07: true,
supportsEntryPointV07: false,
isEip1271Compliant: true
},
{
name: "Kernel 0.2.2",
getSmartAccountClient: async <entryPointVersion extends "0.6" | "0.7">(
conf: AAParamType<entryPointVersion>
) =>
getBundlerClient({
account: await getKernelEcdsaClient({
...conf,
version: "0.2.2" as KernelVersion<entryPointVersion>
}),
...conf
}),
supportsEntryPointV06: true,
supportsEntryPointV07: false,
isEip1271Compliant: true
},
{
name: "Kernel 0.2.3",
getSmartAccountClient: async <entryPointVersion extends "0.6" | "0.7">(
conf: AAParamType<entryPointVersion>
) =>
getBundlerClient({
account: await getKernelEcdsaClient({
...conf,
version: "0.2.3" as KernelVersion<entryPointVersion>
}),
...conf
}),
supportsEntryPointV06: true,
supportsEntryPointV07: false,
isEip1271Compliant: true
},
{
name: "Kernel 0.2.4",
getSmartAccountClient: async <entryPointVersion extends "0.6" | "0.7">(
conf: AAParamType<entryPointVersion>
) =>
getBundlerClient({
account: await getKernelEcdsaClient({
...conf,
version: "0.2.4" as KernelVersion<entryPointVersion>
}),
...conf
}),
supportsEntryPointV06: true,
supportsEntryPointV07: false,
isEip1271Compliant: true
},
{
Expand Down
3 changes: 1 addition & 2 deletions packages/permissionless/accounts/kernel/utils/signMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
hashMessage
} from "viem"
import { signMessage as _signMessage } from "viem/actions"
import { isKernelV2 } from "./isKernelV2.js"
import {
type WrapMessageHashParams,
wrapMessageHash
Expand All @@ -22,7 +21,7 @@ export async function signMessage({
message: SignableMessage
owner: LocalAccount
} & WrapMessageHashParams): Promise<SignMessageReturnType> {
if (isKernelV2(accountVersion)) {
if (accountVersion === "0.2.1" || accountVersion === "0.2.2") {
return owner.signMessage({
message
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
hashTypedData,
validateTypedData
} from "viem"
import { isKernelV2 } from "./isKernelV2.js"
import {
type WrapMessageHashParams,
wrapMessageHash
Expand All @@ -26,7 +25,7 @@ export async function signTypedData(
...typedData
} = parameters

if (isKernelV2(accountVersion)) {
if (accountVersion === "0.2.1" || accountVersion === "0.2.2") {
return owner.signTypedData({
...typedData
})
Expand Down
16 changes: 10 additions & 6 deletions packages/permissionless/accounts/kernel/utils/wrapMessageHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "viem"
import { type Address, domainSeparator } from "viem"
import type { KernelVersion } from "../toEcdsaKernelSmartAccount.js"
import { isKernelV2 } from "./isKernelV2.js"

export type WrapMessageHashParams = {
kernelVersion: KernelVersion<"0.6" | "0.7">
Expand All @@ -26,12 +27,15 @@ export const wrapMessageHash = (
verifyingContract: accountAddress
}
})
const wrappedMessageHash = keccak256(
encodeAbiParameters(
[{ type: "bytes32" }, { type: "bytes32" }],
[keccak256(stringToHex("Kernel(bytes32 hash)")), messageHash]
)
)
const wrappedMessageHash = isKernelV2(kernelVersion)
? messageHash
: keccak256(
encodeAbiParameters(
[{ type: "bytes32" }, { type: "bytes32" }],
[keccak256(stringToHex("Kernel(bytes32 hash)")), messageHash]
)
)

const digest = keccak256(
concatHex(["0x1901", _domainSeparator, wrappedMessageHash])
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe.each(getCoreSmartAccounts())(
({
getSmartAccountClient,
supportsEntryPointV06,
supportsEntryPointV07
supportsEntryPointV07,
name
}) => {
testWithRpc.skipIf(!supportsEntryPointV06)(
"prepareUserOperationForErc20Paymaster_v06",
Expand Down Expand Up @@ -94,18 +95,22 @@ describe.each(getCoreSmartAccounts())(

expect(receipt).toBeTruthy()
expect(receipt).toBeTruthy()
expect(receipt.success).toBeTruthy()

const FINAL_TOKEN_BALANCE = await tokenBalanceOf(
smartAccountClient.account.address,
rpc.anvilRpc
)
const FINAL_ETH_BALANCE = await publicClient.getBalance({
address: smartAccountClient.account.address
})
if (name !== "Kernel 0.2.1") {
expect(receipt.success).toBeTruthy()
const FINAL_TOKEN_BALANCE = await tokenBalanceOf(
smartAccountClient.account.address,
rpc.anvilRpc
)
const FINAL_ETH_BALANCE = await publicClient.getBalance({
address: smartAccountClient.account.address
})

expect(FINAL_TOKEN_BALANCE).toBeLessThan(INITIAL_TOKEN_BALANCE) // Token balance should be deducted
expect(FINAL_ETH_BALANCE).toEqual(INTIAL_ETH_BALANCE) // There should be no ETH balance change
expect(FINAL_TOKEN_BALANCE).toBeLessThan(
INITIAL_TOKEN_BALANCE
) // Token balance should be deducted
expect(FINAL_ETH_BALANCE).toEqual(INTIAL_ETH_BALANCE) // There should be no ETH balance change
}
}
)

Expand Down