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

Panic on ChildAccount.getCapability() adds query complexity #159

Closed
sisyphusSmiling opened this issue Sep 28, 2023 · 2 comments · Fixed by #160
Closed

Panic on ChildAccount.getCapability() adds query complexity #159

sisyphusSmiling opened this issue Sep 28, 2023 · 2 comments · Fixed by #160
Labels
bug Something isn't working

Comments

@sisyphusSmiling
Copy link
Collaborator

Shared from @leontastic in Discord:

I'm running into a hard-to-debug error that is also hard to recover from.

On line 20 there is a call to addr.forEachPrivate to get private paths on the account
On line 25 we call childAcct.getCapability with those paths

Then we run into this error requested capability is not allowed https://github.com/onflow/hybrid-> custody/blob/main/contracts/HybridCustody.cdc#L595

A few issues here:

  1. Obviously childAcct.getCapability is accessing a disallowed capability. But why does it panic? Could it not return a nil value instead?
  2. Why does this script use addr.forEachPrivate if some of these paths may result in a panic? Should the list of paths to capabilities be derived from the published CapabilityFilter instead?
  3. Assuming this is the only way to enumerate and find child capabilities, and that there is no way to guarantee that all private paths of the parent are also available on the child, how can the error be prevented? Ideally this script would just skip over any missing capabilities.
@sisyphusSmiling sisyphusSmiling added the bug Something isn't working label Sep 28, 2023
@sisyphusSmiling
Copy link
Collaborator Author

My thoughts here are:

  1. I don't see why we couldn't return nil on getCapability(). In fact, it would better match expectations given the function signature.
  2. We have to iterate over private paths bc there is no other source of truth. Filters store allowed/disallowed types, not paths
  3. I think the best path forward is to update the contract to return nil instead of panicking.

This wouldn't require changes to method signatures, but a logic update within ChildAccount.getCapability(path: CapabilityPath, type: Type): Capability? after the filter check on the retrieved Capability type here.

@sisyphusSmiling
Copy link
Collaborator Author

Changes from #160 have been deployed to Testnet & Mainnet in the following transactions:

Testnet: a7fadbd22f768a777aefc9c29e7dad546a4c5c90fac72170a5e3a53ff1f7734d
Mainnet: 3a9363154c64a4ac1c6609ac31adaef62b6fa71844b596ddbc9d62fc97d2bb51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant