Skip to content

Fix Transaction.from(tx.toJSON()) roundtrip losing authorizationList and blob fields - #5173

Open
BhariGowda wants to merge 1 commit into
ethers-io:mainfrom
BhariGowda:fix-transaction-roundtrip-authorizationList
Open

Fix Transaction.from(tx.toJSON()) roundtrip losing authorizationList and blob fields#5173
BhariGowda wants to merge 1 commit into
ethers-io:mainfrom
BhariGowda:fix-transaction-roundtrip-authorizationList

Conversation

@BhariGowda

Copy link
Copy Markdown

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.

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transaction.from(tx.toJSON()) roundtrip drops authorizationList, hash mismatch on type 4

1 participant