SIP-020: Add bitwise operators to Clarity 2 (rider SIP to SIP-015 and recent addition to 2.1 upgrade)

Sharing the following notes from Cyle, @brice @HeroGamer, which explain the proposal outlined in SIP-020, a recently approved SIP slated to activate alongside SIP-015 as part of the larger Stacks 2.1 upgrade:

TL;DR on SIP-020

  • SIP proposal led by Stacks community member, Cyle Witruk

  • Consensus-breaking change

  • Recent addition to Stacks 2.1 upgrade

  • Like SIP-018, SIP-020 is a “rider SIP” to SIP-015, meaning it can activate if and only if SIP-015 (and Stacks 2.1 more broadly) is activated

  • Has been reviewed, voted on, and approved by both the Technical and Governance CABs

Approval of SIP-020

While this SIP was a late inclusion to Stacks 2.1, the Steering Committee and relevant CABs generally believed this proposal to be a non-controversial and worthwhile language improvement, and advocated for its inclusion pending completion by the 2.1 code-complete deadline.

SIP-020 Explained

SIP-020 adds six new native functions to perform bitwise operations in the Clarity language. Bitwise operations act on the bits of a value, and are commonly used in other programming languages for encryption, communication, setting and checking flags, and many other applications.

It makes various operations much easier to write and comprehend. While possible to implement these functions using existing Clarity operators, the resulting code can be cumbersome and difficult to understand at a glance, which goes against one of Clarity’s core principals (readability). The introduction of these native functions to the Clarity language helps to alleviate these challenges by:

  • Reducing smart contract publishing and execution costs

  • Enabling faster on-chain computation

  • Lowering the barrier to entry for using such operators

  • Being easier to audit

Possible Areas of Use

  • DAOs that wish to implement more complex, less-static role and membership structures can now implement this efficiently in Clarity by storing role memberships in bitwise flags instead of in separate maps per-role.

  • Shifting operators can be used to power complex generative art for NFT projects more efficiently and more easily than previously possible.

  • Contracts which have a number of boolean flags can now consolidate these flags into a single integer variable, saving on both storage and execution costs.

  • Many others that remain to be seen :slight_smile:

3 Likes