trailofbits / trailofbits/CoBRA

Create Python Bindings

Open
#17 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
343
Forks
18
PR merge metrics
No merged PRs in 30d

Description

Summary

Create a python module with bindings into CoBRA that can be published to PyPi. Introduce: Python mappings into CoBRA's existing Exprs (using nanobind), expose some functions to allow for parsing strings to and from Exprs and introduce a reducer function that uses CoBRA to simplify expressions.

Architecture

lib/bindings/python
    CobraPython.cpp           - All code required to expose functions and classes to python
    CobraPython.h
    PythonInterface.cpp       - Code that implements all the bindings (i.e. str <-> expr ) 
    PythonInterface.h 
    pyproject.toml            - Configuration required for pypi deployment 

Python interface

  • PyExpr class that mimics that of Expr.h to make conversion trivial, we want to hide the specifics of requiring a seprate list to store the variable for equation re-construction hence we need a minimal wrapper around the Expr class.

  • to_expr(expr_string, max_vars=16) function to converts a provided string to an Expr in a similar manor to the cli's ParseToAst (This feels like something that should be re-factored into some form of shared library instead of being just in the CLI).

  • reduce(expr, bitwidth=64) runs the reduction on the expression, we can have it accept a string or a Expr to avoid creating code that looks like reduce(to_expr(foo)).

  • verify(original_expr, new_expr) using an optional dependency of Z3 (If were not forcing users to compile from source on pip install we should be ok here anyway?).

  • Some misc functions to interact with and modify an Expr.

Tasks

  • Update CMAKE to support building the python lib
  • Investigate the z3 and other general requirements for pypi distribution
  • Implement python Expr
  • Implement conversions to and from pythons Expr to CoBRAs
  • Create reduction and verification interface
  • Add some methods and attributes to Expr to make them easier to work with
  • Test, test and test

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing Expr.h and the CLI's ParseToAst implementation, then compare them with the proposed files under lib/bindings/python. Define the Python Expr, conversion, reduction, verification, CMake, and PyPI requirements before implementing them. Done means the bindings build, expose the listed interfaces, and include tests for the Python API.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
api, developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.