stacks-network / stacks-core

The Stacks blockchain implementation
https://docs.stacks.co
GNU General Public License v3.0
3.01k stars 672 forks source link

[RPC] Add method to check of a contract function is read-only, even if it's `define-public` #5437

Open jcnelson opened 2 weeks ago

jcnelson commented 2 weeks ago

Currently, trait definitions do not enforce a read-only property on trait implementations. This is desirable because trait implementation consumers may want to be assured that a particular implementation cannot alter blockchain state. For example, the SIP-009 trait function get-last-token-id should not write new state.

Until the VM can be extended to support read-only enforcement for trait concretizations, the Clarity VM could instead record whether or not a function is truly read-only at analysis time. This analysis is something it already does as part of verifying that a function is properly defined. Once the VM does this, then we can add an RPC endpoint to allow users to query whether or not a trait concretization (or really, any defined function anywhere in the chain) is read-only. This way, users of popular trait concretizations like SIP-009 NFTs can ascertain whether or not functions that are expected to be read-only truly are.