anza-xyz / move

Move compiler targeting llvm supported backends
https://discord.gg/wFgfjG9J
Apache License 2.0
109 stars 34 forks source link

Investigate and implement sui-specific native calls #411

Open brson opened 8 months ago

brson commented 8 months ago

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.

ksolana commented 7 months ago

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 commented 7 months ago

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.

ksolana commented 6 months ago

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?