Skip to content

core/types: reduce allocs in transaction signing#31258

Merged
rjl493456442 merged 6 commits into
ethereum:masterfrom
MariusVanDerWijden:reduce-allocs-signer
Mar 19, 2025
Merged

core/types: reduce allocs in transaction signing#31258
rjl493456442 merged 6 commits into
ethereum:masterfrom
MariusVanDerWijden:reduce-allocs-signer

Conversation

@MariusVanDerWijden
Copy link
Copy Markdown
Member

@MariusVanDerWijden MariusVanDerWijden commented Feb 25, 2025

This PR roughly halves the number of allocations needed to compute the sigHash for a transaction.
This sigHash is used whenever we recover a signature of a transaction, so quite often. During a recent benchmark full syncing on Holesky, roughly 2.8% of all allocations were happening here because the fields from the transaction would be copied multiple times.

66168733  153175654 (flat, cum)  2.80% of Total
         .          .    368:func (s londonSigner) Hash(tx *Transaction) common.Hash {
         .          .    369:	if tx.Type() != DynamicFeeTxType {
         .          .    370:		return s.eip2930Signer.Hash(tx)
         .          .    371:	}
         .   19169966    372:	return prefixedRlpHash(
         .          .    373:		tx.Type(),
  26442187   26442187    374:		[]interface{}{
         .          .    375:			s.chainId,
   6848616    6848616    376:			tx.Nonce(),
         .   19694077    377:			tx.GasTipCap(),
         .   18956774    378:			tx.GasFeeCap(),
   6357089    6357089    379:			tx.Gas(),
         .   12321050    380:			tx.To(),
         .   16865054    381:			tx.Value(),
  13435187   13435187    382:			tx.Data(),
  13085654   13085654    383:			tx.AccessList(),
         .          .    384:		})
         .          .    385:}

This PR reduces the allocations and speeds up the computation of the sigHash by ~22%, which is quite significantly given that this operation involves a call to Keccak

// BenchmarkHash-8   	  440082	      2639 ns/op	     384 B/op	      13 allocs/op
// BenchmarkHash-8   	  493566	      2033 ns/op	     240 B/op	       6 allocs/op
Hash-8   2.691µ ± 8%   2.097µ ± 9%  -22.07% (p=0.000 n=10)

It also kinda cleans up stuff in my opinion, since the transaction should itself know best how to compute the sighash

Screenshot_2025-02-25_13-52-41

Comment thread core/types/tx_legacy.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually Post-EIP155

rjl493456442
rjl493456442 previously approved these changes Feb 26, 2025
@rjl493456442
Copy link
Copy Markdown
Member

Let's deploy it on benchmarks before merging it.

@rjl493456442 rjl493456442 force-pushed the reduce-allocs-signer branch from bf896e8 to d3f230f Compare March 18, 2025 13:56
@rjl493456442 rjl493456442 changed the title Reduce allocs signer core/types: reduce allocs in transaction signing Mar 19, 2025
@rjl493456442 rjl493456442 added this to the 1.15.6 milestone Mar 19, 2025
@rjl493456442 rjl493456442 merged commit b47e4d5 into ethereum:master Mar 19, 2025
sivaratrisrinivas pushed a commit to sivaratrisrinivas/go-ethereum that referenced this pull request Apr 21, 2025
This PR roughly halves the number of allocations needed to compute the
sigHash for a transaction.

This sigHash is used whenever we recover a signature of a transaction,
so quite often. During a recent benchmark full syncing on Holesky,
roughly 2.8% of all allocations were happening here because the fields
from the transaction would be copied multiple times.

```
66168733  153175654 (flat, cum)  2.80% of Total
         .          .    368:func (s londonSigner) Hash(tx *Transaction) common.Hash {
         .          .    369:	if tx.Type() != DynamicFeeTxType {
         .          .    370:		return s.eip2930Signer.Hash(tx)
         .          .    371:	}
         .   19169966    372:	return prefixedRlpHash(
         .          .    373:		tx.Type(),
  26442187   26442187    374:		[]interface{}{
         .          .    375:			s.chainId,
   6848616    6848616    376:			tx.Nonce(),
         .   19694077    377:			tx.GasTipCap(),
         .   18956774    378:			tx.GasFeeCap(),
   6357089    6357089    379:			tx.Gas(),
         .   12321050    380:			tx.To(),
         .   16865054    381:			tx.Value(),
  13435187   13435187    382:			tx.Data(),
  13085654   13085654    383:			tx.AccessList(),
         .          .    384:		})
         .          .    385:}
```

