diff --git a/packages/tx/src/baseTransaction.ts b/packages/tx/src/baseTransaction.ts index 224f57e0c4..9e71e03875 100644 --- a/packages/tx/src/baseTransaction.ts +++ b/packages/tx/src/baseTransaction.ts @@ -28,11 +28,12 @@ import type { Hardfork } from '@ethereumjs/common' import type { BigIntLike } from '@ethereumjs/util' interface TransactionCache { - hash: Uint8Array | undefined + hash?: Uint8Array dataFee?: { value: bigint hardfork: string | Hardfork } + senderPubKey?: Uint8Array } /** @@ -62,6 +63,7 @@ export abstract class BaseTransaction protected cache: TransactionCache = { hash: undefined, dataFee: undefined, + senderPubKey: undefined, } protected readonly txOptions: TxOptions diff --git a/packages/tx/src/eip1559Transaction.ts b/packages/tx/src/eip1559Transaction.ts index a4436a1c96..4d7f7a2094 100644 --- a/packages/tx/src/eip1559Transaction.ts +++ b/packages/tx/src/eip1559Transaction.ts @@ -336,6 +336,10 @@ export class FeeMarketEIP1559Transaction extends BaseTransaction { * Returns the public key of the sender */ getSenderPublicKey(): Uint8Array { + if (this.cache.senderPubKey !== undefined) { + return this.cache.senderPubKey + } + const msgHash = this.getMessageToVerifySignature() const { v, r, s } = this @@ -293,13 +297,17 @@ export class LegacyTransaction extends BaseTransaction { this._validateHighS() try { - return ecrecover( + const sender = ecrecover( msgHash, v!, bigIntToUnpaddedBytes(r!), bigIntToUnpaddedBytes(s!), this.supports(Capability.EIP155ReplayProtection) ? this.common.chainId() : undefined ) + if (Object.isFrozen(this)) { + this.cache.senderPubKey = sender + } + return sender } catch (e: any) { const msg = this._errorMsg('Invalid Signature') throw new Error(msg)