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,25 @@
{
"name": "balancer_wbtc_usdc",
"description": "Simplified Balancer 50/50 weighted pool",
"pool": {
"address": "0x0000000000000000000000000000000000000007",
"exchange": "balancer",
"token0": { "symbol": "WBTC", "decimals": 18 },
"token1": { "symbol": "USDC", "decimals": 18 },
"reserve0": { "value": "100000000000000000000", "decimals": 18, "symbol": "WBTC" },
"reserve1": { "value": "100000000000000000000", "decimals": 18, "symbol": "USDC" },
"weights": [
{ "value": "5", "decimals": 1, "symbol": "W0" },
{ "value": "5", "decimals": 1, "symbol": "W1" }
]
},
"tests": [
{
"name": "amount_out_0_001_wbtc",
"type": "amount_out",
"amount_in": { "value": "1000000000000000000", "decimals": 18, "symbol": "WBTC" },
"expected": { "value": "1000000000000000000", "decimals": 18, "symbol": "USDC" },
"tolerance_bps": 1
}
]
}

View File

@@ -0,0 +1,23 @@
{
"name": "camelot_algebra_weth_usdc",
"description": "Camelot/Algebra concentrated liquidity sample",
"pool": {
"address": "0x0000000000000000000000000000000000000004",
"exchange": "camelot",
"token0": { "symbol": "WETH", "decimals": 18 },
"token1": { "symbol": "USDC", "decimals": 18 },
"reserve0": { "value": "400000000000000000000", "decimals": 18, "symbol": "WETH" },
"reserve1": { "value": "900000000000000000000", "decimals": 18, "symbol": "USDC" },
"fee": { "value": "500", "decimals": 6, "symbol": "FEE" },
"liquidity": "1"
},
"tests": [
{
"name": "amount_out_0_1_weth",
"type": "amount_out",
"amount_in": { "value": "100000000000000000", "decimals": 18, "symbol": "WETH" },
"expected": { "value": "224831320273846572", "decimals": 18, "symbol": "USDC" },
"tolerance_bps": 1
}
]
}

View File

@@ -0,0 +1,23 @@
{
"name": "curve_usdc_usdt",
"description": "Curve stable swap example with 0.04% fee",
"pool": {
"address": "0x0000000000000000000000000000000000000006",
"exchange": "curve",
"token0": { "symbol": "USDC", "decimals": 6 },
"token1": { "symbol": "USDT", "decimals": 6 },
"reserve0": { "value": "1000000000000", "decimals": 6, "symbol": "USDC" },
"reserve1": { "value": "1000000000000", "decimals": 6, "symbol": "USDT" },
"fee": { "value": "4", "decimals": 4, "symbol": "FEE" },
"amplification": "100"
},
"tests": [
{
"name": "amount_out_1_usdc",
"type": "amount_out",
"amount_in": { "value": "1000000", "decimals": 6, "symbol": "USDC" },
"expected": { "value": "999600", "decimals": 6, "symbol": "USDT" },
"tolerance_bps": 1
}
]
}

View File

