Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

fix: r & s should be quantity in transaction when `eth_getTransaction… #560

Merged
merged 1 commit into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/api-server/src/base/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export interface EthTransaction {
nonce: HexNumber;
value: HexNumber;
v: HexNumber;
r: HexString;
s: HexString;
r: HexNumber;
s: HexNumber;
}

export interface EthBlock {
Expand Down
4 changes: 2 additions & 2 deletions packages/api-server/src/convert-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/api-server/src/db/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}

Expand Down
8 changes: 6 additions & 2 deletions packages/api-server/src/filter-web3-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down