CKB Pulse
经验

CKB 学到了什么

从这里开始 · 术语表 · 自测 · 订阅

经验用英文撰写,请用英文搜索。

Rust scripts and ckb-std

找到 35 条经验。 全部经验

第 3 页,共 3 页

Disable overflow checks for ckb-std when using its dummy-atomic polyfills进阶来自一次修复

When a release profile sets overflow-checks = true and ckb-std (here =1.1.0 with the dummy-atomic feature) supplies the single-thread __atomic polyfills, add a per-package override turning overflow checks off for ckb-std. Atomic read/modify/write arithmetic is defined to wrap, so checked arithmetic in those polyfills would panic instead of wrapping.

#Other · 来源(1) · 2026-10-07

Parse raw CKB blocks with from_compatible_slice to accept BlockV1 extension实践来自一次修复

Serialized CKB blocks may be BlockV1, which appends a consensus extension field after the Block molecule fields, so a strict packed::BlockReader::from_slice can reject them. This commit parses block bytes with ckb-gen-types 1.1.1 packed::BlockReader::from_compatible_slice, which accepts the extra field while still exposing header() and transactions().

#Data encoding (molecule, hex, bigints) · 来源(1) · 2026-10-07

Partial load of a cell's type Script header to match code_hash and hash_type进阶来自一次修复

In a ckb-std script you can load a cell's type script into a fixed 49 byte buffer with syscalls::load_cell_by_field(..., CellField::Type), then compare code_hash at bytes 16..48 and hash_type at byte 48 of the molecule Script table, without allocating for args. A short buffer returns Err(SysError::LengthNotEnough) yet still fills the buffer, so treat that error like Ok, and treat ItemMissing as a cell with no type script.

#Data encoding (molecule, hex, bigints) #Cell deps and script lookup · 来源(1) · 2026-10-07

Raw cell_deps indexes match Source::CellDep only before the first dep group进阶来自一次修复

When a script reads the raw transaction's cell_deps (via load_transaction) and uses a position there as a Source::CellDep index for load_cell_type_hash or load_cell_data, the mapping holds only for the leading run of dep_type code entries, because dep groups expand into their member cells and shift later indexes. This vote script restricts its proposal and deposit lookups to that direct prefix and lets wallet dep groups follow it.

#Cell deps and script lookup · 来源(1) · 2026-10-07

Delegating script validation via exec to a hash bound cell dep实践来自一次修复

This lifecycle type script stores a 32 byte data hash in its args, scans cell deps with load_cell_data_hash to find exactly one match (rejecting duplicates), then calls ckb_std syscalls::exec on that dep, which keeps the current Script context (GroupInput, GroupOutput, args) for the child. Because exec only returns when it fails, any code after the call must return an error instead of falling through to success.

#Cell deps and script lookup #Type ID and upgrades · 来源(1) · 2026-10-04

Relative block number since uses top byte 0x80, not the absolute epoch 0x20实践来自一次修复

Under RFC 0017 since encoding, bit 63 marks relative and bits 61 to 62 select the metric (00 is block number), so a relative block count is RELATIVE_BLOCK_FLAG (0x8000000000000000) OR the count, and 256 blocks becomes 0x8000000000000100. In this commit the type script checks since >> 56 == 0x80, so reusing the absolute epoch form (top byte 0x20) is rejected on chain with an error code that does not name the since as the cause.

#Since and time locks · 来源(2) · 2026-10-02

Porting the sighash_all signing message into a Rust lock script实践来自一次修复

To reproduce secp256k1_blake160_sighash_all's message in a ckb-std lock, hash with ckb blake2b: tx hash, then the first GroupInput witness parsed as WitnessArgs with its lock field zero filled (same length) and u64 LE length prefixed, then the other GroupInput witnesses, then every Source::Input witness at index >= the total input count (each length prefixed). The commit counts inputs by probing load_input_since until IndexOutOfBound.

#Witnesses and signatures · 来源(1) · 2026-09-29

Absolute epoch since needs the 0x20 metric flag in the top byte实践来自一次修复

An input since meaning "not before epoch N" must be 0x2000000000000000 | N: top byte 0x20 (absolute, epoch metric) with the epoch number in the low 24 bits. Without the flag the node reads the value as an absolute block number, which for any realistic epoch is already past, so the node enforces no epoch bound. A script that reads since as an epoch must check the metric flag itself, as this project's contract does by refusing a since whose top byte is not 0x20.

Builder side rule for setting the epoch flag.

#Since and time locks · 来源(2) · 2026-09-25

Place a script's raw witness at the index of the input it validates实践来自一次修复

When a type script reads its proof with load_witness(index, Source::Input) for its own input, the builder must put that raw witness at exactly that input's index. This commit puts the ledger cell at input 0 so its proof is witness 0, and pads the remaining witnesses with "0x" so witnesses.length equals inputs.length and a later funding/signing step appends rather than displaces it.

#Witnesses and signatures #Transaction building and fees · 来源(1) · 2026-09-25

Treat an absent WitnessArgs.lock as a load failure in ckb-std lock scripts实践来自一次修复

With ckb-std, `load_witness_args(0, Source::GroupInput)` can succeed while `WitnessArgs.lock` is an empty BytesOpt, so call `lock().to_opt()` and return an error on None before reading `raw_data()`. The commit's ckb-testtool tests check both a missing witness and a WitnessArgs with no lock field, and both fail with the load witness error.

#Witnesses and signatures #Data encoding (molecule, hex, bigints) · 来源(1) · 2026-09-25

Check that a derived successor type args match the spent cell's type args实践来自一次修复

When a successor cell's type args are derived from other data (such as a config commitment) instead of copied from the spent input, compare them with the input cell's own type args before building. A mismatch (for example a config cell paired with a shard from another round) puts the input's type script group in the transaction with no output, so the type script runs as a burn and typically fails with an opaque error code. Read output.type.args during cell discovery and throw a clear client error on mismatch.

#Transaction building and fees #Cell deps and script lookup · 来源(1) · 2026-09-23

第 3 页,共 3 页

文本采用 CC BY 4.0:请署名 LusoCryptoLabs, CKB lessons,并附上经验的链接。 JSON · 想修改或撤下某条经验?请提交 issue。