@@ -0,0 +1,206 @@
{
"version": "1.0.0",
"timestamp": "2024-10-08T00:00:00Z",
"description": "Default test vectors for MEV Bot math validation",
"exchanges": {
"uniswap_v2": {
"exchange_type": "uniswap_v2",
"pricing_tests": [
{
"test_name": "ETH_USDC_Standard_Pool",
"description": "Standard ETH/USDC pool price calculation",
"reserve_0": "1000000000000000000000",
"reserve_1": "2000000000000",
"expected_price": "2000000000000000000000",
"tolerance": 1.0
},
{
"test_name": "WBTC_ETH_High_Value",
"description": "High value WBTC/ETH pool",
"reserve_0": "50000000000",
"reserve_1": "10000000000000000000000",
"expected_price": "20000000000000000000",
"tolerance": 1.0
},
{
"test_name": "Small_Pool_Precision",
"description": "Small liquidity pool precision test",
"reserve_0": "1000000000000000000",
"reserve_1": "2000000000",
"expected_price": "2000000000000000000000",
"tolerance": 5.0
}
],
"amount_tests": [
{
"test_name": "ETH_to_USDC_Small_Swap",
"description": "Small ETH to USDC swap",
"reserve_0": "1000000000000000000000",
"reserve_1": "2000000000000",
"amount_in": "1000000000000000000",
"token_in": "0",
"fee": "3000",
"expected_amount_out": "1994006985000",
"tolerance": 5.0
},
{
"test_name": "USDC_to_ETH_Large_Swap",
"description": "Large USDC to ETH swap",
"reserve_0": "1000000000000000000000",
"reserve_1": "2000000000000",
"amount_in": "10000000000",
"token_in": "1",
"fee": "3000",
"expected_amount_out": "4975124378109453",
"tolerance": 10.0
}
],
"price_impact_tests": [
{
"test_name": "Large_ETH_Swap_Impact",
"description": "Price impact of large ETH swap",
"reserve_0": "1000000000000000000000",
"reserve_1": "2000000000000",
"swap_amount": "100000000000000000000",
"token_in": "0",
"expected_price_impact": "9.09",
"tolerance": 10.0
}
]
},
"uniswap_v3": {
"exchange_type": "uniswap_v3",
"pricing_tests": [
{
"test_name": "ETH_USDC_V3_Basic",
"description": "ETH/USDC V3 price from sqrtPriceX96",
"sqrt_price_x96": "3543191142285914327220224",
"expected_price": "2000000000000000000000",
"tolerance": 1.0
},
{
"test_name": "WBTC_ETH_V3_Tick",
"description": "WBTC/ETH V3 price from tick",
"tick": 92233,
"expected_price": "20000000000000000000",
"tolerance": 2.0
}
],
"amount_tests": [
{
"test_name": "V3_Concentrated_Liquidity_Swap",
"description": "Swap within concentrated liquidity range",
"reserve_0": "1000000000000000000000",
"reserve_1": "2000000000000",
"amount_in": "1000000000000000000",
"token_in": "0",
"fee": "500",
"expected_amount_out": "1999000000000",
"tolerance": 2.0
}
],
"price_impact_tests": [
{
"test_name": "V3_Cross_Tick_Impact",
"description": "Price impact crossing multiple ticks",
"reserve_0": "1000000000000000000000",
"reserve_1": "2000000000000",
"swap_amount": "50000000000000000000",
"token_in": "0",
"expected_price_impact": "4.76",
"tolerance": 20.0
}
]
},
"curve": {
"exchange_type": "curve",
"pricing_tests": [
{
"test_name": "Stable_USDC_USDT_Pool",
"description": "Stable swap USDC/USDT pricing",
"reserve_0": "1000000000000",
"reserve_1": "1000000000000",
"expected_price": "1000000000000000000",
"tolerance": 0.5
},
{
"test_name": "Imbalanced_Stable_Pool",
"description": "Imbalanced stable pool pricing",
"reserve_0": "2000000000000",
"reserve_1": "1000000000000",
"expected_price": "980000000000000000",
"tolerance": 5.0
}
],
"amount_tests": [
{
"test_name": "Stable_Swap_Low_Impact",
"description": "Low price impact stable swap",
"reserve_0": "1000000000000",
"reserve_1": "1000000000000",
"amount_in": "1000000000",
"token_in": "0",
"expected_amount_out": "999000000",
"tolerance": 1.0
}
],
"price_impact_tests": [
{
"test_name": "Large_Stable_Swap_Impact",
"description": "Large swap in stable pool",
"reserve_0": "1000000000000",
"reserve_1": "1000000000000",
"swap_amount": "100000000000",
"token_in": "0",
"expected_price_impact": "0.5",
"tolerance": 2.0
}
]
},
"balancer": {
"exchange_type": "balancer",
"pricing_tests": [
{
"test_name": "Weighted_80_20_ETH_USDC",
"description": "80/20 weighted pool ETH/USDC",
"reserve_0": "800000000000000000000",
"reserve_1": "400000000000",
"expected_price": "2500000000000000000000",
"tolerance": 2.0
},
{
"test_name": "Weighted_50_50_Pool",
"description": "50/50 weighted pool",
"reserve_0": "1000000000000000000000",
"reserve_1": "2000000000000",
"expected_price": "2000000000000000000000",
"tolerance": 1.0
}
],
"amount_tests": [
{
"test_name": "Weighted_Pool_Small_Swap",
"description": "Small swap in weighted pool",
"reserve_0": "800000000000000000000",
"reserve_1": "400000000000",
"amount_in": "1000000000000000000",
"token_in": "0",
"expected_amount_out": "2475000000000",
"tolerance": 5.0
}
],
"price_impact_tests": [
{
"test_name": "Weighted_Pool_Price_Impact",
"description": "Price impact in weighted pool",
"reserve_0": "800000000000000000000",
"reserve_1": "400000000000",
"swap_amount": "80000000000000000000",
"token_in": "0",
"expected_price_impact": "12.5",
"tolerance": 15.0
}
]
}
}
}

