Skip to content

Commit a67d342

Browse files
[SDK] fix: Improve smart wallet signature verification (#6040)
1 parent 60edce4 commit a67d342

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

.changeset/kind-beers-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Always use 712 signature verification if the smart account is already deployed

apps/playground-web/src/components/account-abstraction/sponsored-tx-zksync.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"use client";
2-
32
import { useState } from "react";
43
import { getContract } from "thirdweb";
54
import { zkSyncSepolia } from "thirdweb/chains";
@@ -15,6 +14,12 @@ import { shortenHex } from "thirdweb/utils";
1514
import { THIRDWEB_CLIENT } from "../../lib/client";
1615
import { WALLETS } from "../../lib/constants";
1716

17+
// const chain = abstractTestnet;
18+
// const editionDropContract = getContract({
19+
// client: THIRDWEB_CLIENT,
20+
// address: "0x8A24a7Df38fA5fCCcFD1259e90Fb6996fDdfcADa",
21+
// chain,
22+
// });
1823
const chain = zkSyncSepolia;
1924
const editionDropContract = getContract({
2025
client: THIRDWEB_CLIENT,
@@ -83,6 +88,7 @@ export function SponsoredTxZksyncPreview() {
8388
metadata: nft?.metadata,
8489
}}
8590
onError={(error) => {
91+
console.error("error", error);
8692
alert(`Error: ${error.message}`);
8793
}}
8894
onClick={() => {

packages/thirdweb/src/auth/verify-hash.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { isValidSignature } from "../extensions/erc1271/__generated__/isValidSig
1010
import { eth_call } from "../rpc/actions/eth_call.js";
1111
import { getRpcClient } from "../rpc/rpc.js";
1212
import { isZkSyncChain } from "../utils/any-evm/zksync/isZkSyncChain.js";
13+
import { isContractDeployed } from "../utils/bytecode/is-contract-deployed.js";
1314
import { fromBytes } from "../utils/encoding/from-bytes.js";
1415
import { type Hex, hexToBool, isHex } from "../utils/encoding/hex.js";
1516
import { serializeErc6492Signature } from "./serialize-erc6492-signature.js";
@@ -75,6 +76,33 @@ export async function verifyHash({
7576
);
7677
})();
7778

79+
const isDeployed = await isContractDeployed(
80+
getContract({
81+
address,
82+
client,
83+
chain,
84+
}),
85+
);
86+
87+
if (isDeployed) {
88+
const validEip1271 = await verifyEip1271Signature({
89+
hash,
90+
signature: signatureHex,
91+
contract: getContract({
92+
chain,
93+
address,
94+
client,
95+
}),
96+
}).catch((err) => {
97+
console.error("Error verifying EIP-1271 signature", err);
98+
return false;
99+
});
100+
if (validEip1271) {
101+
return true;
102+
}
103+
}
104+
105+
// contract not deployed, use erc6492 validator to verify signature
78106
const wrappedSignature: Hex = await (async () => {
79107
// If no factory is provided, we have to assume its already deployed or is an EOA
80108
// TODO: Figure out how to automatically tell if our default factory was used
@@ -95,6 +123,7 @@ export async function verifyHash({
95123
to?: string;
96124
data: Hex;
97125
};
126+
98127
const zkSyncChain = await isZkSyncChain(chain);
99128
const abi = ox__Abi.from(ox__WrappedSignature.universalSignatureValidatorAbi);
100129
if (zkSyncChain) {

packages/thirdweb/src/wallets/smart/lib/signing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ async function checkFor712Factory({
268268
}
269269

270270
/**
271-
* Deployes a smart account via a dummy transaction.
271+
* Deployes a smart account via a dummy transaction. If the account is already deployed, this will do nothing.
272272
*
273273
* @param args - Arguments for the deployment.
274274
* @param args.smartAccount - The smart account to deploy.

0 commit comments

Comments
 (0)