Skip to content

Conversation

@Sahil-4555
Copy link
Contributor

Benchmark Code:

package types

import (
	"testing"

	"github.com/erigontech/erigon/common"
	"github.com/erigontech/erigon/common/u256"
	"github.com/holiman/uint256"
)

// BenchmarkSigHash_DynamicFeeTx benchmarks the sigHash method for DynamicFeeTx
// with all fields populated.
func BenchmarkSigHash_DynamicFeeTx(b *testing.B) {
	to := common.HexToAddress("0x000000000000000000000000000000000000dead")

	tx := &DynamicFeeTransaction{
		CommonTx: CommonTx{
			Nonce:    3,
			To:       &to,
			Value:    uint256.NewInt(10),
			GasLimit: 25000,
			Data:     common.FromHex("5544"),
			V:        *uint256.NewInt(27),
			R:        *uint256.NewInt(123456789),
			S:        *uint256.NewInt(987654321),
		},
		ChainID: uint256.NewInt(1),
		TipCap:  uint256.NewInt(1_000_000_000), // 1 gwei
		FeeCap:  uint256.NewInt(2_000_000_000), // 2 gwei
		AccessList: AccessList{
			AccessTuple{
				Address: common.HexToAddress("0x0000000000000000000000000000000000000001"),
				StorageKeys: []common.Hash{
					common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000001"),
					common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000002"),
				},
			},
			AccessTuple{
				Address: common.HexToAddress("0x0000000000000000000000000000000000000002"),
				StorageKeys: []common.Hash{
					common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000003"),
				},
			},
		},
	}

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_ = tx.SigningHash(tx.ChainID.ToBig())
	}
}

// BenchmarkSigHash_AccessListTx benchmarks the sigHash method for AccessListTx
// with all fields populated.
func BenchmarkSigHash_AccessListTx(b *testing.B) {
	to := common.HexToAddress("0x000000000000000000000000000000000000dead")

	tx := &AccessListTx{
		LegacyTx: LegacyTx{
			CommonTx: CommonTx{
				Nonce:    3,
				To:       &to,
				Value:    uint256.NewInt(10),
				GasLimit: 25000,
				Data:     common.FromHex("5544"),
				V:        *uint256.NewInt(27),
				R:        *uint256.NewInt(123456789),
				S:        *uint256.NewInt(987654321),
			},
			GasPrice: uint256.NewInt(2_000_000_000), // 2 gwei
		},
		ChainID: uint256.NewInt(1),
		AccessList: AccessList{
			AccessTuple{
				Address: common.HexToAddress("0x0000000000000000000000000000000000000001"),
				StorageKeys: []common.Hash{
					common.HexToHash("0x01"),
					common.HexToHash("0x02"),
				},
			},
			AccessTuple{
				Address: common.HexToAddress("0x0000000000000000000000000000000000000002"),
				StorageKeys: []common.Hash{
					common.HexToHash("0x03"),
				},
			},
		},
	}

	chainID := tx.ChainID.ToBig()

	for b.Loop() {
		_ = tx.SigningHash(chainID)
	}
}

// BenchmarkSigHash_LegacyTx benchmarks the sigHash method for LegacyTx
// with all fields populated.
func BenchmarkSigHash_LegacyTx(b *testing.B) {
	to := common.HexToAddress("0x000000000000000000000000000000000000dead")

	tx := &LegacyTx{
		CommonTx: CommonTx{
			Nonce:    42,
			To:       &to,
			Value:    uint256.NewInt(1_000_000_000_000_000_000), // 1 ether
			GasLimit: 21000,
			Data:     []byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0},
			V:        *uint256.NewInt(27),
			R:        *uint256.NewInt(123456789),
			S:        *uint256.NewInt(987654321),
		},
		GasPrice: uint256.NewInt(2_000_000_000), // 2 gwei
	}

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_ = tx.SigningHash(u256.Num1.ToBig())
	}
}