View File

@@ -0,0 +1,24 @@
{
"name": "ramses_v3_weth_usdc",
"description": "Ramses V3 concentrated liquidity example",
"pool": {
"address": "0x0000000000000000000000000000000000000005",
"exchange": "ramses",
"token0": { "symbol": "WETH", "decimals": 18 },
"token1": { "symbol": "USDC", "decimals": 18 },
"reserve0": { "value": "200000000000000000000", "decimals": 18, "symbol": "WETH" },
"reserve1": { "value": "400000000000000000000", "decimals": 18, "symbol": "USDC" },
"fee": { "value": "3000", "decimals": 6, "symbol": "FEE" },
"sqrt_price_x96": "79228162514264337593543950336",
"liquidity": "1"
},
"tests": [
{
"name": "amount_out_0_05_weth",
"type": "amount_out",
"amount_in": { "value": "50000000000000000", "decimals": 18, "symbol": "WETH" },
"expected": { "value": "99675155967375131", "decimals": 18, "symbol": "USDC" },
"tolerance_bps": 1
}
]
}

View File

@@ -0,0 +1,21 @@
{
"name": "traderjoe_usdc_weth",
"description": "TraderJoe constant-product pool example mirroring Uniswap V2 math",
"pool": {
"address": "0x0000000000000000000000000000000000000002",
"exchange": "traderjoe",
"token0": { "symbol": "WETH", "decimals": 18 },
"token1": { "symbol": "USDC", "decimals": 18 },
"reserve0": { "value": "800000000000000000000", "decimals": 18, "symbol": "WETH" },
"reserve1": { "value": "1200000000000000000000000", "decimals": 18, "symbol": "USDC" }
},
"tests": [
{
"name": "amount_out_3_weth",
"type": "amount_out",
"amount_in": { "value": "3000000000000000000", "decimals": 18, "symbol": "WETH" },
"expected": { "value": "4469788577954173832583", "decimals": 18, "symbol": "USDC" },
"tolerance_bps": 1
}
]
}

View File

@@ -0,0 +1,21 @@
{
"name": "uniswap_v2_usdc_weth",
"description": "Uniswap V2 style pool with 10k WETH against 20M USDC",
"pool": {
"address": "0x0000000000000000000000000000000000000001",
"exchange": "uniswap_v2",
"token0": { "symbol": "WETH", "decimals": 18 },
"token1": { "symbol": "USDC", "decimals": 18 },
"reserve0": { "value": "500000000000000000000", "decimals": 18, "symbol": "WETH" },
"reserve1": { "value": "1000000000000000000000000", "decimals": 18, "symbol": "USDC" }
},
"tests": [
{
"name": "amount_out_5_weth",
"type": "amount_out",
"amount_in": { "value": "5000000000000000000", "decimals": 18, "symbol": "WETH" },
"expected": { "value": "9871580343970612988504", "decimals": 18, "symbol": "USDC" },
"tolerance_bps": 1
}
]
}

View File

@@ -0,0 +1,24 @@
{
"name": "uniswap_v3_weth_usdc",
"description": "Uniswap V3 style pool around price 1:1 for deterministic regression",
"pool": {
"address": "0x0000000000000000000000000000000000000003",
"exchange": "uniswap_v3",
"token0": { "symbol": "WETH", "decimals": 18 },
"token1": { "symbol": "USDC", "decimals": 18 },
"reserve0": { "value": "500000000000000000000", "decimals": 18, "symbol": "WETH" },
"reserve1": { "value": "1000000000000000000000", "decimals": 18, "symbol": "USDC" },
"fee": { "value": "3000", "decimals": 6, "symbol": "FEE" },
"sqrt_price_x96": "79228162514264337593543950336",
"liquidity": "1"
},
"tests": [
{
"name": "amount_out_0_1_weth",
"type": "amount_out",
"amount_in": { "value": "100000000000000000", "decimals": 18, "symbol": "WETH" },
"expected": { "value": "199360247566635212", "decimals": 18, "symbol": "USDC" },
"tolerance_bps": 1
}
]
}