IntersectMBO / plutus

The Plutus language implementation and tools
Apache License 2.0
1.56k stars 477 forks source link

Documentation about origin / state of indices of BuiltinFun / AST terms etc #5670

Closed nielstron closed 9 months ago

nielstron commented 9 months ago

Describe the feature you'd like

The current standard of flat encoding UPLC implies that terms are distinguished by the order of their constructor. This makes i.e. finding the correct index for AddInteger very painful. Indeed the definition order does not match the indices which makes me wonder where actually one could read up which builtin function has which index?

IMO the index of elements should be independently documented and made sure that the haskell implementation fulfils the standard. The current approach of simply having the Haskell code as the standard is brittle (indexes can change and thus flat decoding will have potentially subtle errors, just by re-ordering elements) and hard to assess for outsiders and third party implementations of uplc such as https://github.com/opshin/uplc

Describe alternatives you've considered

No response

kwxm commented 9 months ago

... which makes me wonder where actually one could read up which builtin function has which index?

Look at Tables C.3, C.4, and C.5 on pp 56-57 of the Plutus Core specification (pdf here).

In the Haskell source, the tags are defined here, which admittedly isn't very easy to find.

nielstron commented 9 months ago

Perfect, thank you! I must have missed this.