This repository was archived by the owner on Mar 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Bad input interpretation for type parameter to transaction; also exact type is not always respected #4597
Copy link
Copy link
Closed
Labels
1.x1.0 related issues1.0 related issuesBugAddressing a bugAddressing a bugwork-in-progressPrevents stalebot from closing a prPrevents stalebot from closing a pr
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
The type parameter to the transaction has some problems with the interpretation of its input. Currently, these problems don't matter since the largest legal transaction type is 2, but they could in the future.
Specifically:
- If a decimal string is given, it will be interpreted as hex rather than as decimal.
- If a number (as
numberorBN; I haven't triedBigNumberbut I assume it's the same) is given, it will be treated as if it were a decimal string and have its decimal digits treated as hex. I.e., if you enter the number10, it's treated as16! Worse yet, if you enter the number0x10, intending to get 16, you'll instead get0x16! This one is definitely the worst part, I'd say. - Types greater than or equal to 0xc0 are treated as if they were 0, rather than being rejected as illegal.
Also, the exact type entered is not always respected. For instance if you specify a type of 1 but don't specify an access list, you'll get a transaction of type 0, rather than a transaction of type 1 with an empty access list.
Expected Behavior
- Numbers should be treated as the numbers that they are, not have their decimal digits read as hex.
- Decimal strings, that do not have a
"0x"prefix, should be treated as decimal, not hex. - Types greater than or equal to 0xc0 should be treated as invalid, not 0.
- The exact type entered should always be respected; type 1 should not be converted to type 0 when no access list is specified (instead the access list should be treated as empty).
Steps to Reproduce
Examples to try:
web3.eth.sendTransaction({ from: accounts[0], to: accounts[1], type: 10 }) //yields 16 instead of 10
web3.eth.sendTransaction({ from: accounts[0], to: accounts[1], type: "10" }) //yields 16 instead of 10
web3.eth.sendTransaction({ from: accounts[0], to: accounts[1], type: 0x10 }) //yields 0x16 instead of 0x10!
web3.eth.sendTransaction({ from: accounts[0], to: accounts[1], type: "0xc0" }) //yields 0 instead of invalid
web3.eth.sendTransaction({ from: accounts[0], to: accounts[1], type: 1 }) //yields 0 rather than 1 unless accessList is also givenWeb3.js Version
1.5.3
Environment
- Operating System: Release Linux Mint 20.2 Uma 64-bit
- Node.js Version: 12.21.0
- NPM Version: 6.14.11
Anything Else?
That last one about type 1 should maybe be a separate issue, let me know if you want me to split this up.
Metadata
Metadata
Assignees
Labels
1.x1.0 related issues1.0 related issuesBugAddressing a bugAddressing a bugwork-in-progressPrevents stalebot from closing a prPrevents stalebot from closing a pr