// BenchmarkSigHash_BlobTx benchmarks the sigHash method for BlobTx
// with all fields populated.
func BenchmarkSigHash_BlobTx(b *testing.B) {
	to := common.HexToAddress("0x000000000000000000000000000000000000dead")

	tx := &BlobTx{
		DynamicFeeTransaction: DynamicFeeTransaction{
			CommonTx: CommonTx{
				Nonce:    42,
				To:       &to,
				Value:    uint256.NewInt(1_000_000_000_000_000_000), // 1 ether
				GasLimit: 21000,
				Data:     []byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0},
				V:        *uint256.NewInt(27),
				R:        *uint256.NewInt(123456789),
				S:        *uint256.NewInt(987654321),
			},
			ChainID: &u256.Num1,
			TipCap:  uint256.NewInt(1_000_000_000), // 1 gwei
			FeeCap:  uint256.NewInt(2_000_000_000), // 2 gwei
			AccessList: AccessList{
				{
					Address: common.HexToAddress("0x0000000000000000000000000000000000000001"),
					StorageKeys: []common.Hash{
						common.HexToHash("0x01"),
						common.HexToHash("0x02"),
					},
				},
				{
					Address: common.HexToAddress("0x0000000000000000000000000000000000000002"),
					StorageKeys: []common.Hash{
						common.HexToHash("0x03"),
					},
				},
			},
		},
		MaxFeePerBlobGas: uint256.NewInt(100_000_000),
		BlobVersionedHashes: []common.Hash{
			common.HexToHash("0x01"),
			common.HexToHash("0x02"),
		},
	}

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_ = tx.SigningHash(tx.ChainID.ToBig())
	}
}

Result:

goos: linux
goarch: amd64
pkg: github.com/erigontech/erigon/execution/types
cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
                       │ old_bench.txt │            new_bench.txt            │
                       │    sec/op     │   sec/op     vs base                │
SigHash_DynamicFeeTx-8     2.274µ ± 2%   1.849µ ± 3%  -18.69% (p=0.000 n=10)
SigHash_AccessListTx-8     2.125µ ± 1%   1.755µ ± 3%  -17.39% (p=0.000 n=10)
SigHash_LegacyTx-8        1379.5n ± 5%   913.4n ± 2%  -33.79% (p=0.000 n=10)
SigHash_BlobTx-8           3.079µ ± 2%   2.599µ ± 5%  -15.58% (p=0.000 n=10)
geomean                    2.128µ        1.666µ       -21.72%

                       │ old_bench.txt │           new_bench.txt            │
                       │     B/op      │    B/op     vs base                │
SigHash_DynamicFeeTx-8      328.0 ± 0%   209.0 ± 0%  -36.28% (p=0.000 n=10)
SigHash_AccessListTx-8      248.0 ± 0%   129.0 ± 0%  -47.98% (p=0.000 n=10)
SigHash_LegacyTx-8          296.0 ± 0%   192.0 ± 0%  -35.14% (p=0.000 n=10)
SigHash_BlobTx-8            384.0 ± 0%   241.0 ± 0%  -37.24% (p=0.000 n=10)
geomean                     310.1        187.9       -39.39%

                       │ old_bench.txt │           new_bench.txt            │
                       │   allocs/op   │ allocs/op   vs base                │
SigHash_DynamicFeeTx-8      9.000 ± 0%   5.000 ± 0%  -44.44% (p=0.000 n=10)
SigHash_AccessListTx-8      7.000 ± 0%   3.000 ± 0%  -57.14% (p=0.000 n=10)
SigHash_LegacyTx-8          7.000 ± 0%   4.000 ± 0%  -42.86% (p=0.000 n=10)
SigHash_BlobTx-8           10.000 ± 0%   5.000 ± 0%  -50.00% (p=0.000 n=10)
geomean                     8.149        4.162       -48.93%

@AskAlexSharov AskAlexSharov enabled auto-merge (squash) January 9, 2026 09:57
@Sahil-4555
Copy link
Contributor Author

@yperbasis @AskAlexSharov; any chance of this getting added? :)

@AskAlexSharov AskAlexSharov merged commit f02eb4f into erigontech:main Jan 13, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants