move icon indicating copy to clipboard operation
move copied to clipboard

Investigate and implement sui-specific native calls

Open brson opened this issue 1 year ago • 3 comments

We are in the process of migrating to the sui codebase. There are likely new native function calls on sui that we do not implement, either in std or in their own sui library.

Look into this and see what we need to add to move-native to make this work.

If there are natives called by sui directly they should probably live in a new sui module inside of move-native, as the calls used by std live in a corresponding std module.

brson avatar Feb 01 '24 18:02 brson

Seems like there are two parts to it

  1. make sure all the methods are there e.g. there is bcs::native_to_bytes in both move/move-native as well as sui/move/move-native so we count it as being there
  2. make sure all the methods implement the same thing. Most methods in sui have been modified for the cost/gas calculations. We can do this in a follow up step once the migration is complete.

ksolana avatar Mar 03 '24 21:03 ksolana

For step#1.

Comparing all the files.

ls sui/external-crates/move/crates/move-stdlib/src/natives/
bcs.rs       debug.rs     hash.rs      helpers.rs   mod.rs       signer.rs    string.rs    type_name.rs unit_test.rs vector.rs

ls move/language/move-stdlib/src/natives/
bcs.rs       event.rs     helpers.rs   signer.rs    type_name.rs vector.rs
debug.rs     hash.rs      mod.rs       string.rs    unit_test.rs

Seems like move/move-stdlib has one extra file event.rs

Comparing for presence of methods in these files. Methods should at least have the same signature.

  • [x] bcs.rs
  • [ ] debug.rs
    • [ ] New functions: native_print_nop, native_print_stack_trace_nop
    • [ ] Different signatures: make_native_print, make_native_print_stack_trace, make_all
    • [ ] Others: Change in scope of some imported types like MoveStructLayout etc.
  • [x] hash.rs
  • [x] helpers.rs
  • [ ] mod.rs
    • [ ] New functions: unit_test:PoisionGasParameters
  • [x] signer.rs
  • [x] string.rs
  • [ ] type_name.rs
    • [ ] New functions: make_native_get
    • [ ] Different signatures: native_get
  • [ ] unit_test.rs
    • [ ] New functions: native_poison, make_native_poison
    • [ ] Others: New class PoisonGasParameters, GasParameters has one more param poison
  • [x] vector.rs

ksolana avatar Mar 03 '24 21:03 ksolana

There are two native functions that are absent in move-language/move(after checking out @brson's updated branch)

// from crates/mysten-util-mem/src/allocators.rs
// Linux/BSD call system allocator (currently malloc).
pub unsafe extern "C" fn malloc_usable_size(_ptr: *const c_void) -> usize
// from crates/mysten-util-mem/src/malloc_size.rs
pub type VoidPtrToSizeFn = unsafe extern "C" fn(ptr: *const c_void) -> usize

This is used for calling size_of for various allocations. All the various size_of implementations are in https://github.com/MystenLabs/sui/tree/main/crates/mysten-util-mem.

Do we still want to implement(import) them in move-native?

ksolana avatar Mar 09 '24 20:03 ksolana