ProvableHQ / sdk

A Software Development Kit (SDK) for Zero-Knowledge Transactions
https://provable.tools
GNU General Public License v3.0
593 stars 471 forks source link

[Bug] python call transfer error #927

Open zhp1254 opened 2 months ago

zhp1254 commented 2 months ago

🐛 Bug Report

1、add rust func transfer_tx 2、build so cargo build --release 3、python ctypes call transfer_tx import ctypes lib = ctypes.CDLL('./target/release/libaleo_wasm.so') kPtr = lib.transfer_tx(b'{"private_key":"APrivateKey1zkpAUbZDoVZBj4xDhD1q5bpR9Lq11QQKd58HcgszW6aLJ8b","amount":0.01,"fee":0.06,"receiver":"aleo12m2q0y4d84vcf5alul2v2q9q3layxgsezxpyxn06gk95zpk3j5rsr4tn4r","state_root":"sr154fn2fz057zm49yk90pdlet883dsj7nsah2reg3hlfqlsvnpdypse92gak"}')

Steps to Reproduce

Code snippet to reproduce

#[no_mangle]
pub extern "C" fn transfer_tx(json_c_char: *const c_char) -> *const c_char {
      let json_cstr = unsafe {
         assert!(!json_c_char.is_null());
         CStr::from_ptr(json_c_char)
     };

     let json_str = match json_cstr.to_str() {
         Ok(v) => v,
         Err(e) => {
             panic!("json ptr to json string err: {:?}", e);
         }
     };

      let data: TransferInfo = match serde_json::from_str(json_str) {
         Ok(v) => v,
         Err(e) => {
            panic!("json to transferInfo struct err: {:?}", e);
         }
     };

     let offline_query = OfflineQuery::new(&data.state_root);
     let private_key = match PrivateKey::from_string(&data.private_key) {
                 Ok(v) => v,
                 Err(e) => {
                     panic!("parse key err: {:?}", e);
                 }
             };

       let ret = block_on(ProgramManager::transfer(
             &private_key,
             data.amount,
             &data.receiver,
             "public",
             None,
             data.fee,
             None,
             None,
             None,
             None,
             None,
             None,
             Some(offline_query.expect("offline query init error")),
         ));

         let transfer = match ret {
                  Ok(v) => v,
                  Err(e) => {
                     panic!("ProgramManager create transfer err: {:?}", e);
                  }
              };

         let resp_json = transfer.to_string();
         let resp_data = CString::new(resp_json).unwrap();
         resp_data.into_raw()
}

Stack trace & error message

thread '<unnamed>' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasm-bindgen-0.2.92/src/lib.rs:1017:1:
function not implemented on non-wasm32 targets
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: wasm_bindgen::__wbindgen_describe
   4: aleo_wasm::programs::manager::transfer::<impl aleo_wasm::programs::manager::ProgramManager>::transfer::{{closure}}
   5: transfer_tx
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: _PyObject_MakeTpCall
  11: _PyEval_EvalFrameDefault
  12: <unknown>
  13: _PyEval_EvalCodeWithName
  14: PyEval_EvalCode
  15: <unknown>
  16: <unknown>
  17: <unknown>
  18: PyRun_InteractiveLoopFlags
  19: PyRun_AnyFileExFlags
  20: <unknown>
  21: Py_BytesMain
  22: __libc_start_main
  23: _start

Expected Behavior

(Write what you expected to happen here)

Your Environment

zhp1254 commented 2 months ago

`

[no_mangle]

pub extern "C" fn new_private() -> *const c_char { let key = PrivateKey::new(); let key_str = key.to_string(); let c_key = CString::new(key_str).unwrap(); c_key.into_raw() } ` new_private call success by python and i got an right private key with lib.so