Skip to content

FEATURE/Add: Full Continuous Differential-Linear Model integration and CP evaluation#440

Draft
rony-ramos wants to merge 5 commits into
developfrom
feature/add-cp-continuous-model-tests
Draft

FEATURE/Add: Full Continuous Differential-Linear Model integration and CP evaluation#440
rony-ramos wants to merge 5 commits into
developfrom
feature/add-cp-continuous-model-tests

Conversation

@rony-ramos
Copy link
Copy Markdown
Collaborator

Overview
This PR introduces the integration of the Continuous Differential-Linear Model into the CP solver pipeline. It enables the evaluation of differential-linear trails (e.g., Speck 9-rounds) by linking a differential top part, a continuous-correlation middle part, and a linear bottom part, based on the mathematical formulation from [BGGMP2023].

Current Implementation Approach:

  1. Canonical Border Semantics: The connection between the continuous middle part and the linear bottom part (_continuous_middle_to_bottom_connecting_constraints) is implemented per canonical border bit. This computes the differential-linear correlation across the boundary and maps fan-outs.
  2. Piecewise Log2 Approximation: The CP model utilizes a piecewise linear log2 approximation to translate the floating-point correlations derived from the continuous part into additive integer weights for the CP solver.
  3. Solver & API Extensibility: - Added optimization_objective injection within build_xor_differential_linear_model, allowing the solver to bypass default satisfying statements and minimize the correlation_log2_approximation.
    • Added the get_fixed_variable_from_hex utility to standardize variable fixing across test suites.
  4. Integration Validation (Speck 9-Rounds): - Added an end-to-end integration test (test_differential_linear_trail_continuous_middle_9_rounds_speck_table4_full_model_float_search_scip) that builds the model and invokes the SCIP solver (float_search) to validate the total probability against the paper's expected values.

How to test

Verify the standalone continuous models and the fully integrated split models:

# 1. Run the standalone continuous model tests
pytest -v tests/unit/cipher_modules/models/cp/mzn_models/mzn_differential_linear_continuous_model_test.py

# 2. Run the integrated differential-linear model tests (includes the Speck 9-round validation)
pytest -v tests/unit/cipher_modules/models/cp/mzn_models/mzn_differential_linear_model_test.py

…ound test

- Translated connection constraints from middle to bottom to use a canonical meaning per border bit, preventing mathematical errors from fan-out logic.
- Adapted the integrated model to properly reflect standalone continuous boundary semantics.
- Updated the differential linear model test to use float_search and explicitly minimize the correlation log2 approximation.
- Improved solver output parsing to iterate over all solutions and accurately fetch the optimal correlation, avoiding premature factible states.
- Added get_fixed_variable_from_hex utility method to MznDifferentialLinearModel to standardize and simplify fixing component bits from hex strings.
- Added optimization_objective parameter to build_xor_differential_linear_model to allow natively injecting custom solve statements (e.g., minimize correlation_log2_approximation) without manual constraint string manipulation.
- Refactored mzn_differential_linear_model_test.py to use these new clean APIs, removing duplicated hex parsing helpers and hacky array replacements.
- Replace direct float equality checks with math.isclose() in continuous predicates
- Extract complex loop logic into helper functions in mzn_differential_linear_model.py
  to reduce cognitive complexity (border constraints, output parsing)
- Simplify intermediate output pinning iteration and remove unused 'pin_bit'
@rony-ramos rony-ramos force-pushed the feature/add-cp-continuous-model-tests branch from 0ede228 to 30f48b8 Compare April 23, 2026 16:26
…linear wiring constraints

Co-authored-by: Copilot <copilot@github.com>
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Collaborator

@juaninf juaninf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should include more tests for many more ARX ciphers. LEA, ChaCha, Salsa, HIGHT...Every distinguisher must be checked experimentally using the checkers module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants