trailofbits / trailofbits/CoBRA
Create Python Bindings
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
-
PyExprclass that mimics that ofExpr.hto 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 anExprin a similar manor to the cli'sParseToAst(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 aExprto avoid creating code that looks likereduce(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
Exprto CoBRAs - Create reduction and verification interface
- Add some methods and attributes to
Exprto make them easier to work with - Test, test and test
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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