Fix Transaction.from(tx.toJSON()) roundtrip losing authorizationList and blob fields - #5173
Open
BhariGowda wants to merge 1 commit into
Open
Conversation
…and blob fields toJSON() followed by Transaction.from() was dropping authorizationList on type 4 transactions and blobVersionedHashes/maxFeePerBlobGas on type 3, causing unsignedHash mismatches on roundtrip. Signed transactions also failed to roundtrip since the signature field wasn't being read back from the parsed JSON. Added a full offline test suite run: 114095 passing. Network-dependent suites (contract, ens, providers-avatar/ccip/data/errors/send/wildcard) weren't run locally due to missing API keys, those are covered by CI. One test (test-providers-jsonrpc.ts) needed a small update. It fakes an RPC response by spreading a Transaction's toJSON() and signature.toJSON() together, then deletes v to test the missing-v recovery path. Since this fix makes toJSON() emit signature, that object now takes the signature-present branch in formatTransactionResponse instead of hitting the sabotage. Added signature: null alongside the existing sig: null to keep exercising the same recovery path. Verified the test fails on unmodified transaction.ts and passes with the fix, so this reflects the real behavior change rather than a workaround. blobWrapperVersion is intentionally left out of the roundtrip since sidecars can't round-trip through toJSON in the first place (blobs are 128KB each and are not serialized). Documented that limit in the doc comment. Fixes ethers-io#5172
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5172.
toJSON() followed by Transaction.from() was dropping authorizationList on type 4 transactions and blobVersionedHashes/maxFeePerBlobGas on type 3, causing unsignedHash mismatches on roundtrip. Signed transactions also failed to roundtrip since the signature field wasn't read back from the parsed JSON.
Full offline test suite: 114095 passing across all 20 files. Network-dependent suites (contract, ens, providers-avatar/ccip/data/errors/send/wildcard) weren't run locally due to missing API keys, but are covered by CI.
One existing test needed updating: test-providers-jsonrpc.ts fakes an RPC response by spreading a Transaction's toJSON() and signature.toJSON() together, then deletes v to test the missing-v recovery path. Since this fix makes toJSON() emit signature, that fake response now takes the signature-present branch in formatTransactionResponse instead of hitting the sabotage. I added signature: null alongside the existing sig: null to keep exercising the same recovery path. Confirmed the test fails on unmodified transaction.ts and passes with this fix, so the change reflects the real behavior difference rather than papering over something.
Both sig and signature are emitted in the JSON output — duplicated, but non-breaking. Renaming sig to signature would break any consumer currently reading .sig, and I didn't want to make that semver call in a bug fix PR. Happy to go that direction if you'd prefer.
blobWrapperVersion is intentionally left out since blob sidecars can't round-trip through toJSON in the first place — blobs are 128KB each and aren't serialized. Documented that limit in the doc comment rather than including an inert field.