erigontech / erigontech/erigon
execution/types: follow-up simplifications for EIP-7702 authorization signing
- Dominant language
- Go
- Stars
- 3.6k
- Forks
- 1.5k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 455
Description
Follow-ups from #22830 (`types.SignAuthorization`), deliberately left out of that PR to keep the recovery path untouched.
## Stream the recovery preimage instead of building it
`recoverSignerFromRLP` builds the signing preimage in a temporary slice before hashing:
```go
hashData := make([]byte, 0, 1+len(rlp))
hashData = append(hashData, params.SetCodeMagicPrefix)
hashData = append(hashData, rlp...)
hash := crypto.Keccak256Hash(hashData)
```
The minimal change reuses `prefixedPayloadHash` (already used by `SignAuthorization`) to stream `prefix || payload` into the pooled Keccak state, removing the per-authorization preimage allocation and copy.
Going further, `Authorization.RecoverSigner` could stream `encodeSigningPayload` directly into the hasher, the same way `SignAuthorization` does. That would also remove the intermediate `bytes.Buffer` the payload is encoded into, and the `data`/`buf` parameters could be dropped, simplifying scratch-buffer management at the production call sites (txpool parsing, block execution, RPC, tracing). This variant changes the method signature, so it ripples further than the minimal one.
Authorization recovery runs per authorization on hot paths, and #22830 intentionally kept its allocation profile unchanged. `keccak.Sum256` is a single-shot hash, so benchmark before/after to confirm the streaming version actually wins.
## Extend signing-helper test coverage to encoder edge cases
`TestSignAuthorizationRoundTrip` covers one typical tuple. A table version could pin the encoder edge paths through the shared `encodeSigningPayload`:
- zero delegation address (the clear-delegation case; currently covered only end-to-end by `TestSetCodeClearDelegationPurgesCodeDomain`)
- `chainID = 0` and `chainID >= 2^248` (single-byte and split-write paths of `rlp.EncodeUint256`)
- `nonce = 0` (empty-string encoding in `rlp.EncodeU64`)
Contributor guide
Assessment
This issue has not been assessed yet.