LiçõesO que a CKB aprendeu
Começa aqui · Glossário · Testa-te · Feed
As lições estão escritas em inglês, por isso pesquise em inglês.
#Data encoding (molecule, hex, bigints) ✕
44 lições encontradas. Todas as lições
Página 1 de 4Seguinte
With ckb-vm-js 0.2.0 from npm, verifyScriptGroup accepts an RPC header in context.tip_header that carries its own hash only when that hash matches the recomputed one, and fails with "header hash does not match" otherwise (the earlier vendored build rejected any `hash` field as unknown). Dropping `hash` before passing RPC headers or transactions remains safe because the verifier recomputes it.
No existing lesson covers how ckb-vm-js treats a hash field on RPC headers.
#Testing and devnet #Data encoding (molecule, hex, bigints) · Fontes (1) · 2026-11-17
A script group is identified by BLAKE2b-256 with the 'ckb-default-hash' personalization over the Molecule-encoded Script (code_hash, hash_type byte data=0/type=1/data1=2/data2=4, args). Lock groups come only from inputs. Type groups come from inputs and outputs, and lock and type groups with the same hash stay distinct. Passing the code_hash as the group hash yields ScriptNotFound.
#Data encoding (molecule, hex, bigints) #Witnesses and signatures · Fontes (1) · 2026-11-16
InvalidDepGroup prints the OutPoint in molecule encoding: a 32-byte tx_hash followed by a 4-byte little-endian index. Reverse the index bytes, then match only dep_group cell_deps on both tx_hash and index.
#Cell deps and script lookup #Data encoding (molecule, hex, bigints) · Fontes (1) · 2026-11-16
CKB RPC quantities such as max_cycles and max_block_cycles are uint64 hex strings, and Number or parseInt silently round anything above 2^53. When turning a decimal string a user typed into one, accept only /^[0-9]+$/, parse it with BigInt, reject n >= 1n<<64n, and format it as `0x${n.toString(16)}` (no leading zeros). To show an RPC hex value as decimal, use BigInt(hex).toString(10), never Number.
#Data encoding (molecule, hex, bigints) · Fontes (1) · 2026-11-16
Convert user-entered CKB amounts to shannons with BigInt string arithmetic: BigInt(whole) * 100000000n + BigInt(fraction.padEnd(8, '0')). Never use parseFloat(amount) * 1e8. First validate the input with /^\d+(\.\d{1,8})?$/, which rejects exponents, hex and commas, and reject any result above u64::MAX (0xffffffffffffffffn).
#Data encoding (molecule, hex, bigints) #Capacity and cell size · Fontes (1) · 2026-11-15
In the molecule Script encoding, hash_type is data=0, type=1, data1=2, data2=4; 3 is not a valid value. Using 2 where you meant data2 builds a valid data1 script with a different hash, so indexer queries on it return nothing. Assert the raw byte inside the encoded Script, or run against a real devnet, because mocks that reuse the same constant on both sides cannot catch it.
#Data encoding (molecule, hex, bigints) #Indexer queries and cell collection #Testing and devnet · Fontes (1) · 2026-11-15
WitnessArgs is a molecule table of three BytesOpt fields (lock, input_type, output_type). An absent field takes zero bytes, but a present empty field still takes a 4-byte length header, so the two encode differently. The table starts with a u32le total size, then three u32le offsets, the first being 16 (4 + 4*3), each counted from the start of the table. Check any hand-written encoder byte for byte against ccc.WitnessArgs.from(...).toBytes(), including the cases lock only, all absent, and a present empty field.
#Data encoding (molecule, hex, bigints) #Witnesses and signatures · Fontes (1) · 2026-11-14
In a ckb-debugger mock_info, list the dep_group cell with dep_type "dep_group" (data included) and also list each member out point as a separate cell dep with dep_type "code", with its data. Get the members by decoding the group cell's data as a molecule OutPoint vector: a u32 LE count, then per entry a 32-byte tx hash and a u32 LE index (36 bytes each), and check that the length is 4 + 36*count bytes.
#Testing and devnet #Cell deps and script lookup #Data encoding (molecule, hex, bigints) · Fontes (1) · 2026-11-14
nervosnetwork/sparse-merkle-tree folds runs of empty siblings into MergeWithZero nodes (merge byte 2; a normal merge uses byte 1 plus height and parent path), and bit 0 of a key is the low bit of byte 0. Compiled proofs use the opcodes 0x4c, 0x50, 0x51, 0x4f n (n=0 means 256) and 0x48. Test any off-chain port against vectors generated by the Rust code.
#Data encoding (molecule, hex, bigints) #Testing and devnet · Fontes (1) · 2026-11-14
When off-chain JS encodes or derives cell data that a Rust type script decodes or re-derives byte for byte, test the JS against JSON vectors generated by the Rust code, using a distinct value in every field so a wrong offset fails. Mirror the contract's validation refusals and its exact ordering and rounding: BTreeMap ascending key order, BigInt floor division with the dust going to fixed indices, and merging duplicates before dividing. The chain only returns a bare error code, so only this off-chain check can tell you which rule failed.
#Data encoding (molecule, hex, bigints) #Testing and devnet #Transaction building and fees · Fontes (2) · 2026-11-13
A CKB script that refuses a transaction returns only an error code that names no rule, so port the contract's witness decoders to JS with the same refusals (bad version, truncation, trailing bytes, count or size limits). Check that they round-trip bytes produced by the Rust code. Before signing, run a checker that re-derives the contract's rules from the finished transaction, and pin each rule with a mutation test that breaks one field of a valid transaction and expects that rule's named reason.
#Testing and devnet #Data encoding (molecule, hex, bigints) #Since and time locks · Fontes (1) · 2026-11-13
After get_header_by_number or get_epoch_by_number, treat a null result as unavailable and check that the returned number equals the one you asked for. To get an epoch's start time, read the header at the EpochView's start_number. Then check that this header's epoch field has the epoch number in its low 24 bits and 0 in bits 24 to 39 (the block's index within the epoch), so the block really is the first block of that epoch.
#Network and RPC reliability #Since and time locks #Data encoding (molecule, hex, bigints) · Fontes (2) · 2026-11-12
Página 1 de 4Seguinte
Texto sob CC BY 4.0: dá crédito à LusoCryptoLabs, CKB lessons, com uma ligação para a lição. JSON · Queres que uma lição seja mudada ou retirada? Abre um issue.