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

Getting/Borrowing a capability as a sibling interface-type of the orignally issued type #3533

Open
SupunS opened this issue Aug 15, 2024 · 7 comments
Assignees
Labels
Feedback Improvement Question Further information is requested

Comments

@SupunS
Copy link
Member

SupunS commented Aug 15, 2024

Issue to be solved

Came up in the thread https://discord.com/channels/613813861610684416/1273464365701398568/1273464651971039336.

Suppose a resource R implements both I1 and I2.

resource R: I1, I2 {}

And a capability to the resource is being issued with I1. i.e: Capability<&{I1}>

Currently this capability is no allowed to be get/borrowed as Capability<&{I2}>. However, once the capability is borrowed, it is possible to upcast/downcast to any of the interface-types that R implements.

The question is, does it make sense to borrow it with I2 as well? (note that none of these grant extra permissions/entitlements)

Suggested Solution

No response

@SupunS SupunS added Question Further information is requested Improvement Feedback labels Aug 15, 2024
@bjartek
Copy link
Contributor

bjartek commented Aug 15, 2024

It appears that this work for caps created in 1.0 but not migrated caps? See here https://discord.com/channels/613813861610684416/1273709822218473513

@SupunS
Copy link
Member Author

SupunS commented Aug 15, 2024

It appears that this work for caps created in 1.0 but not migrated caps? See here https://discord.com/channels/613813861610684416/1273709822218473513

There the problem is, borrowing as a super-type/sub-type works when issued with a single interface. But the same fails when issued with multiple interfaces.
e.g:

resource interface I1: I2 {}

resource interface I2 {}

resource interface I3 {}

 resource R: I1, I2, I3 {}

// Case-1: Issue as `{I2}` only
// Below borrowing will pass
var a = self.account.capabilities.storage.issue<&{I2}>(/storage/r)
self.account.capabilities.publish(a, at: /public/a)

// Case-2: Issue as `{I2, I3}`.
// Below borrowing will fail
var a = self.account.capabilities.storage.issue<&{I2, I3}>(/storage/r)
self.account.capabilities.publish(a, at: /public/a)

// Borrow as `{I1}`
self.account.capabilities.borrow<&{I1}>(/public/a)!

@bjartek
Copy link
Contributor

bjartek commented Aug 15, 2024

Nice find

@SupunS
Copy link
Member Author

SupunS commented Aug 16, 2024

Opened a separate issue #3537 for the second one, as those two more likely need separate handling

@SupunS
Copy link
Member Author

SupunS commented Aug 16, 2024

Took a while for me to realize, #3537 is also actually the same sibling problem.
e.g: The type hierarchy is as follows:

    AnyResource
        / \
       /   \
     I2     I3
    /  \   /
   /    \ /
  I1  {I2,I3}
   \    /
    \  /
      R

{I2,I3} is not a direct subtype or a supertype of I1, but rather a sibling. That's why the borrowing fails, just like the sibling case (original issue in the description).Though both are super-types of R.

A more realistic example is added in #3537 (comment)

@SupunS
Copy link
Member Author

SupunS commented Aug 16, 2024

We can support this from the technical point of view. But then it would make the capability issue type mostly useless, and only the entitlements would matter.

@j1010001
Copy link
Member

j1010001 commented Aug 23, 2024

This is not causing staging/update to fail, if someone runs into the problem they can solve it by upgrading their contract post-Crescendo. To reduce risk we will not fix this before Crescendo but after. We will update Docs to explain the problem and how to work around it.

@SupunS SupunS self-assigned this Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feedback Improvement Question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants