From c6be380c829e09a94739b20ddc442d3df599f854 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Tue, 25 Oct 2022 12:42:35 +0800 Subject: [PATCH] fix: r & s should be quantity in transaction when `eth_getTransactionByHash` --- packages/api-server/src/base/types/api.ts | 4 ++-- packages/api-server/src/convert-tx.ts | 4 ++-- packages/api-server/src/db/types.ts | 4 ++-- packages/api-server/src/filter-web3-tx.ts | 8 ++++++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/api-server/src/base/types/api.ts b/packages/api-server/src/base/types/api.ts index 51eee111..46aaf72d 100644 --- a/packages/api-server/src/base/types/api.ts +++ b/packages/api-server/src/base/types/api.ts @@ -14,8 +14,8 @@ export interface EthTransaction { nonce: HexNumber; value: HexNumber; v: HexNumber; - r: HexString; - s: HexString; + r: HexNumber; + s: HexNumber; } export interface EthBlock { diff --git a/packages/api-server/src/convert-tx.ts b/packages/api-server/src/convert-tx.ts index 2a9ef2c5..17627d9f 100644 --- a/packages/api-server/src/convert-tx.ts +++ b/packages/api-server/src/convert-tx.ts @@ -210,8 +210,8 @@ export function polyjuiceRawTransactionToApiTransaction( nonce: tx.nonce === "0x" ? "0x0" : tx.nonce, value: tx.value === "0x" ? "0x0" : tx.value, v: +tx.v % 2 === 0 ? "0x1" : "0x0", - r: tx.r, - s: tx.s, + r: "0x" + BigInt(tx.r).toString(16), + s: "0x" + BigInt(tx.s).toString(16), }; } diff --git a/packages/api-server/src/db/types.ts b/packages/api-server/src/db/types.ts index 706b0298..cad924ad 100644 --- a/packages/api-server/src/db/types.ts +++ b/packages/api-server/src/db/types.ts @@ -165,8 +165,8 @@ export function toApiTransaction(t: Transaction): EthTransaction { nonce: new Uint64(t.nonce || 0n).toHex(), // TODO: check default value value: new Uint256(t.value).toHex(), v: new Uint64(t.v).toHex(), - r: t.r, - s: t.s, + r: "0x" + BigInt(t.r).toString(16), + s: "0x" + BigInt(t.s).toString(16), }; } diff --git a/packages/api-server/src/filter-web3-tx.ts b/packages/api-server/src/filter-web3-tx.ts index 0e8d2029..9e0c9ddc 100644 --- a/packages/api-server/src/filter-web3-tx.ts +++ b/packages/api-server/src/filter-web3-tx.ts @@ -77,9 +77,13 @@ export async function filterWeb3Transaction( const signature: HexString = l2Tx.signature; // 0..32 bytes - const r = "0x" + signature.slice(2, 66); + let r = "0x" + signature.slice(2, 66); + // Remove r left zeros + r = "0x" + BigInt(r).toString(16); // 32..64 bytes - const s = "0x" + signature.slice(66, 130); + let s = "0x" + signature.slice(66, 130); + // Remove s left zeros + s = "0x" + BigInt(s).toString(16); // signature[65] byte const v = Uint32.fromHex("0x" + signature.slice(130, 132));