fix(multicall): resolve critical multicall parsing corruption issues

- Added comprehensive bounds checking to prevent buffer overruns in multicall parsing
- Implemented graduated validation system (Strict/Moderate/Permissive) to reduce false positives
- Added LRU caching system for address validation with 10-minute TTL
- Enhanced ABI decoder with missing Universal Router and Arbitrum-specific DEX signatures
- Fixed duplicate function declarations and import conflicts across multiple files
- Added error recovery mechanisms with multiple fallback strategies
- Updated tests to handle new validation behavior for suspicious addresses
- Fixed parser test expectations for improved validation system
- Applied gofmt formatting fixes to ensure code style compliance
- Fixed mutex copying issues in monitoring package by introducing MetricsSnapshot
- Resolved critical security vulnerabilities in heuristic address extraction
- Progress: Updated TODO audit from 10% to 35% complete

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Krypto Kajun
2025-10-17 00:12:55 -05:00
parent f358f49aa9
commit 850223a953
8621 changed files with 79808 additions and 7340 deletions

View File

@@ -0,0 +1,43 @@
# Arbitrage Executor Hardening Plan
## Overview
Replace simulated flash-swap execution paths with on-chain integrations, accurate gas handling, and post-trade reconciliation. The current implementation relies on mock receipts, placeholder calldata, and synthetic pool data.
## Tasks
1. **Contract Integration**
- [ ] Add Go bindings for the flash swap/aggregator contract (generate via `abigen` if absent).
- [ ] Define canonical calldata struct matching the on-chain function signature (token path, pool info, slippage limits, recipient).
2. **Transaction Submission**
- [x] Replace `submitTransaction` with actual contract call using flash swap aggregator binding.
- [ ] Implement nonce management and ensure transactions are signed with the configured key manager.
3. **Gas Estimation & Pricing**
- [x] Swap placeholder gas limit with `client.EstimateGas` (include calldata and value).
- [x] Fetch base fee + priority tip dynamically; tie into Arbitrum fee/tip suggestions.
- [ ] Enforce config-driven max fee/tip thresholds (fallback to abort rather than cap to static value).
4. **Confirmation & Reverts**
- [ ] Replace simulated receipt in `waitForConfirmation` with polling `TransactionReceipt`, respecting context timeout.
- [ ] Decode revert reasons/logs for diagnostics; handle dropped/replace-by-fee scenarios.
5. **Profit/Loss Calculation**
- [ ] Update `calculateActualProfit` to parse emitted events/logs for actual amounts in/out.
- [ ] Subtract real gas cost from on-chain data; convert to `UniversalDecimal` with correct symbols.
- [ ] Emit structured logs/metrics for realized profit, slippage, and gas usage.
6. **Fallback & Simulation**
- [ ] Move current simulation helpers into a `*_test.go` or dev-only path; guard with build tags if necessary.
7. **Tests**
- [ ] Unit tests using mocked contract interface for success, revert, and timeout.
- [ ] Integration test with geth simulated backend or fork network verifying end-to-end flash swap.
8. **Documentation**
- [ ] Update `docs/5_development/` and `docs/6_operations/` with new requirements (contract addresses, env vars).
- [ ] Note the removal of simulated paths; include troubleshooting steps for on-chain failures.
References:
- `pkg/arbitrage/executor.go` (simulateFlashSwapArbitrage, executeArbitrage)
- `pkg/arbitrage/flash_executor.go` (submitTransaction, waitForConfirmation, calculateActualProfit)