Web3.js: Possible incorrect parsing of receipt status

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

The Byzantinum fork, IIRC, enabled adding the status to the transaction receipts. But for chains that did not activate it, the status is still null instead of 0x0 or 0x1. Following is the code that parses it to boolean:

https://github.com/ethereum/web3.js/blob/1bbfc5a36f4422a79bb0abfdd4b30aba6b3dc340/packages/web3-core-helpers/src/formatters.js#L219-L221

When testing with some transactions in a chain that did not fork, we saw the status field was incorrectly parsed as false for receipts with status coming as null, which might not be correct as status is actually not provided. This is not enough to say the transaction failed or not.

The condition might be changed to something like the following to properly account for null, 0x0 and 0x1 values:

    if(typeof receipt.status === 'string') {
        receipt.status = Boolean(parseInt(receipt.status));
    }

@frozeman & team, can you please provide your thoughts?

bug

Most helpful comment

@alcuadrado @cgewecke this issue was patched in 1ac78d1 @ #2429 on the 2.x branch but that PR cannot be backported to 1.x. Actually, the only line that needs to be backported, strictly speaking, is this:

--- a/packages/web3-core-helpers/src/formatters.js
+++ b/packages/web3-core-helpers/src/formatters.js
@@ -216,7 +216,7 @@ var outputTransactionReceiptFormatter = function (receipt){
         receipt.contractAddress = utils.toChecksumAddress(receipt.contractAddress);
     }

-    if(typeof receipt.status !== 'undefined') {
+    if(typeof receipt.status !== 'undefined' && receipt.status !== null) {
         receipt.status = Boolean(parseInt(receipt.status));
     }

Issue #3070 says "change causes many 1.x test failures" but it looks like applying this patch on top of v1.2.1 does not break any test.

  2495 passing (25s)

Of course some tests should be added to cover the case of a receipt being returned as null.

All 3 comments

Thanks for submitting this issue. That's true will change it as soon as possible.

@alcuadrado @cgewecke this issue was patched in 1ac78d1 @ #2429 on the 2.x branch but that PR cannot be backported to 1.x. Actually, the only line that needs to be backported, strictly speaking, is this:

--- a/packages/web3-core-helpers/src/formatters.js
+++ b/packages/web3-core-helpers/src/formatters.js
@@ -216,7 +216,7 @@ var outputTransactionReceiptFormatter = function (receipt){
         receipt.contractAddress = utils.toChecksumAddress(receipt.contractAddress);
     }

-    if(typeof receipt.status !== 'undefined') {
+    if(typeof receipt.status !== 'undefined' && receipt.status !== null) {
         receipt.status = Boolean(parseInt(receipt.status));
     }

Issue #3070 says "change causes many 1.x test failures" but it looks like applying this patch on top of v1.2.1 does not break any test.

  2495 passing (25s)

Of course some tests should be added to cover the case of a receipt being returned as null.

@gabmontes Ok excellent. Will open a PR fixing rn Will update #3090 to include this.

Was this page helpful?
0 / 5 - 0 ratings