Skip to content

Commit f0d6e34

Browse files
committed
Adds EIP-1271 Signature Validation Fallback (#4156)
This PR EIP-1271 fallback for smart contract validation since not all chains support the deployless call used in 6792 flow. <!-- start pr-codex --> --- ## PR-Codex overview The focus of this PR is to fix smart contract wallet signature validation on older chains. ### Detailed summary - Updated the prompt text for signing in on the wallet UI - Added a fallback to EIP1271 validation for chains not supporting eth_call simulation - Introduced a new function `verifyEip1271Signature` for EIP1271 signature validation > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent cf4443a commit f0d6e34

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

.changeset/stale-jobs-own.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+
Fix smart contract wallet signature validation on older chains

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
} from "viem";
99
import type { Chain } from "../chains/types.js";
1010
import type { ThirdwebClient } from "../client/client.js";
11+
import { type ThirdwebContract, getContract } from "../contract/contract.js";
12+
import { isValidSignature } from "../extensions/erc1271/__generated__/isValidSignature/read/isValidSignature.js";
1113
import { eth_call } from "../rpc/actions/eth_call.js";
1214
import { getRpcClient } from "../rpc/rpc.js";
1315
import { fromBytes } from "../utils/encoding/from-bytes.js";
@@ -110,8 +112,39 @@ export async function verifyHash({
110112
const hexResult = isHex(result) ? toBytes(result) : result;
111113
return equalBytes(hexResult, toBytes("0x1"));
112114
} catch (error) {
115+
// Some chains do not support the eth_call simulation and will fail, so we fall back to regular EIP1271 validation
116+
const validEip1271 = await verifyEip1271Signature({
117+
hash,
118+
signature: signatureHex,
119+
contract: getContract({
120+
chain,
121+
address,
122+
client,
123+
}),
124+
}).catch(() => false);
125+
if (validEip1271) {
126+
return true;
127+
}
113128
// TODO: Improve overall RPC error handling so we can tell if this was an actual verification failure or some other error
114129
// Verification failed somehow
115130
return false;
116131
}
117132
}
133+
134+
const EIP_1271_MAGIC_VALUE = "0x1626ba7e";
135+
async function verifyEip1271Signature({
136+
hash,
137+
signature,
138+
contract,
139+
}: {
140+
hash: Hex;
141+
signature: Hex;
142+
contract: ThirdwebContract;
143+
}): Promise<boolean> {
144+
const result = await isValidSignature({
145+
hash,
146+
signature,
147+
contract,
148+
});
149+
return result === EIP_1271_MAGIC_VALUE;
150+
}

packages/thirdweb/src/react/web/ui/ConnectWallet/locale/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const connectLocaleEn: ConnectLocale = {
9595
},
9696
signingScreen: {
9797
title: "Signing In",
98-
prompt: "Sign the signature request in your wallet",
98+
prompt: "Signing the signature request in your wallet",
9999
promptForSafe:
100100
"Sign signature request in your wallet & approve transaction in Safe",
101101
approveTransactionInSafe: "Approve transaction in Safe",

0 commit comments

Comments
 (0)