From 595c04ef266a03dbcb0542e236e206428bdc076b Mon Sep 17 00:00:00 2001 From: David Murdoch <187813+davidmurdoch@users.noreply.github.com> Date: Tue, 22 Aug 2023 13:56:30 -0400 Subject: [PATCH] add yParity field --- packages/ethereum/ethereum/tests/database.test.ts | 3 ++- .../transaction/src/eip1559-fee-market-transaction.ts | 10 +++++++--- .../transaction/src/eip2930-access-list-transaction.ts | 9 ++++++--- packages/ethereum/transaction/src/transaction-types.ts | 2 ++ packages/ethereum/transaction/tests/index.test.ts | 1 - 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/ethereum/ethereum/tests/database.test.ts b/packages/ethereum/ethereum/tests/database.test.ts index d2646bc234..ef20a24765 100644 --- a/packages/ethereum/ethereum/tests/database.test.ts +++ b/packages/ethereum/ethereum/tests/database.test.ts @@ -227,7 +227,8 @@ describe("database", () => { accessList: [], v: "0x0", r: "0x48507a6e4e1e7bdbcdb0a5021195d13d7c2a1b89f06555049bca5cc246b6f7d4", - s: "0x487a3f23364c97c469f8ee948a9de2bdc80a4502046625793f664bb7be4c0cd9" + s: "0x487a3f23364c97c469f8ee948a9de2bdc80a4502046625793f664bb7be4c0cd9", + yParity: "0x0" } ], uncles: [] diff --git a/packages/ethereum/transaction/src/eip1559-fee-market-transaction.ts b/packages/ethereum/transaction/src/eip1559-fee-market-transaction.ts index 3aa6e1c04d..f471b33e3f 100644 --- a/packages/ethereum/transaction/src/eip1559-fee-market-transaction.ts +++ b/packages/ethereum/transaction/src/eip1559-fee-market-transaction.ts @@ -34,6 +34,7 @@ export class EIP1559FeeMarketTransaction extends RuntimeTransaction { public accessListJSON: AccessList; public accessListDataFee: bigint; public type: Quantity = Quantity.from("0x2"); + public yParity: Quantity = Quantity.from("0x0"); public constructor( data: EIP1559FeeMarketRawTransaction | EIP1559FeeMarketRpcTransaction, @@ -54,7 +55,7 @@ export class EIP1559FeeMarketTransaction extends RuntimeTransaction { this.accessList = accessListData.accessList; this.accessListJSON = accessListData.AccessListJSON; this.accessListDataFee = accessListData.dataFeeEIP2930; - this.v = Quantity.from(data[9]); + this.yParity = this.v = Quantity.from(data[9]); this.r = Quantity.from(data[10]); this.s = Quantity.from(data[11]); this.raw = data; @@ -93,6 +94,8 @@ export class EIP1559FeeMarketTransaction extends RuntimeTransaction { this.accessListJSON = accessListData.AccessListJSON; this.accessListDataFee = accessListData.dataFeeEIP2930; this.validateAndSetSignature(data); + + this.yParity = this.v; } } @@ -120,7 +123,8 @@ export class EIP1559FeeMarketTransaction extends RuntimeTransaction { accessList: this.accessListJSON, v: this.v, r: this.r, - s: this.s + s: this.s, + yParity: this.yParity }; } @@ -193,7 +197,7 @@ export class EIP1559FeeMarketTransaction extends RuntimeTransaction { const msgHash = keccak(digestWithPrefix(2, [data.output], dataLength)); const sig = ecsign(msgHash, privateKey); - this.v = Quantity.from(sig.v); + this.yParity = this.v = Quantity.from(sig.v); this.r = Quantity.from(sig.r); this.s = Quantity.from(sig.s); diff --git a/packages/ethereum/transaction/src/eip2930-access-list-transaction.ts b/packages/ethereum/transaction/src/eip2930-access-list-transaction.ts index 52bb0b6f09..677fa983e2 100644 --- a/packages/ethereum/transaction/src/eip2930-access-list-transaction.ts +++ b/packages/ethereum/transaction/src/eip2930-access-list-transaction.ts @@ -31,6 +31,7 @@ export class EIP2930AccessListTransaction extends RuntimeTransaction { public accessListDataFee: bigint; public gasPrice: Quantity; public type: Quantity = Quantity.from("0x1"); + public yParity: Quantity = Quantity.from("0x0"); public constructor( data: EIP2930AccessListRawTransaction | EIP2930AccessListRpcTransaction, @@ -50,7 +51,7 @@ export class EIP2930AccessListTransaction extends RuntimeTransaction { this.accessList = accessListData.accessList; this.accessListJSON = accessListData.AccessListJSON; this.accessListDataFee = accessListData.dataFeeEIP2930; - this.v = Quantity.from(data[8]); + this.yParity = this.v = Quantity.from(data[8]); this.r = Quantity.from(data[9]); this.s = Quantity.from(data[10]); this.raw = data; @@ -94,6 +95,7 @@ export class EIP2930AccessListTransaction extends RuntimeTransaction { this.accessListJSON = accessListData.AccessListJSON; this.accessListDataFee = accessListData.dataFeeEIP2930; this.validateAndSetSignature(data); + this.yParity = this.v; } } @@ -119,7 +121,8 @@ export class EIP2930AccessListTransaction extends RuntimeTransaction { accessList: this.accessListJSON, v: this.v, r: this.r, - s: this.s + s: this.s, + yParity: this.v }; } public static fromTxData( @@ -179,7 +182,7 @@ export class EIP2930AccessListTransaction extends RuntimeTransaction { const msgHash = keccak(digestWithPrefix(1, [data.output], dataLength)); const sig = ecsign(msgHash, privateKey); - this.v = Quantity.from(sig.v); + this.yParity = this.v = Quantity.from(sig.v); this.r = Quantity.from(sig.r); this.s = Quantity.from(sig.s); diff --git a/packages/ethereum/transaction/src/transaction-types.ts b/packages/ethereum/transaction/src/transaction-types.ts index 95afc55a9a..5a76645792 100644 --- a/packages/ethereum/transaction/src/transaction-types.ts +++ b/packages/ethereum/transaction/src/transaction-types.ts @@ -52,6 +52,7 @@ export type EIP2930AccessListTransactionJSON = { v: Quantity; r: Quantity; s: Quantity; + yParity: Quantity; }; export type EIP1559FeeMarketTransactionJSON = { @@ -74,4 +75,5 @@ export type EIP1559FeeMarketTransactionJSON = { v: Quantity; r: Quantity; s: Quantity; + yParity: Quantity; }; diff --git a/packages/ethereum/transaction/tests/index.test.ts b/packages/ethereum/transaction/tests/index.test.ts index 34e8c59ca5..f70a640fdb 100644 --- a/packages/ethereum/transaction/tests/index.test.ts +++ b/packages/ethereum/transaction/tests/index.test.ts @@ -9,7 +9,6 @@ import { LegacyRawTransaction, LegacyTransaction, TransactionFactory, - TransactionType, TypedDatabaseTransaction, Transaction, encodeWithPrefix,