stacks-network / clarity-wasm

`clar2wasm` is a compiler for generating WebAssembly from Clarity.
GNU General Public License v3.0
12 stars 10 forks source link

Implement `stacks-block-height` and `tenure-height` #322

Open obycode opened 6 months ago

obycode commented 6 months ago

SIP-021 specifies the following updates to Clarity:

The protocol described in this document would have Stacks blocks occur at a much greater frequency than in the past. Many contracts rely on the block-height primitive to approximate a time assuming that a block takes, on average, 10 minutes. To release faster blocks while preserving the functionality of existing contracts that make this block frequency assumption, this proposal calls for a new version of Clarity, version 3, which includes the following changes.

A new Clarity global variable stacks-block-height will be introduced, which evaluates to the Stacks block height. A new Clarity global variable tenure-height will be introduced, which evaluates to the number of tenures that have passed. When the Nakamoto block-processing starts, this will be equal to the chain length. The Clarity global variable block-height will continue to be supported in existing Clarity 1 and Clarity 2 contracts by returning the same value as tenure-height. Usage of block-height in a Clarity 3+ contract will trigger an analysis error.

These changes will be implemented in the interpreter in stacks-network/stacks-core#3943 and also need to be implemented in the clarity-wasm runtime.

ameeratgithub commented 2 months ago

Just checking to see if it is unblocked now

obycode commented 2 months ago

Yes, @hugocaillard's #420 implements these.

hugocaillard commented 1 month ago

I'm removing myself from this one. That's to be handled as part of the larger #428 issue

The implementation is done. But some changes are required in the testing framework to ensure robust support of the Clarity versions.

csgui commented 1 month ago

The core support for Clarity-3 is already done, meaning that the implementation of stacks-block-height and tenure-height functions.

Changes are missing in the testing components to ensure the tests adapt to different Clarity versions.

hugocaillard commented 1 month ago

Thanks for adding those details @csgui 🙏