Repository: angr/claripy

Issue:
New versions of claripy cannot convert z3.SignExt properly and introduce BVNone
### Description

```
>>> import claripy
>>> claripy.backends.z3._abstract(z3.SignExt(32,z3.BitVec('x',32)))
<BVNone SignExt(32, x)>
>>> claripy.__version__
'9.2.143'
```
vs.
```
>>> claripy.backends.z3._abstract(z3.SignExt(32,z3.BitVec('x',32)))
<BV64 SignExt(32, x)>
>>> claripy.__version__
(9, 0, 'gitrolling')
```
The creation of a BVNone is simply not warranted.

### Steps to reproduce the bug

_No response_

### Environment

_No response_

### Additional context

_No response_

Discussion:

Solution patch:
diff --git a/claripy/backends/backend_z3.py b/claripy/backends/backend_z3.py
index 3eb193bc6..8f66cb968 100644
--- a/claripy/backends/backend_z3.py
+++ b/claripy/backends/backend_z3.py
@@ -546,6 +546,12 @@ def _abstract_internal(self, ctx, ast, split_on=None):
         if op_name == "fpToSBV":
             bv_size = z3.Z3_get_bv_sort_size(ctx, z3_sort)
             return claripy.fpToSBV(*children, bv_size)
+        if op_name == "SignExt":
+            bv_size = z3.Z3_get_decl_int_parameter(ctx, decl, 0)
+            return claripy.SignExt(bv_size, children[0])
+        if op_name == "ZeroExt":
+            bv_size = z3.Z3_get_decl_int_parameter(ctx, decl, 0)
+            return claripy.ZeroExt(bv_size, children[0])
 
         if op_name == "UNINTERPRETED" and num_args == 0:  # symbolic value
             symbol_name = _z3_decl_name_str(ctx, decl)


Test patch:
diff --git a/tests/test_bv.py b/tests/test_bv.py
index dd81d4cc4..cafdb26b8 100644
--- a/tests/test_bv.py
+++ b/tests/test_bv.py
@@ -126,6 +126,20 @@ def _check_exception(va, vb, op):
         _check_exception(a, b, "SMod")
         _check_exception(a, b, "SDiv")
 
+    def test_signext_convert(self):
+        x = claripy.BVS("x", 32)
+        y = claripy.SignExt(32, x)
+        roundtripped = claripy.backends.z3._abstract(claripy.backends.z3.convert(y))
+        print(roundtripped)
+        assert roundtripped.length == 64
+
+    def test_zeroext_convert(self):
+        x = claripy.BVS("x", 32)
+        y = claripy.ZeroExt(32, x)
+        roundtripped = claripy.backends.z3._abstract(claripy.backends.z3.convert(y))
+        print(roundtripped)
+        assert roundtripped.length == 64
+
     def test_type_errors(self):
         self.assertRaises(TypeError, lambda: claripy.BVV(None))
         self.assertRaises(TypeError, lambda: claripy.BVV(3))