Просмотр исходного кода

runtime: remove unused put_object_bytes()

zero 2 лет назад
Родитель
Сommit
56d5281f6c
3 измененных файлов с 0 добавлено и 79 удалено
  1. 0 64
      src/runtime/import/util.rs
  2. 0 6
      src/runtime/vm_runtime.rs
  3. 0 9
      src/sdk/src/wasm/util.rs

+ 0 - 64
src/runtime/import/util.rs

@@ -86,70 +86,6 @@ pub(crate) fn set_return_data(mut ctx: FunctionEnvMut<Env>, ptr: WasmPtr<u8>, le
     wasm::entrypoint::SUCCESS
 }
 
-/// Appends a new object to the [`Env`] objects store.
-/// The data for the object is read from `ptr`.
-///
-/// Returns an index corresponding to the new object's index in the objects
-/// store. (This index is equal to the last index in the store.)
-///
-/// Permissions:
-pub(crate) fn put_object_bytes(mut ctx: FunctionEnvMut<Env>, ptr: WasmPtr<u8>, len: u32) -> i64 {
-    let (env, mut store) = ctx.data_and_store_mut();
-    let cid = env.contract_id;
-
-    // Enforce function ACL
-    if let Err(e) = acl_allow(env, &[]) {
-        error!(
-            target: "runtime::util::put_object_bytes()",
-            "[WASM] [{}] put_object_bytes(): Called in unauthorized section: {}", cid, e,
-        );
-        return darkfi_sdk::error::CALLER_ACCESS_DENIED
-    }
-
-    // Subtract used gas. Here we count the length read from the memory slice.
-    env.subtract_gas(&mut store, len as u64);
-
-    let memory_view = env.memory_view(&store);
-    //debug!(target: "runtime::util", "diagnostic:");
-    let pages = memory_view.size().0;
-    //debug!(target: "runtime::util", "    pages: {}", pages);
-
-    let Ok(slice) = ptr.slice(&memory_view, len) else {
-        error!(
-            target: "runtime::util::put_object_bytes",
-            "[WASM] [{}] put_object_bytes(): Failed to make slice from ptr", cid,
-        );
-        return darkfi_sdk::error::INTERNAL_ERROR
-    };
-
-    let mut buf = vec![0_u8; len as usize];
-    if let Err(e) = slice.read_slice(&mut buf) {
-        error!(
-            target: "runtime::util::put_object_bytes",
-            "[WASM] [{}] put_object_bytes(): Failed to read from memory slice: {}", cid, e,
-        );
-        return darkfi_sdk::error::INTERNAL_ERROR
-    };
-
-    // There would be a serious problem if this is zero.
-    // The number of pages is calculated as a quantity X + 1 where X >= 0
-    assert!(pages > 0);
-
-    //debug!(target: "runtime::util", "    memory: {:02x?}", &buf[0..32]);
-    //debug!(target: "runtime::util", "            {:x?}", &buf[32..64]);
-    //debug!(target: "runtime::util", "    ptr location: {}", ptr.offset());
-
-    let mut objects = env.objects.borrow_mut();
-    objects.push(buf);
-    let obj_idx = objects.len() - 1;
-
-    if obj_idx > u32::MAX as usize {
-        return darkfi_sdk::error::DATA_TOO_LARGE
-    }
-
-    obj_idx as i64
-}
-
 /// Retrieve an object from the object store specified by the index `idx`.
 /// The object's data is written to `ptr`.
 ///

+ 0 - 6
src/runtime/vm_runtime.rs

@@ -261,12 +261,6 @@ impl Runtime {
                     import::db::zkas_db_set,
                 ),
 
-                "put_object_bytes_" => Function::new_typed_with_env(
-                    &mut store,
-                    &ctx,
-                    import::util::put_object_bytes,
-                ),
-
                 "get_object_bytes_" => Function::new_typed_with_env(
                     &mut store,
                     &ctx,

+ 0 - 9
src/sdk/src/wasm/util.rs

@@ -39,14 +39,6 @@ pub fn set_return_data(data: &[u8]) -> Result<(), ContractError> {
     }
 }
 
-pub fn put_object_bytes(data: &[u8]) -> Result<i64, ContractError> {
-    // Ensure that the number of bytes fits within the u32 data type.
-    match u32::try_from(data.len()) {
-        Ok(len) => unsafe { Ok(put_object_bytes_(data.as_ptr(), len)) },
-        Err(_) => Err(ContractError::DataTooLarge),
-    }
-}
-
 pub fn get_object_bytes(data: &mut [u8], object_index: u32) -> i64 {
     unsafe { get_object_bytes_(data.as_mut_ptr(), object_index) }
 }
@@ -183,7 +175,6 @@ pub fn get_tx_location(hash: &TransactionHash) -> GenericResult<(u64, u64)> {
 
 extern "C" {
     fn set_return_data_(ptr: *const u8, len: u32) -> i64;
-    fn put_object_bytes_(ptr: *const u8, len: u32) -> i64;
     fn get_object_bytes_(ptr: *const u8, len: u32) -> i64;
     fn get_object_size_(len: u32) -> i64;