Skip to content

Commit 6543a15

Browse files
committed
Fix canonical entry witness examples
1 parent f925897 commit 6543a15

6 files changed

Lines changed: 58 additions & 3 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/examples/token_amm_bootstrap.md‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,13 @@ which is the fillable skeleton a Rust builder can attach to the candidate
183183
transaction after replacing placeholders with concrete cell, capacity, and
184184
dry-run facts.
185185

186-
`cellc entry-witness` emits the raw `_cellscript_entry` payload. Do not wrap it
187-
in `WitnessArgs.input_type` unless the CellScript source explicitly reads that
188-
separate CKB witness surface.
186+
`cellc entry-witness` emits the raw `_cellscript_entry` payload, not a complete
187+
transaction witness. For the canonical
188+
`cellscript-witnessargs-input-type-v2` placement ABI, parse or create the
189+
selected script-group `WitnessArgs`, preserve its `lock` and `output_type`
190+
fields, and place the payload in `input_type` before any lock-script signer
191+
runs. Never submit the raw `CSARGv1` payload as a transaction witness and never
192+
mutate `input_type` after signing.
189193

190194
## ProofPlan And Builder Assumptions
191195

‎examples/ckb-sdk-builder/Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ publish = false
77

88
[dependencies]
99
cellscript-ckb-adapter = { path = "../../crates/cellscript-ckb-adapter" }
10+
11+
[dev-dependencies]
12+
ckb-types = "1.0.0"

‎examples/ckb-sdk-builder/README.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,27 @@ It demonstrates the boundary:
2424
outputs, lineage, witnesses, warnings, and estimated fee without rendering UI.
2525
- `AcceptedActionReport` records cycles, tx-pool acceptance, optional submitted
2626
tx hash, tx size, occupied capacity, fee, and lineage after node checks.
27+
- `place_entry_witness_payload_before_signing` preserves the existing
28+
`WitnessArgs.lock` and `output_type` fields while placing the compiler-emitted
29+
`CSARGv1` payload in canonical `WitnessArgs.input_type`. Call it before any
30+
lock-script signer because the signature commits to the complete witness.
2731
- `ckb-sdk-rust` owns transaction building, signer integration, RPC cycle
2832
estimation, tx-pool acceptance, and optional submission.
2933

34+
The placement step is explicit:
35+
36+
```rust
37+
let witness = place_entry_witness_payload_before_signing(
38+
&base_witness_args,
39+
EntryWitnessPlacementAbi::WitnessArgsInputTypeV2,
40+
entry_payload,
41+
)?;
42+
```
43+
44+
`entry_payload` is the raw output of `cellc entry-witness`; the resulting
45+
serialized `WitnessArgs` is the transaction witness. A raw `CSARGv1` payload,
46+
`output_type` alias, or post-signing mutation is not compatible with the 0.23
47+
CKB entry ABI.
48+
3049
The cookbook tests are offline and do not require a running CKB node. Focused
3150
local-node evidence lives in `scripts/cellscript_ckb_adapter_acceptance.sh`.

‎examples/ckb-sdk-builder/src/lib.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub use cellscript_ckb_adapter::*;
99
#[cfg(test)]
1010
mod tests {
1111
use super::*;
12+
use ckb_types::{bytes::Bytes, packed::WitnessArgs, prelude::*};
1213

1314
#[test]
1415
fn cookbook_uses_formal_adapter_crate() {
@@ -20,4 +21,25 @@ mod tests {
2021
assert!(!evidence.ckb_vm_execution);
2122
assert!(!evidence.tx_pool_acceptance);
2223
}
24+
25+
#[test]
26+
fn cookbook_places_entry_payload_in_witnessargs_input_type_before_signing() {
27+
let base = WitnessArgs::new_builder()
28+
.lock(Some(Bytes::from(vec![0u8; 65])).pack())
29+
.output_type(Some(Bytes::from_static(b"preserved-output-type")).pack())
30+
.build();
31+
let payload = Bytes::from_static(b"CSARGv1\0\x2a\0\0\0\0\0\0\0");
32+
33+
let witness =
34+
place_entry_witness_payload_before_signing(&base, EntryWitnessPlacementAbi::WitnessArgsInputTypeV2, payload.clone())
35+
.expect("canonical entry placement should succeed before signing");
36+
37+
assert_eq!(witness.lock().to_opt().expect("lock placeholder preserved").raw_data().len(), 65);
38+
assert_eq!(witness.input_type().to_opt().expect("entry payload placed").raw_data(), payload);
39+
assert_eq!(
40+
witness.output_type().to_opt().expect("output_type preserved").raw_data(),
41+
Bytes::from_static(b"preserved-output-type")
42+
);
43+
assert_eq!(EntryWitnessPlacementAbi::WitnessArgsInputTypeV2.name(), ENTRY_WITNESS_PLACEMENT_ABI);
44+
}
2345
}

‎tests/examples.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ fn token_amm_bootstrap_docs_cover_builder_friction_boundary() {
524524
"launch_token` materialises the Pool and LP receipt topology directly",
525525
"Do not rely on \"the first action runs on creation\" as a protocol rule",
526526
"Cell-bound inputs and outputs are transaction Cells, not witness payload args",
527+
"place the payload in `input_type` before any lock-script signer runs",
528+
"Never submit the raw `CSARGv1` payload as a transaction witness",
527529
"Strict v0.16 ProofPlan checks compile the bundled token, AMM, and launch actions as original scoped entries",
528530
] {
529531
assert!(bootstrap_text.contains(needle), "bootstrap guide should contain `{needle}`");
@@ -536,6 +538,10 @@ fn token_amm_bootstrap_docs_cover_builder_friction_boundary() {
536538
] {
537539
assert!(bootstrap.contains(needle), "bootstrap guide should contain `{needle}`");
538540
}
541+
assert!(
542+
!bootstrap.contains("Do not wrap it in `WitnessArgs.input_type`"),
543+
"bootstrap guide must not reintroduce the retired raw-witness placement guidance"
544+
);
539545

540546
let flows = std::fs::read_to_string(
541547
Utf8PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("docs").join("CELLSCRIPT_EXAMPLE_BUSINESS_FLOWS.md"),

0 commit comments

Comments
 (0)