[SDK] @TODO: the returned hash did not match #814
-
Team or ProjectNo response Select the SDKJavaScript EnvironmentMainnet Issue DescriptionThis is literally an error returned by the lib: Well thanks for the detailed explanation. Why doesn't it match? I faced similar error in Now I updated to Expected Behavior¯\_(ツ)_/¯ Code ExampleSomething like this:
Repo Link (Optional)No response |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
It seems like you're encountering an issue where the transaction hash returned by the Here are a few steps you can take to troubleshoot and potentially resolve this issue:
If these steps do not resolve the issue, consider providing more details such as the exact error message and transaction details to the ZKsync developers community for further assistance. Your feedback helps us serve you better. If this fully addresses your question, please give it a thumbs up. If it doesn't, please give it a thumbs down. This will inform the community and team so we can improve our support. |
Beta Was this translation helpful? Give feedback.
-
Hi, this seems to be a bug in zksync-ethers. Please tell me the exact version of zksync-ethers you are using? Could you also provide a full reproduction example? I believe it may matter how you are calling zksync-ethers to send the transaction and this is not shown in the provided code example. |
Beta Was this translation helpful? Give feedback.
-
The EIP712 transaction is not constructed correctly and that is why hashes don't match. Here is the updated example for minimal changes that works on Sepolia: const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const wallet = new Wallet(PRIVATE_KEY, provider);
function serializePaymasterTx(
{transaction, signature}: { transaction: types.TransactionLike; signature: string; }
) {
return utils.serializeEip712(
{
...transaction,
customData: {...transaction.customData, customSignature: signature},
},
signature
);
}
async function sendTransaction(transaction: types.TransactionLike) {
const signer = new EIP712Signer(new ethers.Wallet(PRIVATE_KEY), Number((await provider.getNetwork()).chainId));
const signature = await signer.sign(transaction)
const rawTransaction = serializePaymasterTx({
transaction,
signature,
});
return await provider.broadcastTransaction(rawTransaction);
}
const tokenAddress = '0x927488F48ffbc32112F1fF721759649A89721F8F'; // Crown token which can be minted for free
const paymasterAddress = '0x13D0D8550769f59aa241a41897D4859c87f7Dd46'; // Paymaster for Crown token
const tx = await sendTransaction({
chainId: (await provider.getNetwork()).chainId,
from: wallet.address,
to: '0x81E9D85b65E9CC8618D85A1110e4b1DF63fA30d9',
value: ethers.parseEther('0.01'),
nonce: await wallet.getNonce(),
gasLimit: 200_000n,
maxFeePerGas: 250_000_000_000n,
customData: {
paymasterParams: utils.getPaymasterParams(paymasterAddress, {
type: 'ApprovalBased',
token: tokenAddress,
minimalAllowance: 1,
innerInput: new Uint8Array(),
})
}
})
const receipt = await tx.wait();
console.log(receipt); output:
The easiest way is to utilize EIP712Signer. If that does not work for you, there is also static method Eip712Signer.getSignedDigest that returns the hash of the typed data. You just need to sign the hash to get the signature of the typed data. |
Beta Was this translation helpful? Give feedback.
-
I have created a full reproduction project: It created a basic Send transaction and uses zksync paymaster api The "wrong hash" error is reproduced: @cytadela8 @danijelTxFusion Please check it out |
Beta Was this translation helpful? Give feedback.
-
I have found the issue.
This produces wrong hash The issue didn't happen in In I've created a PR with the fix: zksync-sdk/zksync-ethers#228 |
Beta Was this translation helpful? Give feedback.
I have found the issue.
EIP712Signer.getSignInput
has a bug where it incorrectly fallbacks zeromaxPriorityFeePerGas
tomaxFeePerGas
This produces wrong hash
The issue didn't happen in
zksync-ethers@v5
because zero value looked like0x0
or{ "type": "BigNumber", "hex": "0x00" }
and so the||
operator didn't fall throughIn
v6
, value is now a BigInt0n
and this leads to the bugI've created a PR with the fix: zksync-sdk/zksync-ethers#228