clarinet icon indicating copy to clipboard operation
clarinet copied to clipboard

Feature request: output AST for `clarinet run`

Open MarvinJanssen opened this issue 3 years ago • 8 comments
trafficstars

Asking for the possibility of receiving contract AST in clarinet run. I remember one of the very early versions of this command having the capability (although I might be wrong).

I want to make a simplistic analyser that checks if a given contract conforms to the SIP-013 semi-fungible token standard https://github.com/stacksgov/sips/pull/42.

The SIP defines parameters that cannot be captured by mere trait compliance. I wanted to use the AST to check if there is some usage of specific Clarity primitives; including, but not limited to:

  • Check if transfer calls both ft-transfer? and nft-burn?.
  • Check if the contract prints the right events.
  • ...and so on.

If it works, I am even thinking about generalising such a check system into a separate SIP. Then future SIPs that describe contracts could add a reference trait as well as an AST check. (Cool future feature for Clarinet as well?)

MarvinJanssen avatar Feb 22 '22 02:02 MarvinJanssen

Sounds cool!

unclemantis avatar Feb 22 '22 03:02 unclemantis

Sounds a bit like https://github.com/hirosystems/clarinet/issues/463.

We've been discussing enabling extensions using the ASTVisitor trait (see https://github.com/hirosystems/clarity-repl/blob/develop/src/analysis/ast_visitor.rs). I will work on this soon.

obycode avatar Feb 22 '22 14:02 obycode

Ignore my last comment. I discussed with @lgalabru and now understand that defining a plugin in Rust is not what we're looking for here. We can just expose the AST in Typescript (and maybe later create an ASTVisitor for Typescript).

obycode avatar Mar 02 '22 00:03 obycode

@obycode wondering if there have been any follow-up discussions on this feature request? I would love to include a SIP013 validator script for https://github.com/stacksgov/sips/pull/42.

With the AST exposed, I could make a script that checks:

  1. if the public functions call the right native functions; e.g., transfer calls ft-transfer?, etc..
  2. if the burn-and-mint post condition mechanism exists.
  3. if the proper events are emitted.

MarvinJanssen avatar Apr 29 '22 04:04 MarvinJanssen

Hi @MarvinJanssen. I have not been able to prioritize this yet. How urgent is your need?

obycode avatar May 02 '22 20:05 obycode

@obycode Not sure, it is definitely not a requirement for SIP013 or the other SIP we will be working on at the Lab. However, it would definitely be cool. Is it a lot of work? Maybe I could take a crack at it. Anything in Rust just takes ages for me to figure out.

MarvinJanssen avatar May 03 '22 02:05 MarvinJanssen

I'm not really sure what kind of effort this will take. I have not looked at this code path yet. I'm going to take a look now...

obycode avatar May 03 '22 19:05 obycode

I think the key task for this is going to be figuring out how to represent the AST in the JSON (which gets passed from Rust to Typescript).

obycode avatar May 03 '22 23:05 obycode

Is this still need? I think we might be able quite easily to the @clarinet-sdk (in progress #1065)

hugoclrd avatar Jul 17 '23 11:07 hugoclrd

I slightly repurposed this issue following the deprecation of clarinet run and the release of clarinet sdk

hugoclrd avatar Sep 28 '23 11:09 hugoclrd

Addressed in #1162

hugoclrd avatar Sep 28 '23 11:09 hugoclrd