36 releases
new 0.16.3 | Nov 1, 2024 |
---|---|
0.16.1 | Oct 28, 2024 |
0.15.3 | Mar 25, 2024 |
0.14.3 | Aug 25, 2023 |
0.1.1 | Mar 25, 2020 |
#543 in Magic Beans
634 downloads per month
Used in 4 crates
270KB
7K
SLoC
ckb-std
This library contains several modules that help you write CKB contract with Rust.
Usage
Modules
syscalls
module: defines CKB syscallshigh_level
module: defines high level APIsdynamic_loading
module: dynamic loading primitivesdebug!
macro: aprintln!
like macro helps debuggingentry!
macro: defines contract entry pointdefault_alloc!
macro: defines global allocator for no-std rustdummy_atomic
module: dummy atomic operationslogger
module: colored logger implementationtype_id
module: Type ID implementation (featuretype-id
)
Memory allocator
Default allocator uses a mixed allocation strategy:
- Fixed block heap, only allocate fixed size(64B) memory block
- Dynamic memory heap, allocate any size memory block
User can invoke macro with arguments to customize the heap size. The default heap size arguments are:
(fixed heap size 4KB, dynamic heap size 516KB, dynamic heap min memory block 64B)
Use the macro with arguments to change it:
default_alloc!(4 * 1024, 516 * 1024, 64)
Beware, use difference heap size or memory block size may affect the verification result of the contract, some runtime errors such as out of memory may occur; you should always test the contract after customizing.
Examples
Check examples
and tests to learn how to use.
See also ckb-tool which helps you write tests.
Upgrading Issues
Starting from ckb-std 0.16.0, RISC-V atomic instructions are generated by default. However, ckb-vm doesn't directly support atomic instructions. To address this, ckb-std provides the following solutions:
- Use the "dummy-atomic" feature (enabled by default)
- Adjust Rust compilation flags by adding
-C target-feature=-a
toRUSTFLAGS
For more detailed information on compilation flags, refer to the CKB Script Templates repository.
Dependencies
~1.5–7MB
~61K SLoC