From 57892e739bcdfdb2a232f580796b762dea096035 Mon Sep 17 00:00:00 2001 From: Brandon <121488291+sigmadawg@users.noreply.github.com> Date: Sat, 14 Dec 2024 14:26:23 +0530 Subject: [PATCH] Migrate to current PyO3 version (#275) --- tools/garaga_rs/Cargo.lock | 20 +++++++++---------- tools/garaga_rs/Cargo.toml | 4 ++-- tools/garaga_rs/src/python_bindings/ecip.rs | 7 +++++-- .../garaga_rs/src/python_bindings/extf_mul.rs | 4 +++- .../src/python_bindings/final_exp_witness.rs | 6 ++++-- tools/garaga_rs/src/python_bindings/g2.rs | 16 +++++++-------- .../src/python_bindings/groth16_calldata.rs | 4 ++-- .../src/python_bindings/hades_permutation.rs | 7 +++---- .../src/python_bindings/mpc_calldata.rs | 4 ++-- tools/garaga_rs/src/python_bindings/msm.rs | 4 ++-- .../garaga_rs/src/python_bindings/pairing.rs | 16 +++++++-------- 11 files changed, 49 insertions(+), 43 deletions(-) diff --git a/tools/garaga_rs/Cargo.lock b/tools/garaga_rs/Cargo.lock index f8bd1600..9a614cf8 100644 --- a/tools/garaga_rs/Cargo.lock +++ b/tools/garaga_rs/Cargo.lock @@ -487,9 +487,9 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.22.5" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d922163ba1f79c04bc49073ba7b32fd5a8d3b76a87c955921234b8e77333c51" +checksum = "e484fd2c8b4cb67ab05a318f1fd6fa8f199fcc30819f08f07d200809dba26c15" dependencies = [ "cfg-if", "indoc", @@ -506,9 +506,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.22.5" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc38c5feeb496c8321091edf3d63e9a6829eab4b863b4a6a65f26f3e9cc6b179" +checksum = "dc0e0469a84f208e20044b98965e1561028180219e35352a2afaf2b942beff3b" dependencies = [ "once_cell", "target-lexicon", @@ -516,9 +516,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.22.5" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94845622d88ae274d2729fcefc850e63d7a3ddff5e3ce11bd88486db9f1d357d" +checksum = "eb1547a7f9966f6f1a0f0227564a9945fe36b90da5a93b3933fc3dc03fae372d" dependencies = [ "libc", "pyo3-build-config", @@ -526,9 +526,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.22.5" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e655aad15e09b94ffdb3ce3d217acf652e26bbc37697ef012f5e5e348c716e5e" +checksum = "fdb6da8ec6fa5cedd1626c886fc8749bdcbb09424a86461eb8cdf096b7c33257" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -538,9 +538,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.22.5" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1e3f09eecd94618f60a455a23def79f79eba4dc561a97324bf9ac8c6df30ce" +checksum = "38a385202ff5a92791168b1136afae5059d3ac118457bb7bc304c197c2d33e7d" dependencies = [ "heck", "proc-macro2", diff --git a/tools/garaga_rs/Cargo.toml b/tools/garaga_rs/Cargo.toml index 02f12286..2a3f9148 100644 --- a/tools/garaga_rs/Cargo.toml +++ b/tools/garaga_rs/Cargo.toml @@ -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" diff --git a/tools/garaga_rs/src/python_bindings/ecip.rs b/tools/garaga_rs/src/python_bindings/ecip.rs index 3dbe8665..34ecf8ec 100644 --- a/tools/garaga_rs/src/python_bindings/ecip.rs +++ b/tools/garaga_rs/src/python_bindings/ecip.rs @@ -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::)?; - 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::>()?; + let py_list = PyList::new(py, inner_lists)?; Ok(py_list.into()) } diff --git a/tools/garaga_rs/src/python_bindings/extf_mul.rs b/tools/garaga_rs/src/python_bindings/extf_mul.rs index cc2abac3..358b052d 100644 --- a/tools/garaga_rs/src/python_bindings/extf_mul.rs +++ b/tools/garaga_rs/src/python_bindings/extf_mul.rs @@ -53,6 +53,8 @@ where .into_iter() .map(|x| BigUint::from_bytes_be(&x.to_bytes_be())) .collect::>(); - 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()) } diff --git a/tools/garaga_rs/src/python_bindings/final_exp_witness.rs b/tools/garaga_rs/src/python_bindings/final_exp_witness.rs index 05626ff8..9495280b 100644 --- a/tools/garaga_rs/src/python_bindings/final_exp_witness.rs +++ b/tools/garaga_rs/src/python_bindings/final_exp_witness.rs @@ -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)) } diff --git a/tools/garaga_rs/src/python_bindings/g2.rs b/tools/garaga_rs/src/python_bindings/g2.rs index 6c43b098..a6bc4328 100644 --- a/tools/garaga_rs/src/python_bindings/g2.rs +++ b/tools/garaga_rs/src/python_bindings/g2.rs @@ -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()), @@ -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 { @@ -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()), @@ -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); @@ -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()), @@ -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 { @@ -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()), @@ -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); diff --git a/tools/garaga_rs/src/python_bindings/groth16_calldata.rs b/tools/garaga_rs/src/python_bindings/groth16_calldata.rs index 858c8b09..ba3e8314 100644 --- a/tools/garaga_rs/src/python_bindings/groth16_calldata.rs +++ b/tools/garaga_rs/src/python_bindings/groth16_calldata.rs @@ -35,6 +35,6 @@ pub fn get_groth16_calldata( ) .map_err(PyErr::new::)?; - let py_list = PyList::new_bound(py, result); - Ok(py_list.into()) + let py_list = PyList::new(py, result); + Ok(py_list?.into()) } diff --git a/tools/garaga_rs/src/python_bindings/hades_permutation.rs b/tools/garaga_rs/src/python_bindings/hades_permutation.rs index e4534952..4386254c 100644 --- a/tools/garaga_rs/src/python_bindings/hades_permutation.rs +++ b/tools/garaga_rs/src/python_bindings/hades_permutation.rs @@ -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()) } diff --git a/tools/garaga_rs/src/python_bindings/mpc_calldata.rs b/tools/garaga_rs/src/python_bindings/mpc_calldata.rs index 643b18d3..1a8f0144 100644 --- a/tools/garaga_rs/src/python_bindings/mpc_calldata.rs +++ b/tools/garaga_rs/src/python_bindings/mpc_calldata.rs @@ -20,6 +20,6 @@ pub fn mpc_calldata_builder( curve_id, &values1, n_fixed_g2, &values2, ) .map_err(PyErr::new::)?; - let py_list = PyList::new_bound(py, result); - Ok(py_list.into()) + let py_list = PyList::new(py, result); + Ok(py_list?.into()) } diff --git a/tools/garaga_rs/src/python_bindings/msm.rs b/tools/garaga_rs/src/python_bindings/msm.rs index ef26ea02..c40896c2 100644 --- a/tools/garaga_rs/src/python_bindings/msm.rs +++ b/tools/garaga_rs/src/python_bindings/msm.rs @@ -30,6 +30,6 @@ pub fn msm_calldata_builder( risc0_mode, ) .map_err(PyErr::new::)?; - let py_list = PyList::new_bound(py, result); - Ok(py_list.into()) + let py_list = PyList::new(py, result); + Ok(py_list?.into()) } diff --git a/tools/garaga_rs/src/python_bindings/pairing.rs b/tools/garaga_rs/src/python_bindings/pairing.rs index fcb1e518..de961a0e 100644 --- a/tools/garaga_rs/src/python_bindings/pairing.rs +++ b/tools/garaga_rs/src/python_bindings/pairing.rs @@ -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 { @@ -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); @@ -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 { @@ -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);