Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Move Object] Public Object transfer, borrow, borrow_mut #989

Closed
wants to merge 1 commit into from

Conversation

WGB5445
Copy link
Collaborator

@WGB5445 WGB5445 commented Oct 17, 2023

Summary

Object should be freely borrowable or transferable
Therefore, the borrow and transfer of Object with Key + store are added

Public_add and public_remove have not been added for the time being because they may destabilize the life cycle of Object, so these two functions will not be added for the time being.

@vercel
Copy link

vercel bot commented Oct 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
rooch ⬜️ Ignored (Inspect) Visit Preview Oct 18, 2023 3:26am

@jolestar jolestar requested a review from pause125 October 17, 2023 22:59
@@ -50,6 +50,10 @@ module moveos_std::object {
&self.value
}

public fun public_borrow<T: key + store>(self: &Object<T>): &T {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we remove the private_generics from borrow and borrow_mut? Because Context::borrow_object and Context::borrow_object_mut has the private_generics.

@stevenlaw123 @pause125 @baichuan3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And should we support borrowing Object<T: key+store> from Context without private_generics ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And should we support borrowing Object<T: key+store> from Context without private_generics ?

Maybe this shouldn't be the case, it would mean that other modules could borrow arbitrary Object
This may cause security issues

Copy link
Collaborator Author

@WGB5445 WGB5445 Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we remove the private_generics from borrow and borrow_mut? Because Context::borrow_object and Context::borrow_object_mut has the private_generics.
@stevenlaw123 @pause125 @baichuan3

I think it's reasonable
Because there is no way to get &Object<T> or Object<T> except context and current module.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

borrowing Object<T: key+store>

The reference of Object can only be obtained through context. I think it can be removed and there is no security issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my understanding, borrow Object<T: key> and borrow Object<T: key + store> satisfy two types of scenarios respectively?

  1. If Object<T: key> is only a key capability, it can only be accessed through context::borrow_object (with private_generics(T) restriction) or object:borrow (need to pass Object reference);
  2. If Object<T: key+store> also has store capability, in addition to option 1, it can also be called through context::public_borrow_object* (there is no private_generics(T) restriction, and there is no need to pass the Object reference).

@@ -70,6 +78,10 @@ module moveos_std::object {
self.owner = recipient;
}

public fun public_transfer<T: key + store>(self: &mut Object<T>, recipient: address) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the transfer to key + store and remove #[private_generics(T)], public_transfer to transfer_extend ? Keep consistency with coin and account_coin_store

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does xxx_extend always have #[private_generics(T)] check? Is it more appropriate to put the object public_transfer function in the transfer module?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The transfer function in the transfer module needs to use object_id as the argument.

public entry transfer_object<T:key+store>(ctx, object_id, to){
  let object = context::borrow_object_mut<T>(ctx, object_id);
  object::transfer(object, to);
}

So, it depends on how to support the public borrow object from context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Object] Proposal for an Owner method to directly operate on Objects
3 participants