recon-generate 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Source Map to AST Mapping
3
+ *
4
+ * Creates the chain: pc → source map → AST node ID → CFG edge
5
+ *
6
+ * Solc source map format: "s:l:f:j" where:
7
+ * s = byte offset in source file
8
+ * l = length in bytes
9
+ * f = source file index
10
+ * j = jump type (i=into, o=out, -=regular)
11
+ *
12
+ * AST node src format: "offset:length:fileIndex"
13
+ */
14
+ export interface SourceMapEntry {
15
+ offset: number;
16
+ length: number;
17
+ fileIndex: number;
18
+ jump: string;
19
+ pc: number;
20
+ }
21
+ /**
22
+ * Source line information for LLM-friendly output
23
+ */
24
+ export interface SourceLineInfo {
25
+ line: number;
26
+ column: number;
27
+ endLine?: number;
28
+ endColumn?: number;
29
+ }
30
+ /**
31
+ * Convert byte offset to line/column in source file
32
+ * @param source Source file content
33
+ * @param offset Byte offset
34
+ * @returns Line info (1-based line, 0-based column)
35
+ */
36
+ export declare function offsetToLine(source: string, offset: number): SourceLineInfo;
37
+ /**
38
+ * Convert byte offset + length to line range
39
+ */
40
+ export declare function offsetToLineRange(source: string, offset: number, length: number): SourceLineInfo;
41
+ export interface AstLocation {
42
+ offset: number;
43
+ length: number;
44
+ fileIndex: number;
45
+ }
46
+ export interface PcToAstMapping {
47
+ contract: string;
48
+ codehash: string;
49
+ pcToAstId: Map<number, number>;
50
+ astIdToEdge: Map<number, string>;
51
+ pcToEdge: Map<number, string>;
52
+ }
53
+ /**
54
+ * Parse a compressed source map string into entries
55
+ * Source maps use compression where empty fields inherit from previous entry
56
+ */
57
+ export declare function parseSourceMap(sourceMapStr: string, bytecode: string): SourceMapEntry[];
58
+ /**
59
+ * Parse AST node's src field
60
+ */
61
+ export declare function parseAstSrc(src: string): AstLocation | null;
62
+ /**
63
+ * Build a map from source location to AST node IDs
64
+ * Only includes nodes we care about (branch conditions, statements)
65
+ * Uses iterative traversal to avoid stack overflow on large ASTs
66
+ */
67
+ export declare function buildAstLocationMap(ast: any): Map<string, number[]>;
68
+ /**
69
+ * Find AST node ID at a specific source map entry
70
+ */
71
+ export declare function findAstNodeAtLocation(entry: SourceMapEntry, locToNodes: Map<string, number[]>): number | null;
72
+ /**
73
+ * Find ALL AST node IDs at a specific source map entry
74
+ * Returns all nodes that match exactly or contain this location
75
+ */
76
+ export declare function findAllAstNodesAtLocation(entry: SourceMapEntry, locToNodes: Map<string, number[]>): number[];
77
+ /**
78
+ * Identify JUMPI instructions (branch points) from bytecode
79
+ */
80
+ export declare function findJumpiPcs(bytecode: string): number[];
81
+ /**
82
+ * Build complete PC → Edge mapping for a contract
83
+ */
84
+ export declare function buildPcToEdgeMapping(contractName: string, bytecode: string, sourceMap: string, ast: any, cfgEdges: Map<number, string>): PcToAstMapping;
85
+ /**
86
+ * Load build-info and extract source maps for all contracts
87
+ */
88
+ export declare function loadBuildInfoSourceMaps(buildInfoPath: string): Map<string, {
89
+ bytecode: string;
90
+ sourceMap: string;
91
+ sourceFile: string;
92
+ }>;
93
+ /**
94
+ * Branch statement info with line numbers for LLM-friendly output
95
+ */
96
+ export interface BranchStatementInfo {
97
+ pc: number;
98
+ astId: number | null;
99
+ /** All AST IDs at this source location (for matching with CFG edges) */
100
+ allAstIds: number[];
101
+ offset: number;
102
+ length: number;
103
+ /** Source file index (for multi-file contracts with inheritance) */
104
+ fileIndex: number;
105
+ /** Condition line number (1-based) - the line containing the branch condition */
106
+ conditionLine?: number;
107
+ /** First line of the true branch body (1-based) */
108
+ trueBodyLine?: number;
109
+ /** First line of the false branch body (1-based) */
110
+ falseBodyLine?: number;
111
+ /** First PC of the true branch body (for coverage tracking) */
112
+ trueBodyPc?: number;
113
+ /** First PC of the false branch body (for coverage tracking) */
114
+ falseBodyPc?: number;
115
+ /** Function name this branch belongs to (from AST) */
116
+ functionName?: string;
117
+ }
118
+ /**
119
+ * Info about an IfStatement's bodies - AST IDs, lines, and PCs
120
+ */
121
+ export interface IfStatementBodyInfo {
122
+ conditionLine: number;
123
+ trueBodyLine: number;
124
+ trueBodyAstId?: number;
125
+ falseBodyLine?: number;
126
+ falseBodyAstId?: number;
127
+ trueBodyPc?: number;
128
+ falseBodyPc?: number;
129
+ }
130
+ /**
131
+ * Output format for the fuzzer - compact branch-focused format
132
+ * Enhanced with line numbers for LLM integration
133
+ */
134
+ export interface BranchMapping {
135
+ contract: string;
136
+ sourceFile: string;
137
+ fileIndex: number;
138
+ branches: BranchStatementInfo[];
139
+ totalInstructions: number;
140
+ bytecode?: string;
141
+ }
142
+ /**
143
+ * Generate compact branch mapping (only JUMPI instructions)
144
+ * Enhanced with line numbers for LLM-friendly output
145
+ * @param allAsts - Map of fileIndex -> AST for all source files (for multi-file contracts)
146
+ * @param sourceContents - Map of fileIndex -> source file content (for line number calculation)
147
+ */
148
+ export declare function generateBranchMapping(contractName: string, bytecode: string, sourceMap: string, sourceFile: string, ast: any, allAsts?: Map<number, any>, sourceContents?: Map<number, string>): BranchMapping;
149
+ /**
150
+ * Output format for the fuzzer
151
+ */
152
+ export interface SourceMapOutput {
153
+ contract: string;
154
+ sourceFile: string;
155
+ pcMappings: {
156
+ pc: number;
157
+ astId: number | null;
158
+ edgeId: string | null;
159
+ file: number;
160
+ offset: number;
161
+ length: number;
162
+ isJumpi: boolean;
163
+ }[];
164
+ jumpiPcs: number[];
165
+ }
166
+ /**
167
+ * Generate complete source mapping for a contract
168
+ */
169
+ export declare function generateSourceMapping(contractName: string, bytecode: string, sourceMap: string, sourceFile: string, ast: any, cfgEdges?: Map<number, string>): SourceMapOutput;