From ce3a3dcfebe8d58c55bbd33611ca4d6389d6ecaa Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Mon, 1 Nov 2021 09:42:39 +0700 Subject: [PATCH] pre-alloc uin256 for chainID derive (#141) --- txpool/types.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/txpool/types.go b/txpool/types.go index f12b2c896..7c54f5ec7 100644 --- a/txpool/types.go +++ b/txpool/types.go @@ -44,7 +44,8 @@ type TxParseContext struct { keccak2 hash.Hash chainId, r, s, v uint256.Int // Signature values chainIDMul uint256.Int - buf [65]byte // buffer needs to be enough for hashes (32 bytes) and for public key (65 bytes) + deriveChainID uint256.Int // pre-allocated variable to calculate Sub(&ctx.v, &ctx.chainIDMul) + buf [65]byte // buffer needs to be enough for hashes (32 bytes) and for public key (65 bytes) sighash [32]byte sig [65]byte withSender bool @@ -322,8 +323,8 @@ func (ctx *TxParseContext) ParseTransaction(payload []byte, pos int, slot *TxSlo sigHashLen += 2 // For two extra zeros //vByte = byte(1 - (ctx.v.Uint64() & 1)) - v := uint256.NewInt(0).Sub(&ctx.v, &ctx.chainIDMul) - vByte = v.Sub(v, u256.N8).Bytes()[0] - 27 + ctx.deriveChainID.Sub(&ctx.v, &ctx.chainIDMul) + vByte = ctx.deriveChainID.Sub(&ctx.deriveChainID, u256.N8).Bytes()[0] - 27 } } else { var v uint64