cadence icon indicating copy to clipboard operation
cadence copied to clipboard

Extensibility

Open alxocity opened this issue 4 years ago • 6 comments

Issue To Be Solved

Ability to extend a resource without updating the resource contract.

Suggest A Solution

Essentially this, but in Cadence/Flow: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods

Context

This would allow adding Autographs to NBA TopShot moments, and generically adding resources to other resources without editing the parent resource contract. This would open up full personalization for anyone's NFTs. https://discord.gg/mCtsWyS

alxocity avatar Aug 28 '20 23:08 alxocity

There are lots of interesting use cases that could emerge here.

  • Signing (like moment i guess)?
  • Original Artist
  • Suggested Original Artist resell cut (a marketplace could use this to send a small amount of cash to the oringal artist on resale)
  • Ownership trail

bjartek avatar Aug 29 '20 21:08 bjartek

Here's an example of modifying the Top Shot contract to support autographs that would be preferably done via extensions instead of editing the original contract: https://github.com/Flow-Moment-Company/flow-moment-contracts/blob/master/contracts/nba/TopShot.cdc (find "autograph" in file to see extension points)

alxocity avatar Aug 30 '20 07:08 alxocity

This commit in particular highlights the autographs extensibility that could instead be done outside of the Top Shot contract https://github.com/Flow-Moment-Company/flow-moment-contracts/commit/5924d24444990e8ec06c2f9101769610dd6ded85

alxocity avatar Aug 30 '20 08:08 alxocity

Could mixins be used to model this? If a mixin is stored in another account? And you could say i want

Topshot.NFT with Moment.Autograph

There has to be some guidelines to what could be done in a mixin then i guess. Maybe you should only get a reference to the parent.

bjartek avatar Aug 30 '20 08:08 bjartek

An important issue with smart contract code rather than application code is that extending it can be used to introduce attacks. While extension methods cannot replace existing methods and perform a person-in-the-middle attack, they can add new functions that use existing code and member variables in ways that lead to undesirable results for the user. IMO it's important to look at what any proposal takes from the security of the system as well as what it adds to its expressiveness.

rheaplex avatar Oct 05 '20 16:10 rheaplex

Thank you @alxocity and everyone else for starting this discussion! Extensions have been on our roadmap since the beginning, and we're excited to work on this.

I had a call with @alxocity last Friday, and started a new topic in the forum to discuss this further: https://forum.onflow.org/t/extensibility/622

Please have a look and please share your thoughts! Hopefully we can discuss this together, come up with a proposal, and get it implemented 🚀

I'm also very happy to set up another call with more people who are interested to answer the open questions and work out a proposal. Please let me know!

turbolent avatar Oct 19 '20 19:10 turbolent

The core attachments proposal has been implemented and merged into a feature branch, hopefully to come to master soon.

The portion of the proposal that originally included iteration will be handled separately in the future, tracked in the issue here: https://github.com/onflow/cadence/issues/2193

dsainati1 avatar Dec 12 '22 19:12 dsainati1