Closed 9inpachi closed 3 months ago
Hi @9inpachi
I think the reason is
Your signature code is
const signature = await walletClient.signTypedData({
account: ownerAddress,
domain,
types,
primaryType: "Permit",
message: {
owner: ownerAddress,
spender: spenderAddress,
value,
nonce: permitNonces,
deadline,
},
});
and here you use domain
, defined in your code as
const domain = <const>{
name,
version: selectedToken.permitVersion,
chainId: chain.id,
verifyingContract: selectedToken.chainAddresses[chain.id]
};
If you check EIP-712, you can see that one of signed fields of domain separator is salt, and this is missing from your code.
In pufETH this parameter is 0x0000000000000000000000000000000000000000000000000000000000000000 (accessible throught reading eip712Domain method)
However, curve pools initialize salt as previous blockhash at deployment, which is nonzero. Check out field 39 here: https://etherscan.io/token/0xeeda34a377dd0ca676b9511ee1324974fa8d980d#readContract This way you can figure out the salt for curve pools.
The reason your code works for some tokens is that zero salt produces same signature as non-declared salt. You can verify this behavior by placing console.log(depositPermitSignature);
in index.ts
, and running the code with
const domain = <const>{
name,
version: selectedToken.permitVersion,
chainId: chain.id,
verifyingContract: selectedToken.chainAddresses[chain.id],
salt: 0x0000000000000000000000000000000000000000000000000000000000000000,
};
Observe produced signatures with this snippet, and with present code - and you will see that signatures are the same.
TLDR: Add Salt.
Thanks @heswithme for the detailed response!
It's working now after adding the salt as you said. Thanks a lot!
Hi.
Description
I am trying to generate a permit signature for a Curve LP token but the permit I get is not correct and one of our contracts that uses a permit to check if a token is approved reverts transactions.
Example
I have a complete reproducable example which uses two ERC20 tokens namely
pufETH
andpufETHwstE
. Using the exact same code, the permit signature works forpufETH
but doesn't work forpufETHwstE
. Here's the link to the codesandbox: https://codesandbox.io/p/sandbox/curve-lp-permit-signature-rkth43. Please checkconfig.ts
for more information on how to test the example.The example uses the following code for generating the permit signature using viem.