This PR reduces the allocations and speeds up the computation of the
sigHash by ~22%, which is quite significantly given that this operation
involves a call to Keccak
```
// BenchmarkHash-8   	  440082	      2639 ns/op	     384 B/op	      13 allocs/op
// BenchmarkHash-8   	  493566	      2033 ns/op	     240 B/op	       6 allocs/op
```

```
Hash-8   2.691µ ± 8%   2.097µ ± 9%  -22.07% (p=0.000 n=10)
```

It also kinda cleans up stuff in my opinion, since the transaction
should itself know best how to compute the sighash




![Screenshot_2025-02-25_13-52-41](https://github.com/user-attachments/assets/e2b268aa-e137-417d-926b-f3619daef748)

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
sduchesneau pushed a commit to streamingfast/go-ethereum that referenced this pull request May 22, 2025
This PR roughly halves the number of allocations needed to compute the
sigHash for a transaction.

This sigHash is used whenever we recover a signature of a transaction,
so quite often. During a recent benchmark full syncing on Holesky,
roughly 2.8% of all allocations were happening here because the fields
from the transaction would be copied multiple times.

```
66168733  153175654 (flat, cum)  2.80% of Total
         .          .    368:func (s londonSigner) Hash(tx *Transaction) common.Hash {
         .          .    369:	if tx.Type() != DynamicFeeTxType {
         .          .    370:		return s.eip2930Signer.Hash(tx)
         .          .    371:	}
         .   19169966    372:	return prefixedRlpHash(
         .          .    373:		tx.Type(),
  26442187   26442187    374:		[]interface{}{
         .          .    375:			s.chainId,
   6848616    6848616    376:			tx.Nonce(),
         .   19694077    377:			tx.GasTipCap(),
         .   18956774    378:			tx.GasFeeCap(),
   6357089    6357089    379:			tx.Gas(),
         .   12321050    380:			tx.To(),
         .   16865054    381:			tx.Value(),
  13435187   13435187    382:			tx.Data(),
  13085654   13085654    383:			tx.AccessList(),
         .          .    384:		})
         .          .    385:}
```

This PR reduces the allocations and speeds up the computation of the
sigHash by ~22%, which is quite significantly given that this operation
involves a call to Keccak
```
// BenchmarkHash-8   	  440082	      2639 ns/op	     384 B/op	      13 allocs/op
// BenchmarkHash-8   	  493566	      2033 ns/op	     240 B/op	       6 allocs/op
```

```
Hash-8   2.691µ ± 8%   2.097µ ± 9%  -22.07% (p=0.000 n=10)
```

It also kinda cleans up stuff in my opinion, since the transaction
should itself know best how to compute the sighash




![Screenshot_2025-02-25_13-52-41](https://github.com/user-attachments/assets/e2b268aa-e137-417d-926b-f3619daef748)

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
jakub-freebit pushed a commit to fblch/go-ethereum that referenced this pull request Jul 3, 2025
This PR roughly halves the number of allocations needed to compute the
sigHash for a transaction.

This sigHash is used whenever we recover a signature of a transaction,
so quite often. During a recent benchmark full syncing on Holesky,
roughly 2.8% of all allocations were happening here because the fields
from the transaction would be copied multiple times.

```
66168733  153175654 (flat, cum)  2.80% of Total
         .          .    368:func (s londonSigner) Hash(tx *Transaction) common.Hash {
         .          .    369:	if tx.Type() != DynamicFeeTxType {
         .          .    370:		return s.eip2930Signer.Hash(tx)
         .          .    371:	}
         .   19169966    372:	return prefixedRlpHash(
         .          .    373:		tx.Type(),
  26442187   26442187    374:		[]interface{}{
         .          .    375:			s.chainId,
   6848616    6848616    376:			tx.Nonce(),
         .   19694077    377:			tx.GasTipCap(),
         .   18956774    378:			tx.GasFeeCap(),
   6357089    6357089    379:			tx.Gas(),
         .   12321050    380:			tx.To(),
         .   16865054    381:			tx.Value(),
  13435187   13435187    382:			tx.Data(),
  13085654   13085654    383:			tx.AccessList(),
         .          .    384:		})
         .          .    385:}
```

This PR reduces the allocations and speeds up the computation of the
sigHash by ~22%, which is quite significantly given that this operation
involves a call to Keccak
```
// BenchmarkHash-8   	  440082	      2639 ns/op	     384 B/op	      13 allocs/op
// BenchmarkHash-8   	  493566	      2033 ns/op	     240 B/op	       6 allocs/op
```

```
Hash-8   2.691µ ± 8%   2.097µ ± 9%  -22.07% (p=0.000 n=10)
```

It also kinda cleans up stuff in my opinion, since the transaction
should itself know best how to compute the sighash




![Screenshot_2025-02-25_13-52-41](https://github.com/user-attachments/assets/e2b268aa-e137-417d-926b-f3619daef748)

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
howjmay pushed a commit to iotaledger/go-ethereum that referenced this pull request Aug 27, 2025
This PR roughly halves the number of allocations needed to compute the
sigHash for a transaction.

This sigHash is used whenever we recover a signature of a transaction,
so quite often. During a recent benchmark full syncing on Holesky,
roughly 2.8% of all allocations were happening here because the fields
from the transaction would be copied multiple times.

```
66168733  153175654 (flat, cum)  2.80% of Total
         .          .    368:func (s londonSigner) Hash(tx *Transaction) common.Hash {
         .          .    369:	if tx.Type() != DynamicFeeTxType {
         .          .    370:		return s.eip2930Signer.Hash(tx)
         .          .    371:	}
         .   19169966    372:	return prefixedRlpHash(
         .          .    373:		tx.Type(),
  26442187   26442187    374:		[]interface{}{
         .          .    375:			s.chainId,
   6848616    6848616    376:			tx.Nonce(),
         .   19694077    377:			tx.GasTipCap(),
         .   18956774    378:			tx.GasFeeCap(),
   6357089    6357089    379:			tx.Gas(),
         .   12321050    380:			tx.To(),
         .   16865054    381:			tx.Value(),
  13435187   13435187    382:			tx.Data(),
  13085654   13085654    383:			tx.AccessList(),
         .          .    384:		})
         .          .    385:}
```

This PR reduces the allocations and speeds up the computation of the
sigHash by ~22%, which is quite significantly given that this operation
involves a call to Keccak
```
// BenchmarkHash-8   	  440082	      2639 ns/op	     384 B/op	      13 allocs/op
// BenchmarkHash-8   	  493566	      2033 ns/op	     240 B/op	       6 allocs/op
```

```
Hash-8   2.691µ ± 8%   2.097µ ± 9%  -22.07% (p=0.000 n=10)
```

It also kinda cleans up stuff in my opinion, since the transaction
should itself know best how to compute the sighash




![Screenshot_2025-02-25_13-52-41](https://github.com/user-attachments/assets/e2b268aa-e137-417d-926b-f3619daef748)

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
gballet pushed a commit to gballet/go-ethereum that referenced this pull request Sep 11, 2025
This PR roughly halves the number of allocations needed to compute the
sigHash for a transaction.

This sigHash is used whenever we recover a signature of a transaction,
so quite often. During a recent benchmark full syncing on Holesky,
roughly 2.8% of all allocations were happening here because the fields
from the transaction would be copied multiple times.

```
66168733  153175654 (flat, cum)  2.80% of Total
         .          .    368:func (s londonSigner) Hash(tx *Transaction) common.Hash {
         .          .    369:	if tx.Type() != DynamicFeeTxType {
         .          .    370:		return s.eip2930Signer.Hash(tx)
         .          .    371:	}
         .   19169966    372:	return prefixedRlpHash(
         .          .    373:		tx.Type(),
  26442187   26442187    374:		[]interface{}{
         .          .    375:			s.chainId,
   6848616    6848616    376:			tx.Nonce(),
         .   19694077    377:			tx.GasTipCap(),
         .   18956774    378:			tx.GasFeeCap(),
   6357089    6357089    379:			tx.Gas(),
         .   12321050    380:			tx.To(),
         .   16865054    381:			tx.Value(),
  13435187   13435187    382:			tx.Data(),
  13085654   13085654    383:			tx.AccessList(),
         .          .    384:		})
         .          .    385:}
```

This PR reduces the allocations and speeds up the computation of the
sigHash by ~22%, which is quite significantly given that this operation
involves a call to Keccak
```
// BenchmarkHash-8   	  440082	      2639 ns/op	     384 B/op	      13 allocs/op
// BenchmarkHash-8   	  493566	      2033 ns/op	     240 B/op	       6 allocs/op
```

```
Hash-8   2.691µ ± 8%   2.097µ ± 9%  -22.07% (p=0.000 n=10)
```

It also kinda cleans up stuff in my opinion, since the transaction
should itself know best how to compute the sighash




![Screenshot_2025-02-25_13-52-41](https://github.com/user-attachments/assets/e2b268aa-e137-417d-926b-f3619daef748)

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
eomti-wm added a commit to stable-net/go-stablenet that referenced this pull request Jan 5, 2026
Add sigHash method to TxData interface and move hash computation
into each tx type, reducing allocations during signature operations.

Based on ethereum/go-ethereum#31258
eomti-wm added a commit to stable-net/go-stablenet that referenced this pull request Jan 14, 2026
* chore: update Go version to 1.21

* feat: implement EIP-7702 set code transaction type

Add support for EIP-7702 (SetCodeTx) which allows EOAs to temporarily
delegate their code execution to another account.

Changes include:
- Add SetCodeTx (type 0x04) transaction type and Authorization struct
- Add anzeonSigner for EIP-7702 transaction signing
- Implement delegation designator resolution in EVM
- Add EIP-7702 specific gas calculation for CALL variants
- Update EXTCODE* opcodes to handle delegation designators
- Add prestate tracer support for authorization list
- Update t8n tool and tests for SetCodeTx

Based on ethereum/go-ethereum#30078

* fix: complete EIP-7702 authorization marshaling and eth_call support

Based on ethereum/go-ethereum#30926

* refactor: improve EIP-7702 API naming

- Rename Authorization to SetCodeAuthorization
- Rename SignAuth to SignSetCode with key-first parameter order

Based on ethereum/go-ethereum#30933

* fix: rename SetCodeAuthorization 'v' to 'yParity'

The API spec requires the name yParity.

Based on:
- ethereum/go-ethereum@73a4ecf
- ethereum/go-ethereum#30936

* refactor: rename AuthList to SetCodeAuthorizations

Use SetCode prefix consistently in internal APIs for the authorization
list, as a follow-up to SetCodeAuthorization type renaming.

Based on ethereum/go-ethereum#30935

* refactor: change SetCodeTx.ChainID to uint256

Change ChainID field type from uint64 to uint256.Int in SetCodeTx and
SetCodeAuthorization for consistency with other chain ID handling.

Also removes unused json/gencodec tags from signature value fields
in DynamicFeeTx, BlobTx, SetCodeTx, and FeeDelegateDynamicFeeTx.

Based on ethereum/go-ethereum#30982

* fix: correct chainId check for anzeonSigner

Use zero value check for SetCodeTx chainId validation.
This aligns with cancunSigner and londonSigner as well.

Based on ethereum/go-ethereum#31032

* fix: initialize ChainID in SetCodeTx copy method

ChainID should be properly initialized and copied in the copy() method
to prevent nil pointer issues during transaction processing.

Based on ethereum/go-ethereum#31054

* refactor: remove EXTCODE* special handling for EIP-7702

EXTCODE* opcodes no longer need special overrides for EIP-7702 delegation
designators. The delegation designator is now returned as-is.

Implements EIPs#9248.

Based on ethereum/go-ethereum#31089

* feat: add EIP-7702 SetCode transaction pool support

Add SetCode transaction handling to legacypool:
- SetCodeTxType validation with Anzeon fork check
- Empty authorization rejection
- Authority tracking and conflict prevention
- Account slot limit for delegated accounts and pending authorizations

Note: tx replacement is not supported in go-stablenet. Tests are adjusted
to expect ErrAccountLimitExceeded instead of successful replacement.

Based on ethereum/go-ethereum#31073

* test: add setCodeTx reorg test

Based on ethereum/go-ethereum#31206

* refactor: move setcode tx validation into legacyPool

Move authorization-related validations from common validation to legacyPool
since these checks are specific to SetCode transactions.

Based on ethereum/go-ethereum#31209

* fix: fix error logs flood caused by removeAuthorities

Fix removeAuthorities to only iterate tx's authorities instead of
all authorities in the pool.

Based on ethereum/go-ethereum#31249

* refactor: reduce allocs in transaction signing

Add sigHash method to TxData interface and move hash computation
into each tx type, reducing allocations during signature operations.

Based on ethereum/go-ethereum#31258

* fix: reject gapped tx from delegated account

Add checkDelegationLimit to reject transactions with gapped nonces
from delegated accounts. Only one in-flight executable transaction
is allowed for senders with delegation or pending delegation.

Based on ethereum/go-ethereum#31430

* fix: exclude 7702 authorities from eth_createAccessList result

Exclude valid EIP-7702 authorities from access list generation result.

Based on ethereum/go-ethereum#31336
(which resolves ethereum/go-ethereum#31335)

* fix: data race in checkDelegationLimit

Add delegationTxsCount method with proper lock to fix data race
when accessing auths map in checkDelegationLimit.

Based on ethereum/go-ethereum#31475

* feat: add EIP-7702 protection to blobpool

Add delegation limit checks to blobpool:
- Limit senders with delegation/pending auth to one in-flight tx
- Check reserver for authority conflicts
- Refactor AddressReserver to Reserver struct with Hold/Release/Has

Based on ethereum/go-ethereum#31526

* fix: slot limit check and update comments

- Skip slot limit validation for tx replacements (same nonce reuses slot)
- Clarify cumulative balance validation skip reason: fee delegation compatibility

* fix: allow tx and authority regardless of admission order

Check reserver for authority conflicts to make authorization validation
independent of admission order. Authorities must not conflict with
addresses reserved by other subpools.

Based on ethereum/go-ethereum#31373

* fix: fix data race of txlookup access in test

Reset txlookup fields directly with proper locking instead of
assigning a new lookup object to avoid data race.

Based on ethereum/go-ethereum#31641

* feat: allow passing AuthorizationList to eth_call and eth_estimateGas

Add AuthorizationList field to CallMsg and toCallArg to support
SetCodeTx in eth_call and eth_estimateGas APIs.

Based on ethereum/go-ethereum#31198

* fix: fix data race of pricedList access

Use Reheap() instead of assigning a new pricedList to avoid
data race when clearing pool state.

Based on ethereum/go-ethereum#31758

* fix: resolve incorrect prestate for EIP-7702 authority accounts

Before: Authority accounts' prestate showed post-authorization code/storage
        and incorrect balance/nonce due to wrong capture timing
After:  Authority accounts' prestate correctly reflects state before
        SetCodeAuthorization is applied

- Refactor EVMLogger to pass env in CaptureTxStart instead of CaptureStart
- Capture authority accounts before delegation code (0xef0100...) is set
- Preserve original code/storage while restoring only gas from balance

* feat: prestate tracer lookup EIP-7702 delegation account

Parse and lookup the delegation account if EIP-7702 is enabled
in prestate tracer.

Implements ethereum/go-ethereum#32078
Based on ethereum/go-ethereum#32080

* refactor: expose sigHash as SigHash for SetCodeAuthorization

Rename the private sigHash() method to public SigHash() method
to enable external signing (e.g., MPC signing).

Based on ethereum/go-ethereum#32298
(which resolves ethereum/go-ethereum#32297)

* fix: resolve test failures in tracer and blobpool

- Add tracer lifecycle calls in runtime package
- Fix EIP-7702 and blobpool test configs

* Revert "chore: update Go version to 1.21"

This reverts commit 71e90d7.

* fix: support AuthorizationList in simulated backend gas estimation
eomti-wm added a commit to wemixarchive/go-wbft that referenced this pull request Mar 4, 2026
* chore: update Go version to 1.21

* feat: implement EIP-7702 set code transaction type

Add support for EIP-7702 (SetCodeTx) which allows EOAs to temporarily
delegate their code execution to another account.

Changes include:
- Add SetCodeTx (type 0x04) transaction type and Authorization struct
- Add anzeonSigner for EIP-7702 transaction signing
- Implement delegation designator resolution in EVM
- Add EIP-7702 specific gas calculation for CALL variants
- Update EXTCODE* opcodes to handle delegation designators
- Add prestate tracer support for authorization list
- Update t8n tool and tests for SetCodeTx

Based on ethereum/go-ethereum#30078

* fix: complete EIP-7702 authorization marshaling and eth_call support

Based on ethereum/go-ethereum#30926

* refactor: improve EIP-7702 API naming

- Rename Authorization to SetCodeAuthorization
- Rename SignAuth to SignSetCode with key-first parameter order

Based on ethereum/go-ethereum#30933

* fix: rename SetCodeAuthorization 'v' to 'yParity'

The API spec requires the name yParity.

Based on:
- ethereum/go-ethereum@73a4ecf
- ethereum/go-ethereum#30936

* refactor: rename AuthList to SetCodeAuthorizations

Use SetCode prefix consistently in internal APIs for the authorization
list, as a follow-up to SetCodeAuthorization type renaming.

Based on ethereum/go-ethereum#30935

* refactor: change SetCodeTx.ChainID to uint256

Change ChainID field type from uint64 to uint256.Int in SetCodeTx and
SetCodeAuthorization for consistency with other chain ID handling.

Also removes unused json/gencodec tags from signature value fields
in DynamicFeeTx, BlobTx, SetCodeTx, and FeeDelegateDynamicFeeTx.

Based on ethereum/go-ethereum#30982

* fix: correct chainId check for anzeonSigner

Use zero value check for SetCodeTx chainId validation.
This aligns with cancunSigner and londonSigner as well.

Based on ethereum/go-ethereum#31032

* fix: initialize ChainID in SetCodeTx copy method

ChainID should be properly initialized and copied in the copy() method
to prevent nil pointer issues during transaction processing.

Based on ethereum/go-ethereum#31054

* refactor: remove EXTCODE* special handling for EIP-7702

EXTCODE* opcodes no longer need special overrides for EIP-7702 delegation
designators. The delegation designator is now returned as-is.

Implements EIPs#9248.

Based on ethereum/go-ethereum#31089

* feat: add EIP-7702 SetCode transaction pool support

Add SetCode transaction handling to legacypool:
- SetCodeTxType validation with Anzeon fork check
- Empty authorization rejection
- Authority tracking and conflict prevention
- Account slot limit for delegated accounts and pending authorizations

Note: tx replacement is not supported in go-stablenet. Tests are adjusted
to expect ErrAccountLimitExceeded instead of successful replacement.

Based on ethereum/go-ethereum#31073

* test: add setCodeTx reorg test

Based on ethereum/go-ethereum#31206

* refactor: move setcode tx validation into legacyPool

Move authorization-related validations from common validation to legacyPool
since these checks are specific to SetCode transactions.

Based on ethereum/go-ethereum#31209

* fix: fix error logs flood caused by removeAuthorities

Fix removeAuthorities to only iterate tx's authorities instead of
all authorities in the pool.

Based on ethereum/go-ethereum#31249

* refactor: reduce allocs in transaction signing

Add sigHash method to TxData interface and move hash computation
into each tx type, reducing allocations during signature operations.

Based on ethereum/go-ethereum#31258

* fix: reject gapped tx from delegated account

Add checkDelegationLimit to reject transactions with gapped nonces
from delegated accounts. Only one in-flight executable transaction
is allowed for senders with delegation or pending delegation.

Based on ethereum/go-ethereum#31430

* fix: exclude 7702 authorities from eth_createAccessList result

Exclude valid EIP-7702 authorities from access list generation result.

Based on ethereum/go-ethereum#31336
(which resolves ethereum/go-ethereum#31335)

* fix: data race in checkDelegationLimit

Add delegationTxsCount method with proper lock to fix data race
when accessing auths map in checkDelegationLimit.

Based on ethereum/go-ethereum#31475

* feat: add EIP-7702 protection to blobpool

Add delegation limit checks to blobpool:
- Limit senders with delegation/pending auth to one in-flight tx
- Check reserver for authority conflicts
- Refactor AddressReserver to Reserver struct with Hold/Release/Has

Based on ethereum/go-ethereum#31526

* fix: slot limit check and update comments

- Skip slot limit validation for tx replacements (same nonce reuses slot)
- Clarify cumulative balance validation skip reason: fee delegation compatibility

* fix: allow tx and authority regardless of admission order

Check reserver for authority conflicts to make authorization validation
independent of admission order. Authorities must not conflict with
addresses reserved by other subpools.

Based on ethereum/go-ethereum#31373

* fix: fix data race of txlookup access in test

Reset txlookup fields directly with proper locking instead of
assigning a new lookup object to avoid data race.

Based on ethereum/go-ethereum#31641

* feat: allow passing AuthorizationList to eth_call and eth_estimateGas

Add AuthorizationList field to CallMsg and toCallArg to support
SetCodeTx in eth_call and eth_estimateGas APIs.

Based on ethereum/go-ethereum#31198

* fix: fix data race of pricedList access

Use Reheap() instead of assigning a new pricedList to avoid
data race when clearing pool state.

Based on ethereum/go-ethereum#31758

* fix: resolve incorrect prestate for EIP-7702 authority accounts

Before: Authority accounts' prestate showed post-authorization code/storage
        and incorrect balance/nonce due to wrong capture timing
After:  Authority accounts' prestate correctly reflects state before
        SetCodeAuthorization is applied

- Refactor EVMLogger to pass env in CaptureTxStart instead of CaptureStart
- Capture authority accounts before delegation code (0xef0100...) is set
- Preserve original code/storage while restoring only gas from balance

* feat: prestate tracer lookup EIP-7702 delegation account

Parse and lookup the delegation account if EIP-7702 is enabled
in prestate tracer.

Implements ethereum/go-ethereum#32078
Based on ethereum/go-ethereum#32080

* refactor: expose sigHash as SigHash for SetCodeAuthorization

Rename the private sigHash() method to public SigHash() method
to enable external signing (e.g., MPC signing).

Based on ethereum/go-ethereum#32298
(which resolves ethereum/go-ethereum#32297)

* fix: resolve test failures in tracer and blobpool

- Add tracer lifecycle calls in runtime package
- Fix EIP-7702 and blobpool test configs

* Revert "chore: update Go version to 1.21"

This reverts commit 71e90d700023db9fc1e0a272d7ffb9207ede738f.

* fix: support AuthorizationList in simulated backend gas estimation
eomti-wm added a commit to wemixarchive/go-wbft that referenced this pull request Mar 5, 2026
* feat: EIP-7702 Set Code Transaction support (#42)

* chore: update Go version to 1.21

* feat: implement EIP-7702 set code transaction type

Add support for EIP-7702 (SetCodeTx) which allows EOAs to temporarily
delegate their code execution to another account.

Changes include:
- Add SetCodeTx (type 0x04) transaction type and Authorization struct
- Add anzeonSigner for EIP-7702 transaction signing
- Implement delegation designator resolution in EVM
- Add EIP-7702 specific gas calculation for CALL variants
- Update EXTCODE* opcodes to handle delegation designators
- Add prestate tracer support for authorization list
- Update t8n tool and tests for SetCodeTx

Based on ethereum/go-ethereum#30078

* fix: complete EIP-7702 authorization marshaling and eth_call support

Based on ethereum/go-ethereum#30926

* refactor: improve EIP-7702 API naming

- Rename Authorization to SetCodeAuthorization
- Rename SignAuth to SignSetCode with key-first parameter order

Based on ethereum/go-ethereum#30933

* fix: rename SetCodeAuthorization 'v' to 'yParity'

The API spec requires the name yParity.

Based on:
- ethereum/go-ethereum@73a4ecf
- ethereum/go-ethereum#30936

* refactor: rename AuthList to SetCodeAuthorizations

Use SetCode prefix consistently in internal APIs for the authorization
list, as a follow-up to SetCodeAuthorization type renaming.

Based on ethereum/go-ethereum#30935

* refactor: change SetCodeTx.ChainID to uint256

Change ChainID field type from uint64 to uint256.Int in SetCodeTx and
SetCodeAuthorization for consistency with other chain ID handling.

Also removes unused json/gencodec tags from signature value fields
in DynamicFeeTx, BlobTx, SetCodeTx, and FeeDelegateDynamicFeeTx.

Based on ethereum/go-ethereum#30982

* fix: correct chainId check for anzeonSigner

Use zero value check for SetCodeTx chainId validation.
This aligns with cancunSigner and londonSigner as well.

Based on ethereum/go-ethereum#31032

* fix: initialize ChainID in SetCodeTx copy method

ChainID should be properly initialized and copied in the copy() method
to prevent nil pointer issues during transaction processing.

Based on ethereum/go-ethereum#31054

* refactor: remove EXTCODE* special handling for EIP-7702

EXTCODE* opcodes no longer need special overrides for EIP-7702 delegation
designators. The delegation designator is now returned as-is.

Implements EIPs#9248.

Based on ethereum/go-ethereum#31089

* feat: add EIP-7702 SetCode transaction pool support

Add SetCode transaction handling to legacypool:
- SetCodeTxType validation with Anzeon fork check
- Empty authorization rejection
- Authority tracking and conflict prevention
- Account slot limit for delegated accounts and pending authorizations

Note: tx replacement is not supported in go-stablenet. Tests are adjusted
to expect ErrAccountLimitExceeded instead of successful replacement.

Based on ethereum/go-ethereum#31073

* test: add setCodeTx reorg test

Based on ethereum/go-ethereum#31206

* refactor: move setcode tx validation into legacyPool

Move authorization-related validations from common validation to legacyPool
since these checks are specific to SetCode transactions.

Based on ethereum/go-ethereum#31209

* fix: fix error logs flood caused by removeAuthorities

Fix removeAuthorities to only iterate tx's authorities instead of
all authorities in the pool.

Based on ethereum/go-ethereum#31249

* refactor: reduce allocs in transaction signing

Add sigHash method to TxData interface and move hash computation
into each tx type, reducing allocations during signature operations.

Based on ethereum/go-ethereum#31258

* fix: reject gapped tx from delegated account

Add checkDelegationLimit to reject transactions with gapped nonces
from delegated accounts. Only one in-flight executable transaction
is allowed for senders with delegation or pending delegation.

Based on ethereum/go-ethereum#31430

* fix: exclude 7702 authorities from eth_createAccessList result

Exclude valid EIP-7702 authorities from access list generation result.

Based on ethereum/go-ethereum#31336
(which resolves ethereum/go-ethereum#31335)

* fix: data race in checkDelegationLimit

Add delegationTxsCount method with proper lock to fix data race
when accessing auths map in checkDelegationLimit.

Based on ethereum/go-ethereum#31475

* feat: add EIP-7702 protection to blobpool

Add delegation limit checks to blobpool:
- Limit senders with delegation/pending auth to one in-flight tx
- Check reserver for authority conflicts
- Refactor AddressReserver to Reserver struct with Hold/Release/Has

Based on ethereum/go-ethereum#31526

* fix: slot limit check and update comments

- Skip slot limit validation for tx replacements (same nonce reuses slot)
- Clarify cumulative balance validation skip reason: fee delegation compatibility

* fix: allow tx and authority regardless of admission order

Check reserver for authority conflicts to make authorization validation
independent of admission order. Authorities must not conflict with
addresses reserved by other subpools.

Based on ethereum/go-ethereum#31373

* fix: fix data race of txlookup access in test

Reset txlookup fields directly with proper locking instead of
assigning a new lookup object to avoid data race.

Based on ethereum/go-ethereum#31641

* feat: allow passing AuthorizationList to eth_call and eth_estimateGas

Add AuthorizationList field to CallMsg and toCallArg to support
SetCodeTx in eth_call and eth_estimateGas APIs.

Based on ethereum/go-ethereum#31198

* fix: fix data race of pricedList access

Use Reheap() instead of assigning a new pricedList to avoid
data race when clearing pool state.

Based on ethereum/go-ethereum#31758

* fix: resolve incorrect prestate for EIP-7702 authority accounts

Before: Authority accounts' prestate showed post-authorization code/storage
        and incorrect balance/nonce due to wrong capture timing
After:  Authority accounts' prestate correctly reflects state before
        SetCodeAuthorization is applied

- Refactor EVMLogger to pass env in CaptureTxStart instead of CaptureStart
- Capture authority accounts before delegation code (0xef0100...) is set
- Preserve original code/storage while restoring only gas from balance

* feat: prestate tracer lookup EIP-7702 delegation account

Parse and lookup the delegation account if EIP-7702 is enabled
in prestate tracer.

Implements ethereum/go-ethereum#32078
Based on ethereum/go-ethereum#32080

* refactor: expose sigHash as SigHash for SetCodeAuthorization

Rename the private sigHash() method to public SigHash() method
to enable external signing (e.g., MPC signing).

Based on ethereum/go-ethereum#32298
(which resolves ethereum/go-ethereum#32297)

* fix: resolve test failures in tracer and blobpool

- Add tracer lifecycle calls in runtime package
- Fix EIP-7702 and blobpool test configs

* Revert "chore: update Go version to 1.21"

This reverts commit 71e90d700023db9fc1e0a272d7ffb9207ede738f.

* fix: support AuthorizationList in simulated backend gas estimation

* internal/ethapi: include AuthorizationList in gas estimation (#33849)

Fixes an issue where AuthorizationList wasn't copied over when
estimating gas for a user-provided transaction.

* test: fix EIP-7702 t8n test expected output

* refactor: remove redundant nil check

---------

Co-authored-by: vickkkkkyy <vickyaviles847@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants