Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing decimal values to FeeMarketEIP1559Transaction generates invalid output silently #1497

Closed
Matko95 opened this issue Sep 28, 2021 · 5 comments · Fixed by #1500
Closed

Comments

@Matko95
Copy link

Matko95 commented Sep 28, 2021

In the snippet attached below, if you pass decimal numbers to the FeeMarketEIP1559Transaction constructor it doesn't throw any errors, but alters the values silently, this can be very dangerous as the final payload when ran in a browser environment converts 33974229950.550003 -> 35624562130324685 which is a much larger number than what was originally passed, increasing the gas price.

const ethereumJsTx = require('@ethereumjs/tx') //  "@ethereumjs/tx": "^3.3.0",

const decimal_gas_fee = 33974229950.550003
const base_fee = 5 * 10 ** 9

const rawTx = {
  maxPriorityFeePerGas: decimal_gas_fee,
  maxFeePerGas: decimal_gas_fee + base_fee,
  chainId: 1,
  nonce: 0,
  gasPrice: null,
  gasLimit: 144000,
  to: '0x0000000000000000000000000000000000000000',
  value: 0,
  data: []
}

const tx = ethereumJsTx.FeeMarketEIP1559Transaction.fromTxData(rawTx)

// Browser environment
// maxFeePerGas: 45061746130324685, maxPriorityFeePerGas: 35624562130324685

// Node.js environment
// maxFeePerGas: 2123389402, maxPriorityFeePerGas: 2123389402

console.log(tx.maxFeePerGas.toString(), tx.maxPriorityFeePerGas.toString())
@holgerd77
Copy link
Member

We are on it, we will discuss in a call later today and provide a hotfix release on the library as soon as possible.

@kongnet
Copy link

kongnet commented Sep 29, 2021

indutny/bn.js#211

@jochem-brouwer
Copy link
Member

Hi @Matko95, thanks for opening this issue. One thing I keep wondering about, which you might have more insight in: why does the browser report different values than the values reported by node?

@holgerd77
Copy link
Member

We have just released new versions of the Util and Tx libraries in #1501 which address the issue and provides a safer instantiation on the integer values.

@Matko95
Copy link
Author

Matko95 commented Sep 30, 2021

Thanks for solving this so quickly, you're awesome!

@jochem-brouwer I found it very confusing that different values were reported as I was testing, can't be sure what's the reason yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants