Files
crypto/MIGRATION_NOTES.md
T
Zach Kelling 733d740cf9 refactor: remove geth dependencies and internalize utilities
- Created common types (Hash, Address) in crypto/common
- Created hexutil utilities for hex encoding/decoding
- Created math utilities for big integer operations
- Created minimal RLP encoder for crypto package needs
- Updated all imports from github.com/luxfi/geth to local packages
- All tests pass with no functionality changes
2025-08-03 01:50:33 +00:00

2.2 KiB

Geth Dependency Removal Notes

Summary

Successfully removed all dependencies on github.com/luxfi/geth from the crypto package by implementing the necessary types and utilities locally.

Changes Made

1. Created Common Types (common/types.go)

  • Implemented Hash type (32-byte array) with all necessary methods
  • Implemented Address type (20-byte array) with EIP-55 compliant checksumming
  • Added common big integer constants (Big0, Big1, etc.)
  • Added helper functions for hex encoding/decoding

2. Created Hex Utilities (common/hexutil/)

  • Implemented hex encoding/decoding with 0x prefix support
  • Added types for JSON marshaling (Big, Uint64, Uint, Bytes)
  • Supports all the hex utility functions previously imported from geth

3. Created Math Utilities (common/math/)

  • Implemented big integer math functions (BigPow, BigMax, BigMin)
  • Added PaddedBigBytes for encoding big integers with padding
  • Implemented safe arithmetic operations (SafeAdd, SafeSub, SafeMul, SafeDiv)
  • Added other utility functions like ReadBits, U256, S256

4. Created RLP Encoding (rlp/encode.go)

  • Minimal RLP encoder implementation supporting:
    • Basic types: []byte, string, uint64, *big.Int
    • Common types: common.Address, common.Hash
    • Lists: []interface{}
  • Sufficient for crypto package needs (primarily CreateAddress function)

5. Updated All Imports

  • Changed all imports from github.com/luxfi/geth/* to github.com/luxfi/crypto/*
  • Updated files:
    • crypto.go
    • crypto_test.go
    • signature_test.go
    • signature_cgo.go
    • secp256k1/ethereum.go
    • kzg4844/kzg4844.go
    • kzg4844/kzg4844_ckzg_cgo.go

Testing

  • All existing tests pass
  • No functionality changes, only dependency removal
  • The CreateAddress function works correctly with the new RLP encoder

Benefits

  1. No external dependency on geth
  2. Reduced binary size (only includes necessary code)
  3. Better control over the implementation
  4. Easier to maintain and update

Notes

  • The implementations are minimal but complete for crypto package needs
  • If more RLP functionality is needed in the future, the encoder can be extended
  • The common types match the geth interface exactly for compatibility