From 5dd80f3af5924daaed42ef4cde777b6a555d05a0 Mon Sep 17 00:00:00 2001 From: Jochem Brouwer Date: Fri, 12 Jul 2024 22:19:28 +0200 Subject: [PATCH] tx/common: remove yParity from tx json interface --- packages/client/src/rpc/helpers.ts | 1 - packages/common/src/interfaces.ts | 2 +- packages/tx/src/baseTransaction.ts | 1 - packages/tx/src/types.ts | 2 -- packages/tx/src/util.ts | 14 +++++++------- packages/tx/test/eip1559.spec.ts | 1 - packages/tx/test/eip4844.spec.ts | 2 -- packages/tx/test/eip7702.spec.ts | 20 ++++++++++---------- packages/tx/test/typedTxsAndEIP2930.spec.ts | 1 - packages/vm/test/util.ts | 3 ++- 10 files changed, 20 insertions(+), 27 deletions(-) diff --git a/packages/client/src/rpc/helpers.ts b/packages/client/src/rpc/helpers.ts index 99528f452a..1fbc1c21d9 100644 --- a/packages/client/src/rpc/helpers.ts +++ b/packages/client/src/rpc/helpers.ts @@ -58,7 +58,6 @@ export const jsonRpcTx = (tx: TypedTransaction, block?: Block, txIndex?: number) s: txJSON.s!, maxFeePerBlobGas: txJSON.maxFeePerBlobGas, blobVersionedHashes: txJSON.blobVersionedHashes, - yParity: txJSON.yParity, } } diff --git a/packages/common/src/interfaces.ts b/packages/common/src/interfaces.ts index 9721b31945..6d4629cb29 100644 --- a/packages/common/src/interfaces.ts +++ b/packages/common/src/interfaces.ts @@ -72,7 +72,7 @@ export type AuthorizationListItem = { chainId: PrefixedHexString address: PrefixedHexString nonce: PrefixedHexString[] - yParity: PrefixedHexString + v: PrefixedHexString r: PrefixedHexString s: PrefixedHexString } diff --git a/packages/tx/src/baseTransaction.ts b/packages/tx/src/baseTransaction.ts index 9a5a9cf186..1f677289c9 100644 --- a/packages/tx/src/baseTransaction.ts +++ b/packages/tx/src/baseTransaction.ts @@ -345,7 +345,6 @@ export abstract class BaseTransaction r: this.r !== undefined ? bigIntToHex(this.r) : undefined, s: this.s !== undefined ? bigIntToHex(this.s) : undefined, chainId: bigIntToHex(this.common.chainId()), - yParity: this.v === 0n || this.v === 1n ? bigIntToHex(this.v) : undefined, } } diff --git a/packages/tx/src/types.ts b/packages/tx/src/types.ts index f37ee76b9a..481afbe4b6 100644 --- a/packages/tx/src/types.ts +++ b/packages/tx/src/types.ts @@ -542,7 +542,6 @@ export interface JsonTx { maxFeePerGas?: PrefixedHexString maxFeePerBlobGas?: PrefixedHexString blobVersionedHashes?: PrefixedHexString[] - yParity?: PrefixedHexString } export type JsonBlobTxNetworkWrapper = JsonTx & { @@ -576,5 +575,4 @@ export interface JsonRpcTx { s: string // DATA, 32 Bytes - ECDSA signature s maxFeePerBlobGas?: string // QUANTITY - max data fee for blob transactions blobVersionedHashes?: string[] // DATA - array of 32 byte versioned hashes for blob transactions - yParity?: string // DATA - parity of the y-coordinate of the public key } diff --git a/packages/tx/src/util.ts b/packages/tx/src/util.ts index d4c4475349..c61b17b5ba 100644 --- a/packages/tx/src/util.ts +++ b/packages/tx/src/util.ts @@ -138,7 +138,7 @@ export class AuthorizationLists { if (isAuthorizationList(authorizationList)) { AuthorizationListJSON = authorizationList const newAuthorizationList: AuthorizationListBytes = [] - const jsonItems = ['chainId', 'address', 'nonce', 'yParity', 'r', 's'] + const jsonItems = ['chainId', 'address', 'nonce', 'v', 'r', 's'] for (let i = 0; i < authorizationList.length; i++) { const item: AuthorizationListItem = authorizationList[i] for (const key of jsonItems) { @@ -153,11 +153,11 @@ export class AuthorizationLists { for (let j = 0; j < item.nonce.length; j++) { nonceList.push(hexToBytes(item.nonce[j])) } - const yParity = hexToBytes(item.yParity) + const v = hexToBytes(item.v) const r = hexToBytes(item.r) const s = hexToBytes(item.s) - newAuthorizationList.push([chainId, addressBytes, nonceList, yParity, r, s]) + newAuthorizationList.push([chainId, addressBytes, nonceList, v, r, s]) } bufferAuthorizationList = newAuthorizationList } else { @@ -173,14 +173,14 @@ export class AuthorizationLists { for (let j = 0; j < nonces.length; j++) { nonceList.push(bytesToHex(nonces[j])) } - const yParity = bytesToHex(data[3]) + const v = bytesToHex(data[3]) const r = bytesToHex(data[4]) const s = bytesToHex(data[5]) const jsonItem: AuthorizationListItem = { chainId, address, nonce: nonceList, - yParity, + v, r, s, } @@ -200,10 +200,10 @@ export class AuthorizationLists { const authorizationListItem = authorizationList[key] const address = authorizationListItem[1] const nonceList = authorizationListItem[2] - const yParity = authorizationListItem[3] + const v = authorizationListItem[3] const r = authorizationListItem[4] const s = authorizationListItem[5] - validateNoLeadingZeroes({ yParity, r, s }) + validateNoLeadingZeroes({ v, r, s }) if (address.length !== 20) { throw new Error('Invalid EIP-7702 transaction: address length should be 20 bytes') } diff --git a/packages/tx/test/eip1559.spec.ts b/packages/tx/test/eip1559.spec.ts index 7eada2aac7..20b0dd4083 100644 --- a/packages/tx/test/eip1559.spec.ts +++ b/packages/tx/test/eip1559.spec.ts @@ -259,7 +259,6 @@ describe('[FeeMarketEIP1559Transaction]', () => { v: '0x0', r: '0xf924cb68412c8f1cfd74d9b581c71eeaf94fff6abdde3e5b02ca6b2931dcf47', s: '0x7dd1c50027c3e31f8b565e25ce68a5072110f61fce5eee81b195dd51273c2f83', - yParity: '0x0', } assert.deepEqual(json, expectedJSON, 'Should return expected JSON dict') }) diff --git a/packages/tx/test/eip4844.spec.ts b/packages/tx/test/eip4844.spec.ts index 6a9480d7c3..809b074f36 100644 --- a/packages/tx/test/eip4844.spec.ts +++ b/packages/tx/test/eip4844.spec.ts @@ -154,7 +154,6 @@ describe('fromTxData using from a json', () => { accessList: null, maxFeePerBlobGas: '0xb2d05e00', blobVersionedHashes: ['0x01b0a4cdd5f55589f5c5b4d46c76704bb6ce95c0a8c09f77f197a57808dded28'], - yParity: '0x0', } const txMeta = { hash: '0xe5e02be0667b6d31895d1b5a8b916a6761cbc9865225c6144a3e2c50936d173e', @@ -632,7 +631,6 @@ describe('Network wrapper deserialization test', () => { accessList: [], maxFeePerBlobGas: '0x5f5e100', blobVersionedHashes: ['0x0172ff1d4f354eebdb3cd0cb64e41ac584359094373fd5f979bcccbd6072d936'], - yParity: '0x0', } const txMeta = { sender: '0x652a2b04934d96c26c4710853021779fb9f525d2', diff --git a/packages/tx/test/eip7702.spec.ts b/packages/tx/test/eip7702.spec.ts index 3e7383681b..6b1b29517a 100644 --- a/packages/tx/test/eip7702.spec.ts +++ b/packages/tx/test/eip7702.spec.ts @@ -44,7 +44,7 @@ describe('[EOACodeEIP7702Transaction]', () => { chainId: '0x', address: `0x${'20'.repeat(21)}`, nonce: [], - yParity: '0x1', + v: '0x1', r: ones32, s: ones32, }, @@ -62,7 +62,7 @@ describe('[EOACodeEIP7702Transaction]', () => { chainId: '0x', address: `0x${'20'.repeat(20)}`, nonce: ['0x1', '0x2'], - yParity: '0x1', + v: '0x1', r: ones32, s: ones32, }, @@ -80,7 +80,7 @@ describe('[EOACodeEIP7702Transaction]', () => { chainId: '0x', address: `0x${'20'.repeat(20)}`, nonce: ['0x1'], - yParity: '0x1', + v: '0x1', r: ones32, s: undefined as never, }, @@ -98,7 +98,7 @@ describe('[EOACodeEIP7702Transaction]', () => { chainId: '0x', address: `0x${'20'.repeat(20)}`, nonce: ['0x1'], - yParity: '0x1', + v: '0x1', r: undefined as never, s: ones32, }, @@ -116,7 +116,7 @@ describe('[EOACodeEIP7702Transaction]', () => { chainId: '0x', address: `0x${'20'.repeat(20)}`, nonce: ['0x1'], - yParity: undefined as never, + v: undefined as never, r: ones32, s: ones32, }, @@ -124,7 +124,7 @@ describe('[EOACodeEIP7702Transaction]', () => { }, { common } ) - }, 'yParity is not defined') + }, 'v is not defined') assert.throws(() => { EOACodeEIP7702Transaction.fromTxData( @@ -134,7 +134,7 @@ describe('[EOACodeEIP7702Transaction]', () => { chainId: '0x', address: `0x${'20'.repeat(20)}`, nonce: undefined as never, - yParity: '0x1', + v: '0x1', r: ones32, s: ones32, }, @@ -152,7 +152,7 @@ describe('[EOACodeEIP7702Transaction]', () => { chainId: '0x', address: undefined as never, nonce: ['0x1'], - yParity: '0x1', + v: '0x1', r: ones32, s: ones32, }, @@ -170,7 +170,7 @@ describe('[EOACodeEIP7702Transaction]', () => { chainId: undefined as never, address: `0x${'20'.repeat(20)}`, nonce: ['0x1'], - yParity: '0x1', + v: '0x1', r: ones32, s: ones32, }, @@ -188,7 +188,7 @@ describe('[EOACodeEIP7702Transaction]', () => { chainId: '0x', address: `0x${'20'.repeat(20)}`, nonce: ['0x1'], - yParity: '0x1', + v: '0x1', r: ones32, s: ones32, }, diff --git a/packages/tx/test/typedTxsAndEIP2930.spec.ts b/packages/tx/test/typedTxsAndEIP2930.spec.ts index 57249da644..32cde1fd69 100644 --- a/packages/tx/test/typedTxsAndEIP2930.spec.ts +++ b/packages/tx/test/typedTxsAndEIP2930.spec.ts @@ -664,7 +664,6 @@ describe('[AccessListEIP2930Transaction] -> Class Specific Tests', () => { v: '0x0', r: '0x294ac94077b35057971e6b4b06dfdf55a6fbed819133a6c1d31e187f1bca938d', s: '0xbe950468ba1c25a5cb50e9f6d8aa13c8cd21f24ba909402775b262ac76d374d', - yParity: '0x0', } assert.deepEqual(signed.toJSON(), expectedJSON) diff --git a/packages/vm/test/util.ts b/packages/vm/test/util.ts index 187af17d19..7b3ab7f211 100644 --- a/packages/vm/test/util.ts +++ b/packages/vm/test/util.ts @@ -128,7 +128,8 @@ export function makeTx( // Convert `v` keys to `yParity` for (const signature of txData.authorizationList) { if (signature.v !== undefined) { - signature.yParity = bytesToHex(unpadBytes(hexToBytes(signature.v))) + // Ensure that the authorization signature is of type "unpadded hex", e.g.: '0x', '0x1', but not '0x0', '0x00', or '0x01' + signature.v = bytesToHex(unpadBytes(hexToBytes(signature.v))) } if (signature.nonce !== undefined && signature.nonce[0] === '0x00') { signature.nonce[0] = '0x'