Web3.js: chainId larger than 0x3fffffff messes up transaction signature recovery

Created on 3 May 2019  路  11Comments  路  Source: ChainSafe/web3.js

Description

The transactions still seem to send/work fine, but recovery gives incorrect results.

Expected behavior

Correct results from recoverTransaction() regardless of transaction chainId.

Actual behavior

Correct results from recoverTransaction() for chainIds of 0x3fffffff and lower.
Incorrect results from recoverTransaction() for chainIds of 0x40000000 and higher. (Ganache defaults to timestamp as chain ID and easily shoots past this.)

Steps to reproduce the behavior

let tx = {
  chainId: "0x1",
  gasLimit: "0x927c0",
  gasPrice: "0x4a817c800",
  nonce: "0x9",
  to: "0x0000000000000000000000000000000000000000",
  value: 100
};
const pk = 'a44de2416ee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c4';
const sign = web3.eth.accounts.signTransaction;
const recover = web3.eth.accounts.recoverTransaction;

let signed = await sign(tx, pk);
console.log(recover(signed.rawTransaction));
// > 0xE2a2776777F90e4e38989486544d472bAB067158

tx.chainId = "0x3ffffffe";
signed = await sign(tx, pk);
console.log(recover(signed.rawTransaction));
// > 0xE2a2776777F90e4e38989486544d472bAB067158

tx.chainId = "0x3fffffff";
signed = await sign(tx, pk);
console.log(recover(signed.rawTransaction));
// > 0xE2a2776777F90e4e38989486544d472bAB067158

tx.chainId = "0x40000000";
signed = await sign(tx, pk);
console.log(recover(signed.rawTransaction));
// > 0x3637aa4F877204708cCC92d153648D0e1fa0149e

tx.chainId = "0x40000001";
signed = await sign(tx, pk);
console.log(recover(signed.rawTransaction));
// > 0x1e5B6F3Ca367B664148DD2F71E327daB0bC913Ad

Versions

beta.54

1.x 2.x Stale bug

All 11 comments

Thanks for opening this issue! I will test and if required fix it asap.

@Fang- @nivida I tested this and it seems to be a bug during the recovery (web3.eth.accounts.recoverTransaction) process. So, I tried to reproduce the above code using ethereumjs-tx too and that was working fine. So, One option is to use ethereumjs-tx at the time of recovery too, as we are already using ethereumjs-tx during the signing (web3.eth.accounts.signTransaction) process.

@nivida what's your thinking here. Should we use ethereumjs-tx in recoverTransaction too?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions

Can still reproduce on 1.2.9, fwiw. This is tagged as "2.x". Does that mean this won't be fixed in 1.x?

@Fang- thanks for the update, I have adjusted the labels to make sure we also address this in 1.x

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

Bumping as not stale, considering I haven't seen this referenced as fixed yet.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

Ditto.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oktapodia picture oktapodia  路  3Comments

SCBuergel picture SCBuergel  路  3Comments

webersson picture webersson  路  3Comments

zamoore picture zamoore  路  3Comments

mishell-trickster picture mishell-trickster  路  3Comments