onflow / cadence

Cadence, the resource-oriented smart contract programming language 🏃‍♂️
https://developers.flow.com/cadence
Apache License 2.0
533 stars 140 forks source link

`account.type(at: path)` should not crash when path is set by an outdated contract #2715

Open cybercent opened 1 year ago

cybercent commented 1 year ago

Issue to be solved

Users will interact with different contracts in the lifetime of their account and some of those contacts might lag to update to latest Cadence or are left dead.

Currently, there is a crash when reading the account.type(at: path) set by a contract that is out of date.

Suggested Solution

Return the type without loading the broken contract.

j1010001 commented 1 year ago

Might be solved by rent fixes to storage iteration.

turbolent commented 1 year ago

We should probably handle this function just like we do storage iteration, i.e. return an "invalid type", instead of aborting the transaction.

@cybercent Where are you running into this? How important is this to you?

cybercent commented 1 year ago

I'm iterating over paths on various accounts, in order for the script not to break I'm forced to manually ignore the paths set by contracts that are outdated.

I get into a similar issue when reading data from contracts that force unwrap optionals when the expected data is not there. Many flow contracts wrongly force-unwrap optionals in their own data structures without first checking the data is there so MetadataViews break. These are "quality" projects like MotoGP, Titles etc, not NFT "test contracts".

So maybe one way to handle this is to add a try/catch to Cadence that would work on scripts but not work on transactions.