feat: comprehensive audit infrastructure and Phase 1 refactoring

This commit includes:

## Audit & Testing Infrastructure
- scripts/audit.sh: 12-section comprehensive codebase audit
- scripts/test.sh: 7 test types (unit, integration, race, bench, coverage, contracts, pkg)
- scripts/check-compliance.sh: SPEC.md compliance validation
- scripts/check-docs.sh: Documentation coverage checker
- scripts/dev.sh: Unified development script with all commands

## Documentation
- SPEC.md: Authoritative technical specification
- docs/AUDIT_AND_TESTING.md: Complete testing guide (600+ lines)
- docs/SCRIPTS_REFERENCE.md: All scripts documented (700+ lines)
- docs/README.md: Documentation index and navigation
- docs/DEVELOPMENT_SETUP.md: Environment setup guide
- docs/REFACTORING_PLAN.md: Systematic refactoring plan

## Phase 1 Refactoring (Critical Fixes)
- pkg/validation/helpers.go: Validation functions for addresses/amounts
- pkg/sequencer/selector_registry.go: Thread-safe selector registry
- pkg/sequencer/reader.go: Fixed race conditions with atomic metrics
- pkg/sequencer/swap_filter.go: Fixed race conditions, added error logging
- pkg/sequencer/decoder.go: Added address validation

## Changes Summary
- Fixed race conditions on 13 metric counters (atomic operations)
- Added validation at all ingress points
- Eliminated silent error handling
- Created selector registry for future ABI migration
- Reduced SPEC.md violations from 7 to 5

Build Status:  All packages compile
Compliance:  No race conditions, no silent failures
Documentation:  1,700+ lines across 5 comprehensive guides

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Administrator
2025-11-11 07:17:13 +01:00
parent a13b6ba1f7
commit 3505921207
34 changed files with 7514 additions and 77 deletions

80
pkg/validation/helpers.go Normal file
View File

@@ -0,0 +1,80 @@
package validation
import (
"errors"
"math/big"
"github.com/ethereum/go-ethereum/common"
)
var (
// ErrZeroAddress is returned when a zero address is provided
ErrZeroAddress = errors.New("zero address not allowed")
// ErrNilAddress is returned when a nil address pointer is provided
ErrNilAddress = errors.New("nil address pointer")
// ErrZeroAmount is returned when a zero amount is provided
ErrZeroAmount = errors.New("zero amount not allowed")
// ErrNilAmount is returned when a nil amount pointer is provided
ErrNilAmount = errors.New("nil amount pointer")
// ErrNegativeAmount is returned when a negative amount is provided
ErrNegativeAmount = errors.New("negative amount not allowed")
)
// ValidateAddress validates that an address is not zero
func ValidateAddress(addr common.Address) error {
if addr == (common.Address{}) {
return ErrZeroAddress
}
return nil
}
// ValidateAddressPtr validates that an address pointer is not nil and not zero
func ValidateAddressPtr(addr *common.Address) error {
if addr == nil {
return ErrNilAddress
}
if *addr == (common.Address{}) {
return ErrZeroAddress
}
return nil
}
// ValidateAmount validates that an amount is not nil, not zero, and not negative
func ValidateAmount(amount *big.Int) error {
if amount == nil {
return ErrNilAmount
}
if amount.Sign() == 0 {
return ErrZeroAmount
}
if amount.Sign() < 0 {
return ErrNegativeAmount
}
return nil
}
// ValidateAmountAllowZero validates that an amount is not nil and not negative
// (allows zero amounts for optional parameters)
func ValidateAmountAllowZero(amount *big.Int) error {
if amount == nil {
return ErrNilAmount
}
if amount.Sign() < 0 {
return ErrNegativeAmount
}
return nil
}
// IsZeroAddress checks if an address is zero without returning an error
func IsZeroAddress(addr common.Address) bool {
return addr == (common.Address{})
}
// IsZeroAmount checks if an amount is zero or nil without returning an error
func IsZeroAmount(amount *big.Int) bool {
return amount == nil || amount.Sign() == 0
}