Skip to content

Commit

Permalink
Migrate to current PyO3 version (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmadawg authored Dec 14, 2024
1 parent d1296a2 commit 57892e7
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 43 deletions.
20 changes: 10 additions & 10 deletions tools/garaga_rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tools/garaga_rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ wasm-bindgen-test = "0.3"

# assumes python dependencies when not on wasm32-unknown-unknown
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
pyo3 = { version = "0.22", features = ["extension-module", "num-bigint"] }
pyo3 = { version = "0.23", features = ["extension-module", "num-bigint"] }

# assumes wasm dependencies when on wasm32-unknown-unknown
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2"

[dependencies]
pyo3 = { version = "0.22", features = ["extension-module", "num-bigint"], optional = true }
pyo3 = { version = "0.23", features = ["extension-module", "num-bigint"], optional = true }
wasm-bindgen = { version = "0.2", optional = true }
num-bigint = "0.4"
num-traits = "0.2"
Expand Down
7 changes: 5 additions & 2 deletions tools/garaga_rs/src/python_bindings/ecip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ pub fn zk_ecip_hint(
let v = ecip::core::zk_ecip_hint(list_values, list_scalars, curve_id)
.map_err(PyErr::new::<pyo3::exceptions::PyValueError, _>)?;

let py_list = PyList::new_bound(py, v.into_iter().map(|x| PyList::new_bound(py, x)));

let inner_lists: Vec<_> = v
.into_iter()
.map(|x| PyList::new(py, x))
.collect::<PyResult<_>>()?;
let py_list = PyList::new(py, inner_lists)?;
Ok(py_list.into())
}
4 changes: 3 additions & 1 deletion tools/garaga_rs/src/python_bindings/extf_mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ where
.into_iter()
.map(|x| BigUint::from_bytes_be(&x.to_bytes_be()))
.collect::<Vec<BigUint>>();
let py_tuple = PyTuple::new_bound(py, [PyList::new_bound(py, q), PyList::new_bound(py, r)]);
let q_list = PyList::new(py, q)?;
let r_list = PyList::new(py, r)?;
let py_tuple = PyTuple::new(py, [q_list, r_list])?;
Ok(py_tuple.into())
}
6 changes: 4 additions & 2 deletions tools/garaga_rs/src/python_bindings/final_exp_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub fn get_final_exp_witness(
let f_11: BigUint = py_list.get_item(11)?.extract()?;
let f = [f_0, f_1, f_2, f_3, f_4, f_5, f_6, f_7, f_8, f_9, f_10, f_11];
let (c, wi) = crate::pairing::final_exp_witness::get_final_exp_witness(curve_id, f);
let py_tuple = PyTuple::new_bound(py, [PyList::new_bound(py, c), PyList::new_bound(py, wi)]);
Ok(py_tuple.into())
let c_list = PyList::new(py, c)?;
let wi_list = PyList::new(py, wi)?;
let py_tuple = PyTuple::new(py, [c_list, wi_list])?;
Ok(Py::from(py_tuple))
}
16 changes: 8 additions & 8 deletions tools/garaga_rs/src/python_bindings/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn g2_add(
Fq2::new(Fq::from(b_2), Fq::from(b_3)),
);
let c: G2Affine = (a + b).into();
let py_tuple = PyTuple::new_bound(
let py_tuple = PyTuple::new(
py,
[
BigUint::from(c.x.c0.into_bigint()),
Expand All @@ -36,7 +36,7 @@ pub fn g2_add(
BigUint::from(c.y.c1.into_bigint()),
],
);
return Ok(py_tuple.into());
return Ok(py_tuple?.into_any().into());
}

if curve_id == CURVE_BLS12_381 {
Expand All @@ -50,7 +50,7 @@ pub fn g2_add(
Fq2::new(Fq::from(b_2), Fq::from(b_3)),
);
let c: G2Affine = (a + b).into();
let py_tuple = PyTuple::new_bound(
let py_tuple = PyTuple::new(
py,
[
BigUint::from(c.x.c0.into_bigint()),
Expand All @@ -59,7 +59,7 @@ pub fn g2_add(
BigUint::from(c.y.c1.into_bigint()),
],
);
return Ok(py_tuple.into());
return Ok(py_tuple?.into());
}

panic!("Curve ID {} not supported", curve_id);
Expand All @@ -85,7 +85,7 @@ pub fn g2_scalar_mul(
Fq2::new(Fq::from(a_2), Fq::from(a_3)),
);
let c: G2Affine = a.mul_bigint(k.to_u64_digits()).into();
let py_tuple = PyTuple::new_bound(
let py_tuple = PyTuple::new(
py,
[
BigUint::from(c.x.c0.into_bigint()),
Expand All @@ -94,7 +94,7 @@ pub fn g2_scalar_mul(
BigUint::from(c.y.c1.into_bigint()),
],
);
return Ok(py_tuple.into());
return Ok(py_tuple?.into());
}

if curve_id == CURVE_BLS12_381 {
Expand All @@ -104,7 +104,7 @@ pub fn g2_scalar_mul(
Fq2::new(Fq::from(a_2), Fq::from(a_3)),
);
let c: G2Affine = a.mul_bigint(k.to_u64_digits()).into();
let py_tuple = PyTuple::new_bound(
let py_tuple = PyTuple::new(
py,
[
BigUint::from(c.x.c0.into_bigint()),
Expand All @@ -113,7 +113,7 @@ pub fn g2_scalar_mul(
BigUint::from(c.y.c1.into_bigint()),
],
);
return Ok(py_tuple.into());
return Ok(py_tuple?.into());
}

panic!("Curve ID {} not supported", curve_id);
Expand Down
4 changes: 2 additions & 2 deletions tools/garaga_rs/src/python_bindings/groth16_calldata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ pub fn get_groth16_calldata(
)
.map_err(PyErr::new::<pyo3::exceptions::PyValueError, _>)?;

let py_list = PyList::new_bound(py, result);
Ok(py_list.into())
let py_list = PyList::new(py, result);
Ok(py_list?.into())
}
7 changes: 3 additions & 4 deletions tools/garaga_rs/src/python_bindings/hades_permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ pub fn hades_permutation(

PoseidonCairoStark252::hades_permutation(&mut state);

let py_tuple = PyTuple::new_bound(
let py_tuple = PyTuple::new(
py,
state.iter().map(|fe| {
let fe_bytes = fe.to_bytes_be();
PyBytes::new_bound(py, &fe_bytes)
PyBytes::new(py, &fe_bytes)
}),
);

Ok(py_tuple.into())
Ok(py_tuple?.into())
}
4 changes: 2 additions & 2 deletions tools/garaga_rs/src/python_bindings/mpc_calldata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ pub fn mpc_calldata_builder(
curve_id, &values1, n_fixed_g2, &values2,
)
.map_err(PyErr::new::<pyo3::exceptions::PyValueError, _>)?;
let py_list = PyList::new_bound(py, result);
Ok(py_list.into())
let py_list = PyList::new(py, result);
Ok(py_list?.into())
}
4 changes: 2 additions & 2 deletions tools/garaga_rs/src/python_bindings/msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ pub fn msm_calldata_builder(
risc0_mode,
)
.map_err(PyErr::new::<pyo3::exceptions::PyValueError, _>)?;
let py_list = PyList::new_bound(py, result);
Ok(py_list.into())
let py_list = PyList::new(py, result);
Ok(py_list?.into())
}
16 changes: 8 additions & 8 deletions tools/garaga_rs/src/python_bindings/pairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub fn multi_pairing(
BigUint::from(v.c1.c2.c1.into_bigint()),
]
}
let py_list = PyList::new_bound(py, to(c.0));
return Ok(py_list.into());
let py_list = PyList::new(py, to(c.0));
return Ok(py_list?.into());
}

if curve_id == CURVE_BLS12_381 {
Expand Down Expand Up @@ -84,8 +84,8 @@ pub fn multi_pairing(
BigUint::from(v.c1.c2.c1.into_bigint()),
]
}
let py_list = PyList::new_bound(py, to(c.0));
return Ok(py_list.into());
let py_list = PyList::new(py, to(c.0));
return Ok(py_list?.into());
}

panic!("Curve ID {} not supported", curve_id);
Expand Down Expand Up @@ -135,8 +135,8 @@ pub fn multi_miller_loop(
BigUint::from(v.c1.c2.c1.into_bigint()),
]
}
let py_list = PyList::new_bound(py, to(c.0));
return Ok(py_list.into());
let py_list = PyList::new(py, to(c.0));
return Ok(py_list?.into());
}

if curve_id == CURVE_BLS12_381 {
Expand Down Expand Up @@ -175,8 +175,8 @@ pub fn multi_miller_loop(
BigUint::from(v.c1.c2.c1.into_bigint()),
]
}
let py_list = PyList::new_bound(py, to(c.0));
return Ok(py_list.into());
let py_list = PyList::new(py, to(c.0));
return Ok(py_list?.into());
}

panic!("Curve ID {} not supported", curve_id);
Expand Down

0 comments on commit 57892e7

Please sign in to comment.