feat: added access modifier restrictions on clarity trait definitions #5383
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Was working on this issue in the clarinet repo and felt need of more data from the clarity virtual machine.
Upon further investigation, noticed that there is something wrong about how traits are handle in the virtual machine.
for eg. if we take the standard nft trait SIP009, it has methods like
(get-last-token-id () (response uint uint))
and(transfer (uint principal principal) (response bool uint))
, it should be intuitive but if not according to the standard definition first one should be implemented as a read-only function and the latter should be public.In current scenario, this access modifier like assertion is not stored in the trait definitions. Any contract implementing the trait can implement those methods howsoever it likes as there is no safe-guard about it. Currently, the virtual machine only checks if the name and the signature is a match.
It should be assumed that the average end-user doesn't know about these kind of things. A getter function can be implemented as public one and can easily change the state of the chain. While similarly, a transfer like function is expected to change the state of the chain and consequently should be public but contracts are free to implement it however they like.
In my opinion, this is quite a vulnerability.
This pr should help.