Skip to content

Commit

Permalink
tx/common: remove yParity from tx json interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Jul 12, 2024
1 parent ef20930 commit 5dd80f3
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 27 deletions.
1 change: 0 additions & 1 deletion packages/client/src/rpc/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export type AuthorizationListItem = {
chainId: PrefixedHexString
address: PrefixedHexString
nonce: PrefixedHexString[]
yParity: PrefixedHexString
v: PrefixedHexString
r: PrefixedHexString
s: PrefixedHexString
}
Expand Down
1 change: 0 additions & 1 deletion packages/tx/src/baseTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ export abstract class BaseTransaction<T extends TransactionType>
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,
}
}

Expand Down
2 changes: 0 additions & 2 deletions packages/tx/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ export interface JsonTx {
maxFeePerGas?: PrefixedHexString
maxFeePerBlobGas?: PrefixedHexString
blobVersionedHashes?: PrefixedHexString[]
yParity?: PrefixedHexString
}

export type JsonBlobTxNetworkWrapper = JsonTx & {
Expand Down Expand Up @@ -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
}
14 changes: 7 additions & 7 deletions packages/tx/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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,
}
Expand All @@ -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')
}
Expand Down
1 change: 0 additions & 1 deletion packages/tx/test/eip1559.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ describe('[FeeMarketEIP1559Transaction]', () => {
v: '0x0',
r: '0xf924cb68412c8f1cfd74d9b581c71eeaf94fff6abdde3e5b02ca6b2931dcf47',
s: '0x7dd1c50027c3e31f8b565e25ce68a5072110f61fce5eee81b195dd51273c2f83',
yParity: '0x0',
}
assert.deepEqual(json, expectedJSON, 'Should return expected JSON dict')
})
Expand Down
2 changes: 0 additions & 2 deletions packages/tx/test/eip4844.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ describe('fromTxData using from a json', () => {
accessList: null,
maxFeePerBlobGas: '0xb2d05e00',
blobVersionedHashes: ['0x01b0a4cdd5f55589f5c5b4d46c76704bb6ce95c0a8c09f77f197a57808dded28'],
yParity: '0x0',
}
const txMeta = {
hash: '0xe5e02be0667b6d31895d1b5a8b916a6761cbc9865225c6144a3e2c50936d173e',
Expand Down Expand Up @@ -632,7 +631,6 @@ describe('Network wrapper deserialization test', () => {
accessList: [],
maxFeePerBlobGas: '0x5f5e100',
blobVersionedHashes: ['0x0172ff1d4f354eebdb3cd0cb64e41ac584359094373fd5f979bcccbd6072d936'],
yParity: '0x0',
}
const txMeta = {
sender: '0x652a2b04934d96c26c4710853021779fb9f525d2',
Expand Down
20 changes: 10 additions & 10 deletions packages/tx/test/eip7702.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('[EOACodeEIP7702Transaction]', () => {
chainId: '0x',
address: `0x${'20'.repeat(21)}`,
nonce: [],
yParity: '0x1',
v: '0x1',
r: ones32,
s: ones32,
},
Expand All @@ -62,7 +62,7 @@ describe('[EOACodeEIP7702Transaction]', () => {
chainId: '0x',
address: `0x${'20'.repeat(20)}`,
nonce: ['0x1', '0x2'],
yParity: '0x1',
v: '0x1',
r: ones32,
s: ones32,
},
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -116,15 +116,15 @@ describe('[EOACodeEIP7702Transaction]', () => {
chainId: '0x',
address: `0x${'20'.repeat(20)}`,
nonce: ['0x1'],
yParity: undefined as never,
v: undefined as never,
r: ones32,
s: ones32,
},
],
},
{ common }
)
}, 'yParity is not defined')
}, 'v is not defined')

assert.throws(() => {
EOACodeEIP7702Transaction.fromTxData(
Expand All @@ -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,
},
Expand All @@ -152,7 +152,7 @@ describe('[EOACodeEIP7702Transaction]', () => {
chainId: '0x',
address: undefined as never,
nonce: ['0x1'],
yParity: '0x1',
v: '0x1',
r: ones32,
s: ones32,
},
Expand All @@ -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,
},
Expand All @@ -188,7 +188,7 @@ describe('[EOACodeEIP7702Transaction]', () => {
chainId: '0x',
address: `0x${'20'.repeat(20)}`,
nonce: ['0x1'],
yParity: '0x1',
v: '0x1',
r: ones32,
s: ones32,
},
Expand Down
1 change: 0 additions & 1 deletion packages/tx/test/typedTxsAndEIP2930.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,6 @@ describe('[AccessListEIP2930Transaction] -> Class Specific Tests', () => {
v: '0x0',
r: '0x294ac94077b35057971e6b4b06dfdf55a6fbed819133a6c1d31e187f1bca938d',
s: '0xbe950468ba1c25a5cb50e9f6d8aa13c8cd21f24ba909402775b262ac76d374d',
yParity: '0x0',
}

assert.deepEqual(signed.toJSON(), expectedJSON)
Expand Down
3 changes: 2 additions & 1 deletion packages/vm/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 5dd80f3

Please sign in to comment.