An automatic verification method for bounded equivalence of compiled and optimized binary programs
By performing bounded symbolic execution and sorting path feature vectors on the compiled and optimized binary program, the problems of path splitting and merging were solved, and the equivalence of the compiled and optimized binary program was automatically verified, reducing the false positive rate and clarifying the reasons for verification failure.
Patent Information
- Application Number
- CN202611344870.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-01
- Publication Date
- 2026-11-17
AI Technical Summary
Existing technologies struggle to effectively handle path splitting and merging issues in compiled and optimized binary programs, cannot accurately determine the path comparison order, and cannot effectively verify the consistency of functional behavior in return values, observable memory writes, and global states.
A path alignment and partition refinement-based approach is adopted to perform bounded symbolic execution on the binary programs to be compared, extract path constraints, execution trajectories, return values and global state summaries, and heuristically sort the path feature vectors and trajectory overlap to construct one-to-one or one-to-many path matching. The semantic signature is verified by satisfiability modulo theory.
It can automatically verify the equivalence of compiled and optimized binary programs, handle path splitting and merging issues, reduce invalid queries, reduce false positives, and clarify the reasons for verification failures.
Smart Images

Figure CN123116290A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of program equivalence verification and automatic reasoning based on modular theory of satisfiability, specifically to an automatic method for bounded equivalence verification of compiled and optimized binary programs. Background Technology
[0002] Program equivalence verification is used to determine whether two programs produce consistent functional behavior under the same input. It is a fundamental issue in code optimization verification, program translation or refactoring verification, and program synthesis result confirmation. Existing research mostly focuses on programs with source code, establishing the correspondence between programs through syntax structure, variable information, or intermediate representations. However, in scenarios such as legacy software, third-party software, and compiler optimization result verification, source code, debugging information, or compilation process may not be available, thus requiring direct analysis of the binary executable program.
[0003] When verifying the equivalence of binary programs, it is necessary to distinguish between the consistency of internal execution paths and the consistency of external functional behavior. Two programs may use different conditional boundaries or follow different control flow paths, but still return the same result on the boundary inputs. For example, one program uses a less than relation to judge two inputs, while another program uses a less than or equal to relation. When the two inputs are equal, they will enter different branches, but both will return the same maximum value. If only the literal form of the path constraints is compared, such functionally equivalent programs will be incorrectly judged as inequivalent; conversely, relying solely on the same output under limited test inputs cannot rule out accidental consistency. Binary programs lack variable names, type declarations, and high-level control structures found in the source code. The compiler also performs optimizations such as branch elimination, instruction reordering, loop unrolling, and control flow reconstruction, significantly changing the internal control flow before and after optimization. These changes may split a single execution path in one binary program into multiple paths in another binary program, or they may merge multiple paths into fewer paths. Therefore, the path correspondence between two binary programs cannot be directly determined based solely on the number of paths, path order, or control flow structure.
[0004] Symbolic execution can replace specific inputs with symbolic values to explore the execution paths of binary programs and represent the conditions required to reach each path as satisfiability modular theory constraints. Satisfiability modular theory solvers can be used to determine whether path constraints are satisfiable and to verify the logical relationships between constraints. However, symbolic execution itself cannot solve the path correspondence problem between binary programs. After compilation optimization, two paths that should correspond may have significantly different constraint expressions and basic block execution trajectories. Therefore, before proceeding to equivalence solving, it is still necessary to determine which path in the first binary program should be compared with which path in the second binary program.
[0005] Existing methods for verifying program equivalence are geared towards high-level language source code. They handle the verification complexity introduced by loops and nonlinear arithmetic through common code abstraction, iterative refinement, or the insertion of assertions. These methods typically rely on structured source code, variable names, and local statement locations to establish correspondences between the programs being compared. When the object of analysis is only a binary executable program, the aforementioned source code information is unavailable, making it difficult to directly obtain the relevant correspondences and assertion locations.
[0006] Another approach uses theorem proving tools or verification tools oriented towards specific compiler intermediate representations to prove the correctness of optimization rules. Theorem proving methods offer high reliability but typically require significant manual modeling and proof work; methods oriented towards compiler intermediate representations can automatically verify specific intermediate representations or specific optimization rules, but their verification targets are limited by the corresponding compilation infrastructure and cannot be directly used on binary executables from arbitrary sources.
[0007] In the field of binary program verification, existing methods execute the program to be compared using user-provided test cases, collect specific execution trajectories, infer alignment predicates between programs, and further construct program alignment automata and infer inductive invariants. These methods can handle some complex loop transformations, but the verification results depend on whether the specific test cases can generate representative trajectories, and constructing alignment automata and solving the corresponding proof conditions can incur significant time overhead. Other methods utilize basic block matching, control flow graph similarity, and execution trajectory overlap for binary difference analysis or patch analysis. These structural signals help find candidate corresponding positions, but when used alone, they usually cannot provide a formal proof of optimized loops and program functional behavior.
[0008] In summary, existing program equivalence verification techniques lack optimized binary programs of the source code and still face the following interrelated problems: 1) How to determine the comparison order of candidate paths when both the path constraint form and the control flow trajectory change; 2) How to handle the one-to-many input space correspondences generated by path splitting and path merging; 3) How to perform provable comparisons of functional behaviors such as return values, observable memory writes, and global states after determining the path input space correspondences. Summary of the Invention
[0009] The purpose of this invention is to address the shortcomings of existing technologies by designing an automatic verification method for bounded equivalence of compiled and optimized binary programs. Employing a path alignment and partitioning refinement approach, it can automatically determine the equivalence of binary programs within a finite path space. The method first performs bounded symbolic execution on the two binary programs to be compared, extracting path constraints, execution trajectories, return values, observable memory writes, and global state summaries. Then, it heuristically sorts candidate paths based on the overlap of path constraint feature vectors and trajectories, and constructs one-to-one or one-to-many path matching under the input space coverage relationship. Finally, it verifies the semantic signatures on the overlapping input regions using satisfiability modulo theory constraints, thus providing an equivalence / inequivalence determination. This invention can handle path splitting, path merging, and condition rewriting problems introduced by compiler optimization, and is applicable to scenarios such as optimization verification, patch confirmation, and binary regression testing. It does not require the two programs to have the same number of paths or a one-to-one path structure; instead, it first explores the symbolic representation of paths, then completes matching based on the input space coverage relationship and path features, and finally performs SMT proof on the semantic signatures on the overlapping input regions, showing promising application prospects.
[0010] The specific technical solution to achieve the purpose of this invention is: an automatic verification method for bounded equivalence of compiled and optimized binary programs, characterized in that the verification method includes the following steps:
[0011] Step S1: Perform bounded symbolic execution on the first binary program and the second binary program to be compared. Model the function entry parameters, external inputs and pre-configured global inputs as symbolic variables. Propagate the register state, symbolic memory state and path constraints along the explorable execution path. Record the execution trajectory, return value, observable write events and global state at the end of the path to form two sets of path artifacts.
[0012] Step S2: Extract path constraints from each path's workpiece Execution trajectory Symbol return value Observable memory writes and global state , forming a path summary, the Record observable write addresses, write values, and write order during path execution. Record the final value of the pre-configured global observable state at the end of the path.
[0013] Step S3: Extract all path constraints from the first binary program to obtain the global input space. Extracting all path constraints from the second binary program yields the global input space. And solve the query using Satisfiability Modulus Theory (SMT). Check if there is an input region unique to one side of the two explored path sets.
[0014] Step S4: After passing the global input space check, extract feature vectors from the path constraints of the source path and the target path, calculate the feature similarity of the candidate path combination, and perform heuristic rearrangement based on the execution trajectory overlap when the candidate confidence is insufficient, to generate an ordered candidate queue.
[0015] Step S5: Initialize the remaining uncovered input area for each source path, visit the target path in the ordered candidate queue, calculate the new intersection between the target path and the remaining uncovered area, add one or more target paths covering the newly added area to the coverage set, and update the remaining area to construct a one-to-one or one-to-many path matching record.
[0016] Step S6: For each non-empty overlapping input region in each matching record, construct the difference query for the symbol return value, observable memory write, and global state, and let the SMT solver determine whether the difference query is satisfied.
[0017] Step S7: After completing the coverage matching and semantic verification in the first direction, swap the source path set and target path set of the two binary programs, and re-execute the candidate sorting, coverage matching, and overlapping region semantic verification; when the global input space is consistent, the path coverage in both directions is complete, and all semantic difference queries are unsatisfactory, output equivalent conclusions; when a clear input space difference, coverage gap, or semantic difference is found, output inequivalent conclusions; when the path artifact is incomplete, the solver returns unknown, or the solution times out, output unknown conclusions and save the corresponding diagnostic information.
[0018] Step S1 sets at least one bounded analysis condition, which includes: exploration depth, number of loop unrolls, upper limit of the number of paths, and time budget; the execution state of the bounded symbol at least records the current instruction address, register mapping, symbol memory, path constraints, execution trajectory, and write event sequence; when encountering a conditional jump, the execution state is copied according to the jump condition and its negation; when encountering a return instruction or reaching the analysis boundary, the path artifact and its integrity state are saved.
[0019] Step S2 generates a path summary for the pre-configured observation range.
[0020] In step S3, when the symmetric difference query cannot be satisfied, the input spaces of the two explored path sets are consistent; when the query can be satisfied, the one-sided input represented by the solution model is saved and the inequivalence is output; when the solver returns unknown or times out, the query status is recorded and unknown is output.
[0021] Step S4 extracts and normalizes an eleven-dimensional feature vector from each path constraint. Each component represents the number of constraint assertions, the number of symbolic variables, the bit width distribution, the comparison operation ratio, the expression nesting depth, the constant type distribution, the variable range span, the number of shift operations, the number of zero expansions, the number of sign expansions, and the number of bit extraction operations. When the highest feature similarity is lower than a preset threshold or the similarity difference between the top two candidates is lower than a preset interval, the execution trajectory overlap is calculated using the basic block correspondence between the two binary program control flow graphs, and the candidates are rearranged. The sorting is used to specify the subsequent coverage query order.
[0022] Step S5 initializes the remaining uncovered areas of the current source path. and the target path coverage set C; for candidate target paths Calculate the new area When N can be satisfied, Add C and update Continue until U is no longer satisfied or candidate paths are exhausted; based on the relationship between the source path and the coverage set, form matching records for one-to-one full coverage, one-to-one source subset coverage, one-to-many full coverage, or one-to-many source subset joint coverage.
[0023] Step S6 applies to regions with non-empty overlapping areas. Path, construct difference query , and When none of the three types of queries can be satisfied, the corresponding overlapping regions are determined to be semantically consistent; when any query can be satisfied, the solution model is saved as a counterexample of semantic difference.
[0024] In step S7, the candidate queue, coverage set, and overlapping input region are regenerated during reverse verification, and the forward path matching record is not reused. When the remaining uncovered regions in both directions are unsatisfactory, and all non-empty overlapping regions in both directions pass the return value, observable memory write, and global state verification, an equivalent conclusion is output. For coverage gaps, semantic differences, unknown solutions, solution timeouts, and incomplete path artifacts, the failure stage, path number, query type, solution status, and available solution model are recorded respectively.
[0025] Compared with the prior art, the present invention has the following beneficial technical effects and significant technical progress:
[0026] 1) It can handle path splitting and path merging caused by compilation optimization through one-to-many path coverage;
[0027] 2) It can perform heuristic sorting by combining path constraint features and execution trajectories, thereby reducing invalid satisfiability model queries.
[0028] 3) It can perform unified verification of return values, observable memory writes, and global state, reducing misjudgments caused by comparing only the final output;
[0029] 4) Able to clearly distinguish the reasons for failure in engineering, such as timeout, incomplete path workpiece, and solver return of unknown. Attached Figure Description
[0030] Figure 1 This is a flowchart of the present invention;
[0031] Figure 2 A schematic diagram of spatial coverage relationship for the path input;
[0032] Figure 3 A schematic diagram showing the summary content of the observable area and path;
[0033] Figure 4 A flowchart for heuristic sorting and alignment of candidate paths;
[0034] Figure 5 A flowchart for constructing and verifying one-to-many coverage;
[0035] Figure 6 This diagram illustrates the path summarization, candidate ranking, one-to-many coverage relationship, and intermediate semantic verification process.
[0036] Figure 7 This is a schematic diagram illustrating the source code and compilation analysis input;
[0037] Figure 8 This is a diagram showing actual assembly instruction fragments and observable differences.
[0038] Figure 9 A schematic diagram of the path artifacts, path constraints, return value summaries, memory states, and global states generated by symbolic execution;
[0039] Figure 10 This diagram illustrates the candidate sorting records, coverage matching records, semantic SMT checks of overlapping regions, and the final verification report. Detailed Implementation
[0040] The overall process of this invention can be summarized as follows: first, a global input space check is performed; then, directional path matching is performed; next, semantic verification is performed; and finally, reverse verification is performed to ensure bidirectional coverage. This layered process retains both the ability for rapid global screening and the ability for local path alignment and semantic proof. The first and second binary programs to be compared are respectively subjected to bounded symbolic execution. The function entry parameters, external inputs, and pre-configured global inputs are modeled as symbolic variables. Register states, symbolic memory states, and path constraints are propagated along the explorable execution path. The execution trajectory, return value, observable write events, and global state upon reaching the end of the path are recorded, forming two sets of path artifacts.
[0041] The present invention will be further described below with reference to the accompanying drawings and specific embodiments. These embodiments are used to explain the present invention and not to limit the scope of protection of the present invention.
[0042] Example 1
[0043] See Figure 1 The implementation method of this embodiment includes the following: the sequential relationship between symbolic execution, path digest, candidate sorting, coverage matching, and semantic verification, as detailed below:
[0044] S1: Extract path constraints and execution trajectory
[0045] The execution module 101 extracts path constraints from each path workpiece. Execution trajectory Symbol return value Observable memory writes and global state , forming a path summary, the Record observable write addresses, write values, and write order during path execution. Record the final value of the pre-configured global observable state at the end of the path.
[0046] See Figure 2 There are four types of coverage relationships: Figure 2 'a' represents a one-to-one complete coverage; Figure 2 b represents a one-to-one source subset cover; Figure 2 c represents a one-to-one joint coverage of multiple source subsets; Figure 2 d represents a one-to-many complete cover. (See diagram) It satisfies the input region reachable by the corresponding path of the solution set. The solid box represents the source path input region, the diagonal filled box represents the target path input region, and the union of multiple target intervals represents one-to-many coverage.
[0047] The symbolic execution module 101 establishes an initial execution state starting from the program entry point and symbolizes external inputs, function parameters, and the analyzed memory region. Integer inputs are represented using bit vectors, while floating-point inputs retain IEEE-754 floating-point semantics. For external input functions such as `scanf`, hook functions are used to write the input to the symbolic memory. Each active state has a unique number. When a path terminates, the path number, parent state number, termination address, and path constraints are recorded, allowing backtracking from the path artifact to the corresponding execution process.
[0048] S2: Generate return value
[0049] See Figure 3 This diagram illustrates the observable region and summary content of the path summary module 102, describing the observable objects in the stack, static storage, and heap areas. It distinguishes between the memory write summary recording write addresses, write values, and write order during execution, and the global state summary recording the final values of global and static variables at the end of the path. The path summary module 102 extracts all path constraints of the first binary program to obtain the global input space. Extract all path constraints from the second binary program to obtain the global input space. And solve the query using Satisfiability Modulus Theory (SMT). Check if there is an input region unique to one side of the two explored path sets.
[0050] During the path digest generation process, the path digest module 102 retains the symbolic expression of the return register at the end of the path in the return value digest. For functions without observable side effects, and An empty digest can be recorded; an empty digest indicates that there are no observable writes or global state updates within the preset observation range, but does not mean that the program has not performed any memory accesses. For functions that have writes, Record the write address and write value in the execution order.
[0051] When the input regions of two paths do not intersect, the system does not submit semantic queries for return values, memory, and global state because the path pair does not have common input. Semantic verification records are only established when the intersection query is satisfied; this conforms to the definition of observation equivalence and avoids wasting solution time between paths with no common input. Global input space checks, local intersection checks, and remaining region checks can all return the solution state, and step S7 distinguishes between explicit counterexamples and unknowns.
[0052] S3: Global Input Space Check
[0053] Check if the global input space is consistent. If it is consistent, proceed to the next step for initial sorting; if it is inconsistent, proceed to step S7 to output inequalities.
[0054] S4: Initial sorting based on path constraint feature vectors
[0055] See Figure 4 The diagram illustrates the heuristic sorting and alignment process for candidate paths, showcasing the feature vector sorting, low-confidence determination, and trajectory rearrangement. The path sorting module 103 extracts feature vectors from the path constraints of the source and target paths, calculates the feature similarity of candidate path combinations, and, when candidate confidence is insufficient (i.e., the candidate confidence does not meet the threshold), uses trajectory overlap to perform heuristic rearrangement, generating an ordered candidate queue. When the candidate confidence meets the threshold, the process proceeds to the next step: constructing path matching records.
[0056] The path sorting module 103 employs a two-stage strategy. The first stage performs lexical and structural normalization on the path constraints, including statistical constraint assertions, symbolic variables, bit width, comparison operations, nesting depth, constant types, interval spans, and shift, expansion, and bit extraction operations, resulting in an eleven-dimensional vector. The second stage only calls the basic block graph correspondence and trajectory overlap calculation for low-confidence candidates. In this embodiment, the high-confidence threshold is 0.8, and the candidate interval threshold is 0.05; these thresholds are used to control whether trajectory reordering is initiated and do not participate in subsequent SMT equivalence proofs.
[0057] S5: Construct path matching records
[0058] See Figure 5 This diagram illustrates the one-to-many coverage construction and bidirectional verification sub-process, showcasing the remaining region refinement, matching record generation, semantic verification, and reverse verification processes. Step S5 in the diagram only constructs the input space matching record.
[0059] In step S6, semantic verification and reverse verification are performed. The coverage matching module 104 initializes the remaining uncovered input area for each source path, visits the target path sequentially according to the ordered candidate queue, calculates the new intersection between the target path and the remaining uncovered area, adds one or more target paths covering the newly added area to the coverage set, and updates the remaining area, thereby constructing a one-to-one or one-to-many path matching record.
[0060] The coverage matching module 104 treats path matching as a problem of refining the partitioning of the input region. Even if a candidate path intersects with the current source path, it will not be added to the matching set if it cannot create a new satisfiable coverage area. Each time a candidate is added, the system updates the remaining region and re-checks its satisfiability; when the remaining region is empty, a complete coverage in the current direction is obtained; when candidates are exhausted but the remaining region is still satisfiable, the solution model for that region is saved as a coverage gap. This design avoids the same target path being counted repeatedly and can directly provide diagnostic examples of uncovered inputs.
[0061] In one-to-many coverage, the union of target paths is only used to interpret the input region of the source path, and does not mean that the return values, write events, or global states of different target paths can be simply concatenated. The system uses the intersection of the source path and each target path as a semantic verification unit, and saves the coverage region and three types of difference query states for each unit. In this way, even if the target program adds boundary branches due to compilation optimization, the consistency of return values can be verified separately in the boundary region.
[0062] S6: Two-way coverage and semantic verification
[0063] The semantic verification module 106 constructs a difference query for symbol return value, observable memory write and global state for each non-empty overlapping input region in each matching record. The SMT solver determines whether the difference query is satisfied. After the first direction of coverage matching and semantic verification is completed, the source path set and target path set of the two binary programs are swapped, and the candidate sorting, coverage matching and overlapping region semantic verification are re-executed.
[0064] The semantic verification module 105 strictly separates path matching records and semantic conclusions. For return values, the system compares symbolic expressions in overlapping regions; for memory writes, the system compares write addresses, write values, and write order; for global states, the system compares the final values of global variables, static variables, and other pre-configured global observable states at the end of the path. For one-to-many records, each target partition is checked independently, and semantic verification cannot be skipped simply because the input union of the target path set covers the source path.
[0065] S7: When the global input space is consistent, the path coverage in both directions is complete, and all semantic difference queries are unsatisfactory, i.e., through bidirectional coverage and semantic verification, an equivalent conclusion is output; when a clear input space difference, coverage gap, or semantic difference is found, i.e., through bidirectional coverage and semantic verification, an unequal conclusion is output; when the path artifact is incomplete, the solver returns an unknown, or the solution times out, an unknown conclusion is output and the corresponding diagnostic information is saved.
[0066] After verification, the result file should include at least: whether the global input space is consistent, whether forward and reverse coverage were successful, whether semantic verification was successful, the number of unknown queries, the matching type, candidate ranking information, and the total execution time. For unequal conclusions, the report should save counterexamples from the input space or semantic difference models; for unknown conclusions, the report should save the failure stage and solver status. This output can be used as a basis for judging the automated process, as well as for manual review and subsequent parameter tuning.
[0067] For floating-point operations and pointer addresses, the system uses symbolic expressions that match the semantics of binary instructions. The observable scope is specified by the analysis configuration and can include global variables, registered heap objects, and the caller-visible stack window. This scope is used to define the objects to be observed; compiler temporary layouts outside the observable scope do not directly affect the final decision, but the relevant configurations will be output with the verification report to ensure that the boundaries of the conclusions are clear.
[0068] In practical engineering implementation, solver status and process conclusions are stored separately. Satisfactory results provide counterexample models, unsatisfactory results serve as corresponding consistency proofs, and unknown and timeout results retain the query name, path pairs, constraint sizes, and solver status. The external basic block matching tool is only used for ordering correction of low-confidence candidates, and tool failures are not disguised as semantic equivalence. The system records specific reasons such as unavailable candidate ordering, missing path artifacts, and SMT solution failures, and uniformly represents the situation as "unknown" because it has not yet been sufficiently proven.
[0069] In reverse verification, the system reuses the path of the second program as the source path, and cannot simply reuse the forward coverage record. This allows the discovery of additional input areas covered by the target program, as well as coverage gaps in the forward direction that are temporarily not exposed due to source subset relationships. Only when the input area coverage in both directions is complete, and all valid overlapping areas in each direction have completed return values, memory writes, and global state checks, does step S7 generate an equivalent conclusion.
[0070] Example 2
[0071] See Figure 6 This figure illustrates the path summary, candidate ranking, one-to-many coverage relationship, and intermediate semantic verification process for the Airy / MAX_Eq function pair in the verification embodiment. The comparison conditions in the figure are based on a readable representation that conforms to bit vector constraints; the actual verification still uses the complete SMT expression.
[0072] To verify the feasibility of this invention, the Airy / MAX_Eq function pair from the working area experimental set was selected as a verification example. This function pair includes a first binary program oldV and a second binary program newV, both used to return the larger value from inputs a and b. The control logic of the first binary program can be readablely represented as "If..." "If b is returned, otherwise a is returned." The control logic of the second binary program can be readablely represented as "If b is returned, then b is returned; otherwise a is returned." "Then return 'a', otherwise return 'b'." This scenario represents a situation where, after negating the condition, swapping branches, or rearranging basic blocks, the program functionality remains unchanged while the path predicate and path order change. The input in the experimental output is a signed integer bit vector; for ease of explanation, the complete SMT-LIB bit vector comparison constraint is abbreviated below as... , and In practice, the original bit vector expression is still used for verification.
[0073] In step S1, the symbolic execution module 101 performs bounded symbolic execution on the two binary programs respectively. The first binary program generates paths O1 and O2: the input region of O1 is readable as... The return value summary is 'a'; the input region of O2 is... The return value summary is b. The second binary program generates paths N1 and N2: the input region of N1 is... The return value summary is b; the input region of N2 is... The return value is a summary. Each path simultaneously retains the actual execution trajectory, complete path constraints, and path end state.
[0074] In step S2, the path summary module 102 extracts return values, observable memory writes, and global state from the four paths. This function only calculates and returns input values, producing no observable memory side effects; therefore, the number of memory writes for all four paths is zero, and there are no final updates to the static storage area, registered heap objects, or the caller-visible stack window. In step S3, the system constructs the union of the input spaces of both sides of the path. The first side union is ( )or( The union of the second side is ( ), )or( The solver examines the symmetric difference between the two unions and finds no valid input region covered by only one side, thus proceeding to the candidate sorting stage.
[0075] In step S4, the path sorting module 103 first extracts an eleven-dimensional feature vector from the path constraints. The system generates a candidate order based on the path constraint features, and can utilize the correspondence between basic blocks and the overlap of execution trajectories to assist in sorting when candidates are difficult to distinguish. The experimentally recorded candidate access order is as follows: and This candidate queue only specifies the order of checks for coverage queries and is not directly used as evidence of equivalence.
[0076] See Figure 6 In step S5, the coverage matching module 104 first processes O1 and sets the remaining region U0 equal to ,Right now The coverage set C is empty. After reading the first candidate N1, a new coverage area is added. and Equivalent to The solution is satisfactory; the system adds N1 to C and removes the region from U0 to obtain the remaining region. Then, N2 is read, and its path constraints exactly cover... The updated remaining region is not satisfied. Therefore, O1 does not form a strict one-to-one relationship with a single target path, but rather generates a one-to-many covering record for the set {N1, N2} corresponding to O1.
[0077] For O2, N2 in the candidate queue is checked first, but and Equivalent to ( )and( The solution result is unsatisfactory, and the system continues to read the next candidate. N1 and O2 are... The regions intersect and cover the entire input region of O2, thus generating a one-to-one source subset coverage record for O2 corresponding to N1. After completing the forward record, the system swaps the source and target sides to perform a reverse check: N1 is jointly covered by the equivalent region of O1 and the strictly greater region of O2, and N2 is covered by O1, so the remaining uncovered regions in both directions are unsatisfactory.
[0078] In step S6, the semantic verification module 105 constructs the difference formula only for the actually satisfyable overlapping regions. In regions O1 and N2, both return 'a'; In the region O1, it returns a, while N1 returns b, but the path constraint implies... Therefore, the return value inequality is still not satisfied; in For regions O2 and N1, both return b. Therefore, the formulas for the difference in return values across the three overlapping regions are not satisfied. For memory writes and global state, the summaries of all four paths are empty, and there are no differences in write address, write value, write order, or observable final state upon path exit.
[0079] Step S7 integrates three types of semantic checks: global input space inspection, forward and reverse coverage records, and overlapping regions, outputting two equivalent binary programs. This embodiment demonstrates that even if the conditional direction and path order change, requiring a source path to be jointly interpreted by parts of multiple target paths, the present invention can still form verifiable equivalent conclusions through candidate sorting, remaining region refinement, and SMT difference query, proving that the technical solution can be practically implemented using existing binary analysis and solver tools.
[0080] See Figure 7 This figure illustrates the source code and compilation analysis inputs of two programs to be compared in the Airy / MAX_Eq verification embodiment. To ensure the verification process has a verifiable basis, two C source programs were actually used in the experiment. The first binary program, oldV, is... Returns b if the condition is met, otherwise returns a; the second binary program newV in The program returns 'a' if the condition is met, and 'b' otherwise. Both programs take 'a' and 'b' as input and return the larger value, but the conditions and the order of the return branches differ. The analysis system does not use the source program text as the equivalence conclusion, but compiles it into separate binary files for comparison.
[0081] See Figure 8 The figure illustrates the actual assembly instruction snippets and observable differences of the snippet function after compilation of the two programs. It shows the assembly snippets of the snippet function extracted by objdump from the two compiled binary files. `oldV` uses `jle` to jump to the branch returning 'a' after the comparison instruction, and then executes the path sequentially back to 'b'; `newV` uses `jge` to jump to the branch returning 'b', and then executes the path sequentially back to 'a'. This demonstrates that the two binary files have structural differences in the source of conditional jump instructions and return registers, and these differences constitute the actual input for path alignment and semantic verification.
[0082] See Figure 9 This diagram illustrates the path artifacts, path constraints, return value summaries, memory states, and global states generated by symbolic execution. The symbolic execution module 101 generates four path artifacts; oldV generates O1 and O2, whose readable path regions are respectively... and newV generates N1 and N2, whose readable path regions are respectively and The diagram simultaneously preserves the actual SMT bit vector constraints and the return value summary. The observable memory writes for all four paths are zero, and the global state updates are also zero. After dissecting the path constraints on both sides, the system performs an SMT check on the symmetry difference of the global input space, which results in UNSAT, thus entering the path sorting stage.
[0083] See Figure 10 The figure illustrates the candidate sorting record, coverage matching record, overlapping region semantic SMT check, and final verification report of this verification embodiment. It shows the actual records for subsequent stages. The path sorting module 103 generates an ordered candidate queue. The candidate order only determines the access order of the coverage query and is not directly used as an equivalence proof. The candidate order of O1 is N1, N2, and the candidate order of O2 is N2, N1. The coverage matching module 104 forms a one-to-many source subset joint coverage record from O1 to {N1, N2} and a one-to-one source subset coverage record from O2 to N1; the reverse direction also completes the coverage.
[0084] Step S6 performs semantic verification on the intersection of the three actual paths. First, in In the input region, both the path O1 of oldV and the path N2 of newV return 'a', therefore the return value difference formula is not satisfied in this region. Secondly, in... In the boundary region, O1 returns a while N1 returns b, but the path constraints in this region have already guaranteed... Therefore, the return value difference formula is still not satisfied. Third, in For the input region, both O2 and N1 return b, and the return value difference formula is also unsatisfactory. Since the function only calculates and returns the input value, and there are no observable memory writes or global state updates for any of the four paths, the memory write digest and global state digest comparisons both pass. The system then repeats the same checks on the reverse path relationships. (Final report...) This indicates that they are considered equivalent. This indicates that the input spaces of the two paths are consistent. and These represent the successful forward and reverse semantic verifications, respectively. The statistics for the entire verification process—4 candidate pairs, 2 alignment pairs, and 26 SMT queries—are as follows, with a total time consumption of 0.332019375 seconds. Therefore, the equivalent conclusions derive from the path constraints, path coverage, and overlapping region semantic checks of the compiled binary, rather than from the pure source code or limited test input.
[0085] This invention provides an automated bounded equivalence verification device deployed as a command-line program, service program, or continuous integration task. Its inputs include: two binary files, an entry function, symbolic input configuration, and bounded analysis parameters; intermediate outputs include: path artifacts, candidate sorting files, matching records, and SMT query logs; and final outputs include: determination result, coverage type, semantic object, counterexample model, and failure stage. Because the comparison is based on binary execution semantics and observable states, the source code, variable naming, or debugging information of the programs to be compared is not required.
[0086] This invention can also be deployed in compiler optimization verification, binary patch confirmation, program migration testing, executable file regression testing, and software supply chain consistency auditing systems. Its inputs are two binary programs to be compared and bounded analysis parameters; the outputs are verifiable equivalence, inequivalence, or unknown conclusions, as well as path coverage records, semantic difference counterexamples, and failure stage information. The method can be executed by a general-purpose computer, server, or continuous integration node, is independent of source code availability, and has clear technical implementation means and industrial applicability.
[0087] The above-described specific implementations can be partially adjusted by those skilled in the art in different ways without departing from the principles and purpose of the present invention. The scope of protection of the present invention is defined by the claims and is not limited to the above-described specific implementations. All implementation schemes within the scope of the claims are bound by the present invention.
Claims
1. A method for automatic verification of bounded equivalence in compiled and optimized binary programs, characterized in that, The verification method includes the following steps: Step S1: Perform bounded symbolic execution on the first binary program and the second binary program to be compared respectively. Model the function entry parameters, external inputs and pre-configured global inputs as symbolic variables. Propagate the register state, symbolic memory state and path constraints along the explorable execution path. Record the execution trajectory, return value, observable write events and global state at the end of the path to form two sets of path artifacts. Step S2: Extract path constraints from each path's workpiece Execution trajectory Symbol return value Observable memory writes and global state , forming a path summary, the Record observable write addresses, write values, and write order during path execution. Record the final value of the pre-configured global observable state at the end of the path; Step S3: Extract all path constraints from the first binary program to obtain the global input space. Extracting all path constraints from the second binary program yields the global input space. And solve the query using Satisfiability Modulus Theory (SMT). Check if there is an input region unique to one side of the two explored path sets; Step S4: After passing the global input space check, extract feature vectors from the path constraints of the source path and the target path, calculate the feature similarity of the candidate path combination, and perform heuristic rearrangement based on the execution trajectory overlap when the candidate confidence is insufficient, to generate an ordered candidate queue. Step S5: Initialize the remaining uncovered input area for each source path, visit the target path in the order of the candidate queue, calculate the new intersection between the target path and the remaining uncovered area, add one or more target paths that cover the new area to the coverage set, and update the remaining area to build a one-to-one or one-to-many path matching record. Step S6: For each non-empty overlapping input region in each matching record, construct the difference query for the symbol return value, observable memory write, and global state, and let the SMT solver determine whether the difference query is satisfied; Step S7: After completing the coverage matching and semantic verification in the first direction, swap the source path set and target path set of the two binary programs, and re-execute the candidate sorting, coverage matching, and overlapping region semantic verification; when the global input space is consistent, the path coverage in both directions is complete, and all semantic difference queries are unsatisfactory, output equivalent conclusions; when a clear input space difference, coverage gap, or semantic difference is found, output inequivalent conclusions; when the path artifact is incomplete, the solver returns unknown, or the solution times out, output unknown conclusions and save the corresponding diagnostic information.
2. The automatic verification method for bounded equivalence of compiled and optimized binary programs according to claim 1, characterized in that, Step S1 sets at least one bounded analysis condition, which includes: exploration depth, number of loop unrolls, upper limit of the number of paths, and time budget; the execution state of the bounded symbol at least records the current instruction address, register mapping, symbol memory, path constraints, execution trajectory, and write event sequence; when encountering a conditional jump, the execution state is copied according to the jump condition and its negation; when encountering a return instruction or reaching the analysis boundary, the path artifact and its integrity state are saved.
3. The automatic verification method for bounded equivalence of compiled and optimized binary programs according to claim 1, characterized in that, Step S2 generates a path summary for the pre-configured observation range.
4. The automatic verification method for bounded equivalence of compiled and optimized binary programs according to claim 1, characterized in that, In step S3, when the symmetric difference query cannot be satisfied, the input spaces of the two explored path sets are consistent; when the query can be satisfied, the one-sided input represented by the solution model is saved and the inequivalence is output; when the solver returns unknown or times out, the query status is recorded and unknown is output.
5. The automatic verification method for bounded equivalence of compiled and optimized binary programs according to claim 1, characterized in that, Step S4 extracts and normalizes an eleven-dimensional feature vector from each path constraint. Each component represents the number of constraint assertions, the number of symbolic variables, the bit width distribution, the comparison operation ratio, the expression nesting depth, the constant type distribution, the variable range span, the number of shift operations, the number of zero expansions, the number of sign expansions, and the number of bit extraction operations. When the highest feature similarity is lower than a preset threshold or the similarity difference between the top two candidates is lower than a preset interval, the execution trajectory overlap is calculated using the basic block correspondence between the two binary program control flow graphs, and the candidates are rearranged. The sorting is used to specify the subsequent coverage query order.
6. The automatic verification method for bounded equivalence of compiled and optimized binary programs according to claim 1, characterized in that, Step S5 initializes the remaining uncovered areas of the current source path. and the target path coverage set C; for candidate target paths Calculate the new area When N can be satisfied, Add C and update Continue until U is no longer satisfied or candidate paths are exhausted; based on the relationship between the source path and the coverage set, form matching records for one-to-one full coverage, one-to-one source subset coverage, one-to-many full coverage, or one-to-many source subset joint coverage.
7. The automatic verification method for bounded equivalence of compiled and optimized binary programs according to claim 1, characterized in that, Step S6 applies to regions with non-empty overlapping areas. Path, construct difference query , and When none of the three types of queries can be satisfied, the corresponding overlapping regions are determined to be semantically consistent; when any query can be satisfied, the solution model is saved as a counterexample of semantic difference.
8. The automatic verification method for bounded equivalence of compiled and optimized binary programs according to claim 1, characterized in that, In step S7, the candidate queue, coverage set, and overlapping input region are regenerated during reverse verification, and the forward path matching record is not reused. When the remaining uncovered regions in both directions are unsatisfactory, and all non-empty overlapping regions in both directions pass the return value, observable memory write, and global state verification, an equivalent conclusion is output. For coverage gaps, semantic differences, unknown solutions, solution timeouts, and incomplete path artifacts, the failure stage, path number, query type, solution status, and available solution model are recorded respectively.
