Skip to content

fix(crypto): take *types.Transaction in RecoverPublicKey - #567

Open
0xrlawrence wants to merge 1 commit into
canopy-network:mainfrom
0xrlawrence:fix/recoverpublickey-tx-pointer
Open

0xrlawrence wants to merge 1 commit into
canopy-network:mainfrom
0xrlawrence:fix/recoverpublickey-tx-pointer

Conversation

@0xrlawrence

Copy link
Copy Markdown

Description

RecoverPublicKey accepts go-ethereum's types.Transaction by value. That type carries atomic.Pointer caches for the hash, size and sender, and is documented as non-copyable. go vet reports it:

lib/crypto/eth_secp256k1.go:114: RecoverPublicKey passes lock by value:
types.Transaction contains sync/atomic.Pointer[...] contains atomic.noCopy

The only caller is rlpToCanopyTransaction, which handles untrusted inbound Ethereum-compatibility transactions, so this is on a hot path.

Changes Made

  • Changed the parameter to *types.Transaction.
  • signer.Hash(tx) now hashes the caller's transaction — and can use its hash cache — instead of a throwaway copy.
  • Updated the single caller, which already has an addressable local, to pass &tx.

Testing

  • go build ./...
  • go test ./lib/crypto/ ./fsm/ passes
  • go vet ./lib/crypto/ no longer reports the copylocks finding

🤖 Generated with Claude Code

go-ethereum's types.Transaction carries atomic.Pointer caches for the hash,
size and sender, and is documented as non-copyable. Accepting it by value
copied those caches on every call; 'go vet' reports it as a lock copy:

    lib/crypto/eth_secp256k1.go:114: RecoverPublicKey passes lock by value:
    types.Transaction contains sync/atomic.Pointer[...] contains atomic.noCopy

The only caller is rlpToCanopyTransaction, which handles untrusted inbound
Ethereum-compatibility transactions, so this is on a hot path.

Switching the parameter to a pointer removes the copy and lets
signer.Hash(tx) use the caller's transaction (and its hash cache) directly
instead of a throwaway copy. The caller already has an addressable local, so
it just passes &tx.
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.

1 participant