rooch-network / rooch

VApp Container with Move Language
https://rooch.network
Apache License 2.0
128 stars 54 forks source link

[NativeFunction] Native Function error code #960

Closed jolestar closed 7 months ago

jolestar commented 7 months ago

Some native functions directly raise the error code.

https://github.com/rooch-network/rooch/blob/4a649e19a2040d8e3c9378f0701bf8217bf84fee/crates/rooch-framework/src/natives/rooch_framework/crypto/ecdsa_k1_recoverable.rs#L50-L52

This needs to be converted by the moveos_types::move_std::error function, like

https://github.com/rooch-network/rooch/blob/4a649e19a2040d8e3c9378f0701bf8217bf84fee/moveos/moveos-stdlib/src/natives/moveos_stdlib/raw_table/mod.rs#L482-L485

pause125 commented 7 months ago

What's the difference of returning Ok(NativeResult::err(...)) and Err(PartialVMError) ?

jolestar commented 7 months ago

What's the difference of returning Ok(NativeResult::err(...)) and Err(PartialVMError) ?

NativeResult = Result<T, PartialVMError>

pause125 commented 7 months ago

What's the difference of returning Ok(NativeResult::err(...)) and Err(PartialVMError) ?

NativeResult = Result<T, PartialVMError>

NativeResult defination: https://github.com/rooch-network/move/blob/47bb63611844e547fed85c9fe7f66d508caa684a/language/move-vm/types/src/natives/function.rs#L35C15-L35C15

Result<T, PartialVMError> is PartialVMResult<T> defined here, which is the return type of native functions.

I see that in some native function error is returned with Err(PartialVMError::new(...)), some is returned with Ok(NativeResult::err(...))

jolestar commented 7 months ago

I made a mistake on the previous, PartialVMError has no location, VMError has a location.

pause125 commented 7 months ago

So, when returning with error, when to return Err(PartialVMError), when to return Ok(NativeResult::err) ?

jolestar commented 7 months ago

In the VM, if we know the location, return VMError. Otherwise, return PartialVMError and let the invoker set the location.