Files
mev-beta/tools/math-audit/internal/report/report.go
Krypto Kajun 850223a953 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>
2025-10-17 00:12:55 -05:00

98 lines
2.9 KiB
Go

package report
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/fraktal/mev-beta/tools/math-audit/internal/audit"
)
// WriteJSON writes the audit result as pretty JSON to the specified directory.
func WriteJSON(dir string, res audit.Result) (string, error) {
if err := os.MkdirAll(dir, 0o755); err != nil {
return "", fmt.Errorf("create report dir: %w", err)
}
path := filepath.Join(dir, "report.json")
payload, err := json.MarshalIndent(res, "", " ")
if err != nil {
return "", fmt.Errorf("marshal report: %w", err)
}
if err := os.WriteFile(path, payload, 0o644); err != nil {
return "", fmt.Errorf("write report: %w", err)
}
return path, nil
}
// WriteMarkdown renders a human-readable summary and writes it next to the JSON.
func WriteMarkdown(dir string, res audit.Result) (string, error) {
if err := os.MkdirAll(dir, 0o755); err != nil {
return "", fmt.Errorf("create report dir: %w", err)
}
path := filepath.Join(dir, "report.md")
content := GenerateMarkdown(res)
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
return "", fmt.Errorf("write markdown: %w", err)
}
return path, nil
}
// GenerateMarkdown returns a markdown representation of the audit result.
func GenerateMarkdown(res audit.Result) string {
var b strings.Builder
b.WriteString("# Math Audit Report\n\n")
b.WriteString(fmt.Sprintf("- Generated: %s UTC\n", res.Summary.GeneratedAt.Format("2006-01-02 15:04:05")))
b.WriteString(fmt.Sprintf("- Vectors: %d/%d passed\n", res.Summary.VectorsPassed, res.Summary.TotalVectors))
b.WriteString(fmt.Sprintf("- Assertions: %d/%d passed\n", res.Summary.AssertionsPassed, res.Summary.TotalAssertions))
b.WriteString(fmt.Sprintf("- Property checks: %d/%d passed\n\n", res.Summary.PropertySucceeded, res.Summary.PropertyChecks))
if len(res.Vectors) > 0 {
b.WriteString("## Vector Results\n\n")
b.WriteString("| Vector | Exchange | Status | Notes |\n")
b.WriteString("| --- | --- | --- | --- |\n")
for _, vec := range res.Vectors {
status := "✅ PASS"
if !vec.Passed {
status = "❌ FAIL"
}
var notes []string
for _, test := range vec.Tests {
if !test.Passed {
notes = append(notes, fmt.Sprintf("%s (%.4f bps)", test.Name, test.DeltaBPS))
}
}
if len(vec.Errors) > 0 {
notes = append(notes, vec.Errors...)
}
noteStr := ""
if len(notes) > 0 {
noteStr = strings.Join(notes, "; ")
}
b.WriteString(fmt.Sprintf("| %s | %s | %s | %s |\n", vec.Name, vec.Exchange, status, noteStr))
}
b.WriteString("\n")
}
if len(res.PropertyChecks) > 0 {
b.WriteString("## Property Checks\n\n")
for _, check := range res.PropertyChecks {
status := "✅"
if !check.Passed {
status = "❌"
}
if check.Details != "" {
b.WriteString(fmt.Sprintf("- %s %s — %s\n", status, check.Name, check.Details))
} else {
b.WriteString(fmt.Sprintf("- %s %s\n", status, check.Name))
}
}
b.WriteString("\n")
}
return b.String()
}