瀏覽代碼

sdk-py: Minor cleanups

parazyd 3 年之前
父節點
當前提交
4824c84cb5

+ 120 - 28
Cargo.lock

@@ -173,9 +173,9 @@ checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545"
 
 [[package]]
 name = "arrayvec"
-version = "0.7.2"
+version = "0.7.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
+checksum = "8868f09ff8cea88b079da74ae569d9b8c62a23c68c746240b704ee6f7525c89c"
 
 [[package]]
 name = "async-attributes"
@@ -1125,14 +1125,14 @@ dependencies = [
 
 [[package]]
 name = "crossbeam-epoch"
-version = "0.9.14"
+version = "0.9.15"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695"
+checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7"
 dependencies = [
  "autocfg",
  "cfg-if",
  "crossbeam-utils",
- "memoffset",
+ "memoffset 0.9.0",
  "scopeguard",
 ]
 
@@ -1148,9 +1148,9 @@ dependencies = [
 
 [[package]]
 name = "crossbeam-utils"
-version = "0.8.15"
+version = "0.8.16"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b"
+checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
 dependencies = [
  "cfg-if",
 ]
@@ -1173,9 +1173,9 @@ dependencies = [
 
 [[package]]
 name = "crossterm_winapi"
-version = "0.9.0"
+version = "0.9.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c"
+checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b"
 dependencies = [
  "winapi",
 ]
@@ -1469,6 +1469,17 @@ dependencies = [
  "thiserror",
 ]
 
+[[package]]
+name = "darkfi-sdk-py"
+version = "0.4.1"
+dependencies = [
+ "darkfi",
+ "darkfi-sdk",
+ "halo2_gadgets",
+ "pyo3",
+ "rand",
+]
+
 [[package]]
 name = "darkfi-serial"
 version = "0.4.1"
@@ -2733,6 +2744,12 @@ dependencies = [
  "unicode-width",
 ]
 
+[[package]]
+name = "indoc"
+version = "1.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306"
+
 [[package]]
 name = "inout"
 version = "0.1.3"
@@ -2887,9 +2904,9 @@ checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e"
 
 [[package]]
 name = "js-sys"
-version = "0.3.63"
+version = "0.3.64"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2f37a4a5928311ac501dee68b3c7613a1037d0edb30c8e5427bd832d55d1b790"
+checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a"
 dependencies = [
  "wasm-bindgen",
 ]
@@ -3064,6 +3081,15 @@ dependencies = [
  "autocfg",
 ]
 
+[[package]]
+name = "memoffset"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
+dependencies = [
+ "autocfg",
+]
+
 [[package]]
 name = "minimal-lexical"
 version = "0.2.1"
@@ -3727,6 +3753,66 @@ dependencies = [
  "unicase",
 ]
 
+[[package]]
+name = "pyo3"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cffef52f74ec3b1a1baf295d9b8fcc3070327aefc39a6d00656b13c1d0b8885c"
+dependencies = [
+ "cfg-if",
+ "indoc",
+ "libc",
+ "memoffset 0.9.0",
+ "parking_lot 0.12.1",
+ "pyo3-build-config",
+ "pyo3-ffi",
+ "pyo3-macros",
+ "unindent",
+]
+
+[[package]]
+name = "pyo3-build-config"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "713eccf888fb05f1a96eb78c0dbc51907fee42b3377272dc902eb38985f418d5"
+dependencies = [
+ "once_cell",
+ "target-lexicon",
+]
+
+[[package]]
+name = "pyo3-ffi"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5b2ecbdcfb01cbbf56e179ce969a048fd7305a66d4cdf3303e0da09d69afe4c3"
+dependencies = [
+ "libc",
+ "pyo3-build-config",
+]
+
+[[package]]
+name = "pyo3-macros"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b78fdc0899f2ea781c463679b20cb08af9247febc8d052de941951024cd8aea0"
+dependencies = [
+ "proc-macro2",
+ "pyo3-macros-backend",
+ "quote",
+ "syn 1.0.109",
+]
+
+[[package]]
+name = "pyo3-macros-backend"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "60da7b84f1227c3e2fe7593505de274dcf4c8928b4e0a1c23d551a14e4e80a0f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+]
+
 [[package]]
 name = "quick-error"
 version = "1.2.3"
@@ -5083,6 +5169,12 @@ version = "0.1.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e"
 
+[[package]]
+name = "unindent"
+version = "0.1.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c"
+
 [[package]]
 name = "universal-hash"
 version = "0.5.1"
@@ -5125,9 +5217,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
 
 [[package]]
 name = "uuid"
-version = "1.3.3"
+version = "1.3.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "345444e32442451b267fc254ae85a209c64be56d2890e601a0c37ff0c3c5ecd2"
+checksum = "0fa2982af2eec27de306107c027578ff7f423d65f7250e40ce0fea8f45248b81"
 
 [[package]]
 name = "value-bag"
@@ -5206,9 +5298,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
 
 [[package]]
 name = "wasm-bindgen"
-version = "0.2.86"
+version = "0.2.87"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73"
+checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
 dependencies = [
  "cfg-if",
  "wasm-bindgen-macro",
@@ -5216,9 +5308,9 @@ dependencies = [
 
 [[package]]
 name = "wasm-bindgen-backend"
-version = "0.2.86"
+version = "0.2.87"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "19b04bc93f9d6bdee709f6bd2118f57dd6679cf1176a1af464fca3ab0d66d8fb"
+checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"
 dependencies = [
  "bumpalo",
  "log",
@@ -5254,9 +5346,9 @@ dependencies = [
 
 [[package]]
 name = "wasm-bindgen-futures"
-version = "0.4.36"
+version = "0.4.37"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2d1985d03709c53167ce907ff394f5316aa22cb4e12761295c5dc57dacb6297e"
+checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03"
 dependencies = [
  "cfg-if",
  "js-sys",
@@ -5266,9 +5358,9 @@ dependencies = [
 
 [[package]]
 name = "wasm-bindgen-macro"
-version = "0.2.86"
+version = "0.2.87"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "14d6b024f1a526bb0234f52840389927257beb670610081360e5a03c5df9c258"
+checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
 dependencies = [
  "quote",
  "wasm-bindgen-macro-support",
@@ -5276,9 +5368,9 @@ dependencies = [
 
 [[package]]
 name = "wasm-bindgen-macro-support"
-version = "0.2.86"
+version = "0.2.87"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8"
+checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -5289,9 +5381,9 @@ dependencies = [
 
 [[package]]
 name = "wasm-bindgen-shared"
-version = "0.2.86"
+version = "0.2.87"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93"
+checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
 
 [[package]]
 name = "wasm-encoder"
@@ -5448,7 +5540,7 @@ dependencies = [
  "lazy_static",
  "libc",
  "mach",
- "memoffset",
+ "memoffset 0.8.0",
  "more-asserts",
  "region",
  "scopeguard",
@@ -5490,9 +5582,9 @@ dependencies = [
 
 [[package]]
 name = "web-sys"
-version = "0.3.63"
+version = "0.3.64"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3bdd9ef4e984da1187bf8110c5cf5b845fbc87a23602cdf912386a76fcd3a7c2"
+checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b"
 dependencies = [
  "js-sys",
  "wasm-bindgen",

+ 1 - 1
src/sdk/python/.gitignore

@@ -69,4 +69,4 @@ docs/_build/
 .vscode/
 
 # Pyenv
-.python-version
+.python-version

+ 1 - 2
src/sdk/python/Cargo.toml

@@ -17,6 +17,5 @@ crate-type = ["cdylib"]
 darkfi = { path = "../../../", features = ["zk", "zkas"] }
 darkfi-sdk = { path = "../" }
 halo2_gadgets = "0.3.0"
-pasta_curves = "0.5.1"
 pyo3 = "0.19.0"
-rand = "0.8.5"
+rand = "0.8.5"

+ 3 - 2
src/sdk/python/src/affine.rs

@@ -16,10 +16,11 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use crate::base::Base;
-use pasta_curves::{arithmetic::CurveAffine, pallas};
+use darkfi_sdk::pasta::{arithmetic::CurveAffine, pallas};
 use pyo3::prelude::*;
 
+use super::base::Base;
+
 /// A Pallas point in the affine coordinate space (or the point at infinity).
 #[pyclass]
 pub struct Affine(pub(crate) pallas::Affine);

+ 6 - 5
src/sdk/python/src/base.rs

@@ -16,17 +16,18 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+use std::ops::Deref;
+
 use darkfi_sdk::{
     bridgetree::Hashable,
     crypto::{poseidon_hash, MerkleNode},
-};
-use pasta_curves::{
-    group::ff::{Field, FromUniformBytes, PrimeField},
-    pallas,
+    pasta::{
+        group::ff::{Field, FromUniformBytes, PrimeField},
+        pallas,
+    },
 };
 use pyo3::prelude::*;
 use rand::rngs::OsRng;
-use std::ops::Deref;
 
 /// The base field of the Pallas and iso-Pallas curves.
 /// Randomness is provided by the OS and on the Rust side.

+ 11 - 1
src/sdk/python/src/lib.rs

@@ -16,14 +16,24 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+/// Pallas point in affine space
 mod affine;
+/// Pallas base field element
 mod base;
+/// Pallas point in projective space
 mod point;
+/// Pallas scalar field element
+mod scalar;
+
+/// ZK proof creation
 mod proof;
+/// Proving key creation
 mod proving_key;
-mod scalar;
+/// Verifying key creation
 mod verifying_key;
+/// zkas ZkBinary wrappers
 mod zk_binary;
+/// zkvm wrappers
 mod zk_circuit;
 
 #[pyo3::prelude::pymodule]

+ 5 - 3
src/sdk/python/src/point.rs

@@ -16,7 +16,8 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use crate::{affine::Affine, base::Base, scalar::Scalar};
+use std::ops::{Add, Mul};
+
 use darkfi_sdk::{
     crypto::{
         constants::fixed_bases::{
@@ -29,12 +30,13 @@ use darkfi_sdk::{
     pasta::{
         arithmetic::CurveExt,
         group::{Curve, Group},
+        pallas,
     },
 };
 use halo2_gadgets::ecc::chip::FixedPoint;
-use pasta_curves::pallas;
 use pyo3::prelude::*;
-use std::ops::{Add, Mul};
+
+use super::{affine::Affine, base::Base, scalar::Scalar};
 
 /// A Pallas point in the projective coordinate space.
 #[pyclass]

+ 7 - 5
src/sdk/python/src/proof.rs

@@ -16,14 +16,16 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use crate::{
-    base::Base, proving_key::ProvingKey, verifying_key::VerifyingKey, zk_circuit::ZkCircuit,
-};
+use std::ops::Deref;
+
 use darkfi::zk::{proof, vm};
-use pasta_curves::pallas;
+use darkfi_sdk::pasta::pallas;
 use pyo3::prelude::*;
 use rand::rngs::OsRng;
-use std::ops::Deref;
+
+use super::{
+    base::Base, proving_key::ProvingKey, verifying_key::VerifyingKey, zk_circuit::ZkCircuit,
+};
 
 #[pyclass]
 pub struct Proof(pub(crate) proof::Proof);

+ 4 - 2
src/sdk/python/src/proving_key.rs

@@ -16,10 +16,12 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use crate::zk_circuit::ZkCircuit;
+use std::ops::Deref;
+
 use darkfi::zk::{proof, vm};
 use pyo3::prelude::*;
-use std::ops::Deref;
+
+use super::zk_circuit::ZkCircuit;
 
 #[pyclass]
 pub struct ProvingKey(pub(crate) proof::ProvingKey);

+ 4 - 2
src/sdk/python/src/scalar.rs

@@ -16,8 +16,10 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use darkfi_sdk::crypto::pasta_prelude::{Field, PrimeField};
-use pasta_curves::pallas;
+use darkfi_sdk::{
+    crypto::pasta_prelude::{Field, PrimeField},
+    pasta::pallas,
+};
 use pyo3::prelude::*;
 use rand::rngs::OsRng;
 

+ 4 - 2
src/sdk/python/src/verifying_key.rs

@@ -16,10 +16,12 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use crate::zk_circuit::ZkCircuit;
+use std::ops::Deref;
+
 use darkfi::zk::proof;
 use pyo3::prelude::*;
-use std::ops::Deref;
+
+use super::zk_circuit::ZkCircuit;
 
 #[pyclass]
 pub struct VerifyingKey(pub(crate) proof::VerifyingKey);

+ 4 - 2
src/sdk/python/src/zk_circuit.rs

@@ -16,11 +16,13 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use crate::{base::Base, point::Point, scalar::Scalar, zk_binary::ZkBinary};
+use std::ops::Deref;
+
 use darkfi::zk::{halo2::Value, vm, vm_heap::empty_witnesses};
 use darkfi_sdk::crypto::MerkleNode;
 use pyo3::prelude::*;
-use std::ops::Deref;
+
+use super::{base::Base, point::Point, scalar::Scalar, zk_binary::ZkBinary};
 
 #[pyclass]
 pub struct ZkCircuit(pub(crate) vm::ZkCircuit, pub(crate) Vec<vm::Witness>);

+ 3 - 0
src/zk/vm.rs

@@ -572,13 +572,16 @@ impl Circuit<pallas::Base> for ZkCircuit {
                 Opcode::EcMulShort => {
                     trace!(target: "zk::vm", "Executing `EcMulShort{:?}` opcode", opcode.1);
                     let args = &opcode.1;
+
                     let lhs: FixedPointShort<pallas::Affine, EccChip<OrchardFixedBases>> =
                         heap[args[1].1].clone().into();
+
                     let rhs = ScalarFixedShort::new(
                         ecc_chip.clone(),
                         layouter.namespace(|| "EcMulShort: ScalarFixedShort::new()"),
                         (heap[args[0].1].clone().into(), one.clone()),
                     )?;
+
                     let (ret, _) = lhs.mul(layouter.namespace(|| "EcMulShort()"), rhs)?;
 
                     trace!(target: "zk::vm", "Pushing result to heap address {}", heap.len());